clibdocker
0.1.0-alpha.0
A Docker API for C
|
Docker Connection Utils. More...
#include <coll_arraylist.h>
#include <coll_arraylist_map.h>
#include <stdlib.h>
#include "docker_common.h"
#include <stdbool.h>
#include <json-c/json_object.h>
#include <json-c/json_tokener.h>
#include <json-c/linkhash.h>
#include <curl/curl.h>
#include "docker_result.h"
Go to the source code of this file.
Data Structures | |
struct | docker_context_t |
A docker context for a specific docker server. More... | |
struct | docker_call_t |
internal datastructure representing a Docker Call object. More... | |
Macros | |
#define | DOCKER_API_VERSION_1_39 "1.39" |
Currently supported Docker API Version. | |
#define | DOCKER_DEFAULT_UNIX_SOCKET "/var/run/docker.sock" |
Docker UNIX Socket URL. | |
#define | DOCKER_NPIPE_URL_PREFIX "npipe://" |
Window NPIPE URL Prefix. | |
#define | DOCKER_DEFAULT_WINDOWS_NAMED_PIPE "npipe:////./pipe/docker_engine" |
Default Windows Docker NPIPE URL. | |
#define | DOCKER_DEFAULT_LOCALHOST_URL "http://localhost:2375/" |
Default Docker HTTP URL. | |
#define | HEADER_JSON "Content-Type: application/json" |
JSON Content Type Header. | |
#define | HEADER_TAR "Content-Type: application/x-tar" |
TAR Content Type Header. | |
Typedefs | |
typedef void() | docker_result_handler_fn(struct docker_context_t *ctx, docker_result *result) |
Defines a docker result handler function. More... | |
typedef struct docker_context_t | docker_context |
A docker context for a specific docker server. | |
typedef void() | status_callback(char *msg, void *cbargs, void *client_cbargs) |
Status callback function type. This is used to get a status callback from docker calls. | |
typedef struct docker_call_t | docker_call |
internal datastructure representing a Docker Call object. More... | |
Enumerations | |
enum | docker_object_type { NONE = 0 , CONTAINER = 1 , IMAGE = 2 , SYSTEM = 3 , NETWORK = 4 , VOLUME = 5 } |
Docker Object type in the Docker API call JSON. | |
Functions | |
bool | is_http_url (char *url) |
Check if the given string input is a HTTP(s) URL. More... | |
bool | is_unix_socket (char *url) |
Check if the given string input is a UNIX socket URL. More... | |
bool | is_npipe (char *url) |
Check if the given string input is an NPIPE URL. More... | |
char * | npipe_url_only (char *url) |
Get the docker api url part of the npipe url. Removes the npipe:// prefix from the url. More... | |
d_err_t | docker_api_init () |
void | docker_api_cleanup () |
d_err_t | make_docker_context_url (docker_context **ctx, const char *url) |
d_err_t | make_docker_context_default_local (docker_context **ctx) |
d_err_t | docker_context_result_handler_set (docker_context *ctx, docker_result_handler_fn *result_handler_fn) |
docker_result_handler_fn * | docker_context_result_handler_get (docker_context *ctx) |
Get the docker context result handler function. More... | |
d_err_t | docker_context_client_args_set (docker_context *ctx, void *client_args) |
Set the client args for the docker context. More... | |
void * | docker_context_client_args_get (docker_context *ctx) |
Get the client args for the docker context. More... | |
d_err_t | free_docker_context (docker_context **ctx) |
d_err_t | make_docker_call (docker_call **dcall, char *site_url, docker_object_type object, const char *id, const char *method) |
Create a new generic Docker API Call object. More... | |
void | docker_call_request_method_set (docker_call *dcall, char *method) |
Set the docker request HTTP method. More... | |
char * | docker_call_request_method_get (docker_call *dcall) |
Get the docker request HTTP method. More... | |
void | docker_call_content_type_header_set (docker_call *dcall, char *content_type_header) |
Set the docker call content type header. More... | |
char * | docker_call_content_type_header_get (docker_call *dcall) |
Get the docker request content type header. More... | |
void | docker_call_request_data_set (docker_call *dcall, char *request_data) |
Set the docker request data. More... | |
char * | docker_call_request_data_get (docker_call *dcall) |
Get the docker request data. More... | |
void | docker_call_request_data_len_set (docker_call *dcall, size_t request_data_len) |
Set the docker request data length. More... | |
size_t | docker_call_request_data_len_get (docker_call *dcall) |
Get the docker request data length. More... | |
char * | docker_call_response_data_get (docker_call *dcall) |
Get the docker response data. More... | |
size_t | docker_call_response_data_length (docker_call *dcall) |
Get the docker response data length. More... | |
int | docker_call_http_code_get (docker_call *dcall) |
Get the docker response HTTP code. More... | |
void | docker_call_http_code_set (docker_call *dcall, int http_code) |
Set the docker respose HTTP code. More... | |
void | docker_call_status_cb_set (docker_call *dcall, status_callback *status_callback) |
Set the docker call callback function. More... | |
status_callback * | docker_call_status_cb_get (docker_call *dcall) |
Get the docker call callback function. More... | |
void | docker_call_cb_args_set (docker_call *dcall, void *cb_args) |
Set the docker call callback function callback args. More... | |
void * | docker_call_cb_args_get (docker_call *dcall) |
Get the docker call callback function callback args. More... | |
void | docker_call_client_cb_args_set (docker_call *dcall, void *client_cb_args) |
Set the docker call client callback args. More... | |
void * | docker_call_client_cb_args_get (docker_call *dcall) |
Get the docker call client callback args. More... | |
void | free_docker_call (docker_call *dcall) |
Free the docker call object. More... | |
int | docker_call_params_add (docker_call *dcall, char *param, char *value) |
Add a string key/value pair to the docker call parameters. More... | |
int | docker_call_params_add_boolean (docker_call *dcall, char *param, int value) |
Add a string key/boolean value pair to the docker call parameters. More... | |
char * | docker_call_get_url (docker_call *dcall) |
Get the docker request HTTP url. More... | |
char * | docker_call_get_svc_url (docker_call *dcall) |
Get the docker request service url. More... | |
d_err_t | docker_call_exec (docker_context *ctx, docker_call *dcall, json_object **response) |
Execute the Docker Call i.e. send the request to the server and get response. More... | |
Docker Connection Utils.
typedef struct docker_call_t docker_call |
internal datastructure representing a Docker Call object.
All Docker API call implementations internally use this object to represent a call to the Docker API.
typedef void() docker_result_handler_fn(struct docker_context_t *ctx, docker_result *result) |
Defines a docker result handler function.
This function type is used to define a result handler by a client program. The result handler is called when the docker API call returns.
void docker_api_cleanup | ( | ) |
Global cleanup of the docker API, should be called once when all api usage is complete.
d_err_t docker_api_init | ( | ) |
Global initialization of the docker API, should be called only once in an application
void* docker_call_cb_args_get | ( | docker_call * | dcall | ) |
Get the docker call callback function callback args.
dcall | docker call object |
References docker_call_t::cb_args.
void docker_call_cb_args_set | ( | docker_call * | dcall, |
void * | cb_args | ||
) |
Set the docker call callback function callback args.
dcall | docker call object |
cb_args | callback args (argument to callback function) |
References docker_call_t::cb_args.
void* docker_call_client_cb_args_get | ( | docker_call * | dcall | ) |
Get the docker call client callback args.
dcall | docker call object |
References docker_call_t::client_cb_args.
void docker_call_client_cb_args_set | ( | docker_call * | dcall, |
void * | client_cb_args | ||
) |
Set the docker call client callback args.
dcall | docker call object |
client_cb_args | args set by the client of the api |
References docker_call_t::client_cb_args.
char* docker_call_content_type_header_get | ( | docker_call * | dcall | ) |
Get the docker request content type header.
dcall | docker call object |
References docker_call_t::content_type_header.
void docker_call_content_type_header_set | ( | docker_call * | dcall, |
char * | content_type_header | ||
) |
Set the docker call content type header.
dcall | docker call object |
content_type_header | content type header |
References docker_call_t::content_type_header, and str_clone().
d_err_t docker_call_exec | ( | docker_context * | ctx, |
docker_call * | dcall, | ||
json_object ** | response | ||
) |
Execute the Docker Call i.e. send the request to the server and get response.
ctx | docker context |
dcall | docker call object |
response | json response object to be set |
char* docker_call_get_svc_url | ( | docker_call * | dcall | ) |
Get the docker request service url.
dcall | docker call object |
References docker_call_t::id, docker_call_t::method, docker_call_t::object, docker_call_t::params, and str_clone().
char* docker_call_get_url | ( | docker_call * | dcall | ) |
Get the docker request HTTP url.
dcall | docker call object |
References docker_call_t::id, docker_call_t::method, docker_call_t::object, docker_call_t::params, docker_call_t::site_url, and str_clone().
int docker_call_http_code_get | ( | docker_call * | dcall | ) |
Get the docker response HTTP code.
dcall | docker call object |
References docker_call_t::http_error_code.
void docker_call_http_code_set | ( | docker_call * | dcall, |
int | http_code | ||
) |
Set the docker respose HTTP code.
dcall | docker call object |
http_code | http response code |
References docker_call_t::http_error_code.
int docker_call_params_add | ( | docker_call * | dcall, |
char * | param, | ||
char * | value | ||
) |
Add a string key/value pair to the docker call parameters.
dcall | docker call object |
param | parameter key |
value | parameter value |
References docker_call_t::params, and str_clone().
Referenced by docker_call_params_add_boolean().
int docker_call_params_add_boolean | ( | docker_call * | dcall, |
char * | param, | ||
int | value | ||
) |
Add a string key/boolean value pair to the docker call parameters.
dcall | docker call object |
param | parameter key |
value | parameter value |
References docker_call_params_add().
char* docker_call_request_data_get | ( | docker_call * | dcall | ) |
Get the docker request data.
dcall | docker call object |
References docker_call_t::request_data.
size_t docker_call_request_data_len_get | ( | docker_call * | dcall | ) |
Get the docker request data length.
dcall | docker call object |
References docker_call_t::request_data_len.
void docker_call_request_data_len_set | ( | docker_call * | dcall, |
size_t | request_data_len | ||
) |
Set the docker request data length.
dcall | docker call object |
request_data_len | request data length |
References docker_call_t::request_data_len.
Referenced by docker_call_request_data_set().
void docker_call_request_data_set | ( | docker_call * | dcall, |
char * | request_data | ||
) |
Set the docker request data.
dcall | docker call object |
request_data | json request data |
References docker_call_request_data_len_set(), docker_call_t::request_data, and str_clone().
char* docker_call_request_method_get | ( | docker_call * | dcall | ) |
Get the docker request HTTP method.
dcall | docker call object |
References docker_call_t::request_method.
void docker_call_request_method_set | ( | docker_call * | dcall, |
char * | method | ||
) |
Set the docker request HTTP method.
dcall | docker call object |
method | http method |
References docker_call_t::request_method, and str_clone().
char* docker_call_response_data_get | ( | docker_call * | dcall | ) |
Get the docker response data.
dcall | docker call object |
References docker_call_t::memory.
size_t docker_call_response_data_length | ( | docker_call * | dcall | ) |
Get the docker response data length.
dcall | docker call object |
References docker_call_t::size.
status_callback* docker_call_status_cb_get | ( | docker_call * | dcall | ) |
Get the docker call callback function.
dcall | docker call object |
References docker_call_t::status_cb.
void docker_call_status_cb_set | ( | docker_call * | dcall, |
status_callback * | status_callback | ||
) |
Set the docker call callback function.
dcall | docker call object |
status_callback* | status callback function for the docker call |
References docker_call_t::status_cb.
void* docker_context_client_args_get | ( | docker_context * | ctx | ) |
Get the client args for the docker context.
ctx | docker context |
References docker_context_t::client_args.
d_err_t docker_context_client_args_set | ( | docker_context * | ctx, |
void * | client_args | ||
) |
Set the client args for the docker context.
ctx | docker context |
client_args | a client args value |
References docker_context_t::client_args.
docker_result_handler_fn* docker_context_result_handler_get | ( | docker_context * | ctx | ) |
Get the docker context result handler function.
ctx | docker context |
References docker_context_t::result_handler_fn.
d_err_t docker_context_result_handler_set | ( | docker_context * | ctx, |
docker_result_handler_fn * | result_handler_fn | ||
) |
Set the result handler function for the docker context. Every API call's result will be passed to the result handler, once the call is complete. NOTE: the result handler will be freed before the API call returns, so if a copy of any of the data in the result is to be retained, caller must make a copy.
ctx | the docker context |
result_handler_fn | callback which receives the docker_result object. |
References docker_context_t::result_handler_fn.
void free_docker_call | ( | docker_call * | dcall | ) |
Free the docker call object.
dcall | docker call object |
References docker_call_t::memory, and docker_call_t::params.
d_err_t free_docker_context | ( | docker_context ** | ctx | ) |
Free docker context memory.
bool is_http_url | ( | char * | url | ) |
Check if the given string input is a HTTP(s) URL.
url | input string |
bool is_npipe | ( | char * | url | ) |
Check if the given string input is an NPIPE URL.
url | input string |
References DOCKER_NPIPE_URL_PREFIX.
Referenced by npipe_url_only().
bool is_unix_socket | ( | char * | url | ) |
Check if the given string input is a UNIX socket URL.
url | input string |
d_err_t make_docker_call | ( | docker_call ** | dcall, |
char * | site_url, | ||
docker_object_type | object, | ||
const char * | id, | ||
const char * | method | ||
) |
Create a new generic Docker API Call object.
The Docker Call object has getters and setters of the form docker_call_<member>_get
, and docker_call_<member>_set
.
dcall | pointer to docker_call* to create and return |
site_url | request url |
object | the docker object type whose endpoint is being called |
id | docker object id |
method | docker request http method |
Referenced by docker_container_attach_default(), docker_container_changes(), docker_container_list(), docker_container_logs(), docker_create_container(), docker_image_build_cb(), docker_images_list(), docker_inspect_container(), docker_kill_container(), docker_networks_list(), docker_pause_container(), docker_ping(), docker_process_list_container(), docker_remove_container(), docker_rename_container(), docker_restart_container(), docker_start_container(), docker_stop_container(), docker_system_df(), docker_system_events_cb(), docker_system_info(), docker_system_version(), docker_unpause_container(), docker_volume_create(), docker_volume_delete(), docker_volumes_delete_unused(), docker_volumes_list(), and docker_wait_container().
d_err_t make_docker_context_default_local | ( | docker_context ** | ctx | ) |
Connect to the default local docker.
ctx | context to create |
References DOCKER_DEFAULT_UNIX_SOCKET, DOCKER_DEFAULT_WINDOWS_NAMED_PIPE, and make_docker_context_url().
d_err_t make_docker_context_url | ( | docker_context ** | ctx, |
const char * | url | ||
) |
Create a new docker context with the given url.
The method makes a copy of the given string for use, so that it can be safely freed by the calling program.
Referenced by make_docker_context_default_local().
char* npipe_url_only | ( | char * | url | ) |
Get the docker api url part of the npipe url. Removes the npipe:// prefix from the url.
url | input string |
References DOCKER_NPIPE_URL_PREFIX, and is_npipe().