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

📄 mod_proxy.c

📁 最新apache的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
                         "Parsed host %s", New->name);#endif        }        else {            ap_proxy_is_word(New, parms->pool);#if DEBUGGING            fprintf(stderr, "Parsed word %s\n", New->name);#endif        }    }    return NULL;}static const char *    set_proxy_domain(cmd_parms *parms, void *dummy, const char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    if (arg[0] != '.')        return "ProxyDomain: domain name must start with a dot.";    psf->domain = arg;    return NULL;}static const char *    set_proxy_req(cmd_parms *parms, void *dummy, int flag){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    psf->req = flag;    psf->req_set = 1;    return NULL;}static const char *    set_proxy_error_override(cmd_parms *parms, void *dummy, int flag){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    psf->error_override = flag;    psf->error_override_set = 1;    return NULL;}static const char *    set_preserve_host(cmd_parms *parms, void *dummy, int flag){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    psf->preserve_host = flag;    psf->preserve_host_set = 1;    return NULL;}static const char *    set_recv_buffer_size(cmd_parms *parms, void *dummy, const char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    int s = atoi(arg);    if (s < 512 && s != 0) {        return "ProxyReceiveBufferSize must be >= 512 bytes, or 0 for system default.";    }    psf->recv_buffer_size = s;    psf->recv_buffer_size_set = 1;    return NULL;}static const char *    set_io_buffer_size(cmd_parms *parms, void *dummy, const char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    long s = atol(arg);    psf->io_buffer_size = ((s > AP_IOBUFSIZE) ? s : AP_IOBUFSIZE);    psf->io_buffer_size_set = 1;    return NULL;}static const char *    set_max_forwards(cmd_parms *parms, void *dummy, const char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    long s = atol(arg);    if (s < 0) {        return "ProxyMaxForwards must be greater or equal to zero..";    }    psf->maxfwd = s;    psf->maxfwd_set = 1;    return NULL;}static const char*    set_proxy_timeout(cmd_parms *parms, void *dummy, const char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    int timeout;    timeout=atoi(arg);    if (timeout<1) {        return "Proxy Timeout must be at least 1 second.";    }    psf->timeout_set=1;    psf->timeout=apr_time_from_sec(timeout);    return NULL;    }static const char*    set_via_opt(cmd_parms *parms, void *dummy, const char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    if (strcasecmp(arg, "Off") == 0)        psf->viaopt = via_off;    else if (strcasecmp(arg, "On") == 0)        psf->viaopt = via_on;    else if (strcasecmp(arg, "Block") == 0)        psf->viaopt = via_block;    else if (strcasecmp(arg, "Full") == 0)        psf->viaopt = via_full;    else {        return "ProxyVia must be one of: "            "off | on | full | block";    }    psf->viaopt_set = 1;    return NULL;    }static const char*    set_bad_opt(cmd_parms *parms, void *dummy, const char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    if (strcasecmp(arg, "IsError") == 0)        psf->badopt = bad_error;    else if (strcasecmp(arg, "Ignore") == 0)        psf->badopt = bad_ignore;    else if (strcasecmp(arg, "StartBody") == 0)        psf->badopt = bad_body;    else {        return "ProxyBadHeader must be one of: "            "IsError | Ignore | StartBody";    }    psf->badopt_set = 1;    return NULL;    }static void ap_add_per_proxy_conf(server_rec *s, ap_conf_vector_t *dir_config){    proxy_server_conf *sconf = ap_get_module_config(s->module_config,					            &proxy_module);    void **new_space = (void **)apr_array_push(sconf->sec_proxy);        *new_space = dir_config;}static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg){    const char *errmsg;    const char *endp = ap_strrchr_c(arg, '>');    int old_overrides = cmd->override;    char *old_path = cmd->path;    proxy_dir_conf *conf;    ap_conf_vector_t *new_dir_conf = ap_create_per_dir_config(cmd->pool);    regex_t *r = NULL;    const command_rec *thiscmd = cmd->cmd;    const char *err = ap_check_cmd_context(cmd,                                           NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);    if (err != NULL) {        return err;    }    if (endp == NULL) {        return apr_pstrcat(cmd->pool, cmd->cmd->name,                           "> directive missing closing '>'", NULL);    }    arg=apr_pstrndup(cmd->pool, arg, endp-arg);    if (!arg) {        if (thiscmd->cmd_data)            return "<ProxyMatch > block must specify a path";        else            return "<Proxy > block must specify a path";    }    cmd->path = ap_getword_conf(cmd->pool, &arg);    cmd->override = OR_ALL|ACCESS_CONF;    if (!strncasecmp(cmd->path, "proxy:", 6))        cmd->path += 6;    /* XXX Ignore case?  What if we proxy a case-insensitive server?!?      * While we are at it, shouldn't we also canonicalize the entire     * scheme?  See proxy_fixup()     */    if (thiscmd->cmd_data) { /* <ProxyMatch> */        r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED);        if (!r) {            return "Regex could not be compiled";        }    }    else if (!strcmp(cmd->path, "~")) {        cmd->path = ap_getword_conf(cmd->pool, &arg);        if (!cmd->path)            return "<Proxy ~ > block must specify a path";        if (strncasecmp(cmd->path, "proxy:", 6))            cmd->path += 6;        r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED);        if (!r) {            return "Regex could not be compiled";        }    }    /* initialize our config and fetch it */    conf = ap_set_config_vectors(cmd->server, new_dir_conf, cmd->path,                                 &proxy_module, cmd->pool);    errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_dir_conf);    if (errmsg != NULL)        return errmsg;    conf->r = r;    conf->p = cmd->path;    conf->p_is_fnmatch = apr_fnmatch_test(conf->p);    ap_add_per_proxy_conf(cmd->server, new_dir_conf);    if (*arg != '\0') {        return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name,                           "> arguments not (yet) supported.", NULL);    }    cmd->path = old_path;    cmd->override = old_overrides;    return NULL;}static const command_rec proxy_cmds[] ={    AP_INIT_RAW_ARGS("<Proxy", proxysection, NULL, RSRC_CONF,     "Container for directives affecting resources located in the proxied "    "location"),    AP_INIT_RAW_ARGS("<ProxyMatch", proxysection, (void*)1, RSRC_CONF,    "Container for directives affecting resources located in the proxied "    "location, in regular expression syntax"),    AP_INIT_FLAG("ProxyRequests", set_proxy_req, NULL, RSRC_CONF,     "on if the true proxy requests should be accepted"),    AP_INIT_TAKE2("ProxyRemote", add_proxy_noregex, NULL, RSRC_CONF,     "a scheme, partial URL or '*' and a proxy server"),    AP_INIT_TAKE2("ProxyRemoteMatch", add_proxy_regex, NULL, RSRC_CONF,     "a regex pattern and a proxy server"),    AP_INIT_TAKE12("ProxyPass", add_pass, NULL, RSRC_CONF|ACCESS_CONF,     "a virtual path and a URL"),    AP_INIT_TAKE12("ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF|ACCESS_CONF,     "a virtual path and a URL for reverse proxy behaviour"),    AP_INIT_ITERATE("ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF,     "A list of names, hosts or domains to which the proxy will not connect"),    AP_INIT_TAKE1("ProxyReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF,     "Receive buffer size for outgoing HTTP and FTP connections in bytes"),    AP_INIT_TAKE1("ProxyIOBufferSize", set_io_buffer_size, NULL, RSRC_CONF,     "IO buffer size for outgoing HTTP and FTP connections in bytes"),    AP_INIT_TAKE1("ProxyMaxForwards", set_max_forwards, NULL, RSRC_CONF,     "The maximum number of proxies a request may be forwarded through."),    AP_INIT_ITERATE("NoProxy", set_proxy_dirconn, NULL, RSRC_CONF,     "A list of domains, hosts, or subnets to which the proxy will connect directly"),    AP_INIT_TAKE1("ProxyDomain", set_proxy_domain, NULL, RSRC_CONF,     "The default intranet domain name (in absence of a domain in the URL)"),    AP_INIT_ITERATE("AllowCONNECT", set_allowed_ports, NULL, RSRC_CONF,     "A list of ports which CONNECT may connect to"),    AP_INIT_TAKE1("ProxyVia", set_via_opt, NULL, RSRC_CONF,     "Configure Via: proxy header header to one of: on | off | block | full"),    AP_INIT_FLAG("ProxyErrorOverride", set_proxy_error_override, NULL, RSRC_CONF,     "use our error handling pages instead of the servers' we are proxying"),    AP_INIT_FLAG("ProxyPreserveHost", set_preserve_host, NULL, RSRC_CONF,     "on if we should preserve host header while proxying"),    AP_INIT_TAKE1("ProxyTimeout", set_proxy_timeout, NULL, RSRC_CONF,     "Set the timeout (in seconds) for a proxied connection. "     "This overrides the server timeout"),    AP_INIT_TAKE1("ProxyBadHeader", set_bad_opt, NULL, RSRC_CONF,     "How to handle bad header line in response: IsError | Ignore | StartBody"),     {NULL}};APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));static APR_OPTIONAL_FN_TYPE(ssl_proxy_enable) *proxy_ssl_enable = NULL;static APR_OPTIONAL_FN_TYPE(ssl_engine_disable) *proxy_ssl_disable = NULL;PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c){    /*      * if c == NULL just check if the optional function was imported     * else run the optional function so ssl filters are inserted     */    if (proxy_ssl_enable) {        return c ? proxy_ssl_enable(c) : 1;    }    return 0;}PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c){    if (proxy_ssl_disable) {        return proxy_ssl_disable(c);    }    return 0;}static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog,                             apr_pool_t *ptemp, server_rec *s){    proxy_ssl_enable = APR_RETRIEVE_OPTIONAL_FN(ssl_proxy_enable);    proxy_ssl_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable);    return OK;}static void register_hooks(apr_pool_t *p){    /* fixup before mod_rewrite, so that the proxied url will not     * escaped accidentally by our fixup.     */    static const char * const aszSucc[]={ "mod_rewrite.c", NULL };    /* handler */    ap_hook_handler(proxy_handler, NULL, NULL, APR_HOOK_FIRST);    /* filename-to-URI translation */    ap_hook_translate_name(proxy_trans, NULL, NULL, APR_HOOK_FIRST);    /* walk <Proxy > entries and suppress default TRACE behavior */    ap_hook_map_to_storage(proxy_map_location, NULL,NULL, APR_HOOK_FIRST);    /* fixups */    ap_hook_fixups(proxy_fixup, NULL, aszSucc, APR_HOOK_FIRST);    /* post read_request handling */    ap_hook_post_read_request(proxy_detect, NULL, NULL, APR_HOOK_FIRST);    /* post config handling */    ap_hook_post_config(proxy_post_config, NULL, NULL, APR_HOOK_MIDDLE);}module AP_MODULE_DECLARE_DATA proxy_module ={    STANDARD20_MODULE_STUFF,    create_proxy_dir_config,    /* create per-directory config structure */    merge_proxy_dir_config,     /* merge per-directory config structures */    create_proxy_config,	/* create per-server config structure */    merge_proxy_config,		/* merge per-server config structures */    proxy_cmds,			/* command table */    register_hooks};APR_HOOK_STRUCT(	APR_HOOK_LINK(scheme_handler)	APR_HOOK_LINK(canon_handler))APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, scheme_handler,                                      (request_rec *r, proxy_server_conf *conf,                                      char *url, const char *proxyhost,                                      apr_port_t proxyport),(r,conf,url,                                     proxyhost,proxyport),DECLINED)APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, canon_handler,                                      (request_rec *r, char *url),(r,                                     url),DECLINED)APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, fixups,				    (request_rec *r), (r),				    OK, DECLINED)

⌨️ 快捷键说明

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