⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ngx_http_browser_module.c

📁 nginx 反向代理0.7.1版本 用于实现反向代理
💻 C
📖 第 1 页 / 共 2 页
字号:
        }    }    if (cf->ancient_browsers) {        ancient = cf->ancient_browsers->elts;        for (i = 0; i < cf->ancient_browsers->nelts; i++) {            if (len >= ancient[i].len                && ngx_strstr(ua, ancient[i].data) != NULL)            {                return NGX_HTTP_ANCIENT_BROWSER;            }        }    }    if (cf->modern_unlisted_browsers) {        return NGX_HTTP_MODERN_BROWSER;    }    return NGX_HTTP_ANCIENT_BROWSER;}static ngx_int_tngx_http_msie_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,    uintptr_t data){    if (r->headers_in.msie) {        *v = ngx_http_variable_true_value;        return NGX_OK;    }    *v = ngx_http_variable_null_value;    return NGX_OK;}static ngx_int_tngx_http_browser_add_variable(ngx_conf_t *cf){    ngx_http_browser_variable_t   *var;    ngx_http_variable_t           *v;    for (var = ngx_http_browsers; var->name.len; var++) {        v = ngx_http_add_variable(cf, &var->name, NGX_HTTP_VAR_CHANGEABLE);        if (v == NULL) {            return NGX_ERROR;        }        v->get_handler = var->handler;        v->data = var->data;    }    return NGX_OK;}static void *ngx_http_browser_create_conf(ngx_conf_t *cf){    ngx_http_browser_conf_t  *conf;    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_browser_conf_t));    if (conf == NULL) {        return NGX_CONF_ERROR;    }    /*     * set by ngx_pcalloc():     *     *     conf->modern_browsers = NULL;     *     conf->ancient_browsers = NULL;     *     conf->modern_browser_value = NULL;     *     conf->ancient_browser_value = NULL;     *     *     conf->modern_unlisted_browsers = 0;     *     conf->netscape4 = 0;     */    return conf;}static char *ngx_http_browser_merge_conf(ngx_conf_t *cf, void *parent, void *child){    ngx_http_browser_conf_t *prev = parent;    ngx_http_browser_conf_t *conf = child;    ngx_uint_t                  i, n;    ngx_http_modern_browser_t  *browsers, *opera;    /*     * At the merge the skip field is used to store the browser slot,     * it will be used in sorting and then will overwritten     * with a real skip value.  The zero value means Opera.     */    if (conf->modern_browsers == NULL) {        conf->modern_browsers = prev->modern_browsers;    } else {        browsers = conf->modern_browsers->elts;        for (i = 0; i < conf->modern_browsers->nelts; i++) {            if (browsers[i].skip == 0) {                goto found;            }        }        /*         * Opera may contain MSIE string, so if Opera was not enumerated         * as modern browsers, then add it and set a unreachable version         */        opera = ngx_array_push(conf->modern_browsers);        if (opera == NULL) {            return NGX_CONF_ERROR;        }        opera->skip = 0;        opera->version = 4001000000U;        browsers = conf->modern_browsers->elts;found:        ngx_qsort(browsers, (size_t) conf->modern_browsers->nelts,                  sizeof(ngx_http_modern_browser_t),                  ngx_http_modern_browser_sort);        for (i = 0; i < conf->modern_browsers->nelts; i++) {             n = browsers[i].skip;             browsers[i].skip = ngx_http_modern_browser_masks[n].skip;             browsers[i].add = ngx_http_modern_browser_masks[n].add;             (void) ngx_cpystrn(browsers[i].name,                                ngx_http_modern_browser_masks[n].name, 12);        }    }    if (conf->ancient_browsers == NULL) {        conf->ancient_browsers = prev->ancient_browsers;    }    if (conf->modern_browser_value == NULL) {        conf->modern_browser_value = prev->modern_browser_value;    }    if (conf->modern_browser_value == NULL) {        conf->modern_browser_value = &ngx_http_variable_true_value;    }    if (conf->ancient_browser_value == NULL) {        conf->ancient_browser_value = prev->ancient_browser_value;    }    if (conf->ancient_browser_value == NULL) {        conf->ancient_browser_value = &ngx_http_variable_true_value;    }    return NGX_CONF_OK;}static int ngx_libc_cdeclngx_http_modern_browser_sort(const void *one, const void *two){    ngx_http_modern_browser_t *first = (ngx_http_modern_browser_t *) one;    ngx_http_modern_browser_t *second = (ngx_http_modern_browser_t *) two;    return (first->skip - second->skip);}static char *ngx_http_modern_browser(ngx_conf_t *cf, ngx_command_t *cmd, void *conf){    ngx_http_browser_conf_t *bcf = conf;    u_char                           c;    ngx_str_t                       *value;    ngx_uint_t                       i, n, version, ver, scale;    ngx_http_modern_browser_t       *browser;    ngx_http_modern_browser_mask_t  *mask;    value = cf->args->elts;    if (cf->args->nelts == 2) {        if (ngx_strcmp(value[1].data, "unlisted") == 0) {            bcf->modern_unlisted_browsers = 1;            return NGX_CONF_OK;        }        return NGX_CONF_ERROR;    }    if (bcf->modern_browsers == NULL) {        bcf->modern_browsers = ngx_array_create(cf->pool, 5,                                            sizeof(ngx_http_modern_browser_t));        if (bcf->modern_browsers == NULL) {            return NGX_CONF_ERROR;        }    }    browser = ngx_array_push(bcf->modern_browsers);    if (browser == NULL) {        return NGX_CONF_ERROR;    }    mask = ngx_http_modern_browser_masks;    for (n = 0; mask[n].browser[0] != '\0'; n++) {        if (ngx_strcasecmp(mask[n].browser, value[1].data) == 0) {            goto found;        }    }    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,                       "unknown browser name \"%V\"", &value[1]);    return NGX_CONF_ERROR;found:    /*     * at this stage the skip field is used to store the browser slot,     * it will be used in sorting in merge stage and then will overwritten     * with a real value     */    browser->skip = n;    version = 0;    ver = 0;    scale = 1000000;    for (i = 0; i < value[2].len; i++) {        c = value[2].data[i];        if (c >= '0' && c <= '9') {            ver = ver * 10 + (c - '0');            continue;        }        if (c == '.') {            version += ver * scale;            ver = 0;            scale /= 100;            continue;        }        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,                           "invalid browser version \"%V\"", &value[2]);        return NGX_CONF_ERROR;    }    version += ver * scale;    browser->version = version;    return NGX_CONF_OK;}static char *ngx_http_ancient_browser(ngx_conf_t *cf, ngx_command_t *cmd, void *conf){    ngx_http_browser_conf_t *bcf = conf;    ngx_str_t   *value, *browser;    ngx_uint_t   i;    value = cf->args->elts;    for (i = 1; i < cf->args->nelts; i++) {        if (ngx_strcmp(value[i].data, "netscape4") == 0) {            bcf->netscape4 = 1;            continue;        }        if (bcf->ancient_browsers == NULL) {            bcf->ancient_browsers = ngx_array_create(cf->pool, 4,                                                     sizeof(ngx_str_t));            if (bcf->ancient_browsers == NULL) {                return NGX_CONF_ERROR;            }        }        browser = ngx_array_push(bcf->ancient_browsers);        if (browser == NULL) {            return NGX_CONF_ERROR;        }        *browser = value[i];    }    return NGX_CONF_OK;}static char *ngx_http_modern_browser_value(ngx_conf_t *cf, ngx_command_t *cmd, void *conf){    ngx_http_browser_conf_t *bcf = conf;    ngx_str_t  *value;    bcf->modern_browser_value = ngx_palloc(cf->pool,                                           sizeof(ngx_http_variable_value_t));    if (bcf->modern_browser_value == NULL) {        return NGX_CONF_ERROR;    }    value = cf->args->elts;    bcf->modern_browser_value->len = value[1].len;    bcf->modern_browser_value->valid = 1;    bcf->modern_browser_value->no_cacheable = 0;    bcf->modern_browser_value->not_found = 0;    bcf->modern_browser_value->data = value[1].data;    return NGX_CONF_OK;}static char *ngx_http_ancient_browser_value(ngx_conf_t *cf, ngx_command_t *cmd, void *conf){    ngx_http_browser_conf_t *bcf = conf;    ngx_str_t  *value;    bcf->ancient_browser_value = ngx_palloc(cf->pool,                                            sizeof(ngx_http_variable_value_t));    if (bcf->ancient_browser_value == NULL) {        return NGX_CONF_ERROR;    }    value = cf->args->elts;    bcf->ancient_browser_value->len = value[1].len;    bcf->ancient_browser_value->valid = 1;    bcf->ancient_browser_value->no_cacheable = 0;    bcf->ancient_browser_value->not_found = 0;    bcf->ancient_browser_value->data = value[1].data;    return NGX_CONF_OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -