xref: /lighttpd1.4/src/plugin_config.h (revision 2a7d3a27)
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_PREFIX,  /** =^ */ /*(use ELSE for not-prefix)*/
19 	CONFIG_COND_SUFFIX,  /** =$ */ /*(use ELSE for not-suffix)*/
20 	CONFIG_COND_ELSE     /** (always true if reached) */
21 } config_cond_t;
22 
23 /**
24  * possible fields to match against
25  */
26 typedef enum {
27 	COMP_UNSET,
28 	COMP_SERVER_SOCKET,
29 	COMP_HTTP_URL,
30 	COMP_HTTP_HOST,
31 	COMP_HTTP_REFERER,        /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/
32 	COMP_HTTP_USER_AGENT,     /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/
33 	COMP_HTTP_LANGUAGE,       /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/
34 	COMP_HTTP_COOKIE,         /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/
35 	COMP_HTTP_REMOTE_IP,
36 	COMP_HTTP_QUERY_STRING,
37 	COMP_HTTP_SCHEME,
38 	COMP_HTTP_REQUEST_METHOD,
39 	COMP_HTTP_REQUEST_HEADER,
40 
41 	COMP_LAST_ELEMENT
42 } comp_key_t;
43 
44 typedef struct {
45 	comp_key_t comp;
46 	config_cond_t cond;
47 	const buffer *string;
48 	const char *comp_key;
49 } config_cond_info;
50 
51 __attribute_cold__
52 void config_get_config_cond_info(config_cond_info *cfginfo, uint32_t idx);
53 
54 __attribute_cold__
55 int config_capture(server *srv, int idx);
56 
57 __attribute_cold__
58 void config_init(server *srv);
59 
60 __attribute_cold__
61 void config_print(server *srv);
62 
63 __attribute_cold__
64 int config_read(server *srv, const char *fn);
65 
66 __attribute_cold__
67 int config_set_defaults(server *srv);
68 
69 __attribute_cold__
70 int config_finalize(server *srv, const buffer *default_server_tag);
71 
72 __attribute_cold__
73 void config_free(server *srv);
74 
75 __attribute_cold__
76 int config_log_error_open(server *srv);
77 
78 __attribute_cold__
79 void config_log_error_close(server *srv);
80 
81 void config_reset_config_bytes_sec(void *p);
82 
83 /*void config_reset_config(request_st *r);*//* moved to request_config_reset()*/
84 void config_patch_config(request_st *r);
85 
86 void config_cond_cache_reset(request_st *r);
87 void config_cond_cache_reset_item(request_st *r, comp_key_t item);
88 
89 typedef enum { T_CONFIG_UNSET,
90 		T_CONFIG_STRING,
91 		T_CONFIG_SHORT,
92 		T_CONFIG_INT,
93 		T_CONFIG_BOOL,
94 		T_CONFIG_ARRAY,
95 		T_CONFIG_ARRAY_KVANY,
96 		T_CONFIG_ARRAY_KVARRAY,
97 		T_CONFIG_ARRAY_KVSTRING,
98 		T_CONFIG_ARRAY_VLIST,
99 		T_CONFIG_LOCAL,
100 		T_CONFIG_DEPRECATED,
101 		T_CONFIG_UNSUPPORTED
102 } config_values_type_t;
103 
104 typedef enum { T_CONFIG_SCOPE_UNSET,
105 		T_CONFIG_SCOPE_SERVER,
106 		T_CONFIG_SCOPE_CONNECTION,
107 		T_CONFIG_SCOPE_SOCKET
108 } config_scope_type_t;
109 
110 typedef struct config_plugin_value {
111     int k_id;
112     config_values_type_t vtype;
113     union v_u {
114       void *v;
115       const array *a;
116       const buffer *b;
117       const char *s;
118       unsigned int u;
119       unsigned short int shrt;
120       double d;
121       off_t o;
122       uint32_t u2[2];
123     } v;
124 } config_plugin_value_t;
125 
126 typedef struct {
127     const char *k;
128     uint8_t klen;    /* directives must be <= 255 chars */
129     /*uint8_t k_id;*//*(array index is used for k_id)*/
130     uint8_t ktype;   /* config_values_type_t */
131     uint8_t scope;   /* config_scope_type_t */
132 } config_plugin_keys_t;
133 
134 __attribute_cold__
135 __attribute_pure__
136 int config_plugin_value_tobool(const data_unset *du, int default_value);
137 
138 __attribute_cold__
139 __attribute_pure__
140 int32_t config_plugin_value_to_int32 (const data_unset *du, int32_t default_value);
141 
142 __attribute_cold__
143 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);
144 
145 __attribute_cold__
146 int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname);
147 
148 typedef enum {
149     /* condition not active at the moment because itself or some
150      * pre-condition depends on data not available yet
151      */
152     COND_RESULT_UNSET,
153 
154     /* special "unset" for branches not selected due to pre-conditions
155      * not met (but pre-conditions are not "unset" anymore)
156      */
157     COND_RESULT_SKIP,
158 
159     /* actually evaluated the condition itself */
160     COND_RESULT_FALSE, /* not active */
161     COND_RESULT_TRUE   /* active */
162 } cond_result_t;
163 
164 typedef struct cond_cache_t {
165     /* current result (with preconditions) */
166     int8_t result;        /*(cond_result_t)*/
167     /* result without preconditions (must never be "skip") */
168     int8_t local_result;  /*(cond_result_t)*/
169 } cond_cache_t; /* 2 bytes (2^1) */
170 
171 #ifdef HAVE_PCRE2_H
172 struct pcre2_real_match_data_8; /* declaration */
173 #endif
174 
175 typedef struct cond_match_t {
176     const buffer *comp_value; /* just a pointer */
177  #ifdef HAVE_PCRE2_H
178     struct pcre2_real_match_data_8 *match_data;
179  #endif
180     int captures;
181     void *matches; /* pcre2:(PCRE2_SIZE *), pcre:(int *) */
182 } cond_match_t;
183 
184 int config_check_cond(request_st *r, int context_ndx);
185 
186 __attribute_cold__
187 __attribute_pure__
188 int config_feature_bool (const server *srv, const char *feature, int default_value);
189 
190 __attribute_cold__
191 __attribute_pure__
192 int32_t config_feature_int (const server *srv, const char *feature, int32_t default_value);
193 
194 
195 /**
196  * plugin statistics
197  * convention: key is <module-prefix>.<name>, value is counter
198  *
199  * example:
200  *   fastcgi.backends        = 10
201  *   fastcgi.active-backends = 6
202  *   fastcgi.backend.<key>.load = 24
203  *   fastcgi.backend.<key>....
204  *
205  *   fastcgi.backend.<key>.disconnects = ...
206  */
207 extern array plugin_stats;
208 
209 #define plugin_stats_get_ptr(s, len) \
210         array_get_int_ptr(&plugin_stats, (s), (len))
211 
212 #define plugin_stats_incr(s, len) \
213         (++(*array_get_int_ptr(&plugin_stats, (s), (len))))
214 
215 #define plugin_stats_inc(s) \
216         plugin_stats_incr((s), sizeof(s)-1)
217 
218 #define plugin_stats_decr(s, len) \
219         (--(*array_get_int_ptr(&plugin_stats, (s), (len))))
220 
221 #define plugin_stats_set(s, len, val) \
222         (*array_get_int_ptr(&plugin_stats, (s), (len)) = (val))
223 
224 
225 #endif
226