]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Improve a bit the processing of the URL
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 19 Jun 2011 19:33:33 +0000 (19:33 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 19 Jun 2011 19:33:33 +0000 (19:33 +0000)
Detect more strictly the scheme prefixing the URL to avoid any false
positive.

The caller decides if the full URL must be kept or truncated.

include/defs.h
log.c
url.c

index 440948b5b5e08933fa65d7c162dd841087a424aa..7c9e508f8deaa2bf37271a7742e9d32851fe72a2 100755 (executable)
@@ -193,7 +193,7 @@ void day_totalize(const char *tmp, const struct userinfostruct *uinfo);
 // url.c
 void read_hostalias(const char *Filename);
 void free_hostalias(void);
-const char *process_url(char *url);
+const char *process_url(char *url,bool full_url);
 void url_hostname(const char *url,char *hostname,int hostsize);
 
 // usage.c
diff --git a/log.c b/log.c
index 59aca0dfad8516def2334e062984d6ad3a5f918f..a0eedf1b1a6e3e90daaca30f9a4691854c679230 100644 (file)
--- a/log.c
+++ b/log.c
@@ -1338,7 +1338,7 @@ int main(int argc,char *argv[])
                        } else
                                download_flag=false;
 
-                       url=process_url(full_url);
+                       url=process_url(full_url,LongUrl);
                        if (!url || url[0] == '\0') continue;
 
                        if(addr[0] != '\0'){
diff --git a/url.c b/url.c
index 74324206872ddb13c8c9e2856adcc87e0c22dbe7..a4ee3658715b1b08532b3fca5b3056c8b9c2d616 100644 (file)
--- a/url.c
+++ b/url.c
@@ -227,6 +227,7 @@ void free_hostalias(void)
                free((void *)alias->Alias);
                free(alias);
        }
+       FirstAlias=NULL;
 }
 
 /*!
@@ -266,21 +267,23 @@ const char *alias_url(const char *url)
 Get the part of the URL necessary to generate the report.
 
 \param url The URL as extracted from the report.
+\param full_url \c True to keep the whole URL. If \c false,
+the URL is truncated to only keep the host name and port number.
 */
-const char *process_url(char *url)
+const char *process_url(char *url,bool full_url)
 {
        char *str;
        const char *start;
 
        // remove any scheme:// at the beginning of the URL (see rfc2396 section 3.1)
        for (str=url ; *str && (isalnum(*str) || *str=='+' || *str=='-' || *str=='.') ; str++);
-       if (*str==':' && str[1]=='/') {
-               url=str+1;
+       if (*str==':' && str[1]=='/' && str[2]=='/') {
+               url=str+3;
                while (*url=='/') url++;
        }
 
        start=url;
-       if (!LongUrl) {
+       if (!full_url) {
                for (str=url ; *str && *str!='/' ; str++);
                if (*str=='/') *str='\0';
                if (FirstAlias)