]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Allow multiple headers in an ISA log.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 1 Dec 2009 19:46:01 +0000 (19:46 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 1 Dec 2009 19:46:01 +0000 (19:46 +0000)
Introduce getword_skip to skip a word without storing it in a buffer.

CMakeLists.txt
documentation/util.txt
include/defs.h
include/info.h
log.c
util.c

index 4fa0ae6d202be7d0a2091a6e523e8f734fc1b1d9..bbba5b73a105bcd305d3e1c868b1b47deb9a0d29 100755 (executable)
@@ -3,7 +3,7 @@ PROJECT(sarg C)
 SET(sarg_VERSION 2)
 SET(sarg_REVISION 2)
 SET(sarg_BUILD "7rc1")
-SET(sarg_BUILDDATE "Nov-28-2009")
+SET(sarg_BUILDDATE "Dec-01-2009")
 
 INCLUDE(AddFileDependencies)
 INCLUDE(CheckIncludeFile)
index b544a9f496bc69fb328383ed233970fa3a0a0684..5b872de8d990bde36cd31565fa17996a3232d25f 100644 (file)
@@ -28,7 +28,7 @@ the function displays an error message and returns an error code.
 \param stop The character indicating the end of the word.
 
 \retval 0 The word is extracted.
-\retval -1 The stop character was not found before the limit or the end of the string is reached.
+\retval -1 The stop character was not found before the limit is reached.
 
 */
 
@@ -50,27 +50,24 @@ the function displays an error message and returns an error code.
 \param stop The character indicating the end of the word.
 
 \retval 0 The word is extracted.
-\retval -1 The stop character was not found before the limit or the end of the string is reached.
+\retval -1 The stop character was not found before the limit is reached.
 
 */
 
 
 
 
+/*! \fn int getword_skip(int limit, char *line, int stop)
+Skip one "word" from the text line and remove it from the text line. The word's boundary is defined
+by the \a stop character.
 
-/*! \fn int getword3(char *word, int limit, char *line, int stop)
-
-This function is now identical to getword().
-
-\param word The buffer to store the extracted word.
-\param limit The size of the buffer. If the stop character isn't found before that limit is reached,
+\param limit The maximum number of characters to skip. If the stop character isn't found before that limit is reached,
 the function displays an error message and returns an error code.
 \param line The text line from which the word must be extracted.
 \param stop The character indicating the end of the word.
 
-\retval 0 The word is extracted.
-\retval -1 The stop character was not found before the limit or the end of the string is reached.
-
+\retval 0 The word is skipped.
+\retval -1 The stop character was not found before the limit is reached.
 */
 
 
index b4505343efc9f847f2d79d4468707ddbe3a5813a..4ce1f9bbae43619a0da99b3a9f4a89fe3d6efaec 100755 (executable)
@@ -115,6 +115,7 @@ void useragent(void);
 // util.c
 int getword(char *word, int limit, char *line, int stop);
 int getword_multisep(char *word, int limit, char *line, int stop);
+int getword_skip(int limit, char *line, 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);
index 2b62dfe5a245ff3732285eff73b6fcf36289550c..734a073dd84cf2cf2f26b1e1e891ddd1bb608e91 100755 (executable)
@@ -1,3 +1,3 @@
-#define VERSION PACKAGE_VERSION" Nov-28-2009"
+#define VERSION PACKAGE_VERSION" Dec-01-2009"
 #define PGM PACKAGE_NAME
 #define URL "http://sarg.sourceforge.net"
diff --git a/log.c b/log.c
index 88b3b2488f1a83b87cf0268b473e60e8b706559a..b723be9b58efdcfa7a5adc6b746e0e4a4f0bbab4 100644 (file)
--- a/log.c
+++ b/log.c
@@ -45,6 +45,17 @@ static void getuexclude(const char *uexfile, int debug);
 
 int main(int argc,char *argv[])
 {
+   enum isa_col_id {
+      ISACOL_Ip,
+      ISACOL_UserName,
+      ISACOL_Date,
+      ISACOL_Time,
+      ISACOL_TimeTaken,
+      ISACOL_Bytes,
+      ISACOL_Uri,
+      ISACOL_Status,
+      ISACOL_Last //last entry of the list !
+   };
 
    FILE *fp_in = NULL, *fp_denied=NULL, *fp_authfail=NULL, *fp_log=NULL;
 
@@ -104,7 +115,7 @@ int main(int argc,char *argv[])
    int  narq=0;
    int  iarq=0;
    int  exstring=0;
-   int  i0=0,i1=-1,i2=-1,i3=-1,i4=-1,i5=-1,i6=-1,i7=-1,i8=-1;
+   int isa_ncols=0,isa_cols[ISACOL_Last];
    long totregsl=0;
    long totregsg=0;
    long totregsx=0;
@@ -945,84 +956,88 @@ int main(int argc,char *argv[])
                exit(1);
             }
          } else if(isalog) {
-            if(!i0) {
-               if (getword(val1,sizeof(val1),bufz,' ')<0){
+            if (bufz[0] == '#') {
+               int ncols,cols[ISACOL_Last];
+
+               fixendofline(bufz);
+               // remove the #Fields: column at the beginning of the line
+               if (getword_skip(1000,bufz,' ')<0){
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
-               fixendofline(bufz);
+               for (ncols=0 ; ncols<ISACOL_Last ; ncols++) cols[ncols]=-1;
+               ncols=0;
                while(bufz[0] != '\0') {
                   if (getword(val1,sizeof(val1),bufz,'\t')<0){
                      printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                      exit(1);
                   }
-                  if(strcmp(val1,"c-ip") == 0) i1=i0;
-                  if(strcmp(val1,"cs-username") == 0) i2=i0;
-                  if(strcmp(val1,"date") == 0) i3=i0;
-                  if(strcmp(val1,"time") == 0) i4=i0;
-                  if(strcmp(val1,"time-taken") == 0) i5=i0;
-                  if(strcmp(val1,"sc-bytes") == 0) i6=i0;
-                  if(strcmp(val1,"cs-uri") == 0) i7=i0;
-                  if(strcmp(val1,"sc-status") == 0) i8=i0;
-                  i0++;
+                  if(strcmp(val1,"c-ip") == 0) cols[ISACOL_Ip]=ncols;
+                  if(strcmp(val1,"cs-username") == 0) cols[ISACOL_UserName]=ncols;
+                  if(strcmp(val1,"date") == 0) cols[ISACOL_Date]=ncols;
+                  if(strcmp(val1,"time") == 0) cols[ISACOL_Time]=ncols;
+                  if(strcmp(val1,"time-taken") == 0) cols[ISACOL_TimeTaken]=ncols;
+                  if(strcmp(val1,"sc-bytes") == 0) cols[ISACOL_Bytes]=ncols;
+                  if(strcmp(val1,"cs-uri") == 0) cols[ISACOL_Uri]=ncols;
+                  if(strcmp(val1,"sc-status") == 0) cols[ISACOL_Status]=ncols;
+                  ncols++;
                }
-               if (i1<0) {
-                  // not the line we are looking for
-                  i0=0;
+               if (cols[ISACOL_Ip]>=0) {
+                  isa_ncols=ncols;
+                  for (isa_ncols=0 ; isa_ncols<ncols ; isa_ncols++)
+                     isa_cols[isa_ncols]=cols[isa_ncols];
                }
+               continue;
             }
-            if (!fgets(bufz,sizeof(bufz),fp_in)) {
-               fprintf(stderr,"SARG: read error in %s\n",arq);
-               exit(1);
-            }
-            for (x=0 ; x<i0 ; x++) {
+            if (!isa_ncols) continue;
+            for (x=0 ; x<isa_ncols ; x++) {
                if (getword(val1,sizeof(val1),bufz,'\t')<0) {
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
-               if (x==i1) {
+               if (x==isa_cols[ISACOL_Ip]) {
                   if (strlen(val1)>=sizeof(ip)) {
                      printf("SARG: Maybe you have a broken IP in your %s file.\n",arq);
                      exit(1);
                   }
                   strcpy(ip,val1);
-               } else if (x==i2) {
+               } else if (x==isa_cols[ISACOL_UserName]) {
                   if (strlen(val1)>=sizeof(user)) {
                      printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
                      exit(1);
                   }
                   strcpy(user,val1);
-               } else if (x==i3) {
+               } else if (x==isa_cols[ISACOL_Date]) {
                   if (strlen(val1)>=sizeof(data)) {
                      printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                      exit(1);
                   }
                   strcpy(data,val1);
-               } else if (x==i4) {
+               } else if (x==isa_cols[ISACOL_Time]) {
                   if (strlen(val1)>=sizeof(hora)) {
                      printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
                      exit(1);
                   }
                   strcpy(hora,val1);
-               } else if (x==i5) {
+               } else if (x==isa_cols[ISACOL_TimeTaken]) {
                   if (strlen(val1)>=sizeof(elap)) {
                      printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq);
                      exit(1);
                   }
                   strcpy(elap,val1);
-               } else if (x==i6) {
+               } else if (x==isa_cols[ISACOL_Bytes]) {
                   if (strlen(val1)>=sizeof(tam)) {
                      printf("SARG: Maybe you have a broken download size in your %s file.\n",arq);
                      exit(1);
                   }
                   strcpy(tam,val1);
-               } else if (x==i7) {
+               } else if (x==isa_cols[ISACOL_Uri]) {
                   if (strlen(val1)>=sizeof(url)) {
                      printf("SARG: Maybe you have a broken URL in your %s file.\n",arq);
                      exit(1);
                   }
                   strcpy(url,val1);
-               } else if (x==i8) {
+               } else if (x==isa_cols[ISACOL_Status]) {
                   if (strlen(val1)>=sizeof(code)) {
                      printf("SARG: Maybe you have a broken access code in your %s file.\n",arq);
                      exit(1);
diff --git a/util.c b/util.c
index cee9667e659b45595b7f1260b7ebdbf9b57f3c71..88ed598df4c6e2e43e9dc50efe9c6a8256c0b1c6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -111,6 +111,27 @@ int getword_multisep(char *word, int limit, char *line, int stop)
   return(0);
 }
 
+int getword_skip(int limit, char *line, int stop)
+{
+   int x,y;
+
+   for(x=0;((line[x]) && (line[x] != stop ));x++) {
+      if(x>=limit) {
+         printf("SARG: getword_skip loop detected after %d bytes.\n",x);
+         printf("SARG: Record=\"%s\"\n",line);
+         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);
+      }
+   }
+
+   if (line[x]) ++x;
+   y=0;
+
+   while((line[y++] = line[x++]));
+   return(0);
+}
+
 
 #ifdef LEGACY_MY_ATOLL