libyajl2 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f95518499377e1e83cabf69e6e843cea17165780
4
- data.tar.gz: 200ac16d0e24061e4d2a63609418449745ff7d8b
3
+ metadata.gz: a9aaac355ea45375884e78ae8dfc3f69870c0b31
4
+ data.tar.gz: 6ffa830fddd7751e20a87e038890cd367f52fa50
5
5
  SHA512:
6
- metadata.gz: 91707dfd9a946163b1623e4e7dde753df9e8392bca99d928f1c64c39efca85a2f019522aad9edb8798bf5c44d71a8d79d2817641c2a605e7c3023cba500c9a24
7
- data.tar.gz: 4f52966b3599eb377b018f10a59c61e49a8f753998959ba944b02e22b9250d5cfe33dfa3debef5032248f8cf6350305b5a01ff8892c16c60a47c6d12e274a292
6
+ metadata.gz: 6e642db48bf78b1c4085e8b71344dbbd51a22345be128b037d4bcb055738b958e4ed3ddf28d75d4ea4d15b49cbfab8be5d14a50669548052fceddba190763cca
7
+ data.tar.gz: cea43bd5d95bc27453978d973db3b86b78eec5ad1f5ca15e055834d4bd5605da8aa02d4265048e53fdd8ef2a83fe6944faa6447754a4b7579a4ba347ef44a97d
data/Rakefile CHANGED
@@ -29,27 +29,82 @@ end
29
29
  # sh %{gem uninstall #{GEM_NAME} -x -v #{Libyajl2::VERSION} }
30
30
  #end
31
31
  #
32
- #desc "compile native gem"
33
32
  #task :compile do
34
- # cd "ext/libyajl2"
33
+ # cp "ext/libyajl2"
35
34
  # ruby "extconf.rb"
36
35
  #end
37
- #
38
- #desc "clean the git repo"
39
- #task :clean do
40
- # sh "git clean -fdx"
41
- # cd "ext/libyajl2/vendor/yajl"
42
- # sh "git clean -fdx"
43
- #end
36
+
37
+ desc "clean the git repo"
38
+ task :clean do
39
+ sh "git clean -fdx"
40
+ cd "ext/libyajl2/vendor/yajl"
41
+ sh "git clean -fdx"
42
+ end
44
43
 
45
44
  Rake::ExtensionTask.new('libyajl', gemspec) do |ext|
46
45
  ext.lib_dir = 'lib/libyajl2/vendored-libyajl2/lib'
47
46
  ext.ext_dir = 'ext/libyajl2'
48
47
  end
49
48
 
49
+ # hack to generate yajl_version.h without using cmake
50
+ def generate_yajl_version
51
+ build_path = File.expand_path("../ext/libyajl2", __FILE__)
52
+ vendor_path = File.expand_path("../ext/libyajl2/vendor/yajl", __FILE__)
53
+
54
+ yajl_major = yajl_minor = yajl_micro = nil
55
+ File.open("#{vendor_path}/CMakeLists.txt").each do |line|
56
+ if m = line.match(/YAJL_MAJOR (\d+)/)
57
+ yajl_major = m[1]
58
+ end
59
+ if m = line.match(/YAJL_MINOR (\d+)/)
60
+ yajl_minor = m[1]
61
+ end
62
+ if m = line.match(/YAJL_MICRO (\d+)/)
63
+ yajl_micro = m[1]
64
+ end
65
+ end
66
+ File.open("#{build_path}/api/yajl_version.h", "w+") do |out| # FIXME: relative path
67
+ File.open("#{vendor_path}/src/api/yajl_version.h.cmake").each do |line|
68
+ line.gsub!(/\$\{YAJL_MAJOR\}/, yajl_major)
69
+ line.gsub!(/\$\{YAJL_MINOR\}/, yajl_minor)
70
+ line.gsub!(/\$\{YAJL_MICRO\}/, yajl_micro)
71
+ out.write(line)
72
+ end
73
+ end
74
+ FileUtils.cp "#{build_path}/api/yajl_version.h", "#{build_path}/yajl/yajl_version.h"
75
+ end
76
+
77
+ desc "Prep and patch yajl sources"
78
+ task :prep do
79
+ build_path = File.expand_path("../ext/libyajl2", __FILE__)
80
+ vendor_src_path = File.expand_path("../ext/libyajl2/vendor/yajl/src", __FILE__)
81
+
82
+ # copy yajl files into build position
83
+ FileUtils.cp Dir["#{vendor_src_path}/*.c"], build_path
84
+ FileUtils.cp Dir["#{vendor_src_path}/*.h"], build_path
85
+
86
+ # the *.c files need api/yajl_foo.h headers
87
+ Dir.mkdir "#{build_path}/api" unless Dir.exist?("#{build_path}/api")
88
+ FileUtils.cp Dir["#{vendor_src_path}/api/*.h"], "#{build_path}/api"
89
+
90
+ # the header files need yajl/yajl_foo.h headers (and windows symlinks
91
+ # are a bit of a PITA so just copy them all)
92
+ Dir.mkdir "#{build_path}/yajl" unless Dir.exist?("#{build_path}/yajl")
93
+ FileUtils.cp Dir["#{vendor_src_path}/api/*.h"], "#{build_path}/yajl"
94
+
95
+ # apply patches that haven't yet been pushed upstream
96
+ Dir["#{build_path}/patches/*"].sort.each do |file|
97
+ Dir.chdir build_path
98
+ sh "patch -p2 < #{file}"
99
+ end
100
+
101
+ # generate the yajl_version.h header file without invoking cmake
102
+ generate_yajl_version
103
+ end
104
+
50
105
  # FIXME: need a rake task to update the git submodule and need to do that before shipping
51
106
  desc "Build it and ship it"
52
- task :ship => [:clean, :gem] do
107
+ task :ship => [:clean, :prep, :gem] do
53
108
  sh("git tag #{Libyajl2::VERSION}")
54
109
  sh("git push --tags")
55
110
  Dir[File.expand_path("../pkg/*.gem", __FILE__)].reverse.each do |built_gem|
@@ -0,0 +1,75 @@
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_COMMON_H__
18
+ #define __YAJL_COMMON_H__
19
+
20
+ #include <stddef.h>
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ #define YAJL_MAX_DEPTH 128
27
+
28
+ /* msft dll export gunk. To build a DLL on windows, you
29
+ * must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared
30
+ * DLL, you must define YAJL_SHARED and WIN32 */
31
+ #if (defined(_WIN32) || defined(WIN32)) && defined(YAJL_SHARED)
32
+ # ifdef YAJL_BUILD
33
+ # define YAJL_API __declspec(dllexport)
34
+ # else
35
+ # define YAJL_API __declspec(dllimport)
36
+ # endif
37
+ #else
38
+ # if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
39
+ # define YAJL_API __attribute__ ((visibility("default")))
40
+ # else
41
+ # define YAJL_API
42
+ # endif
43
+ #endif
44
+
45
+ /** pointer to a malloc function, supporting client overriding memory
46
+ * allocation routines */
47
+ typedef void * (*yajl_malloc_func)(void *ctx, size_t sz);
48
+
49
+ /** pointer to a free function, supporting client overriding memory
50
+ * allocation routines */
51
+ typedef void (*yajl_free_func)(void *ctx, void * ptr);
52
+
53
+ /** pointer to a realloc function which can resize an allocation. */
54
+ typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, size_t sz);
55
+
56
+ /** A structure which can be passed to yajl_*_alloc routines to allow the
57
+ * client to specify memory allocation functions to be used. */
58
+ typedef struct
59
+ {
60
+ /** pointer to a function that can allocate uninitialized memory */
61
+ yajl_malloc_func malloc;
62
+ /** pointer to a function that can resize memory allocations */
63
+ yajl_realloc_func realloc;
64
+ /** pointer to a function that can free memory allocated using
65
+ * reallocFunction or mallocFunction */
66
+ yajl_free_func free;
67
+ /** a context pointer that will be passed to above allocation routines */
68
+ void * ctx;
69
+ } yajl_alloc_funcs;
70
+
71
+ #ifdef __cplusplus
72
+ }
73
+ #endif
74
+
75
+ #endif
@@ -0,0 +1,167 @@
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
+ /**
18
+ * \file yajl_gen.h
19
+ * Interface to YAJL's JSON generation facilities.
20
+ */
21
+
22
+ #include <yajl/yajl_common.h>
23
+
24
+ #ifndef __YAJL_GEN_H__
25
+ #define __YAJL_GEN_H__
26
+
27
+ #include <stddef.h>
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif
32
+ /** generator status codes */
33
+ typedef enum {
34
+ /** no error */
35
+ yajl_gen_status_ok = 0,
36
+ /** at a point where a map key is generated, a function other than
37
+ * yajl_gen_string was called */
38
+ yajl_gen_keys_must_be_strings,
39
+ /** YAJL's maximum generation depth was exceeded. see
40
+ * YAJL_MAX_DEPTH */
41
+ yajl_max_depth_exceeded,
42
+ /** A generator function (yajl_gen_XXX) was called while in an error
43
+ * state */
44
+ yajl_gen_in_error_state,
45
+ /** A complete JSON document has been generated */
46
+ yajl_gen_generation_complete,
47
+ /** yajl_gen_double was passed an invalid floating point value
48
+ * (infinity or NaN). */
49
+ yajl_gen_invalid_number,
50
+ /** A print callback was passed in, so there is no internal
51
+ * buffer to get from */
52
+ yajl_gen_no_buf,
53
+ /** returned from yajl_gen_string() when the yajl_gen_validate_utf8
54
+ * option is enabled and an invalid was passed by client code.
55
+ */
56
+ yajl_gen_invalid_string
57
+ } yajl_gen_status;
58
+
59
+ /** an opaque handle to a generator */
60
+ typedef struct yajl_gen_t * yajl_gen;
61
+
62
+ /** a callback used for "printing" the results. */
63
+ typedef void (*yajl_print_t)(void * ctx,
64
+ const char * str,
65
+ size_t len);
66
+
67
+ /** configuration parameters for the parser, these may be passed to
68
+ * yajl_gen_config() along with option specific argument(s). In general,
69
+ * all configuration parameters default to *off*. */
70
+ typedef enum {
71
+ /** generate indented (beautiful) output */
72
+ yajl_gen_beautify = 0x01,
73
+ /**
74
+ * Set an indent string which is used when yajl_gen_beautify
75
+ * is enabled. Maybe something like \\t or some number of
76
+ * spaces. The default is four spaces ' '.
77
+ */
78
+ yajl_gen_indent_string = 0x02,
79
+ /**
80
+ * Set a function and context argument that should be used to
81
+ * output generated json. the function should conform to the
82
+ * yajl_print_t prototype while the context argument is a
83
+ * void * of your choosing.
84
+ *
85
+ * example:
86
+ * yajl_gen_config(g, yajl_gen_print_callback, myFunc, myVoidPtr);
87
+ */
88
+ yajl_gen_print_callback = 0x04,
89
+ /**
90
+ * Normally the generator does not validate that strings you
91
+ * pass to it via yajl_gen_string() are valid UTF8. Enabling
92
+ * this option will cause it to do so.
93
+ */
94
+ yajl_gen_validate_utf8 = 0x08,
95
+ /**
96
+ * the forward solidus (slash or '/' in human) is not required to be
97
+ * escaped in json text. By default, YAJL will not escape it in the
98
+ * iterest of saving bytes. Setting this flag will cause YAJL to
99
+ * always escape '/' in generated JSON strings.
100
+ */
101
+ yajl_gen_escape_solidus = 0x10
102
+ } yajl_gen_option;
103
+
104
+ /** allow the modification of generator options subsequent to handle
105
+ * allocation (via yajl_alloc)
106
+ * \returns zero in case of errors, non-zero otherwise
107
+ */
108
+ YAJL_API int yajl_gen_config(yajl_gen g, yajl_gen_option opt, ...);
109
+
110
+ /** allocate a generator handle
111
+ * \param allocFuncs an optional pointer to a structure which allows
112
+ * the client to overide the memory allocation
113
+ * used by yajl. May be NULL, in which case
114
+ * malloc/free/realloc will be used.
115
+ *
116
+ * \returns an allocated handle on success, NULL on failure (bad params)
117
+ */
118
+ YAJL_API yajl_gen yajl_gen_alloc(const yajl_alloc_funcs * allocFuncs);
119
+
120
+ /** free a generator handle */
121
+ YAJL_API void yajl_gen_free(yajl_gen handle);
122
+
123
+ YAJL_API yajl_gen_status yajl_gen_integer(yajl_gen hand, long long int number);
124
+ /** generate a floating point number. number may not be infinity or
125
+ * NaN, as these have no representation in JSON. In these cases the
126
+ * generator will return 'yajl_gen_invalid_number' */
127
+ YAJL_API yajl_gen_status yajl_gen_double(yajl_gen hand, double number);
128
+ YAJL_API yajl_gen_status yajl_gen_number(yajl_gen hand,
129
+ const char * num,
130
+ size_t len);
131
+ YAJL_API yajl_gen_status yajl_gen_string(yajl_gen hand,
132
+ const unsigned char * str,
133
+ size_t len);
134
+ YAJL_API yajl_gen_status yajl_gen_null(yajl_gen hand);
135
+ YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean);
136
+ YAJL_API yajl_gen_status yajl_gen_map_open(yajl_gen hand);
137
+ YAJL_API yajl_gen_status yajl_gen_map_close(yajl_gen hand);
138
+ YAJL_API yajl_gen_status yajl_gen_array_open(yajl_gen hand);
139
+ YAJL_API yajl_gen_status yajl_gen_array_close(yajl_gen hand);
140
+
141
+ /** access the null terminated generator buffer. If incrementally
142
+ * outputing JSON, one should call yajl_gen_clear to clear the
143
+ * buffer. This allows stream generation. */
144
+ YAJL_API yajl_gen_status yajl_gen_get_buf(yajl_gen hand,
145
+ const unsigned char ** buf,
146
+ size_t * len);
147
+
148
+ /** clear yajl's output buffer, but maintain all internal generation
149
+ * state. This function will not "reset" the generator state, and is
150
+ * intended to enable incremental JSON outputing. */
151
+ YAJL_API void yajl_gen_clear(yajl_gen hand);
152
+
153
+ /** Reset the generator state. Allows a client to generate multiple
154
+ * json entities in a stream. The "sep" string will be inserted to
155
+ * separate the previously generated entity from the current,
156
+ * NULL means *no separation* of entites (clients beware, generating
157
+ * multiple JSON numbers without a separator, for instance, will result in ambiguous output)
158
+ *
159
+ * Note: this call will not clear yajl's output buffer. This
160
+ * may be accomplished explicitly by calling yajl_gen_clear() */
161
+ YAJL_API void yajl_gen_reset(yajl_gen hand, const char * sep);
162
+
163
+ #ifdef __cplusplus
164
+ }
165
+ #endif
166
+
167
+ #endif
@@ -0,0 +1,226 @@
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
+ /**
18
+ * \file yajl_parse.h
19
+ * Interface to YAJL's JSON stream parsing facilities.
20
+ */
21
+
22
+ #include <yajl/yajl_common.h>
23
+
24
+ #ifndef __YAJL_PARSE_H__
25
+ #define __YAJL_PARSE_H__
26
+
27
+ #include <stddef.h>
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif
32
+ /** error codes returned from this interface */
33
+ typedef enum {
34
+ /** no error was encountered */
35
+ yajl_status_ok,
36
+ /** a client callback returned zero, stopping the parse */
37
+ yajl_status_client_canceled,
38
+ /** An error occured during the parse. Call yajl_get_error for
39
+ * more information about the encountered error */
40
+ yajl_status_error
41
+ } yajl_status;
42
+
43
+ /** attain a human readable, english, string for an error */
44
+ YAJL_API const char * yajl_status_to_string(yajl_status code);
45
+
46
+ /** an opaque handle to a parser */
47
+ typedef struct yajl_handle_t * yajl_handle;
48
+
49
+ /** yajl is an event driven parser. this means as json elements are
50
+ * parsed, you are called back to do something with the data. The
51
+ * functions in this table indicate the various events for which
52
+ * you will be called back. Each callback accepts a "context"
53
+ * pointer, this is a void * that is passed into the yajl_parse
54
+ * function which the client code may use to pass around context.
55
+ *
56
+ * All callbacks return an integer. If non-zero, the parse will
57
+ * continue. If zero, the parse will be canceled and
58
+ * yajl_status_client_canceled will be returned from the parse.
59
+ *
60
+ * \attention {
61
+ * A note about the handling of numbers:
62
+ *
63
+ * yajl will only convert numbers that can be represented in a
64
+ * double or a 64 bit (long long) int. All other numbers will
65
+ * be passed to the client in string form using the yajl_number
66
+ * callback. Furthermore, if yajl_number is not NULL, it will
67
+ * always be used to return numbers, that is yajl_integer and
68
+ * yajl_double will be ignored. If yajl_number is NULL but one
69
+ * of yajl_integer or yajl_double are defined, parsing of a
70
+ * number larger than is representable in a double or 64 bit
71
+ * integer will result in a parse error.
72
+ * }
73
+ */
74
+ typedef struct {
75
+ int (* yajl_null)(void * ctx);
76
+ int (* yajl_boolean)(void * ctx, int boolVal);
77
+ int (* yajl_integer)(void * ctx, long long integerVal);
78
+ int (* yajl_double)(void * ctx, double doubleVal);
79
+ /** A callback which passes the string representation of the number
80
+ * back to the client. Will be used for all numbers when present */
81
+ int (* yajl_number)(void * ctx, const char * numberVal,
82
+ size_t numberLen);
83
+
84
+ /** strings are returned as pointers into the JSON text when,
85
+ * possible, as a result, they are _not_ null padded */
86
+ int (* yajl_string)(void * ctx, const unsigned char * stringVal,
87
+ size_t stringLen);
88
+
89
+ int (* yajl_start_map)(void * ctx);
90
+ int (* yajl_map_key)(void * ctx, const unsigned char * key,
91
+ size_t stringLen);
92
+ int (* yajl_end_map)(void * ctx);
93
+
94
+ int (* yajl_start_array)(void * ctx);
95
+ int (* yajl_end_array)(void * ctx);
96
+ } yajl_callbacks;
97
+
98
+ /** allocate a parser handle
99
+ * \param callbacks a yajl callbacks structure specifying the
100
+ * functions to call when different JSON entities
101
+ * are encountered in the input text. May be NULL,
102
+ * which is only useful for validation.
103
+ * \param afs memory allocation functions, may be NULL for to use
104
+ * C runtime library routines (malloc and friends)
105
+ * \param ctx a context pointer that will be passed to callbacks.
106
+ */
107
+ YAJL_API yajl_handle yajl_alloc(const yajl_callbacks * callbacks,
108
+ yajl_alloc_funcs * afs,
109
+ void * ctx);
110
+
111
+
112
+ /** configuration parameters for the parser, these may be passed to
113
+ * yajl_config() along with option specific argument(s). In general,
114
+ * all configuration parameters default to *off*. */
115
+ typedef enum {
116
+ /** Ignore javascript style comments present in
117
+ * JSON input. Non-standard, but rather fun
118
+ * arguments: toggled off with integer zero, on otherwise.
119
+ *
120
+ * example:
121
+ * yajl_config(h, yajl_allow_comments, 1); // turn comment support on
122
+ */
123
+ yajl_allow_comments = 0x01,
124
+ /**
125
+ * When set the parser will verify that all strings in JSON input are
126
+ * valid UTF8 and will emit a parse error if this is not so. When set,
127
+ * this option makes parsing slightly more expensive (~7% depending
128
+ * on processor and compiler in use)
129
+ *
130
+ * example:
131
+ * yajl_config(h, yajl_dont_validate_strings, 1); // disable utf8 checking
132
+ */
133
+ yajl_dont_validate_strings = 0x02,
134
+ /**
135
+ * By default, upon calls to yajl_complete_parse(), yajl will
136
+ * ensure the entire input text was consumed and will raise an error
137
+ * otherwise. Enabling this flag will cause yajl to disable this
138
+ * check. This can be useful when parsing json out of a that contains more
139
+ * than a single JSON document.
140
+ */
141
+ yajl_allow_trailing_garbage = 0x04,
142
+ /**
143
+ * Allow multiple values to be parsed by a single handle. The
144
+ * entire text must be valid JSON, and values can be seperated
145
+ * by any kind of whitespace. This flag will change the
146
+ * behavior of the parser, and cause it continue parsing after
147
+ * a value is parsed, rather than transitioning into a
148
+ * complete state. This option can be useful when parsing multiple
149
+ * values from an input stream.
150
+ */
151
+ yajl_allow_multiple_values = 0x08,
152
+ /**
153
+ * When yajl_complete_parse() is called the parser will
154
+ * check that the top level value was completely consumed. I.E.,
155
+ * if called whilst in the middle of parsing a value
156
+ * yajl will enter an error state (premature EOF). Setting this
157
+ * flag suppresses that check and the corresponding error.
158
+ */
159
+ yajl_allow_partial_values = 0x10
160
+ } yajl_option;
161
+
162
+ /** allow the modification of parser options subsequent to handle
163
+ * allocation (via yajl_alloc)
164
+ * \returns zero in case of errors, non-zero otherwise
165
+ */
166
+ YAJL_API int yajl_config(yajl_handle h, yajl_option opt, ...);
167
+
168
+ /** free a parser handle */
169
+ YAJL_API void yajl_free(yajl_handle handle);
170
+
171
+ /** Parse some json!
172
+ * \param hand - a handle to the json parser allocated with yajl_alloc
173
+ * \param jsonText - a pointer to the UTF8 json text to be parsed
174
+ * \param jsonTextLength - the length, in bytes, of input text
175
+ */
176
+ YAJL_API yajl_status yajl_parse(yajl_handle hand,
177
+ const unsigned char * jsonText,
178
+ size_t jsonTextLength);
179
+
180
+ /** Parse any remaining buffered json.
181
+ * Since yajl is a stream-based parser, without an explicit end of
182
+ * input, yajl sometimes can't decide if content at the end of the
183
+ * stream is valid or not. For example, if "1" has been fed in,
184
+ * yajl can't know whether another digit is next or some character
185
+ * that would terminate the integer token.
186
+ *
187
+ * \param hand - a handle to the json parser allocated with yajl_alloc
188
+ */
189
+ YAJL_API yajl_status yajl_complete_parse(yajl_handle hand);
190
+
191
+ /** get an error string describing the state of the
192
+ * parse.
193
+ *
194
+ * If verbose is non-zero, the message will include the JSON
195
+ * text where the error occured, along with an arrow pointing to
196
+ * the specific char.
197
+ *
198
+ * \returns A dynamically allocated string will be returned which should
199
+ * be freed with yajl_free_error
200
+ */
201
+ YAJL_API unsigned char * yajl_get_error(yajl_handle hand, int verbose,
202
+ const unsigned char * jsonText,
203
+ size_t jsonTextLength);
204
+
205
+ /**
206
+ * get the amount of data consumed from the last chunk passed to YAJL.
207
+ *
208
+ * In the case of a successful parse this can help you understand if
209
+ * the entire buffer was consumed (which will allow you to handle
210
+ * "junk at end of input").
211
+ *
212
+ * In the event an error is encountered during parsing, this function
213
+ * affords the client a way to get the offset into the most recent
214
+ * chunk where the error occured. 0 will be returned if no error
215
+ * was encountered.
216
+ */
217
+ YAJL_API size_t yajl_get_bytes_consumed(yajl_handle hand);
218
+
219
+ /** free an error returned from yajl_get_error */
220
+ YAJL_API void yajl_free_error(yajl_handle hand, unsigned char * str);
221
+
222
+ #ifdef __cplusplus
223
+ }
224
+ #endif
225
+
226
+ #endif