libjapi
0.3.2
Universal JSON API Library
|
Universal JSON API library. More...
Go to the source code of this file.
Data Structures | |
struct | japi_context |
JAPI context struct. More... | |
struct | japi_client |
JAPI client context. More... | |
struct | japi_request |
JAPI request struct. More... | |
Typedefs | |
typedef void(* | japi_req_handler )(japi_context *ctx, json_object *request, json_object *response) |
JAPI request handler type. | |
Functions | |
japi_context * | japi_init (void *userptr) |
Create and initialize a new JAPI context. More... | |
int | japi_destroy (japi_context *ctx) |
Destroy a JAPI context. More... | |
int | japi_register_request (japi_context *ctx, const char *req_name, japi_req_handler req_handler) |
Register a JAPI request handler. More... | |
int | japi_start_server (japi_context *ctx, const char *port) |
Start a JAPI server. More... | |
int | japi_set_max_allowed_clients (japi_context *ctx, uint16_t num) |
Set the number of allowed clients. More... | |
int | japi_include_args_in_response (japi_context *ctx, bool include_args) |
Configure context to include request arguments in response. More... | |
int | japi_shutdown (japi_context *ctx) |
Shutdown the JAPI server. More... | |
Universal JSON API library.
libjapi is a universal JSON API library.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
int japi_destroy | ( | japi_context * | ctx | ) |
Destroy a JAPI context.
Destroy the JAPI context pointed to by ctx and release allocated memory.
ctx | JAPI context |
References japi_pushsrv_destroy(), japi_context::lock, japi_pushsrv_context::next, japi_request::next, japi_context::push_services, and japi_context::requests.
int japi_include_args_in_response | ( | japi_context * | ctx, |
bool | include_args | ||
) |
Configure context to include request arguments in response.
Configure context to include request arguments in response
ctx | JAPI context |
include_args | Include request arguments in response. |
References japi_context::include_args_in_response.
japi_context* japi_init | ( | void * | userptr | ) |
Create and initialize a new JAPI context.
Create, initialize and return a new japi_context object.
userptr | Pointer to user data or NULL. If a valid pointer is provided a request handler can access that data later. |
References japi_context::clients, japi_context::include_args_in_response, japi_context::init, japi_cmd_list(), japi_pushsrv_list(), japi_pushsrv_subscribe(), japi_pushsrv_unsubscribe(), japi_register_request(), japi_request_not_found_handler(), japi_context::lock, japi_context::max_clients, japi_context::num_clients, japi_context::push_services, japi_context::requests, japi_context::shutdown, and japi_context::userptr.
int japi_register_request | ( | japi_context * | ctx, |
const char * | req_name, | ||
japi_req_handler | req_handler | ||
) |
Register a JAPI request handler.
Register a JAPI request handler provided as a function pointer req_handler for the request specified by req_name.
ctx | JAPI context |
req_name | Request name |
req_handler | Function pointer |
References japi_request::func, japi_context::init, japi_request::name, japi_request::next, and japi_context::requests.
Referenced by japi_init().
int japi_set_max_allowed_clients | ( | japi_context * | ctx, |
uint16_t | num | ||
) |
Set the number of allowed clients.
Set the maximal number of allowed clients.
ctx | JAPI context |
num | Number of clients to be allowed. 0 stands for unlimited. |
References japi_context::max_clients.
int japi_shutdown | ( | japi_context * | ctx | ) |
Shutdown the JAPI server.
Shutdown the JAPI server.
ctx | JAPI context |
References japi_context::shutdown.
int japi_start_server | ( | japi_context * | ctx, |
const char * | port | ||
) |
Start a JAPI server.
Start a JAPI server on the given port.
ctx | JAPI context |
port | Port to be used by the JAPI server |
References japi_context::clients, creadline_r(), japi_add_client(), japi_process_message(), japi_remove_all_clients(), japi_remove_client(), japi_context::max_clients, japi_context::num_clients, japi_context::shutdown, tcp_start_server(), and write_n().