From 1a2609b0bf9303ffe85ef3d474148ea89ff09977 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Sun, 19 Jun 2011 19:33:33 +0000 Subject: [PATCH] Improve a bit the processing of the URL 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 | 2 +- log.c | 2 +- url.c | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/defs.h b/include/defs.h index 440948b..7c9e508 100755 --- a/include/defs.h +++ b/include/defs.h @@ -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 59aca0d..a0eedf1 100644 --- 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 7432420..a4ee365 100644 --- 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) -- 2.47.2