xref: /lighttpd1.4/src/plugin_config.h (revision 50bdb55d)
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 void config_reset_config_bytes_sec(void *p);
73 
74 void config_reset_config(connection *con);
75 void config_patch_config(connection *con);
76 
77 void config_cond_cache_reset(connection *con);
78 void config_cond_cache_reset_item(connection *con, comp_key_t item);
79 
80 typedef enum { T_CONFIG_UNSET,
81 		T_CONFIG_STRING,
82 		T_CONFIG_SHORT,
83 		T_CONFIG_INT,
84 		T_CONFIG_BOOL,
85 		T_CONFIG_ARRAY,
86 		T_CONFIG_LOCAL,
87 		T_CONFIG_DEPRECATED,
88 		T_CONFIG_UNSUPPORTED
89 } config_values_type_t;
90 
91 typedef enum { T_CONFIG_SCOPE_UNSET,
92 		T_CONFIG_SCOPE_SERVER,
93 		T_CONFIG_SCOPE_CONNECTION
94 } config_scope_type_t;
95 
96 typedef struct config_plugin_value {
97     int k_id;
98     config_values_type_t vtype;
99     union v_u {
100       void *v;
101       const array *a;
102       const buffer *b;
103       const char *s;
104       unsigned int u;
105       unsigned short int shrt;
106       double d;
107       off_t o;
108       uint32_t u2[2];
109     } v;
110 } config_plugin_value_t;
111 
112 typedef struct {
113     const char *k;
114     uint32_t klen;
115     /*uint32_t k_id;*//*(array index is used for k_id)*/
116     config_values_type_t ktype;
117     config_scope_type_t scope;
118 } config_plugin_keys_t;
119 
120 __attribute_cold__
121 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);
122 
123 __attribute_cold__
124 int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname);
125 
126 typedef enum {
127     /* condition not active at the moment because itself or some
128      * pre-condition depends on data not available yet
129      */
130     COND_RESULT_UNSET,
131 
132     /* special "unset" for branches not selected due to pre-conditions
133      * not met (but pre-conditions are not "unset" anymore)
134      */
135     COND_RESULT_SKIP,
136 
137     /* actually evaluated the condition itself */
138     COND_RESULT_FALSE, /* not active */
139     COND_RESULT_TRUE   /* active */
140 } cond_result_t;
141 
142 typedef struct cond_cache_t {
143     /* current result (with preconditions) */
144     int8_t result;        /*(cond_result_t)*/
145     /* result without preconditions (must never be "skip") */
146     int8_t local_result;  /*(cond_result_t)*/
147     int16_t patterncount;
148 } cond_cache_t; /* 8 bytes (2^3) */
149 
150 typedef struct cond_match_t {
151     const buffer *comp_value; /* just a pointer */
152   #if !(defined(_LP64) || defined(__LP64__) || defined(_WIN64)) /*(not 64-bit)*/
153     int dummy_alignment; /*(for alignment in 32-bit)*/
154   #endif
155     int matches[3 * 10];
156 } cond_match_t; /* 128 bytes (2^7) */
157 
158 int config_check_cond(connection *con, int context_ndx);
159 
160 #endif
161