ubjsc  0.5
Enterprise-grade C library for manipulating UBJSON
ubjs_parser.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Tomasz Sieprawski
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  **/
31 #ifndef HAVE_UBJS_PARSER
32 #define HAVE_UBJS_PARSER
33 
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38 
39 #include "ubjs_common.h"
40 #include "ubjs_library.h"
41 #include "ubjs_primitives.h"
42 
44 struct ubjs_parser;
45 
47 struct ubjs_parser_context;
48 
51 
53 struct ubjs_parser_error;
54 
56 typedef struct ubjs_parser ubjs_parser;
57 
60 
63 
66 
73 typedef void (*ubjs_parser_context_parsed)(ubjs_parser_context *context, ubjs_prmtv *primitive);
88 
95  unsigned int *plength);
105 
113 {
120 
130 
136  unsigned int limit_string_length;
137 
143  unsigned int limit_recursion_level;
144 
152 };
153 
156 {
158  void *userdata;
159 
162 
165 
168 };
169 
182  ubjs_parser_context *context, ubjs_parser **pthis);
183 
191 UBJS_EXPORT ubjs_result ubjs_parser_free(ubjs_parser **pthis);
192 
200 
208  ubjs_parser_settings **psettings);
209 
226 UBJS_EXPORT ubjs_result ubjs_parser_parse(ubjs_parser *this, uint8_t *data, unsigned int len);
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif
Library handle, allocation callbacks, glues.
ubjs_parser_context_error error
Definition: ubjs_parser.h:164
Definitions of common types, ubjson markers and some utilities.
struct ubjs_prmtv ubjs_prmtv
Definition: ubjs_primitives.h:166
UBJS_EXPORT ubjs_result ubjs_parser_new(ubjs_library *lib, ubjs_parser_settings *settings, ubjs_parser_context *context, ubjs_parser **pthis)
Creates new parser.
Definition: ubjs_parser.c:115
void(* ubjs_parser_context_error)(ubjs_parser_context *context, ubjs_parser_error *error)
Callback when encountered a parsing error.
Definition: ubjs_parser.h:81
void * userdata
Definition: ubjs_parser.h:158
struct ubjs_parser_error ubjs_parser_error
Holder for parser errors.
Definition: ubjs_parser.h:65
UBJS_EXPORT ubjs_result ubjs_parser_get_settings(ubjs_parser *this, ubjs_parser_settings **psettings)
Gets settings from the parser.
Definition: ubjs_parser.c:397
UBJS_EXPORT ubjs_result ubjs_parser_get_context(ubjs_parser *this, ubjs_parser_context **pcontext)
Gets user context from the parser.
Definition: ubjs_parser.c:386
Library handle.
Definition: ubjs_library.h:827
unsigned int limit_bytes_since_last_callback
Max number of bytes to process since last callback. If this is 0, limit is effectively off...
Definition: ubjs_parser.h:119
ubjs_bool debug
Debugging mode. If this is UTRUE, parser will fprintf(stderr) lots of internal messages about how and...
Definition: ubjs_parser.h:151
ubjs_bool
Wrapper around regular C-like booleans.
Definition: ubjs_common.h:59
Wrappers over ubjson primitive types.
UBJS_EXPORT ubjs_result ubjs_parser_free(ubjs_parser **pthis)
Frees the parser.
Definition: ubjs_parser.c:340
UBJS_EXPORT ubjs_result ubjs_parser_parse(ubjs_parser *this, uint8_t *data, unsigned int len)
Parses the incoming data.
Definition: ubjs_parser.c:408
struct ubjs_parser ubjs_parser
Parser itself.
Definition: ubjs_parser.h:56
void(* ubjs_parser_context_free)(ubjs_parser_context *)
Callback when parser is about to be free-d.
Definition: ubjs_parser.h:87
unsigned int limit_string_length
Max number of characters in string or HPN. If this is 0, limit is effectively off. Else parser errors when expected length exceeds the limit. This setting is global to whole parser.
Definition: ubjs_parser.h:136
ubjs_result
Enum that defines the result of a method.
Definition: ubjs_common.h:73
void(* ubjs_parser_context_parsed)(ubjs_parser_context *context, ubjs_prmtv *primitive)
Callback to be executed just when parser parsed a first-citizen primitive.
Definition: ubjs_parser.h:73
ubjs_parser_context_parsed parsed
Definition: ubjs_parser.h:161
unsigned int limit_container_length
Max number of items in container. This applies to arrays and objects. If this is 0, limit is effectively off. Else parser errors when:
Definition: ubjs_parser.h:129
UBJS_EXPORT ubjs_result ubjs_parser_error_get_message_text(ubjs_parser_error *this, char *text)
Copies the error message's content to provided array.
Definition: ubjs_parser.c:71
ubjs_parser_context_free free
Definition: ubjs_parser.h:167
User-provided context - callbacks and userdata.
Definition: ubjs_parser.h:155
UBJS_EXPORT ubjs_result ubjs_parser_error_get_message_length(ubjs_parser_error *this, unsigned int *plength)
Gets the error message's length.
Definition: ubjs_parser.c:60
unsigned int limit_recursion_level
Max recursion level for containers. If this is 0, limit is effectively off. Else parser errors when r...
Definition: ubjs_parser.h:143
Settings for parser.
Definition: ubjs_parser.h:112