Exemplo n.º 1
0
orderly_json_parse_status
orderly_json_parse(orderly_alloc_funcs * alloc,
                   const unsigned char * schemaText,
                   const unsigned int schemaTextLen,
                   const char **error_message,
                   orderly_node ** n,
                   unsigned int * final_offset)
{
    /* a high level interface to non-stream based json parsing */
    orderly_json_parse_status s;
    orderly_json * j;

    *final_offset = schemaTextLen;
    
    j = orderly_read_json(alloc, (const char *) schemaText, final_offset);
    if (j == NULL) return orderly_json_parse_s_invalid_json;
    
    /* we've parsed the json into a memory representation, now let's
     * interpret it's semantic meaning as we merge it over into a
     * orderly_node representation */
    s = parse_json_schema(alloc, j, n);

    (void) orderly_free_json(alloc, &j);
    
    return s;
}
Exemplo n.º 2
0
void
orderly_free_json(orderly_alloc_funcs * alloc, orderly_json ** node)
{
    if (node && *node) {
        if ((*node)->k) OR_FREE(alloc, (void *) (*node)->k);

        if ((*node)->t == orderly_json_string) {
            OR_FREE(alloc, (void *) (*node)->v.s);
        } else if ((*node)->t == orderly_json_array ||
                   (*node)->t == orderly_json_object)
        {
            orderly_free_json(alloc, &((*node)->v.children.first));
        }
        if ((*node)->next) orderly_free_json(alloc, &((*node)->next));
        OR_FREE(alloc, (void *) (*node));        
    }
}