/* ** This function maintains backwards compatibility with the old ** environment variables and searches for the most common values: ** http, ftp, news, wais, and gopher */ PUBLIC void HTProxy_getEnvVar (void) { char buf[80]; static const char *accesslist[] = { "http", "ftp", "news", "wais", "gopher", NULL }; const char **access = accesslist; HTTRACE(PROT_TRACE, "Proxy....... Looking for environment variables\n"); while (*access) { BOOL found = NO; char *gateway=NULL; char *proxy=NULL; /* Search for proxy gateways */ if (found == NO) { strcpy(buf, *access); strcat(buf, "_proxy"); if ((proxy = (char *) getenv(buf)) && *proxy) { HTProxy_add(*access, proxy); found = YES; } /* Try the same with upper case */ if (found == NO) { char * up = buf; while ((*up = TOUPPER(*up))) up++; if ((proxy = (char *) getenv(buf)) && *proxy) { HTProxy_add(*access, proxy); found = YES; } } } /* As a last resort, search for gateway servers */ if (found == NO) { strcpy(buf, "WWW_"); strcat(buf, *access); strcat(buf, "_GATEWAY"); if ((gateway = (char *) getenv(buf)) && *gateway) { HTGateway_add(*access, gateway); found = YES; } } ++access; } /* Search for `noproxy' directive */ { char *noproxy = getenv("no_proxy"); if (noproxy && *noproxy) { char *str = NULL; char *strptr; char *name; StrAllocCopy(str, noproxy); /* Get copy we can mutilate */ strptr = str; while ((name = HTNextField(&strptr)) != NULL) { char *portstr = strchr(name, ':'); unsigned port=0; if (portstr) { *portstr++ = '\0'; if (*portstr) port = (unsigned) atoi(portstr); } /* Register it for all access methods */ HTNoProxy_add(name, NULL, port); } HT_FREE(str); } } }
/* Load one line of configuration ** ------------------------------ ** Call this, for example, to load a X resource with config info. ** Returns YES if line OK, else NO */ PUBLIC BOOL HTRule_parseLine (HTList * list, const char * config) { HTRuleOp op; char * line = NULL; char * ptr; char * word1, * word2, * word3; int status; if (!config) return NO; if ((ptr = strchr(config, '#'))) *ptr = '\0'; StrAllocCopy(line, config); /* Get our own copy */ ptr = line; HTTRACE(APP_TRACE, "Rule Parse.. `%s\'\n" _ config ? config : "<null>"); if ((word1 = HTNextField(&ptr)) == NULL) { /* Empty line */ HT_FREE(line); return YES; } if ((word2 = HTNextField(&ptr)) == NULL) { HTTRACE(APP_TRACE, "Rule Parse.. Insufficient operands: `%s\'\n" _ line); HT_FREE(line); return NO; } word3 = HTNextField(&ptr); /* Look for things we recognize */ if (!strcasecomp(word1, "addtype")) { double quality; char * encoding = HTNextField(&ptr); status = ptr ? sscanf(ptr, "%lf", &quality) : 0; HTBind_add(word2, /* suffix */ word3, /* type */ encoding ? encoding : "binary", /* encoding */ NULL, /* cte */ NULL, /* language */ status >= 1? quality : 1.0); /* quality */ } else if (!strcasecomp(word1, "addencoding")) { double quality; status = ptr ? sscanf(ptr, "%lf", &quality) : 0; HTBind_addEncoding(word2, word3, status >= 1 ? quality : 1.0); } else if (!strcasecomp(word1, "addlanguage")) { double quality; status = ptr ? sscanf(ptr, "%lf", &quality) : 0; HTBind_addLanguage(word2, word3, status >= 1 ? quality : 1.0); } else if (!strcasecomp(word1, "presentation")) { HTList * converters = HTFormat_conversion(); double quality, secs, secs_per_byte; status = ptr ? sscanf(ptr,"%lf%lf%lf",&quality,&secs,&secs_per_byte):0; HTPresentation_add(converters, word2, word3, NULL, status >= 1 ? quality : 1.0, status >= 2 ? secs : 0.0, status >= 3 ? secs_per_byte : 0.0); } else if (!strcasecomp(word1, "proxy")) { HTProxy_add(word2, word3); } else if (!strcasecomp(word1, "noproxy")) { int port = 0; status = ptr ? sscanf(ptr, "%d", &port) : 0; HTNoProxy_add(word2, word3, port); } else if (!strcasecomp(word1, "gateway")) { HTGateway_add(word2, word3); } else { op = 0==strcasecomp(word1, "map") ? HT_Map : 0==strcasecomp(word1, "pass") ? HT_Pass : 0==strcasecomp(word1, "fail") ? HT_Fail : HT_Invalid; if (op == HT_Invalid) { HTTRACE(APP_TRACE, "Rule Parse.. Bad or unknown: `%s'\n" _ config); } else HTRule_add(list, op, word2, word3); } HT_FREE(line); return YES; }