Il ven, 2004-01-30 alle 17:59, Gilles Detillieux ha scritto:
> It certainly seems like a bug to me, and your patch seems correct as far
> as I can tell. However, I don't see the need for supporting a dash or
> "noproxy". With your patch, if you set http_proxy to an empty string
> within the URL block, it should do the right thing. What was missing
> before was the code you added to delete the old "proxy" value and set
> the pointer to null when proxyURL's length is 0.
I found another *bug* in the *configuration* module. I guess it is a
*logical* bug.
Everytime I specified an empty attribute in a block, the configuration
parameter was discarded, as it returned a value with 0 length. The
interested method was "HtConfiguration::Find(URL *aUrl, const char
*value) const".
Here is my proposed patch, which now encapsulates an Exists method in
the Configuration class.
IMHO, if a string parameter is specified (even if empty), this operation
must be considered to be valid; therefore, I changed the method above
(Find) in order to issue an Exists check before finding a value
corresponding to a certain attribute.
If the requested parameter is present in the dictionary (even though it
may be empty) the associated value is returned anyway.
Please have a look at the following patch and let me know what you think
guys, so that I can commit the changes and close the bug.
Ciao and thanks,
-Gabriele
Index: htcommon/HtConfiguration.cc
===================================================================
RCS file: /cvsroot/htdig/htdig/htcommon/HtConfiguration.cc,v
retrieving revision 1.8
diff -3 -u -p -r1.8 HtConfiguration.cc
--- htcommon/HtConfiguration.cc 21 Jul 2003 08:16:10 -0000 1.8
+++ htcommon/HtConfiguration.cc 2 Feb 2004 15:47:44 -0000
@@ -134,24 +134,28 @@ const String HtConfiguration::Find(URL *
// or make url list sorted ?
// or implement abstract Dictionary::Compare?
const char *strParamUrl=(const char *)aUrl->path();
- char* confUrl= NULL;
- while ( (confUrl=tmpPtr->Get_Next()) ) {
+ char* confUrl= NULL;
+ bool found(false);
+ while ( !found && (confUrl=tmpPtr->Get_Next()) ) {
if (strncmp(confUrl,strParamUrl,strlen(confUrl))==0
&& (strlen(confUrl)>=candidate.len)) {
// it seems this URL match better
candidate.obj=tmpPtr->Find(confUrl);
- // but does it has got necessery parameter?
- candidate.value=((HtConfiguration *)candidate.obj)->Find(value);
- if (candidate.value[0]!=0) {
- // yes, it has! We've got new candidate.
- returnValue=candidate.value;
- candidate.len=candidate.value.length();
- }
+
+ // Let's see if it exists
+ if (((HtConfiguration *)candidate.obj)->Exists(value))
+ {
+ // yes, it has! We've got new candidate.
+ candidate.value=((HtConfiguration *)candidate.obj)->Find(value);
+ returnValue=candidate.value;
+ candidate.len=candidate.value.length();
+ found = true;
+ }
}
}
- if (candidate.len>0) {
+
+ if (found)
return ParsedString(returnValue).get(dcGlobalVars);
- }
}
return Find(value);
Index: htdig/Document.cc
===================================================================
RCS file: /cvsroot/htdig/htdig/htdig/Document.cc,v
retrieving revision 1.68
diff -3 -u -p -r1.68 Document.cc
--- htdig/Document.cc 23 Oct 2003 02:10:55 -0000 1.68
+++ htdig/Document.cc 2 Feb 2004 15:47:44 -0000
@@ -180,25 +180,31 @@ Document::Reset()
void
Document::Url(const String &u)
{
- HtConfiguration* config= HtConfiguration::config();
+ HtConfiguration* config= HtConfiguration::config();
if (url)
delete url;
url = new URL(u);
+ // Re-initialise the proxy
+ if (proxy)
+ delete proxy;
+ proxy = 0;
+
+ // Get the proxy information for this URL
const String proxyURL = config->Find(url,"http_proxy");
+
+ // If http_proxy is not empty we set the proxy for the current URL
if (proxyURL.length())
{
- proxy = new URL(proxyURL);
- proxy->normalize();
+ proxy = new URL(proxyURL);
+ proxy->normalize();
+ // set the proxy authorization information
+ setProxyUsernamePassword(config->Find(url,"http_proxy_authorization"));
}
- const String credentials = config->Find(url,"authorization");
- if (credentials.length() )
- setUsernamePassword(credentials);
-
- const String proxy_credentials = config->Find(url,"http_proxy_authorization");
- if (proxy_credentials.length() )
- setProxyUsernamePassword(proxy_credentials);
+ // Set the authorization information
+ setUsernamePassword(config->Find(url,"authorization"));
+
}
Index: htlib/Configuration.cc
===================================================================
RCS file: /cvsroot/htdig/htdig/htlib/Configuration.cc,v
retrieving revision 1.18
diff -3 -u -p -r1.18 Configuration.cc
--- htlib/Configuration.cc 24 Jun 2003 20:05:44 -0000 1.18
+++ htlib/Configuration.cc 2 Feb 2004 15:47:44 -0000
@@ -229,6 +229,14 @@ const String Configuration::Find(const S
}
}
+//-
+// Return 1 if the value of configuration attribute <b>name</b> has
+// been set, 0 otherwise
+int Configuration::Exists(const String& name) const
+{
+ return dcGlobalVars.Exists(name);
+}
+
//*********************************************************************
Object *Configuration::Get_Object(char *name) {
return dcGlobalVars[name];
Index: htlib/Configuration.h
===================================================================
RCS file: /cvsroot/htdig/htdig/htlib/Configuration.h,v
retrieving revision 1.9
diff -3 -u -p -r1.9 Configuration.h
--- htlib/Configuration.h 24 Jun 2003 20:05:44 -0000 1.9
+++ htlib/Configuration.h 2 Feb 2004 15:47:44 -0000
@@ -179,6 +179,12 @@ public:
// <i>String</i>.
//
const String Find(const String& name) const;
+
+ //-
+ // Return 1 if the value of configuration attribute <b>name</b> has
+ // been set, 0 otherwise
+ int Exists(const String& name) const;
+
#ifndef SWIG
//-
// Alias to the <b>Find</b> method.