xref: /lighttpd1.4/src/plugin_config.h (revision cf3e3012)
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_cycle(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);
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 int config_plugin_value_tobool(const data_unset *du, int default_value);
133 
134 __attribute_cold__
135 int32_t config_plugin_value_to_int32 (const data_unset *du, int32_t default_value);
136 
137 __attribute_cold__
138 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);
139 
140 __attribute_cold__
141 int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname);
142 
143 typedef enum {
144     /* condition not active at the moment because itself or some
145      * pre-condition depends on data not available yet
146      */
147     COND_RESULT_UNSET,
148 
149     /* special "unset" for branches not selected due to pre-conditions
150      * not met (but pre-conditions are not "unset" anymore)
151      */
152     COND_RESULT_SKIP,
153 
154     /* actually evaluated the condition itself */
155     COND_RESULT_FALSE, /* not active */
156     COND_RESULT_TRUE   /* active */
157 } cond_result_t;
158 
159 typedef struct cond_cache_t {
160     /* current result (with preconditions) */
161     int8_t result;        /*(cond_result_t)*/
162     /* result without preconditions (must never be "skip") */
163     int8_t local_result;  /*(cond_result_t)*/
164     int16_t patterncount;
165 } cond_cache_t; /* 8 bytes (2^3) */
166 
167 typedef struct cond_match_t {
168     const buffer *comp_value; /* just a pointer */
169   #if !(defined(_LP64) || defined(__LP64__) || defined(_WIN64)) /*(not 64-bit)*/
170     int dummy_alignment; /*(for alignment in 32-bit)*/
171   #endif
172     int matches[3 * 10];
173 } cond_match_t; /* 128 bytes (2^7) */
174 
175 int config_check_cond(request_st *r, int context_ndx);
176 
177 #endif
178