]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Alias the host names in the redirector report
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 19 Jun 2011 19:33:48 +0000 (19:33 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 19 Jun 2011 19:33:48 +0000 (19:33 +0000)
The scheme is removed from the URL even for a custom report format and the
URL is always truncated to keep only the host name. The full URL was
always reported for a custom log format.

In addition, the reported host name is replaced by the alias if one is
defined.

There is no grouping of the identical host names as the report list one
access per line along with the access time so there is no grouping any
way.

log.c
squidguard_log.c

diff --git a/log.c b/log.c
index a0eedf1b1a6e3e90daaca30f9a4691854c679230..e4d6cd0226537ee15367ae577990859db2892bd9 100644 (file)
--- a/log.c
+++ b/log.c
@@ -1571,7 +1571,6 @@ int main(int argc,char *argv[])
        free_download();
        free_excludecodes();
        free_exclude();
-       free_hostalias();
 
        if(debug) {
                int totalcount=0;
@@ -1692,6 +1691,7 @@ int main(int argc,char *argv[])
                unlinkdir(tmp,0);
        }
 
+       free_hostalias();
        userinfo_free();
        if(userfile)
                free(userfile);
index cc602b7b43848695e50bec2d53f991174128661f..e46141838f9226ed1451cbbff523303ef1e1a65d 100644 (file)
@@ -38,14 +38,14 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
        char leks[5], sep[2], res[MAXLEN];
        char hour[15];
        char source[128], list[128];
-       char url[MAX_URL_LEN];
+       char full_url[MAX_URL_LEN];
+       const char *url;
        char user[MAX_USER_LEN];
        char ip[45];
        long long int lmon, lday, lyear;
        int mon, day, year;
        int  idata=0;
        int  i;
-       char *str;
        bool id_is_ip;
        struct getwordstruct gwarea;
        struct getwordstruct gwarea1;
@@ -116,7 +116,7 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
                        list[0]='\0';
                        ip[0]='\0';
                        user[0]='\0';
-                       url[0]='\0';
+                       full_url[0]='\0';
                        while(strcmp(leks,"end") != 0) {
                                if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
                                        debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (missing # at end of tag)\n"));
@@ -168,11 +168,11 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
                                                }
                                                strcpy(user,res);
                                        } else if(strcmp(leks,"url") == 0) {
-                                               if (strlen(res)>=sizeof(url)) {
+                                               if (strlen(res)>=sizeof(full_url)) {
                                                        debuga(_("URL too long in redirector log file %s\n"),wentp);
                                                        exit(EXIT_FAILURE);
                                                }
-                                               strcpy(url,res);
+                                               strcpy(full_url,res);
                                        }
                                }
                        }
@@ -197,7 +197,7 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
                                debuga(_("Invalid redirected list in file %s\n"),wentp);
                                exit(EXIT_FAILURE);
                        }
-                       if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword_limit(url,sizeof(url),&gwarea,' ')<0) {
+                       if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword_limit(full_url,sizeof(full_url),&gwarea,' ')<0) {
                                debuga(_("Invalid URL in file %s\n"),wentp);
                                exit(EXIT_FAILURE);
                        }
@@ -209,23 +209,8 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
                                debuga(_("Invalid user in file %s\n"),wentp);
                                exit(EXIT_FAILURE);
                        }
-                       /*
-                       The URL may be "http://url:port/data" if the method is GET or simply "url:port/" if the method is CONNECT.
-                       The following code removes the protocol:// if it is detected and always truncates the URL after the domain name.
-                       It will fail if the URL doesn't start with the protocol and contains two consecutive / in the path (i.e.
-                       the URL is not normalized).
-                       */
-                       str=strchr(url,'/');
-                       if (str) {
-                               if (str[1]=='/') {
-                                       str+=2;
-                                       for (i=0 ; *str && *str!='/' ; i++) url[i]=*str++;
-                                       url[i]='\0';
-                               } else {
-                                       *str='\0';
-                               }
-                       }
                }
+               url=process_url(full_url,false);
 
                //sprintf(warea,"%04d%02d%02d",year,mon,day);