| 633 | } while(0) |
| 634 | |
| 635 | int process_extra_prometheus_entry(cJSON *obj,str *page, int max_len) |
| 636 | { |
| 637 | cJSON *header,*values,*value, *name, *counter; |
| 638 | str val, cval; |
| 639 | int c; |
| 640 | |
| 641 | if (!obj) |
| 642 | return -1; |
| 643 | |
| 644 | if (obj->type != cJSON_Object) { |
| 645 | LM_ERR("Expecting a JSON object in the array but got %d \n",obj->type); |
| 646 | return -1; |
| 647 | } |
| 648 | |
| 649 | header = cJSON_GetObjectItem(obj, "header"); |
| 650 | values = cJSON_GetObjectItem(obj, "values"); |
| 651 | |
| 652 | if (!header || header->type != cJSON_String) { |
| 653 | LM_ERR("Invalid header provided \n"); |
| 654 | return -1; |
| 655 | } |
| 656 | |
| 657 | if (!values || values->type != cJSON_Array) { |
| 658 | LM_ERR("Invalid values provided \n"); |
| 659 | return -1; |
| 660 | } |
| 661 | |
| 662 | val.s = header->valuestring; |
| 663 | val.len = strlen(val.s); |
| 664 | |
| 665 | if (!val.len) { |
| 666 | LM_ERR("No header content provided \n"); |
| 667 | return -1; |
| 668 | } |
| 669 | |
| 670 | if (page->len + val.len + 1 >= max_len) { |
| 671 | LM_ERR("No more HTTP buffer space, have %d, need extra %d into max %d\n",page->len,val.len + 1,max_len); |
| 672 | return -1; |
| 673 | } |
| 674 | |
| 675 | memcpy(page->s + page->len,val.s,val.len); |
| 676 | page->len += val.len; |
| 677 | |
| 678 | memcpy(page->s + page->len, "\n", 1); |
| 679 | page->len += 1; |
| 680 | |
| 681 | value = values->child; |
| 682 | while (value) { |
| 683 | if (value->type != cJSON_Object) { |
| 684 | LM_ERR("Expected value object and found type %d\n",value->type); |
| 685 | goto next_value; |
| 686 | } |
| 687 | |
| 688 | name = cJSON_GetObjectItem(value, "name"); |
| 689 | if (!name || name->type != cJSON_String) { |
| 690 | LM_ERR("Stat name not found \n"); |
| 691 | goto next_value; |
| 692 | } |
no test coverage detected