mjsonrpc 1.0
A lightweight JSON-RPC 2.0 message parser and generator based on cJSON
Loading...
Searching...
No Matches
Functions
Request Processing Functions

Functions for processing JSON-RPC requests. More...

Functions

char * mjrpc_process_str (mjrpc_handle_t *handle, const char *request_str, int *ret_code)
 Process a JSON-RPC request string.
 
cJSON * mjrpc_process_cjson (mjrpc_handle_t *handle, const cJSON *request_cjson, int *ret_code)
 Process a JSON-RPC request cJSON object.
 

Detailed Description

Functions for processing JSON-RPC requests.

Function Documentation

◆ mjrpc_process_cjson()

cJSON * mjrpc_process_cjson ( mjrpc_handle_t handle,
const cJSON *  request_cjson,
int *  ret_code 
)

Process a JSON-RPC request cJSON object.

Processes a JSON-RPC request cJSON object, calling the appropriate registered method and returning the response as a cJSON object.

Parameters
handleJSON-RPC handle containing registered methods
request_cjsonJSON-RPC request cJSON object
ret_codePointer to store the return code (can be NULL)
Returns
Response cJSON object (caller must delete), or NULL for notifications
Return values
NULLIf the request was a notification or an error occurred
Note
The returned cJSON object must be deleted by the caller
Supports both single requests and batch requests (JSON arrays)
Example:
cJSON *request = cJSON_Parse("{\"jsonrpc\":\"2.0\",\"method\":\"hello\",\"id\":1}");
int ret_code;
cJSON *response = mjrpc_process_cjson(handle, request, &ret_code);
if (response) {
char *response_str = cJSON_Print(response);
printf("Response: %s\n", response_str);
free(response_str);
cJSON_Delete(response);
}
cJSON_Delete(request);
cJSON * mjrpc_process_cjson(mjrpc_handle_t *handle, const cJSON *request_cjson, int *ret_code)
Process a JSON-RPC request cJSON object.

◆ mjrpc_process_str()

char * mjrpc_process_str ( mjrpc_handle_t handle,
const char *  request_str,
int *  ret_code 
)

Process a JSON-RPC request string.

Parses and processes a JSON-RPC request string, calling the appropriate registered method and returning the response as a string.

Parameters
handleJSON-RPC handle containing registered methods
request_strJSON-RPC request string (must be valid JSON)
ret_codePointer to store the return code (can be NULL)
Returns
Response string (caller must free), or NULL for notifications
Return values
NULLIf the request was a notification or an error occurred
Note
The returned string must be freed by the caller
Supports both single requests and batch requests (JSON arrays)
Example:
const char *request = "{\"jsonrpc\":\"2.0\",\"method\":\"hello\",\"id\":1}";
int ret_code;
char *response = mjrpc_process_str(handle, request, &ret_code);
if (response) {
printf("Response: %s\n", response);
free(response);
} else if (ret_code == MJRPC_RET_OK_NOTIFICATION) {
printf("Notification processed\n");
}
char * mjrpc_process_str(mjrpc_handle_t *handle, const char *request_str, int *ret_code)
Process a JSON-RPC request string.
@ MJRPC_RET_OK_NOTIFICATION
Operation completed successfully (notification request)
Definition mjsonrpc.h:90