libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-struct.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25#if defined(LWS_WITH_STRUCT_SQLITE3)
26#include <sqlite3.h>
27#endif
28
41
47
48typedef struct lws_struct_map {
49 const char *colname;
52 size_t ofs; /* child dll2; points to dll2_owner */
53 size_t aux;
54 size_t ofs_clist;
58
59typedef int (*lws_struct_args_cb)(void *obj, void *cb_arg);
60
61typedef struct lws_struct_args {
64 struct lwsac *ac;
65 void *cb_arg;
66 void *dest;
67
68 size_t dest_len;
73
75
76 /*
77 * temp ac used to collate unknown possibly huge strings before final
78 * allocation and copy
79 */
80 struct lwsac *ac_chunks;
84
85#define LSM_SIGNED(type, name, qname) \
86 { \
87 qname, \
88 NULL, \
89 NULL, \
90 offsetof(type, name), \
91 sizeof ((type *)0)->name, \
92 0, \
93 0, \
94 LSMT_SIGNED \
95 }
96
97#define LSM_UNSIGNED(type, name, qname) \
98 { \
99 qname, \
100 NULL, \
101 NULL, \
102 offsetof(type, name), \
103 sizeof ((type *)0)->name, \
104 0, \
105 0, \
106 LSMT_UNSIGNED \
107 }
108
109#define LSM_BOOLEAN(type, name, qname) \
110 { \
111 qname, \
112 NULL, \
113 NULL, \
114 offsetof(type, name), \
115 sizeof ((type *)0)->name, \
116 0, \
117 0, \
118 LSMT_BOOLEAN \
119 }
120
121#define LSM_CARRAY(type, name, qname) \
122 { \
123 qname, \
124 NULL, \
125 NULL, \
126 offsetof(type, name), \
127 sizeof (((type *)0)->name), \
128 0, \
129 0, \
130 LSMT_STRING_CHAR_ARRAY \
131 }
132
133#define LSM_STRING_PTR(type, name, qname) \
134 { \
135 qname, \
136 NULL, \
137 NULL, \
138 offsetof(type, name), \
139 sizeof (((type *)0)->name), \
140 0, \
141 0, \
142 LSMT_STRING_PTR \
143 }
144
145#define LSM_LIST(ptype, pname, ctype, cname, lejp_cb, cmap, qname) \
146 { \
147 qname, \
148 cmap, \
149 lejp_cb, \
150 offsetof(ptype, pname), \
151 sizeof (ctype), \
152 offsetof(ctype, cname), \
153 LWS_ARRAY_SIZE(cmap), \
154 LSMT_LIST \
155 }
156
157#define LSM_CHILD_PTR(ptype, pname, ctype, lejp_cb, cmap, qname) \
158 { \
159 qname, \
160 cmap, \
161 lejp_cb, \
162 offsetof(ptype, pname), \
163 sizeof (ctype), \
164 0, \
165 LWS_ARRAY_SIZE(cmap), \
166 LSMT_CHILD_PTR \
167 }
168
169#define LSM_SCHEMA(ctype, lejp_cb, map, schema_name) \
170 { \
171 schema_name, \
172 map, \
173 lejp_cb, \
174 0, \
175 sizeof (ctype), \
176 0, \
177 LWS_ARRAY_SIZE(map), \
178 LSMT_SCHEMA \
179 }
180
181#define LSM_SCHEMA_DLL2(ctype, cdll2mem, lejp_cb, map, schema_name) \
182 { \
183 schema_name, \
184 map, \
185 lejp_cb, \
186 offsetof(ctype, cdll2mem), \
187 sizeof (ctype), \
188 0, \
189 LWS_ARRAY_SIZE(map), \
190 LSMT_SCHEMA \
191 }
192
193/*
194 * This is just used to create the table schema, it is not part of serialization
195 * and deserialization. Blobs should be accessed separately.
196 */
197
198#define LSM_BLOB_PTR(type, blobptr_name, qname) \
199 { \
200 qname, /* JSON item, or sqlite3 column name */ \
201 NULL, \
202 NULL, \
203 offsetof(type, blobptr_name), /* member that points to blob */ \
204 sizeof (((type *)0)->blobptr_name), /* size of blob pointer */ \
205 0, /* member holding blob len */ \
206 0, /* size of blob length member */ \
207 LSMT_BLOB_PTR \
208 }
209
220
221enum {
224};
225
235
241
244 void *user);
245
246LWS_VISIBLE LWS_EXTERN signed char
247lws_struct_schema_only_lejp_cb(struct lejp_ctx *ctx, char reason);
248
249LWS_VISIBLE LWS_EXTERN signed char
250lws_struct_default_lejp_cb(struct lejp_ctx *ctx, char reason);
251
254 size_t map_entries, int flags,
255 const void *ptoplevel);
256
259
262 size_t len, size_t *written);
263
264typedef struct sqlite3 sqlite3;
265
268 lws_dll2_owner_t *owner, uint32_t manual_idx);
269
271lws_struct_sq3_deserialize(sqlite3 *pdb, const char *filter, const char *order,
272 const lws_struct_map_t *schema, lws_dll2_owner_t *o,
273 struct lwsac **ac, int start, int limit);
274
277
279lws_struct_sq3_open(struct lws_context *context, const char *sqlite3_path,
280 char create_if_missing, sqlite3 **pdb);
281
284
struct lws_dll2_owner lws_dll2_owner_t
unsigned int uint32_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
#define LEJP_MAX_PARSING_STACK_DEPTH
Definition lws-lejp.h:181
#define LEJP_STRING_CHUNK
Definition lws-lejp.h:194
signed char(* lejp_callback)(struct lejp_ctx *ctx, char reason)
Definition lws-lejp.h:178
LWS_VISIBLE LWS_EXTERN int lws_struct_json_init_parse(struct lejp_ctx *ctx, lejp_callback cb, void *user)
lws_struct_map_type_eum
Definition lws-struct.h:29
@ LSMT_SIGNED
Definition lws-struct.h:30
@ LSMT_CHILD_PTR
Definition lws-struct.h:36
@ LSMT_BLOB_PTR
Definition lws-struct.h:38
@ LSMT_STRING_CHAR_ARRAY
Definition lws-struct.h:33
@ LSMT_LIST
Definition lws-struct.h:35
@ LSMT_BOOLEAN
Definition lws-struct.h:32
@ LSMT_STRING_PTR
Definition lws-struct.h:34
@ LSMT_UNSIGNED
Definition lws-struct.h:31
@ LSMT_SCHEMA
Definition lws-struct.h:37
struct sqlite3 sqlite3
Definition lws-struct.h:264
lws_struct_serialize_st_t st[LEJP_MAX_PARSING_STACK_DEPTH]
Definition lws-struct.h:227
char buf[LEJP_STRING_CHUNK+1]
Definition lws-struct.h:45
size_t toplevel_dll2_ofs
Definition lws-struct.h:69
const char * colname
Definition lws-struct.h:49
size_t chunks_length
Definition lws-struct.h:82
size_t ofs_clist
Definition lws-struct.h:54
const struct lws_struct_map * child_map
Definition lws-struct.h:50
LWS_VISIBLE LWS_EXTERN int lws_struct_sq3_serialize(sqlite3 *pdb, const lws_struct_map_t *schema, lws_dll2_owner_t *owner, uint32_t manual_idx)
LWS_VISIBLE LWS_EXTERN int lws_struct_sq3_close(sqlite3 **pdb)
const lws_struct_map_t * map
Definition lws-struct.h:212
int(* lws_struct_args_cb)(void *obj, void *cb_arg)
Definition lws-struct.h:59
LWS_VISIBLE LWS_EXTERN lws_struct_json_serialize_result_t lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, size_t len, size_t *written)
LWS_VISIBLE LWS_EXTERN void lws_struct_json_serialize_destroy(lws_struct_serialize_t **pjs)
lws_struct_args_cb cb
Definition lws-struct.h:63
size_t ac_block_size
Definition lws-struct.h:71
lejp_callback lejp_cb
Definition lws-struct.h:51
LWS_VISIBLE LWS_EXTERN signed char lws_struct_default_lejp_cb(struct lejp_ctx *ctx, char reason)
size_t child_map_size
Definition lws-struct.h:55
LWS_VISIBLE LWS_EXTERN lws_struct_serialize_t * lws_struct_json_serialize_create(const lws_struct_map_t *map, size_t map_entries, int flags, const void *ptoplevel)
struct lws_struct_args lws_struct_args_t
struct lws_struct_serialize lws_struct_serialize_t
const struct lws_dll2 * dllpos
Definition lws-struct.h:211
struct lejp_collation lejp_collation_t
struct lws_dll2_owner chunks_owner
Definition lws-struct.h:81
LWS_VISIBLE LWS_EXTERN int lws_struct_sq3_create_table(sqlite3 *pdb, const lws_struct_map_t *schema)
struct lws_dll2 chunks
Definition lws-struct.h:43
struct lws_struct_map lws_struct_map_t
lws_struct_map_type_eum type
Definition lws-struct.h:56
LWS_VISIBLE LWS_EXTERN int lws_struct_sq3_open(struct lws_context *context, const char *sqlite3_path, char create_if_missing, sqlite3 **pdb)
LWS_VISIBLE LWS_EXTERN signed char lws_struct_schema_only_lejp_cb(struct lejp_ctx *ctx, char reason)
LWS_VISIBLE LWS_EXTERN int lws_struct_sq3_deserialize(sqlite3 *pdb, const char *filter, const char *order, const lws_struct_map_t *schema, lws_dll2_owner_t *o, struct lwsac **ac, int start, int limit)
struct lwsac * ac_chunks
Definition lws-struct.h:80
lws_struct_json_serialize_result_t
Definition lws-struct.h:236
@ LSJS_RESULT_CONTINUE
Definition lws-struct.h:237
@ LSJS_RESULT_FINISH
Definition lws-struct.h:238
@ LSJS_RESULT_ERROR
Definition lws-struct.h:239
size_t map_entries_st[LEJP_MAX_PARSING_STACK_DEPTH]
Definition lws-struct.h:70
struct lwsac * ac
Definition lws-struct.h:64
const lws_struct_map_t * map_st[LEJP_MAX_PARSING_STACK_DEPTH]
Definition lws-struct.h:62
@ LSSERJ_FLAG_OMIT_SCHEMA
Definition lws-struct.h:223
@ LSSERJ_FLAG_PRETTY
Definition lws-struct.h:222
struct lws_struct_serialize_st lws_struct_serialize_st_t