1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #ifndef UCX_PROPERTIES_H
37 #define UCX_PROPERTIES_H
38
39 #include "common.h"
40 #include "string.h"
41 #include "map.h"
42 #include "buffer.h"
43
44 #include <stdio.h>
45 #include <string.h>
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51
52
53
54 struct cx_properties_config_s {
55
56
57
58
59 char delimiter;
60
61
62
63
64
65 char comment1;
66
67
68
69
70
71 char comment2;
72
73
74
75
76
77 char comment3;
78
79
80
81
82
83
84
85
86 char continuation;
87 };
88
89
90
91
92 typedef struct cx_properties_config_s CxPropertiesConfig;
93
94
95
96
97 CX_EXPORT extern const CxPropertiesConfig cx_properties_config_default;
98
99
100
101
102 enum cx_properties_status {
103
104
105
106 CX_PROPERTIES_NO_ERROR,
107
108
109
110 CX_PROPERTIES_NO_DATA,
111
112
113
114
115
116
117 CX_PROPERTIES_INCOMPLETE_DATA,
118
119
120
121
122
123
124
125
126 CX_PROPERTIES_OK,
127
128
129
130 CX_PROPERTIES_NULL_INPUT,
131
132
133
134 CX_PROPERTIES_INVALID_EMPTY_KEY,
135
136
137
138 CX_PROPERTIES_INVALID_MISSING_DELIMITER,
139
140
141
142 CX_PROPERTIES_BUFFER_ALLOC_FAILED,
143
144
145
146
147
148 CX_PROPERTIES_READ_INIT_FAILED,
149
150
151
152
153
154 CX_PROPERTIES_READ_FAILED,
155
156
157
158
159
160 CX_PROPERTIES_SINK_FAILED,
161 };
162
163
164
165
166 typedef enum cx_properties_status CxPropertiesStatus;
167
168
169
170
171 struct cx_properties_s {
172
173
174
175 CxPropertiesConfig config;
176
177
178
179
180 CxBuffer input;
181
182
183
184
185 CxBuffer buffer;
186 };
187
188
189
190
191 typedef struct cx_properties_s CxProperties;
192
193
194
195
196
197 typedef struct cx_properties_sink_s CxPropertiesSink;
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212 typedef int(*cx_properties_sink_func)(
213 CxProperties *prop,
214 CxPropertiesSink *sink,
215 cxstring key,
216 cxstring value
217 );
218
219
220
221
222 struct cx_properties_sink_s {
223
224
225
226 void *sink;
227
228
229
230 void *data;
231
232
233
234 cx_properties_sink_func sink_func;
235 };
236
237
238
239
240
241 typedef struct cx_properties_source_s CxPropertiesSource;
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258 typedef int(*cx_properties_read_func)(
259 CxProperties *prop,
260 CxPropertiesSource *src,
261 cxstring *target
262 );
263
264
265
266
267
268
269
270
271
272 typedef int(*cx_properties_read_init_func)(
273 CxProperties *prop,
274 CxPropertiesSource *src
275 );
276
277
278
279
280
281
282
283 typedef void(*cx_properties_read_clean_func)(
284 CxProperties *prop,
285 CxPropertiesSource *src
286 );
287
288
289
290
291 struct cx_properties_source_s {
292
293
294
295
296
297 void *src;
298
299
300
301 void *data_ptr;
302
303
304
305 size_t data_size;
306
307
308
309 cx_properties_read_func read_func;
310
311
312
313 cx_properties_read_init_func read_init_func;
314
315
316
317
318 cx_properties_read_clean_func read_clean_func;
319 };
320
321
322
323
324
325
326
327
328 cx_attr_nonnull
329 CX_EXPORT void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
330
331
332
333
334
335
336
337
338
339
340
341
342 cx_attr_nonnull
343 CX_EXPORT void cxPropertiesDestroy(CxProperties *prop);
344
345
346
347
348
349
350
351
352
353 cx_attr_nonnull
354 CX_EXPORT void cxPropertiesReset(CxProperties *prop);
355
356
357
358
359
360
361
362 #define cxPropertiesInitDefault(prop) \
363 cxPropertiesInit(prop, cx_properties_config_default)
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386 cx_attr_nonnull cx_attr_access_r(
2,
3)
387 CX_EXPORT int cxPropertiesFilln(CxProperties *prop,
const char *buf,
size_t len);
388
389
390
391
392
393
394
395
396
397 cx_attr_nonnull
398 CX_INLINE int cx_properties_fill(CxProperties *prop, cxstring str) {
399 return cxPropertiesFilln(prop, str.ptr, str.length);
400 }
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422 #define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str))
423
424
425
426
427
428
429
430
431 cx_attr_nonnull
432 CX_EXPORT void cxPropertiesUseStack(CxProperties *prop,
char *buf,
size_t capacity);
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464 cx_attr_nonnull cx_attr_nodiscard
465 CX_EXPORT CxPropertiesStatus cxPropertiesNext(CxProperties *prop, cxstring *key, cxstring *value);
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481 cx_attr_nonnull cx_attr_nodiscard
482 CX_EXPORT CxPropertiesSink cxPropertiesMapSink(CxMap *map);
483
484
485
486
487
488
489
490
491 cx_attr_nodiscard
492 CX_EXPORT CxPropertiesSource cxPropertiesStringSource(cxstring str);
493
494
495
496
497
498
499
500
501
502 cx_attr_nonnull cx_attr_nodiscard cx_attr_access_r(
1,
2)
503 CX_EXPORT CxPropertiesSource cxPropertiesCstrnSource(
const char *str,
size_t len);
504
505
506
507
508
509
510
511
512
513
514
515 cx_attr_nonnull cx_attr_nodiscard cx_attr_cstr_arg(
1)
516 CX_EXPORT CxPropertiesSource cxPropertiesCstrSource(
const char *str);
517
518
519
520
521
522
523
524
525
526
527 cx_attr_nonnull cx_attr_nodiscard cx_attr_access_r(
1)
528 CX_EXPORT CxPropertiesSource cxPropertiesFileSource(
FILE *file,
size_t chunk_size);
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559 cx_attr_nonnull
560 CX_EXPORT CxPropertiesStatus cxPropertiesLoad(CxProperties *prop,
561 CxPropertiesSink sink, CxPropertiesSource source);
562
563 #ifdef __cplusplus
564 }
565 #endif
566
567 #endif
568