nxt_conf_validation.c (678:f05d36cbe461) nxt_conf_validation.c (685:99f3d48664de)
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>

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

31
32#define NXT_CONF_VLDT_NEXT(f) { nxt_null_string, 0, NULL, (f) }
33#define NXT_CONF_VLDT_END { nxt_null_string, 0, NULL, NULL }
34
35
36typedef nxt_int_t (*nxt_conf_vldt_member_t)(nxt_conf_validation_t *vldt,
37 nxt_str_t *name,
38 nxt_conf_value_t *value);
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>

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

31
32#define NXT_CONF_VLDT_NEXT(f) { nxt_null_string, 0, NULL, (f) }
33#define NXT_CONF_VLDT_END { nxt_null_string, 0, NULL, NULL }
34
35
36typedef nxt_int_t (*nxt_conf_vldt_member_t)(nxt_conf_validation_t *vldt,
37 nxt_str_t *name,
38 nxt_conf_value_t *value);
39
39typedef nxt_int_t (*nxt_conf_vldt_element_t)(nxt_conf_validation_t *vldt,
40 nxt_conf_value_t *value);
40typedef nxt_int_t (*nxt_conf_vldt_system_t)(nxt_conf_validation_t *vldt,
41 char *name);
42
43
44static nxt_int_t nxt_conf_vldt_type(nxt_conf_validation_t *vldt,
45 nxt_str_t *name, nxt_conf_value_t *value, nxt_conf_vldt_type_t type);
46static nxt_int_t nxt_conf_vldt_error(nxt_conf_validation_t *vldt,
47 const char *fmt, ...);

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

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);
59static nxt_int_t nxt_conf_vldt_object_iterator(nxt_conf_validation_t *vldt,
60 nxt_conf_value_t *value, void *data);
41typedef nxt_int_t (*nxt_conf_vldt_system_t)(nxt_conf_validation_t *vldt,
42 char *name);
43
44
45static nxt_int_t nxt_conf_vldt_type(nxt_conf_validation_t *vldt,
46 nxt_str_t *name, nxt_conf_value_t *value, nxt_conf_vldt_type_t type);
47static nxt_int_t nxt_conf_vldt_error(nxt_conf_validation_t *vldt,
48 const char *fmt, ...);

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

54static nxt_int_t nxt_conf_vldt_app(nxt_conf_validation_t *vldt,
55 nxt_str_t *name, nxt_conf_value_t *value);
56static nxt_int_t nxt_conf_vldt_object(nxt_conf_validation_t *vldt,
57 nxt_conf_value_t *value, void *data);
58static nxt_int_t nxt_conf_vldt_processes(nxt_conf_validation_t *vldt,
59 nxt_conf_value_t *value, void *data);
60static nxt_int_t nxt_conf_vldt_object_iterator(nxt_conf_validation_t *vldt,
61 nxt_conf_value_t *value, void *data);
62static nxt_int_t nxt_conf_vldt_array_iterator(nxt_conf_validation_t *vldt,
63 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);
65static nxt_int_t nxt_conf_vldt_environment(nxt_conf_validation_t *vldt,
66 nxt_str_t *name, nxt_conf_value_t *value);
64static nxt_int_t nxt_conf_vldt_system(nxt_conf_validation_t *vldt,
65 nxt_conf_value_t *value, void *data);
66static nxt_int_t nxt_conf_vldt_user(nxt_conf_validation_t *vldt, char *name);
67static nxt_int_t nxt_conf_vldt_group(nxt_conf_validation_t *vldt, char *name);
68static nxt_int_t nxt_conf_vldt_environment(nxt_conf_validation_t *vldt,
69 nxt_str_t *name, nxt_conf_value_t *value);
70static nxt_int_t nxt_conf_vldt_argument(nxt_conf_validation_t *vldt,
71 nxt_conf_value_t *value);
67
68
69static nxt_conf_vldt_object_t nxt_conf_vldt_root_members[] = {
70 { nxt_string("listeners"),
71 NXT_CONF_VLDT_OBJECT,
72 &nxt_conf_vldt_object_iterator,
73 (void *) &nxt_conf_vldt_listener },
74

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

217
218
219static nxt_conf_vldt_object_t nxt_conf_vldt_go_members[] = {
220 { nxt_string("executable"),
221 NXT_CONF_VLDT_STRING,
222 NULL,
223 NULL },
224
72
73
74static nxt_conf_vldt_object_t nxt_conf_vldt_root_members[] = {
75 { nxt_string("listeners"),
76 NXT_CONF_VLDT_OBJECT,
77 &nxt_conf_vldt_object_iterator,
78 (void *) &nxt_conf_vldt_listener },
79

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

222
223
224static nxt_conf_vldt_object_t nxt_conf_vldt_go_members[] = {
225 { nxt_string("executable"),
226 NXT_CONF_VLDT_STRING,
227 NULL,
228 NULL },
229
230 { nxt_string("arguments"),
231 NXT_CONF_VLDT_ARRAY,
232 &nxt_conf_vldt_array_iterator,
233 (void *) &nxt_conf_vldt_argument },
234
225 NXT_CONF_VLDT_NEXT(&nxt_conf_vldt_common_members)
226};
227
228
229static nxt_conf_vldt_object_t nxt_conf_vldt_perl_members[] = {
230 { nxt_string("script"),
231 NXT_CONF_VLDT_STRING,
232 NULL,

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

664 if (ret != NXT_OK) {
665 return ret;
666 }
667 }
668}
669
670
671static nxt_int_t
235 NXT_CONF_VLDT_NEXT(&nxt_conf_vldt_common_members)
236};
237
238
239static nxt_conf_vldt_object_t nxt_conf_vldt_perl_members[] = {
240 { nxt_string("script"),
241 NXT_CONF_VLDT_STRING,
242 NULL,

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

674 if (ret != NXT_OK) {
675 return ret;
676 }
677 }
678}
679
680
681static nxt_int_t
682nxt_conf_vldt_array_iterator(nxt_conf_validation_t *vldt,
683 nxt_conf_value_t *value, void *data)
684{
685 uint32_t index;
686 nxt_int_t ret;
687 nxt_conf_value_t *element;
688 nxt_conf_vldt_element_t validator;
689
690 validator = (nxt_conf_vldt_element_t) data;
691
692 for (index = 0; /* void */ ; index++) {
693 element = nxt_conf_get_array_element(value, index);
694
695 if (element == NULL) {
696 return NXT_OK;
697 }
698
699 ret = validator(vldt, element);
700
701 if (ret != NXT_OK) {
702 return ret;
703 }
704 }
705}
706
707
708static nxt_int_t
672nxt_conf_vldt_system(nxt_conf_validation_t *vldt, nxt_conf_value_t *value,
673 void *data)
674{
675 size_t length;
676 nxt_str_t name;
677 nxt_conf_vldt_system_t validator;
678 char string[32];
679

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

763
764 if (nxt_memchr(str.start, '\0', str.length) != NULL) {
765 return nxt_conf_vldt_error(vldt, "The \"%V\" environment value must "
766 "not contain null character.", name);
767 }
768
769 return NXT_OK;
770}
709nxt_conf_vldt_system(nxt_conf_validation_t *vldt, nxt_conf_value_t *value,
710 void *data)
711{
712 size_t length;
713 nxt_str_t name;
714 nxt_conf_vldt_system_t validator;
715 char string[32];
716

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

800
801 if (nxt_memchr(str.start, '\0', str.length) != NULL) {
802 return nxt_conf_vldt_error(vldt, "The \"%V\" environment value must "
803 "not contain null character.", name);
804 }
805
806 return NXT_OK;
807}
808
809
810static nxt_int_t
811nxt_conf_vldt_argument(nxt_conf_validation_t *vldt, nxt_conf_value_t *value)
812{
813 nxt_str_t str;
814
815 if (nxt_conf_type(value) != NXT_CONF_STRING) {
816 return nxt_conf_vldt_error(vldt, "The \"arguments\" array "
817 "must contain only string values.");
818 }
819
820 nxt_conf_get_string(value, &str);
821
822 if (nxt_memchr(str.start, '\0', str.length) != NULL) {
823 return nxt_conf_vldt_error(vldt, "The \"arguments\" array must not "
824 "contain strings with null character.");
825 }
826
827 return NXT_OK;
828}