]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Early rejection of an access.log line outside of the requested date range
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 2 Mar 2010 12:10:39 +0000 (12:10 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 2 Mar 2010 12:10:39 +0000 (12:10 +0000)
log.c

diff --git a/log.c b/log.c
index 38e794b6acddcd5ca3c0944aeecdb60ec3bfab88..2ae767672ec4b109eb519c50e6149b5b3f48c3c6 100644 (file)
--- a/log.c
+++ b/log.c
@@ -878,9 +878,6 @@ int main(int argc,char *argv[])
          }
          if(exstring) continue;
 
-         if ((str = strchr(linebuf, '\n')) != NULL)
-            *str = '\0';          /* strip \n */
-
          totregsl++;
          if(debugm)
             printf("BUF=%s\n",linebuf);
@@ -1065,37 +1062,37 @@ int main(int argc,char *argv[])
                }
                if (x==isa_cols[ISACOL_Ip]) {
                   if (strlen(str)>=sizeof(ip)) {
-                     printf("SARG: Maybe you have a broken IP in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken IP in your %s file"),arq);
                      exit(1);
                   }
                   strcpy(ip,str);
                } else if (x==isa_cols[ISACOL_UserName]) {
                   if (strlen(str)>=sizeof(user)) {
-                     printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken user in your %s file"),arq);
                      exit(1);
                   }
                   strcpy(user,str);
                } else if (x==isa_cols[ISACOL_Date]) {
                   if (strlen(str)>=sizeof(data)) {
-                     printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken date in your %s file"),arq);
                      exit(1);
                   }
                   strcpy(data,str);
                } else if (x==isa_cols[ISACOL_Time]) {
                   if (strlen(str)>=sizeof(hora)) {
-                     printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken time in your %s file"),arq);
                      exit(1);
                   }
                   strcpy(hora,str);
                } else if (x==isa_cols[ISACOL_TimeTaken]) {
                   if (strlen(str)>=sizeof(elap)) {
-                     printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken download duration in your %s file"),arq);
                      exit(1);
                   }
                   strcpy(elap,str);
                } else if (x==isa_cols[ISACOL_Bytes]) {
                   if (strlen(str)>=sizeof(tam)) {
-                     printf("SARG: Maybe you have a broken download size in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken download size in your %s file"),arq);
                      exit(1);
                   }
                   strcpy(tam,str);
@@ -1103,7 +1100,7 @@ int main(int argc,char *argv[])
                   url=str;
                } else if (x==isa_cols[ISACOL_Status]) {
                   if (strlen(str)>=sizeof(code)) {
-                     printf("SARG: Maybe you have a broken access code in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken access code in your %s file"),arq);
                      exit(1);
                   }
                   strcpy(code,str);
@@ -1116,102 +1113,21 @@ int main(int argc,char *argv[])
             }
             getword_start(&gwarea,data);
             if (getword(ano,sizeof(ano),&gwarea,'-')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file"),arq);
                exit(1);
             }
             if (getword(mes,sizeof(mes),&gwarea,'-')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file"),arq);
                exit(1);
             }
             if (getword(dia,sizeof(dia),&gwarea,'\0')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file"),arq);
                exit(1);
             }
             conv_month_name(mes);
             sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
          }
 
-         if(strlen(user) > MAX_USER_LEN) {
-            if (debugm) printf("User too long: %s\n",user);
-            totregsx++;
-            continue;
-         }
-
-         // include_users
-         if(IncludeUsers[0] != '\0') {
-            sprintf(val1,":%s:",user);
-            if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL )
-               continue;
-         }
-
-         if(vercode(code)) {
-            if (debugm) printf("Excluded code: %s\n",code);
-            totregsx++;
-            continue;
-         }
-
-         if(testvaliduserchar(user))
-            continue;
-
-#if 0
-         if((str = strstr(user,"%20")) != NULL) {
-            /*
-            This is a patch introduced to solve bug #1624251 reported at sourceforge but
-            the side effect is to truncate the name at the first space and merge the reports
-            of people whose name is identical up to the first space.
-
-            The old code used to truncate the user name at the first % if a %20 was
-            found anywhere in the string. That means the string could be truncated
-            at the wrong place if another % occured before the %20. This new code should
-            avoid that problem and only truncate at the space. There is no bug
-            report indicating that anybody noticed this.
-            */
-            *str='\0';
-         }
-
-         /*
-         Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
-         found in the user name.
-         */
-         while((str = strstr(user,"%5c")) != NULL) {
-            *str='.';
-            for (x=3 ; str[x] ; x++) str[x-2]=str[x];
-         }
-#endif
-
-         urly=url;
-
-         if(ilf!=ILF_Sarg) {
-            /*
-            The full URL is not saved in sarg log. There is no point in testing the URL to detect
-            a downloaded file.
-            */
-            download_flag=is_download_suffix(url);
-            if (download_flag) {
-               download_url=url;
-               download_count++;
-            }
-         }
-
-         // remove any protocol:// at the beginning of the URL
-         if ((str = strchr(url,'/')) != NULL && str[1] == '/') {
-            int i;
-
-            str+=2;
-            for (i=0 ; str[i] ; i++)
-               url[i]=str[i];
-            url[i]='\0';
-         }
-
-         if(!LongUrl) {
-            int i;
-
-            for (i=0 ; i<sizeof(hostname)-1 && url[i] && url[i]!='/' ; i++)
-               hostname[i]=url[i];
-            hostname[i]='\0';
-            url=hostname;
-         }
-
          if(ilf==ILF_Squid) {
             tt=atoi(data);
             t=localtime(&tt);
@@ -1239,24 +1155,24 @@ int main(int argc,char *argv[])
          } else if(ilf==ILF_Common || ilf==ILF_Isa) {
             getword_start(&gwarea,data+1);
             if (getword_multisep(data,sizeof(data),&gwarea,':')<0){
-               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken date in your %s file"),arq);
                exit(1);
             }
             if (getword_multisep(hora,sizeof(hora),&gwarea,' ')<0){
-               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken date in your %s file"),arq);
                exit(1);
             }
             getword_start(&gwarea,data);
             if (getword(dia,sizeof(dia),&gwarea,'/')<0){
-               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken date in your %s file"),arq);
                exit(1);
             }
             if (getword(mes,sizeof(mes),&gwarea,'/')<0){
-               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken date in your %s file"),arq);
                exit(1);
             }
             if (getword(ano,sizeof(ano),&gwarea,'/')<0){
-               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken date in your %s file"),arq);
                exit(1);
             }
 
@@ -1270,25 +1186,25 @@ int main(int argc,char *argv[])
             getword_start(&gwarea,data);
             if(strcmp(df,"u") == 0) {
                if (getword(mes,sizeof(mes),&gwarea,'/')<0){
-                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken date in your %s file"),arq);
                   exit(1);
                }
                if (getword(dia,sizeof(dia),&gwarea,'/')<0){
-                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken date in your %s file"),arq);
                   exit(1);
                }
             } else {
                if (getword(dia,sizeof(dia),&gwarea,'/')<0){
-                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken date in your %s file"),arq);
                   exit(1);
                }
                if (getword(mes,sizeof(mes),&gwarea,'/')<0){
-                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken date in your %s file"),arq);
                   exit(1);
                }
             }
             if (getword(ano,sizeof(ano),&gwarea,0)<0){
-               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken date in your %s file"),arq);
                exit(1);
             }
             snprintf(wdata,9,"%s%s%s",ano,mes,dia);
@@ -1301,6 +1217,88 @@ int main(int argc,char *argv[])
          if(date[0] != '\0'){
             if(idata < dfrom || idata > duntil) continue;
          }
+
+         if(strlen(user) > MAX_USER_LEN) {
+            if (debugm) printf(_("User ID too long: %s\n"),user);
+            totregsx++;
+            continue;
+         }
+
+         // include_users
+         if(IncludeUsers[0] != '\0') {
+            sprintf(val1,":%s:",user);
+            if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL )
+               continue;
+         }
+
+         if(vercode(code)) {
+            if (debugm) printf(_("Excluded code: %s\n"),code);
+            totregsx++;
+            continue;
+         }
+
+         if(testvaliduserchar(user))
+            continue;
+
+#if 0
+         if((str = strstr(user,"%20")) != NULL) {
+            /*
+            This is a patch introduced to solve bug #1624251 reported at sourceforge but
+            the side effect is to truncate the name at the first space and merge the reports
+            of people whose name is identical up to the first space.
+
+            The old code used to truncate the user name at the first % if a %20 was
+            found anywhere in the string. That means the string could be truncated
+            at the wrong place if another % occured before the %20. This new code should
+            avoid that problem and only truncate at the space. There is no bug
+            report indicating that anybody noticed this.
+            */
+            *str='\0';
+         }
+
+         /*
+         Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
+         found in the user name.
+         */
+         while((str = strstr(user,"%5c")) != NULL) {
+            *str='.';
+            for (x=3 ; str[x] ; x++) str[x-2]=str[x];
+         }
+#endif
+
+         urly=url;
+
+         if(ilf!=ILF_Sarg) {
+            /*
+            The full URL is not saved in sarg log. There is no point in testing the URL to detect
+            a downloaded file.
+            */
+            download_flag=is_download_suffix(url);
+            if (download_flag) {
+               download_url=url;
+               download_count++;
+            }
+         }
+
+         // remove any protocol:// at the beginning of the URL
+         if ((str = strchr(url,'/')) != NULL && str[1] == '/') {
+            int i;
+
+            str+=2;
+            for (i=0 ; str[i] ; i++)
+               url[i]=str[i];
+            url[i]='\0';
+         }
+
+         if(!LongUrl) {
+            int i;
+
+            for (i=0 ; i<sizeof(hostname)-1 && url[i] && url[i]!='/' ; i++)
+               hostname[i]=url[i];
+            hostname[i]='\0';
+            url=hostname;
+         }
+
          if(url[0] == '\0') continue;
 
          if(addr[0] != '\0'){