174
177
static cond_result_t config_check_cond_nocache(server *srv, connection *con, data_config *dc) {
176
179
server_socket *srv_sock = con->srv_socket;
177
181
/* check parent first */
178
182
if (dc->parent && dc->parent->context_ndx) {
184
* a nested conditional
186
* if the parent is not decided yet or false, we can't be true either
179
188
if (con->conf.log_condition_handling) {
180
189
log_error_write(srv, __FILE__, __LINE__, "sb", "go parent", dc->parent->key);
182
if (config_check_cond_cached(srv, con, dc->parent) == COND_RESULT_FALSE) {
192
switch (config_check_cond_cached(srv, con, dc->parent)) {
193
case COND_RESULT_FALSE:
183
194
return COND_RESULT_FALSE;
195
case COND_RESULT_UNSET:
196
return COND_RESULT_UNSET;
206
* we can only be executed, if all of our previous brothers
188
209
if (con->conf.log_condition_handling) {
189
210
log_error_write(srv, __FILE__, __LINE__, "sb", "go prev", dc->prev->key);
191
213
/* make sure prev is checked first */
192
214
config_check_cond_cached(srv, con, dc->prev);
193
216
/* one of prev set me to FALSE */
194
if (COND_RESULT_FALSE == con->cond_cache[dc->context_ndx].result) {
195
return COND_RESULT_FALSE;
217
switch (con->cond_cache[dc->context_ndx].result) {
218
case COND_RESULT_FALSE:
219
return con->cond_cache[dc->context_ndx].result;
225
if (!con->conditional_is_valid[dc->comp]) {
226
if (con->conf.log_condition_handling) {
227
log_error_write(srv, __FILE__, __LINE__, "dss",
230
con->conditional_is_valid[dc->comp] ? "yeah" : "nej");
233
return COND_RESULT_UNSET;
199
236
/* pass the rules */
458
caches[dc->context_ndx].comp_type = dc->comp;
420
460
if (con->conf.log_condition_handling) {
421
461
log_error_write(srv, __FILE__, __LINE__, "dss", dc->context_ndx,
422
462
"(uncached) result:",
423
caches[dc->context_ndx].result == COND_RESULT_TRUE ? "true" : "false");
463
caches[dc->context_ndx].result == COND_RESULT_UNSET ? "unknown" :
464
(caches[dc->context_ndx].result == COND_RESULT_TRUE ? "true" : "false"));
426
467
if (con->conf.log_condition_handling) {
427
468
log_error_write(srv, __FILE__, __LINE__, "dss", dc->context_ndx,
428
469
"(cached) result:",
429
caches[dc->context_ndx].result == COND_RESULT_TRUE ? "true" : "false");
470
caches[dc->context_ndx].result == COND_RESULT_UNSET ? "unknown" :
471
(caches[dc->context_ndx].result == COND_RESULT_TRUE ? "true" : "false"));
432
474
return caches[dc->context_ndx].result;
478
* reset the config-cache for a named item
480
* if the item is COND_LAST_ELEMENT we reset all items
482
void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item) {
485
for (i = 0; i < srv->config_context->used; i++) {
486
if (item == COMP_LAST_ELEMENT ||
487
con->cond_cache[i].comp_type == item) {
488
con->cond_cache[i].result = COND_RESULT_UNSET;
489
con->cond_cache[i].patterncount = 0;
490
con->cond_cache[i].comp_value = NULL;
496
* reset the config cache to its initial state at connection start
435
498
void config_cond_cache_reset(server *srv, connection *con) {
436
#if COND_RESULT_UNSET
439
for (i = srv->config_context->used - 1; i >= 0; i --) {
440
con->cond_cache[i].result = COND_RESULT_UNSET;
441
con->cond_cache[i].patterncount = 0;
501
config_cond_cache_reset_all_items(srv, con);
503
for (i = 0; i < COMP_LAST_ELEMENT; i++) {
504
con->conditional_is_valid[i] = 0;
444
memset(con->cond_cache, 0, sizeof(cond_cache_t) * srv->config_context->used);
448
508
int config_check_cond(server *srv, connection *con, data_config *dc) {