]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Remove any limit on the maximum URL length (bugs remain)
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 14 Feb 2010 14:38:42 +0000 (14:38 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 14 Feb 2010 14:38:42 +0000 (14:38 +0000)
22 files changed:
authfail.c
dansguardian_log.c
dansguardian_report.c
datafile.c
denied.c
documentation/util.txt
download.c
html.c
include/conf.h
include/defs.h
index.c
log.c
realtime.c
report.c
siteuser.c
squidguard_log.c
squidguard_report.c
topsites.c
topuser.c
totday.c
totger.c
util.c

index 856723fe5c3b3d1898224469b4fce0ecf3b92a52..58e7daed92efa6b254e544f3e52cc5a784f87013 100644 (file)
@@ -33,7 +33,7 @@ void authfail_report(void)
    FILE *fp_in = NULL, *fp_ou = NULL;
 
    char *buf;
-   char url[MAX_URL_LEN];
+   char *url;
    char authfail_in[MAXLEN];
    char per[MAXLEN];
    char report[MAXLEN];
@@ -55,6 +55,7 @@ void authfail_report(void)
    if(DataFile[0] != '\0') return;
 
    ouser[0]='\0';
+   ouser2[0]='\0';
 
    sprintf(tmp4,"%s/sarg/authfail.log.unsort",TempDir);
 
@@ -115,9 +116,12 @@ void authfail_report(void)
    while((buf=longline_read(fp_in,&line))!=NULL) {
       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);
+          getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken record or garbage in your %s file"),authfail_in);
+         exit(1);
+      }
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),authfail_in);
          exit(1);
       }
 
index c16e9559e2590f60af280acec4eff839ee3b74b9..bcb708f3c4bae4ed2f7a266456885a234519572e 100644 (file)
@@ -39,7 +39,7 @@ void dansguardian_log(void)
    char user[MAXLEN], code1[255], code2[255];
    char ip[30];
    char wdata[127];
-   char url[MAX_URL_LEN];
+   char *url;
    int  idata=0;
    int cstatus;
    struct getwordstruct gwarea;
@@ -109,12 +109,13 @@ void dansguardian_log(void)
    }
 
    if(debug) {
+      char short_url[1024];
       getword_start(&gwarea,text[7]);
-      if (getword(url,sizeof(url),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
+      if (getword_limit(short_url,sizeof(short_url),&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",url,gwarea.current,loglocation);
+      debuga("%s DansGuardian %s: %s",short_url,gwarea.current,loglocation);
    }
 
    if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
@@ -129,10 +130,17 @@ void dansguardian_log(void)
       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_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0) {
+         debuga(_("Maybe you have a broken record or garbage in your %s file"),loglocation);
+         exit(1);
+      }
+      if (getword_ptr(buf,&url,&gwarea,' ')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),loglocation);
+         exit(1);
+      }
+      if (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);
+         debuga(_("Maybe you have a broken record or garbage in your %s file"),loglocation);
          exit(1);
       }
       sprintf(wdata,"%s%02d%s",year,atoi(mon),day);
index bf0ff88e50a9ca3526b2ec3aa29a741bdc868432..745c747f9ecfed0e131672831c3bc3ca2e704c57 100644 (file)
@@ -32,7 +32,7 @@ void dansguardian_report(void)
 
    FILE *fp_in = NULL, *fp_ou = NULL;
 
-   char url[MAXLEN];
+   char *url;
    char dansguardian_in[MAXLEN];
    char per[MAXLEN];
    char report[MAXLEN];
@@ -94,9 +94,16 @@ void dansguardian_report(void)
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       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);
+          getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken record or garbage in your %s file"),dansguardian_in);
+         exit(1);
+      }
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),dansguardian_in);
+         exit(1);
+      }
+      if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
+         debuga(_("Maybe you have a broken rule in your %s file"),dansguardian_in);
          exit(1);
       }
 
@@ -158,7 +165,11 @@ void dansguardian_report(void)
             continue;
       }
 
-      fprintf(fp_ou,"<tr><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s-%s</td><td class=\"data2\" nospaw><a href=\"http://%s\">%s</a></td><td class=\"data2\" nospaw>%s</td></tr>\n",name,ip,date,hour,url,url,rule);
+      fprintf(fp_ou,"<tr><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s-%s</td><td class=\"data2\" nospaw><a href=\"http://",name,ip,date,hour);
+      output_html_url(fp_ou,url);
+      fputs("\">",fp_ou);
+      output_html_string(fp_ou,url,100);
+      fprintf(fp_ou,"</a></td><td class=\"data2\" nospaw>%s</td></tr>\n",rule);
    }
    fclose(fp_in);
 
index 15b7e988a97eaede59a425ca7f1c74589c022da2..e866ee0675f8dcff257222bc0054e371334b524c 100644 (file)
@@ -155,18 +155,13 @@ void saverecs(char *dirname, char *user, long long int nacc, char *url, long lon
 {
    FILE *fp_ou;
    char reg[MAXLEN];
+   char val[20];
 
    if((fp_ou=MY_FOPEN(DataFile,"a"))==NULL){
       fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],DataFile);
       exit(1);
    }
 
-   my_lltoa(nacc,val1,0);
-   my_lltoa(nbytes,val2,0);
-   my_lltoa(nelap,val3,0);
-   my_lltoa(incache,val4,0);
-   my_lltoa(oucache,val5,0);
-
    if((DataFileFields & DATA_FIELD_USER) != 0) {
       strcpy(reg,user);
       strncat(reg,DataFileDelimiter,1);
@@ -186,23 +181,28 @@ void saverecs(char *dirname, char *user, long long int nacc, char *url, long lon
       strncat(reg,DataFileDelimiter,1);
    }
    if((DataFileFields & DATA_FIELD_CONNECT) != 0) {
-      strncat(reg,val1,strlen(val1));
+      my_lltoa(nacc,val,sizeof(val),0);
+      strcat(reg,val);
       strncat(reg,DataFileDelimiter,1);
    }
    if((DataFileFields & DATA_FIELD_BYTES) != 0) {
-      strncat(reg,val2,strlen(val2));
+      my_lltoa(nbytes,val,sizeof(val),0);
+      strcat(reg,val);
       strncat(reg,DataFileDelimiter,1);
    }
    if((DataFileFields & DATA_FIELD_IN_CACHE) != 0) {
-      strncat(reg,val4,strlen(val4));
+      my_lltoa(incache,val,sizeof(val),0);
+      strcat(reg,val);
       strncat(reg,DataFileDelimiter,1);
    }
    if((DataFileFields & DATA_FIELD_OUT_CACHE) != 0) {
-      strncat(reg,val5,strlen(val5));
+      my_lltoa(oucache,val,sizeof(val),0);
+      strcat(reg,val);
       strncat(reg,DataFileDelimiter,1);
    }
    if((DataFileFields & DATA_FIELD_ELAPSED) != 0) {
-      strncat(reg,val3,strlen(val3));
+      my_lltoa(nelap,val,sizeof(val),0);
+      strcat(reg,val);
       strncat(reg,DataFileDelimiter,1);
    }
 
index 9315b86fc743e789dca468c6a3cb598034f50b32..5239001abc9b47d3458b84053f765d479de4af7e 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -33,7 +33,7 @@ void gen_denied_report(void)
    FILE *fp_in = NULL, *fp_ou = NULL;
 
    char *buf;
-   char url[MAX_URL_LEN];
+   char *url;
    char denied_in[MAXLEN];
    char per[MAXLEN];
    char report[MAXLEN];
@@ -101,11 +101,14 @@ void gen_denied_report(void)
    while((buf=longline_read(fp_in,&line))!=NULL) {
       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) {
+          getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",denied_in);
          exit(1);
       }
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),denied_in);
+         exit(1);
+      }
 
       if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
          if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
index d63bad00c98b9d4758598c94587ded01b41eae25..b5b9656d91fd302b48eb3d0a93e89d6fb9a2bb59 100644 (file)
@@ -20,7 +20,7 @@ The list of the months.
 
 
 
-/*! \fn void getword_start(struct getwordstruct *gwarea, const char *line)
+/*! \fn void getword_start(struct getwordstruct *gwarea, char *line)
 Initialize the getword buffer with the given text line.
 
 \param gwarea The getword buffer to initialize.
@@ -63,6 +63,22 @@ the function displays an error message and returns an error code.
 
 
 
+/*! \fn int getword_limit(char *word, int limit, struct getwordstruct *gwarea, int stop)
+Extract one word with a maximum size and skip any supernumerary bytes until the stop bytes is
+found.
+
+\param word The buffer to store the extracted word.
+\param limit The size of the buffer.
+\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.
+*/
+
+
+
+
+
 /*! \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
@@ -108,13 +124,29 @@ Extract one number from the text line.
 \param gwarea The getword buffer initialized by getword_start().
 \param stop The character indicating the end of the word.
 
-\retval 0 The number is skipped.
+\retval 0 The number is extracted.
 \retval -1 The stop character was not found after the number.
 */
 
 
 
 
+/*! \fn int getword_ptr(char *orig_line,char **word, struct getwordstruct *gwarea, int stop)
+Return a pointer to a null terminated string starting at the current position and ending
+and the stop character.
+
+\param orig_line The line that is being parsed.
+\param word A pointer to set to the beginning of the string.
+\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.
+\retval -1 Invalid \a orig_line passed to the function.
+*/
+
+
+
+
 /*! \fn long long int my_atoll (const char *nptr)
 
 Convert a string into a long long.
@@ -157,12 +189,13 @@ Create the directory and all the non existing parent directories.
 
 
 
-/*! \fn void my_lltoa(unsigned long long int n, char s[], int len)
+/*! \fn void my_lltoa(unsigned long long int n, char *s, int ssize, int len)
 
 Format a long long into a string.
 
 \param n The number to format.
 \param s The buffer to write the number.
+\param ssize The size of the output buffer.
 \param len The minimum number of digits to format in the output. If the formatted
 number is less than this length, it is padded with zeros.
 
@@ -748,6 +781,18 @@ be at least 255 characters long.
 
 
 
+/*! \fn void url_to_file(const char *url,char *file,int filesize)
+Mangle an URL to produce a part that can be included in a file.
+
+\param url The URL to mangle.
+\param file The buffer to write the mangled URL.
+\param filesize The size of the buffer.
+*/
+
+
+
+
+
 /*! \fn void write_html_trailer(FILE *fp_ou)
 End the HTML file by closing the centered table that was opened by write_html_header(), writting
 the informations of show_info() and closing the body and html tag. After this function returns, the
index 1018deded480b0f80162fd7a3bf4835cae63d93b..5ba22c46af128ced9d4df0577648141c710152f0 100644 (file)
@@ -37,7 +37,7 @@ void download_report(void)
    FILE *fp_in = NULL, *fp_ou = NULL;
 
    char *buf;
-   char url[MAX_URL_LEN];
+   char *url;
    char report_in[MAXLEN];
    char wdirname[MAXLEN];
    char report[MAXLEN];
@@ -106,9 +106,12 @@ void download_report(void)
    while((buf=longline_read(fp_in,&line))!=NULL) {
       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);
+          getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken record or garbage in your %s file"),report_in);
+         exit(1);
+      }
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),report_in);
          exit(1);
       }
 
@@ -160,7 +163,7 @@ void download_report(void)
          output_html_url(fp_ou,url);
          fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",ImageFile);
       }
-      fputs("<a href=\"",fp_ou);
+      fputs("<a href=\"html://",fp_ou);
       output_html_url(fp_ou,url);
       fputs("\">",fp_ou);
       output_html_string(fp_ou,url,100);
diff --git a/html.c b/html.c
index 53d498f43bde8dd05eb8d68ffdaf500458cf3899..560dd41c26c0171baa3041081abf87b1b2817331 100644 (file)
--- a/html.c
+++ b/html.c
@@ -39,11 +39,11 @@ void htmlrel(void)
    long long int ltemp;
    long long int ntotuser;
    long long int userbytes, userelap;
-   char *linebuf;
+   char *buf;
    char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
-   char url[MAX_URL_LEN], tmsg[50], csort[MAXLEN];
+   char *url, tmsg[50], csort[MAXLEN];
    char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
-   char userurl[1024], userhora[9], userdia[9];
+   char userhora[9], userdia[9];
    char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
    char denied_report[255], name2[MAXLEN];
    char *str;
@@ -57,10 +57,9 @@ void htmlrel(void)
    int cstatus;
    const char txtext[]=".txt";
    int dlen;
-   char urly[MAX_URL_LEN];
-   char siteind[MAX_URL_LEN];
+   char siteind[MAX_TRUNCATED_URL];
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   struct longlinestruct line,line1;
 
    if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
 
@@ -88,10 +87,14 @@ void htmlrel(void)
       fprintf(stderr, "SARG: (html2) %s: %s\n",text[45],arqper);
       exit(1);
    }
+   if (longline_prepare(&line)<0) {
+      debuga(_("Not enough memory to read file %s"),arqper);
+      exit(1);
+   }
    ttnacc=0;
    totbytes=0;
    totelap=0;
-   while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+   while((buf=longline_read(fp_in,&line))!=NULL) {
       if(strncmp(buf,"TOTAL\t",6) == 0) {
          getword_start(&gwarea,buf);
          if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(&ltemp,&gwarea,'\t')<0) {
@@ -112,6 +115,7 @@ void htmlrel(void)
       }
    }
    fclose(fp_in);
+   longline_free(&line);
 
    strcpy(arqper,dirname);
    strcat(arqper,"/sarg-users");
@@ -206,20 +210,20 @@ void htmlrel(void)
       tnelap=0;
       tnincache=0;
       tnoucache=0;
-      while((linebuf=longline_read(fp_in,&line))!=NULL) {
-         getword_start(&gwarea,linebuf);
+      while((buf=longline_read(fp_in,&line))!=NULL) {
+         getword_start(&gwarea,buf);
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+            printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
             exit(1);
          }
          tnacc+=ltemp;
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+            printf("SARG: Maybe you have a broken downloaded size in your %s file.\n",arqin);
             exit(1);
          }
          tnbytes+=ltemp;
-         if (getword_skip(MAX_URL_LEN,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+         if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+            debuga(_("Maybe you have a broken url in your %s file"),arqin);
             exit(1);
          }
          if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
@@ -227,17 +231,17 @@ void htmlrel(void)
             exit(1);
          }
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+            printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
             exit(1);
          }
          tnelap+=ltemp;
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+            printf("SARG: Maybe you have a broken in-cache volume in your %s file.\n",arqin);
             exit(1);
          }
          tnincache+=ltemp;
          if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqin,__LINE__);
+            printf("SARG: Maybe you have a broken out-cache volume in your %s file (%d).\n",arqin,__LINE__);
             exit(1);
          }
          tnoucache+=ltemp;
@@ -292,8 +296,8 @@ void htmlrel(void)
             debuga("%s: %s",text[61],usuario);
       }
 
-      while((linebuf=longline_read(fp_in,&line))!=NULL) {
-         getword_start(&gwarea,linebuf);
+      while((buf=longline_read(fp_in,&line))!=NULL) {
+         getword_start(&gwarea,buf);
          if (getword_atoll(&twork,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
             exit(1);
@@ -302,8 +306,8 @@ void htmlrel(void)
             printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
             exit(1);
          }
-         if (getword(url,sizeof(url),&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken url in your %s file.\n",arqin);
+         if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+            debuga(_("Maybe you have a broken url in your %s file"),arqin);
             exit(1);
          }
          if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
@@ -331,34 +335,12 @@ void htmlrel(void)
             else
                strcpy(tmp6,"../../images");
 
-            if(!LongUrl) {
-               char *endofhost=strchr(url,'/');
-               if (endofhost) *endofhost='\0';
-               strcpy(urly,url);
-            } else {
-               strcpy(urly,url);
-               url_module(url, module);
-               str=strchr(url,'/');
-               if (str){
-                  *str='\0';
-                  strcat(url,"&hellip;");
-                  strcat(url,module);
-               }
-            }
-
             if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
                s=text[110];
                for(z1=0 ; z1<sizeof(ltext110)-1 && s[z1] ; z1++)
                   ltext110[z1]=tolower(s[z1]);
                ltext110[z1]='\0';
-               for(z1=0; urly[z1]; z1++) {
-                  if(urly[z1]=='?' || urly[z1]=='-' || urly[z1]=='.' || urly[z1]==':' || urly[z1]=='/' || urly[z1]=='\\' ||
-                     urly[z1]=='*' || urly[z1]=='\'' || urly[z1]=='\"' || urly[z1]=='$')
-                     siteind[z1]='_';
-                  else
-                     siteind[z1]=urly[z1];
-               }
-               siteind[z1]='\0';
+               url_to_file(url,siteind,sizeof(siteind));
                fprintf(fp_ou,"<td class=\"data\"><a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" title=\"%s %s\" alt=\"T\"></a></td>",usuario,siteind,tmp6,ltext110,text[55]);
             } else {
                fprintf(fp_ou,"<td class=\"data\"></td>");
@@ -367,10 +349,17 @@ void htmlrel(void)
             if(Privacy)
                fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
             else {
+               fputs("<td class=\"data2\">",fp_ou);
                if(BlockIt[0]!='\0') {
-                  fprintf(fp_ou,"<td class=\"data2\"><a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\"></a><a href=\"http://%s\">&nbsp;%s</a></td>",wwwDocumentRoot,BlockIt,urly,tmp6,urly,urly);
-               } else
-                  fprintf(fp_ou,"<td class=\"data2\"><a href=\"http://%s\" title=\"%s\">%s</a></td>",urly,urly,url);
+                  fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
+                  output_html_url(fp_ou,url);
+                  fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
+               }
+               fputs("<a href=\"http://",fp_ou);
+               output_html_url(fp_ou,url);
+               fputs("\">%s",fp_ou);
+               output_html_string(fp_ou,url,100);
+               fputs("</a></td>",fp_ou);
             }
 
             if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
@@ -418,10 +407,15 @@ void htmlrel(void)
                exit(1);
             }
 
-            while(fgets(buf,sizeof(buf),fp_ip)!=NULL) {
+            if (longline_prepare(&line1)<0) {
+               debuga(_("Not enough memory to read file %s"),arqip);
+               exit(1);
+            }
+            while((buf=longline_read(fp_ip,&line1))!=NULL) {
                if(strstr(buf,url) != 0)
                   fputs(buf,fp_ip2);
             }
+            longline_free(&line1);
 
             fclose(fp_ip);
             fclose(fp_ip2);
@@ -441,14 +435,18 @@ void htmlrel(void)
 
             olduserip[0]='\0';
 
-            while(fgets(buf,sizeof(buf),fp_ip)) {
+            if (longline_prepare(&line1)<0) {
+               debuga(_("Not enough memory to read file %s"),arqip);
+               exit(1);
+            }
+            while((buf=longline_read(fp_ip,&line1))!=NULL) {
                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),&gwarea,'\t')<0) {
-                  printf("SARG: Maybe you have a broken user URL in your %s file.\n",tmp3);
+               if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+                  debuga(_("Maybe you have a broken user url in your %s file"),tmp3);
                   exit(1);
                }
                if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) {
@@ -468,9 +466,8 @@ void htmlrel(void)
                   exit(1);
                }
                if(strcmp(user_ip,olduserip) != 0) {
-                  my_lltoa(unelap,val2,0);
                   sprintf(wwork1,"%s",fixnum(unbytes,1));
-                  fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val2);
+                  fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%lld</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
 
                   strcpy(olduserip,user_ip);
                   unacc=0;
@@ -483,13 +480,13 @@ void htmlrel(void)
             }
 
             fclose(fp_ip);
+            longline_free(&line1);
 
             unlink(tmp2);
             unlink(tmp3);
 
-            my_lltoa(unelap,val3,0);
             sprintf(wwork1,"%s",fixnum(unbytes,1));
-            fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val3);
+            fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%lld</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
          }
 
          unacc=0;
index 2e6f6ad09f639d25e920e2254be64dfda56bc3a5..73eed1a91830d833a8d2714ab7cf2ea0d88d1880 100755 (executable)
@@ -151,6 +151,7 @@ int mkstemps(char *template, int suffixlen);
 
 #define MAXLEN 20000
 #define MAX_URL_LEN 40000
+#define MAX_TRUNCATED_URL 512
 #define MAXLOGS 255
 
 #define REPORT_TYPE_USERS_SITES         0x0001UL
@@ -203,8 +204,6 @@ int mkstemps(char *template, int suffixlen);
 #define INDEX_TREE_DATE 0x0001UL
 #define INDEX_TREE_FILE 0x0002UL
 
-FILE *fp_tt;
-
 char outdir[MAXLEN];
 char dirname[MAXLEN];
 char buf[MAXLEN];
index 427c9f1c5a9f8e534318c62bf651168626b6b594..6a1554698a58e6ffa6e191a33b427146f865cb1e 100755 (executable)
@@ -3,6 +3,7 @@ struct getwordstruct
 {
    const char *current;
    const char *beginning;
+   int modified;
 };
 
 struct longlinestruct
@@ -149,9 +150,11 @@ void close_usertab(void);
 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_limit(char *word, int limit, struct getwordstruct *gwarea, int stop);
 int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop);
 int getword_skip(int limit, struct getwordstruct *gwarea, int stop);
 int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop);
+int getword_ptr(char *orig_line,char **word, struct getwordstruct *gwarea, int stop);
 long long int my_atoll (const char *nptr);
 int is_absolute(const char *path);
 int getnumlist(char *, numlist *, const int, const int);
@@ -178,9 +181,10 @@ void subs(char *str, int size, char *from, char *to);
 void conv_month(char *month);
 void debuga(const char *msg,...);
 void debugaz(const char *head, const char *msg);
-void my_lltoa(unsigned long long int n, char s[], int len);
+void my_lltoa(unsigned long long int n, char *s, int ssize, int len);
 char *get_size(const char *path, const char *file);
 void url_module(const char *url, char *w2);
+void url_to_file(const char *url,char *file,int filesize);
 void strip_latin(char *line);
 char *buildtime(long long int elap);
 void obtdate(const char *dirname, const char *name, char *data);
diff --git a/index.c b/index.c
index c9a1c44869fa03bfad9410a8d1c2d3cc51dd6240..9b7a82bc8b4b8b3df585a289b5a614df5392fe40 100644 (file)
--- a/index.c
+++ b/index.c
@@ -336,29 +336,29 @@ static void make_file_index(void)
          */
          getword_start(&gwarea,data);
          if (getword_skip(16,&gwarea,' ')<0) {
-            printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+            debuga(_("Maybe you have a broken week day in your %s%s/sarg-date file"),outdir,direntp->d_name);
             exit(1);
          }
          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);
+            debuga(_("Maybe you have a broken month in your %s%s/sarg-date file"),outdir,direntp->d_name);
             exit(1);
          }
          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);
+            debuga(_("Maybe you have a broken day in your %s%s/sarg-date file"),outdir,direntp->d_name);
             exit(1);
          }
          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);
+            debuga(_("Maybe you have a broken time in your %s%s/sarg-date file"),outdir,direntp->d_name);
             exit(1);
          }
          do {
             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);
+               debuga(_("Maybe you have a broken year in your %s%s/sarg-date file"),outdir,direntp->d_name);
                exit(1);
             }
          } while (year[0] && !isdigit(year[0])); //skip time zone information with spaces until the year is found
          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);
+            debuga(_("Maybe you have a broken time in your %s%s/sarg-date file"),outdir,direntp->d_name);
             exit(1);
          }
          buildymd(day,mon,year,ftime);
diff --git a/log.c b/log.c
index 20769a3e968cb09c4ec61695e89216f1789e206a..3cbf8f998981e6f49e039863a5235a9fd8dd86f2 100644 (file)
--- a/log.c
+++ b/log.c
@@ -100,8 +100,9 @@ int main(int argc,char *argv[])
    char start_hour[128];
    char end_hour[128];
    char *linebuf;
-   char url[MAX_URL_LEN];
-   char urly[MAX_URL_LEN];
+   char hostname[512];
+   char *url;
+   char *urly;
    enum InputLogFormat ilf;
    int ilf_count[ILF_Last];
    int  ch;
@@ -129,7 +130,7 @@ int main(int argc,char *argv[])
    unsigned long recs2=0UL;
    int OutputNonZero = REPORT_EVERY_X_LINES ;
    int download_flag=0;
-   char download_url[MAX_URL_LEN];
+   char *download_url;
    char sz_Last_User[MAXLEN]="";
    struct getwordstruct gwarea;
    struct longlinestruct line;
@@ -890,8 +891,8 @@ int main(int argc,char *argv[])
                      printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                      exit(1);
                   }
-                  if (getword(url,sizeof(url),&gwarea,' ')<0) {
-                     printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  if (getword_ptr(linebuf,&url,&gwarea,' ')<0) {
+                     debuga(_("Maybe you have a broken url in your %s file"),arq);
                      exit(1);
                   }
                   if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0 ||
@@ -949,8 +950,8 @@ int main(int argc,char *argv[])
                   printf("SARG: Maybe you have a broken request method in your %s file.\n",arq);
                   exit(1);
                }
-               if (getword(url,sizeof(url),&gwarea,' ')<0){
-                  printf("SARG: Maybe you have a broken URI in your %s file.\n",arq);
+               if (getword_ptr(linebuf,&url,&gwarea,' ')<0){
+                  debuga(_("Maybe you have a broken url in your %s file"),arq);
                   exit(1);
                }
                if (getword(user,sizeof(user),&gwarea,' ')<0){
@@ -979,8 +980,8 @@ int main(int argc,char *argv[])
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(url,sizeof(url),&gwarea,'\t')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+            if (getword_ptr(linebuf,&url,&gwarea,'\t')<0){
+               debuga(_("Maybe you have a broken record or garbage in your %s file"),arq);
                exit(1);
             }
             if (getword(tam,sizeof(tam),&gwarea,'\t')<0){
@@ -1038,58 +1039,54 @@ int main(int argc,char *argv[])
             if (!isa_ncols) continue;
             getword_start(&gwarea,linebuf);
             for (x=0 ; x<isa_ncols ; x++) {
-               if (getword(val1,sizeof(val1),&gwarea,'\t')<0) {
-                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               if (getword_ptr(linebuf,&str,&gwarea,'\t')<0) {
+                  debuga(_("Maybe you have a broken record or garbage in your %s file"),arq);
                   exit(1);
                }
                if (x==isa_cols[ISACOL_Ip]) {
-                  if (strlen(val1)>=sizeof(ip)) {
+                  if (strlen(str)>=sizeof(ip)) {
                      printf("SARG: Maybe you have a broken IP in your %s file.\n",arq);
                      exit(1);
                   }
-                  strcpy(ip,val1);
+                  strcpy(ip,str);
                } else if (x==isa_cols[ISACOL_UserName]) {
-                  if (strlen(val1)>=sizeof(user)) {
+                  if (strlen(str)>=sizeof(user)) {
                      printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
                      exit(1);
                   }
-                  strcpy(user,val1);
+                  strcpy(user,str);
                } else if (x==isa_cols[ISACOL_Date]) {
-                  if (strlen(val1)>=sizeof(data)) {
+                  if (strlen(str)>=sizeof(data)) {
                      printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                      exit(1);
                   }
-                  strcpy(data,val1);
+                  strcpy(data,str);
                } else if (x==isa_cols[ISACOL_Time]) {
-                  if (strlen(val1)>=sizeof(hora)) {
+                  if (strlen(str)>=sizeof(hora)) {
                      printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
                      exit(1);
                   }
-                  strcpy(hora,val1);
+                  strcpy(hora,str);
                } else if (x==isa_cols[ISACOL_TimeTaken]) {
-                  if (strlen(val1)>=sizeof(elap)) {
+                  if (strlen(str)>=sizeof(elap)) {
                      printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq);
                      exit(1);
                   }
-                  strcpy(elap,val1);
+                  strcpy(elap,str);
                } else if (x==isa_cols[ISACOL_Bytes]) {
-                  if (strlen(val1)>=sizeof(tam)) {
+                  if (strlen(str)>=sizeof(tam)) {
                      printf("SARG: Maybe you have a broken download size in your %s file.\n",arq);
                      exit(1);
                   }
-                  strcpy(tam,val1);
+                  strcpy(tam,str);
                } else if (x==isa_cols[ISACOL_Uri]) {
-                  if (strlen(val1)>=sizeof(url)) {
-                     printf("SARG: Maybe you have a broken URL in your %s file.\n",arq);
-                     exit(1);
-                  }
-                  strcpy(url,val1);
+                  url=str;
                } else if (x==isa_cols[ISACOL_Status]) {
-                  if (strlen(val1)>=sizeof(code)) {
+                  if (strlen(str)>=sizeof(code)) {
                      printf("SARG: Maybe you have a broken access code in your %s file.\n",arq);
                      exit(1);
                   }
-                  strcpy(code,val1);
+                  strcpy(code,str);
                }
             }
 
@@ -1181,8 +1178,7 @@ int main(int argc,char *argv[])
             }
          }
 
-         if((ReportType & REPORT_TYPE_DENIED) != 0)
-            strcpy(urly,url);
+         urly=url;
 
          if(ilf!=ILF_Sarg) {
             /*
@@ -1191,7 +1187,7 @@ int main(int argc,char *argv[])
             */
             download_flag=is_download_suffix(url);
             if (download_flag) {
-               strcpy(download_url,url);
+               download_url=url;
                download_count++;
             }
          }
@@ -1207,12 +1203,12 @@ int main(int argc,char *argv[])
          }
 
          if(!LongUrl) {
-            char *endofhost=strchr(url,'/');
-            if (endofhost)
-               *endofhost='\0';
-            if(strlen(url) > 512 && (endofhost=strchr(url,'%')) != NULL) {
-               *endofhost='\0';
-            }
+            int i;
+
+            for (i=0 ; i<sizeof(hostname)-1 && url[i] && url[i]!='/' ; i++)
+               hostname[i]=url[i];
+            hostname[i]='\0';
+            url=hostname;
          }
 
          if(ilf==ILF_Squid) {
index 78dc1bcf0eafca8e818854ea07e32e9ddf9382a8..867e607523a08388157d8bc34719721dee13840f 100755 (executable)
@@ -32,10 +32,6 @@ static void datashow(const char *);
 static void getlog(void);
 static void header(void);
 
-char typ[128];
-char ouser[MAXLEN]="";
-char ourl[MAXLEN]="";
-
 void realtime(void)
 {
 
@@ -97,8 +93,9 @@ static int getdata(char *rec, FILE *ftmp)
    struct tm *t;
    char dat[128];
    char tbuf[128];
+   char typ[128];
    char warea[MAXLEN];
-   char url[MAX_URL_LEN];
+   char *url;
    struct getwordstruct gwarea;
 
    getword_start(&gwarea,rec);
@@ -131,7 +128,7 @@ static int getdata(char *rec, FILE *ftmp)
       return(-1);
    }
    if(strncmp(typ,"CONNECT",7) == 0) {
-      if (getword(url,sizeof(url),&gwarea,' ')<0) {
+      if (getword_ptr(rec,&url,&gwarea,' ')<0) {
          return(-1);
       }
       if (getword(user,sizeof(user),&gwarea,' ')<0) {
@@ -146,16 +143,16 @@ static int getdata(char *rec, FILE *ftmp)
          fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
          return(-1);
       }
-      if (getword(url,sizeof(url),&gwarea,'/')<0) {
-         fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
+      if (getword_ptr(rec,&url,&gwarea,'/')<0) {
+         debuga(_("The URL at column 7 is too long"));
          return(-1);
       }
       if (getword_skip(MAXLEN,&gwarea,' ')<0) {
-         fprintf(stderr,"SARG: The data at column 8 is too long.\n");
+         debuga(_("The data at column 8 is too long"));
          return(-1);
       }
       if (getword(user,sizeof(user),&gwarea,' ')<0) {
-         fprintf(stderr,"SARG: The user at column 9 is too long.\n");
+         debuga(_("The user at column 9 is too long"));
          return(-1);
       }
    }
@@ -179,9 +176,15 @@ static void datashow(const char *tmp)
    FILE *fin;
    char dat[128];
    char tim[128];
-   char buf[MAXLEN];
-   char url[MAX_URL_LEN];
+   char *buf;
+   char *url;
+   char *ourl=NULL;
+   char ouser[MAXLEN]="";
+   char typ[128];
+   int url_len;
+   int ourl_size=0;
    struct getwordstruct gwarea;
+   struct longlinestruct line;
 
    if((fin=fopen(tmp,"r"))==NULL) {
       fprintf(stderr, "SARG: (realtime) open error %s - %s\n",tmp,strerror(errno));
@@ -190,7 +193,12 @@ static void datashow(const char *tmp)
 
    header();
 
-   while(fgets(buf, sizeof(buf), fin)) {
+   if (longline_prepare(&line)<0) {
+      debuga(_("Not enough memory to read the log file"));
+      exit(1);
+   }
+
+   while((buf=longline_read(fin,&line))!=NULL) {
       fixendofline(buf);
       getword_start(&gwarea,buf);
       if (getword(dat,sizeof(dat),&gwarea,'\t')<0) {
@@ -210,8 +218,8 @@ static void datashow(const char *tmp)
          exit(1);
       }
       if(strlen(dat) < 3 || strlen(user) < 1) continue;
-      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),tmp);
          exit(1);
       }
       if (getword(typ,sizeof(typ),&gwarea,'\t')<0) {
@@ -221,7 +229,7 @@ static void datashow(const char *tmp)
       if(strstr(RealtimeTypes,typ) == 0)
          continue;
 
-      if(strcmp(ouser,user) == 0 && strcmp(ourl,url) == 0)
+      if(strcmp(ouser,user) == 0 && ourl && strcmp(ourl,url) == 0)
          continue;
 
       if(userip)
@@ -237,8 +245,20 @@ static void datashow(const char *tmp)
 
       printf("<tr><td class=\"data\">%s %s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data2\"><a href=\"http://%s\">%s</td></tr>\n",dat,tim,ip,name,typ,url,url);
       strcpy(ouser,user);
+
+      url_len=strlen(url);
+      if (!ourl || url_len>=ourl_size) {
+         ourl_size=url_len+1;
+         ourl=realloc(ourl,ourl_size);
+         if (!ourl) {
+            debuga(_("Not enough memory to store the url"));
+            exit(1);
+         }
+      }
       strcpy(ourl,url);
    }
+   longline_free(&line);
+   if (ourl) free(ourl);
 
    puts("</table>\n</div>\n</body>\n</html>\n");
    fclose(fin);
@@ -259,7 +279,7 @@ static void header(void)
       printf("  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
    css(stdout);
    puts("</head>\n");
-   printf(buf,"<body style=\"font-family:%s;font-size:%s;background-color:%s;background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
+   printf("<body style=\"font-family:%s;font-size:%s;background-color:%s;background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
    puts("<div align=\"center\"><table cellpadding=\"1\" cellspacing=\"1\">\n");
    printf("<tr><th class=\"title_l\" colspan=\"10\">SARG %s</th></tr>\n",text[134]);
    printf("<tr><th class=\"text\" colspan=\"10\">%s: %d s</th></tr>\n",text[136],realtime_refresh);
index 3f7f9c532b06992652a0a6de33627813a9f88c28..16ca34ea85114aff22b00086733f08ac3c322c44 100644 (file)
--- a/report.c
+++ b/report.c
@@ -27,6 +27,8 @@
 #include "include/conf.h"
 #include "include/defs.h"
 
+static FILE *fp_tt=NULL;
+
 static void maketmp(const char *user, const char *dirname, int debug, int indexonly);
 static void maketmp_hour(const char *user, const char *dirname, int indexonly);
 static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly);
@@ -42,16 +44,18 @@ void gerarel(void)
    FILE *fp_gen;
 
    char *buf;
-   char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAX_URL_LEN];
+   char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], *accurl;
    char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN];
-   char wdirname[MAXLEN], oldurl[MAX_URL_LEN], oldaccuser[MAXLEN];
+   char wdirname[MAXLEN], oldaccuser[MAXLEN];
+   char *oldurl=NULL;
    char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAXLEN];
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char accsmart[MAXLEN];
    char crc2[MAXLEN/2 -1];
-   char siteind[MAX_URL_LEN];
+   char siteind[MAX_TRUNCATED_URL];
    char arqtt[256];
-   char oldurltt[MAX_URL_LEN],oldaccdiatt[11],oldacchoratt[9];
+   char *oldurltt=NULL;
+   char oldaccdiatt[11],oldacchoratt[9];
    long long int nbytes=0;
    long long int nelap=0;
    long long int nacc=0;
@@ -64,6 +68,9 @@ void gerarel(void)
    struct dirent *direntp;
    const char logext[]=".log";
    int dlen;
+   int url_len;
+   int ourl_size=0;
+   int ourltt_size=0;
    struct getwordstruct gwarea;
    struct longlinestruct line;
 
@@ -90,6 +97,7 @@ void gerarel(void)
 
    olduser[0]='\0';
    strncat(tmp,"/sarg",5);
+   fp_tt=NULL;
 
    dirp = opendir(tmp);
    while ((direntp = readdir( dirp )) != NULL ) {
@@ -131,7 +139,8 @@ void gerarel(void)
       }
 
       ttopen=0;
-      memset(oldurltt,0,sizeof(oldurltt));
+      oldurltt=NULL;
+      ourltt_size=0;
       memset(oldaccdiatt,0,sizeof(oldaccdiatt));
       memset(oldacchoratt,0,sizeof(oldacchoratt));
 
@@ -144,9 +153,9 @@ void gerarel(void)
          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_atoll(&accbytes,&gwarea,'\t')<0 ||
+             getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&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 (%d).\n",tmp3,__LINE__);
+            debuga(_("Maybe you have a broken record or garbage in your %s file (%d)"),tmp3,__LINE__);
             exit(1);
          }
          if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue;
@@ -182,6 +191,15 @@ void gerarel(void)
          }
 
          if(!rtotal){
+            url_len=strlen(accurl);
+            if (!oldurl || url_len>=ourl_size) {
+               ourl_size=url_len+1;
+               oldurl=realloc(oldurl,ourl_size);
+               if (!oldurl) {
+                  debuga(_("Not enough memory to store the url"));
+                  exit(1);
+               }
+            }
             strcpy(oldurl,accurl);
             strcpy(oldacccode,acccode);
             strcpy(oldaccuser,accuser);
@@ -226,16 +244,11 @@ void gerarel(void)
          nelap+=accelap;
 
          if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0 &&
-             (strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) {
+             (!oldurltt || strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) {
 
             if(!ttopen) {
                ind2++;
-               strcpy(siteind,accurl);
-               for(str=siteind; *str; str++) {
-                  if(*str=='?' || *str=='-' || *str=='.' || *str==':' || *str=='/' || *str=='\\' || *str=='*' ||
-                     *str=='\'' || *str=='\"' || *str=='$' || *str=='@')
-                     *str='_';
-               }
+               url_to_file(accurl,siteind,sizeof(siteind));
                snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,accuser);
                if(access(arqtt, R_OK) != 0)
                   my_mkdir(arqtt);
@@ -268,8 +281,19 @@ void gerarel(void)
                fprintf(fp_tt,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[91],tmp4,text[110]+5);
             }
 
-            fprintf(fp_tt,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accurl,accdia,acchora);
+            fputs("<tr><td class=\"data\">",fp_tt);
+            output_html_string(fp_tt,accurl,100);
+            fprintf(fp_tt,"</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia,acchora);
 
+            url_len=strlen(accurl);
+            if (!oldurltt || url_len>=ourltt_size) {
+               ourltt_size=url_len+1;
+               oldurltt=realloc(oldurltt,ourltt_size);
+               if (!oldurltt) {
+                  debuga(_("Not enough memory to store the url"));
+                  exit(1);
+               }
+            }
             strcpy(oldurltt,accurl);
             strcpy(oldaccdiatt,accdia);
             strcpy(oldacchoratt,acchora);
@@ -290,6 +314,15 @@ void gerarel(void)
 
          strcpy(oldacccode,acccode);
          strcpy(oldaccip,accip);
+         url_len=strlen(accurl);
+         if (url_len>=ourl_size) {
+            ourl_size=url_len+1;
+            oldurl=realloc(oldurl,ourl_size);
+            if (!oldurl) {
+               debuga(_("Not enough memory to store the url"));
+               exit(1);
+            }
+         }
          strcpy(oldurl,accurl);
          strcpy(oldaccdia,accdia);
          strcpy(oldacchora,acchora);
@@ -299,19 +332,23 @@ void gerarel(void)
       fclose(fp_in);
       unlink(tmp3);
       longline_free(&line);
+      if (oldurltt) free(oldurltt);
    }
    closedir(dirp);
 
-   if(strstr(oldacccode,"DENIED") != 0)
-      strcpy(oldmsg,text[46]);
-   else
-      strcpy(oldmsg,"OK");
-   strcpy(wdirname,dirname);
-   if(oldaccuser[0] == '\0')
-      strcpy(oldaccuser,accuser);
-   gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
-   strcpy(wdirname,dirname);
-   gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+   if (oldurl) {
+      if(strstr(oldacccode,"DENIED") != 0)
+         strcpy(oldmsg,text[46]);
+      else
+         strcpy(oldmsg,"OK");
+      strcpy(wdirname,dirname);
+      if(oldaccuser[0] == '\0')
+         strcpy(oldaccuser,accuser);
+      gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+      strcpy(wdirname,dirname);
+      gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+      free(oldurl);
+   }
    fclose(fp_gen);
    day_totalize(tmp,oldaccuser,indexonly);
 
@@ -433,18 +470,13 @@ void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, lo
 {
 
    FILE *fp_ou;
-   char val1[16];
-   char val2[16];
-   char val3[16];
-   char val4[16];
-   char val5[16];
    char wdirname[MAXLEN];
 
    if(indexonly) return;
    if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
 
    if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) {
-      fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser);
+      debuga(_("Path too long %s/%s.utmp"),tmp,oldaccuser);
       exit(1);
    }
 
@@ -453,12 +485,7 @@ void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, lo
       exit(1);
    }
 
-   my_lltoa(nacc,val1,0);
-   my_lltoa(nbytes,val2,0);
-   my_lltoa(nelap,val3,0);
-   my_lltoa(incache,val4,0);
-   my_lltoa(oucache,val5,0);
-   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5);
+   fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
 
    fclose(fp_ou);
    ttopen=0;
@@ -467,6 +494,7 @@ void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, lo
       fputs("</table>\n</div>\n",fp_tt);
       fputs("</body>\n</html>\n",fp_tt);
       fclose(fp_tt);
+      fp_tt=NULL;
    }
 
    return;
@@ -546,12 +574,7 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o
       exit(1);
    }
 
-   my_lltoa(nacc,val1,0);
-   my_lltoa(nbytes,val2,0);
-   my_lltoa(nelap,val3,0);
-   my_lltoa(incache,val4,0);
-   my_lltoa(oucache,val5,0);
-   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5);
+   fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
 
    fclose(fp_ou);
    ttopen=0;
@@ -561,6 +584,7 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o
       fputs("</table>\n",fp_tt);
       fputs("</body>\n</html>\n",fp_tt);
       fclose(fp_tt);
+      fp_tt=NULL;
    }
 
    return;
@@ -570,12 +594,7 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o
 
 static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache)
 {
-   my_lltoa(nacc,val1,0);
-   my_lltoa(nbytes,val2,0);
-   my_lltoa(nelap,val3,0);
-   my_lltoa(incache,val4,0);
-   my_lltoa(oucache,val5,0);
-   fprintf(fp_gen,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5);
+   fprintf(fp_gen,"%s\t%lld\t%lld\t%s\t%s\t%s\t%s\t%lld\t%lld\t%lld\n",user,nacc,nbytes,url,ip,hora,dia,nelap,incache,oucache);
    return;
 
 }
index 4de082714b8e24ed63374a0ef79eaa53514bf8d3..d7ac77a7922a1f02c984ec70f3e0594a94587ec6 100644 (file)
@@ -34,9 +34,9 @@ void siteuser(void)
 
    char *buf;
    char user[MAXLEN];
-   char url[MAX_URL_LEN];
+   char *url;
    char wuser[MAXLEN];
-   char ourl[MAX_URL_LEN];
+   char *ourl;
    char csort[255];
    char general[MAXLEN];
    char general2[MAXLEN];
@@ -46,6 +46,8 @@ void siteuser(void)
    char period[100];
    int regs=0;
    int ucount=0;
+   int ourl_size;
+   int url_len;
    char *users;
    long long int nbytes;
    long long int obytes;
@@ -107,7 +109,8 @@ void siteuser(void)
       fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[100],text[91],text[103]);
 
    user[0]='\0';
-   ourl[0]='\0';
+   ourl=NULL;
+   ourl_size=0;
    obytes=0;
 
    if((users=(char *) malloc(204800))==NULL){
@@ -162,12 +165,21 @@ void siteuser(void)
          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),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have an invalid url in your %s file of the siteuser.\n",general2);
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have an invalid url in your %s file of the siteuser"),general2);
          exit(1);
       }
 
       if(!regs) {
+         url_len=strlen(url);
+         if (!ourl || url_len>=ourl_size) {
+            ourl_size=url_len+1;
+            ourl=realloc(ourl,ourl_size);
+            if (!ourl) {
+               debuga(_("Not enough memory to store the url"));
+               exit(1);
+            }
+         }
          strcpy(ourl,url);
          obytes=nbytes;
          regs++;
@@ -210,6 +222,15 @@ void siteuser(void)
          ucount=0;
          strcpy(users,name);
          strcat(users," ");
+         url_len=strlen(url);
+         if (url_len>=ourl_size) {
+            ourl_size=url_len+1;
+            ourl=realloc(ourl,ourl_size);
+            if (!ourl) {
+               debuga(_("Not enough memory to store the url"));
+               exit(1);
+            }
+         }
          strcpy(ourl,url);
          obytes=nbytes;
       }
@@ -224,6 +245,7 @@ void siteuser(void)
       output_html_string(fp_ou,ourl,100);
       fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></tr>\n",users);
    }
+   if (ourl) free(ourl);
 
    unlink(general2);
 
index fe8009803feb88637f7871328aadaa9bb6b684e7..f084dd1bb31c7d1b06f690c93bec6d4841d49672 100644 (file)
@@ -113,8 +113,6 @@ static void read_log(const char *wentp, FILE *fp_ou)
                }
                if(strcmp(leks,"year") == 0)
                   strcpy(year,res);
-               else if(strcmp(leks,"year") == 0)
-                  strcpy(year,res);
                else if(strcmp(leks,"mon") == 0)
                   strcpy(mon,res);
                else if(strcmp(leks,"day") == 0)
index 6f60820a06cfcf762c8224a9a71de348187bdacb..49aca08e78ef4f27c8c11d274a3fb8729eadda1a 100644 (file)
@@ -32,7 +32,7 @@ void squidguard_report(void)
 
    FILE *fp_in = NULL, *fp_ou = NULL;
 
-   char url[MAXLEN];
+   char *url;
    char squidguard_in[MAXLEN];
    char per[MAXLEN];
    char report[MAXLEN];
@@ -94,9 +94,16 @@ void squidguard_report(void)
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       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);
+          getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken record or garbage in your %s file"),squidguard_in);
+         exit(1);
+      }
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),squidguard_in);
+         exit(1);
+      }
+      if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
+         debuga(_("Maybe you have a broken rule in your %s file"),squidguard_in);
          exit(1);
       }
 
@@ -158,7 +165,11 @@ void squidguard_report(void)
             continue;
       }
 
-      fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></th>\n",name,ip,data,hora,url,url,rule);
+      fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://",name,ip,data,hora);
+      output_html_url(fp_ou,url);
+      fputs("\">",fp_ou);
+      output_html_string(fp_ou,url,100);
+      fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></th>\n",rule);
    }
    fclose(fp_in);
 
index 93a7ae19501e1f290270a0762bdf53eaad61554c..599041ff313253aaeb324c7efbd5515951b44073 100644 (file)
@@ -33,8 +33,9 @@ void topsites(void)
    FILE *fp_in, *fp_ou;
 
    char *buf;
-   char url[MAX_URL_LEN];
-   char ourl[MAX_URL_LEN];
+   char user[MAXLEN];
+   char *url;
+   char *ourl=NULL;
    char ntemp[255];
    char ttnacc[20];
    char ttnbytes[20];
@@ -58,6 +59,8 @@ void topsites(void)
    long long int twork1=0, twork2=0, twork3=0;
    int regs=0;
    int cstatus;
+   int url_len;
+   int ourl_size=0;
    struct getwordstruct gwarea;
    struct longlinestruct line;
 
@@ -112,11 +115,11 @@ void topsites(void)
 
    while((buf=longline_read(fp_in,&line))!=NULL) {
       getword_start(&gwarea,buf);
-      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
+      if (getword(user,sizeof(user),&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(strcmp(user,"TOTAL") == 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);
@@ -139,8 +142,8 @@ void topsites(void)
          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),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have an invalid url in your %s file of the topsites.\n",general2);
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have an invalid url in your %s file of the topsites"),general2);
          exit(1);
       }
       if (getword(ntemp,sizeof(ntemp),&gwarea,'\t')<0) {
@@ -161,15 +164,30 @@ void topsites(void)
       }
 
       if(!regs) {
+         url_len=strlen(url);
+         if (!ourl || url_len>=ourl_size) {
+            ourl_size=url_len+1;
+            ourl=realloc(ourl,ourl_size);
+            if (!ourl) {
+               debuga(_("Not enough memory to store the url"));
+               exit(1);
+            }
+         }
          strcpy(ourl,url);
          regs++;
       }
 
       if(strcmp(url,ourl) != 0) {
-         my_lltoa(tnacc,val1,15);
-         my_lltoa(tnbytes,val2,15);
-         my_lltoa(tntime,val3,15);
-         fprintf(fp_ou,"%s\t%s\t%s\t%s\n",val1,val2,val3,ourl);
+         fprintf(fp_ou,"%015lld\t%015lld\t%015lld\t%s\n",tnacc,tnbytes,tntime,ourl);
+         url_len=strlen(url);
+         if (url_len>=ourl_size) {
+            ourl_size=url_len+1;
+            ourl=realloc(ourl,ourl_size);
+            if (!ourl) {
+               debuga(_("Not enough memory to store the url"));
+               exit(1);
+            }
+         }
          strcpy(ourl,url);
          tnacc=0;
          tnbytes=0;
@@ -184,10 +202,10 @@ void topsites(void)
    unlink(general2);
    longline_free(&line);
 
-   my_lltoa(tnacc,val1,15);
-   my_lltoa(tnbytes,val2,15);
-   my_lltoa(tntime,val3,15);
-   fprintf(fp_ou,"%s\t%s\t%s\t%s\n",val1,val2,val3,ourl);
+   if (ourl) {
+      fprintf(fp_ou,"%015lld\t%015lld\t%015lld\t%s\n",tnacc,tnbytes,tntime,ourl);
+      free(ourl);
+   }
 
    fclose(fp_ou);
 
@@ -251,11 +269,14 @@ void topsites(void)
          exit(1);
       }
       if (nacc == 0) continue;
-      if (getword_atoll(&nbytes,&gwarea,'\t')<0 ||
-          getword_atoll(&ntime,&gwarea,'\t')<0 || getword(url,sizeof(url),&gwarea,'\t')<0) {
+      if (getword_atoll(&nbytes,&gwarea,'\t')<0 || getword_atoll(&ntime,&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
          exit(1);
       }
+      if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),sites);
+         exit(1);
+      }
 
       twork1=nacc;
       twork2=nbytes;
@@ -265,7 +286,7 @@ void topsites(void)
       strcpy(wwork2,fixnum(twork2,1));
       strcpy(wwork3,fixtime(twork3));
 
-      fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2 link\">",regs);
+      fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2 link\">",++regs);
 
       if(BlockIt[0] != '\0') {
          fprintf(fp_ou,"<a href=\"%s%s?url=\"",wwwDocumentRoot,BlockIt);
@@ -278,7 +299,6 @@ void topsites(void)
       fputs("\">",fp_ou);
       output_html_string(fp_ou,url,100);
       fprintf(fp_ou,"</a></td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",wwork1,wwork2,wwork3);
-      regs++;
    }
    fclose(fp_in);
    longline_free(&line);
index c5d12fa66308669a08a713584aaac3c132581ee0..83c1f0c4d8cda4c74d5f5874999ebd4909758316 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -126,8 +126,8 @@ void topuser(void)
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
          exit(1);
       }
-      if (getword_skip(MAX_URL_LEN,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
+      if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),wger);
          exit(1);
       }
       if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
@@ -158,12 +158,7 @@ void topuser(void)
          totuser++;
 
          if (olduser[0] != '\0') {
-            my_lltoa(tnbytes,val1,15);
-            my_lltoa(tnacc,val2,15);
-            my_lltoa(tnelap,val3,15);
-            my_lltoa(tnincache,val4,15);
-            my_lltoa(tnoucache,val5,15);
-            fprintf(fp_top2,"%s\t%s\t%s\t%s\t%s\t%s\n",olduser,val1,val2,val3,val4,val5);
+            fprintf(fp_top2,"%s\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
 
             ttnbytes+=tnbytes;
             ttnacc+=tnacc;
@@ -189,12 +184,7 @@ void topuser(void)
    longline_free(&line);
 
    if (olduser[0] != '\0') {
-      my_lltoa(tnbytes,val1,15);
-      my_lltoa(tnacc,val2,15);
-      my_lltoa(tnelap,val3,15);
-      my_lltoa(tnincache,val4,15);
-      my_lltoa(tnoucache,val5,15);
-      fprintf(fp_top2,"%s\t%s\t%s\t%s\t%s\t%s\n",olduser,val1,val2,val3,val4,val5);
+      fprintf(fp_top2,"%s\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
 
       ttnbytes+=tnbytes;
       ttnacc+=tnacc;
index 6b8b7a9363095be3f712858bc0349e10365a70cf..d24cec484b80d5e2782f5eb2b6b75830336f36bf 100644 (file)
--- a/totday.c
+++ b/totday.c
@@ -93,8 +93,7 @@ void day_totalize(const char *tmp, const char *user, int indexonly)
       }
 
       if(strcmp(hora,ohora) != 0 || strcmp(data,odata) != 0) {
-         my_lltoa(telap,val1,15);
-         fprintf(fp_ou,"%s\t%s\t%s\n",odata,ohora,val1);
+         fprintf(fp_ou,"%s\t%s\t%015lld\n",odata,ohora,telap);
          strcpy(odata,data);
          strcpy(ohora,hora);
          telap=0;
@@ -103,8 +102,7 @@ void day_totalize(const char *tmp, const char *user, int indexonly)
       telap+=my_atoll(elap);
    }
 
-   my_lltoa(telap,val1,15);
-   fprintf(fp_ou,"%s\t%s\t%s\n",data,hora,val1);
+   fprintf(fp_ou,"%s\t%s\t%015lld\n",data,hora,telap);
 
    fclose(fp_in);
    fclose(fp_ou);
index 469168bbb8470ebf3605341a44e8c6b885cd55ff..177fb95d055886b2e73f3c299cb7b0ae3d9d9a70 100644 (file)
--- a/totger.c
+++ b/totger.c
@@ -37,7 +37,7 @@ int totalger(const char *dirname, int debug, const char *outdir)
    long long int nacc, nbytes;
    long long int elap;
    long long int incac, oucac;
-   char wger[MAXLEN], user[MAXLEN], url[MAX_URL_LEN];
+   char wger[MAXLEN], user[MAXLEN];
    char ip[MAXLEN], hora[9], data[15];
    char *warea;
    struct getwordstruct gwarea;
@@ -72,8 +72,8 @@ int totalger(const char *dirname, int debug, const char *outdir)
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
+      if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+         debuga(_("Maybe you have a broken url in your %s file"),wger);
          exit(1);
       }
       if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
@@ -118,14 +118,7 @@ int totalger(const char *dirname, int debug, const char *outdir)
     exit(1);
    }
 
-   url[0]='\0';
-
-   my_lltoa(tnacc,val1,15);
-   my_lltoa(tnbytes,val2,15);
-   my_lltoa(telap,val3,15);
-   my_lltoa(tincache,val4,15);
-   my_lltoa(toucache,val5,15);
-   fprintf(fp_ou,"TOTAL\t%s\t%s\t%s\t%s\t%s\n",val1,val2,val3,val4,val5);
+   fprintf(fp_ou,"TOTAL\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",tnacc,tnbytes,telap,tincache,toucache);
    fclose(fp_ou);
 
    return (0);
diff --git a/util.c b/util.c
index 86975b5698a797c009aa82ecc3f9a6e1d5bdc313..29ea194b93ded9d7cdee05a351da3cf58ffca9b2 100644 (file)
--- a/util.c
+++ b/util.c
@@ -89,10 +89,15 @@ void getword_start(struct getwordstruct *gwarea, const char *line)
 {
    gwarea->beginning=line;
    gwarea->current=line;
+   gwarea->modified=0;
 }
 
 void getword_restart(struct getwordstruct *gwarea)
 {
+   if (gwarea->modified) {
+      debuga(_("Cannot parse again the line as it was modified"));
+      exit(1);
+   }
    gwarea->current=gwarea->beginning;
 }
 
@@ -122,6 +127,21 @@ int getword(char *word, int limit, struct getwordstruct *gwarea, int stop)
   return(0);
 }
 
+int getword_limit(char *word, int limit, struct getwordstruct *gwarea, int stop)
+{
+  int x;
+
+  limit--;
+  for(x=0; x<limit && gwarea->current[x] && gwarea->current[x] != stop ;x++) {
+     word[x] = gwarea->current[x];
+  }
+  word[x] = '\0';
+  gwarea->current+=x;
+  while (*gwarea->current && *gwarea->current != stop)  gwarea->current++;
+  if (*gwarea->current) ++gwarea->current;
+  return(0);
+}
+
 int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop)
 {
   int x;
@@ -206,6 +226,34 @@ int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop)
 }
 
 
+int getword_ptr(char *orig_line,char **word, struct getwordstruct *gwarea, int stop)
+{
+   /*!
+   \note Why pass the original buffer to the function ? Because we must modify it to
+   insert the terminating ASCII zero for the word we return and that's not compatible
+   with getword_restart(). Moreover, getword_start() sometime works on constant strings
+   so this function require the original buffer to detect any missuse.
+   */
+   int x;
+   int sep;
+   int start;
+
+   if (orig_line && orig_line!=gwarea->beginning) {
+      debuga(_("Invalid buffer passed to getword_ptr"));
+      return(-1);
+   }
+
+   start=(gwarea->current-gwarea->beginning);
+   if (word && orig_line) *word=orig_line+start;
+   for(x=0;((gwarea->current[x]) && (gwarea->current[x] != stop ));x++);
+   sep=(gwarea->current[x]!='\0');
+   if (word && orig_line) orig_line[start+x] = '\0';
+   if (sep) ++x;
+   gwarea->current+=x;
+   gwarea->modified=1;
+   return(0);
+}
+
 #define MAXLLL 30 //!< Maximum number of digits in long long (a guess).
 long long int my_atoll (const char *nptr)
 {
@@ -280,16 +328,22 @@ void my_mkdir(const char *name)
 }
 
 
-void my_lltoa(unsigned long long int n, char s[], int len)
+void my_lltoa(unsigned long long int n, char *s, int ssize, int len)
 {
    int i;
    int slen = 0;
    int j;
    char c;
 
+   ssize--;
+   if (len>ssize) {
+      debuga(_("The requested number length passed to my_lltoa (%d) is bigger than the output buffer size (%d)"),len,ssize);
+      abort();
+   }
+
    do {
       s[slen++] = (n % 10) + '0';
-   } while ((n /= 10) > 0);
+   } while ((n /= 10) > 0 && slen<ssize);
    s[slen] = '\0';
 
    for (i = 0, j = slen-1; i<j; i++, j--) {
@@ -477,7 +531,7 @@ char *fixnum(long long int value, int n)
    int numlen;
    static char abbrev[30];
 
-   my_lltoa(value, num, 0);
+   my_lltoa(value, num, sizeof(num), 0);
 
    if(strcmp(DisplayedValues,"abbreviation") == 0) {
       numlen = strlen(num);
@@ -568,7 +622,7 @@ char *fixnum2(long long int value, int n)
    char *pret;
    register int i, j, k;
 
-   my_lltoa(value, num, 0);
+   my_lltoa(value, num, sizeof(num), 0);
    bzero(buf, MAXLEN_FIXNUM2*2);
 
    pbuf = buf;
@@ -1554,6 +1608,24 @@ void url_module(const char *url, char *w2)
    w2[x]='\0';
 }
 
+void url_to_file(const char *url,char *file,int filesize)
+{
+   int i,skip;
+
+   filesize--;
+   skip=0;
+   for(i=0; i<filesize && *url; url++) {
+      if(*url=='?' || *url=='-' || *url=='.' || *url==':' || *url=='/' || *url=='\\' ||
+         *url=='*' || *url=='\'' || *url=='\"' || *url=='$') {
+         if (!skip) file[i++]='_';
+         skip=1;
+      } else {
+         file[i++]=*url;
+         skip=0;
+      }
+   }
+   file[i]='\0';
+}
 
 void version(void)
 {
@@ -1642,11 +1714,10 @@ char *longline_read(FILE *fp_in,struct longlinestruct *line)
    size_t nread;
 
    if (!line->buffer) return(NULL);
-   if (feof(fp_in)) return(NULL);
 
    line->start=line->end;
    skipcr=1;
-   while (skipcr || (line->buffer[line->end]!='\n' && line->buffer[line->end]!='\r')) {
+   while (skipcr || line->end>=line->length || (line->buffer[line->end]!='\n' && line->buffer[line->end]!='\r')) {
       if (line->end>=line->length) {
          if (line->start>0) {
             for (i=line->start ; i<line->end ; i++)