--------------------- PatchSet 1886 Date: 2005/09/27 15:32:07 Author: dwsquid Branch: squid3-icap Tag: (none) Log: ran astyle Members: src/ICAPConfig.cc:1.1.2.1->1.1.2.2 src/ICAPConfig.h:1.1.2.1->1.1.2.2 src/cache_cf.cc:1.52.2.3->1.52.2.4 Index: squid3/src/ICAPConfig.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICAPConfig.cc,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/src/ICAPConfig.cc 27 Sep 2005 15:22:39 -0000 1.1.2.1 +++ squid3/src/ICAPConfig.cc 27 Sep 2005 15:32:07 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: ICAPConfig.cc,v 1.1.2.1 2005/09/27 15:22:39 dwsquid Exp $ + * $Id: ICAPConfig.cc,v 1.1.2.2 2005/09/27 15:32:07 dwsquid Exp $ * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- @@ -48,7 +48,7 @@ if (!strcmp(type_name, "reqmod_precache")) { return SERVICE_REQMOD_PRECACHE; } else if (!strcmp(type_name, "reqmod_postcache")) { - return SERVICE_REQMOD_POSTCACHE; + return SERVICE_REQMOD_POSTCACHE; } else if (!strcmp(type_name, "respmod_precache")) { return SERVICE_RESPMOD_PRECACHE; } else if (!strcmp(type_name, "respmod_postcache")) { @@ -58,7 +58,7 @@ } }; -void +void IcapService::parseConfigLine() { @@ -68,32 +68,35 @@ ConfigParser::ParseString(&uri); }; -int +int IcapService::prepare() { char *s, *e, *t; unsigned int len; int uport; - parseConfigLine(); + parseConfigLine(); debug(3, 5) ("IcapService::prepare (line %d): %s %s %d\n", config_lineno, key, type_name, bypass); - + type = ServiceType(); + if (type >= SERVICE_MAX) { return 0; - } + } if ((type == SERVICE_REQMOD_PRECACHE) || (type == SERVICE_REQMOD_POSTCACHE)) { method = ICAP_METHOD_REQMOD; } else if ((type == SERVICE_RESPMOD_PRECACHE) || (type == SERVICE_RESPMOD_POSTCACHE)) { method = ICAP_METHOD_RESPMOD; } + debug(3, 5) ("IcapService::prepare (line %d): type=%d\n", config_lineno, type); - + if (strncmp(uri, "icap://", 7) != 0) { debug(3, 0) ("IcapService::prepare (line %d): wrong uri: %s\n", config_lineno, uri); return 0; } + s = uri + 7; if ((e = strchr(s, ':')) != NULL) { @@ -103,42 +106,54 @@ } else { return 0; } + len = e - s; hostname = xstrndup(s, len + 1); hostname[len] = '\0'; s = e; + if (uport) { s++; + if ((e = strchr(s, '/')) != NULL) { port = strtoul(s, &t, 0) % 65536; + if (t != e) { return 0; } + s = e; + if (s[0] != '/') { return 0; } } } else { + struct servent *serv = getservbyname("icap", "tcp"); + if (serv) { port = htons(serv->s_port); } else { port = 1344; } } - + s++; e = strchr(s, '\0'); len = e - s; + if (len > 1024) { debug(3, 0) ("icap_service_process (line %d): long resource name (>1024), probably wrong\n", config_lineno); } + resource = xstrndup(s, len + 1); resource[len] = 0; + if ((bypass != 0) && (bypass != 1)) { return 0; } + return 1; }; @@ -147,7 +162,7 @@ IcapClass::prepare() { int found = 0; - List **Tail; + List **Tail; List *service_iter; wordlist *iter; @@ -158,16 +173,18 @@ for (service_iter = TheICAPConfig.services; service_iter; service_iter = service_iter->next) { if (!strcmp(service_iter->element.key, iter->key)) { for (Tail = &services; *Tail; Tail = &((*Tail)->next)) - + ; List * q = new List(service_iter->element); + *(Tail) = q; + found = 1; } } - } - - return found; + } + + return found; }; int @@ -177,19 +194,21 @@ ConfigParser::ParseString(&key); - List *data = TheICAPConfig.classes; + List *data = TheICAPConfig.classes; + while (data != NULL) { - if (!strcmp(data->element.key, key)) { + if (!strcmp(data->element.key, key)) { aclass =& data->element; found = 1; - break; + break; } + data = data->next; } - if (found) { - aclParseAccessLine(&(this->access)); - } + if (found) { + aclParseAccessLine(&(this->access)); + } return found; }; @@ -199,28 +218,32 @@ { List **Tail; IcapService *S = new IcapService(); + if (S->prepare()) { for (Tail = &services; *Tail; Tail = &((*Tail)->next)) - + ; List * q = new List(*S); + *(Tail) = q; } else { delete S; - } + } + return; }; -void +void ICAPConfig::freeIcapService() { delete services; }; -void -ICAPConfig::dumpIcapService(StoreEntry *entry, const char *name) +void +ICAPConfig::dumpIcapService(StoreEntry *entry, const char *name) { - List *data = services; + List *data = services; + while (data != NULL) { storeAppendPrintf(entry, "%s %s %s %d %s\n", name, data->element.key, data->element.type_name, data->element.bypass, data->element.uri); data = data->next; @@ -231,30 +254,33 @@ ICAPConfig::parseIcapClass() { List **Tail; - + IcapClass *C = new IcapClass(); + if (C->prepare()) { for (Tail = &classes; *Tail; Tail = &((*Tail)->next)) - + ; List * q = new List(*C); + *(Tail) = q; } else { delete C; - } + } }; -void +void ICAPConfig::freeIcapClass() { delete classes; }; -void -ICAPConfig::dumpIcapClass(StoreEntry *entry, const char *name) +void +ICAPConfig::dumpIcapClass(StoreEntry *entry, const char *name) { List *data = classes; + while (data != NULL) { storeAppendPrintf(entry, "%s %s\n", name, data->element.key); data = data->next; @@ -267,35 +293,40 @@ List **Tail; IcapAccess *A = new IcapAccess(); + if (A->prepare()) { for (Tail = &accesses; *Tail; Tail = &((*Tail)->next)) - + ; List * q = new List(*A); + *(Tail) = q; } else { delete A; - } + } + return; }; -void +void ICAPConfig::freeIcapAccess() { delete accesses; }; -void -ICAPConfig::dumpIcapAccess(StoreEntry *entry, const char *name) +void +ICAPConfig::dumpIcapAccess(StoreEntry *entry, const char *name) { LOCAL_ARRAY(char, nom, 64); + if (!accesses) { storeAppendPrintf(entry, "%s 0\n", name); return; } List *data = accesses; + while (data != NULL) { snprintf(nom, 64, "%s %s", name, data->element.key); dump_acl_access(entry, nom, data->element.access); @@ -303,7 +334,7 @@ } }; -ICAPConfig::~ICAPConfig() +ICAPConfig::~ICAPConfig() { delete classes; delete services; Index: squid3/src/ICAPConfig.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICAPConfig.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/src/ICAPConfig.h 27 Sep 2005 15:22:39 -0000 1.1.2.1 +++ squid3/src/ICAPConfig.h 27 Sep 2005 15:32:07 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: ICAPConfig.h,v 1.1.2.1 2005/09/27 15:22:39 dwsquid Exp $ + * $Id: ICAPConfig.h,v 1.1.2.2 2005/09/27 15:32:07 dwsquid Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -39,6 +39,7 @@ #include "List.h" class acl_access; + class ICAPConfig; typedef enum { @@ -72,11 +73,13 @@ icap_service_t type; icap_method_t method; - IcapService() : key(NULL), uri(NULL), type_name(NULL) { + IcapService() : key(NULL), uri(NULL), type_name(NULL) + { type = SERVICE_MAX; }; + icap_service_t ServiceType(); - void parseConfigLine(); + void parseConfigLine(); int prepare(); }; @@ -91,7 +94,8 @@ List *services; - IcapClass() : key(NULL), service_names(NULL), services(NULL) {}; + IcapClass() : key(NULL), service_names(NULL), services(NULL) {}; + int prepare(); }; @@ -104,14 +108,15 @@ IcapClass *aclass; acl_access *access; - IcapAccess() + IcapAccess() { key = NULL; aclass = NULL; access = NULL; }; + int prepare(); - + }; class ICAPConfig @@ -131,7 +136,8 @@ List *classes; List *accesses; - ICAPConfig() : services(NULL), classes(NULL), accesses(NULL) {}; + ICAPConfig() : services(NULL), classes(NULL), accesses(NULL) {}; + ~ICAPConfig(); void parseIcapService(void); Index: squid3/src/cache_cf.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/cache_cf.cc,v retrieving revision 1.52.2.3 retrieving revision 1.52.2.4 diff -u -r1.52.2.3 -r1.52.2.4 --- squid3/src/cache_cf.cc 27 Sep 2005 15:18:03 -0000 1.52.2.3 +++ squid3/src/cache_cf.cc 27 Sep 2005 15:32:07 -0000 1.52.2.4 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.52.2.3 2005/09/27 15:18:03 dwsquid Exp $ + * $Id: cache_cf.cc,v 1.52.2.4 2005/09/27 15:32:07 dwsquid Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -56,7 +56,7 @@ #include "ICAPConfig.h" extern ICAPConfig TheICAPConfig; // for cf_parser.h -static void parse_icap_service_type(ICAPConfig *); +static void parse_icap_service_type(ICAPConfig *); static void dump_icap_service_type(StoreEntry *, const char *, ICAPConfig ); static void free_icap_service_type(ICAPConfig *); static void parse_icap_class_type(ICAPConfig *); @@ -2308,10 +2308,10 @@ *var = xstrdup(token); } -void -ConfigParser::ParseString(char **var) -{ - parse_string(var); +void +ConfigParser::ParseString(char **var) +{ + parse_string(var); } static void @@ -2461,10 +2461,10 @@ } void -ConfigParser::ParseWordList(wordlist ** list) +ConfigParser::ParseWordList(wordlist ** list) { parse_wordlist(list); -} +} void parse_wordlist(wordlist ** list) @@ -3371,4 +3371,5 @@ { cfg.dumpIcapAccess(entry, name); } + #endif