xref: /lighttpd1.4/src/plugin_config.h (revision ed2c6983)
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 void config_init(server *srv);
54 
55 __attribute_cold__
56 void config_print(server *srv);
57 
58 __attribute_cold__
59 int config_read(server *srv, const char *fn);
60 
61 __attribute_cold__
62 int config_set_defaults(server *srv);
63 
64 __attribute_cold__
65 int config_finalize(server *srv, const buffer *default_server_tag);
66 
67 __attribute_cold__
68 void config_free(server *srv);
69 
70 __attribute_cold__
71 int config_log_error_open(server *srv);
72 
73 __attribute_cold__
74 void config_log_error_close(server *srv);
75 
76 void config_reset_config_bytes_sec(void *p);
77 
78 /*void config_reset_config(request_st *r);*//* moved to request_config_reset()*/
79 void config_patch_config(request_st *r);
80 
81 void config_cond_cache_reset(request_st *r);
82 void config_cond_cache_reset_item(request_st *r, comp_key_t item);
83 
84 typedef enum { T_CONFIG_UNSET,
85 		T_CONFIG_STRING,
86 		T_CONFIG_SHORT,
87 		T_CONFIG_INT,
88 		T_CONFIG_BOOL,
89 		T_CONFIG_ARRAY,
90 		T_CONFIG_ARRAY_KVANY,
91 		T_CONFIG_ARRAY_KVARRAY,
92 		T_CONFIG_ARRAY_KVSTRING,
93 		T_CONFIG_ARRAY_VLIST,
94 		T_CONFIG_LOCAL,
95 		T_CONFIG_DEPRECATED,
96 		T_CONFIG_UNSUPPORTED
97 } config_values_type_t;
98 
99 typedef enum { T_CONFIG_SCOPE_UNSET,
100 		T_CONFIG_SCOPE_SERVER,
101 		T_CONFIG_SCOPE_CONNECTION
102 } config_scope_type_t;
103 
104 typedef struct config_plugin_value {
105     int k_id;
106     config_values_type_t vtype;
107     union v_u {
108       void *v;
109       const array *a;
110       const buffer *b;
111       const char *s;
112       unsigned int u;
113       unsigned short int shrt;
114       double d;
115       off_t o;
116       uint32_t u2[2];
117     } v;
118 } config_plugin_value_t;
119 
120 typedef struct {
121     const char *k;
122     uint8_t klen;    /* directives must be <= 255 chars */
123     /*uint8_t k_id;*//*(array index is used for k_id)*/
124     uint8_t ktype;   /* config_values_type_t */
125     uint8_t scope;   /* config_scope_type_t */
126 } config_plugin_keys_t;
127 
128 __attribute_cold__
129 __attribute_pure__
130 int config_plugin_value_tobool(const data_unset *du, int default_value);
131 
132 __attribute_cold__
133 __attribute_pure__
134 int32_t config_plugin_value_to_int32 (const data_unset *du, int32_t default_value);
135 
136 __attribute_cold__
137 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);
138 
139 __attribute_cold__
140 int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname);
141 
142 typedef enum {
143     /* condition not active at the moment because itself or some
144      * pre-condition depends on data not available yet
145      */
146     COND_RESULT_UNSET,
147 
148     /* special "unset" for branches not selected due to pre-conditions
149      * not met (but pre-conditions are not "unset" anymore)
150      */
151     COND_RESULT_SKIP,
152 
153     /* actually evaluated the condition itself */
154     COND_RESULT_FALSE, /* not active */
155     COND_RESULT_TRUE   /* active */
156 } cond_result_t;
157 
158 typedef struct cond_cache_t {
159     /* current result (with preconditions) */
160     int8_t result;        /*(cond_result_t)*/
161     /* result without preconditions (must never be "skip") */
162     int8_t local_result;  /*(cond_result_t)*/
163     int16_t patterncount;
164 } cond_cache_t; /* 8 bytes (2^3) */
165 
166 typedef struct cond_match_t {
167     const buffer *comp_value; /* just a pointer */
168   #if !(defined(_LP64) || defined(__LP64__) || defined(_WIN64)) /*(not 64-bit)*/
169     int dummy_alignment; /*(for alignment in 32-bit)*/
170   #endif
171     int matches[3 * 10];
172 } cond_match_t; /* 128 bytes (2^7) */
173 
174 int config_check_cond(request_st *r, int context_ndx);
175 
176 __attribute_cold__
177 __attribute_pure__
178 int config_feature_bool (const server *srv, const char *feature, int default_value);
179 
180 __attribute_cold__
181 __attribute_pure__
182 int32_t config_feature_int (const server *srv, const char *feature, int32_t default_value);
183 
184 #endif
185