]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Sarg.conf can use multiple access_log lines.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 19 Dec 2009 21:20:20 +0000 (21:20 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 19 Dec 2009 21:20:20 +0000 (21:20 +0000)
Some small optimizations.

15 files changed:
CMakeLists.txt
authfail.c
datafile.c
documentation/getconf.txt
documentation/util.txt
getconf.c
html.c
include/conf.h
include/defs.h
index.c
log.c
realtime.c
report.c
sort.c
util.c

index cce2a9881d5f1abacfa35541522a4516bfad1ed7..c3e07251a7d6bed24031c983e64e10537e165f51 100755 (executable)
@@ -61,7 +61,9 @@ ADD_EXECUTABLE(sarg ${SRC})
 
 SET_TARGET_PROPERTIES(sarg PROPERTIES VERSION "${sarg_VERSION}.${sarg_REVISION}.${sarg_BUILD}")
 
-SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
+SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "$ENV{CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
+SET_TARGET_PROPERTIES(sarg PROPERTIES LINK_FLAGS "$ENV{LDFLAGS}")
+
 CHECK_C_COMPILER_FLAG("-Werror=implicit-function-declaration" HAVE_WERROR_IMPLICIT_FUNCTION)
 IF(HAVE_WERROR_IMPLICIT_FUNCTION)
    GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
index 191fc37907b57ebfcce694ab685f6afaa911fa80..b27287d6896b6de071c5b9262ffe3277db306f92 100644 (file)
@@ -49,7 +49,7 @@ void authfail_report(void)
    int  cstatus;
    struct getwordstruct gwarea;
 
-   if(strlen(DataFile) > 0) return;
+   if(DataFile[0] != '\0') return;
 
    ouser[0]='\0';
 
index a3f6229947d77335d27ecb3a5ba2eb88095bff94..be22a41a491381578faf16068d0685ff5b685c15 100644 (file)
@@ -111,8 +111,7 @@ void data_file(char *tmp)
          if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){
             strcpy(oldmsg,"OK");
             if(strstr(oldacccode,"DENIED") != 0) strcpy(oldmsg,text[46]);
-            strcpy(wdirname,dirname);
-            gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+            gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
             strcpy(wdirname,dirname);
             saverecs(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
             nacc=0;
index 21e43b2f39c5035dc18015a9938d1534f113de9b..1b904d1b8cf2d2ea357bdece961c8bc2d2f0dadd 100644 (file)
@@ -3,6 +3,19 @@
 */
 
 
+/*! \fn static int isparam_string(const char *param,const char *buf)
+Tell if the buffer contains a line defining the given parameter.
+
+\param param The name of the parameter to find.
+\param buf The string read from the input file.
+
+\retval 1 Parameter match.
+\retval 0 The line is not for that parameter.
+*/
+
+
+
+
 /*! \fn static int getparam_string(const char *param,char *buf,char *value,int value_size)
 Extract a string value from a line if it it the right parameter.
 
index b52ee5d4dc49f0b7c893b80e180db15c0338415a..04564a7d5092a433c092501a4e402454d6d599ce 100644 (file)
@@ -93,6 +93,21 @@ the function displays an error message and returns an error code.
 
 
 
+
+/*! \fn int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop)
+Extract one number from the text line.
+
+\param number Where the store the extracted number.
+\param gwarea The getword buffer initialized by getword_start().
+\param stop The character indicating the end of the word.
+
+\retval 0 The number is skipped.
+\retval -1 The stop character was not found after the number.
+*/
+
+
+
+
 /*! \fn long long int my_atoll (const char *nptr)
 
 Convert a string into a long long.
index 63ae654d89e5d8e3bf56e3eaf4088ee2b4800476..9a85ae39673a37ead1fe5715f5f141e545ce81ff 100644 (file)
--- a/getconf.c
+++ b/getconf.c
 
 extern numlist hours, weekdays;
 
+static int isparam_string(const char *param,const char *buf)
+{
+   int plen;
+
+   plen=strlen(param);
+   if (strncmp(buf,param,plen) != 0) return(0);
+   buf+=plen;
+   if ((unsigned char)*buf>' ') return(0);
+   return(1);
+}
+
 static int getparam_string(const char *param,char *buf,char *value,int value_size)
 {
    int plen;
@@ -219,7 +230,17 @@ static void parmtest(char *buf)
 
    if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
 
-   if (getparam_string("access_log",buf,AccessLog,sizeof(AccessLog))>0) return;
+   if (isparam_string("access_log",buf)>0) {
+      if (AccessLogFromCmdLine==0) {
+         if (NAccessLog>=MAXLOGS) {
+            fprintf(stderr,"SARG: Too many log files.\n");
+            exit(1);
+         }
+         getparam_string("access_log",buf,AccessLog[NAccessLog],MAXLEN);
+         NAccessLog++;
+      }
+      return;
+   }
 
    if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return;
 
diff --git a/html.c b/html.c
index 78955a20e6197cd7d3c6ed77721df4e4cbaad4c9..56628f6ff6e96c7b4d9d381eb52835d73ac32559 100644 (file)
--- a/html.c
+++ b/html.c
@@ -35,16 +35,19 @@ void htmlrel(void)
    long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0;
    long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
    long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0, twork2=0;
+   long long int ltemp;
+   long long int ntotuser;
+   long long int userbytes, userelap;
    char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
-   char nacc[20], nbytes[20], url[MAXLEN], tmsg[50], nelap[20], csort[MAXLEN];
+   char url[MAXLEN], tmsg[50], csort[MAXLEN];
    char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
-   char userbytes[20], userelap[20], userurl[1024], userhora[9], userdia[9];
-   char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN], incac[20], oucac[20];
+   char userurl[1024], userhora[9], userdia[9];
+   char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
    char denied_report[255], name2[MAXLEN];
    //char ttd1[3], ttd2[3], ttd3[5], ttt1[3], ttt2[3], ttt3[3];
    char *str;
    char warea[MAXLEN];
-   char wtemp[MAXLEN], totuser[8];
+   char totuser[8];
    long long int tnacc=0, ttnacc=0, unacc=0;
    float perc=0, perc2=0, ouperc=0, inperc=0;
    char *s;
@@ -90,23 +93,23 @@ void htmlrel(void)
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       if(strstr(buf,"TOTAL") == 0) {
          getword_start(&gwarea,buf);
-         if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
+         if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(&ltemp,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
             exit(1);
          }
-         ttnacc+=my_atoll(gwarea.current);
-         if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+         ttnacc+=ltemp;
+         if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
             exit(1);
          }
-         totbytes+=my_atoll(wtemp);
+         totbytes+=ltemp;
          if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
              getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
-             getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
+             getword_atoll(&ltemp,&gwarea,'\t')<0) {
+            printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqper,__LINE__);
             exit(1);
          }
-         totelap+=my_atoll(wtemp);
+         totelap+=ltemp;
       }
    }
 
@@ -183,32 +186,32 @@ void htmlrel(void)
 
       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
          getword_start(&gwarea,buf);
-         if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+         if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
             exit(1);
          }
-         tnacc+=my_atoll(wtemp);
-         if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+         tnacc+=ltemp;
+         if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
             exit(1);
          }
-         tnbytes+=my_atoll(wtemp);
+         tnbytes+=ltemp;
          if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
-             getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+             getword_atoll(&ltemp,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
             exit(1);
          }
-         tnelap+=my_atoll(wtemp);
-         if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+         tnelap+=ltemp;
+         if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
             exit(1);
          }
-         tnincache+=my_atoll(wtemp);
-         if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+         tnincache+=ltemp;
+         if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
+            printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqin,__LINE__);
             exit(1);
          }
-         tnoucache+=my_atoll(wtemp);
+         tnoucache+=ltemp;
       }
 
       rewind(fp_in);
@@ -292,11 +295,11 @@ void htmlrel(void)
 
       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
          getword_start(&gwarea,buf);
-         if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
+         if (getword_atoll(&twork,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
             exit(1);
          }
-         if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
+         if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
             exit(1);
          }
@@ -308,16 +311,16 @@ void htmlrel(void)
             printf("SARG: Maybe you have a broken status in your %s file.\n",arqin);
             exit(1);
          }
-         if (getword(nelap,sizeof(nelap),&gwarea,'\t')<0) {
+         if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
             exit(1);
          }
-         if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
+         if (getword_atoll(&incache,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin);
             exit(1);
          }
-         if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",arqin);
+         if (getword_atoll(&oucache,&gwarea,'\n')<0) {
+            printf("SARG: Maybe you have a broken not in cache column in your %s file (%d).\n",arqin,__LINE__);
             exit(1);
          }
 
@@ -325,11 +328,6 @@ void htmlrel(void)
             sprintf(tmsg,"<td class=\"data\">%s</td>",text[46]);
          else bzero(tmsg, 50);
 
-         nnbytes=my_atoll(nbytes);
-         nnelap=my_atoll(nelap);
-         incache=my_atoll(incac);
-         oucache=my_atoll(oucac);
-
          if(nnbytes) {
             perc=nnbytes * 100;
             perc=perc / tnbytes;
@@ -353,7 +351,6 @@ void htmlrel(void)
             ouperc=ouperc / nnbytes;
          } else ouperc=0;
 
-         twork=my_atoll(nacc);
          strcpy(wwork1,fixnum(twork,1));
          strcpy(wwork2,fixnum(nnbytes,1));
          strcpy(wwork3,fixnum2(nnelap,1));
@@ -506,12 +503,12 @@ void htmlrel(void)
                   printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3);
                   exit(1);
                }
-               if (getword(userbytes,sizeof(userbytes),&gwarea,'\t')<0) {
+               if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
                   printf("SARG: Maybe you have a broken size in your %s file.\n",tmp3);
                   exit(1);
                }
-               if (getword(userelap,sizeof(userelap),&gwarea,'\t')<0) {
-                  printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",tmp3);
+               if (getword_atoll(&userelap,&gwarea,'\t')<0) {
+                  printf("SARG: Maybe you have a broken elapsed time in your %s file (%d).\n",tmp3,__LINE__);
                   exit(1);
                }
                if(strcmp(user_ip,olduserip) != 0) {
@@ -525,8 +522,8 @@ void htmlrel(void)
                   unelap=0;
                }
 
-               unbytes=unbytes+my_atoll(userbytes);
-               unelap=unelap+my_atoll(userelap);
+               unbytes=unbytes+userbytes;
+               unelap=unelap+userelap;
             }
 
             fclose(fp_ip);
@@ -676,14 +673,16 @@ void htmlrel(void)
             exit(1);
          }
 
-         if (!fgets(totuser,8,fp_in)) {
+         if (!fgets(totuser,sizeof(totuser),fp_in)) {
             fprintf(stderr,"SARG: (html11) read error in %s\n",arqper);
             exit(1);
          }
          fclose(fp_in);
 
-         totbytes2=totbytes/my_atoll(totuser);
-         totelap2=totelap/my_atoll(totuser);
+         ntotuser=my_atoll(totuser);
+         if (ntotuser<=0) ntotuser=1;
+         totbytes2=totbytes/ntotuser;
+         totelap2=totelap/ntotuser;
 
          if(totbytes2) {
             perc = totbytes / 100;
@@ -695,7 +694,7 @@ void htmlrel(void)
             perc2 = totelap2 / perc2;
          } else perc2=0;
 
-         twork2=my_atoll(totuser);
+         twork2=ntotuser;
          twork=ttnacc/twork2;
 
          strcpy(wwork1,fixnum(twork,1));
index 32fddc3b94529c75f81bb3bbc6ec59203f0780a3..4f158e098e44f99d41da538bb9198a2b28c9d79a 100755 (executable)
@@ -128,6 +128,8 @@ int mkstemps(char *template, int suffixlen);
 #endif /*__MINGW32__*/
 
 #define MAXLEN 20000
+#define MAXLOGS 255
+
 long long int my_atoll (const char *nptr);
 
 FILE *fp_tt;
@@ -186,7 +188,9 @@ char LongUrl[20];
 char Ip2Name[20];
 char language[255];
 char bufy[MAXLEN];
-char AccessLog[MAXLEN];
+int NAccessLog;
+char AccessLog[MAXLOGS][MAXLEN];
+int AccessLogFromCmdLine;
 char Title[MAXLEN];
 char BgColor[MAXLEN];
 char BgImage[MAXLEN];
index 96afc89d81e067020e2a7e01cc952cc3bf767c66..1bc7f604ceb5c4a4ae90565790850207169c7a9e 100755 (executable)
@@ -79,7 +79,7 @@ void realtime(void);
 void report_day(const char *user);
 
 // report.c
-void gravatmp(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
+void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
 void gerarel(void);
 
 // siteuser.c
@@ -125,6 +125,7 @@ void getword_restart(struct getwordstruct *gwarea);
 int getword(char *word, int limit, struct getwordstruct *gwarea, int stop);
 int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop);
 int getword_skip(int limit, struct getwordstruct *gwarea, int stop);
+int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop);
 void name_month(char *month,int month_len);
 void conv_month_name(char *month);
 void buildymd(const char *dia, const char *mes, const char *ano, char *wdata);
diff --git a/index.c b/index.c
index 8e0277a92701e45bf7895348fdd7eafb4a66a322..e11fb4474f30203ac1a0e9333f912dd9c1b84cf4 100644 (file)
--- a/index.c
+++ b/index.c
@@ -50,12 +50,11 @@ void make_index(void)
    char day[16], mon[16], year[40], hour[10];
    char *str;
    int cstatus;
-   int iyear, imonth, iday, ihour, iminute, isecond;
+   int iyear, imonth, iday, ihour, iminute, isecond, idst;
    char y1[5], y2[5];
    char d1[3], d2[3];
    char m1[4], m2[4];
    struct getwordstruct gwarea;
-   int iyear, imonth, iday, ihour, iminute, isecond, idst;
 
    if(LastLog[0] != '\0') mklastlog(outdir);
 
diff --git a/log.c b/log.c
index 268695e3116a8c4b9bd8f2ae7a251de981c4a954..a7a1002b4eb5ded83f7b3067e946d6a14ed50a77 100644 (file)
--- a/log.c
+++ b/log.c
@@ -93,7 +93,6 @@ int main(int argc,char *argv[])
    char date[255];
    char arq[255];
    char arq_log[255];
-   char warq[255][255];
    char hm[15], hmf[15], hmr[15];
    int  chm=0;
    char uagent[MAXLEN];
@@ -117,7 +116,6 @@ int main(int argc,char *argv[])
    int  fuser=0;
    int  idata=0;
    int  mindate=0;
-   int  narq=0;
    int  iarq=0;
    int  exstring=0;
    int isa_ncols=0,isa_cols[ISACOL_Last];
@@ -156,10 +154,8 @@ int main(int argc,char *argv[])
    ExternalCSSFile[0]='\0';
    SquidGuardLogFormat[0]='\0';
    SquidGuardLogAlternate[0]='\0';
-   arq[0]='\0';
    for (ilf=0 ; ilf<ILF_Last ; ilf++) ilf_count[ilf]=0;
 
-   strcpy(AccessLog,"/var/log/squid/access.log");
    sprintf(ExcludeCodes,"%s/exclude_codes",SYSCONFDIR);
    strcpy(GraphDaysBytesBarColor,"orange");
    strcpy(BgColor,"#ffffff");
@@ -294,8 +290,10 @@ int main(int argc,char *argv[])
    setlocale(LC_TIME,"");
 #endif
 
-   for(x=0; x<=254; x++)
-      warq[x][0]='\0';
+   NAccessLog=0;
+   for(x=0; x<=MAXLOGS; x++)
+      AccessLog[x][0]='\0';
+   AccessLogFromCmdLine=0;
 
    language_load(language);
    strcpy(Title,text[88]);
@@ -341,12 +339,13 @@ int main(int argc,char *argv[])
             iprel++;
             break;
          case 'l':
-            if (narq>=sizeof(warq)/sizeof(warq[0])) {
+            if (NAccessLog>=MAXLOGS) {
                printf("SARG: Too many log files.\n");
                exit(1);
             }
-            strcpy(warq[narq],optarg);
-            narq++;
+            strcpy(AccessLog[NAccessLog],optarg);
+            NAccessLog++;
+            AccessLogFromCmdLine++;
             break;
          case 'L':
             strcpy(SquidGuardLogAlternate,optarg);
@@ -459,18 +458,18 @@ int main(int argc,char *argv[])
 
    subs(UserReportFields,sizeof(UserReportFields),"%BYTES","SETYB");
 
-   if(!narq) {
-      strcpy(warq[0],AccessLog);
-      narq++;
+   if(!NAccessLog) {
+      strcpy(AccessLog[0],"/var/log/squid/access.log");
+      NAccessLog++;
    }
 
    if(strcmp(hexclude,"onvert") == 0 && strcmp(site,"plit") != 0) {
-      convlog(warq[0], df, dfrom, duntil);
+      convlog(AccessLog[0], df, dfrom, duntil);
       exit(0);
    }
 
    if(strcmp(site,"plit") == 0) {
-      splitlog(warq[0], df, dfrom, duntil, hexclude);
+      splitlog(AccessLog[0], df, dfrom, duntil, hexclude);
       exit(0);
    }
 
@@ -517,9 +516,6 @@ int main(int argc,char *argv[])
    if(strlen(outdir)<1) strcpy(outdir,OutputDir);
    strcat(outdir,"/");
 
-
-   if(arq[0] == '\0') strcpy(arq,AccessLog);
-
    if(uagent[0] == '\0') strcpy(uagent,UserAgentLog);
 
    if(tmp[0] == '\0') strcpy(tmp,TempDir);
@@ -586,9 +582,10 @@ int main(int argc,char *argv[])
          fprintf(stderr, "SARG: %35s (-g) = %s (yyyy/ww)\n",text[25],text[85]);
       if(iprel)
          fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[1]);
-       else
+      else
          fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[2]);
-      fprintf(stderr, "SARG: %35s (-l) = %s\n",text[37],arq);
+      for (iarq=0 ; iarq<NAccessLog ; iarq++)
+         fprintf(stderr, "SARG: %35s (-l) = %s\n",text[37],AccessLog[iarq]);
       if(strcmp(Ip2Name,"yes") == 0)
          fprintf(stderr, "SARG: %35s (-n) = %s\n",text[65],text[1]);
        else
@@ -629,9 +626,10 @@ int main(int argc,char *argv[])
          printf("%35s (-g) = %s (yyyy/ww)\n",text[25],text[85]);
       if(iprel)
          printf("%35s (-i) = %s\n",text[28],text[1]);
-       else
+      else
          printf("%35s (-i) = %s\n",text[28],text[2]);
-      printf("%35s (-l) = %s\n",text[37],arq);
+      for (iarq=0 ; iarq<NAccessLog ; iarq++)
+         printf("%35s (-l) = %s\n",text[37],AccessLog[iarq]);
       if(strcmp(Ip2Name,"yes") == 0)
          printf("%35s (-n) = %s\n",text[65],text[1]);
        else
@@ -715,9 +713,8 @@ int main(int argc,char *argv[])
       }
    }
 
-   while(narq--) {
-      strcpy(arq,warq[iarq]);
-      iarq++;
+   for (iarq=0 ; iarq<NAccessLog ; iarq++) {
+      strcpy(arq,AccessLog[iarq]);
 
       strcpy(arqtt,arq);
 
index 1610a7f8062328de26f1c5c6ebb34f7db241c26a..fce89340f2e52daf3ea56067f15695ee63bfac0c 100755 (executable)
@@ -64,7 +64,7 @@ static void getlog(void)
        exit(1);
    }
 
-   sprintf(cmd,"tail -%d %s",realtime_access_log_lines,AccessLog);
+   sprintf(cmd,"tail -%d %s",realtime_access_log_lines,AccessLog[0]);
    fp = popen(cmd, "r");
    while(fgets(buf,sizeof(buf),fp) != NULL )
       if (getdata(buf,tmp)<0) {
index 555e6ee96b009755bcf062b3f368a13a59d0c45c..f5e7d17d64423a267e8300b117035f5fc02eb26c 100644 (file)
--- a/report.c
+++ b/report.c
@@ -31,13 +31,14 @@ static void maketmp_hour(const char *user, const char *dirname, int indexonly);
 static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, const char *elap, const char *accbytes, int indexonly);
 static void gravatmpf(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
 static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, const char *tam, const char *elap, int indexonly);
-static void gravager(char *dirname, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache);
+static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache);
 static void grava_SmartFilter(const char *dirname, const char *user, const char *ip, const char *data, const char *hora, const char *url, const char *smart);
 
 void gerarel(void)
 {
 
    FILE *fp_in;
+   FILE *fp_gen;
 
    char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN], accbytes[12], accelap[10];
    char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN], wdir[MAXLEN], per1[MAXLEN];
@@ -46,6 +47,7 @@ void gerarel(void)
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char accsmart[MAXLEN];
    char crc2[MAXLEN/2 -1];
+   char dirname[MAXLEN];
    long long int nbytes=0;
    long long int nelap=0;
    long long int nacc=0;
@@ -78,6 +80,12 @@ void gerarel(void)
 
    if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent();
 
+   sprintf(wdirname,"%s/sarg-general",dirname);
+   if((fp_gen=MY_FOPEN(wdirname,"a"))==NULL){
+      fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
+      exit(1);
+   }
+
    olduser[0]='\0';
    strncat(tmp,"/sarg",5);
 
@@ -177,8 +185,8 @@ void gerarel(void)
                strcpy(oldmsg,"OK");
                if(strstr(oldacccode,"DENIED") != 0)
                   sprintf(oldmsg,"%s",text[46]);
-               gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
-               gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+               gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+               gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
                nacc=0;
                nbytes=0;
                nelap=0;
@@ -190,10 +198,8 @@ void gerarel(void)
                strcpy(oldmsg,"OK");
                if(strstr(oldacccode,"DENIED") != 0)
                   sprintf(oldmsg,"%s",text[46]);
-               strcpy(wdirname,dirname);
-               gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
-               strcpy(wdirname,dirname);
-               gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+               gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+               gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
                nacc=0;
                nbytes=0;
                nelap=0;
@@ -312,8 +318,8 @@ void gerarel(void)
       strcpy(oldaccuser,accuser);
    gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
    strcpy(wdirname,dirname);
-   gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
-   strcpy(wdirname,dirname);
+   gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+   fclose(fp_gen);
    day_totalize(tmp,oldaccuser,indexonly);
 
    tmpsort();
@@ -430,7 +436,7 @@ static void maketmp_hour(const char *user, const char *dirname, int indexonly)
 }
 
 
-void gravatmp(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache)
+void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache)
 {
 
    FILE *fp_ou;
@@ -439,27 +445,26 @@ void gravatmp(const char *oldaccuser, const char *dirname, const char *oldurl, l
    char val3[16];
    char val4[16];
    char val5[16];
-
    char wdirname[MAXLEN];
 
    if(indexonly) return;
    if(strstr(ReportType,"users_sites") == 0) return;
 
-   strcpy(wdirname,tmp);
-   strcat(wdirname,"/");
-   strcat(wdirname,oldaccuser);
-   strcat(wdirname,".utmp");
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) {
+      fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser);
+      exit(1);
+   }
 
    if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
       exit(1);
    }
 
-   my_lltoa(nacc,val1,15);
-   my_lltoa(nbytes,val2,15);
-   my_lltoa(nelap,val3,15);
-   my_lltoa(incache,val4,15);
-   my_lltoa(oucache,val5,15);
+   my_lltoa(nacc,val1,0);
+   my_lltoa(nbytes,val2,0);
+   my_lltoa(nelap,val3,0);
+   my_lltoa(incache,val4,0);
+   my_lltoa(oucache,val5,0);
    fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5);
 
    fclose(fp_ou);
@@ -484,10 +489,10 @@ static void gravatmp_hora(const char *dirname, const char *user, const char *dat
 
    if(indexonly || (strstr(ReportType,"users_sites") == 0)) return;
 
-   strcpy(wdirname,tmp);
-   strcat(wdirname,"/");
-   strcat(wdirname,user);
-   strcat(wdirname,".htmp");
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) {
+      fprintf(stderr,"SARG: Path too long %s/%s.htmp\n",tmp,user);
+      exit(1);
+   }
 
    if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
       fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno));
@@ -507,15 +512,14 @@ static void gravaporuser(const char *user, const char *dirname, const char *url,
 {
 
    FILE *fp_ou;
-
    char wdirname[MAXLEN];
 
    if(indexonly || (strstr(ReportType,"users_sites") == 0)) return;
 
-   strcpy(wdirname,tmp);
-   strcat(wdirname,"/");
-   strcat(wdirname,user);
-   strcat(wdirname,".ip");
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,user)>=sizeof(wdirname)) {
+      fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,user);
+      exit(1);
+   }
 
    if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
@@ -535,26 +539,25 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o
 {
 
    FILE *fp_ou;
-
    char wdirname[MAXLEN];
 
    if(indexonly || (strstr(ReportType,"users_sites") == 0)) return;
 
-   strcpy(wdirname,tmp);
-   strcat(wdirname,"/");
-   strcat(wdirname,oldaccuser);
-   strcat(wdirname,".utmp");
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) {
+      fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser);
+      exit(1);
+   }
 
    if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
       exit(1);
    }
 
-   my_lltoa(nacc,val1,15);
-   my_lltoa(nbytes,val2,15);
-   my_lltoa(nelap,val3,15);
-   my_lltoa(incache,val4,15);
-   my_lltoa(oucache,val5,15);
+   my_lltoa(nacc,val1,0);
+   my_lltoa(nbytes,val2,0);
+   my_lltoa(nelap,val3,0);
+   my_lltoa(incache,val4,0);
+   my_lltoa(oucache,val5,0);
    fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5);
 
    fclose(fp_ou);
@@ -572,27 +575,14 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o
 }
 
 
-static void gravager(char *dirname, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache)
+static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache)
 {
-
-   FILE *fp_ou;
-
-   strcat(dirname,"/");
-   strcat(dirname,"sarg-general");
-
-   if((fp_ou=MY_FOPEN(dirname,"a"))==NULL){
-      fprintf(stderr, "SARG: (report) %s: %s\n",text[45],dirname);
-      exit(1);
-   }
-
-   my_lltoa(nacc,val1,15);
-   my_lltoa(nbytes,val2,15);
-   my_lltoa(nelap,val3,15);
-   my_lltoa(incache,val4,15);
-   my_lltoa(oucache,val5,15);
-   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5);
-
-   fclose(fp_ou);
+   my_lltoa(nacc,val1,0);
+   my_lltoa(nbytes,val2,0);
+   my_lltoa(nelap,val3,0);
+   my_lltoa(incache,val4,0);
+   my_lltoa(oucache,val5,0);
+   fprintf(fp_gen,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5);
    return;
 
 }
@@ -601,7 +591,6 @@ static void grava_SmartFilter(const char *dirname, const char *user, const char
 {
 
    FILE *fp_ou;
-
    char wdirname[MAXLEN];
 
    sprintf(wdirname,"%s/smartfilter.unsort",dirname);
diff --git a/sort.c b/sort.c
index fc0caef21af2f7ccd765ed604fdcafe0ff2a9ff0..93622dac91bc6d9da35997ca7c77c627290e3463 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -74,7 +74,7 @@ void tmpsort(void)
       if (dlen>0) {
          if (dlen>=sizeof(wnome)) continue;
          strncpy(wnome,direntp->d_name,dlen);
-         wnome[dlen]=0;
+         wnome[dlen]='\0';
       } else {
          wnome[0]='\0';
       }
diff --git a/util.c b/util.c
index 1a82b6b0c81f4abac0e4eec45d5d1ab8c3ba2350..a7feedcff2b90d2c3a0016b49fca2a44ba93ce84 100644 (file)
--- a/util.c
+++ b/util.c
@@ -134,65 +134,51 @@ int getword_skip(int limit, struct getwordstruct *gwarea, int stop)
    return(0);
 }
 
-
-#ifdef LEGACY_MY_ATOLL
-
-// BMG (bguillory@email.com)
-// 3 August 1999
-long long int my_atoll (const char *nptr)
-#define MAXLLL 30 //maximum number of digits in long long (a guess)
+int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop)
 {
-  int offset=0, x;
-  long long int returnval=0;
-  char one_digit[2];
-
-  one_digit[1]='\0';
-
-  // Soak up all the white space
-  while (isspace(nptr[offset])) {
-    offset++;
-  } //while
-
-  //For each character left to right
-  //change the character to a single digit
-  //multiply what we had before by 10 and add the new digit
-  for(x=offset; x<=MAXLLL+offset && isdigit(nptr[x]); x++) {
-    sprintf(one_digit, "%c", nptr[x]); //I don't know how else to do this
-    returnval = (returnval * 10) + atoi(one_digit);
-  } //for
+   int x;
 
-  return returnval;
+   *number=0LL;
+   for(x=0;isdigit(gwarea->current[x]);x++) {
+      *number=(*number * 10) + gwarea->current[x]-'0';
+   }
+   if(gwarea->current[x] && gwarea->current[x]!=stop) {
+      printf("SARG: getword_atoll loop detected after %d bytes.\n",x);
+      printf("SARG: Line=\"%s\"\n",gwarea->beginning);
+      printf("SARG: Record=\"%s\"\n",gwarea->current);
+      printf("SARG: searching for \'x%x\'\n",stop);
+      //printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
+      return(-1);
+   }
 
-} //my_atoll
+   if (gwarea->current[x]) ++x;
+   gwarea->current+=x;
+   return(0);
+}
 
-#else
 
 #define MAXLLL 30 //!< Maximum number of digits in long long (a guess).
 long long int my_atoll (const char *nptr)
 {
-  long long int returnval=0;
-  const char * t = nptr ;
+  long long int returnval=0LL;
   int max_digits = MAXLLL ;
 
   // Soak up all the white space
-  while (isspace( *t )) {
-    t++;
-  } //while
+  while (isspace( *nptr )) {
+    nptr++;
+  }
 
   //For each character left to right
   //change the character to a single digit
   //multiply what we had before by 10 and add the new digit
 
-  for( ; --max_digits && isdigit( *t ) ; t++ )
+  while (--max_digits && isdigit( *nptr ))
   {
-     returnval = ( returnval * 10 ) + ( *t - '0' ) ;
+     returnval = ( returnval * 10 ) + ( *nptr++ - '0' ) ;
   }
 
   return returnval;
-
-} //my_atoll
-
-#endif
+}
 
 static int is_absolute(const char *path)
 {
@@ -247,33 +233,53 @@ void my_mkdir(const char *name)
 
 void my_lltoa(unsigned long long int n, char s[], int len)
 {
-  int i = 0;
-  int x = 0;
-  char ww[50];
-  do {
-    s[i++] = (n % 10) + '0';
-  } while ((n /= 10) > 0);
-  s[i] = '\0';
-  {
-    int c,i,j;
-    for (i = 0, j = strlen(s)-1; i<j; i++, j--)
-      {
-        c = s[i];
-        s[i] = s[j];
-        s[j] = c;
-      }
-  }
+   int i;
+   int slen = 0;
+   int j;
+   char c;
 
-  if(len) {
-     bzero(ww,sizeof(ww));
-     i=len-strlen(s)-1;
-     for(x=0; x<=i; x++)
-        ww[x]='0';
-     i=strlen(s);
-     strncat(ww,s,i>sizeof(ww)?sizeof(ww):i);
-     strcpy(s,ww);
-  }
+   do {
+      s[slen++] = (n % 10) + '0';
+   } while ((n /= 10) > 0);
+   s[slen] = '\0';
+
+   for (i = 0, j = slen-1; i<j; i++, j--) {
+      c = s[i];
+      s[i] = s[j];
+      s[j] = c;
+   }
+
+   if(len>slen) {
+      i=len-slen;
+      for(j=slen; j>=0; j--)
+         s[j+i]=s[j];
+      for(j=0 ; j<i ; j++)
+         s[j]='0';
+   }
+
+#if 0 //old code
+   do {
+      s[slen++] = (n % 10) + '0';
+   } while ((n /= 10) > 0);
+   s[slen] = '\0';
 
+   for (i = 0, j = slen-1; i<j; i++, j--)
+   {
+      c = s[i];
+      s[i] = s[j];
+      s[j] = c;
+   }
+
+   if(len) {
+      i=len-strlen(s)-1;
+      for(x=0; x<=i; x++)
+         ww[x]='0';
+      ww[x]='\0';
+      i=strlen(s);
+      strncat(ww,s,i>sizeof(ww)?sizeof(ww):i);
+      strcpy(s,ww);
+   }
+#endif
 }
 
 
@@ -748,8 +754,7 @@ void gperiod(const char *dirname, const char *period)
    char wdirname[MAXLEN];
 
    strcpy(wdirname,dirname);
-   strcat(wdirname,"/");
-   strcat(wdirname,"sarg-period");
+   strcat(wdirname,"/sarg-period");
 
    if((fp_ou=fopen(wdirname,"w"))==NULL){
       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);