clibdocker  0.1.0-alpha.0
A Docker API for C
docker_util.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2018-2022 Abhishek Mishra
4  *
5  * This file is part of clibdocker.
6  *
7  * clibdocker is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation,
10  * either version 3 of the License, or (at your option)
11  * any later version.
12  *
13  * clibdocker is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with clibdocker.
20  * If not, see <https://www.gnu.org/licenses/>.
21  *
22  */
23 
29 #ifndef SRC_DOCKER_UTIL_H_
30 #define SRC_DOCKER_UTIL_H_
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 // Do not warn about strcpy_s, sprintf_s and sscanf_s on windows build
37 #define _CRT_SECURE_NO_WARNINGS
38 
39 #include <json-c/json_object.h>
40 #include "docker_result.h"
41 
46 typedef struct pair_t {
47  char* key;
48  char* value;
49 } pair;
50 
60 MODULE_API d_err_t make_pair(pair** p, char* key, char* value);
61 
67 MODULE_API char* get_value(pair*p);
68 
74 MODULE_API char* get_key(pair*p);
75 
80 MODULE_API void free_pair(pair*p);
81 
82 // Filter utility functions for use in Docker API calls.
83 
91 MODULE_API json_object* make_filters();
92 
100 MODULE_API void add_filter_str(json_object* filters, const char* name, const char* value);
101 
109 MODULE_API void add_filter_int(json_object* filters, const char* name, int value);
110 
118 MODULE_API const char* filters_to_str(json_object* filters);
119 
128 MODULE_API char* str_clone(const char* from);
129 
138 MODULE_API char* get_attr_str(json_object* obj, const char* name);
139 
148 MODULE_API d_err_t set_attr_str(json_object* obj, const char* name, const char* val);
149 
157 MODULE_API int get_attr_int(json_object* obj, const char* name);
158 
167 MODULE_API d_err_t set_attr_int(json_object* obj, const char* name, int val);
168 
176 MODULE_API int get_attr_boolean(json_object* obj, const char* name);
177 
186 MODULE_API d_err_t set_attr_boolean(json_object* obj, const char* name, int val);
187 
195 MODULE_API long get_attr_long(json_object* obj, const char* name);
196 
205 MODULE_API d_err_t set_attr_long(json_object* obj, const char* name, long val);
206 
214 MODULE_API unsigned long get_attr_unsigned_long(json_object* obj, const char* name);
215 
224 MODULE_API d_err_t set_attr_unsigned_long(json_object* obj, const char* name, unsigned long val);
225 
233 MODULE_API long long get_attr_long_long(json_object* obj, const char* name);
234 
243 MODULE_API d_err_t set_attr_long_long(json_object* obj, const char* name, long long val);
244 
252 MODULE_API time_t get_attr_time(json_object* obj, const char* name);
253 
262 MODULE_API d_err_t set_attr_time(json_object* obj, const char* name, time_t val);
263 
271 MODULE_API json_object* get_attr_json_object(json_object* obj, const char* name);
272 
281 MODULE_API d_err_t set_attr_json_object(json_object* obj, const char* name, json_object* val);
282 
292 MODULE_API json_type get_attr_type(json_object* obj, const char* name);
293 
304 MODULE_API const char* get_json_string(json_object* obj);
305 
313 MODULE_API void add_array_str(json_object* obj, const char* name, const char* value);
314 
322 MODULE_API void add_array_int(json_object* obj, const char* name, int value);
323 
330 MODULE_API void parse_iso_datetime(char* date_str, struct tm* tm);
331 
338 MODULE_API void parse_docker_stats_readtime(char* date_str, struct tm* tm);
339 
347 MODULE_API char* calculate_size(uint64_t size);
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 
353 #endif /* SRC_DOCKER_UTIL_H_ */
Docker Results.
enum _config_error d_err_t
Definition: docker_result.h:60
json_object * get_attr_json_object(json_object *obj, const char *name)
Definition: docker_util.c:194
void parse_docker_stats_readtime(char *date_str, struct tm *tm)
Parse the docker stats read time from the given string.
Definition: docker_util.c:314
d_err_t set_attr_long(json_object *obj, const char *name, long val)
Definition: docker_util.c:120
int get_attr_boolean(json_object *obj, const char *name)
Definition: docker_util.c:62
int get_attr_int(json_object *obj, const char *name)
Definition: docker_util.c:89
d_err_t set_attr_boolean(json_object *obj, const char *name, int val)
Definition: docker_util.c:77
struct pair_t pair
void add_array_int(json_object *obj, const char *name, int value)
Definition: docker_util.c:283
d_err_t set_attr_unsigned_long(json_object *obj, const char *name, unsigned long val)
Definition: docker_util.c:141
long long get_attr_long_long(json_object *obj, const char *name)
Definition: docker_util.c:153
void add_filter_int(json_object *filters, const char *name, int value)
Definition: docker_util.c:259
json_type get_attr_type(json_object *obj, const char *name)
Definition: docker_util.c:204
d_err_t make_pair(pair **p, char *key, char *value)
Definition: docker_util.c:219
char * get_attr_str(json_object *obj, const char *name)
Definition: docker_util.c:41
char * calculate_size(uint64_t size)
Definition: docker_util.c:338
d_err_t set_attr_str(json_object *obj, const char *name, const char *val)
Definition: docker_util.c:50
void add_filter_str(json_object *filters, const char *name, const char *value)
Definition: docker_util.c:249
d_err_t set_attr_long_long(json_object *obj, const char *name, long long val)
Definition: docker_util.c:162
d_err_t set_attr_json_object(json_object *obj, const char *name, json_object *val)
Definition: docker_util.c:200
time_t get_attr_time(json_object *obj, const char *name)
Definition: docker_util.c:174
char * get_key(pair *p)
Definition: docker_util.c:234
const char * filters_to_str(json_object *filters)
Definition: docker_util.c:269
char * str_clone(const char *from)
Definition: docker_util.c:30
d_err_t set_attr_time(json_object *obj, const char *name, time_t val)
Definition: docker_util.c:182
json_object * make_filters()
Definition: docker_util.c:245
long get_attr_long(json_object *obj, const char *name)
Definition: docker_util.c:111
char * get_value(pair *p)
Definition: docker_util.c:230
void free_pair(pair *p)
Definition: docker_util.c:238
void add_array_str(json_object *obj, const char *name, const char *value)
Definition: docker_util.c:273
void parse_iso_datetime(char *date_str, struct tm *tm)
Parse the iso date time from given string.
Definition: docker_util.c:295
const char * get_json_string(json_object *obj)
Definition: docker_util.c:215
unsigned long get_attr_unsigned_long(json_object *obj, const char *name)
Definition: docker_util.c:132
d_err_t set_attr_int(json_object *obj, const char *name, int val)
Definition: docker_util.c:99
Definition: docker_util.h:46
char * key
Definition: docker_util.h:47
char * value
Definition: docker_util.h:48