1 #ifndef INCLUDE_PLUGIN_CONFIG_H
2 #define INCLUDE_PLUGIN_CONFIG_H
3 #include "first.h"
4 
5 #include "base_decls.h"
6 #include "array.h"
7 #include "buffer.h"
8 
9 /**
10  * possible compare ops in the configfile parser
11  */
12 typedef enum {
13 	CONFIG_COND_UNSET,
14 	CONFIG_COND_EQ,      /** == */
15 	CONFIG_COND_MATCH,   /** =~ */
16 	CONFIG_COND_NE,      /** != */
17 	CONFIG_COND_NOMATCH, /** !~ */
18 	CONFIG_COND_ELSE     /** (always true if reached) */
19 } config_cond_t;
20 
21 /**
22  * possible fields to match against
23  */
24 typedef enum {
25 	COMP_UNSET,
26 	COMP_SERVER_SOCKET,
27 	COMP_HTTP_URL,
28 	COMP_HTTP_HOST,
29 	COMP_HTTP_REFERER,        /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/
30 	COMP_HTTP_USER_AGENT,     /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/
31 	COMP_HTTP_LANGUAGE,       /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/
32 	COMP_HTTP_COOKIE,         /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/
33 	COMP_HTTP_REMOTE_IP,
34 	COMP_HTTP_QUERY_STRING,
35 	COMP_HTTP_SCHEME,
36 	COMP_HTTP_REQUEST_METHOD,
37 	COMP_HTTP_REQUEST_HEADER,
38 
39 	COMP_LAST_ELEMENT
40 } comp_key_t;
41 
42 typedef struct {
43 	comp_key_t comp;
44 	config_cond_t cond;
45 	const buffer *string;
46 	const char *comp_key;
47 } config_cond_info;
48 
49 __attribute_cold__
50 void config_get_config_cond_info(config_cond_info *cfginfo, uint32_t idx);
51 
52 __attribute_cold__
53 int config_capture(server *srv, int idx);
54 
55 __attribute_cold__
56 void config_init(server *srv);
57 
58 __attribute_cold__
59 void config_print(server *srv);
60 
61 __attribute_cold__
62 int config_read(server *srv, const char *fn);
63 
64 __attribute_cold__
65 int config_set_defaults(server *srv);
66 
67 __attribute_cold__
68 int config_finalize(server *srv, const buffer *default_server_tag);
69 
70 __attribute_cold__
71 void config_free(server *srv);
72 
73 __attribute_cold__
74 int config_log_error_open(server *srv);
75 
76 __attribute_cold__
77 void config_log_error_close(server *srv);
78 
79 void config_reset_config_bytes_sec(void *p);
80 
81 /*void config_reset_config(request_st *r);*//* moved to request_config_reset()*/
82 void config_patch_config(request_st *r);
83 
84 void config_cond_cache_reset(request_st *r);
85 void config_cond_cache_reset_item(request_st *r, comp_key_t item);
86 
87 typedef enum { T_CONFIG_UNSET,
88 		T_CONFIG_STRING,
89 		T_CONFIG_SHORT,
90 		T_CONFIG_INT,
91 		T_CONFIG_BOOL,
92 		T_CONFIG_ARRAY,
93 		T_CONFIG_ARRAY_KVANY,
94 		T_CONFIG_ARRAY_KVARRAY,
95 		T_CONFIG_ARRAY_KVSTRING,
96 		T_CONFIG_ARRAY_VLIST,
97 		T_CONFIG_LOCAL,
98 		T_CONFIG_DEPRECATED,
99 		T_CONFIG_UNSUPPORTED
100 } config_values_type_t;
101 
102 typedef enum { T_CONFIG_SCOPE_UNSET,
103 		T_CONFIG_SCOPE_SERVER,
104 		T_CONFIG_SCOPE_CONNECTION
105 } config_scope_type_t;
106 
107 typedef struct config_plugin_value {
108     int k_id;
109     config_values_type_t vtype;
110     union v_u {
111       void *v;
112       const array *a;
113       const buffer *b;
114       const char *s;
115       unsigned int u;
116       unsigned short int shrt;
117       double d;
118       off_t o;
119       uint32_t u2[2];
120     } v;
121 } config_plugin_value_t;
122 
123 typedef struct {
124     const char *k;
125     uint8_t klen;    /* directives must be <= 255 chars */
126     /*uint8_t k_id;*//*(array index is used for k_id)*/
127     uint8_t ktype;   /* config_values_type_t */
128     uint8_t scope;   /* config_scope_type_t */
129 } config_plugin_keys_t;
130 
131 __attribute_cold__
132 __attribute_pure__
133 int config_plugin_value_tobool(const data_unset *du, int default_value);
134 
135 __attribute_cold__
136 __attribute_pure__
137 int32_t config_plugin_value_to_int32 (const data_unset *du, int32_t default_value);
138 
139 __attribute_cold__
140 int config_plugin_values_init_block(server * const srv, const array * const ca, const config_plugin_keys_t * const cpk, const char * const mname, config_plugin_value_t *cpv);
141 
142 __attribute_cold__
143 int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname);
144 
145 typedef enum {
146     /* condition not active at the moment because itself or some
147      * pre-condition depends on data not available yet
148      */
149     COND_RESULT_UNSET,
150 
151     /* special "unset" for branches not selected due to pre-conditions
152      * not met (but pre-conditions are not "unset" anymore)
153      */
154     COND_RESULT_SKIP,
155 
156     /* actually evaluated the condition itself */
157     COND_RESULT_FALSE, /* not active */
158     COND_RESULT_TRUE   /* active */
159 } cond_result_t;
160 
161 typedef struct cond_cache_t {
162     /* current result (with preconditions) */
163     int8_t result;        /*(cond_result_t)*/
164     /* result without preconditions (must never be "skip") */
165     int8_t local_result;  /*(cond_result_t)*/
166 } cond_cache_t; /* 2 bytes (2^1) */
167 
168 #ifdef HAVE_PCRE2_H
169 struct pcre2_real_match_data_8; /* declaration */
170 #endif
171 
172 typedef struct cond_match_t {
173     const buffer *comp_value; /* just a pointer */
174  #ifdef HAVE_PCRE2_H
175     struct pcre2_real_match_data_8 *match_data;
176  #endif
177     int captures;
178     void *matches; /* pcre2:(PCRE2_SIZE *), pcre:(int *) */
179 } cond_match_t;
180 
181 int config_check_cond(request_st *r, int context_ndx);
182 
183 __attribute_cold__
184 __attribute_pure__
185 int config_feature_bool (const server *srv, const char *feature, int default_value);
186 
187 __attribute_cold__
188 __attribute_pure__
189 int32_t config_feature_int (const server *srv, const char *feature, int32_t default_value);
190 
191 #endif
192