| 1094 | } |
| 1095 | |
| 1096 | static void compose_patch(cJSON * const patches, const unsigned char * const operation, const unsigned char * const path, const unsigned char *suffix, const cJSON * const value) |
| 1097 | { |
| 1098 | cJSON *patch = NULL; |
| 1099 | |
| 1100 | if ((patches == NULL) || (operation == NULL) || (path == NULL)) |
| 1101 | { |
| 1102 | return; |
| 1103 | } |
| 1104 | |
| 1105 | patch = cJSON_CreateObject(); |
| 1106 | if (patch == NULL) |
| 1107 | { |
| 1108 | return; |
| 1109 | } |
| 1110 | cJSON_AddItemToObject(patch, "op", cJSON_CreateString((const char*)operation)); |
| 1111 | |
| 1112 | if (suffix == NULL) |
| 1113 | { |
| 1114 | cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)path)); |
| 1115 | } |
| 1116 | else |
| 1117 | { |
| 1118 | size_t suffix_length = pointer_encoded_length(suffix); |
| 1119 | size_t path_length = strlen((const char*)path); |
| 1120 | unsigned char *full_path = (unsigned char*)cJSON_malloc(path_length + suffix_length + sizeof("/")); |
| 1121 | |
| 1122 | sprintf((char*)full_path, "%s/", (const char*)path); |
| 1123 | encode_string_as_pointer(full_path + path_length + 1, suffix); |
| 1124 | |
| 1125 | cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)full_path)); |
| 1126 | cJSON_free(full_path); |
| 1127 | } |
| 1128 | |
| 1129 | if (value != NULL) |
| 1130 | { |
| 1131 | cJSON_AddItemToObject(patch, "value", cJSON_Duplicate(value, 1)); |
| 1132 | } |
| 1133 | cJSON_AddItemToArray(patches, patch); |
| 1134 | } |
| 1135 | |
| 1136 | CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value) |
| 1137 | { |
no test coverage detected
searching dependent graphs…