1 | /*
2 | * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
3 | *
4 | * Permission to use, copy, modify, and/or distribute this software for any
5 | * purpose with or without fee is hereby granted, provided that the above
6 | * copyright notice and this permission notice appear in all copies.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 | */
16 |
17 | #ifndef __YAJL_PARSER_H__
18 | #define __YAJL_PARSER_H__
19 |
20 | #include "yajl/yajl_parse.h"
21 | #include "yajl_bytestack.h"
22 | #include "yajl_buf.h"
23 | #include "yajl_lex.h"
24 |
25 |
26 | typedef enum {
27 | yajl_state_start = 0,
28 | yajl_state_parse_complete,
29 | yajl_state_parse_error,
30 | yajl_state_lexical_error,
31 | yajl_state_map_start,
32 | yajl_state_map_sep,
33 | yajl_state_map_need_val,
34 | yajl_state_map_got_val,
35 | yajl_state_map_need_key,
36 | yajl_state_array_start,
37 | yajl_state_array_got_val,
38 | yajl_state_array_need_val,
39 | yajl_state_got_value
40 | } yajl_state;
41 |
42 | struct yajl_handle_t {
43 | const yajl_callbacks * callbacks;
44 | void * ctx;
45 | yajl_lexer lexer;
46 | const char * parseError;
47 | /* the number of bytes consumed from the last client buffer,
48 | * in the case of an error this will be an error offset, in the
49 | * case of an error this can be used as the error offset */
50 | size_t bytesConsumed;
51 | /* temporary storage for decoded strings */
52 | yajl_buf decodeBuf;
53 | /* a stack of states. access with yajl_state_XXX routines */
54 | yajl_bytestack stateStack;
55 | /* memory allocation routines */
56 | yajl_alloc_funcs alloc;
57 | /* half-assed bitfield */
58 | unsigned int flags;
59 | };
60 |
61 | yajl_status
62 | yajl_do_parse(yajl_handle handle, const unsigned char * jsonText,
63 | size_t jsonTextLen);
64 |
65 | yajl_status
66 | yajl_do_finish(yajl_handle handle);
67 |
68 | unsigned char *
69 | yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
70 | size_t jsonTextLen, int verbose);
71 |
72 | /* A little built in integer parsing routine with the same semantics as strtol
73 | * that's unaffected by LOCALE. */
74 | long long
75 | yajl_parse_integer(const unsigned char *number, size_t length);
76 |
77 |
78 | #endif