ubjsc  0.4-dev
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_primitives.h"
41 
43 struct ubjs_parser;
44 
46 struct ubjs_parser_context;
47 
50 
52 struct ubjs_parser_error;
53 
55 typedef struct ubjs_parser ubjs_parser;
56 
59 
62 
65 
72 typedef void (*ubjs_parser_context_parsed)(ubjs_parser_context *context, ubjs_prmtv *primitive);
87 
94  unsigned int *plength);
104 
112 {
119 
129 
135  unsigned int limit_string_length;
136 
142  unsigned int limit_recursion_level;
143 
151 };
152 
155 {
157  void *userdata;
158 
161 
164 
167 };
168 
181  ubjs_parser_context *context, ubjs_parser **pthis);
182 
190 UBJS_EXPORT ubjs_result ubjs_parser_free(ubjs_parser **pthis);
191 
199 
207  ubjs_parser_settings **psettings);
208 
225 UBJS_EXPORT ubjs_result ubjs_parser_parse(ubjs_parser *this, uint8_t *data, unsigned int len);
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 
231 #endif
ubjs_parser_context_error error
Definition: ubjs_parser.h:163
Definitions of common types, ubjson markers and some utilities.
struct ubjs_prmtv ubjs_prmtv
Definition: ubjs_primitives.h:165
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:108
void(* ubjs_parser_context_error)(ubjs_parser_context *context, ubjs_parser_error *error)
Callback when encountered a parsing error.
Definition: ubjs_parser.h:80
void * userdata
Definition: ubjs_parser.h:157
struct ubjs_parser_error ubjs_parser_error
Holder for parser errors.
Definition: ubjs_parser.h:64
UBJS_EXPORT ubjs_result ubjs_parser_get_settings(ubjs_parser *this, ubjs_parser_settings **psettings)
Gets settings from the parser.
Definition: ubjs_parser.c:320
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:309
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:118
ubjs_bool debug
Debugging mode. If this is UTRUE, parser will fprintf(stderr) lots of internal messages about how and...
Definition: ubjs_parser.h:150
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:267
UBJS_EXPORT ubjs_result ubjs_parser_parse(ubjs_parser *this, uint8_t *data, unsigned int len)
Parses the incoming data.
Definition: ubjs_parser.c:331
struct ubjs_parser ubjs_parser
Parser itself.
Definition: ubjs_parser.h:55
void(* ubjs_parser_context_free)(ubjs_parser_context *)
Callback when parser is about to be free-d.
Definition: ubjs_parser.h:86
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:135
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:72
ubjs_parser_context_parsed parsed
Definition: ubjs_parser.h:160
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:128
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:68
ubjs_parser_context_free free
Definition: ubjs_parser.h:166
User-provided context - callbacks and userdata.
Definition: ubjs_parser.h:154
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:57
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:142
struct ubjs_library ubjs_library
Library handle.
Definition: ubjs_common.h:203
Settings for parser.
Definition: ubjs_parser.h:111