From jamie.anstice@sli-systems.com Mon Oct 15 23:35:28 2001 Date: Tue, 16 Oct 2001 15:52:54 +1300 From: Jamie Anstice To: htdig-general@lists.sourceforge.net Subject: [htdig] PATCH: Server fallthrough htcommon/HtConfiguration.cc Here's a 3.2.x patch. It makes the server block configuration matching more flexible. Instead of the host name having to exactly match the name specified in the server block, a less-qualified server name can be specified, and all host names under this will match. For example, a block would match hosts foo.net, www.foo.net, store.foo.net and www.store.foo.net. However, it won't try to match just 'net', so a block will have no effect (but a block would). ==================================== --- htdig/htcommon/HtConfiguration.cc Thu May 17 04:36:44 2001 +++ htdig-patched/htcommon/HtConfiguration.cc Thu Oct 11 17:11:21 2001 @@ -57,47 +57,97 @@ HtConfiguration::Add(const char *name, c } //********************************************************************* -const String HtConfiguration::Find(const char *blockName,const char *name,const char *value) const +const String +HtConfiguration::Find(const char *blockName,const char *name,const char *value) const { - if (!(blockName && name && value) ) - return String(); - union { - void *ptr; - Object *obj; - Dictionary *dict; - HtConfiguration *conf; - } tmpPtr; - String chr; - - if (strcmp("url",blockName)==0) { // URL needs special compare - URL paramUrl(name); // split URL to compare separatly host and path - chr=Find(¶mUrl,value); - if (chr[0]!=0) { - return chr; + if (!(blockName && name && value) ) + return String(); + union { + void *ptr; + Object *obj; + Dictionary *dict; + HtConfiguration *conf; + } tmpPtr; + String chr; + + if (strcmp("url",blockName)==0) { // URL needs special compare + URL paramUrl(name); // split URL to compare separatly host and path + chr=Find(¶mUrl,value); + if (chr[0]!=0) { + return chr; + } } + else if (strcmp("server", blockName)==0) { + tmpPtr.obj=dcBlocks.Find(blockName); + if (tmpPtr.ptr) + { + // look to see if 'name' matches exactly with something in the config + tmpPtr.obj = tmpPtr.dict->Find(name); + if (tmpPtr.ptr) + { + chr = tmpPtr.conf->Find(value); + if (chr[0] != 0) + return chr; + } + else + // if it doesn't, and if 'name' contains two or more dots, like www.htdig.org + // remove the first part of the domain (to something like htdig.org) + // and see if that matches a config file entry + // but don't file down the name if there is only one dot, we don't want + // 'foo.com' to reduce to 'com' + { + String tmp_host( name ); + int first_dot_pos = 0, second_dot_pos = 0; + + while( 1 ) + { + first_dot_pos = tmp_host.indexOf( '.' ); + if ( first_dot_pos != -1 ) + { + second_dot_pos = tmp_host.indexOf( '.', first_dot_pos+1 ); + if ( second_dot_pos != -1 ) + { + tmp_host = tmp_host.sub( first_dot_pos + 1 ); + + tmpPtr.obj=dcBlocks.Find(blockName); + tmpPtr.obj = tmpPtr.dict->Find( tmp_host.get() ); + if (tmpPtr.ptr) { + chr = tmpPtr.conf->Find(value); + if (chr[0] != 0) + return chr; + } + } + else // one dot + break; + } + else // no dots + break; + } + } + } } - else { // end "server" - tmpPtr.obj=dcBlocks.Find(blockName); - if (tmpPtr.ptr) { - tmpPtr.obj = tmpPtr.dict->Find(name); - if (tmpPtr.ptr) { - chr = tmpPtr.conf->Find(value); - if (chr[0] != 0) - return chr; - } - } + else { // neither URL or server + tmpPtr.obj=dcBlocks.Find(blockName); + if (tmpPtr.ptr) { + tmpPtr.obj = tmpPtr.dict->Find(name); + if (tmpPtr.ptr) { + chr = tmpPtr.conf->Find(value); + if (chr[0] != 0) + return chr; + } + } + } + + // If this parameter is defined in global then return it + chr=Find(value); + if (chr[0]!=0) { + return chr; } - - // If this parameter is defined in global then return it - chr=Find(value); - if (chr[0]!=0) { - return chr; - } #ifdef DEBUG - cerr << "Could not find configuration option " << blockName<<":" - < To unsubscribe, send a message to with a subject of unsubscribe FAQ: http://htdig.sourceforge.net/FAQ.html