| 727 | } |
| 728 | |
| 729 | int process_extra_prometheus(char *extra, int len,str *page, int max_len) |
| 730 | { |
| 731 | cJSON *j_obj=NULL,*arr; |
| 732 | char *extra_nt; |
| 733 | |
| 734 | if (!extra || len <= 0) { |
| 735 | return -1; |
| 736 | } |
| 737 | |
| 738 | extra_nt = pkg_malloc(len + 1); |
| 739 | if (!extra_nt) { |
| 740 | LM_ERR("could not allocate null terminated json\n"); |
| 741 | return -1; |
| 742 | } |
| 743 | memcpy(extra_nt, extra, len); |
| 744 | extra_nt[len] = 0; |
| 745 | |
| 746 | j_obj = cJSON_Parse(extra_nt); |
| 747 | if (j_obj == NULL) { |
| 748 | LM_ERR("Failed to parse JSON obj %s\n", extra_nt); |
| 749 | pkg_free(extra_nt); |
| 750 | return -1; |
| 751 | } |
| 752 | pkg_free(extra_nt); |
| 753 | |
| 754 | if (j_obj->type != cJSON_Array) { |
| 755 | LM_ERR("Main JSON object expecting an array \n"); |
| 756 | goto error; |
| 757 | } |
| 758 | |
| 759 | arr = j_obj->child; |
| 760 | while (arr) { |
| 761 | if (process_extra_prometheus_entry(arr,page,max_len) < 0) { |
| 762 | LM_ERR("Failed to process JSON entry \n"); |
| 763 | goto error; |
| 764 | } |
| 765 | |
| 766 | arr=arr->next; |
| 767 | } |
| 768 | error: |
| 769 | cJSON_Delete(j_obj); |
| 770 | |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | |
| 775 | int prom_answer_to_connection (void *cls, void *connection, |
no test coverage detected