]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - log.c
Use the correct format for off_t on amd64.
[thirdparty/sarg.git] / log.c
diff --git a/log.c b/log.c
index fd2296528891ed12da9b9f00a886c963e4441523..45b85f8b1cdedebbc2ea6ab2dd9d5993b2ba673f 100644 (file)
--- a/log.c
+++ b/log.c
@@ -43,11 +43,8 @@ numlist hours = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
              13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
 
 static void getusers(const char *pwdfile, int debug);
-void gethexclude(char *hexfile, int debug);
-void getuexclude(char *uexfile, int debug);
-void ttx(char *user);
-
-#define _FILE_OFFSET_BITS 64
+static void gethexclude(const char *hexfile, int debug);
+static void getuexclude(const char *uexfile, int debug);
 
 int main(int argc,char *argv[])
 {
@@ -72,7 +69,7 @@ int main(int argc,char *argv[])
    char fun[MAXLEN];
    char wuser[MAXLEN];
    char smartfilter[MAXLEN];
-   char dia[128]; 
+   char dia[128];
    char wdata[128];
    char mes[30];
    char ano[30];
@@ -95,7 +92,7 @@ int main(int argc,char *argv[])
    char *str;
    char bufz[MAXLEN];
    char bufy[MAXLEN];
-   int  common; 
+   int  common;
    int  common_log=0;
    int  squid_log=0;
    int  ch;
@@ -111,7 +108,7 @@ int main(int argc,char *argv[])
    int  iarq=0;
    int  exstring=0;
    int  i0=0,i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0;
-   long totregsl=0; 
+   long totregsl=0;
    long totregsg=0;
    long totregsx=0;
    long totper=0;
@@ -279,7 +276,7 @@ int main(int argc,char *argv[])
    bzero(IncludeUsers, MAXLEN);
    bzero(ExcludeString, MAXLEN);
 
-   for(x=0; x<=254; x++) 
+   for(x=0; x<=254; x++)
       warq[x][0]='\0';
 
    language_load(language);
@@ -540,7 +537,7 @@ int main(int argc,char *argv[])
       sprintf(tmp3,"rm -rf %s",warea);
       system(tmp3);
    }
-   
+
    sprintf(tmp3,"%s/sarg",tmp);
    my_mkdir(tmp3);
    strcpy(tmp4,tmp3);
@@ -750,7 +747,7 @@ int main(int argc,char *argv[])
          if( bool_ShowReadStatistics && ! --OutputNonZero) {
            perc = recs2 * 100 ;
            perc = perc / recs1 ;
-           printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\r",recs1,perc);
+           printf("SARG: Records in file: " OFFSET_STRING", reading: %3.2f%%\r",recs1,perc);
            fflush (stdout);
            OutputNonZero = REPORT_EVERY_X_LINES ;
          }
@@ -793,7 +790,7 @@ int main(int argc,char *argv[])
 
          strcpy(bufy,bufz);
          if ((str = strchr(bufz, '\n')) != NULL)
-            *str = '\0';          /* strip \n */       
+            *str = '\0';          /* strip \n */
 
          totregsl++;
          common=0;
@@ -836,7 +833,7 @@ int main(int argc,char *argv[])
                   else strcpy(code,bufz);
 
                   if ((str = strchr(code, ':')) != NULL)
-                     *str = '/'; 
+                     *str = '/';
 
                   if(strcmp(tam,"\0") == 0)
                      strcpy(tam,"0");
@@ -1091,6 +1088,7 @@ int main(int argc,char *argv[])
          }
 
          if (strchr(url,'/')) {
+            // remove any protocol:// at the beginning of the URL
             if (getword(w,sizeof(w),url,'/')<0){
                printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
                exit(1);
@@ -1111,7 +1109,7 @@ int main(int argc,char *argv[])
                exit(1);
             }
             strcpy(url,w);
-            if(strlen(url) > 512 && strstr(url,"%") != 0) {
+            if(strlen(url) > 512 && strchr(url,'%') != NULL) {
                if (getword_multisep(w,sizeof(w),url,'%')<0){
                   printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
                   exit(1);
@@ -1249,11 +1247,11 @@ int main(int argc,char *argv[])
 
          if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
             if(strcmp(RecordsWithoutUser,"ip") == 0)
-            strcpy(user,ip);
+               strcpy(user,ip);
             if(strcmp(RecordsWithoutUser,"ignore") == 0)
-            continue;
+               continue;
             if(strcmp(RecordsWithoutUser,"everybody") == 0)
-            strcpy(user,"everybody");
+               strcpy(user,"everybody");
          }
 
          if(dotinuser) {
@@ -1393,10 +1391,10 @@ int main(int argc,char *argv[])
         printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\n",recs1, (float) 100 );
    }
 
-   if ( fp_Download_Unsort ) 
+   if ( fp_Download_Unsort )
      fclose (fp_Download_Unsort);
 
-   if (fp_Write_User) 
+   if (fp_Write_User)
      fclose (fp_Write_User);
 
    if(debug) {
@@ -1405,7 +1403,7 @@ int main(int argc,char *argv[])
       if((common_log) && (squid_log))
          debuga("%s",text[12]);
 
-      if((common_log) && (!squid_log)) 
+      if((common_log) && (!squid_log))
          debuga("%s",text[13]);
 
       if((!common_log) && (squid_log))
@@ -1467,7 +1465,7 @@ int main(int argc,char *argv[])
       fclose(fp_authfail);
 
    if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog) {
-      fclose(fp_log); 
+      fclose(fp_log);
       strcpy(val1,period);
       if (getword_multisep(val2,sizeof(val2),val1,'-')<0){
          printf("SARG: Maybe you have a broken date range definition.\n");
@@ -1588,7 +1586,7 @@ static void getusers(const char *pwdfile, int debug)
 }
 
 
-void gethexclude(char *hexfile, int debug)
+static void gethexclude(const char *hexfile, int debug)
 {
 
    FILE *fp_ex;
@@ -1604,20 +1602,20 @@ void gethexclude(char *hexfile, int debug)
    }
 
    fseek(fp_ex, (off_t)0, SEEK_END);
-   nreg = ftell(fp_ex);
+   nreg = ftell(fp_ex)+11;
    fseek(fp_ex, (off_t)0, SEEK_SET);
 
-   if((excludefile=(char *) malloc(nreg+11))==NULL){
+   if((excludefile=(char *) malloc(nreg))==NULL){
       fprintf(stderr, "SARG: %s (%ld):\n",text[59],nreg);
       exit(1);
    }
 
-   bzero(excludefile,nreg+11);
+   bzero(excludefile,nreg);
 
-   while(fgets(buf,255,fp_ex)!=NULL){
-     if(strstr(buf,"#") != 0)
+   while(fgets(buf,sizeof(buf),fp_ex)!=NULL){
+     if(strchr(buf,'#') != NULL)
         continue;
-     buf[strlen(buf)-1]='\0';
+     fixendofline(buf);
      strcat(excludefile,buf);
      strcat(excludefile," ");
    }
@@ -1630,7 +1628,7 @@ void gethexclude(char *hexfile, int debug)
 }
 
 
-void getuexclude(char *uexfile, int debug)
+static void getuexclude(const char *uexfile, int debug)
 {
 
    FILE *fp_ex;
@@ -1646,20 +1644,20 @@ void getuexclude(char *uexfile, int debug)
    }
 
    fseek(fp_ex, (off_t)0, SEEK_END);
-   nreg = ftell(fp_ex);
+   nreg = ftell(fp_ex)+11;
    fseek(fp_ex, (off_t)0, SEEK_SET);
 
-   if((excludeuser=(char *) malloc(nreg+11))==NULL){
+   if((excludeuser=(char *) malloc(nreg))==NULL){
       fprintf(stderr, "SARG: %s (%ld):\n",text[59],nreg);
       exit(1);
    }
 
-   bzero(excludeuser,nreg+11);
+   bzero(excludeuser,nreg);
 
-   while(fgets(buf,255,fp_ex)!=NULL){
-     if(strstr(buf,"#") != 0)
+   while(fgets(buf,sizeof(buf),fp_ex)!=NULL){
+     if(strchr(buf,'#') != NULL)
         continue;
-     buf[strlen(buf)-1]='\0';
+     fixendofline(buf);
      strcat(excludeuser,buf);
      strcat(excludeuser," ");
    }