~ubuntu-branches/ubuntu/hardy/lighttpd/hardy

« back to all changes in this revision

Viewing changes to src/configfile-glue.c

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2007-09-05 09:30:15 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070905093015-pm98jekbu9ylcd3w
Tags: 1.4.17-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Update maintainer field in debian/control.
  - Build against libgamin-dev rather than libfam-dev (fixes a warning
    during startup)
  - Make sure that upgrades succeed, even if we can't restart lighttpd.
  - Clean environment in init.d script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include "log.h"
7
7
#include "plugin.h"
8
8
 
 
9
#include "configfile.h"
 
10
 
9
11
/**
10
12
 * like all glue code this file contains functions which
11
13
 * are the external interface of lighttpd. The functions
133
135
                        break;
134
136
                }
135
137
        }
 
138
 
136
139
        return 0;
137
140
}
138
141
 
174
177
static cond_result_t config_check_cond_nocache(server *srv, connection *con, data_config *dc) {
175
178
        buffer *l;
176
179
        server_socket *srv_sock = con->srv_socket;
 
180
 
177
181
        /* check parent first */
178
182
        if (dc->parent && dc->parent->context_ndx) {
 
183
                /**
 
184
                 * a nested conditional 
 
185
                 *
 
186
                 * if the parent is not decided yet or false, we can't be true either 
 
187
                 */
179
188
                if (con->conf.log_condition_handling) {
180
189
                        log_error_write(srv, __FILE__, __LINE__,  "sb", "go parent", dc->parent->key);
181
190
                }
182
 
                if (config_check_cond_cached(srv, con, dc->parent) == COND_RESULT_FALSE) {
 
191
 
 
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;
 
197
                default:
 
198
                        break;
184
199
                }
185
200
        }
186
201
 
187
202
        if (dc->prev) {
 
203
                /**
 
204
                 * a else branch
 
205
                 *
 
206
                 * we can only be executed, if all of our previous brothers 
 
207
                 * are false
 
208
                 */
188
209
                if (con->conf.log_condition_handling) {
189
210
                        log_error_write(srv, __FILE__, __LINE__,  "sb", "go prev", dc->prev->key);
190
211
                }
 
212
 
191
213
                /* make sure prev is checked first */
192
214
                config_check_cond_cached(srv, con, dc->prev);
 
215
 
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;
196
 
                }
 
217
                switch (con->cond_cache[dc->context_ndx].result) {
 
218
                case COND_RESULT_FALSE:
 
219
                        return con->cond_cache[dc->context_ndx].result;
 
220
                default:
 
221
                        break;
 
222
                }
 
223
        }
 
224
 
 
225
        if (!con->conditional_is_valid[dc->comp]) {
 
226
                if (con->conf.log_condition_handling) {
 
227
                        log_error_write(srv, __FILE__, __LINE__,  "dss", 
 
228
                                dc->comp,
 
229
                                dc->key->ptr,
 
230
                                con->conditional_is_valid[dc->comp] ? "yeah" : "nej");
 
231
                }
 
232
 
 
233
                return COND_RESULT_UNSET;
197
234
        }
198
235
 
199
236
        /* pass the rules */
385
422
                cache->patterncount = n;
386
423
                if (n > 0) {
387
424
                        cache->comp_value = l;
 
425
                        cache->comp_type  = dc->comp;
388
426
                        return (dc->cond == CONFIG_COND_MATCH) ? COND_RESULT_TRUE : COND_RESULT_FALSE;
389
427
                } else {
390
428
                        /* cache is already cleared */
417
455
                                }
418
456
                        }
419
457
                }
 
458
                caches[dc->context_ndx].comp_type = dc->comp;
 
459
 
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"));
424
465
                }
425
466
        } else {
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"));
430
472
                }
431
473
        }
432
474
        return caches[dc->context_ndx].result;
433
475
}
434
476
 
 
477
/**
 
478
 * reset the config-cache for a named item
 
479
 *
 
480
 * if the item is COND_LAST_ELEMENT we reset all items
 
481
 */
 
482
void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item) {
 
483
        size_t i;
 
484
 
 
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;
 
491
                }
 
492
        }
 
493
}
 
494
 
 
495
/**
 
496
 * reset the config cache to its initial state at connection start
 
497
 */
435
498
void config_cond_cache_reset(server *srv, connection *con) {
436
 
#if COND_RESULT_UNSET
437
499
        size_t i;
438
500
 
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);
 
502
 
 
503
        for (i = 0; i < COMP_LAST_ELEMENT; i++) {
 
504
                con->conditional_is_valid[i] = 0;
442
505
        }
443
 
#else
444
 
        memset(con->cond_cache, 0, sizeof(cond_cache_t) * srv->config_context->used);
445
 
#endif
446
506
}
447
507
 
448
508
int config_check_cond(server *srv, connection *con, data_config *dc) {