| 643 | } |
| 644 | |
| 645 | int 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 | |
| 691 | char *mi_get_req_method(mi_request_t *req) |
| 692 | { |
no test coverage detected