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

Function detach_path

cpworker/src/cJSON/cJSON_Utils.c:437–489  ·  view source on GitHub ↗

detach an item at the given path */

Source from the content-addressed store, hash-verified

435
436/* detach an item at the given path */
437static cJSON *detach_path(cJSON *object, const unsigned char *path, const cJSON_bool case_sensitive)
438{
439 unsigned char *parent_pointer = NULL;
440 unsigned char *child_pointer = NULL;
441 cJSON *parent = NULL;
442 cJSON *detached_item = NULL;
443
444 /* copy path and split it in parent and child */
445 parent_pointer = cJSONUtils_strdup(path);
446 if (parent_pointer == NULL)
447 {
448 goto cleanup;
449 }
450
451 child_pointer = (unsigned char *)strrchr((char *)parent_pointer, '/'); /* last '/' */
452 if (child_pointer == NULL)
453 {
454 goto cleanup;
455 }
456 /* split strings */
457 child_pointer[0] = '\0';
458 child_pointer++;
459
460 parent = get_item_from_pointer(object, (char *)parent_pointer, case_sensitive);
461 decode_pointer_inplace(child_pointer);
462
463 if (cJSON_IsArray(parent))
464 {
465 size_t index = 0;
466 if (!decode_array_index_from_pointer(child_pointer, &index))
467 {
468 goto cleanup;
469 }
470 detached_item = detach_item_from_array(parent, index);
471 }
472 else if (cJSON_IsObject(parent))
473 {
474 detached_item = cJSON_DetachItemFromObject(parent, (char *)child_pointer);
475 }
476 else
477 {
478 /* Couldn't find object to remove child from. */
479 goto cleanup;
480 }
481
482cleanup:
483 if (parent_pointer != NULL)
484 {
485 cJSON_free(parent_pointer);
486 }
487
488 return detached_item;
489}
490
491/* sort lists using mergesort */
492static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive)

Callers 1

apply_patchFunction · 0.85

Calls 9

cJSONUtils_strdupFunction · 0.85
get_item_from_pointerFunction · 0.85
decode_pointer_inplaceFunction · 0.85
cJSON_IsArrayFunction · 0.85
detach_item_from_arrayFunction · 0.85
cJSON_IsObjectFunction · 0.85
cJSON_freeFunction · 0.85

Tested by

no test coverage detected