static char *
ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{
    u_char                            *data;
    size_t                             len;
    ngx_int_t                          rv;
    ngx_str_t                         *value, v;
    ngx_uint_t                         i, key;
    ngx_http_map_conf_ctx_t           *ctx;
    ngx_http_complex_value_t           cv, *cvp;
    ngx_http_variable_value_t         *var, **vp;
    ngx_http_compile_complex_value_t   ccv;
    ctx = cf->ctx;
    value = cf->args->elts;
    if (cf->args->nelts == 1
        && ngx_strcmp(value[0].data, "hostnames") == 0)
    {
        ctx->hostnames = 1;
        return NGX_CONF_OK;
    } else if (cf->args->nelts != 2) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "invalid number of the map parameters");
        return NGX_CONF_ERROR;
    }
    if (ngx_strcmp(value[0].data, "include") == 0) {
        return ngx_conf_include(cf, dummy, conf);
    }
    key = 0;
    for (i = 0; i < value[1].len; i++) {
        key = ngx_hash(key, value[1].data[i]);
    }
    key %= ctx->keys.hsize;
    vp = ctx->values_hash[key].elts;
    if (vp) {
        for (i = 0; i < ctx->values_hash[key].nelts; i++) {
            if (vp[i]->valid) {
                data = vp[i]->data;
                len = vp[i]->len;
            } else {
                cvp = (ngx_http_complex_value_t *) vp[i]->data;
                data = cvp->value.data;
                len = cvp->value.len;
            }
            if (value[1].len != len) {
                continue;
            }
            if (ngx_strncmp(value[1].data, data, len) == 0) {
                var = vp[i];
                goto found;
            }
        }
    } else {
        if (ngx_array_init(&ctx->values_hash[key], cf->pool, 4,
                           sizeof(ngx_http_variable_value_t *))
            != NGX_OK)
        {
            return NGX_CONF_ERROR;
        }
    }
    var = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_variable_value_t));
    if (var == NULL) {
        return NGX_CONF_ERROR;
    }
    v.len = value[1].len;
    v.data = ngx_pstrdup(ctx->keys.pool, &value[1]);
    if (v.data == NULL) {
        return NGX_CONF_ERROR;
    }
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
    ccv.cf = ctx->cf;
    ccv.value = &v;
    ccv.complex_value = &cv;
    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
        return NGX_CONF_ERROR;
    }
    if (cv.lengths != NULL) {
        cvp = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_complex_value_t));
        if (cvp == NULL) {
            return NGX_CONF_ERROR;
        }
        *cvp = cv;
        var->len = 0;
        var->data = (u_char *) cvp;
        var->valid = 0;
    } else {
        var->len = v.len;
        var->data = v.data;
        var->valid = 1;
    }
    var->no_cacheable = 0;
    var->not_found = 0;
    vp = ngx_array_push(&ctx->values_hash[key]);
    if (vp == NULL) {
        return NGX_CONF_ERROR;
    }
    *vp = var;
found:
    if (ngx_strcmp(value[0].data, "default") == 0) {
        if (ctx->default_value) {
            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                               "duplicate default map parameter");
            return NGX_CONF_ERROR;
        }
        ctx->default_value = var;
        return NGX_CONF_OK;
    }
#if (NGX_PCRE)
    if (value[0].len && value[0].data[0] == '~') {
        ngx_regex_compile_t    rc;
        ngx_http_map_regex_t  *regex;
        u_char                 errstr[NGX_MAX_CONF_ERRSTR];
        regex = ngx_array_push(&ctx->regexes);
        if (regex == NULL) {
            return NGX_CONF_ERROR;
        }
        value[0].len--;
        value[0].data++;
        ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
        if (value[0].data[0] == '*') {
            value[0].len--;
            value[0].data++;
            rc.options = NGX_REGEX_CASELESS;
        }
        rc.pattern = value[0];
        rc.err.len = NGX_MAX_CONF_ERRSTR;
        rc.err.data = errstr;
        regex->regex = ngx_http_regex_compile(ctx->cf, &rc);
        if (regex->regex == NULL) {
            return NGX_CONF_ERROR;
        }
        regex->value = var;
        return NGX_CONF_OK;
    }
#endif
    if (value[0].len && value[0].data[0] == '\\') {
        value[0].len--;
        value[0].data++;
    }
    rv = ngx_hash_add_key(&ctx->keys, &value[0], var,
                          (ctx->hostnames) ? NGX_HASH_WILDCARD_KEY : 0);
    if (rv == NGX_OK) {
        return NGX_CONF_OK;
    }
    if (rv == NGX_DECLINED) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "invalid hostname or wildcard \"%V\"", &value[0]);
    }
    if (rv == NGX_BUSY) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "conflicting parameter \"%V\"", &value[0]);
    }
    return NGX_CONF_ERROR;
}
['static char *\nngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)\n{\n    u_char                            *data;\n    size_t                             len;\n    ngx_int_t                          rv;\n    ngx_str_t                         *value, v;\n    ngx_uint_t                         i, key;\n    ngx_http_map_conf_ctx_t           *ctx;\n    ngx_http_complex_value_t           cv, *cvp;\n    ngx_http_variable_value_t         *var, **vp;\n    ngx_http_compile_complex_value_t   ccv;\n    ctx = cf->ctx;\n    value = cf->args->elts;\n    if (cf->args->nelts == 1\n        && ngx_strcmp(value[0].data, "hostnames") == 0)\n    {\n        ctx->hostnames = 1;\n        return NGX_CONF_OK;\n    } else if (cf->args->nelts != 2) {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           "invalid number of the map parameters");\n        return NGX_CONF_ERROR;\n    }\n    if (ngx_strcmp(value[0].data, "include") == 0) {\n        return ngx_conf_include(cf, dummy, conf);\n    }\n    key = 0;\n    for (i = 0; i < value[1].len; i++) {\n        key = ngx_hash(key, value[1].data[i]);\n    }\n    key %= ctx->keys.hsize;\n    vp = ctx->values_hash[key].elts;\n    if (vp) {\n        for (i = 0; i < ctx->values_hash[key].nelts; i++) {\n            if (vp[i]->valid) {\n                data = vp[i]->data;\n                len = vp[i]->len;\n            } else {\n                cvp = (ngx_http_complex_value_t *) vp[i]->data;\n                data = cvp->value.data;\n                len = cvp->value.len;\n            }\n            if (value[1].len != len) {\n                continue;\n            }\n            if (ngx_strncmp(value[1].data, data, len) == 0) {\n                var = vp[i];\n                goto found;\n            }\n        }\n    } else {\n        if (ngx_array_init(&ctx->values_hash[key], cf->pool, 4,\n                           sizeof(ngx_http_variable_value_t *))\n            != NGX_OK)\n        {\n            return NGX_CONF_ERROR;\n        }\n    }\n    var = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_variable_value_t));\n    if (var == NULL) {\n        return NGX_CONF_ERROR;\n    }\n    v.len = value[1].len;\n    v.data = ngx_pstrdup(ctx->keys.pool, &value[1]);\n    if (v.data == NULL) {\n        return NGX_CONF_ERROR;\n    }\n    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));\n    ccv.cf = ctx->cf;\n    ccv.value = &v;\n    ccv.complex_value = &cv;\n    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {\n        return NGX_CONF_ERROR;\n    }\n    if (cv.lengths != NULL) {\n        cvp = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_complex_value_t));\n        if (cvp == NULL) {\n            return NGX_CONF_ERROR;\n        }\n        *cvp = cv;\n        var->len = 0;\n        var->data = (u_char *) cvp;\n        var->valid = 0;\n    } else {\n        var->len = v.len;\n        var->data = v.data;\n        var->valid = 1;\n    }\n    var->no_cacheable = 0;\n    var->not_found = 0;\n    vp = ngx_array_push(&ctx->values_hash[key]);\n    if (vp == NULL) {\n        return NGX_CONF_ERROR;\n    }\n    *vp = var;\nfound:\n    if (ngx_strcmp(value[0].data, "default") == 0) {\n        if (ctx->default_value) {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               "duplicate default map parameter");\n            return NGX_CONF_ERROR;\n        }\n        ctx->default_value = var;\n        return NGX_CONF_OK;\n    }\n#if (NGX_PCRE)\n    if (value[0].len && value[0].data[0] == \'~\') {\n        ngx_regex_compile_t    rc;\n        ngx_http_map_regex_t  *regex;\n        u_char                 errstr[NGX_MAX_CONF_ERRSTR];\n        regex = ngx_array_push(&ctx->regexes);\n        if (regex == NULL) {\n            return NGX_CONF_ERROR;\n        }\n        value[0].len--;\n        value[0].data++;\n        ngx_memzero(&rc, sizeof(ngx_regex_compile_t));\n        if (value[0].data[0] == \'*\') {\n            value[0].len--;\n            value[0].data++;\n            rc.options = NGX_REGEX_CASELESS;\n        }\n        rc.pattern = value[0];\n        rc.err.len = NGX_MAX_CONF_ERRSTR;\n        rc.err.data = errstr;\n        regex->regex = ngx_http_regex_compile(ctx->cf, &rc);\n        if (regex->regex == NULL) {\n            return NGX_CONF_ERROR;\n        }\n        regex->value = var;\n        return NGX_CONF_OK;\n    }\n#endif\n    if (value[0].len && value[0].data[0] == \'\\\\\') {\n        value[0].len--;\n        value[0].data++;\n    }\n    rv = ngx_hash_add_key(&ctx->keys, &value[0], var,\n                          (ctx->hostnames) ? NGX_HASH_WILDCARD_KEY : 0);\n    if (rv == NGX_OK) {\n        return NGX_CONF_OK;\n    }\n    if (rv == NGX_DECLINED) {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           "invalid hostname or wildcard \\"%V\\"", &value[0]);\n    }\n    if (rv == NGX_BUSY) {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           "conflicting parameter \\"%V\\"", &value[0]);\n    }\n    return NGX_CONF_ERROR;\n}']