xref: /lighttpd1.4/src/plugin_config.h (revision fda01e33)
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 buffer *comp_tag;
47 	const buffer *comp_key;
48 	const char *op;
49 } config_cond_info;
50 
51 __attribute_cold__
52 void config_get_config_cond_info(server *srv, uint32_t idx, config_cond_info *cfginfo);
53 
54 __attribute_cold__
55 void config_init(server *srv);
56 
57 __attribute_cold__
58 void config_print(server *srv);
59 
60 __attribute_cold__
61 int config_read(server *srv, const char *fn);
62 
63 __attribute_cold__
64 int config_set_defaults(server *srv);
65 
66 __attribute_cold__
67 int config_finalize(server *srv, const buffer *default_server_tag);
68 
69 __attribute_cold__
70 void config_free(server *srv);
71 
72 __attribute_cold__
73 int config_log_error_open(server *srv);
74 
75 __attribute_cold__
76 void config_log_error_cycle(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(connection *con);
84 void config_patch_config(connection *con);
85 
86 void config_cond_cache_reset(connection *con);
87 void config_cond_cache_reset_item(connection *con, 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 } config_scope_type_t;
108 
109 typedef struct config_plugin_value {
110     int k_id;
111     config_values_type_t vtype;
112     union v_u {
113       void *v;
114       const array *a;
115       const buffer *b;
116       const char *s;
117       unsigned int u;
118       unsigned short int shrt;
119       double d;
120       off_t o;
121       uint32_t u2[2];
122     } v;
123 } config_plugin_value_t;
124 
125 typedef struct {
126     const char *k;
127     uint8_t klen;    /* directives must be <= 255 chars */
128     /*uint8_t k_id;*//*(array index is used for k_id)*/
129     uint8_t ktype;   /* config_values_type_t */
130     uint8_t scope;   /* config_scope_type_t */
131 } config_plugin_keys_t;
132 
133 __attribute_cold__
134 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);
135 
136 __attribute_cold__
137 int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname);
138 
139 typedef enum {
140     /* condition not active at the moment because itself or some
141      * pre-condition depends on data not available yet
142      */
143     COND_RESULT_UNSET,
144 
145     /* special "unset" for branches not selected due to pre-conditions
146      * not met (but pre-conditions are not "unset" anymore)
147      */
148     COND_RESULT_SKIP,
149 
150     /* actually evaluated the condition itself */
151     COND_RESULT_FALSE, /* not active */
152     COND_RESULT_TRUE   /* active */
153 } cond_result_t;
154 
155 typedef struct cond_cache_t {
156     /* current result (with preconditions) */
157     int8_t result;        /*(cond_result_t)*/
158     /* result without preconditions (must never be "skip") */
159     int8_t local_result;  /*(cond_result_t)*/
160     int16_t patterncount;
161 } cond_cache_t; /* 8 bytes (2^3) */
162 
163 typedef struct cond_match_t {
164     const buffer *comp_value; /* just a pointer */
165   #if !(defined(_LP64) || defined(__LP64__) || defined(_WIN64)) /*(not 64-bit)*/
166     int dummy_alignment; /*(for alignment in 32-bit)*/
167   #endif
168     int matches[3 * 10];
169 } cond_match_t; /* 128 bytes (2^7) */
170 
171 int config_check_cond(connection *con, int context_ndx);
172 
173 #endif
174