nxt_conf.c (111:cfdcff16aa43) nxt_conf.c (116:b36238461b48)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_main.h>
9#include <nxt_conf.h>
10#if 0
11#include <math.h>
12#include <float.h>
13#endif
14
15
16#define NXT_CONF_MAX_SHORT_STRING 14
17
18
19typedef enum {
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_main.h>
9#include <nxt_conf.h>
10#if 0
11#include <math.h>
12#include <float.h>
13#endif
14
15
16#define NXT_CONF_MAX_SHORT_STRING 14
17
18
19typedef enum {
20 NXT_CONF_NULL = 0,
21 NXT_CONF_BOOLEAN,
22 NXT_CONF_INTEGER,
23 NXT_CONF_NUMBER,
24 NXT_CONF_SHORT_STRING,
25 NXT_CONF_STRING,
26 NXT_CONF_ARRAY,
27 NXT_CONF_OBJECT,
28} nxt_conf_type_t;
20 NXT_CONF_VALUE_NULL = 0,
21 NXT_CONF_VALUE_BOOLEAN,
22 NXT_CONF_VALUE_INTEGER,
23 NXT_CONF_VALUE_NUMBER,
24 NXT_CONF_VALUE_SHORT_STRING,
25 NXT_CONF_VALUE_STRING,
26 NXT_CONF_VALUE_ARRAY,
27 NXT_CONF_VALUE_OBJECT,
28} nxt_conf_value_type_t;
29
30
31typedef enum {
32 NXT_CONF_OP_PASS = 0,
33 NXT_CONF_OP_CREATE,
34 NXT_CONF_OP_REPLACE,
35 NXT_CONF_OP_DELETE,
36} nxt_conf_op_action_t;

--- 9 unchanged lines hidden (view full) ---

46 int64_t integer;
47 double number;
48 u_char str[1 + NXT_CONF_MAX_SHORT_STRING];
49 nxt_str_t *string;
50 nxt_conf_array_t *array;
51 nxt_conf_object_t *object;
52 } u;
53
29
30
31typedef enum {
32 NXT_CONF_OP_PASS = 0,
33 NXT_CONF_OP_CREATE,
34 NXT_CONF_OP_REPLACE,
35 NXT_CONF_OP_DELETE,
36} nxt_conf_op_action_t;

--- 9 unchanged lines hidden (view full) ---

46 int64_t integer;
47 double number;
48 u_char str[1 + NXT_CONF_MAX_SHORT_STRING];
49 nxt_str_t *string;
50 nxt_conf_array_t *array;
51 nxt_conf_object_t *object;
52 } u;
53
54 nxt_conf_type_t type:8; /* 3 bits. */
54 nxt_conf_value_type_t type:8; /* 3 bits. */
55};
56
57
58struct nxt_conf_array_s {
59 nxt_uint_t count;
60 nxt_conf_value_t elements[];
61};
62

--- 72 unchanged lines hidden (view full) ---

135
136 return p;
137}
138
139
140nxt_inline void
141nxt_conf_get_string(nxt_conf_value_t *value, nxt_str_t *str)
142{
55};
56
57
58struct nxt_conf_array_s {
59 nxt_uint_t count;
60 nxt_conf_value_t elements[];
61};
62

--- 72 unchanged lines hidden (view full) ---

135
136 return p;
137}
138
139
140nxt_inline void
141nxt_conf_get_string(nxt_conf_value_t *value, nxt_str_t *str)
142{
143 if (value->type == NXT_CONF_SHORT_STRING) {
143 if (value->type == NXT_CONF_VALUE_SHORT_STRING) {
144 str->length = value->u.str[0];
145 str->start = &value->u.str[1];
146
147 } else {
148 *str = *value->u.string;
149 }
150}
151
152
144 str->length = value->u.str[0];
145 str->start = &value->u.str[1];
146
147 } else {
148 *str = *value->u.string;
149 }
150}
151
152
153nxt_uint_t
154nxt_conf_type(nxt_conf_value_t *value)
155{
156 switch (value->type) {
157
158 case NXT_CONF_VALUE_NULL:
159 return NXT_CONF_NULL;
160
161 case NXT_CONF_VALUE_BOOLEAN:
162 return NXT_CONF_BOOLEAN;
163
164 case NXT_CONF_VALUE_INTEGER:
165 return NXT_CONF_INTEGER;
166
167 case NXT_CONF_VALUE_NUMBER:
168 return NXT_CONF_NUMBER;
169
170 case NXT_CONF_VALUE_SHORT_STRING:
171 case NXT_CONF_VALUE_STRING:
172 return NXT_CONF_STRING;
173
174 case NXT_CONF_VALUE_ARRAY:
175 return NXT_CONF_ARRAY;
176
177 case NXT_CONF_VALUE_OBJECT:
178 return NXT_CONF_OBJECT;
179 }
180
181 nxt_unreachable();
182
183 return 0;
184}
185
186
153typedef struct {
154 u_char *start;
155 u_char *end;
156 nxt_bool_t last;
157} nxt_conf_path_parse_t;
158
159
160static void nxt_conf_path_next_token(nxt_conf_path_parse_t *parse,

--- 59 unchanged lines hidden (view full) ---

220nxt_conf_get_object_member(nxt_conf_value_t *value, nxt_str_t *name,
221 uint32_t *index)
222{
223 nxt_str_t str;
224 nxt_uint_t n;
225 nxt_conf_object_t *object;
226 nxt_conf_object_member_t *member;
227
187typedef struct {
188 u_char *start;
189 u_char *end;
190 nxt_bool_t last;
191} nxt_conf_path_parse_t;
192
193
194static void nxt_conf_path_next_token(nxt_conf_path_parse_t *parse,

--- 59 unchanged lines hidden (view full) ---

254nxt_conf_get_object_member(nxt_conf_value_t *value, nxt_str_t *name,
255 uint32_t *index)
256{
257 nxt_str_t str;
258 nxt_uint_t n;
259 nxt_conf_object_t *object;
260 nxt_conf_object_member_t *member;
261
228 if (value->type != NXT_CONF_OBJECT) {
262 if (value->type != NXT_CONF_VALUE_OBJECT) {
229 return NULL;
230 }
231
232 object = value->u.object;
233
234 for (n = 0; n < object->count; n++) {
235 member = &object->members[n];
236

--- 31 unchanged lines hidden (view full) ---

268 nxt_str_t str;
269 void *v;
270 } *ptr;
271
272 for (i = 0; map[i].name.length != 0; i++) {
273
274 v = nxt_conf_get_object_member(value, &map[i].name, NULL);
275
263 return NULL;
264 }
265
266 object = value->u.object;
267
268 for (n = 0; n < object->count; n++) {
269 member = &object->members[n];
270

--- 31 unchanged lines hidden (view full) ---

302 nxt_str_t str;
303 void *v;
304 } *ptr;
305
306 for (i = 0; map[i].name.length != 0; i++) {
307
308 v = nxt_conf_get_object_member(value, &map[i].name, NULL);
309
276 if (v == NULL || v->type == NXT_CONF_NULL) {
310 if (v == NULL || v->type == NXT_CONF_VALUE_NULL) {
277 continue;
278 }
279
280 ptr = nxt_pointer_to(data, map[i].offset);
281
282 switch (map[i].type) {
283
284 case NXT_CONF_MAP_INT8:
285
311 continue;
312 }
313
314 ptr = nxt_pointer_to(data, map[i].offset);
315
316 switch (map[i].type) {
317
318 case NXT_CONF_MAP_INT8:
319
286 if (v->type != NXT_CONF_BOOLEAN) {
320 if (v->type != NXT_CONF_VALUE_BOOLEAN) {
287 return NXT_ERROR;
288 }
289
290 ptr->ui8 = v->u.boolean;
291
292 break;
293
294 case NXT_CONF_MAP_INT32:
295 case NXT_CONF_MAP_INT64:
296 case NXT_CONF_MAP_INT:
297 case NXT_CONF_MAP_SIZE:
298 case NXT_CONF_MAP_OFF:
299 case NXT_CONF_MAP_MSEC:
300
321 return NXT_ERROR;
322 }
323
324 ptr->ui8 = v->u.boolean;
325
326 break;
327
328 case NXT_CONF_MAP_INT32:
329 case NXT_CONF_MAP_INT64:
330 case NXT_CONF_MAP_INT:
331 case NXT_CONF_MAP_SIZE:
332 case NXT_CONF_MAP_OFF:
333 case NXT_CONF_MAP_MSEC:
334
301 if (v->type != NXT_CONF_INTEGER) {
335 if (v->type != NXT_CONF_VALUE_INTEGER) {
302 return NXT_ERROR;
303 }
304
305 switch (map[i].type) {
306
307 case NXT_CONF_MAP_INT32:
308 ptr->ui8 = v->u.integer;
309 break;

--- 21 unchanged lines hidden (view full) ---

331 default:
332 nxt_unreachable();
333 }
334
335 break;
336
337 case NXT_CONF_MAP_DOUBLE:
338
336 return NXT_ERROR;
337 }
338
339 switch (map[i].type) {
340
341 case NXT_CONF_MAP_INT32:
342 ptr->ui8 = v->u.integer;
343 break;

--- 21 unchanged lines hidden (view full) ---

365 default:
366 nxt_unreachable();
367 }
368
369 break;
370
371 case NXT_CONF_MAP_DOUBLE:
372
339 if (v->type == NXT_CONF_NUMBER) {
373 if (v->type == NXT_CONF_VALUE_NUMBER) {
340 ptr->dbl = v->u.number;
341
374 ptr->dbl = v->u.number;
375
342 } else if (v->type == NXT_CONF_INTEGER) {
376 } else if (v->type == NXT_CONF_VALUE_INTEGER) {
343 ptr->dbl = v->u.integer;
344
345 } else {
346 return NXT_ERROR;
347 }
348
349 break;
350
351 case NXT_CONF_MAP_STR:
352
377 ptr->dbl = v->u.integer;
378
379 } else {
380 return NXT_ERROR;
381 }
382
383 break;
384
385 case NXT_CONF_MAP_STR:
386
353 if (v->type != NXT_CONF_SHORT_STRING
354 && v->type != NXT_CONF_STRING)
387 if (v->type != NXT_CONF_VALUE_SHORT_STRING
388 && v->type != NXT_CONF_VALUE_STRING)
355 {
356 return NXT_ERROR;
357 }
358
359 nxt_conf_get_string(v, &ptr->str);
360
361 break;
362

--- 13 unchanged lines hidden (view full) ---

376nxt_conf_value_t *
377nxt_conf_next_object_member(nxt_conf_value_t *value, nxt_str_t *name,
378 uint32_t *next)
379{
380 uint32_t n;
381 nxt_conf_object_t *object;
382 nxt_conf_object_member_t *member;
383
389 {
390 return NXT_ERROR;
391 }
392
393 nxt_conf_get_string(v, &ptr->str);
394
395 break;
396

--- 13 unchanged lines hidden (view full) ---

410nxt_conf_value_t *
411nxt_conf_next_object_member(nxt_conf_value_t *value, nxt_str_t *name,
412 uint32_t *next)
413{
414 uint32_t n;
415 nxt_conf_object_t *object;
416 nxt_conf_object_member_t *member;
417
384 if (value->type != NXT_CONF_OBJECT) {
418 if (value->type != NXT_CONF_VALUE_OBJECT) {
385 return NULL;
386 }
387
388 n = *next;
389 object = value->u.object;
390
391 if (n >= object->count) {
392 return NULL;

--- 68 unchanged lines hidden (view full) ---

461 if (token.length > NXT_CONF_MAX_SHORT_STRING) {
462
463 member->name.u.string = nxt_mp_get(mp, sizeof(nxt_str_t));
464 if (nxt_slow_path(member->name.u.string == NULL)) {
465 return NXT_ERROR;
466 }
467
468 *member->name.u.string = token;
419 return NULL;
420 }
421
422 n = *next;
423 object = value->u.object;
424
425 if (n >= object->count) {
426 return NULL;

--- 68 unchanged lines hidden (view full) ---

495 if (token.length > NXT_CONF_MAX_SHORT_STRING) {
496
497 member->name.u.string = nxt_mp_get(mp, sizeof(nxt_str_t));
498 if (nxt_slow_path(member->name.u.string == NULL)) {
499 return NXT_ERROR;
500 }
501
502 *member->name.u.string = token;
469 member->name.type = NXT_CONF_STRING;
503 member->name.type = NXT_CONF_VALUE_STRING;
470
471 } else {
472 member->name.u.str[0] = token.length;
473 nxt_memcpy(&member->name.u.str[1], token.start, token.length);
474
504
505 } else {
506 member->name.u.str[0] = token.length;
507 nxt_memcpy(&member->name.u.str[1], token.start, token.length);
508
475 member->name.type = NXT_CONF_SHORT_STRING;
509 member->name.type = NXT_CONF_VALUE_SHORT_STRING;
476 }
477
478 member->value = *value;
479
480 op->action = NXT_CONF_OP_CREATE;
481 op->ctx = member;
482
483 } else {

--- 29 unchanged lines hidden (view full) ---

513static nxt_int_t
514nxt_conf_copy_value(nxt_mp_t *mp, nxt_conf_op_t *op, nxt_conf_value_t *dst,
515 nxt_conf_value_t *src)
516{
517 size_t size;
518 nxt_int_t rc;
519 nxt_uint_t n;
520
510 }
511
512 member->value = *value;
513
514 op->action = NXT_CONF_OP_CREATE;
515 op->ctx = member;
516
517 } else {

--- 29 unchanged lines hidden (view full) ---

547static nxt_int_t
548nxt_conf_copy_value(nxt_mp_t *mp, nxt_conf_op_t *op, nxt_conf_value_t *dst,
549 nxt_conf_value_t *src)
550{
551 size_t size;
552 nxt_int_t rc;
553 nxt_uint_t n;
554
521 if (op != NULL && src->type != NXT_CONF_OBJECT) {
555 if (op != NULL && src->type != NXT_CONF_VALUE_OBJECT) {
522 return NXT_ERROR;
523 }
524
525 dst->type = src->type;
526
527 switch (src->type) {
528
556 return NXT_ERROR;
557 }
558
559 dst->type = src->type;
560
561 switch (src->type) {
562
529 case NXT_CONF_STRING:
563 case NXT_CONF_VALUE_STRING:
530
531 dst->u.string = nxt_str_dup(mp, NULL, src->u.string);
532
533 if (nxt_slow_path(dst->u.string == NULL)) {
534 return NXT_ERROR;
535 }
536
537 break;
538
564
565 dst->u.string = nxt_str_dup(mp, NULL, src->u.string);
566
567 if (nxt_slow_path(dst->u.string == NULL)) {
568 return NXT_ERROR;
569 }
570
571 break;
572
539 case NXT_CONF_ARRAY:
573 case NXT_CONF_VALUE_ARRAY:
540
541 size = sizeof(nxt_conf_array_t)
542 + src->u.array->count * sizeof(nxt_conf_value_t);
543
544 dst->u.array = nxt_mp_get(mp, size);
545 if (nxt_slow_path(dst->u.array == NULL)) {
546 return NXT_ERROR;
547 }

--- 6 unchanged lines hidden (view full) ---

554
555 if (nxt_slow_path(rc != NXT_OK)) {
556 return NXT_ERROR;
557 }
558 }
559
560 break;
561
574
575 size = sizeof(nxt_conf_array_t)
576 + src->u.array->count * sizeof(nxt_conf_value_t);
577
578 dst->u.array = nxt_mp_get(mp, size);
579 if (nxt_slow_path(dst->u.array == NULL)) {
580 return NXT_ERROR;
581 }

--- 6 unchanged lines hidden (view full) ---

588
589 if (nxt_slow_path(rc != NXT_OK)) {
590 return NXT_ERROR;
591 }
592 }
593
594 break;
595
562 case NXT_CONF_OBJECT:
596 case NXT_CONF_VALUE_OBJECT:
563 return nxt_conf_copy_object(mp, op, dst, src);
564
565 default:
566 dst->u = src->u;
567 }
568
569 return NXT_OK;
570}

--- 204 unchanged lines hidden (view full) ---

775 case '"':
776 return nxt_conf_json_parse_string(mp, value, start, end);
777
778 case 't':
779 if (nxt_fast_path(end - start >= 4
780 && nxt_memcmp(start, "true", 4) == 0))
781 {
782 value->u.boolean = 1;
597 return nxt_conf_copy_object(mp, op, dst, src);
598
599 default:
600 dst->u = src->u;
601 }
602
603 return NXT_OK;
604}

--- 204 unchanged lines hidden (view full) ---

809 case '"':
810 return nxt_conf_json_parse_string(mp, value, start, end);
811
812 case 't':
813 if (nxt_fast_path(end - start >= 4
814 && nxt_memcmp(start, "true", 4) == 0))
815 {
816 value->u.boolean = 1;
783 value->type = NXT_CONF_BOOLEAN;
817 value->type = NXT_CONF_VALUE_BOOLEAN;
784
785 return start + 4;
786 }
787
788 return NULL;
789
790 case 'f':
791 if (nxt_fast_path(end - start >= 5
792 && nxt_memcmp(start, "false", 5) == 0))
793 {
794 value->u.boolean = 0;
818
819 return start + 4;
820 }
821
822 return NULL;
823
824 case 'f':
825 if (nxt_fast_path(end - start >= 5
826 && nxt_memcmp(start, "false", 5) == 0))
827 {
828 value->u.boolean = 0;
795 value->type = NXT_CONF_BOOLEAN;
829 value->type = NXT_CONF_VALUE_BOOLEAN;
796
797 return start + 5;
798 }
799
800 return NULL;
801
802 case 'n':
803 if (nxt_fast_path(end - start >= 4
804 && nxt_memcmp(start, "null", 4) == 0))
805 {
830
831 return start + 5;
832 }
833
834 return NULL;
835
836 case 'n':
837 if (nxt_fast_path(end - start >= 4
838 && nxt_memcmp(start, "null", 4) == 0))
839 {
806 value->type = NXT_CONF_NULL;
840 value->type = NXT_CONF_VALUE_NULL;
807 return start + 4;
808 }
809
810 return NULL;
811 }
812
813 if (nxt_fast_path(ch == '-' || (ch - '0') <= 9)) {
814 return nxt_conf_json_parse_number(mp, value, start, end);

--- 109 unchanged lines hidden (view full) ---

924
925 object = nxt_mp_get(mp, sizeof(nxt_conf_object_t)
926 + count * sizeof(nxt_conf_object_member_t));
927 if (nxt_slow_path(object == NULL)) {
928 goto error;
929 }
930
931 value->u.object = object;
841 return start + 4;
842 }
843
844 return NULL;
845 }
846
847 if (nxt_fast_path(ch == '-' || (ch - '0') <= 9)) {
848 return nxt_conf_json_parse_number(mp, value, start, end);

--- 109 unchanged lines hidden (view full) ---

958
959 object = nxt_mp_get(mp, sizeof(nxt_conf_object_t)
960 + count * sizeof(nxt_conf_object_member_t));
961 if (nxt_slow_path(object == NULL)) {
962 goto error;
963 }
964
965 value->u.object = object;
932 value->type = NXT_CONF_OBJECT;
966 value->type = NXT_CONF_VALUE_OBJECT;
933
934 object->count = count;
935 member = object->members;
936
937 nxt_memzero(&lhe, sizeof(nxt_lvlhsh_each_t));
938 lhe.proto = &nxt_conf_object_hash_proto;
939
940 for ( ;; ) {

--- 136 unchanged lines hidden (view full) ---

1077
1078 array = nxt_mp_get(mp, sizeof(nxt_conf_array_t)
1079 + count * sizeof(nxt_conf_value_t));
1080 if (nxt_slow_path(array == NULL)) {
1081 goto error;
1082 }
1083
1084 value->u.array = array;
967
968 object->count = count;
969 member = object->members;
970
971 nxt_memzero(&lhe, sizeof(nxt_lvlhsh_each_t));
972 lhe.proto = &nxt_conf_object_hash_proto;
973
974 for ( ;; ) {

--- 136 unchanged lines hidden (view full) ---

1111
1112 array = nxt_mp_get(mp, sizeof(nxt_conf_array_t)
1113 + count * sizeof(nxt_conf_value_t));
1114 if (nxt_slow_path(array == NULL)) {
1115 goto error;
1116 }
1117
1118 value->u.array = array;
1085 value->type = NXT_CONF_ARRAY;
1119 value->type = NXT_CONF_VALUE_ARRAY;
1086
1087 array->count = count;
1088 element = array->elements;
1089
1090 nxt_list_each(value, list) {
1091 *element++ = *value;
1092 } nxt_list_loop;
1093

--- 105 unchanged lines hidden (view full) ---

1199 }
1200
1201 /* Points to the ending quote mark. */
1202 last = p;
1203
1204 size = last - start - surplus;
1205
1206 if (size > NXT_CONF_MAX_SHORT_STRING) {
1120
1121 array->count = count;
1122 element = array->elements;
1123
1124 nxt_list_each(value, list) {
1125 *element++ = *value;
1126 } nxt_list_loop;
1127

--- 105 unchanged lines hidden (view full) ---

1233 }
1234
1235 /* Points to the ending quote mark. */
1236 last = p;
1237
1238 size = last - start - surplus;
1239
1240 if (size > NXT_CONF_MAX_SHORT_STRING) {
1207 value->type = NXT_CONF_STRING;
1241 value->type = NXT_CONF_VALUE_STRING;
1208 value->u.string = nxt_str_alloc(mp, size);
1209
1210 if (nxt_slow_path(value->u.string == NULL)) {
1211 return NULL;
1212 }
1213
1214 s = value->u.string->start;
1215
1216 } else {
1242 value->u.string = nxt_str_alloc(mp, size);
1243
1244 if (nxt_slow_path(value->u.string == NULL)) {
1245 return NULL;
1246 }
1247
1248 s = value->u.string->start;
1249
1250 } else {
1217 value->type = NXT_CONF_SHORT_STRING;
1251 value->type = NXT_CONF_VALUE_SHORT_STRING;
1218 value->u.str[0] = size;
1219
1220 s = &value->u.str[1];
1221 }
1222
1223 if (surplus == 0) {
1224 nxt_memcpy(s, start, size);
1225 return last + 1;

--- 137 unchanged lines hidden (view full) ---

1363 integer = integer * 10 + ch;
1364 }
1365
1366 if (nxt_slow_path(p == start || (p - start > 1 && *start == '0'))) {
1367 return NULL;
1368 }
1369
1370 if (ch != '.') {
1252 value->u.str[0] = size;
1253
1254 s = &value->u.str[1];
1255 }
1256
1257 if (surplus == 0) {
1258 nxt_memcpy(s, start, size);
1259 return last + 1;

--- 137 unchanged lines hidden (view full) ---

1397 integer = integer * 10 + ch;
1398 }
1399
1400 if (nxt_slow_path(p == start || (p - start > 1 && *start == '0'))) {
1401 return NULL;
1402 }
1403
1404 if (ch != '.') {
1371 value->type = NXT_CONF_INTEGER;
1405 value->type = NXT_CONF_VALUE_INTEGER;
1372 value->u.integer = sign * integer;
1373 return p;
1374 }
1375
1376#if 0
1377 start = p + 1;
1378
1379 frac = 0;

--- 18 unchanged lines hidden (view full) ---

1398 frac = frac * 10 + ch;
1399 power *= 10;
1400 }
1401
1402 if (nxt_slow_path(p == start)) {
1403 return NULL;
1404 }
1405
1406 value->u.integer = sign * integer;
1407 return p;
1408 }
1409
1410#if 0
1411 start = p + 1;
1412
1413 frac = 0;

--- 18 unchanged lines hidden (view full) ---

1432 frac = frac * 10 + ch;
1433 power *= 10;
1434 }
1435
1436 if (nxt_slow_path(p == start)) {
1437 return NULL;
1438 }
1439
1406 value->type = NXT_CONF_NUMBER;
1440 value->type = NXT_CONF_VALUE_NUMBER;
1407 value->u.number = integer + (double) frac / power;
1408
1409 value->u.number = copysign(value->u.number, sign);
1410
1411 if (ch == 'e' || ch == 'E') {
1412 start = p + 1;
1413
1414 ch = *start;

--- 43 unchanged lines hidden (view full) ---

1458}
1459
1460
1461size_t
1462nxt_conf_json_length(nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty)
1463{
1464 switch (value->type) {
1465
1441 value->u.number = integer + (double) frac / power;
1442
1443 value->u.number = copysign(value->u.number, sign);
1444
1445 if (ch == 'e' || ch == 'E') {
1446 start = p + 1;
1447
1448 ch = *start;

--- 43 unchanged lines hidden (view full) ---

1492}
1493
1494
1495size_t
1496nxt_conf_json_length(nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty)
1497{
1498 switch (value->type) {
1499
1466 case NXT_CONF_NULL:
1500 case NXT_CONF_VALUE_NULL:
1467 return sizeof("null") - 1;
1468
1501 return sizeof("null") - 1;
1502
1469 case NXT_CONF_BOOLEAN:
1503 case NXT_CONF_VALUE_BOOLEAN:
1470 return value->u.boolean ? sizeof("true") - 1 : sizeof("false") - 1;
1471
1504 return value->u.boolean ? sizeof("true") - 1 : sizeof("false") - 1;
1505
1472 case NXT_CONF_INTEGER:
1506 case NXT_CONF_VALUE_INTEGER:
1473 return nxt_conf_json_integer_length(value);
1474
1507 return nxt_conf_json_integer_length(value);
1508
1475 case NXT_CONF_NUMBER:
1509 case NXT_CONF_VALUE_NUMBER:
1476 /* TODO */
1477 return 0;
1478
1510 /* TODO */
1511 return 0;
1512
1479 case NXT_CONF_SHORT_STRING:
1480 case NXT_CONF_STRING:
1513 case NXT_CONF_VALUE_SHORT_STRING:
1514 case NXT_CONF_VALUE_STRING:
1481 return nxt_conf_json_string_length(value);
1482
1515 return nxt_conf_json_string_length(value);
1516
1483 case NXT_CONF_ARRAY:
1517 case NXT_CONF_VALUE_ARRAY:
1484 return nxt_conf_json_array_length(value, pretty);
1485
1518 return nxt_conf_json_array_length(value, pretty);
1519
1486 case NXT_CONF_OBJECT:
1520 case NXT_CONF_VALUE_OBJECT:
1487 return nxt_conf_json_object_length(value, pretty);
1488 }
1489
1490 nxt_unreachable();
1491
1492 return 0;
1493}
1494
1495
1496u_char *
1497nxt_conf_json_print(u_char *p, nxt_conf_value_t *value,
1498 nxt_conf_json_pretty_t *pretty)
1499{
1500 switch (value->type) {
1501
1521 return nxt_conf_json_object_length(value, pretty);
1522 }
1523
1524 nxt_unreachable();
1525
1526 return 0;
1527}
1528
1529
1530u_char *
1531nxt_conf_json_print(u_char *p, nxt_conf_value_t *value,
1532 nxt_conf_json_pretty_t *pretty)
1533{
1534 switch (value->type) {
1535
1502 case NXT_CONF_NULL:
1536 case NXT_CONF_VALUE_NULL:
1503 return nxt_cpymem(p, "null", 4);
1504
1537 return nxt_cpymem(p, "null", 4);
1538
1505 case NXT_CONF_BOOLEAN:
1539 case NXT_CONF_VALUE_BOOLEAN:
1506 return value->u.boolean ? nxt_cpymem(p, "true", 4)
1507 : nxt_cpymem(p, "false", 5);
1508
1540 return value->u.boolean ? nxt_cpymem(p, "true", 4)
1541 : nxt_cpymem(p, "false", 5);
1542
1509 case NXT_CONF_INTEGER:
1543 case NXT_CONF_VALUE_INTEGER:
1510 return nxt_conf_json_print_integer(p, value);
1511
1544 return nxt_conf_json_print_integer(p, value);
1545
1512 case NXT_CONF_NUMBER:
1546 case NXT_CONF_VALUE_NUMBER:
1513 /* TODO */
1514 return p;
1515
1547 /* TODO */
1548 return p;
1549
1516 case NXT_CONF_SHORT_STRING:
1517 case NXT_CONF_STRING:
1550 case NXT_CONF_VALUE_SHORT_STRING:
1551 case NXT_CONF_VALUE_STRING:
1518 return nxt_conf_json_print_string(p, value);
1519
1552 return nxt_conf_json_print_string(p, value);
1553
1520 case NXT_CONF_ARRAY:
1554 case NXT_CONF_VALUE_ARRAY:
1521 return nxt_conf_json_print_array(p, value, pretty);
1522
1555 return nxt_conf_json_print_array(p, value, pretty);
1556
1523 case NXT_CONF_OBJECT:
1557 case NXT_CONF_VALUE_OBJECT:
1524 return nxt_conf_json_print_object(p, value, pretty);
1525 }
1526
1527 nxt_unreachable();
1528
1529 return p;
1530}
1531

--- 357 unchanged lines hidden ---
1558 return nxt_conf_json_print_object(p, value, pretty);
1559 }
1560
1561 nxt_unreachable();
1562
1563 return p;
1564}
1565

--- 357 unchanged lines hidden ---