| 626 | } |
| 627 | |
| 628 | static int mi_http_write_resp(char** p, char *buf, int max_page_len, |
| 629 | mi_response_t *resp) |
| 630 | { |
| 631 | mi_item_t *res; |
| 632 | str unesc_buf; |
| 633 | str tmp_s; |
| 634 | int tmp_i; |
| 635 | |
| 636 | res = cJSON_GetObjectItem(resp, JSONRPC_ERROR_S); |
| 637 | if (!res) |
| 638 | res = cJSON_GetObjectItem(resp, JSONRPC_RESULT_S); |
| 639 | if (!res) { |
| 640 | LM_ERR("Invalid jsonrpc response object\n"); |
| 641 | return -1; |
| 642 | } |
| 643 | |
| 644 | unesc_buf.s = cJSON_Print(res); |
| 645 | if (!unesc_buf.s) { |
| 646 | LM_ERR("Failed to print json response\n"); |
| 647 | return -1; |
| 648 | } |
| 649 | unesc_buf.len = strlen(unesc_buf.s); |
| 650 | |
| 651 | MI_HTTP_ESC_COPY(*p, unesc_buf, tmp_s, tmp_i); |
| 652 | |
| 653 | cJSON_PurgeString(unesc_buf.s); |
| 654 | |
| 655 | return 0; |
| 656 | |
| 657 | error: |
| 658 | LM_ERR("buffer 2 small\n"); |
| 659 | return -1; |
| 660 | } |
| 661 | |
| 662 | int mi_http_build_content(str *page, int max_page_len, |
| 663 | int mod, int cmd, mi_response_t *response) |
no test coverage detected