MCPcopy Create free account
hub / github.com/Netis/cloud-probe / compose_patch

Function compose_patch

cpworker/src/cJSON/cJSON_Utils.c:1117–1156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1115}
1116
1117static void compose_patch(cJSON *const patches, const unsigned char *const operation, const unsigned char *const path,
1118 const unsigned char *suffix, const cJSON *const value)
1119{
1120 cJSON *patch = NULL;
1121
1122 if ((patches == NULL) || (operation == NULL) || (path == NULL))
1123 {
1124 return;
1125 }
1126
1127 patch = cJSON_CreateObject();
1128 if (patch == NULL)
1129 {
1130 return;
1131 }
1132 cJSON_AddItemToObject(patch, "op", cJSON_CreateString((const char *)operation));
1133
1134 if (suffix == NULL)
1135 {
1136 cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char *)path));
1137 }
1138 else
1139 {
1140 size_t suffix_length = pointer_encoded_length(suffix);
1141 size_t path_length = strlen((const char *)path);
1142 unsigned char *full_path = (unsigned char *)cJSON_malloc(path_length + suffix_length + sizeof("/"));
1143
1144 sprintf((char *)full_path, "%s/", (const char *)path);
1145 encode_string_as_pointer(full_path + path_length + 1, suffix);
1146
1147 cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char *)full_path));
1148 cJSON_free(full_path);
1149 }
1150
1151 if (value != NULL)
1152 {
1153 cJSON_AddItemToObject(patch, "value", cJSON_Duplicate(value, 1));
1154 }
1155 cJSON_AddItemToArray(patches, patch);
1156}
1157
1158CJSON_PUBLIC(void)
1159cJSONUtils_AddPatchToArray(cJSON *const array, const char *const operation, const char *const path,

Callers 2

create_patchesFunction · 0.85

Calls 9

cJSON_CreateObjectFunction · 0.85
cJSON_AddItemToObjectFunction · 0.85
cJSON_CreateStringFunction · 0.85
pointer_encoded_lengthFunction · 0.85
cJSON_mallocFunction · 0.85
encode_string_as_pointerFunction · 0.85
cJSON_freeFunction · 0.85
cJSON_DuplicateFunction · 0.85
cJSON_AddItemToArrayFunction · 0.85

Tested by

no test coverage detected