clibdocker  0.1.0-alpha.0
A Docker API for C
docker_result.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_RESULT_H_
30 #define SRC_DOCKER_RESULT_H_
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include "docker_common.h"
37 #include <time.h>
38 
40 #define DOCKER_PARAM_TRUE 1
41 
43 #define DOCKER_PARAM_FALSE 0
44 
45 // The error code usage below based on suggestions at
46 // https://stackoverflow.com/questions/6286874/c-naming-suggestion-for-error-code-enums
47 
50  E_UNKNOWN_ERROR = 1,
51  E_SUCCESS = 0,
52  E_INVALID_INPUT = -1,
53  E_FILE_NOT_FOUND = -2,
54  E_ALLOC_FAILED = -3,
55  E_PING_FAILED = -4,
56  E_CONNECTION_FAILED = -5
57 };
58 
60 typedef enum _config_error d_err_t;
61 
63 #define HTTP_GET_STR "GET"
64 
66 #define HTTP_POST_STR "POST"
67 
69 #define HTTP_DELETE_STR "DELETE"
70 
71 /* use this to provide a perror style method to help consumers out */
72 //struct _errordesc {
73 // int code;
74 // char *message;
75 //} errordesc[] = { { E_SUCCESS, "No error" },
76 // { E_INVALID_INPUT, "Invalid input" }, { E_FILE_NOT_FOUND,
77 // "File not found" }, };
78 
93 typedef struct docker_result_t {
96  time_t start_time;
99  time_t end_time;
102  char* url;
103  char* method;
108  char* message;
111 
116 MODULE_API d_err_t new_docker_result(docker_result** result);
117 
125 //MODULE_API d_err_t make_docker_result(docker_result** result, d_err_t error_code,
126 // long http_error_code, const char* url, const char* msg);
127 
132 MODULE_API void free_docker_result(docker_result* result);
133 
140 MODULE_API docker_result* docker_result_clone(docker_result* result);
141 
150 
157 MODULE_API time_t docker_result_get_start_time(docker_result* result);
158 
165 MODULE_API time_t docker_result_get_end_time(docker_result* result);
166 
173 MODULE_API char* docker_result_get_url(docker_result* result);
174 
182 MODULE_API char* docker_result_get_method(docker_result* result);
183 
190 MODULE_API char* docker_result_get_request_json_str(docker_result* result);
191 
198 MODULE_API char* docker_result_get_response_json_str(docker_result* result);
199 
206 MODULE_API long docker_result_get_http_error_code(docker_result* result);
207 
216 MODULE_API char* docker_result_get_message(docker_result* result);
217 
221 MODULE_API int is_ok(docker_result* result);
222 
223 
224 //TODO these two functions can be made a single generic function.
230 
235 MODULE_API void docker_simple_error_handler_log(docker_result* res);
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #endif /* SRC_DOCKER_RESULT_H_ */
Some common declarations.
char * docker_result_get_method(docker_result *result)
Get the HTTP method used for the docker API call performed by this operation.
Definition: docker_result.c:131
char * docker_result_get_response_json_str(docker_result *result)
Get the JSON response string received from the docker API endpoint.
Definition: docker_result.c:149
time_t docker_result_get_end_time(docker_result *result)
Get the end time of the operation which produces this result.
Definition: docker_result.c:113
_config_error
Definition: docker_result.h:49
long docker_result_get_http_error_code(docker_result *result)
Get the HTTP error code returned by the docker API call.
Definition: docker_result.c:158
enum _config_error d_err_t
Definition: docker_result.h:60
docker_result * docker_result_clone(docker_result *result)
Clone the given docker_result object.
Definition: docker_result.c:74
d_err_t docker_result_get_error_code(docker_result *result)
Get the result error code. For possible values of the error code see the enum d_err_t.
Definition: docker_result.c:95
void docker_simple_error_handler_print(docker_result *res)
Definition: docker_result.c:187
char * docker_result_get_url(docker_result *result)
Get the url for the docker API call performed by this operation.
Definition: docker_result.c:122
void free_docker_result(docker_result *result)
Definition: docker_result.c:56
d_err_t new_docker_result(docker_result **result)
Definition: docker_result.c:35
char * docker_result_get_request_json_str(docker_result *result)
Get the JSON request string sent to the docker API endpoint.
Definition: docker_result.c:140
void docker_simple_error_handler_log(docker_result *res)
Definition: docker_result.c:200
struct docker_result_t docker_result
int is_ok(docker_result *result)
Definition: docker_result.c:179
char * docker_result_get_message(docker_result *result)
Get the message string received from docker API call. This is usually part of the JSON response....
Definition: docker_result.c:167
time_t docker_result_get_start_time(docker_result *result)
Get the start time of the operation which produced this result.
Definition: docker_result.c:104
Definition: docker_result.h:93
char * message
Definition: docker_result.h:108
time_t start_time
Definition: docker_result.h:96
long http_error_code
Response HTTP error code.
Definition: docker_result.h:107
char * method
Definition: docker_result.h:103
d_err_t error_code
Definition: docker_result.h:94
char * url
URL for the docker API call.
Definition: docker_result.h:102
time_t end_time
Definition: docker_result.h:99
char * response_json_str
Response JSON data (might be NULL)
Definition: docker_result.h:106
char * request_json_str
Request JSON data.
Definition: docker_result.h:105