| 1115 | } |
| 1116 | |
| 1117 | static 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 | |
| 1158 | CJSON_PUBLIC(void) |
| 1159 | cJSONUtils_AddPatchToArray(cJSON *const array, const char *const operation, const char *const path, |
no test coverage detected