clibdocker  0.1.0-alpha.0
A Docker API for C
Data Structures | Macros | Typedefs | Functions
docker_util.h File Reference

Docker API utils. More...

#include <json-c/json_object.h>
#include "docker_result.h"
Include dependency graph for docker_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pair_t
 

Typedefs

typedef struct pair_t pair
 

Functions

d_err_t make_pair (pair **p, char *key, char *value)
 
char * get_value (pair *p)
 
char * get_key (pair *p)
 
void free_pair (pair *p)
 
json_object * make_filters ()
 
void add_filter_str (json_object *filters, const char *name, const char *value)
 
void add_filter_int (json_object *filters, const char *name, int value)
 
const char * filters_to_str (json_object *filters)
 
char * str_clone (const char *from)
 
char * get_attr_str (json_object *obj, const char *name)
 
d_err_t set_attr_str (json_object *obj, const char *name, const char *val)
 
int get_attr_int (json_object *obj, const char *name)
 
d_err_t set_attr_int (json_object *obj, const char *name, int val)
 
int get_attr_boolean (json_object *obj, const char *name)
 
d_err_t set_attr_boolean (json_object *obj, const char *name, int val)
 
long get_attr_long (json_object *obj, const char *name)
 
d_err_t set_attr_long (json_object *obj, const char *name, long val)
 
unsigned long get_attr_unsigned_long (json_object *obj, const char *name)
 
d_err_t set_attr_unsigned_long (json_object *obj, const char *name, unsigned long val)
 
long long get_attr_long_long (json_object *obj, const char *name)
 
d_err_t set_attr_long_long (json_object *obj, const char *name, long long val)
 
time_t get_attr_time (json_object *obj, const char *name)
 
d_err_t set_attr_time (json_object *obj, const char *name, time_t val)
 
json_object * get_attr_json_object (json_object *obj, const char *name)
 
d_err_t set_attr_json_object (json_object *obj, const char *name, json_object *val)
 
json_type get_attr_type (json_object *obj, const char *name)
 
const char * get_json_string (json_object *obj)
 
void add_array_str (json_object *obj, const char *name, const char *value)
 
void add_array_int (json_object *obj, const char *name, int value)
 
void parse_iso_datetime (char *date_str, struct tm *tm)
 Parse the iso date time from given string. More...
 
void parse_docker_stats_readtime (char *date_str, struct tm *tm)
 Parse the docker stats read time from the given string. More...
 
char * calculate_size (uint64_t size)
 

Detailed Description

Docker API utils.

Typedef Documentation

◆ pair

typedef struct pair_t pair

A simple pair of strings

Function Documentation

◆ add_array_int()

void add_array_int ( json_object *  obj,
const char *  name,
int  value 
)

Add an int value to the array if it exits, or create a new one.

Parameters
objthe json object containing the array
namename of the array
valuevalue of the array

◆ add_array_str()

void add_array_str ( json_object *  obj,
const char *  name,
const char *  value 
)

Add a string value to the array if it exits, or create a new one.

Parameters
objthe json object containing the array
namename of the array
valuevalue of the array

◆ add_filter_int()

void add_filter_int ( json_object *  filters,
const char *  name,
int  value 
)

Add an int value to the filter if it exits, or create a new one.

Parameters
filtersthe filters object created earlier using make_filters
namename of the filter
valuevalue of the filter

◆ add_filter_str()

void add_filter_str ( json_object *  filters,
const char *  name,
const char *  value 
)

Add a string value to the filter if it exits, or create a new one.

Parameters
filtersthe filters object created earlier using make_filters
namename of the filter
valuevalue of the filter

◆ calculate_size()

char* calculate_size ( uint64_t  size)

Get the size in bytes, kb, mb, gb, tb etc. (higest possible unit)

Parameters
size
Returns
string with the description of the size

◆ filters_to_str()

const char* filters_to_str ( json_object *  filters)

Convert the filters object to a json string. Behaviour is undefined if filters is NULL.

Parameters
filters
Returns
json string

◆ free_pair()

void free_pair ( pair p)

Free the pair object

Parameters
ppair

References pair_t::key, and pair_t::value.

◆ get_attr_boolean()

int get_attr_boolean ( json_object *  obj,
const char *  name 
)

Get a boolean object with the given key from a json_object

Parameters
objthe json object
nameof the string attribute
Returns
boolean value of attribute

◆ get_attr_int()

int get_attr_int ( json_object *  obj,
const char *  name 
)

Get a int object with the given key from a json_object

Parameters
objthe json object
nameof the string attribute
Returns
int value of attribute

◆ get_attr_json_object()

json_object* get_attr_json_object ( json_object *  obj,
const char *  name 
)

Get a long long object with the given key from a json_object

Parameters
objthe json object
nameof the object attribute
Returns
long long value of attribute

◆ get_attr_long()

long get_attr_long ( json_object *  obj,
const char *  name 
)

Get a long object with the given key from a json_object

Parameters
objthe json object
nameof the string attribute
Returns
long value of attribute

◆ get_attr_long_long()

long long get_attr_long_long ( json_object *  obj,
const char *  name 
)

Get a long long object with the given key from a json_object

Parameters
objthe json object
nameof the string attribute
Returns
long long value of attribute

◆ get_attr_str()

char* get_attr_str ( json_object *  obj,
const char *  name 
)

Get a string object with the given key from a json_object (will return NULL if the attribute is not found).

Parameters
objthe json object
nameof the string attribute
Returns
string value of attribute

Referenced by get_attr_time().

◆ get_attr_time()

time_t get_attr_time ( json_object *  obj,
const char *  name 
)

Get the time_t object with the given key from a json_object

Parameters
objthe json_object
nameof the string attribute
Returns
time_t value of the attribute

References get_attr_str(), and parse_iso_datetime().

◆ get_attr_type()

json_type get_attr_type ( json_object *  obj,
const char *  name 
)

Get the json type of the attribute identified by "name" of the given json_object. See the json_type enum for possible values.

Parameters
objthe json object
nameof the attribute
Returns
json_type

◆ get_attr_unsigned_long()

unsigned long get_attr_unsigned_long ( json_object *  obj,
const char *  name 
)

Get a unsigned long object with the given key from a json_object

Parameters
objthe json object
nameof the string attribute
Returns
unsigned long value of attribute

◆ get_json_string()

const char* get_json_string ( json_object *  obj)

Get prettified json string. The returned string is owned by the json_object, and will be free when the json_object is freed. If caller needs to use the string beyond the lifetime of owning object, create a duplicate.

Parameters
objthe json object.
Returns
the json string.

◆ get_key()

char* get_key ( pair p)

Get the key part of the pair

Parameters
ppair
Returns
string key

References pair_t::key.

◆ get_value()

char* get_value ( pair p)

Get the value part of the pair

Parameters
ppair
Returns
string value

References pair_t::value.

◆ make_filters()

json_object* make_filters ( )

Create new filter json_object for use in calls to the docker API, which uses filters in many endpoints.

Returns
new json_object* which should be passed to all calls to filter methods.

◆ make_pair()

d_err_t make_pair ( pair **  p,
char *  key,
char *  value 
)

Create a new pair with the given key and value. The key and value strings can be freed, as the constructor creates its own copy of the strings.

Parameters
ppair to create and return
keykey of the pair
valuevalue of the pair
Returns
error code

◆ parse_docker_stats_readtime()

void parse_docker_stats_readtime ( char *  date_str,
struct tm *  tm 
)

Parse the docker stats read time from the given string.

Parameters
date_strinput date string
tmoutput time object

◆ parse_iso_datetime()

void parse_iso_datetime ( char *  date_str,
struct tm *  tm 
)

Parse the iso date time from given string.

Parameters
date_strinput date string
tmoutput time object

Referenced by get_attr_time().

◆ set_attr_boolean()

d_err_t set_attr_boolean ( json_object *  obj,
const char *  name,
int  val 
)

Set a boolean object with the given key in a json_object

Parameters
objthe json object
nameof the string attribute
valstring value of the attribute
Returns
string value of attribute

◆ set_attr_int()

d_err_t set_attr_int ( json_object *  obj,
const char *  name,
int  val 
)

Set an integer object with the given key in a json_object

Parameters
objthe json object
nameof the string attribute
valstring value of the attribute
Returns
string value of attribute

◆ set_attr_json_object()

d_err_t set_attr_json_object ( json_object *  obj,
const char *  name,
json_object *  val 
)

Set a json object with the given key in a json_object

Parameters
objthe json object
nameof the string attribute
valstring value of the attribute
Returns
string value of attribute

◆ set_attr_long()

d_err_t set_attr_long ( json_object *  obj,
const char *  name,
long  val 
)

Set a long integer object with the given key in a json_object

Parameters
objthe json object
nameof the string attribute
valstring value of the attribute
Returns
string value of attribute

◆ set_attr_long_long()

d_err_t set_attr_long_long ( json_object *  obj,
const char *  name,
long long  val 
)

Set a long long int object with the given key in a json_object

Parameters
objthe json object
nameof the string attribute
valstring value of the attribute
Returns
string value of attribute

◆ set_attr_str()

d_err_t set_attr_str ( json_object *  obj,
const char *  name,
const char *  val 
)

Set a string object with the given key in a json_object

Parameters
objthe json object
nameof the string attribute
valstring value of the attribute
Returns
string value of attribute

◆ set_attr_time()

d_err_t set_attr_time ( json_object *  obj,
const char *  name,
time_t  val 
)

Set a time object with the given key in a json_object

Parameters
objthe json object
nameof the string attribute
valstring value of the attribute
Returns
string value of attribute

◆ set_attr_unsigned_long()

d_err_t set_attr_unsigned_long ( json_object *  obj,
const char *  name,
unsigned long  val 
)

Set an unsigned long integer object with the given key in a json_object

Parameters
objthe json object
nameof the string attribute
valstring value of the attribute
Returns
string value of attribute

◆ str_clone()

char* str_clone ( const char *  from)

Clone a string for usage in internal apis. User of api can then get rid of their copy. (obviously wasteful, use with caution)

Parameters
fromstring to clone from
Returns
cloned string, NULL if there is an error.

Referenced by docker_call_content_type_header_set(), docker_call_get_svc_url(), docker_call_get_url(), docker_call_params_add(), docker_call_request_data_set(), docker_call_request_method_set(), and list_dir_w_ignore().