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

📄 mod_proxy.c

📁 apache简化版
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (sscanf(q + 1, "%u", &port) != 1 || port > 65535)	    return "ProxyRemote: Bad syntax for a remote proxy server (bad port number)";	*q = '\0';    }    else	port = -1;    *p = '\0';    if (strchr(f, ':') == NULL)	ap_str_tolower(f);		/* lowercase scheme */    ap_str_tolower(p + 3);		/* lowercase hostname */    if (port == -1) {	int i;	for (i = 0; defports[i].scheme != NULL; i++)	    if (strcasecmp(defports[i].scheme, r) == 0)		break;	port = defports[i].port;    }    new = ap_push_array(conf->proxies);    new->scheme = f;    new->protocol = r;    new->hostname = p + 3;    new->port = port;    return NULL;}static const char *     add_pass(cmd_parms *cmd, void *dummy, char *f, char *r){    server_rec *s = cmd->server;    proxy_server_conf *conf =    (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);    struct proxy_alias *new;    new = ap_push_array(conf->aliases);    new->fake = f;    new->real = r;    return NULL;}static const char *    add_pass_reverse(cmd_parms *cmd, void *dummy, char *f, char *r){    server_rec *s = cmd->server;    proxy_server_conf *conf;    struct proxy_alias *new;    conf = (proxy_server_conf *)ap_get_module_config(s->module_config,                                                   &proxy_module);    new = ap_push_array(conf->raliases);    new->fake = f;    new->real = r;    return NULL;}static const char *     set_proxy_exclude(cmd_parms *parms, void *dummy, char *arg){    server_rec *s = parms->server;    proxy_server_conf *conf =    ap_get_module_config(s->module_config, &proxy_module);    struct noproxy_entry *new;    struct noproxy_entry *list = (struct noproxy_entry *) conf->noproxies->elts;    struct hostent hp;    int found = 0;    int i;    /* Don't duplicate entries */    for (i = 0; i < conf->noproxies->nelts; i++) {	if (strcasecmp(arg, list[i].name) == 0) /* ignore case for host names */	    found = 1;    }    if (!found) {	new = ap_push_array(conf->noproxies);	new->name = arg;	/* Don't do name lookups on things that aren't dotted */	if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL)	    /*@@@FIXME: This copies only the first of (possibly many) IP addrs */	    memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));	else	    new->addr.s_addr = 0;    }    return NULL;}/* * Set the ports CONNECT can use */static const char *    set_allowed_ports(cmd_parms *parms, void *dummy, char *arg){    server_rec *s = parms->server;    proxy_server_conf *conf =      ap_get_module_config(s->module_config, &proxy_module);    int *New;    if (!isdigit(arg[0]))	return "AllowCONNECT: port number must be numeric";    New = ap_push_array(conf->allowed_connect_ports);    *New = atoi(arg);    return NULL;}/* Similar to set_proxy_exclude(), but defining directly connected hosts, * which should never be accessed via the configured ProxyRemote servers */static const char *     set_proxy_dirconn(cmd_parms *parms, void *dummy, char *arg){    server_rec *s = parms->server;    proxy_server_conf *conf =    ap_get_module_config(s->module_config, &proxy_module);    struct dirconn_entry *New;    struct dirconn_entry *list = (struct dirconn_entry *) conf->dirconn->elts;    int found = 0;    int i;    /* Don't duplicate entries */    for (i = 0; i < conf->dirconn->nelts; i++) {	if (strcasecmp(arg, list[i].name) == 0)	    found = 1;    }    if (!found) {	New = ap_push_array(conf->dirconn);	New->name = arg;	New->hostentry = NULL;	if (ap_proxy_is_ipaddr(New, parms->pool)) {#if DEBUGGING	    fprintf(stderr, "Parsed addr %s\n", inet_ntoa(New->addr));	    fprintf(stderr, "Parsed mask %s\n", inet_ntoa(New->mask));#endif	}	else if (ap_proxy_is_domainname(New, parms->pool)) {	    ap_str_tolower(New->name);#if DEBUGGING	    fprintf(stderr, "Parsed domain %s\n", New->name);#endif	}	else if (ap_proxy_is_hostname(New, parms->pool)) {	    ap_str_tolower(New->name);#if DEBUGGING	    fprintf(stderr, "Parsed host %s\n", 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, 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;    return NULL;}static const char *     set_cache_size(cmd_parms *parms, char *struct_ptr, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    int val;    if (sscanf(arg, "%d", &val) != 1)	return "CacheSize value must be an integer (kBytes)";    psf->cache.space = val;    return NULL;}static const char *     set_cache_root(cmd_parms *parms, void *dummy, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    psf->cache.root = arg;    return NULL;}static const char *     set_cache_factor(cmd_parms *parms, void *dummy, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    double val;    if (sscanf(arg, "%lg", &val) != 1)	return "CacheLastModifiedFactor value must be a float";    psf->cache.lmfactor = val;    return NULL;}static const char *     set_cache_maxex(cmd_parms *parms, void *dummy, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    double val;    if (sscanf(arg, "%lg", &val) != 1)	return "CacheMaxExpire value must be a float";    psf->cache.maxexpire = (int) (val * (double) SEC_ONE_HR);    return NULL;}static const char *     set_cache_defex(cmd_parms *parms, void *dummy, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    double val;    if (sscanf(arg, "%lg", &val) != 1)	return "CacheDefaultExpire value must be a float";    psf->cache.defaultexpire = (int) (val * (double) SEC_ONE_HR);    return NULL;}static const char *     set_cache_gcint(cmd_parms *parms, void *dummy, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    double val;    if (sscanf(arg, "%lg", &val) != 1)	return "CacheGcInterval value must be a float";    psf->cache.gcinterval = (int) (val * (double) SEC_ONE_HR);    return NULL;}static const char *     set_cache_dirlevels(cmd_parms *parms, char *struct_ptr, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    int val;    val = atoi(arg);    if (val < 1)	return "CacheDirLevels value must be an integer greater than 0";    if (val * psf->cache.dirlength > CACHEFILE_LEN)	return "CacheDirLevels*CacheDirLength value must not be higher than 20";    psf->cache.dirlevels = val;    return NULL;}static const char *     set_cache_dirlength(cmd_parms *parms, char *struct_ptr, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    int val;    val = atoi(arg);    if (val < 1)	return "CacheDirLength value must be an integer greater than 0";    if (val * psf->cache.dirlevels > CACHEFILE_LEN)	return "CacheDirLevels*CacheDirLength value must not be higher than 20";    psf->cache.dirlength = val;    return NULL;}static const char *     set_cache_exclude(cmd_parms *parms, void *dummy, char *arg){    server_rec *s = parms->server;    proxy_server_conf *conf =    ap_get_module_config(s->module_config, &proxy_module);    struct nocache_entry *new;    struct nocache_entry *list = (struct nocache_entry *) conf->nocaches->elts;    struct hostent hp;    int found = 0;    int i;    /* Don't duplicate entries */    for (i = 0; i < conf->nocaches->nelts; i++) {	if (strcasecmp(arg, list[i].name) == 0) /* ignore case for host names */	    found = 1;    }    if (!found) {	new = ap_push_array(conf->nocaches);	new->name = arg;	/* Don't do name lookups on things that aren't dotted */	if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL)	    /*@@@FIXME: This copies only the first of (possibly many) IP addrs */	    memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));	else	    new->addr.s_addr = 0;    }    return NULL;}static const char *     set_recv_buffer_size(cmd_parms *parms, void *dummy, 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;    return NULL;}static const char*    set_cache_completion(cmd_parms *parms, void *dummy, char *arg){    proxy_server_conf *psf =    ap_get_module_config(parms->server->module_config, &proxy_module);    int s = atoi(arg);    if (s > 100 || s < 0) {	return "CacheForceCompletion must be <= 100 percent, "               "or 0 for system default.";    }    if (s > 0)      psf->cache.cache_completion = ((float)s / 100);    return NULL;    }static const char*    set_via_opt(cmd_parms *parms, void *dummy, 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";    }    return NULL;    }static const handler_rec proxy_handlers[] ={    {"proxy-server", proxy_handler},    {NULL}};static const command_rec proxy_cmds[] ={    {"ProxyRequests", set_proxy_req, NULL, RSRC_CONF, FLAG,     "on if the true proxy requests should be accepted"},    {"ProxyRemote", add_proxy, NULL, RSRC_CONF, TAKE2,     "a scheme, partial URL or '*' and a proxy server"},    {"ProxyPass", add_pass, NULL, RSRC_CONF, TAKE2,     "a virtual path and a URL"},    {"ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF, TAKE2,     "a virtual path and a URL for reverse proxy behaviour"},    {"ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF, ITERATE,     "A list of names, hosts or domains to which the proxy will not connect"},    {"ProxyReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF, TAKE1,     "Receive buffer size for outgoing HTTP and FTP connections in bytes"},    {"NoProxy", set_proxy_dirconn, NULL, RSRC_CONF, ITERATE,     "A list of domains, hosts, or subnets to which the proxy will connect directly"},    {"ProxyDomain", set_proxy_domain, NULL, RSRC_CONF, TAKE1,     "The default intranet domain name (in absence of a domain in the URL)"},    {"AllowCONNECT", set_allowed_ports, NULL, RSRC_CONF, ITERATE,     "A list of ports which CONNECT may connect to"},    {"CacheRoot", set_cache_root, NULL, RSRC_CONF, TAKE1,     "The directory to store cache files"},    {"CacheSize", set_cache_size, NULL, RSRC_CONF, TAKE1,     "The maximum disk space used by the cache in Kb"},    {"CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF, TAKE1,     "The maximum time in hours to cache a document"},    {"CacheDefaultExpire", set_cache_defex, NULL, RSRC_CONF, TAKE1,     "The default time in hours to cache a document"},    {"CacheLastModifiedFactor", set_cache_factor, NULL, RSRC_CONF, TAKE1,     "The factor used to estimate Expires date from LastModified date"},    {"CacheGcInterval", set_cache_gcint, NULL, RSRC_CONF, TAKE1,     "The interval between garbage collections, in hours"},    {"CacheDirLevels", set_cache_dirlevels, NULL, RSRC_CONF, TAKE1,     "The number of levels of subdirectories in the cache"},    {"CacheDirLength", set_cache_dirlength, NULL, RSRC_CONF, TAKE1,     "The number of characters in subdirectory names"},    {"NoCache", set_cache_exclude, NULL, RSRC_CONF, ITERATE,     "A list of names, hosts or domains for which caching is *not* provided"},    {"CacheForceCompletion", set_cache_completion, NULL, RSRC_CONF, TAKE1,     "Force a http cache completion after this percentage is loaded"},    {"ProxyVia", set_via_opt, NULL, RSRC_CONF, TAKE1,     "Configure Via: proxy header header to one of: on | off | block | full"},    {NULL}};module MODULE_VAR_EXPORT proxy_module ={    STANDARD_MODULE_STUFF,    proxy_init,			/* initializer */    NULL,			/* create per-directory config structure */    NULL,			/* merge per-directory config structures */    create_proxy_config,	/* create per-server config structure */    NULL,			/* merge per-server config structures */    proxy_cmds,			/* command table */    proxy_handlers,		/* handlers */    proxy_trans,		/* translate_handler */    NULL,			/* check_user_id */    NULL,			/* check auth */    NULL,			/* check access */    NULL,			/* type_checker */    proxy_fixup,		/* pre-run fixups */    NULL,			/* logger */    NULL,			/* header parser */    NULL,			/* child_init */    NULL,			/* child_exit */    proxy_detect		/* post read-request */};

⌨️ 快捷键说明

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