]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Use string pointers in getword instead of copying the strings
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 15 Dec 2009 20:43:57 +0000 (20:43 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 15 Dec 2009 20:43:57 +0000 (20:43 +0000)
36 files changed:
CMakeLists.txt
ChangeLog
auth.c
authfail.c
convlog.c
dansguardian_log.c
dansguardian_report.c
datafile.c
denied.c
documentation/util.txt
download.c
email.c
exclude.c
getconf.c
grepday.c
html.c
include/defs.h
index.c
ip2name.c
language.c
lastlog.c
log.c
realtime.c
repday.c
report.c
siteuser.c
smartfilter.c
splitlog.c
squidguard_log.c
squidguard_report.c
topsites.c
topuser.c
totday.c
totger.c
useragent.c
util.c

index 9dd4a0f69518376a97179c37acb0525f5424c6d0..e2291d04c42141fc3877dda68d0b448c91231c61 100755 (executable)
@@ -11,6 +11,7 @@ INCLUDE(CheckLibraryExists)
 INCLUDE(CheckFunctionExists)
 INCLUDE(CheckTypeSize)
 INCLUDE(CheckSymbolExists)
+INCLUDE(CheckCCompilerFlag)
 
 DEFINE_PROPERTY(GLOBAL PROPERTY enable-htmldir BRIEF_DOCS "--enable-htmldir=htmldir"
                         FULL_DOCS "Select htmldir as the root of your WWW documents")
@@ -58,9 +59,21 @@ ENDFOREACH(f)
 
 ADD_EXECUTABLE(sarg ${SRC})
 
-SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAG "${CFLAGS} -Wall -Wextra -Werror=implicit-function-declaration -Werror=format -Wno-sign-compare -Wno-unused-parameter")
 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")
+CHECK_C_COMPILER_FLAG("-Werror=implicit-function-declaration" HAVE_WERROR_IMPLICIT_FUNCTION)
+IF(HAVE_WERROR_IMPLICIT_FUNCTION)
+   GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+   SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Werror=implicit-function-declaration")
+ENDIF(HAVE_WERROR_IMPLICIT_FUNCTION)
+
+CHECK_C_COMPILER_FLAG("-Werror=format" HAVE_WERROR_FORMAT)
+IF(HAVE_WERROR_FORMAT)
+   GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+   SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Werror=format")
+ENDIF(HAVE_WERROR_FORMAT)
+
 # Required header files
 CHECK_INCLUDE_FILE(stdio.h HAVE_STDIO_H)
 CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H)
@@ -235,7 +248,13 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "solaris")
 
 OPTION(ENABLE_EXTRA_PROTECT "Enable compile and runtime extra protections" OFF)
 IF(ENABLE_EXTRA_PROTECT)
-   SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAG "${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror")
+   GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+   SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2 -Werror")
+   CHECK_C_COMPILER_FLAG("-Werror=format-security" HAVE_WERROR_FORMAT_SECURITY)
+   IF(HAVE_WERROR_FORMAT_SECURITY)
+      GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+      SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Werror=format-security")
+   ENDIF(HAVE_WERROR_FORMAT_SECURITY)
 ENDIF(ENABLE_EXTRA_PROTECT)
 
 # Save the configuration for the project
index 4d1842ed407d2fbeecca501bcd35c58234c318a3..4c6bdc14b10ca0e2b37ad35daefbb2303c04ba03 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,11 @@
 SARG ChangeLog
 
-Dec-03-2009 Version 2.2.7
+Dec-15-2009 Version 2.2.7
                - Extra compile and run time protection (FORTIFY_SOURCE) fixed in configure.
                - Use tabulations as columns separator in intermediary files to avoid problems when a field of the log contains a space.
                - Input log file type detection partly rewritten to clearly distinguish which type is processed where.
                - Read the input log file from standard input if log file name is -.
+               - Use string pointers in getword instead of copying the strings over and over.
 
 Dec-14-2009 Version 2.2.6.1
                - Remove unecessary dependency on off_t.
diff --git a/auth.c b/auth.c
index 3cb5d09bf23211a91da1aa77c8beeabedc068410..119f8dd50efb07d4c1993e4b6d7e8bb03206e55d 100644 (file)
--- a/auth.c
+++ b/auth.c
@@ -30,6 +30,7 @@ void htaccess(const char *name)
 {
    char htname[MAXLEN];
    FILE *fp_auth;
+   struct getwordstruct gwarea;
 
    if(strncmp(UserAuthentication,"yes",3) !=0 )
       return;
@@ -40,8 +41,8 @@ void htaccess(const char *name)
       exit(1);
    }
 
-   strcpy(warea,Require);
-   if (getword(buf,sizeof(buf),warea,'%')<0) {
+   getword_start(&gwarea,Require);
+   if (getword(buf,sizeof(buf),&gwarea,'%')<0) {
       printf("SARG: The \"Require\" entry of your sarg.conf file is too long for your %s file.\n",htname);
       exit(1);
    }
index e6b7fe8044e710525b59f3130d83c2c163e1a136..191fc37907b57ebfcce694ab685f6afaa911fa80 100644 (file)
@@ -47,6 +47,7 @@ void authfail_report(void)
    int  z=0;
    int  count=0;
    int  cstatus;
+   struct getwordstruct gwarea;
 
    if(strlen(DataFile) > 0) return;
 
@@ -117,9 +118,10 @@ void authfail_report(void)
    fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(data,sizeof(data),buf,'\t')<0 || getword(hora,sizeof(hora),buf,'\t')<0 ||
-          getword(user,sizeof(user),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
-          getword(url,sizeof(url),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
+          getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+          getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",authfail_in);
          exit(1);
       }
index ad8ba2ffd873a91c6200ccb7c10acfa5db8db182..e60d3639a59d38d74daaa0924f5b847c4793d767 100644 (file)
--- a/convlog.c
+++ b/convlog.c
@@ -37,6 +37,7 @@ void convlog(const char *arq, char *df, int dfrom, int duntil)
    time_t tt;
    int idata=0;
    struct tm *t;
+   struct getwordstruct gwarea;
 
    if(arq[0] == '\0')
       arq="/var/log/squid/access.log";
@@ -47,7 +48,8 @@ void convlog(const char *arq, char *df, int dfrom, int duntil)
    }
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(data,sizeof(data),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(data,sizeof(data),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
          exit(1);
       }
@@ -66,7 +68,7 @@ void convlog(const char *arq, char *df, int dfrom, int duntil)
        else
          strftime(dia, sizeof(dia), "%m/%d/%Y", t);
 
-      printf("%s %02d:%02d:%02d %s",dia,t->tm_hour,t->tm_min,t->tm_sec,buf);
+      printf("%s %02d:%02d:%02d %s",dia,t->tm_hour,t->tm_min,t->tm_sec,gwarea.current);
    }
 
    fclose(fp_in);
index 4a617d8a8a4fb32ded56bcb6e5a51f381b16458a..d4339044bad0b3a0c821fac2d153746cbb917a05 100644 (file)
@@ -40,6 +40,7 @@ void dansguardian_log(void)
    char wdata[127];
    int  idata=0;
    int cstatus;
+   struct getwordstruct gwarea;
 
    bzero(day, 3);
    bzero(mon, 4);
@@ -92,12 +93,12 @@ void dansguardian_log(void)
    }
 
    while(fgets(buf,sizeof(buf),fp_guard)!=NULL) {
-      if(strstr(buf,"\n") != 0)
-         buf[strlen(buf)-1]='\0';
-      if(strncmp(buf,"#",1) == 0)
+      fixendofline(buf);
+      if(buf[0]=='#')
          continue;
       if(strstr(buf,"loglocation ") != 0) {
-         if (getword(loglocation,sizeof(loglocation),buf,'\'')<0 || getword(loglocation,sizeof(loglocation),buf,'\'')<0) {
+         getword_start(&gwarea,buf);
+         if (getword_skip(MAXLEN,&gwarea,'\'')<0 || getword(loglocation,sizeof(loglocation),&gwarea,'\'')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",DansGuardianConf);
             exit(1);
          }
@@ -106,12 +107,12 @@ void dansguardian_log(void)
    }
 
    if(debug) {
-      strcpy(buf,text[7]);
-      if (getword(urly,sizeof(urly),buf,' ')<0 || getword(href,sizeof(href),buf,' ')<0) {
+      getword_start(&gwarea,text[7]);
+      if (getword(urly,sizeof(urly),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s entry.\n",text[7]);
          exit(1);
       }
-      debuga("%s DansGuardian %s: %s",urly,buf,loglocation);
+      debuga("%s DansGuardian %s: %s",urly,gwarea.current,loglocation);
    }
 
    if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
@@ -122,12 +123,13 @@ void dansguardian_log(void)
    while(fgets(buf,sizeof(buf),fp_in) != NULL) {
       if(strstr(buf," *DENIED* ") == 0)
          continue;
-      if (getword(year,sizeof(year),buf,'.')<0 || getword(mon,sizeof(mon),buf,'.')<0 ||
-          getword(day,sizeof(day),buf,' ')<0 || getword(hour,sizeof(hour),buf,' ')<0 ||
-          getword(user,sizeof(user),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 ||
-          getword(url,sizeof(url),buf,'/')<0 || getword(url,sizeof(url),buf,'/')<0 ||
-          getword(url,sizeof(url),buf,' ')<0 || getword(code1,sizeof(code1),buf,' ')<0 ||
-          getword(code1,sizeof(code1),buf,' ')<0 || getword(code2,sizeof(code2),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(year,sizeof(year),&gwarea,'.')<0 || getword(mon,sizeof(mon),&gwarea,'.')<0 ||
+          getword(day,sizeof(day),&gwarea,' ')<0 || getword(hour,sizeof(hour),&gwarea,' ')<0 ||
+          getword(user,sizeof(user),&gwarea,' ')<0 || getword(ip,sizeof(ip),&gwarea,' ')<0 ||
+          getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0 ||
+          getword(url,sizeof(url),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0 ||
+          getword(code1,sizeof(code1),&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",loglocation);
          exit(1);
       }
index a4bb4f43d8c668cfed93d41315447d8ffd718910..07b9161874c388a0d6e63ee969fcdde54459d7f3 100644 (file)
@@ -47,6 +47,7 @@ void dansguardian_report(void)
    char *str;
    int  z=0;
    int  count=0;
+   struct getwordstruct gwarea;
 
    ouser[0]='\0';
 
@@ -103,9 +104,10 @@ void dansguardian_report(void)
    fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91],text[129]);
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(user,sizeof(user),buf,'\t')<0 || getword(date2,sizeof(date2),buf,'\t')<0 ||
-          getword(hour,sizeof(hour),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
-          getword(url,sizeof(url),buf,'\t')<0 || getword(rule,sizeof(rule),buf,'\n')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
+          getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+          getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
          exit(1);
       }
index d12998e148b90e8e95a3623bbc560bd29dc789f0..a3f6229947d77335d27ecb3a5ba2eb88095bff94 100644 (file)
@@ -39,10 +39,9 @@ void data_file(char *tmp)
    char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50];
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char accsmart[MAXLEN];
-   char wcrc[50];
    char crc2[50];
    char wdname[MAXLEN];
-   char wname2[MAXLEN];
+   char *str;
    DIR *dirp;
    struct dirent *direntp;
    long long int nbytes=0;
@@ -51,6 +50,7 @@ void data_file(char *tmp)
    long long int rtotal=0;
    long long int incache=0;
    long long int oucache=0;
+   struct getwordstruct gwarea;
 
    ipantes[0]='\0';
    nameantes[0]='\0';
@@ -62,26 +62,28 @@ void data_file(char *tmp)
    while ( (direntp = readdir( dirp )) != NULL ) {
       if(strstr(direntp->d_name,".log") == 0)
          continue;
-      sprintf(tmp3,"%s/%s",tmp,direntp->d_name);
+      if (snprintf(tmp3,sizeof(tmp3),"%s/%s",tmp,direntp->d_name)>=sizeof(tmp3)) {
+         fprintf(stderr,"SARG: (datafile) directory path too long: %s/%s\n",tmp,direntp->d_name);
+         exit(1);
+      }
 
       if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){
          fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],tmp);
          exit(1);
       }
       strcpy(wdname,direntp->d_name);
-      if (getword(wname2,sizeof(wname2),wdname,'.')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",tmp);
-         exit(1);
-      }
-      strcat(user,wname2);
+      str=strchr(wdname,'.');
+      if (str) *str='\0';
+      strcat(user,wdname);
 
       ttopen=0;
       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-         if (getword(accdia,sizeof(accdia),buf,' ')<0 || getword(acchora,sizeof(acchora),buf,' ')<0 ||
-             getword(accuser,sizeof(accuser),buf,' ')<0 || getword(accip,sizeof(accip),buf,' ')<0 ||
-             getword(accurl,sizeof(accurl),buf,' ')<0 || getword(accbytes,sizeof(accbytes),buf,' ')<0 ||
-             getword(acccode,sizeof(acccode),buf,' ')<0 || getword(accelap,sizeof(accelap),buf,' ')<0 ||
-             getword(accsmart,sizeof(accsmart),buf,' ')<0 || getword(accsmart,sizeof(accsmart),buf,'"')<0) {
+         getword_start(&gwarea,buf);
+         if (getword(accdia,sizeof(accdia),&gwarea,' ')<0 || getword(acchora,sizeof(acchora),&gwarea,' ')<0 ||
+             getword(accuser,sizeof(accuser),&gwarea,' ')<0 || getword(accip,sizeof(accip),&gwarea,' ')<0 ||
+             getword(accurl,sizeof(accurl),&gwarea,' ')<0 || getword(accbytes,sizeof(accbytes),&gwarea,' ')<0 ||
+             getword(acccode,sizeof(acccode),&gwarea,' ')<0 || getword(accelap,sizeof(accelap),&gwarea,' ')<0 ||
+             getword_skip(20000,&gwarea,' ')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
             exit(1);
          }
@@ -125,11 +127,9 @@ void data_file(char *tmp)
          nbytes+=my_atoll(accbytes);
          nelap+=my_atoll(accelap);
 
-         strcpy(wcrc,acccode);
-         if (getword(crc2,sizeof(crc2),wcrc,'/')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
-            exit(1);
-         }
+         strcpy(crc2,acccode);
+         str=strchr(crc2,'/');
+         if (str) *str='\0';
 
          if(strstr(crc2,"MISS") != 0) oucache+=my_atoll(accbytes);
          else incache+=my_atoll(accbytes);
index 4d181424617c104b1a82490f3242d970c5be7406..bf831ab678cafcf2c501304667338f545a5232e4 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -46,6 +46,7 @@ void gen_denied_report(void)
    char *str;
    int  z=0;
    int  count=0;
+   struct getwordstruct gwarea;
 
    ouser[0]='\0';
    ouser2[0]='\0';
@@ -103,9 +104,10 @@ void gen_denied_report(void)
    fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(data,sizeof(data),buf,'\t')<0 || getword(hora,sizeof(hora),buf,'\t')<0 ||
-          getword(user,sizeof(user),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
-          getword(url,sizeof(url),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
+          getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+          getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",denied_in);
          exit(1);
       }
@@ -150,7 +152,7 @@ void gen_denied_report(void)
             continue;
       }
 
-      if(strlen(BlockIt) > 0)
+      if(BlockIt[0] != '\0')
          sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,url,ImageFile);
       else BlockImage[0]='\0';
 
index 9fa5c8e949291f18fb9a8f340a6913ad05980ee1..9de854b2fbeb60464f3a189e7dc33782c1c0676a 100644 (file)
@@ -13,8 +13,28 @@ The list of the months.
 
 
 
+/*! \fn void getword_start(struct getwordstruct *gwarea, const char *line)
+Initialize the getword buffer with the given text line.
 
-/*! \fn int getword(char *word, int limit, char *line, int stop)
+\param gwarea The getword buffer to initialize.
+\param line The text line to use in the getword buffer.
+*/
+
+
+
+
+
+/*! \fn void getword_restart(struct getwordstruct *gwarea)
+Restart the getword buffer from the beginning.
+
+\param gwarea The getword buffer to reset.
+*/
+
+
+
+
+
+/*! \fn int getword(char *word, int limit, struct getwordstruct *gwarea, int stop)
 
 Extract one "word" from the text line and remove it from the text line. The word's boundary is defined
 by the \a stop character. If multiple stop characters are found after the word, only the first one is
@@ -24,7 +44,7 @@ like manner.
 \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,
 the function displays an error message and returns an error code.
-\param line The text line from which the word must be extracted.
+\param gwarea The getword buffer initialized by getword_start().
 \param stop The character indicating the end of the word.
 
 \retval 0 The word is extracted.
@@ -36,7 +56,7 @@ the function displays an error message and returns an error code.
 
 
 
-/*! \fn int getword_multisep(char *word, int limit, char *line, int stop)
+/*! \fn int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop)
 
 Extract one "word" from the text line and remove it from the text line. The word's boundary is defined
 by the \a stop character. All the stop characters following the word are removed too. Therefore, passing
@@ -46,7 +66,7 @@ characters.
 \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,
 the function displays an error message and returns an error code.
-\param line The text line from which the word must be extracted.
+\param gwarea The getword buffer initialized by getword_start().
 \param stop The character indicating the end of the word.
 
 \retval 0 The word is extracted.
@@ -57,13 +77,13 @@ the function displays an error message and returns an error code.
 
 
 
-/*! \fn int getword_skip(int limit, char *line, int stop)
+/*! \fn int getword_skip(int limit, struct getwordstruct *gwarea, 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.
 
 \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 gwarea The getword buffer initialized by getword_start().
 \param stop The character indicating the end of the word.
 
 \retval 0 The word is skipped.
index b22bd7188d2823a1901bf2b2a28a4b1676feb8b9..f0c61d521930db18e66c723b4412ecee2267241d 100644 (file)
@@ -47,6 +47,7 @@ void download_report(void)
    int  z=0;
    int  count=0;
    int i;
+   struct getwordstruct gwarea;
 
    ouser[0]='\0';
    ouser2[0]='\0';
@@ -106,9 +107,10 @@ void download_report(void)
    fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(data,sizeof(data),buf,'\t')<0 || getword(hora,sizeof(hora),buf,'\t')<0 ||
-          getword(user,sizeof(user),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
-          getword(url,sizeof(url),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
+          getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+          getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",report_in);
          exit(1);
       }
diff --git a/email.c b/email.c
index 2c0d7b415771a648d0b05c196a3c516a5f0f9ffd..da36e10e0dba8d13e64d67c18e19c03a3d762004 100644 (file)
--- a/email.c
+++ b/email.c
@@ -45,6 +45,7 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con
    struct tm *local;
    int cstatus;
    char warea[MAXLEN];
+   struct getwordstruct gwarea;
 
    strcpy(wger,dirname);
    strcpy(top1,dirname);
@@ -75,48 +76,48 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con
    olduser[0]='\0';
    totuser=0;
 
-   while(fgets(warea,sizeof(warea),fp_in))
-   {
-      if (getword(user,sizeof(user),warea,'\t')<0) {
+   while(fgets(warea,sizeof(warea),fp_in)) {
+      getword_start(&gwarea,warea);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
          exit(1);
       }
       if(strcmp(user,"TOTAL") == 0) {
          continue;
       }
-      if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(url,sizeof(url),warea,'\t')<0) {
+      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(ip,sizeof(ip),warea,'\t')<0) {
+      if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken source IP address in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(hora,sizeof(hora),warea,'\t')<0) {
+      if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken time in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(data,sizeof(data),warea,'\t')<0) {
+      if (getword(data,sizeof(data),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(elap,sizeof(elap),warea,'\t')<0) {
+      if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(incac,sizeof(incac),warea,'\t')<0) {
+      if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken in cache column in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(oucac,sizeof(oucac),warea,0)<0) {
+      if (getword(oucac,sizeof(oucac),&gwarea,0)<0) {
          printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",wger);
          exit(1);
       }
@@ -246,19 +247,20 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con
 
    while(fgets(warea,sizeof(warea),fp_top1))
    {
-      if (getword(user,sizeof(user),warea,'\t')<0) {
+      getword_start(&gwarea,warea);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
          exit(1);
       }
-      if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1);
          exit(1);
       }
-      if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1);
          exit(1);
       }
-      if (getword(elap,sizeof(elap),warea,'\t')<0) {
+      if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",top1);
          exit(1);
       }
index ace99a5ad370a77d8ba2c01e625e969db62151f8..d18349e7c38bfef4611943896ed6ad7c06060f1a 100644 (file)
--- a/exclude.c
+++ b/exclude.c
 int vhexclude(const char *excludefile, const char *url)
 {
 
-   char whost[1024];
+   char *whost;
+   char *whost_next;
+   char *whost_dom;
    char *str;
    char *wurl;
-   int len;
+   char *wurl_dom;
    char *port;
 
-   len = strlen(excludefile);
-   if((str=(char *) malloc(len+1))==NULL) {
-         fprintf(stderr, "SARG: %s (%d):\n",text[59], len);
+   if((str=strdup(excludefile))==NULL) {
+         fprintf(stderr, "SARG: %s (%u):\n",text[59], (unsigned int)(strlen(excludefile)+1));
          exit(1);
    }
-   len = strlen(url);
-   if((wurl=(char *) malloc(len+1))==NULL) {
-         fprintf(stderr, "SARG: %s (%d):\n",text[59], len);
+   if((wurl=strdup(url))==NULL) {
+         fprintf(stderr, "SARG: %s (%u):\n",text[59], (unsigned int)(strlen(url)+1));
          exit(1);
    }
-   whost[0]='\0';
-   strcpy(str,excludefile);
-   strcpy(wurl,url);
-   if (getword(whost,sizeof(whost),str,' ')<0) {
-      printf("SARG: Maybe you have a broken record or garbage in your exclude host file.\n");
-      exit(1);
-   }
+   whost=str;
+   whost_next=strchr(whost,' ');
+   if (whost_next) *whost_next++ = '\0';
 
    port=strchr(wurl,':');
    if(port != NULL) {
       // remove the port number at the end of the site's address
       *port='\0';
    }
+   wurl_dom=strchr(wurl,'.');
 
    while(strcmp(whost,"*END*") != 0) {
       if(strcmp(wurl,whost) == 0) {
@@ -65,25 +62,18 @@ int vhexclude(const char *excludefile, const char *url)
          free(str);
          return(0);
       }
-      if(strchr(whost,'*') != 0) {
-         if (getword(warea,sizeof(warea),whost,'.')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your exclude host file.\n");
-            exit(1);
-         }
-         if (getword(warea,sizeof(warea),wurl,'.')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your exclude host file.\n");
-            exit(1);
-         }
-         if(strcmp(wurl,whost) == 0) {
+      if(wurl_dom != NULL && strchr(whost,'*') != 0) {
+         whost_dom=strchr(whost,'.');
+         if (whost_dom != NULL && strcmp(wurl_dom,whost_dom) == 0) {
             free(wurl);
             free(str);
             return(0);
          }
       }
-      if (getword(whost,sizeof(whost),str,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your exclude host file.\n");
-         exit(1);
-      }
+      if (whost_next == NULL) break;
+      whost=whost_next;
+      whost_next=strchr(whost,' ');
+      if (whost_next) *whost_next++ = '\0';
    }
    free(wurl);
    free(str);
index c4d6142e43dedd8edfff3362a1a12485e4fb42e6..361e4e87208c72896eceb69e8f9c52381e3eabcf 100644 (file)
--- a/getconf.c
+++ b/getconf.c
@@ -138,6 +138,7 @@ static int getparam_int(const char *param,char *buf,int *value)
 static void parmtest(char *buf)
 {
    char wbuf[50];
+   struct getwordstruct gwarea;
 
    while (*buf && (unsigned char)*buf<=' ') buf++;
 
@@ -190,11 +191,12 @@ static void parmtest(char *buf)
    if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return;
 
    if(strstr(buf,"date_format") != 0) {
-      if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in date_format parameter.\n");
          exit(1);
       }
-      strncpy(DateFormat,buf,1);
+      strncpy(DateFormat,gwarea.current,1);
       fixnone(DateFormat);
       return;
    }
@@ -384,16 +386,17 @@ static void parmtest(char *buf)
    }
 
    if(strstr(buf,"byte_cost") != 0) {
-      if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
          exit(1);
       }
-      cost=atol(buf);
-      if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
+      cost=atol(gwarea.current);
+      if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
          exit(1);
       }
-      nocost=my_atoll(buf);
+      nocost=my_atoll(gwarea.current);
       return;
    }
 
index aff71f0f88b9cf375b57a23ebb0242b749ab4d6c..e200278b8798f8c79db9e2435bfac7db76a16211 100644 (file)
--- a/grepday.c
+++ b/grepday.c
@@ -240,6 +240,7 @@ void greport_day(const char *user)
    int brect[8];
    char wdirname[MAXLEN];
    char graph[MAXLEN];
+   char buf[MAXLEN];
    char wuser[255];
    char csort[255];
    char data[20];
@@ -253,6 +254,8 @@ void greport_day(const char *user)
    struct tm *local;
    int cstatus;
    char s[15];
+   struct getwordstruct gwarea;
+   struct getwordstruct gwarea1;
 
    if(strcmp(Graphs,"yes") != 0) {
       unlink(wdirname);
@@ -430,12 +433,19 @@ void greport_day(const char *user)
    get_usertab_name(wuser,name,sizeof(name));
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(data,sizeof(data),buf,'\t')<0 || getword(day,sizeof(day),data,'/')<0) {
+      fixendofline(buf);
+      getword_start(&gwarea,buf);
+      if (getword(data,sizeof(data),&gwarea,'\t')<0) {
+         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
+         exit(1);
+      }
+      getword_start(&gwarea1,data);
+      if (getword(day,sizeof(day),&gwarea1,'/')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
          exit(1);
       }
       if(strcmp(DateFormat,"u") == 0) {
-         if (getword(day,sizeof(day),data,'/')<0) {
+         if (getword(day,sizeof(day),&gwarea1,'/')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
             exit(1);
          }
@@ -444,11 +454,10 @@ void greport_day(const char *user)
          strcpy(oday,day);
          count++;
       }
-      if (getword(bytes,sizeof(bytes),buf,'\t')<0 || getword(bytes,sizeof(bytes),buf,'\t')<0) {
+      if (getword(bytes,sizeof(bytes),&gwarea,'\t')<0 || getword(bytes,sizeof(bytes),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
          exit(1);
       }
-      bytes[strlen(bytes)-1]='\0';
 
       if(strcmp(oday,day) != 0) {
          strcpy(warea,oday);
diff --git a/html.c b/html.c
index df1851fab614afd9b102815b43f1b7697ccca62e..78955a20e6197cd7d3c6ed77721df4e4cbaad4c9 100644 (file)
--- a/html.c
+++ b/html.c
@@ -55,6 +55,7 @@ void htmlrel(void)
    char href2[MAXLEN];
    char urly[MAXLEN];
    char siteind[MAXLEN];
+   struct getwordstruct gwarea;
 
    if(strstr(ReportType,"users_sites") == 0) return;
 
@@ -88,19 +89,20 @@ void htmlrel(void)
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       if(strstr(buf,"TOTAL") == 0) {
-         if (getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+         getword_start(&gwarea,buf);
+         if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
             exit(1);
          }
-         ttnacc+=my_atoll(buf);
-         if (getword(wtemp,sizeof(wtemp),buf,'\t')<0 || getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+         ttnacc+=my_atoll(gwarea.current);
+         if (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);
             exit(1);
          }
          totbytes+=my_atoll(wtemp);
-         if (getword(wtemp,sizeof(wtemp),buf,'\t')<0 || getword(wtemp,sizeof(wtemp),buf,'\t')<0 ||
-             getword(wtemp,sizeof(wtemp),buf,'\t')<0 || getword(wtemp,sizeof(wtemp),buf,'\t')<0 ||
-             getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+         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);
             exit(1);
          }
@@ -180,28 +182,29 @@ void htmlrel(void)
       }
 
       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-         if (getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+         getword_start(&gwarea,buf);
+         if (getword(wtemp,sizeof(wtemp),&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),buf,'\t')<0) {
+         if (getword(wtemp,sizeof(wtemp),&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);
-         if (getword(wtemp,sizeof(wtemp),buf,'\t')<0 || getword(wtemp,sizeof(wtemp),buf,'\t')<0 ||
-             getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+         if (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",arqin);
             exit(1);
          }
          tnelap+=my_atoll(wtemp);
-         if (getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+         if (getword(wtemp,sizeof(wtemp),&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),buf,'\t')<0) {
+         if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
             exit(1);
          }
@@ -288,31 +291,32 @@ void htmlrel(void)
       }
 
       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-         if (getword(nacc,sizeof(nacc),buf,'\t')<0) {
+         getword_start(&gwarea,buf);
+         if (getword(nacc,sizeof(nacc),&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),buf,'\t')<0) {
+         if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
             exit(1);
          }
-         if (getword(url,sizeof(url),buf,'\t')<0) {
+         if (getword(url,sizeof(url),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken url in your %s file.\n",arqin);
             exit(1);
          }
-         if (getword(tmsg,sizeof(tmsg),buf,'\t')<0) {
+         if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken status in your %s file.\n",arqin);
             exit(1);
          }
-         if (getword(nelap,sizeof(nelap),buf,'\t')<0) {
+         if (getword(nelap,sizeof(nelap),&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),buf,'\t')<0) {
+         if (getword(incac,sizeof(incac),&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),buf,'\t')<0) {
+         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);
             exit(1);
          }
@@ -361,11 +365,12 @@ void htmlrel(void)
          } else {
             strcpy(urly,url);
             url_module(url, module);
-            if (getword(warea,sizeof(warea),url,'/')<0) {
-               printf("SARG: Maybe you have a broken record or garbage in the url of the %s file.\n",arqin);
-               exit(1);
+            str=strchr(url,'/');
+            if (str){
+               *str='\0';
+               strcat(url,"...");
+               strcat(url,module);
             }
-            sprintf(url,"%s...%s",warea,module);
          }
 
          if(strcmp(Privacy,"yes") == 0)
@@ -484,27 +489,28 @@ void htmlrel(void)
             olduserip[0]='\0';
 
             while(fgets(buf,sizeof(buf),fp_ip)) {
-               if (getword(user_ip,sizeof(user_ip),buf,'\t')<0) {
+               getword_start(&gwarea,buf);
+               if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
                   printf("SARG: Maybe you have a broken user IP in your %s file.\n",tmp3);
                   exit(1);
                }
-               if (getword(userurl,sizeof(userurl),buf,'\t')<0) {
+               if (getword(userurl,sizeof(userurl),&gwarea,'\t')<0) {
                   printf("SARG: Maybe you have a broken user URL in your %s file.\n",tmp3);
                   exit(1);
                }
-               if (getword(userdia,sizeof(userdia),buf,'\t')<0) {
+               if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) {
                   printf("SARG: Maybe you have a broken day in your %s file.\n",tmp3);
                   exit(1);
                }
-               if (getword(userhora,sizeof(userhora),buf,'\t')<0) {
+               if (getword(userhora,sizeof(userhora),&gwarea,'\t')<0) {
                   printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3);
                   exit(1);
                }
-               if (getword(userbytes,sizeof(userbytes),buf,'\t')<0) {
+               if (getword(userbytes,sizeof(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),buf,'\t')<0) {
+               if (getword(userelap,sizeof(userelap),&gwarea,'\t')<0) {
                   printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",tmp3);
                   exit(1);
                }
index 4e6428bfdf76254cd334bf388e1d51e629480910..c9d54986a41f47a989cbe8cf021aff9ce7f41a8f 100755 (executable)
@@ -1,3 +1,10 @@
+
+struct getwordstruct
+{
+   const char *current;
+   const char *beginning;
+};
+
 // auth.c
 void htaccess(const char *name);
 
@@ -113,9 +120,11 @@ void usage(const char *prog);
 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 getword_start(struct getwordstruct *gwarea, const char *line);
+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);
 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 a28df4215a2a99e446bcbede9cf14b6a6645583b..d8f9939a4417ba82ec3f181ebcb3824f6861b4f3 100644 (file)
--- a/index.c
+++ b/index.c
@@ -48,12 +48,13 @@ void make_index(void)
    char media[20];
    char ftime[128];
    char day[16], mon[16], year[40], hour[10];
-   char h[3], m[3], s[3];
+   char *str;
    int cstatus;
+   int iyear, imonth, iday, ihour, iminute, isecond;
    char y1[5], y2[5];
    char d1[3], d2[3];
    char m1[4], m2[4];
-   int iyear, imonth, iday, ihour, iminute, isecond;
+   struct getwordstruct gwarea;
 
    if(LastLog[0] != '\0') mklastlog(outdir);
 
@@ -132,12 +133,10 @@ void make_index(void)
                   if(!isdigit(direntp3->d_name[0]) && !isdigit(direntp3->d_name[1])) continue;
                   bzero(newname,512);
                   strcpy(warea,direntp2->d_name);
-                  if(strstr(warea,"-") != 0) {
-                     if (getword_multisep(m1,sizeof(m1),warea,'-')<0) {
-                        printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2);
-                        exit(1);
-                     }
-                     strcpy(m2,warea);
+                  if((str = strchr(warea,'-')) != 0) {
+                     *str++ = '\0';
+                     strcpy(m1,warea);
+                     strcpy(m2,str);
                      conv_month_name(m1);
                      conv_month_name(m2);
                   } else {
@@ -146,11 +145,9 @@ void make_index(void)
                      strcpy(m2,m1);
                   }
                   strcpy(warea,direntp3->d_name);
-                  if(strstr(warea,"-") != 0) {
-                     if (getword_multisep(d1,sizeof(d1),warea,'-')<0) {
-                        printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2);
-                        exit(1);
-                     }
+                  if((str = strchr(warea,'-')) != 0) {
+                     *str++ = '\0';
+                     strcpy(d1,warea);
                      strcpy(d2,warea);
                   } else {
                      strcpy(d1,warea);
@@ -213,44 +210,36 @@ void make_index(void)
             /*
             Old code to parse a date stored by sarg before 2.2.6.1 in the sarg-date file of each report directory.
             */
-            strcpy(html,data);
-            if (getword_multisep(mon,sizeof(mon),html,' ')<0) {
+            getword_start(&gwarea,data);
+            if (getword_multisep(mon,sizeof(mon),&gwarea,' ')<0) {
                printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
                exit(1);
             }
-            if (getword_multisep(mon,sizeof(mon),html,' ')<0) {
+            if (getword_multisep(mon,sizeof(mon),&gwarea,' ')<0) {
                printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
                exit(1);
             }
-            if (getword_multisep(day,sizeof(day),html,' ')<0) {
+            if (getword_multisep(day,sizeof(day),&gwarea,' ')<0) {
                printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
                exit(1);
             }
-            if (getword_multisep(hour,sizeof(hour),html,' ')<0) {
+            if (getword_multisep(hour,sizeof(hour),&gwarea,' ')<0) {
                printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
                exit(1);
             }
             do {
-               if (getword_multisep(year,sizeof(year),html,' ')<0) {
+               if (getword_multisep(year,sizeof(year),&gwarea,' ')<0) {
                   printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
                   exit(1);
                }
             } while (year[0] && !isdigit(year[0])); //skip time zone information with spaces until the year is found
             strcpy(html,hour);
-            if (getword_multisep(h,sizeof(h),html,':')<0) {
-               printf("SARG: Maybe you have a broken hour in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-               exit(1);
-            }
-            if (getword_multisep(m,sizeof(m),html,':')<0) {
-               printf("SARG: Maybe you have a broken minute in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-               exit(1);
-            }
-            if (getword_multisep(s,sizeof(s),html,0)<0) {
-               printf("SARG: Maybe you have a broken second in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+            if (sscanf(hour,"%d:%d:%d",&ihour,&iminute,&isecond)!=3) {
+               printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
                exit(1);
             }
             buildymd(day,mon,year,ftime);
-            fprintf(fp_tmp,"%s%s%s%s;%s;%s;%s;%s;%s;%s\n",ftime, h, m, s, direntp->d_name, data, tuser, tbytes, media,newname);
+            fprintf(fp_tmp,"%s%02d%02d%02d;%s;%s;%s;%s;%s;%s\n",ftime, ihour, iminute, isecond, direntp->d_name, data, tuser, tbytes, media,newname);
          }
          continue;
       }
@@ -284,11 +273,12 @@ void make_index(void)
       write_html_header(fp_ou, ".");
       fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[130],hbc1,text[132]);
       while(fgets(wwork1,sizeof(wwork1),fp_tmp)!=NULL) {
-         if (getword(tmp4,sizeof(tmp4),wwork1,'\t')<0) {
+         getword_start(&gwarea,wwork1);
+         if (getword(tmp4,sizeof(tmp4),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
             exit(1);
          }
-         fprintf(fp_ou,"<tr><td class=\"data2\"><a href=\"%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",tmp4,tmp4,wwork1);
+         fprintf(fp_ou,"<tr><td class=\"data2\"><a href=\"%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",tmp4,tmp4,gwarea.current);
          sprintf(tmp2,"%s%s",outdir,tmp4);
          sprintf(tmp3,"%s%s/index.unsort",outdir,tmp4);
          // Year dir
@@ -325,18 +315,15 @@ void make_index(void)
          }
          write_html_header(fp_ou2,"..");
          fprintf(fp_ou2,"<tr><th %s>%s/%s</th></tr>\n",hbc1,text[130],text[131]);
-         while(fgets(wwork1,MAXLEN,fp_tmp2)!=NULL) {
-            wwork1[strlen(wwork1)-1]='\0';
+         while(fgets(wwork1,sizeof(wwork1),fp_tmp2)!=NULL) {
+            fixendofline(wwork1);
             strcpy(tmp5,wwork1);
-            if(strstr(tmp5,"-") != 0) {
-               if (getword_multisep(warea,sizeof(warea),tmp5,'-')<0) {
-                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp3);
-                  exit(1);
-               }
-               name_month(warea,sizeof(warea));
-               sprintf(tmp6,"%s-",warea);
+            if((str = strchr(tmp5,'-')) != 0) {
+               *str++ = '\0';
+               strcpy(tmp6,str);
                name_month(tmp5,sizeof(tmp5));
-               sprintf(nmonth,"%s%s",tmp6,tmp5);
+               name_month(tmp6,sizeof(tmp6));
+               sprintf(nmonth,"%s-%s",tmp5,tmp6);
             } else {
                strcpy(nmonth,tmp5);
                name_month(nmonth,sizeof(nmonth));
@@ -420,28 +407,29 @@ void make_index(void)
       }
       write_html_header(fp_ou,".");
       fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[101],hbc1,text[102],hbc1,text[103],hbc1,text[93],hbc1,text[96]);
-      while(fgets(buf,MAXLEN,fp_tmp2)!=NULL) {
-         if (getword_multisep(period,sizeof(period),buf,';')<0) {
+      while(fgets(buf,sizeof(buf),fp_tmp2)!=NULL) {
+         getword_start(&gwarea,buf);
+         if (getword_multisep(period,sizeof(period),&gwarea,';')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
             exit(1);
          }
-         if (getword_multisep(period,sizeof(period),buf,';')<0) {
+         if (getword_multisep(period,sizeof(period),&gwarea,';')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
             exit(1);
          }
-         if (getword_multisep(data,sizeof(data),buf,';')<0) {
+         if (getword_multisep(data,sizeof(data),&gwarea,';')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
             exit(1);
          }
-         if (getword_multisep(tuser,sizeof(tuser),buf,';')<0) {
+         if (getword_multisep(tuser,sizeof(tuser),&gwarea,';')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
             exit(1);
          }
-         if (getword_multisep(tbytes,sizeof(tbytes),buf,';')<0) {
+         if (getword_multisep(tbytes,sizeof(tbytes),&gwarea,';')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
             exit(1);
          }
-         if (getword_multisep(media,sizeof(media),buf,';')<0) {
+         if (getword_multisep(media,sizeof(media),&gwarea,';')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
             exit(1);
          }
index 6240e2f985b78d0f5667cb489b3bfb97b5fe69a9..344af8d9d7f8ea5b696ced844fc137ff4a7f6ea2 100644 (file)
--- a/ip2name.c
+++ b/ip2name.c
@@ -27,7 +27,7 @@
 #include "include/defs.h"
 
 void ip2name(char *ip,int ip_len)
-{ 
+{
    u_long addr;
    struct hostent *hp;
    char **p;
@@ -51,7 +51,7 @@ void ip2name(char *ip,int ip_len)
 }
 
 void name2ip(char *name)
-{ 
+{
    struct in_addr ia;
    struct hostent *hp;
    char *port;
@@ -59,22 +59,23 @@ void name2ip(char *name)
    char n2[4];
    char n3[4];
    char n4[4];
+   struct getwordstruct gwarea;
 
    port=strchr(name,':');
    if (port) *port=0;
 
    if((hp=gethostbyname(name))==NULL)
       return;
-      
+
    memcpy(&ia.s_addr,hp->h_addr_list[0],sizeof(ia.s_addr));
    ia.s_addr=ntohl(ia.s_addr);
-   strcpy(name,inet_ntoa(ia));
-   if (getword(n4,sizeof(n4),name,'.')<0 || getword(n3,sizeof(n3),name,'.')<0 ||
-         getword(n2,sizeof(n2),name,'.')<0 || getword(n1,sizeof(n1),name,0)<0) {
-      printf("SARG: Maybe you have a broken record or garbage in your %s ip address.\n",name);
+   getword_start(&gwarea,inet_ntoa(ia));
+   if (getword(n4,sizeof(n4),&gwarea,'.')<0 || getword(n3,sizeof(n3),&gwarea,'.')<0 ||
+         getword(n2,sizeof(n2),&gwarea,'.')<0 || getword(n1,sizeof(n1),&gwarea,0)<0) {
+      printf("SARG: Maybe you have a broken record or garbage in your %s ip address.\n",gwarea.beginning);
       exit(1);
    }
    sprintf(name,"%s.%s.%s.%s",n1,n2,n3,n4);
 
    return;
-} 
+}
index 8d9558522c1bbc49fdaa759167c37b841062e5e2..e01ceacfa8b3d7f2ba001b73b0228283af9087af 100644 (file)
@@ -31,6 +31,7 @@ void language_load(const char *language)
    char lfile[FILENAME_MAX];
    FILE *fp_text;
    char buf[MAXLEN];
+   char *begin, *end;
    int record=0;
 
    if (snprintf(lfile,sizeof(lfile),LANGDIR"/%s",language)>=sizeof(lfile)) {
@@ -46,14 +47,21 @@ void language_load(const char *language)
       printf("Reading language from %s\n",lfile);
 
    while(record<sizeof(text)/sizeof(text[0]) && fgets(buf,sizeof(buf),fp_text)!=NULL) {
-      if (getword(warea,sizeof(warea),buf,'"')<0 || getword(warea,sizeof(warea),buf,'"')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",lfile);
-         exit(1);
+      if (buf[0] == '#') {
+         text[record][0] = '\0';
+      } else {
+         begin = strchr(buf,'\"');
+         if (begin == NULL) {
+            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",lfile);
+            exit(1);
+         }
+         begin++;
+         end = strchr(begin,'\"');
+         if (end) *end = '\0';
+         strcpy(text[record],begin);
       }
-      strcpy(text[record],warea);
-
       if(langcode)
-         printf("%d %s\n",record,warea);
+         printf("%d %s\n",record,begin);
 
       record++;
    }
index 31ca76ae7df6ea11ab1972ab39df0d264538241e..3131c06e109dec425de229a5efd2b419d8e73d90 100644 (file)
--- a/lastlog.c
+++ b/lastlog.c
@@ -40,6 +40,7 @@ void mklastlog(const char *outdir)
    struct tm *local;
    struct stat statb;
    int cstatus;
+   struct getwordstruct gwarea;
 
    if(strcmp(LastLog,"0") == 0)
       return;
@@ -52,7 +53,7 @@ void mklastlog(const char *outdir)
 
    dirp = opendir(outdir);
    while ((direntp = readdir( dirp )) != NULL ){
-      if(strstr(direntp->d_name,"-") == 0)
+      if(strchr(direntp->d_name,'-') == 0)
          continue;
 
       sprintf(warea,"%s%s",outdir,direntp->d_name);
@@ -64,7 +65,6 @@ void mklastlog(const char *outdir)
       ftot++;
    }
 
-   (void)rewinddir( dirp );
    (void)closedir( dirp );
    fclose(fp_ou);
 
@@ -93,30 +93,28 @@ void mklastlog(const char *outdir)
      exit(1);
    }
 
-   while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(warea,sizeof(warea),buf,'\t')<0) {
+   while(ftot>0 && fgets(buf,sizeof(buf),fp_in)!=NULL) {
+      fixendofline(buf);
+      getword_start(&gwarea,buf);
+      if (getword(warea,sizeof(warea),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",temp);
          exit(1);
       }
-      fixendofline(buf);
 
-      if(ftot) {
-         if(debug)
-            debuga("%s: %s",text[81],buf);
-//         sprintf(temp,"%s%s",outdir,buf);
-         if (snprintf(temp,sizeof(temp),"rm -r \"%s%s\"",outdir,buf)>=sizeof(temp)) {
-            fprintf(stderr,"SARG: Directory name too long: %s%s\n",outdir,buf);
-            exit(1);
-         }
-         cstatus=system(temp);
-         if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
-            fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
-            fprintf(stderr, "SARG: command: %s\n",temp);
-            exit(1);
-         }
-         unlink(temp);
-         ftot--;
+      if(debug)
+         debuga("%s: %s",text[81],gwarea.current);
+      if (snprintf(temp,sizeof(temp),"rm -r \"%s%s\"",outdir,gwarea.current)>=sizeof(temp)) {
+         fprintf(stderr,"SARG: Directory name too long: %s%s\n",outdir,gwarea.current);
+         exit(1);
+      }
+      cstatus=system(temp);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: command: %s\n",temp);
+         exit(1);
       }
+      unlink(temp);
+      ftot--;
    }
 
    fclose(fp_in);
diff --git a/log.c b/log.c
index 9c34cee53614a16f185ce10651cfa421d8e134ef..86d2000b626516a254261e9f3b91791fb01b2dca 100644 (file)
--- a/log.c
+++ b/log.c
@@ -75,10 +75,8 @@ int main(int argc,char *argv[])
    extern int optopt;
    extern char *optarg;
 
-   char w[MAXLEN];
    char data[255];
    char elap[255];
-   char none[255];
    char ip[MAXLEN];
    char msg[MAXLEN];
    char tam[255];
@@ -96,7 +94,7 @@ int main(int argc,char *argv[])
    char arq[255];
    char arq_log[255];
    char warq[255][255];
-   char hm[15], hmf[15], hmr[15], whm[15];
+   char hm[15], hmf[15], hmr[15];
    int  chm=0;
    char uagent[MAXLEN];
    char hexclude[MAXLEN];
@@ -137,6 +135,7 @@ int main(int argc,char *argv[])
    int download_flag;
    char download_url[MAXLEN];
    char sz_Last_User[MAXLEN]="";
+   struct getwordstruct gwarea;
 
    BgImage[0]='\0';
    LogoImage[0]='\0';
@@ -310,9 +309,10 @@ int main(int argc,char *argv[])
             strcpy(hexclude,optarg);
             break;
          case 'd':
-            strcpy(date,optarg);
-            strcpy(cduntil,optarg);
-            if (getword(cdfrom,sizeof(cdfrom),cduntil,'-')<0) {
+            strncpy(date,optarg,sizeof(date)-1);
+            date[sizeof(date)-1]='\0';
+            getword_start(&gwarea,optarg);
+            if (getword(cdfrom,sizeof(cdfrom),&gwarea,'-')<0 || getword(cduntil,sizeof(cduntil),&gwarea,0)<0) {
                printf("SARG: Maybe you have a broken record or garbage in your date range.\n");
                exit(1);
             }
@@ -366,39 +366,31 @@ int main(int argc,char *argv[])
             strcpy(site,optarg);
             break;
          case 't':
+         {
+            int h,m;
+
             if(strstr(optarg,"-") == 0) {
               strcpy(hm,optarg);
               strcpy(hmf,optarg);
             } else {
-               if (getword(hm,sizeof(hm),optarg,'-')<0) {
-                  printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
+               getword_start(&gwarea,optarg);
+               if (getword(hm,sizeof(hm),&gwarea,'-')<0 || getword(hmf,sizeof(hmf),&gwarea,0)<0) {
+                  fprintf(stderr,"SARG: Maybe you have a broken record or garbage in your time range.\n");
                   exit(1);
                }
-               strcpy(hmf,optarg);
             }
-            if(strlen(hm) > 5) {
-               printf("SARG: time period must be MM or MM:SS. Exit.\n");
+            if(sscanf(hm,"%d:%d",&h,&m)!=2) {
+               fprintf(stderr,"SARG: time period must be MM or MM:SS. Exit.\n");
                exit(1);
             }
-            bzero(whm,15);
-            if(strstr(hm,":") != 0) {
-               if (getword(warea,sizeof(warea),hm,':')<0) {
-                  printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
-                  exit(1);
-               }
-               sprintf(whm,"%s%s",warea,hm);
-               strcpy(hm,whm);
-            }
-            bzero(whm,15);
-            if(strstr(hmf,":") != 0) {
-               if (getword(warea,sizeof(warea),hmf,':')<0) {
-                  printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
-                  exit(1);
-               }
-               sprintf(whm,"%s%s",warea,hmf);
-               strcpy(hmf,whm);
+            sprintf(hm,"%02d%02d",h,m);
+            if(sscanf(hmf,"%d:%d",&h,&m)!=2) {
+               fprintf(stderr,"SARG: time period must be MM or MM:SS. Exit.\n");
+               exit(1);
             }
+            sprintf(hmf,"%02d%02d",h,m);
             break;
+         }
          case 'u':
             strcpy(us,optarg);
             break;
@@ -765,8 +757,9 @@ int main(int argc,char *argv[])
             }
 
             if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
-               if (getword(val2,sizeof(val2),arqtt,'-')<0 || getword(val2,sizeof(val2),arqtt,'_')<0 ||
-                   getword(val3,sizeof(val3),arqtt,'-')<0 || getword(val3,sizeof(val3),arqtt,'_')<0) {
+               getword_start(&gwarea,arqtt);
+               if (getword(val2,sizeof(val2),&gwarea,'-')<0 || getword(val2,sizeof(val2),&gwarea,'_')<0 ||
+                   getword(val3,sizeof(val3),&gwarea,'-')<0 || getword(val3,sizeof(val3),&gwarea,'_')<0) {
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
@@ -819,18 +812,18 @@ int main(int argc,char *argv[])
 
          // exclude_string
          exstring=0;
-         if(strlen(ExcludeString) > 0) {
+         if(ExcludeString[0] != '\0') {
             strcpy(warea,bufz);
-            strcpy(html,ExcludeString);
-            while(strstr(html,":") != 0) {
-               if (getword_multisep(val1,sizeof(val1),html,':')<0) {
+            getword_start(&gwarea,ExcludeString);
+            while(strchr(gwarea.current,':') != 0) {
+               if (getword_multisep(val1,sizeof(val1),&gwarea,':')<0) {
                   printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
                   exit(1);
                }
                if((str=(char *) strstr(warea,val1)) != (char *) NULL )
                   exstring++;
             }
-            if((str=(char *) strstr(warea,html)) != (char *) NULL )
+            if((str=(char *) strstr(warea,gwarea.current)) != (char *) NULL )
                   exstring++;
          }
          if(exstring) continue;
@@ -844,7 +837,8 @@ int main(int argc,char *argv[])
             printf("BUF=%s\n",bufz);
 
          if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) {
-            if (getword(data,sizeof(data),bufz,' ')<0) {
+            getword_start(&gwarea,bufz);
+            if (getword(data,sizeof(data),&gwarea,' ')<0) {
                printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
                exit(1);
             }
@@ -853,30 +847,34 @@ int main(int argc,char *argv[])
                   strcpy(ip,data);
                   strcpy(elap,"0");
                   if(squid24) {
-                     if (getword(user,sizeof(user),bufz,' ')<0 || getword(none,sizeof(none),bufz,' ')<0) {
+                     if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) {
                         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                         exit(1);
                      }
                   } else {
-                     if (getword(none,sizeof(none),bufz,' ')<0 || getword(user,sizeof(user),bufz,' ')<0) {
+                     if (getword_skip(255,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
                         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                         exit(1);
                      }
                   }
-                  if (getword(data,sizeof(data),bufz,']')<0 || getword(fun,sizeof(fun),bufz,'"')<0 ||
-                      getword(fun,sizeof(fun),bufz,' ')<0 || getword(url,sizeof(url),bufz,' ')<0 ||
-                      getword(code2,sizeof(code2),bufz,' ')<0 || getword(code2,sizeof(code2),bufz,' ')<0 ||
-                      getword(tam,sizeof(tam),bufz,' ')<0) {
+                  if (getword(data,sizeof(data),&gwarea,']')<0 || getword_skip(MAXLEN,&gwarea,'"')<0 ||
+                      getword(fun,sizeof(fun),&gwarea,' ')<0 || getword(url,sizeof(url),&gwarea,' ')<0 ||
+                      getword_skip(MAXLEN,&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0 ||
+                      getword(tam,sizeof(tam),&gwarea,' ')<0) {
                      printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                      exit(1);
                   }
-                  if((str=(char *) strchr(bufz, ' ')) != (char *) NULL ) {
-                     if (getword(code,sizeof(code),bufz,' ')<0) {
+                  if((str=(char *) strchr(gwarea.current, ' ')) != (char *) NULL ) {
+                     if (getword(code,sizeof(code),&gwarea,' ')<0) {
+                        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                        exit(1);
+                     }
+                  } else {
+                     if (getword(code,sizeof(code),&gwarea,'\0')<0) {
                         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                         exit(1);
                      }
                   }
-                  else strcpy(code,bufz);
 
                   if ((str = strchr(code, ':')) != NULL)
                      *str = '/';
@@ -890,33 +888,33 @@ int main(int argc,char *argv[])
             }
 
             if(ilf==ILF_Unknown || ilf==ILF_Squid) {
-               if (getword(elap,sizeof(elap),bufz,' ')<0) {
+               if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
-               while(strcmp(elap,"") == 0 && strlen(bufz) > 0)
-                  if (getword(elap,sizeof(elap),bufz,' ')<0) {
+               while(strcmp(elap,"") == 0 && gwarea.current[0] != '\0')
+                  if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
                      printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                      exit(1);
                   }
                if(strlen(elap) < 1) continue;
-               if (getword(ip,sizeof(ip),bufz,' ')<0){
+               if (getword(ip,sizeof(ip),&gwarea,' ')<0){
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
-               if (getword(code,sizeof(code),bufz,' ')<0){
+               if (getword(code,sizeof(code),&gwarea,' ')<0){
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
-               if (getword(tam,sizeof(tam),bufz,' ')<0){
+               if (getword(tam,sizeof(tam),&gwarea,' ')<0){
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
-               if (getword(fun,sizeof(fun),bufz,' ')<0){
+               if (getword(fun,sizeof(fun),&gwarea,' ')<0){
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
-               if (getword(url,sizeof(url),bufz,' ')<0){
+               if (getword(url,sizeof(url),&gwarea,' ')<0){
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
@@ -924,7 +922,7 @@ int main(int argc,char *argv[])
 //                 getword(warea,bufz,' ');
 //                 strcat(url,warea);
 //              }
-               if (getword(user,sizeof(user),bufz,' ')<0){
+               if (getword(user,sizeof(user),&gwarea,' ')<0){
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
@@ -933,39 +931,40 @@ int main(int argc,char *argv[])
             }
          }
          if (ilf==ILF_Sarg) {
-            if (getword(data,sizeof(data),bufz,' ')<0){
+            getword_start(&gwarea,bufz);
+            if (getword(data,sizeof(data),&gwarea,' ')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(hora,sizeof(hora),bufz,' ')<0) {
+            if (getword(hora,sizeof(hora),&gwarea,' ')<0) {
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(user,sizeof(user),bufz,' ')<0) {
+            if (getword(user,sizeof(user),&gwarea,' ')<0) {
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(ip,sizeof(ip),bufz,' ')<0) {
+            if (getword(ip,sizeof(ip),&gwarea,' ')<0) {
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(url,sizeof(url),bufz,' ')<0){
+            if (getword(url,sizeof(url),&gwarea,' ')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(tam,sizeof(tam),bufz,' ')<0){
+            if (getword(tam,sizeof(tam),&gwarea,' ')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(code,sizeof(code),bufz,' ')<0){
+            if (getword(code,sizeof(code),&gwarea,' ')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(elap,sizeof(elap),bufz,' ')<0){
+            if (getword(elap,sizeof(elap),&gwarea,' ')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(smartfilter,sizeof(smartfilter),bufz,' ')<0){
+            if (getword(smartfilter,sizeof(smartfilter),&gwarea,' ')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
@@ -975,15 +974,16 @@ int main(int argc,char *argv[])
                int ncols,cols[ISACOL_Last];
 
                fixendofline(bufz);
+               getword_start(&gwarea,bufz);
                // remove the #Fields: column at the beginning of the line
-               if (getword_skip(1000,bufz,' ')<0){
+               if (getword_skip(1000,&gwarea,' ')<0){
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
                for (ncols=0 ; ncols<ISACOL_Last ; ncols++) cols[ncols]=-1;
                ncols=0;
-               while(bufz[0] != '\0') {
-                  if (getword(val1,sizeof(val1),bufz,'\t')<0){
+               while(gwarea.current[0] != '\0') {
+                  if (getword(val1,sizeof(val1),&gwarea,'\t')<0){
                      printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                      exit(1);
                   }
@@ -1005,8 +1005,9 @@ int main(int argc,char *argv[])
                continue;
             }
             if (!isa_ncols) continue;
+            getword_start(&gwarea,bufz);
             for (x=0 ; x<isa_ncols ; x++) {
-               if (getword(val1,sizeof(val1),bufz,'\t')<0) {
+               if (getword(val1,sizeof(val1),&gwarea,'\t')<0) {
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                   exit(1);
                }
@@ -1065,15 +1066,19 @@ int main(int argc,char *argv[])
                sprintf(val1,"DENIED/%s",code);
                strcpy(code,val1);
             }
-            if (getword(ano,sizeof(ano),data,'-')<0){
+            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);
+               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);
                exit(1);
             }
-            if (getword(mes,sizeof(mes),data,'-')<0){
+            if (getword(dia,sizeof(dia),&gwarea,'\0')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            strcpy(dia,data);
             conv_month_name(mes);
             sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
          }
@@ -1113,13 +1118,13 @@ int main(int argc,char *argv[])
             *str='\0';
          }
 
-         while(strstr(user,"%5c") != 0) {
-            if (getword_multisep(w,sizeof(w),user,'%')<0){
-               printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
-               exit(1);
-            }
-            strcpy(wuser,user+2);
-            sprintf(user,"%s.%s",w,wuser);
+         /*
+         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];
          }
 
          for(str=user; *str; str++) {
@@ -1130,16 +1135,14 @@ int main(int argc,char *argv[])
 
          strlow(user);
          if(strncmp(NtlmUserFormat,"user",4) == 0) {
-            if(strchr(user,'_') != 0)
-               if (getword_multisep(warea,sizeof(warea),user,'_')<0){
-                  printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
-                  exit(1);
-               }
-            if(strchr(user,'+') != 0)
-               if (getword_multisep(warea,sizeof(warea),user,'+')<0){
-                  printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
-                  exit(1);
-               }
+            if((str = strchr(user,'_')) != 0) {
+               strcpy(warea,str+1);
+               strcpy(user,warea);
+            }
+            if((str = strchr(user,'+')) != 0) {
+               strcpy(warea,str+1);
+               strcpy(user,warea);
+            }
          }
 
          if(strstr(ReportType,"denied") != 0)
@@ -1151,24 +1154,14 @@ int main(int argc,char *argv[])
             download_count++;
          }
 
-         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);
-            }
-            if (getword(w,sizeof(w),url,'/')<0){
-               printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
-               exit(1);
-            }
-            /*
-            This code rejects any host without a directory. Now it
-            doesn't look necessary so it is commented out.
-            if (!strchr(url,'/')) {
-               if (debugm) printf("URL without directory: %s\n",url);
-               totregsx++;
-               continue;
-            }*/
+         // 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(strcmp(LongUrl,"no") == 0) {
@@ -1203,24 +1196,25 @@ int main(int argc,char *argv[])
                strftime(dia, sizeof(dia), "%d/%m/%Y", t);
             sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
          } else if(ilf==ILF_Common || ilf==ILF_Isa) {
-            strcpy(wtemp,data+1);
-            if (getword_multisep(data,sizeof(data),wtemp,':')<0){
+            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);
                exit(1);
             }
-            if (getword_multisep(hora,sizeof(hora),wtemp,' ')<0){
+            if (getword_multisep(hora,sizeof(hora),&gwarea,' ')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
-            if (getword_multisep(dia,sizeof(dia),data,'/')<0){
+            getword_start(&gwarea,data);
+            if (getword_multisep(dia,sizeof(dia),&gwarea,'/')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
-            if (getword_multisep(mes,sizeof(mes),data,'/')<0){
+            if (getword_multisep(mes,sizeof(mes),&gwarea,'/')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
-            if (getword_multisep(ano,sizeof(ano),data,'/')<0){
+            if (getword_multisep(ano,sizeof(ano),&gwarea,'/')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
@@ -1232,15 +1226,16 @@ int main(int argc,char *argv[])
             builddia(dia,mes,ano,df,wdata);
             idata=atoi(wdata);
          } else if (ilf==ILF_Sarg) {
-            if (getword_multisep(mes,sizeof(mes),data,'/')<0){
+            getword_start(&gwarea,data);
+            if (getword_multisep(mes,sizeof(mes),&gwarea,'/')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
-            if (getword_multisep(dia,sizeof(dia),data,'/')<0){
+            if (getword_multisep(dia,sizeof(dia),&gwarea,'/')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
-            if (getword_multisep(ano,sizeof(ano),data,0)<0){
+            if (getword_multisep(ano,sizeof(ano),&gwarea,0)<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
@@ -1273,18 +1268,18 @@ int main(int argc,char *argv[])
          }
          if(l){
             if(hm[0] != '\0') {
-               strcpy(whm,hora);
-               bzero(hmr,15);
+               bzero(hmr,sizeof(hmr));
                chm++;
+               getword_start(&gwarea,hora);
                while(chm) {
-                  if (getword_multisep(warea,sizeof(warea),whm,':')<0){
+                  if (getword_multisep(warea,sizeof(warea),&gwarea,':')<0){
                      printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
                      exit(1);
                   }
                   strncat(hmr,warea,2);
                   chm--;
                }
-               strncat(hmr,whm,2);
+               strncat(hmr,gwarea.current,2);
 
                if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf))
                   l=1;else l=0;
@@ -1522,16 +1517,21 @@ int main(int argc,char *argv[])
 
    if(fp_log != NULL) {
       fclose(fp_log);
-      strcpy(val1,period);
-      if (getword_multisep(val2,sizeof(val2),val1,'-')<0){
+      getword_start(&gwarea,period);
+      if (getword_multisep(val2,sizeof(val2),&gwarea,'-')<0){
+         printf("SARG: Maybe you have a broken date range definition.\n");
+         exit(1);
+      }
+      if (getword_multisep(val1,sizeof(val1),&gwarea,'\0')<0){
          printf("SARG: Maybe you have a broken date range definition.\n");
          exit(1);
       }
-      if (getword_multisep(val3,sizeof(val3),per_hour,'-')<0){
+      getword_start(&gwarea,per_hour);
+      if (getword_multisep(val3,sizeof(val3),&gwarea,'-')<0){
          printf("SARG: Maybe you have a broken date range definition.\n");
          exit(1);
       }
-      sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,val3,val1,per_hour);
+      sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,val3,val1,gwarea.current);
       rename(arq_log,val4);
       strcpy(arq_log,val4);
 
index 4e5ed610d6385b9d8361e94d8679213916d842a5..1610a7f8062328de26f1c5c6ebb34f7db241c26a 100755 (executable)
@@ -90,60 +90,63 @@ static int getdata(char *rec, FILE *ftmp)
    time_t tt;
    struct tm *t;
    char tbuf[128];
+   char warea[MAXLEN];
+   struct getwordstruct gwarea;
 
-   if (getword(dat,sizeof(dat),rec,' ')<0) {
+   getword_start(&gwarea,rec);
+   if (getword(dat,sizeof(dat),&gwarea,' ')<0) {
       fprintf(stderr,"SARG: The time stamp at column 1 is too long.\n");
       return(-1);
    }
-   if (getword(warea,sizeof(warea),rec,' ')<0) {
+   if (getword(warea,sizeof(warea),&gwarea,' ')<0) {
       fprintf(stderr,"SARG: The connection duration at column 2 is too long.\n");
       return(-1);
    }
-   while(strcmp(warea,"") == 0 && strlen(rec) > 0)
-      if (getword(warea,sizeof(warea),rec,' ')<0) {
+   while(strcmp(warea,"") == 0 && gwarea.current[0] != '\0')
+      if (getword(warea,sizeof(warea),&gwarea,' ')<0) {
          return(-1);
       }
-   if (getword(ip,sizeof(ip),rec,' ')<0) {
+   if (getword(ip,sizeof(ip),&gwarea,' ')<0) {
       fprintf(stderr,"SARG: The IP address at column 3 is too long.\n");
       return(-1);
    }
-   if (getword(warea,sizeof(warea),rec,' ')<0) {
+   if (getword_skip(MAXLEN,&gwarea,' ')<0) {
       fprintf(stderr,"SARG: The status at column 4 is too long.\n");
       return(-1);
    }
-   if (getword(warea,sizeof(warea),rec,' ')<0) {
+   if (getword_skip(MAXLEN,&gwarea,' ')<0) {
       fprintf(stderr,"SARG: The size at column 5 is too long.\n");
       return(-1);
    }
-   if (getword(typ,sizeof(typ),rec,' ')<0) {
+   if (getword(typ,sizeof(typ),&gwarea,' ')<0) {
       fprintf(stderr,"SARG: The action at column 6 is too long.\n");
       return(-1);
    }
    if(strncmp(typ,"CONNECT",7) == 0) {
-      if (getword(url,sizeof(url),rec,' ')<0) {
+      if (getword(url,sizeof(url),&gwarea,' ')<0) {
          return(-1);
       }
-      if (getword(user,sizeof(user),rec,' ')<0) {
+      if (getword(user,sizeof(user),&gwarea,' ')<0) {
          return(-1);
       }
    }else {
-      if (getword(url,sizeof(url),rec,'/')<0) {
+      if (getword_skip(MAXLEN,&gwarea,'/')<0) {
          fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
          return(-1);
       }
-      if (getword(url,sizeof(url),rec,'/')<0) {
+      if (getword_skip(MAXLEN,&gwarea,'/')<0) {
          fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
          return(-1);
       }
-      if (getword(url,sizeof(url),rec,'/')<0) {
+      if (getword(url,sizeof(url),&gwarea,'/')<0) {
          fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
          return(-1);
       }
-      if (getword(user,sizeof(user),rec,' ')<0) {
+      if (getword_skip(MAXLEN,&gwarea,' ')<0) {
          fprintf(stderr,"SARG: The data at column 8 is too long.\n");
          return(-1);
       }
-      if (getword(user,sizeof(user),rec,' ')<0) {
+      if (getword(user,sizeof(user),&gwarea,' ')<0) {
          fprintf(stderr,"SARG: The user at column 9 is too long.\n");
          return(-1);
       }
@@ -167,6 +170,7 @@ static void datashow(const char *tmp)
 {
    FILE *fin;
    char buf[MAXLEN];
+   struct getwordstruct gwarea;
 
    if((fin=fopen(tmp,"r"))==NULL) {
       fprintf(stderr, "SARG: (realtime) open error %s - %s\n",tmp,strerror(errno));
@@ -177,28 +181,29 @@ static void datashow(const char *tmp)
 
    while(fgets(buf, sizeof(buf), fin)) {
       fixendofline(buf);
-      if (getword(dat,sizeof(dat),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(dat,sizeof(dat),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
          exit(1);
       }
-      if (getword(tim,sizeof(tim),buf,'\t')<0) {
+      if (getword(tim,sizeof(tim),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
          exit(1);
       }
-      if (getword(ip,sizeof(ip),buf,'\t')<0) {
+      if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
          exit(1);
       }
-      if (getword(user,sizeof(user),buf,'\t')<0) {
+      if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
          exit(1);
       }
       if(strlen(dat) < 3 || strlen(user) < 1) continue;
-      if (getword(url,sizeof(url),buf,'\t')<0) {
+      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
          exit(1);
       }
-      if (getword(typ,sizeof(typ),buf,'\t')<0) {
+      if (getword(typ,sizeof(typ),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
          exit(1);
       }
index 009d3254bad992fc43bd3d4ffcc4bddf84c0a369..bc61665cd240b7c68ed1f5136842ff1ad1dae367 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -51,6 +51,7 @@ void report_day(const char *user)
                             0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
    long long int tt=0, ttt=0;
    int i;
+   struct getwordstruct gwarea;
 
    sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
    sprintf(wdirname,"%s/%s.day",tmp,user);
@@ -124,7 +125,9 @@ void report_day(const char *user)
      "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(data,sizeof(data),buf,'\t')<0) {
+      fixendofline(buf);
+      getword_start(&gwarea,buf);
+      if (getword(data,sizeof(data),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
          exit(1);
       }
@@ -133,11 +136,10 @@ void report_day(const char *user)
          count++;
       }
 
-      if (getword(hour,sizeof(hour),buf,'\t')<0 || getword(elap,sizeof(elap),buf,'\t')<0) {
+      if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(elap,sizeof(elap),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
          exit(1);
       }
-      elap[strlen(elap)-1]='\0';
 
       if(strcmp(data,odata) != 0) {
          strcpy(oelap,elap);
index 40360320c6aec549ccc52834c476ee4892b6f8be..088e1b4fe99bfbbf7ddd9d0bbda4a09f8d7433da 100644 (file)
--- a/report.c
+++ b/report.c
@@ -45,7 +45,6 @@ void gerarel(void)
    char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldaccelap[10], oldacccode[MAXLEN/2 - 1], user[MAXLEN];
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char accsmart[MAXLEN];
-   char wcrc[MAXLEN/2 -1];
    char crc2[MAXLEN/2 -1];
    long long int nbytes=0;
    long long int nelap=0;
@@ -53,12 +52,13 @@ void gerarel(void)
    long long int rtotal=0;
    long long int incache=0;
    long long int oucache=0;
-   char *s;
+   char *str;
    DIR *dirp;
    struct dirent *direntp;
    const char logext[]=".log";
    int dlen;
    char siteind[MAXLEN];
+   struct getwordstruct gwarea;
 
    ipantes[0]='\0';
    nameantes[0]='\0';
@@ -124,16 +124,17 @@ void gerarel(void)
       bzero(html_old, MAXLEN);
 
       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-         if (getword(accdia,sizeof(accdia),buf,'\t')<0 || getword(acchora,sizeof(acchora),buf,'\t')<0 ||
-             getword(accuser,sizeof(accuser),buf,'\t')<0 || getword(accip,sizeof(accip),buf,'\t')<0 ||
-             getword(accurl,sizeof(accurl),buf,'\t')<0 || getword(accbytes,sizeof(accbytes),buf,'\t')<0 ||
-             getword(acccode,sizeof(acccode),buf,'\t')<0) {
+         getword_start(&gwarea,buf);
+         if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 ||
+             getword(accuser,sizeof(accuser),&gwarea,'\t')<0 || getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
+             getword(accurl,sizeof(accurl),&gwarea,'\t')<0 || getword(accbytes,sizeof(accbytes),&gwarea,'\t')<0 ||
+             getword(acccode,sizeof(acccode),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
             exit(1);
          }
          if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue;
-         if (getword(accelap,sizeof(accelap),buf,'\t')<0 || getword(accsmart,sizeof(accsmart),buf,'\t')<0 ||
-             getword(accsmart,sizeof(accsmart),buf,'"')<0) {
+         if (getword(accelap,sizeof(accelap),&gwarea,'\t')<0 || getword_skip(20000,&gwarea,'\t')<0 ||
+             getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
             exit(1);
          }
@@ -237,8 +238,8 @@ void gerarel(void)
                */
 
                sprintf(ltext110,"%s",text[110]);
-               for(s=ltext110; *s; ++s)
-                  *s=tolower(*s);
+               for(str=ltext110; *str; ++str)
+                  *str=tolower(*str);
 
                fprintf(fp_tt, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
                css(fp_tt);
@@ -274,11 +275,9 @@ void gerarel(void)
             strcpy(html_old, html);
          } else bzero(ltext110, 50);
 
-         strcpy(wcrc,acccode);
-         if (getword(crc2,sizeof(crc2),wcrc,'/')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
-            exit(1);
-         }
+         strcpy(crc2,acccode);
+         str=strchr(crc2,'/');
+         if (str) *str='\0';
 
          if(strstr(crc2,"MISS") != 0)
             oucache+=my_atoll(accbytes);
index 28b26bb325733289e15975d5c5fa9c9e678762bc..6afde003e05d5ffacc2a5615a0aed1a4ab6d8ca2 100644 (file)
@@ -50,6 +50,7 @@ void siteuser(void)
    char *users;
    long long int llbytes=0;
    int cstatus;
+   struct getwordstruct gwarea;
 
    if(strcmp(Privacy,"yes") == 0)
       return;
@@ -128,7 +129,8 @@ void siteuser(void)
    strcpy(users," ");
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(user,sizeof(user),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have an invalid user in the %s file of the siteuser.\n",general2);
          exit(1);
       }
@@ -158,16 +160,16 @@ void siteuser(void)
          ip2name(user,sizeof(user));
       */
 
-      if (getword(nacc,sizeof(nacc),buf,'\t')<0){
+      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0){
          printf("SARG: Maybe you have an invalid number of access in your %s file of the siteuser.\n",general2);
          exit(1);
       }
       if (atoi(nacc) > 0) nsitesusers = 1;
-      if (getword(nbytes,sizeof(nbytes),buf,'\t')<0){
+      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0){
          printf("SARG: Maybe you have an invalid number of bytes in your %s file of the siteuser.\n",general2);
          exit(1);
       }
-      if (getword(url,sizeof(url),buf,'\t')<0) {
+      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have an invalid url in your %s file of the siteuser.\n",general2);
          exit(1);
       }
index e05df46899b565477a11018af35e80179dac03c1..e5a62e80f6fda336eb0ff99f1c04c5b18481cc33 100644 (file)
@@ -51,6 +51,7 @@ void smartfilter_report(void)
    char *str;
    int  fuser=0;
    int cstatus;
+   struct getwordstruct gwarea;
 
    ouser[0]='\0';
 
@@ -115,9 +116,10 @@ void smartfilter_report(void)
    fprintf(fp_ou,"<tr><th bgcolor=%s><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th></tr>\n",HeaderBgColor,FontSize,text[98],HeaderBgColor,FontSize,text[111],HeaderBgColor,FontSize,text[110],HeaderBgColor,FontSize,text[91],HeaderBgColor,FontSize,smartheader);
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(user,sizeof(user),buf,'\t')<0 || getword(data,sizeof(data),buf,'\t')<0 ||
-          getword(hora,sizeof(hora),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
-          getword(url,sizeof(url),buf,'\t')<0 || getword(smartcat,sizeof(smartcat),buf,'\n')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data,sizeof(data),&gwarea,'\t')<0 ||
+          getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+          getword(url,sizeof(url),&gwarea,'\t')<0 || getword(smartcat,sizeof(smartcat),&gwarea,'\n')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",smart_ou);
          exit(1);
       }
index 3216c90e4c370f96ad2831f34cd916c220964ac8..068df07159cff1f18086346ae7f939164cf49f83 100644 (file)
@@ -37,6 +37,7 @@ void splitlog(const char *arq, char *df, int dfrom, int duntil, char *convert)
    time_t tt;
    int idata=0;
    struct tm *t;
+   struct getwordstruct gwarea;
 
    if(arq[0] == '\0')
       arq="/var/log/squid/access.log";
@@ -47,7 +48,8 @@ void splitlog(const char *arq, char *df, int dfrom, int duntil, char *convert)
    }
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(data,sizeof(data),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(data,sizeof(data),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
          exit(1);
       }
@@ -62,7 +64,7 @@ void splitlog(const char *arq, char *df, int dfrom, int duntil, char *convert)
       }
 
       if(strcmp(convert,"onvert") != 0) {
-         printf("%s %s",data,buf);
+         printf("%s %s",data,gwarea.current);
          continue;
       }
 
@@ -71,7 +73,7 @@ void splitlog(const char *arq, char *df, int dfrom, int duntil, char *convert)
        else
          strftime(dia, sizeof(dia), "%m/%d/%Y", t);
 
-      printf("%s %02d:%02d:%02d %s",dia,t->tm_hour,t->tm_min,t->tm_sec,buf);
+      printf("%s %02d:%02d:%02d %s",dia,t->tm_hour,t->tm_min,t->tm_sec,gwarea.current);
    }
 
    fclose(fp_in);
index 8e495b48f8ef71e28ff524e92745e4f39f81cd61..d3f5389e667e316ec9b856bac0ac3669f7d5d177 100644 (file)
@@ -33,7 +33,6 @@ static int nfiles_done = 0;
 static void read_log(const char *wentp, FILE *fp_ou)
 {
    FILE *fp_in = NULL;
-   char bufbsf[255];
    char leks[5], sep[2], res[MAXLEN];
    char mon[10], hour[15];
    char list[MAXLEN];
@@ -41,14 +40,16 @@ static void read_log(const char *wentp, FILE *fp_ou)
    int  idata=0;
    int  i;
    char *str;
+   struct getwordstruct gwarea;
+   struct getwordstruct gwarea1;
 
    if(debug) {
-      strcpy(buf,text[7]);
-      if (getword(urly,sizeof(urly),buf,' ')<0 || getword(href,sizeof(href),buf,' ')<0) {
+      getword_start(&gwarea,text[7]);
+      if (getword(urly,sizeof(urly),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s string.\n",text[7]);
          exit(1);
       }
-      debuga("%s squidGuard %s: %s",urly,buf,wentp);
+      debuga("%s squidGuard %s: %s",urly,gwarea.current,wentp);
    }
 
    /* With squidGuard, you can log groups in only one log file.
@@ -90,20 +91,21 @@ static void read_log(const char *wentp, FILE *fp_ou)
    }
 
    while (fgets(buf,sizeof(buf),fp_in) != NULL) {
-      if(strlen(SquidGuardLogFormat) > 0) {
-         strcpy(bufbsf,SquidGuardLogFormat);
+      getword_start(&gwarea,buf);
+      if(SquidGuardLogFormat[0] != '\0') {
+         getword_start(&gwarea1,SquidGuardLogFormat);
          leks[0]='\0';
-         if (getword(leks,sizeof(leks),bufbsf,'#')<0) {
+         if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
             exit(1);
          }
          while(strcmp(leks,"end") != 0) {
-            if (getword(leks,sizeof(leks),bufbsf,'#')<0 || getword(sep,sizeof(sep),bufbsf,'#')<0) {
+            if (getword(leks,sizeof(leks),&gwarea1,'#')<0 || getword(sep,sizeof(sep),&gwarea1,'#')<0) {
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
                exit(1);
             }
             if(strcmp(leks,"end") != 0) {
-               if (getword(res,sizeof(res),buf,sep[0])<0) {
+               if (getword(res,sizeof(res),&gwarea,sep[0])<0) {
                   printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
                   exit(1);
                }
@@ -128,13 +130,13 @@ static void read_log(const char *wentp, FILE *fp_ou)
             }
          }
       } else {
-         if (getword(year,sizeof(year),buf,'-')<0 || getword(mon,sizeof(mon),buf,'-')<0 ||
-             getword(day,sizeof(day),buf,' ')<0 || getword(hour,sizeof(hour),buf,' ')<0 ||
-             getword(list,sizeof(list),buf,'/')<0 || getword(list,sizeof(list),buf,'/')<0 ||
-             getword(tmp5,sizeof(tmp5),buf,'/')<0 || getword(tmp5,sizeof(tmp5),buf,'/')<0 ||
-             getword(url,sizeof(url),buf,' ')<0 ||
-             getword(ip,sizeof(ip),buf,'/')<0 || getword(user,sizeof(user),buf,' ')<0 ||
-             getword(user,sizeof(user),buf,' ')<0) {
+         if (getword(year,sizeof(year),&gwarea,'-')<0 || getword(mon,sizeof(mon),&gwarea,'-')<0 ||
+             getword(day,sizeof(day),&gwarea,' ')<0 || getword(hour,sizeof(hour),&gwarea,' ')<0 ||
+             getword_skip(MAXLEN,&gwarea,'/')<0 || getword(list,sizeof(list),&gwarea,'/')<0 ||
+             getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0 ||
+             getword(url,sizeof(url),&gwarea,' ')<0 ||
+             getword(ip,sizeof(ip),&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,' ')<0 ||
+             getword(user,sizeof(user),&gwarea,' ')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
             exit(1);
           }
@@ -181,7 +183,7 @@ void squidguard_log(void)
    if(strlen(SquidGuardConf) < 1 && strlen(SquidGuardLogAlternate) < 1)
      return;
 
-   if (strlen(SquidGuardLogAlternate) > 0)
+   if (SquidGuardLogAlternate[0] != '\0')
       SquidGuardConf[0]='\0';
 
    sprintf(guard_in,"%s/squidguard.unsort",tmp);
@@ -238,12 +240,19 @@ void squidguard_log(void)
 
       logdir[0]=0;
       while(fgets(buf,sizeof(buf),fp_guard)!=NULL) {
-         if(strstr(buf,"\n") != 0)
-            buf[strlen(buf)-1]='\0';
+         fixendofline(buf);
          if((str=get_param_value("logdir",buf))!=NULL) {
-            if (getword(logdir,sizeof(logdir),str,' ')<0) {
-               printf("SARG: Maybe you have an invalid logdir line in your %s file.\n",SquidGuardConf);
-               exit(1);
+            /*
+            We want to tolerate spaces inside the directory name but we must also
+            remove the trailing spaces left by the editor after the directory name.
+            This should not be a problem as nobody use a file name with trailing spaces.
+            */
+            for (y=strlen(str)-1 ; y>=0 && (unsigned char)str[y]<=' ' ; y--);
+            if (y>=sizeof(logdir)-1) y=sizeof(logdir)-2;
+            logdir[y+1] = '\0';
+            while (y>=0) {
+               logdir[y] = str[y];
+               y--;
             }
          } else if((str=get_param_value("log",buf))!=NULL) {
             if((str2=get_param_value("anonymous",str))!=NULL)
index dc85365c21900179ec0f8f06948a584262e4639f..86144ad5642c11bcb37987169acc4f85e2a14e0c 100644 (file)
@@ -47,6 +47,7 @@ void squidguard_report(void)
    char *str;
    int  z=0;
    int  count=0;
+   struct getwordstruct gwarea;
 
    ouser[0]='\0';
 
@@ -103,9 +104,10 @@ void squidguard_report(void)
    fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91],text[121]);
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(user,sizeof(user),buf,'\t')<0 || getword(data2,sizeof(data2),buf,'\t')<0 ||
-          getword(hora,sizeof(hora),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
-          getword(url,sizeof(url),buf,'\t')<0 || getword(rule,sizeof(rule),buf,'\n')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data2,sizeof(data2),&gwarea,'\t')<0 ||
+          getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+          getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",squidguard_in);
          exit(1);
       }
index be51db05e72ecb6915dc445ee3dd63d388289f60..f9c6739b682161ee0eeb90d1e6a30ba9dd0dbe42 100644 (file)
@@ -56,6 +56,7 @@ void topsites(void)
    long long int twork1=0, twork2=0, twork3=0;
    int regs=0;
    int cstatus;
+   struct getwordstruct gwarea;
 
    if(strcmp(Privacy,"yes") == 0)
       return;
@@ -102,50 +103,51 @@ void topsites(void)
    }
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(url,sizeof(url),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have an invalid user in your %s file of the topsites.\n",general2);
          exit(1);
       }
       if(strcmp(url,"TOTAL") == 0) {
-         if (getword(ttnacc,sizeof(ttnacc),buf,'\t')<0) {
+         if (getword(ttnacc,sizeof(ttnacc),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have an invalid total number of access in your %s file of the topsites.\n",general2);
             exit(1);
          }
-         if (getword(ttnbytes,sizeof(ttnbytes),buf,'\t')<0) {
+         if (getword(ttnbytes,sizeof(ttnbytes),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have an invalid total number of bytes in your %s file of the topsites.\n",general2);
             exit(1);
          }
-         if (getword(ttntime,sizeof(ttntime),buf,'\t')<0) {
+         if (getword(ttntime,sizeof(ttntime),&gwarea,'\t')<0) {
             printf("SARG: Maybe you have an invalid total time in your %s file of the topsites.\n",general2);
             exit(1);
          }
          continue;
       }
-      if (getword(nacc,sizeof(nacc),buf,'\t')<0) {
+      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have an invalid number of access in your %s file of the topsites.\n",general2);
          exit(1);
       }
-      if (getword(nbytes,sizeof(nbytes),buf,'\t')<0) {
+      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have an invalid number of bytes in your %s file of the topsites.\n",general2);
          exit(1);
       }
-      if (getword(url,sizeof(url),buf,'\t')<0) {
+      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have an invalid url in your %s file of the topsites.\n",general2);
          exit(1);
       }
-      if (getword(ntemp,sizeof(ntemp),buf,'\t')<0) {
+      if (getword(ntemp,sizeof(ntemp),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in column 5 in your %s file of the topsites.\n",general2);
          exit(1);
       }
-      if (getword(ntemp,sizeof(ntemp),buf,'\t')<0) {
+      if (getword(ntemp,sizeof(ntemp),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in column 6 in your %s file of the topsites.\n",general2);
          exit(1);
       }
-      if (getword(ntemp,sizeof(ntemp),buf,'\t')<0) {
+      if (getword(ntemp,sizeof(ntemp),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in column 7 in your %s file of the topsites.\n",general2);
          exit(1);
       }
-      if (getword(ntime,sizeof(ntime),buf,'\t')<0) {
+      if (getword(ntime,sizeof(ntime),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in column 8 in your %s file of the topsites.\n",general2);
          exit(1);
       }
@@ -246,13 +248,14 @@ void topsites(void)
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       if(regs>atoi(TopSitesNum))
          break;
-      if (getword(nacc,sizeof(nacc),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
          exit(1);
       }
       if (atoi(nacc) == 0) continue;
-      if (getword(nbytes,sizeof(nbytes),buf,'\t')<0 ||
-          getword(ntime,sizeof(ntime),buf,'\t')<0 || getword(url,sizeof(url),buf,'\t')<0) {
+      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0 ||
+          getword(ntime,sizeof(ntime),&gwarea,'\t')<0 || getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
          exit(1);
       }
@@ -265,7 +268,7 @@ void topsites(void)
       strcpy(wwork2,fixnum(twork2,1));
       strcpy(wwork3,fixtime(twork3));
 
-      if(strlen(BlockIt) > 0)
+      if(BlockIt[0] != '\0')
          sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,url);
       else BlockImage[0]='\0';
 
index 5e505632f33d213da5445e447080ba590f3f235d..be3b7179c23996610260667050c8c4e0f467d424 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -60,6 +60,7 @@ void topuser(void)
    char href1end[5];
    char href2end[5];
    char href3end[5];
+   struct getwordstruct gwarea;
 
    ipantes[0]='\0';
    nameantes[0]='\0';
@@ -90,46 +91,47 @@ void topuser(void)
    totuser=0;
 
    while(fgets(warea,sizeof(warea),fp_in)) {
-      if (getword(user,sizeof(user),warea,'\t')<0) {
+      getword_start(&gwarea,warea);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
          exit(1);
       }
       if(strcmp(user,"TOTAL") == 0) {
          continue;
       }
-      if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(url,sizeof(url),warea,'\t')<0) {
+      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(ip,sizeof(ip),warea,'\t')<0) {
+      if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken user's IP in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(time,sizeof(time),warea,'\t')<0) {
+      if (getword(time,sizeof(time),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken time in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(date,sizeof(date),warea,'\t')<0) {
+      if (getword(date,sizeof(date),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(elap,sizeof(elap),warea,'\t')<0) {
+      if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken download duration in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(incac,sizeof(incac),warea,'\t')<0) {
+      if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken in cache download in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(oucac,sizeof(oucac),warea,'\t')<0) {
+      if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken not in cache download in your %s file.\n",wger);
          exit(1);
       }
@@ -366,27 +368,28 @@ void topuser(void)
    ntopuser = 0;
 
    while(fgets(warea,sizeof(warea),fp_top1)) {
-      if (getword(user,sizeof(user),warea,'\t')<0) {
+      getword_start(&gwarea,warea);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
          exit(1);
       }
-      if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1);
          exit(1);
       }
-      if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1);
          exit(1);
       }
-      if (getword(elap,sizeof(elap),warea,'\t')<0) {
+      if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken elpased time in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(incac,sizeof(incac),warea,'\t')<0) {
+      if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(oucac,sizeof(oucac),warea,'\t')<0) {
+      if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",wger);
          exit(1);
       }
index fadbea2a2bf8ebe6a44dcdbaad8daddaae446c04..ce46c53c44bf361f735e727b070dbe26b0e5ef37 100644 (file)
--- a/totday.c
+++ b/totday.c
@@ -48,6 +48,7 @@ void day_totalize(const char *tmp, const char *user, int indexonly)
    long long int telap=0;
    long long int tused=0;
    int cstatus;
+   struct getwordstruct gwarea;
 
    if(indexonly) return;
    if(strstr(ReportType,"users_sites") == 0) return;
@@ -77,12 +78,11 @@ void day_totalize(const char *tmp, const char *user, int indexonly)
    }
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if(strstr(buf,"\n") != 0)
-         buf[strlen(buf)-1]='\0';
-
-      if (getword(data,sizeof(data),buf,'\t')<0 || getword(hora,sizeof(hora),buf,':')<0 ||
-          getword(min,sizeof(min),buf,':')<0 || getword(elap,sizeof(elap),buf,'\t')<0 ||
-          getword(elap,sizeof(elap),buf,0)<0) {
+      fixendofline(buf);
+      getword_start(&gwarea,buf);
+      if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,':')<0 ||
+          getword(min,sizeof(min),&gwarea,':')<0 || getword(elap,sizeof(elap),&gwarea,'\t')<0 ||
+          getword(elap,sizeof(elap),&gwarea,0)<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sortout);
          exit(1);
       }
index 33da84eea2c7566084fb3584c34ce984beaa7989..132407283a2689b33cb3be458f47eeac3693ac15 100644 (file)
--- a/totger.c
+++ b/totger.c
@@ -37,6 +37,7 @@ int totalger(const char *dirname, int debug, const char *outdir)
    char ip[MAXLEN], hora[9], data[15], elap[16];
    char incac[30], oucac[30];
    char warea[MAXLEN];
+   struct getwordstruct gwarea;
 
    strcpy(wger,dirname);
    strcat(wger,"/sarg-general");
@@ -49,43 +50,44 @@ int totalger(const char *dirname, int debug, const char *outdir)
    while(fgets(warea,sizeof(warea),fp_in))
    {
       //printf("%s\n",warea);
-      if (getword(user,sizeof(user),warea,'\t')<0) {
+      getword_start(&gwarea,warea);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(url,sizeof(url),warea,'\t')<0) {
+      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(ip,sizeof(ip),warea,'\t')<0) {
+      if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken source IP address in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(hora,sizeof(hora),warea,'\t')<0) {
+      if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken time in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(data,sizeof(data),warea,'\t')<0) {
+      if (getword(data,sizeof(data),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(elap,sizeof(elap),warea,'\t')<0) {
+      if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(incac,sizeof(incac),warea,'\t')<0) {
+      if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken in cache column in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(oucac,sizeof(oucac),warea,0)<0) {
+      if (getword(oucac,sizeof(oucac),&gwarea,0)<0) {
          printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",wger);
          exit(1);
       }
index c4d1ef8447d2ef209376b17a72ca053283ea0c6a..532b41d9c503200a4b1e8292f9c73ac324f43176 100644 (file)
@@ -41,6 +41,7 @@ void useragent(void)
    unsigned long totregsl=0;
    int cstatus;
    char ftime[128];
+   struct getwordstruct gwarea;
 
    ip[0]='\0';
    data[0]='\0';
@@ -70,14 +71,15 @@ void useragent(void)
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       totregsl++;
-      if (getword(ip,sizeof(ip),buf,' ')<0 || getword(data,sizeof(data),buf,'[')<0 ||
-          getword(data,sizeof(data),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(ip,sizeof(ip),&gwarea,' ')<0 || getword_skip(MAXLEN,&gwarea,'[')<0 ||
+          getword(data,sizeof(data),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserAgentLog);
          exit(1);
       }
       if(totregsl == 1)
          strcpy(idate,data);
-      if (getword(agent,sizeof(agent),buf,'"')<0 || getword(agent,sizeof(agent),buf,'"')<0) {
+      if (getword_skip(MAXLEN,&gwarea,'"')<0 || getword(agent,sizeof(agent),&gwarea,'"')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserAgentLog);
          exit(1);
       }
@@ -86,8 +88,8 @@ void useragent(void)
       if(strstr(warea,"SCRIPT") != 0 || strstr(warea,"ONLOAD") != 0)
          baddata();
 
-      if(strlen(buf)) {
-         if (getword(user,sizeof(user),buf,' ')<0 || getword(user,sizeof(user),buf,'\n')<0) {
+      if(strlen(gwarea.current)) {
+         if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,'\n')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserAgentLog);
             exit(1);
          }
@@ -167,7 +169,8 @@ void useragent(void)
    fprintf(fp_ou,"<tr><th align=\"left\" bgcolor=\"%s\"><font color=\"%s\">%s</font></th><th bgcolor=\"%s\" align=\"left\"><font color=\"%s\">%s</font></th></tr>\n",HeaderBgColor,HeaderColor,text[98],HeaderBgColor,HeaderColor,text[106]);
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(ip,sizeof(ip),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp2);
          exit(1);
       }
@@ -180,8 +183,8 @@ void useragent(void)
          } else strcpy(ip,namebefore);
       }
 
-      if (getword(agent,sizeof(agent),buf,'\t')<0 ||
-          getword(user,sizeof(user),buf,'\t')<0) {
+      if (getword(agent,sizeof(agent),&gwarea,'\t')<0 ||
+          getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp2);
          exit(1);
       }
@@ -226,8 +229,9 @@ void useragent(void)
    cont=0;
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(ip,sizeof(ip),buf,'\t')<0 ||
-          getword(agent,sizeof(agent),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+          getword(agent,sizeof(agent),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
          exit(1);
       }
@@ -283,7 +287,8 @@ void useragent(void)
    perc=0.;
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       fixendofline(buf);
-      if (getword(tagent,sizeof(tagent),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(tagent,sizeof(tagent),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
          exit(1);
       }
@@ -293,7 +298,7 @@ void useragent(void)
          perc=perc / agentot2;
       }
 
-      fprintf(fp_ht,"<tr><td align=\"left\" bgcolor=\"%s\">%s</td><td align=\"right\" bgcolor=\"%s\">%d</td><td align=\"right\" bgcolor=\"%s\">%3.2f</td></tr>\n",TxBgColor,buf,TxBgColor,nagent,TxBgColor,perc);
+      fprintf(fp_ht,"<tr><td align=\"left\" bgcolor=\"%s\">%s</td><td align=\"right\" bgcolor=\"%s\">%d</td><td align=\"right\" bgcolor=\"%s\">%3.2f</td></tr>\n",TxBgColor,gwarea.current,TxBgColor,nagent,TxBgColor,perc);
    }
 
    fputs("</table></html>\n",fp_ht);
diff --git a/util.c b/util.c
index ad7601ccbd98ea56c2b00b8a95658fdc28f5920c..edd2d922d41a7fae56b22ac3afca36b2f2334ff0 100644 (file)
--- a/util.c
+++ b/util.c
@@ -56,79 +56,81 @@ static char *excludecode=NULL;
     }
 }*/
 
-int getword(char *word, int limit, char *line, int stop)
+void getword_start(struct getwordstruct *gwarea, const char *line)
 {
-  int x = 0,y;
+   gwarea->beginning=line;
+   gwarea->current=line;
+}
 
-  /*if(strlen(line) < 3) {
-     word[0]='\0';
-     return(0);
-   }*/
+void getword_restart(struct getwordstruct *gwarea)
+{
+   gwarea->current=gwarea->beginning;
+}
+
+int getword(char *word, int limit, struct getwordstruct *gwarea, int stop)
+{
+  int x;
 
-  for(x=0;((line[x]) && (line[x] != stop ));x++) {
+  for(x=0;((gwarea->current[x]) && (gwarea->current[x] != stop ));x++) {
      if(x>=limit) {
         printf("SARG: getword loop detected after %d bytes.\n",x);
-        printf("SARG: Record=\"%s\"\n",line);
+        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");
         word[(limit>0) ? limit-1 : 0]='\0';
         return(-1);
      }
-     word[x] = line[x];
+     word[x] = gwarea->current[x];
   }
 
   word[x] = '\0';
-  if (line[x]) ++x;
-  y=0;
-
-  while((line[y++] = line[x++]));
+  if (gwarea->current[x]) ++x;
+  gwarea->current+=x;
   return(0);
 }
 
-int getword_multisep(char *word, int limit, char *line, int stop)
+int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop)
 {
-  int x = 0,y;
+  int x;
 
-  for(x=0;((line[x]) && (line[x] != stop ));x++) {
+  for(x=0;((gwarea->current[x]) && (gwarea->current[x] != stop ));x++) {
      if(x>=limit) {
         printf("SARG: getword_multisep loop detected.\n");
-        printf("SARG: Record=\"%s\"\n",line);
-        printf("SARG: searching for \'x%x\'\n",stop);
+        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");
         if (limit>0) word[limit-1]='\0';
         //exit(1);
         return(-1);
      }
-     word[x] = line[x];
+     word[x] = gwarea->current[x];
   }
 
   word[x] = '\0';
-  while (line[x] && line[x]==stop) ++x;
-  y=0;
-
-  while((line[y++] = line[x++]));
+  while (gwarea->current[x] && gwarea->current[x]==stop) ++x;
+  gwarea->current+=x;
   return(0);
 }
 
-int getword_skip(int limit, char *line, int stop)
+int getword_skip(int limit, struct getwordstruct *gwarea, int stop)
 {
-   int x,y;
+   int x;
 
-   for(x=0;((line[x]) && (line[x] != stop ));x++) {
+   for(x=0;(gwarea->current[x] && (gwarea->current[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: 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);
       }
    }
 
-   if (line[x]) ++x;
-   y=0;
-
-   while((line[y++] = line[x++]));
+   if (gwarea->current[x]) ++x;
+   gwarea->current+=x;
    return(0);
 }
 
@@ -206,6 +208,7 @@ void my_mkdir(const char *name)
    char w0[255];
    char w1[255];
    char w2[255];
+   struct getwordstruct gwarea;
 
    if(!is_absolute(name)) {
       fprintf(stderr,"SARG: Invalid path (%s). Please, use absolute paths only.\n",name);
@@ -215,12 +218,13 @@ void my_mkdir(const char *name)
 
    strcpy(w0,name);
    strcpy(w2,"/");
-   if (getword_multisep(w1,sizeof(w1),w0,'/')<0) {
+   getword_start(&gwarea,w0);
+   if (getword_multisep(w1,sizeof(w1),&gwarea,'/')<0) {
       printf("SARG: Maybe you have a broken record or garbage in the directory name %s.\n",name);
       exit(1);
    }
-   while(strchr(w0,'/')) {
-      if (getword_multisep(w1,sizeof(w1),w0,'/')<0) {
+   while(strchr(gwarea.current,'/')) {
+      if (getword_multisep(w1,sizeof(w1),&gwarea,'/')<0) {
          printf("SARG: Maybe you have a broken record or garbage in the directory name %s.\n",name);
          exit(1);
       }
@@ -234,7 +238,7 @@ void my_mkdir(const char *name)
       }
       strcat(w2,"/");
    }
-   strcat(w2,w0);
+   strcat(w2,gwarea.current);
    if(access(w2, R_OK) != 0) {
       if(mkdir(w2,0755)) {
          fprintf(stderr,"SARG: mkdir %s %s\n",w2,strerror(errno));
@@ -342,15 +346,17 @@ void name_month(char *month,int month_len)
    int  x, z=atoi(month)-1;
    char m[255];
    char w[20];
+   struct getwordstruct gwarea;
 
    strcpy(m,text[133]);
+   getword_start(&gwarea,m);
 
    for(x=0; x<z; x++)
-      if (getword_multisep(w,sizeof(w),m,',')<0) {
+      if (getword_multisep(w,sizeof(w),&gwarea,',')<0) {
          printf("SARG: Maybe you have a broken record or garbage in the names of the months.\n");
          exit(1);
       }
-   if (getword_multisep(month,month_len,m,',')<0) {
+   if (getword_multisep(month,month_len,&gwarea,',')<0) {
       printf("SARG: Maybe you have a broken record or garbage in the name of the months.\n");
       exit(1);
    }
@@ -688,10 +694,12 @@ void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser,
 {
 
    FILE *fp_in;
+   char buf[MAXLEN];
    char wdir[MAXLEN];
    long long int med=0;
    long long int wtuser=0;
    long long int twork;
+   struct getwordstruct gwarea;
 
    sprintf(wdir,"%s%s/sarg-general",dirname,name);
    if ((fp_in = fopen(wdir, "r")) == 0) {
@@ -703,17 +711,18 @@ void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser,
    }
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(warea,sizeof(warea),buf,'\t')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(warea,sizeof(warea),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir);
          exit(1);
       }
       if(strcmp(warea,"TOTAL") != 0)
          continue;
-      if (getword(warea,sizeof(warea),buf,'\t')<0) {
+      if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir);
          exit(1);
       }
-      if (getword(warea,sizeof(warea),buf,'\t')<0) {
+      if (getword(warea,sizeof(warea),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir);
          exit(1);
       }
@@ -964,23 +973,22 @@ void vrfydir(const char *dir, const char *per1, const char *addr, const char *si
 
 void strip_latin(char *line)
 {
-   char buf[255];
-   char warea[255];
-
-   while(strstr(line,"&") != 0){
-      if (getword_multisep(warea,sizeof(warea),line,'&')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in a line to strip from HTML entities.\n");
-         exit(1);
-      }
-      strncat(warea,line,1);
-      if (getword_multisep(buf,sizeof(buf),line,';')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in a line to strip from HTML entities.\n");
-         exit(1);
+   int i,j;
+   int skip;
+
+   j=0;
+   skip=0;
+   for (i=0;line[i];i++){
+      if (skip){
+         if (line[i]==';') skip=0;
+      } else {
+         if (line[i]=='&')
+            skip=1;
+         else
+            line[j++]=line[i];
       }
-      strcat(warea,line);
-      strcpy(line,warea);
    }
-
+   line[j]='\0';
    return;
 
 }
@@ -1040,30 +1048,34 @@ char *fixtime(long int elap)
 void date_from(char *date, char *dfrom, char *duntil)
 {
 
-   char diaf[10];
-   char mesf[10];
-   char anof[10];
-   char diau[10];
-   char mesu[10];
-   char anou[10];
-   static char wdate[50];
+   int diaf;
+   int mesf;
+   int anof;
+   int diau;
+   int mesu;
+   int anou;
+   char wdate[50];
 
 
-   strcpy(wdate,date);
+   strncpy(wdate,date,sizeof(wdate)-1);
+   wdate[sizeof(wdate)-1]='\0';
    if(strchr(wdate,'-') == NULL) {
+      if (strlen(wdate)*2+1>=sizeof(wdate)) {
+         fprintf(stderr,"SARG: Invalid date range passed as argument.\n");
+         exit(1);
+      }
       strcat(wdate,"-");
       strcat(wdate,date);
       strcpy(date,wdate);
    }
 
-   if (getword(diaf,sizeof(diaf),wdate,'/')<0 || getword(mesf,sizeof(mesf),wdate,'/')<0 || getword(anof,sizeof(anof),wdate,'-')<0 ||
-       getword(diau,sizeof(diau),wdate,'/')<0 || getword(mesu,sizeof(mesu),wdate,'/')<0 || getword(anou,sizeof(anou),wdate,0)<0) {
-      printf("SARG: Maybe you have a broken record or garbage in a date.\n");
+   if (sscanf(wdate,"%d/%d/%d-%d/%d/%d",&diaf,&mesf,&anof,&diau,&mesu,&anou)!=6) {
+      fprintf(stderr,"SARG: The date range passed as argument is not formated as dd/mm/yyyy-dd/mm/yyyy.\n");
       exit(1);
    }
 
-   sprintf(dfrom,"%s%s%s",anof,mesf,diaf);
-   sprintf(duntil,"%s%s%s",anou,mesu,diau);
+   sprintf(dfrom,"%04d%02d%02d",anof,mesf,diaf);
+   sprintf(duntil,"%04d%02d%02d",anou,mesu,diau);
    return;
 }
 
@@ -1340,8 +1352,9 @@ int getnumlist( char *buf, numlist *list, const int len, const int maxvalue )
 char *get_size(const char *path, const char *file)
 {
    FILE *fp;
-   char response[255];
+   static char response[255];
    char cmd[255];
+   char *ptr;
 
    if (snprintf(cmd,sizeof(cmd),"du -skh %s%s",path,file)>=sizeof(cmd)) {
       printf("SARG: Cannot get disk space because the path %s%s is too long.\n",path,file);
@@ -1352,13 +1365,15 @@ char *get_size(const char *path, const char *file)
       fprintf(stderr,"SARG: Cannot get disk size with command %s",cmd);
       exit(1);
    }
-   if (getword_multisep(val5,sizeof(val5),response,'\t')<0) {
-      printf("SARG: Maybe the command %s failed.\n",cmd);
+   ptr=strchr(response,'\t');
+   if (ptr==NULL) {
+      fprintf(stderr,"SARG: The command %s failed.\n",cmd);
       exit(1);
    }
    pclose(fp);
+   *ptr='\0';
 
-   return (val5);
+   return (response);
 }
 
 void show_info(FILE *fp_ou)
@@ -1512,54 +1527,54 @@ void read_usertab(const char *UserTabFile)
    FILE *fp_usr;
    long int nreg;
    char buf[MAXLEN];
-   char bufy[MAXLEN];
    int z2;
    int z1;
-   int i;
 
-   if (UserTabFile[0] != '\0') {
-      if(debug) {
-         debuga("%s: %s",text[86],UserTabFile);
-      }
-      if((fp_usr=fopen(UserTabFile,"r"))==NULL) {
-         fprintf(stderr, "SARG: (log) %s: %s - %s\n",text[45],UserTabFile,strerror(errno));
-         exit(1);
-      }
-      fseek(fp_usr, 0, SEEK_END);
-      nreg = ftell(fp_usr);
-      if (nreg<0) {
-         printf("SARG: Cannot get the size of file %s",UserTabFile);
-         exit(1);
-      }
-      nreg += 100;
-      fseek(fp_usr, 0, SEEK_SET);
-      if((userfile=(char *) malloc(nreg))==NULL){
-         fprintf(stderr, "SARG ERROR: %s",text[87]);
-         exit(1);
-      }
-      strcpy(userfile,"\t");
-      z2=1;
-      while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
-         if (buf[0]=='#') continue;
-         for (i=strlen(buf)-1 ; i>=0 && (unsigned char)buf[i]<=' ' ; i--) buf[i]=0;
-         if (getword_multisep(bufy,sizeof(bufy),buf,' ')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserTabFile);
+   if (UserTabFile[0] == '\0') return;
+   if(debug)
+      debuga("%s: %s",text[86],UserTabFile);
+   if((fp_usr=fopen(UserTabFile,"r"))==NULL) {
+      fprintf(stderr, "SARG: (log) %s: %s - %s\n",text[45],UserTabFile,strerror(errno));
+      exit(1);
+   }
+   fseek(fp_usr, 0, SEEK_END);
+   nreg = ftell(fp_usr);
+   if (nreg<0) {
+      fprintf(stderr,"SARG: Cannot get the size of file %s",UserTabFile);
+      exit(1);
+   }
+   nreg += 100;
+   fseek(fp_usr, 0, SEEK_SET);
+   if((userfile=(char *) malloc(nreg))==NULL){
+      fprintf(stderr, "SARG ERROR: %s",text[87]);
+      exit(1);
+   }
+   userfile[0]='\t';
+   z2=1;
+   while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
+      if (buf[0]=='#') continue;
+      fixendofline(buf);
+      z1=0;
+      while(buf[z1] && (unsigned char)buf[z1]>' ') {
+         if (z2+3>=nreg) { //need at least 3 additional bytes for the minimum string "\n\t\0"
+            fprintf(stderr,"SARG: The list of the users is too long in your %s file.\n",UserTabFile);
             exit(1);
          }
-         if (z2+strlen(bufy)+strlen(buf)+3>=nreg) {
-            printf("SARG: The list of the users is too long in your %s file.\n",UserTabFile);
+         userfile[z2++]=buf[z1++];
+      }
+      while(buf[z1] && (unsigned char)buf[z1]<=' ') z1++;
+      userfile[z2++]='\n';
+      while(buf[z1] && (unsigned char)buf[z1]>' ') {
+         if (z2+2>=nreg) { //need at least 2 additional bytes for "\t\0"
+            fprintf(stderr,"SARG: The list of the users is too long in your %s file.\n",UserTabFile);
             exit(1);
          }
-         for(z1=0; bufy[z1]; z1++)
-            userfile[z2++]=bufy[z1];
-         userfile[z2++]='\n';
-         for(z1=0; buf[z1]; z1++)
-            userfile[z2++]=buf[z1];
-         userfile[z2++]='\t';
+         userfile[z2++]=buf[z1++];
       }
-      userfile[z2]=0;
-      fclose(fp_usr);
+      userfile[z2++]='\t';
    }
+   userfile[z2]='\0';
+   fclose(fp_usr);
 }
 
 void get_usertab_name(const char *user,char *name,int namelen)