MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / parse_mi_request

Function parse_mi_request

mi/mi.c:645–689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

643}
644
645int parse_mi_request(const char *req, const char **end_ptr, mi_request_t *parsed)
646{
647 mi_item_t *req_jsonrpc;
648
649 _init_mi_sys_mem_hooks();
650
651 parsed->req_obj = cJSON_ParseWithOpts(req, end_ptr, 0);
652 if (!parsed->req_obj) {
653 _init_mi_pkg_mem_hooks();
654 return -1;
655 }
656
657 /* check if the request is a valid JSON-RPC Request object */
658 /* get request id (if absent -> notification) */
659 parsed->id = cJSON_GetObjectItem(parsed->req_obj, JSONRPC_ID_S);
660 if (parsed->id && !(parsed->id->type & (cJSON_NULL|cJSON_Number|cJSON_String)))
661 parsed->invalid = 1;
662
663 /* check 'jsonrpc' member */
664 req_jsonrpc = cJSON_GetObjectItem(parsed->req_obj, JSONRPC_S);
665 if (!req_jsonrpc || !(req_jsonrpc->type & cJSON_String) ||
666 strcmp(req_jsonrpc->valuestring, JSONRPC_VERS_S))
667 parsed->invalid = 1;
668
669 /* check 'method' member */
670 parsed->method = cJSON_GetObjectItem(parsed->req_obj, JSONRPC_METHOD_S);
671 if (!parsed->method || !(parsed->method->type & cJSON_String)) {
672 parsed->method = NULL;
673 parsed->invalid = 1;
674 }
675
676 /* check 'params' member */
677 parsed->params = cJSON_GetObjectItem(parsed->req_obj, JSONRPC_PARAMS_S);
678 if (parsed->params) {
679 if (!(parsed->params->type & (cJSON_Array|cJSON_Object)))
680 parsed->invalid = 1;
681 else if (!parsed->params->child) {
682 parsed->params = NULL;
683 }
684 }
685
686 _init_mi_pkg_mem_hooks();
687
688 return 0;
689}
690
691char *mi_get_req_method(mi_request_t *req)
692{

Callers 3

mi_fifo_callbackFunction · 0.85
mi_datagram_callbackFunction · 0.85

Calls 4

_init_mi_sys_mem_hooksFunction · 0.85
cJSON_ParseWithOptsFunction · 0.85
_init_mi_pkg_mem_hooksFunction · 0.85
cJSON_GetObjectItemFunction · 0.50

Tested by

no test coverage detected