nxt_conf_validation.c (487:3059afdc331c) nxt_conf_validation.c (507:fa714d76592b)
1
2/*
3 * Copyright (C) Valentin V. Bartenev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8#include <nxt_conf.h>

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

49static nxt_int_t nxt_conf_vldt_listener(nxt_conf_validation_t *vldt,
50 nxt_str_t *name, nxt_conf_value_t *value);
51static nxt_int_t nxt_conf_vldt_app_name(nxt_conf_validation_t *vldt,
52 nxt_conf_value_t *value, void *data);
53static nxt_int_t nxt_conf_vldt_app(nxt_conf_validation_t *vldt,
54 nxt_str_t *name, nxt_conf_value_t *value);
55static nxt_int_t nxt_conf_vldt_object(nxt_conf_validation_t *vldt,
56 nxt_conf_value_t *value, void *data);
1
2/*
3 * Copyright (C) Valentin V. Bartenev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8#include <nxt_conf.h>

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

49static nxt_int_t nxt_conf_vldt_listener(nxt_conf_validation_t *vldt,
50 nxt_str_t *name, nxt_conf_value_t *value);
51static nxt_int_t nxt_conf_vldt_app_name(nxt_conf_validation_t *vldt,
52 nxt_conf_value_t *value, void *data);
53static nxt_int_t nxt_conf_vldt_app(nxt_conf_validation_t *vldt,
54 nxt_str_t *name, nxt_conf_value_t *value);
55static nxt_int_t nxt_conf_vldt_object(nxt_conf_validation_t *vldt,
56 nxt_conf_value_t *value, void *data);
57static nxt_int_t nxt_conf_vldt_processes(nxt_conf_validation_t *vldt,
58 nxt_conf_value_t *value, void *data);
57static nxt_int_t nxt_conf_vldt_object_iterator(nxt_conf_validation_t *vldt,
58 nxt_conf_value_t *value, void *data);
59static nxt_int_t nxt_conf_vldt_system(nxt_conf_validation_t *vldt,
60 nxt_conf_value_t *value, void *data);
61static nxt_int_t nxt_conf_vldt_user(nxt_conf_validation_t *vldt, char *name);
62static nxt_int_t nxt_conf_vldt_group(nxt_conf_validation_t *vldt, char *name);
63
64

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

102 NXT_CONF_VLDT_INTEGER,
103 NULL,
104 NULL },
105
106 NXT_CONF_VLDT_END
107};
108
109
59static nxt_int_t nxt_conf_vldt_object_iterator(nxt_conf_validation_t *vldt,
60 nxt_conf_value_t *value, void *data);
61static nxt_int_t nxt_conf_vldt_system(nxt_conf_validation_t *vldt,
62 nxt_conf_value_t *value, void *data);
63static nxt_int_t nxt_conf_vldt_user(nxt_conf_validation_t *vldt, char *name);
64static nxt_int_t nxt_conf_vldt_group(nxt_conf_validation_t *vldt, char *name);
65
66

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

104 NXT_CONF_VLDT_INTEGER,
105 NULL,
106 NULL },
107
108 NXT_CONF_VLDT_END
109};
110
111
110static nxt_conf_vldt_object_t nxt_conf_vldt_common_members[] = {
111 { nxt_string("type"),
112 NXT_CONF_VLDT_STRING,
112static nxt_conf_vldt_object_t nxt_conf_vldt_app_processes_members[] = {
113 { nxt_string("spare"),
114 NXT_CONF_VLDT_INTEGER,
113 NULL,
114 NULL },
115
115 NULL,
116 NULL },
117
116 { nxt_string("workers"),
118 { nxt_string("max"),
117 NXT_CONF_VLDT_INTEGER,
118 NULL,
119 NULL },
120
119 NXT_CONF_VLDT_INTEGER,
120 NULL,
121 NULL },
122
123 { nxt_string("idle_timeout"),
124 NXT_CONF_VLDT_INTEGER,
125 NULL,
126 NULL },
127
128 NXT_CONF_VLDT_END
129};
130
131
132static nxt_conf_vldt_object_t nxt_conf_vldt_common_members[] = {
133 { nxt_string("type"),
134 NXT_CONF_VLDT_STRING,
135 NULL,
136 NULL },
137
121 { nxt_string("limits"),
122 NXT_CONF_VLDT_OBJECT,
123 &nxt_conf_vldt_object,
124 (void *) &nxt_conf_vldt_app_limits_members },
125
138 { nxt_string("limits"),
139 NXT_CONF_VLDT_OBJECT,
140 &nxt_conf_vldt_object,
141 (void *) &nxt_conf_vldt_app_limits_members },
142
143 { nxt_string("processes"),
144 NXT_CONF_VLDT_INTEGER | NXT_CONF_VLDT_OBJECT,
145 &nxt_conf_vldt_processes,
146 (void *) &nxt_conf_vldt_app_processes_members },
147
126 { nxt_string("user"),
127 NXT_CONF_VLDT_STRING,
128 nxt_conf_vldt_system,
129 (void *) &nxt_conf_vldt_user },
130
131 { nxt_string("group"),
132 NXT_CONF_VLDT_STRING,
133 nxt_conf_vldt_system,

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

470 }
471
472 break;
473 }
474 }
475}
476
477
148 { nxt_string("user"),
149 NXT_CONF_VLDT_STRING,
150 nxt_conf_vldt_system,
151 (void *) &nxt_conf_vldt_user },
152
153 { nxt_string("group"),
154 NXT_CONF_VLDT_STRING,
155 nxt_conf_vldt_system,

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

492 }
493
494 break;
495 }
496 }
497}
498
499
500typedef struct {
501 int64_t spare;
502 int64_t max;
503 int64_t idle_timeout;
504} nxt_conf_vldt_processes_conf_t;
505
506
507static nxt_conf_map_t nxt_conf_vldt_processes_conf_map[] = {
508 {
509 nxt_string("spare"),
510 NXT_CONF_MAP_INT64,
511 offsetof(nxt_conf_vldt_processes_conf_t, spare),
512 },
513
514 {
515 nxt_string("max"),
516 NXT_CONF_MAP_INT64,
517 offsetof(nxt_conf_vldt_processes_conf_t, max),
518 },
519
520 {
521 nxt_string("idle_timeout"),
522 NXT_CONF_MAP_INT64,
523 offsetof(nxt_conf_vldt_processes_conf_t, idle_timeout),
524 },
525};
526
527
478static nxt_int_t
528static nxt_int_t
529nxt_conf_vldt_processes(nxt_conf_validation_t *vldt, nxt_conf_value_t *value,
530 void *data)
531{
532 int64_t int_value;
533 nxt_int_t ret;
534 nxt_conf_vldt_processes_conf_t proc;
535
536 static nxt_str_t max_str = nxt_string("max");
537
538 if (nxt_conf_type(value) == NXT_CONF_INTEGER) {
539 int_value = nxt_conf_get_integer(value);
540
541 if (int_value < 1) {
542 return nxt_conf_vldt_error(vldt, "The \"processes\" number must be "
543 "equal to or greater than 1.");
544 }
545
546 if (int_value > NXT_INT32_T_MAX) {
547 return nxt_conf_vldt_error(vldt, "The \"processes\" number must "
548 "not exceed %d.", NXT_INT32_T_MAX);
549 }
550
551 return NXT_OK;
552 }
553
554 ret = nxt_conf_vldt_object(vldt, value, data);
555 if (ret != NXT_OK) {
556 return ret;
557 }
558
559 proc.spare = 1;
560 proc.max = 1;
561 proc.idle_timeout = 15;
562
563 ret = nxt_conf_map_object(vldt->pool, value,
564 nxt_conf_vldt_processes_conf_map,
565 nxt_nitems(nxt_conf_vldt_processes_conf_map),
566 &proc);
567 if (ret != NXT_OK) {
568 return ret;
569 }
570
571 if (proc.spare < 0) {
572 return nxt_conf_vldt_error(vldt, "The \"spare\" number must not be "
573 "negative.");
574 }
575
576 if (proc.spare > NXT_INT32_T_MAX) {
577 return nxt_conf_vldt_error(vldt, "The \"spare\" number must not "
578 "not exceed %d.", NXT_INT32_T_MAX);
579 }
580
581 if (nxt_conf_get_object_member(value, &max_str, NULL) != NULL) {
582
583 if (proc.max < 1) {
584 return nxt_conf_vldt_error(vldt, "The \"max\" number must be equal "
585 "to or greater than 1.");
586 }
587
588 if (proc.max > NXT_INT32_T_MAX) {
589 return nxt_conf_vldt_error(vldt, "The \"max\" number must not "
590 "not exceed %d.", NXT_INT32_T_MAX);
591 }
592
593 if (proc.max < proc.spare) {
594 return nxt_conf_vldt_error(vldt, "The \"spare\" number must be "
595 "lower than \"max\".");
596 }
597 }
598
599 if (proc.idle_timeout < 0) {
600 return nxt_conf_vldt_error(vldt, "The \"idle_timeout\" number must not "
601 "be negative.");
602 }
603
604 if (proc.idle_timeout > NXT_INT32_T_MAX / 1000) {
605 return nxt_conf_vldt_error(vldt, "The \"idle_timeout\" number must not "
606 "not exceed %d.", NXT_INT32_T_MAX / 1000);
607 }
608
609 return NXT_OK;
610}
611
612
613static nxt_int_t
479nxt_conf_vldt_object_iterator(nxt_conf_validation_t *vldt,
480 nxt_conf_value_t *value, void *data)
481{
482 uint32_t index;
483 nxt_int_t ret;
484 nxt_str_t name;
485 nxt_conf_value_t *member;
486 nxt_conf_vldt_member_t validator;

--- 85 unchanged lines hidden ---
614nxt_conf_vldt_object_iterator(nxt_conf_validation_t *vldt,
615 nxt_conf_value_t *value, void *data)
616{
617 uint32_t index;
618 nxt_int_t ret;
619 nxt_str_t name;
620 nxt_conf_value_t *member;
621 nxt_conf_vldt_member_t validator;

--- 85 unchanged lines hidden ---