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

Function parse_object

lib/cJSON.c:1412–1512  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

1410
1411/* Build an object from the text. */
1412static const unsigned char *parse_object(cJSON *item, const unsigned char *value, const unsigned char **ep)
1413{
1414 cJSON *child = NULL;
1415 if (*value != '{')
1416 {
1417 /* not an object! */
1418 *ep = value;
1419 goto fail;
1420 }
1421
1422 item->type = cJSON_Object;
1423 value = skip(value + 1);
1424 if (*value == '}')
1425 {
1426 /* empty object. */
1427 return value + 1;
1428 }
1429
1430 child = cJSON_New_Item();
1431 item->child = child;
1432 if (!item->child)
1433 {
1434 goto fail;
1435 }
1436 /* parse first key */
1437 value = skip(parse_string(child, skip(value), ep));
1438 if (!value)
1439 {
1440 goto fail;
1441 }
1442 /* use string as key, not value */
1443 child->string = child->valuestring;
1444 child->valuestring = NULL;
1445
1446 if (*value != ':')
1447 {
1448 /* invalid object. */
1449 *ep = value;
1450 goto fail;
1451 }
1452 /* skip any spacing, get the value. */
1453 value = skip(parse_value(child, skip(value + 1), ep));
1454 if (!value)
1455 {
1456 goto fail;
1457 }
1458
1459 while (*value == ',')
1460 {
1461 cJSON *new_item = NULL;
1462 if (!(new_item = cJSON_New_Item()))
1463 {
1464 /* memory fail */
1465 goto fail;
1466 }
1467 /* add to linked list */
1468 child->next = new_item;
1469 new_item->prev = child;

Callers 1

parse_valueFunction · 0.70

Calls 5

skipFunction · 0.70
cJSON_New_ItemFunction · 0.70
parse_stringFunction · 0.70
parse_valueFunction · 0.70
cJSON_DeleteFunction · 0.70

Tested by

no test coverage detected