void ajv_free_node_state( const orderly_alloc_funcs * alloc, ajv_node_state *node) { if (node && *node) { orderly_ps_free(alloc, (*node)->seen); orderly_ps_free(alloc, (*node)->required); OR_FREE(alloc,*node); *node = NULL; } }
void ajv_free(ajv_handle hand) { const orderly_alloc_funcs *AF = hand->AF; ajv_node_state cur; ajv_clear_error(hand); orderly_free_node(hand->AF,(orderly_node **)&(hand->any.node)); while (orderly_ps_length(hand->node_state)) { cur = orderly_ps_current(hand->node_state); ajv_free_node_state(hand->AF,&cur); orderly_ps_pop(hand->node_state); } orderly_ps_free(hand->AF,hand->node_state); orderly_free_node(hand->AF,(orderly_node **)&(hand->any.node)); yajl_free(hand->yajl); OR_FREE(AF,hand); }
orderly_json * orderly_read_json(orderly_alloc_funcs * alloc, const char * jsonText, unsigned int * len) { static yajl_callbacks callbacks = { o_json_parse_null, o_json_parse_boolean, o_json_parse_integer, o_json_parse_double, NULL, o_json_parse_string, o_json_parse_start_map, o_json_parse_map_key, o_json_parse_end_map, o_json_parse_start_array, o_json_parse_end_array }; yajl_handle hand; yajl_status stat; /* allow comments! */ yajl_parser_config cfg = { 1, 1 }; o_json_parse_context pc; orderly_json * j = NULL; memset((void *) &pc, 0, sizeof(pc)); pc.alloc = alloc; /* allocate a parser */ hand = yajl_alloc(&callbacks, &cfg, (const yajl_alloc_funcs *) alloc, (void *) &pc); /* read file data, pass to parser */ stat = yajl_parse(hand, (const unsigned char *) jsonText, *len); *len = yajl_get_bytes_consumed(hand); if (stat == yajl_status_insufficient_data) { stat = yajl_parse_complete(hand); } if (stat != yajl_status_ok) { /* unsigned char * str = yajl_get_error(hand, 1, (const unsigned char *) jsonText, *len); */ /* fprintf(stderr, (const char *) str); */ /* yajl_free_error(hand, str); */ } else if (!orderly_ps_length(pc.nodeStack)) { /* XXX: ERROR! */ } else { /* we're ok! */ j = orderly_ps_current(pc.nodeStack); } yajl_free(hand); orderly_ps_free(alloc, pc.nodeStack); orderly_ps_free(alloc, pc.keyStack); return j; }