~ubuntu-branches/ubuntu/jaunty/nginx/jaunty-updates

« back to all changes in this revision

Viewing changes to src/http/modules/ngx_http_map_module.c

  • Committer: Bazaar Package Importer
  • Author(s): Jose Parrella
  • Date: 2007-12-08 11:27:54 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071208112754-23ohg2b1zshkdayw
Tags: 0.5.33-1
* New stable upstream release (Closes: #451173)
* nginx now provides httpd, httpd-cgi virtual packages
  (Closes: #439468, #452025)
* sites-enabled/default link is now provided only on fresh 
  installations (Closes: #432961)
* Updated code for online upgrading of nginx (Closes: #445246)
* Reviewed maintainer scripts for correct behaviour on updates
  (Closes: #452787, #435965)
* Removed debian/nginx.links and debian/preinst.
* Changing Maintainer address to bureado@debian.org.
* Welcoming Fabio Tranchitella <kobold@debian.org> as an nginx 
  uploader for Debian. Thanks for your patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
 
28
28
typedef struct {
29
 
    ngx_hash_t                  hash;
30
 
    ngx_hash_wildcard_t        *dns_wildcards;
 
29
    ngx_hash_combined_t         hash;
31
30
    ngx_int_t                   index;
32
31
    ngx_http_variable_value_t  *default_value;
33
32
    ngx_uint_t                  hostnames;      /* unsigned  hostnames:1 */
142
141
        key = ngx_hash(key, name[i]);
143
142
    }
144
143
 
145
 
    value = NULL;
146
 
 
147
 
    if (map->hash.buckets) {
148
 
        value = ngx_hash_find(&map->hash, key, name, len);
149
 
    }
 
144
    value = ngx_hash_find_combined(&map->hash, key, name, len);
150
145
 
151
146
    if (value) {
152
147
        *v = *value;
153
148
 
154
149
    } else {
155
 
        if (map->dns_wildcards && map->dns_wildcards->hash.buckets) {
156
 
            value = ngx_hash_find_wildcard(map->dns_wildcards, name, len);
157
 
            if (value) {
158
 
                *v = *value;
159
 
 
160
 
            } else {
161
 
                *v = *map->default_value;
162
 
            }
163
 
 
164
 
        } else {
165
 
            *v = *map->default_value;
166
 
        }
 
150
        *v = *map->default_value;
167
151
    }
168
152
 
169
153
    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
170
 
                   "http map: \"%V\" \"%V\"", vv, v);
 
154
                   "http map: \"%v\" \"%v\"", vv, v);
171
155
 
172
156
    return NGX_OK;
173
157
}
282
266
        return rv;
283
267
    }
284
268
 
 
269
    map->default_value = ctx.default_value ? ctx.default_value:
 
270
                                             &ngx_http_variable_null_value;
 
271
 
285
272
    hash.key = ngx_hash_key_lc;
286
273
    hash.max_size = mcf->hash_max_size;
287
274
    hash.bucket_size = mcf->hash_bucket_size;
289
276
    hash.pool = cf->pool;
290
277
 
291
278
    if (ctx.keys.keys.nelts) {
292
 
        hash.hash = &map->hash;
 
279
        hash.hash = &map->hash.hash;
293
280
        hash.temp_pool = NULL;
294
281
 
295
282
        if (ngx_hash_init(&hash, ctx.keys.keys.elts, ctx.keys.keys.nelts)
300
287
        }
301
288
    }
302
289
 
303
 
    map->default_value = ctx.default_value ? ctx.default_value:
304
 
                                             &ngx_http_variable_null_value;
305
 
 
306
 
    if (ctx.keys.dns_wildcards.nelts) {
307
 
 
308
 
        ngx_qsort(ctx.keys.dns_wildcards.elts,
309
 
                  (size_t) ctx.keys.dns_wildcards.nelts,
310
 
                  sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards);
311
 
 
312
 
        hash.hash = NULL;
313
 
        hash.temp_pool = pool;
314
 
 
315
 
        if (ngx_hash_wildcard_init(&hash, ctx.keys.dns_wildcards.elts,
316
 
                                   ctx.keys.dns_wildcards.nelts)
317
 
            != NGX_OK)
318
 
        {
319
 
            ngx_destroy_pool(pool);
320
 
            return NGX_CONF_ERROR;
321
 
        }
322
 
 
323
 
        map->dns_wildcards = (ngx_hash_wildcard_t *) hash.hash;
 
290
    if (ctx.keys.dns_wc_head.nelts) {
 
291
 
 
292
        ngx_qsort(ctx.keys.dns_wc_head.elts,
 
293
                  (size_t) ctx.keys.dns_wc_head.nelts,
 
294
                  sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards);
 
295
 
 
296
        hash.hash = NULL;
 
297
        hash.temp_pool = pool;
 
298
 
 
299
        if (ngx_hash_wildcard_init(&hash, ctx.keys.dns_wc_head.elts,
 
300
                                   ctx.keys.dns_wc_head.nelts)
 
301
            != NGX_OK)
 
302
        {
 
303
            ngx_destroy_pool(pool);
 
304
            return NGX_CONF_ERROR;
 
305
        }
 
306
 
 
307
        map->hash.wc_head = (ngx_hash_wildcard_t *) hash.hash;
 
308
    }
 
309
 
 
310
    if (ctx.keys.dns_wc_tail.nelts) {
 
311
 
 
312
        ngx_qsort(ctx.keys.dns_wc_tail.elts,
 
313
                  (size_t) ctx.keys.dns_wc_tail.nelts,
 
314
                  sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards);
 
315
 
 
316
        hash.hash = NULL;
 
317
        hash.temp_pool = pool;
 
318
 
 
319
        if (ngx_hash_wildcard_init(&hash, ctx.keys.dns_wc_tail.elts,
 
320
                                   ctx.keys.dns_wc_tail.nelts)
 
321
            != NGX_OK)
 
322
        {
 
323
            ngx_destroy_pool(pool);
 
324
            return NGX_CONF_ERROR;
 
325
        }
 
326
 
 
327
        map->hash.wc_tail = (ngx_hash_wildcard_t *) hash.hash;
324
328
    }
325
329
 
326
330
    ngx_destroy_pool(pool);
344
348
static char *
345
349
ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
346
350
{
347
 
    u_char                      ch;
348
351
    ngx_int_t                   rc;
349
352
    ngx_str_t                  *value, file;
350
 
    ngx_uint_t                  i, key, flags;
 
353
    ngx_uint_t                  i, key;
351
354
    ngx_http_map_conf_ctx_t    *ctx;
352
355
    ngx_http_variable_value_t  *var, **vp;
353
356
 
439
442
 
440
443
found:
441
444
 
442
 
    ch = value[0].data[0];
443
 
 
444
 
    if ((ch != '*' && ch != '.') || ctx->hostnames == 0) {
445
 
 
446
 
        if (ngx_strcmp(value[0].data, "default") == 0) {
447
 
 
448
 
            if (ctx->default_value) {
449
 
                ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
450
 
                                   "duplicate default map parameter");
451
 
                return NGX_CONF_ERROR;
452
 
            }
453
 
 
454
 
            ctx->default_value = var;
455
 
 
456
 
            return NGX_CONF_OK;
457
 
        }
458
 
 
459
 
        if (value[0].len && ch == '!') {
460
 
            value[0].len--;
461
 
            value[0].data++;
462
 
        }
463
 
 
464
 
        flags = 0;
465
 
 
466
 
    } else {
467
 
 
468
 
        if ((ch == '*' && (value[0].len < 3 || value[0].data[1] != '.'))
469
 
            || (ch == '.' && value[0].len < 2))
470
 
        {
 
445
    if (ngx_strcmp(value[0].data, "default") == 0) {
 
446
 
 
447
        if (ctx->default_value) {
471
448
            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
472
 
                               "invalid DNS wildcard \"%V\"", &value[0]);
473
 
 
 
449
                               "duplicate default map parameter");
474
450
            return NGX_CONF_ERROR;
475
451
        }
476
452
 
477
 
        flags = NGX_HASH_WILDCARD_KEY;
478
 
    }
479
 
 
480
 
    rc = ngx_hash_add_key(&ctx->keys, &value[0], var, flags);
 
453
        ctx->default_value = var;
 
454
 
 
455
        return NGX_CONF_OK;
 
456
    }
 
457
 
 
458
    if (value[0].len && value[0].data[0] == '!') {
 
459
        value[0].len--;
 
460
        value[0].data++;
 
461
    }
 
462
 
 
463
    rc = ngx_hash_add_key(&ctx->keys, &value[0], var,
 
464
                          (ctx->hostnames) ? NGX_HASH_WILDCARD_KEY : 0);
481
465
 
482
466
    if (rc == NGX_OK) {
483
467
        return NGX_CONF_OK;
484
468
    }
485
469
 
 
470
    if (rc == NGX_DECLINED) {
 
471
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
 
472
                           "invalid hostname or wildcard \"%V\"", &value[0]);
 
473
    }
 
474
 
486
475
    if (rc == NGX_BUSY) {
487
476
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
488
477
                           "conflicting parameter \"%V\"", &value[0]);