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

Function w_merge_json

modules/json/json.c:1090–1145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1088}
1089
1090int w_merge_json(struct sip_msg *msg, str *j1, str* j2, pv_spec_t *res)
1091{
1092 cJSON *in1, *in2, *out;
1093 char *p;
1094 pv_value_t pv_val;
1095
1096 in1 = cJSON_Parse(j1->s);
1097 if (!in1) {
1098 LM_ERR("Failed to parse first param \n");
1099 return -1;
1100 }
1101
1102 in2 = cJSON_Parse(j2->s);
1103 if (!in2) {
1104 LM_ERR("Failed to parse second param \n");
1105 cJSON_Delete(in1);
1106 return -1;
1107 }
1108
1109 out = cJSONUtils_MergePatch(in1,in2);
1110 if (!out) {
1111 LM_ERR("Failed to merge the two jsons \n");
1112 cJSON_Delete(in1);
1113 cJSON_Delete(in2);
1114 return -1;
1115 }
1116
1117 p = cJSON_Print(out);
1118 if (!p) {
1119 LM_ERR("Failed to merge the two jsons \n");
1120 cJSON_Delete(in1);
1121 cJSON_Delete(in2);
1122 return -1;
1123 }
1124
1125 cJSON_Minify(p);
1126
1127 pv_val.flags = PV_VAL_STR;
1128 pv_val.rs.s = p;
1129 pv_val.rs.len = strlen(p);
1130
1131
1132 if (pv_set_value( msg, res, 0, &pv_val) != 0) {
1133 LM_ERR("SET output value failed \n");
1134 pkg_free(p);
1135 cJSON_Delete(in1);
1136 cJSON_Delete(in2);
1137 return -1;
1138 }
1139
1140 pkg_free(p);
1141 cJSON_Delete(in1);
1142 cJSON_Delete(in2);
1143
1144 return 1;
1145}

Callers

nothing calls this directly

Calls 6

cJSONUtils_MergePatchFunction · 0.85
cJSON_MinifyFunction · 0.85
pv_set_valueFunction · 0.85
cJSON_ParseFunction · 0.50
cJSON_DeleteFunction · 0.50
cJSON_PrintFunction · 0.50

Tested by

no test coverage detected