]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Download suffix stored in index with dichotomic search for efficiency.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 20 Dec 2009 20:06:18 +0000 (20:06 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 20 Dec 2009 20:06:18 +0000 (20:06 +0000)
Added getword_atoll to extract a number without requiring an additionnal string buffer.

18 files changed:
CMakeLists.txt
datafile.c
documentation/download.txt [new file with mode: 0644]
documentation/getconf.txt
documentation/util.txt
download.c
getconf.c
include/conf.h
include/defs.h
include/info.h
log.c
repday.c
report.c
siteuser.c
topsites.c
topuser.c
totger.c
util.c

index c3e07251a7d6bed24031c983e64e10537e165f51..7ab14557280f82a2e378ef6abacf26bd6a1cfed6 100755 (executable)
@@ -3,7 +3,7 @@ PROJECT(sarg C)
 SET(sarg_VERSION 2)
 SET(sarg_REVISION 2)
 SET(sarg_BUILD "7rc1")
-SET(sarg_BUILDDATE "Dec-18-2009")
+SET(sarg_BUILDDATE "Dec-20-2009")
 
 INCLUDE(AddFileDependencies)
 INCLUDE(CheckIncludeFile)
index be22a41a491381578faf16068d0685ff5b685c15..01a3335dd10c75f236e4e25950acf9584e4482b7 100644 (file)
@@ -33,10 +33,10 @@ void data_file(char *tmp)
 
    FILE *fp_in;
 
-   char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN], accbytes[12], accelap[10];
+   char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN];
    char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN];
    char dirname[MAXLEN], wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN];
-   char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50];
+   char olduser[MAXLEN], oldmsg[50], acccode[50], oldacccode[50];
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char accsmart[MAXLEN];
    char crc2[50];
@@ -50,6 +50,8 @@ void data_file(char *tmp)
    long long int rtotal=0;
    long long int incache=0;
    long long int oucache=0;
+   long long int accbytes;
+   long long int accelap;
    struct getwordstruct gwarea;
 
    ipantes[0]='\0';
@@ -81,8 +83,8 @@ void data_file(char *tmp)
          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(accurl,sizeof(accurl),&gwarea,' ')<0 || getword_atoll(&accbytes,&gwarea,' ')<0 ||
+             getword(acccode,sizeof(acccode),&gwarea,' ')<0 || getword_atoll(&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);
@@ -100,7 +102,6 @@ void data_file(char *tmp)
          if(!rtotal){
             strcpy(oldurl,accurl);
             strcpy(oldacccode,acccode);
-            strcpy(oldaccelap,accelap);
             strcpy(oldaccuser,accuser);
             strcpy(oldaccip,accip);
             strcpy(oldaccdia,accdia);
@@ -123,20 +124,19 @@ void data_file(char *tmp)
          }
 
          nacc++;
-         nbytes+=my_atoll(accbytes);
-         nelap+=my_atoll(accelap);
+         nbytes+=accbytes;
+         nelap+=accelap;
 
          strcpy(crc2,acccode);
          str=strchr(crc2,'/');
          if (str) *str='\0';
 
-         if(strstr(crc2,"MISS") != 0) oucache+=my_atoll(accbytes);
-         else incache+=my_atoll(accbytes);
+         if(strstr(crc2,"MISS") != 0) oucache+=accbytes;
+         else incache+=accbytes;
 
          strcpy(oldurl,accurl);
          strcpy(oldaccuser,accuser);
          strcpy(oldacccode,acccode);
-         strcpy(oldaccelap,accelap);
          strcpy(oldaccip,accip);
          strcpy(oldaccdia,accdia);
          strcpy(oldacchora,acchora);
diff --git a/documentation/download.txt b/documentation/download.txt
new file mode 100644 (file)
index 0000000..7b500b1
--- /dev/null
@@ -0,0 +1,72 @@
+/*!\file download.c
+\brief Report the downloaded files
+*/
+
+
+/*! \var static char *DownloadSuffix=NULL;
+The buffer to store the list of the suffixes to take into account when generating
+the report of the downloaded files. The suffixes in the list are separated by the ASCII
+null.
+*/
+
+
+
+/*! \var static char **DownloadSuffixIndex=NULL;
+The index of all the suffixes stored in ::DownloadSuffix. The list is sorted alphabetically.
+to speed up the search.
+*/
+
+
+/*! \var static int NDownloadSuffix=0;
+The number of suffixes in ::DownloadSuffixIndex.
+*/
+
+
+
+/*! \fn void download_report(void)
+Generate the report of the downloaded files. The list of the suffixes to take into account
+is set with set_download_suffix().
+*/
+
+
+
+/*! \fn void free_download(void)
+Free the memory allocated by set_download_suffix().
+*/
+
+
+
+/*! \fn void set_download_suffix(const char *list)
+Set the list of the suffixes corresponding to the download of files you want to detect with
+is_download_suffix(). The list is sorted to make the search faster.
+
+\param list A comma separated list of the suffixes to set in ::DownloadSuffix.
+
+\note The memory allocated by this function must be freed by free_download().
+*/
+
+
+
+
+
+/*! \fn int is_download_suffix(const char *url)
+Tell if the URL correspond to a downloaded file. The function takes the extension at the end of the
+URL with a maximum of 9 characters and compare it to the list of the download suffix in
+::DownloadSuffix. If the suffix is found in the list, the function reports the URL as the download
+of a file.
+
+\param url The URL to test.
+
+\retval 1 The URL matches a suffix of a download.
+\retval 0 The URL is not a known download.
+
+\note A downloaded file cannot be detected if the file name is embedded in a GET or POST request. Only requests
+that ends with the file name can be detected.
+
+\note A URL embedding another web site's address ending by .com at the end of the URL will match the download
+extension com if it is defined in the ::DownloadSuffix.
+*/
+
+
+
+
index 1b904d1b8cf2d2ea357bdece961c8bc2d2f0dadd..795b7742c2f8af2b7d116824cc316217182eca4f 100644 (file)
@@ -3,7 +3,7 @@
 */
 
 
-/*! \fn static int isparam_string(const char *param,const char *buf)
+/*! \fn static int is_param(const char *param,const char *buf)
 Tell if the buffer contains a line defining the given parameter.
 
 \param param The name of the parameter to find.
index 04564a7d5092a433c092501a4e402454d6d599ce..a61998f17857e56f0daf75796b6882c4fde644e7 100644 (file)
@@ -396,7 +396,7 @@ bytes long.
 
 
 
-/*! \fn void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, char *media)
+/*! \fn void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media)
 Count the total size transfered in a connection directory and compute the average number of bytes
 per entry.
 
@@ -802,28 +802,6 @@ The usertab file must have been read by read_usertab().
 
 
 
-
-/*! \fn int is_download_suffix(const char *url)
-Tell if the URL correspond to a downloaded file. The function takes the extension at the end of the
-URL with a maximum of 9 characters and compare it to the list of the download suffix in
-::DownloadSuffix. If the suffix is found in the list, the function reports the URL as the download
-of a file.
-
-\param url The URL to test.
-
-\retval 1 The URL matches a suffix of a download.
-\retval 0 The URL is not a known download.
-
-\note A downloaded file cannot be detected if the file name is embedded in a GET or POST request. Only requests
-that ends with the file name can be detected.
-
-\note A URL embedding another web site's address ending by .com at the end of the URL will match the download
-extension com if it is defined in the ::DownloadSuffix.
-*/
-
-
-
-
 /*! \fn void write_logo_image(FILE *fp_ou)
 Write a link of the logo of the organisation that generate the report in the HTML file. The logo
 is written in a centered table.
index f0c61d521930db18e66c723b4412ecee2267241d..92afee210848f9b40547270944db3c876d055400 100644 (file)
 #include "include/conf.h"
 #include "include/defs.h"
 
+static char *DownloadSuffix=NULL;
+static char **DownloadSuffixIndex=NULL;
+static int NDownloadSuffix=0;
+
 void download_report(void)
 {
 
@@ -177,3 +181,101 @@ void download_report(void)
 
    return;
 }
+
+void free_download(void)
+{
+   if (DownloadSuffix) {
+      free(DownloadSuffix);
+      DownloadSuffix=NULL;
+   }
+   if (DownloadSuffixIndex) {
+      free(DownloadSuffixIndex);
+      DownloadSuffixIndex=NULL;
+   }
+   NDownloadSuffix=0;
+}
+
+void set_download_suffix(const char *list)
+{
+   char *str;
+   int i, j, k;
+   int cmp;
+
+   free_download();
+
+   DownloadSuffix=strdup(list);
+   if (!DownloadSuffix) {
+      fprintf(stderr,"SARG: Download suffix list too long\n");
+      exit(1);
+   }
+   j = 1;
+   for (i=0 ; list[i] ; i++)
+      if (list[i] == ',') j++;
+   DownloadSuffixIndex=malloc(j*sizeof(char *));
+   if (!DownloadSuffixIndex) {
+      fprintf(stderr,"SARG: Too many download suffixes\n");
+      exit(1);
+   }
+
+   str = DownloadSuffix;
+   for (i=0 ; DownloadSuffix[i] ; i++) {
+      if (DownloadSuffix[i] == ',') {
+         DownloadSuffix[i] = '\0';
+         if (*str) {
+            for (j=0 ; j<NDownloadSuffix && (cmp=strcasecmp(str,DownloadSuffixIndex[j]))>0 ; j++);
+            if (cmp != 0) {
+               for (k=NDownloadSuffix ; k>j ; k--)
+                  DownloadSuffixIndex[k]=DownloadSuffixIndex[k-1];
+               NDownloadSuffix++;
+               DownloadSuffixIndex[j]=str;
+            }
+         }
+         str=DownloadSuffix+i+1;
+      }
+   }
+
+   if (*str) {
+      for (j=0 ; j<NDownloadSuffix && (cmp=strcasecmp(str,DownloadSuffixIndex[j]))>0 ; j++);
+      if (cmp != 0) {
+         for (k=NDownloadSuffix ; k>j ; k--)
+            DownloadSuffixIndex[k]=DownloadSuffixIndex[k-1];
+         NDownloadSuffix++;
+         DownloadSuffixIndex[j]=str;
+      }
+   }
+}
+
+int is_download_suffix(const char *url)
+{
+   int urllen;
+   int i;
+   int down, up, center;
+   const char *suffix;
+   int cmp;
+   const int max_suffix=10;
+
+   if(DownloadSuffix == NULL || NDownloadSuffix == 0) return(0);
+
+   urllen=strlen(url)-1;
+   if (urllen<=0) return(0);
+   if (url[urllen] == '.') return(0); //reject a single trailing dot
+
+   for (i=0 ; i<=max_suffix && i<urllen && url[urllen-i]!='.' ; i++)
+      if (url[urllen-i] == '/') return(0);
+   if (i>max_suffix || i>=urllen) return(0);
+
+   suffix=url+urllen-i+1;
+   down=0;
+   up=NDownloadSuffix-1;
+   while (down<=up) {
+      center=(down+up)/2;
+      cmp=strcasecmp(suffix,DownloadSuffixIndex[center]);
+      if (cmp == 0) return(1);
+      if (cmp < 0)
+         up = center-1;
+      else
+         down = center+1;
+   }
+   return(0);
+}
+
index 9a85ae39673a37ead1fe5715f5f141e545ce81ff..8bd916bfd1abfc6eacd808c826b305e53a48127b 100644 (file)
--- a/getconf.c
+++ b/getconf.c
@@ -28,7 +28,7 @@
 
 extern numlist hours, weekdays;
 
-static int isparam_string(const char *param,const char *buf)
+static int is_param(const char *param,const char *buf)
 {
    int plen;
 
@@ -230,7 +230,7 @@ static void parmtest(char *buf)
 
    if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
 
-   if (isparam_string("access_log",buf)>0) {
+   if (is_param("access_log",buf)>0) {
       if (AccessLogFromCmdLine==0) {
          if (NAccessLog>=MAXLOGS) {
             fprintf(stderr,"SARG: Too many log files.\n");
@@ -377,7 +377,12 @@ static void parmtest(char *buf)
 
    if (getparam_string("Require",buf,Require,sizeof(Require))>0) return;
 
-   if (getparam_quoted("download_suffix",buf,DownloadSuffix,sizeof(DownloadSuffix))>0) return;
+   if (is_param("download_suffix",buf)) {
+      char warea[MAXLEN];
+
+      getparam_quoted("download_suffix",buf,warea,sizeof(warea));
+      set_download_suffix(warea);
+   }
 
    if (getparam_string("graphs",buf,Graphs,sizeof(Graphs))>0) return;
 
index 4f158e098e44f99d41da538bb9198a2b28c9d79a..d60edee8d9427ebd8b27b2810facd9ba46ec5466 100755 (executable)
@@ -280,7 +280,6 @@ char AuthUserFile[255];
 char AuthName[512];
 char AuthType[255];
 char Require[512];
-char DownloadSuffix[MAXLEN];
 char *userfile;
 char *str;
 char *str2;
index 1bc7f604ceb5c4a4ae90565790850207169c7a9e..7bebcf2ef2589781ae1dc61027f216e0a62672e1 100755 (executable)
@@ -38,6 +38,9 @@ void gen_denied_report(void);
 
 // download.c
 void download_report(void);
+void free_download(void);
+void set_download_suffix(const char *list);
+int is_download_suffix(const char *url);
 
 // email.c
 int geramail(const char *dirname, int debug, const char *outdir, int userip, const char *email, const char *TempDir);
@@ -156,7 +159,7 @@ char *buildtime(long long int elap);
 void obtdate(const char *dirname, const char *name, char *data);
 void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst);
 void obtuser(const char *dirname, const char *name, char *tuser);
-void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, char *media);
+void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media);
 void version(void);
 int vercode(const char *code);
 void load_excludecodes(const char *ExcludeCodes);
@@ -175,4 +178,3 @@ char *get_param_value(const char *param,char *line);
 void read_usertab(const char *UserTabFile);
 void get_usertab_name(const char *user,char *name,int namelen);
 int compar( const void *, const void * );
-int is_download_suffix(const char *url);
index c26ef74f2ea23dcd966629dfe4160ca838d56f29..e302479f53a27ecd9a41ffb7dbaa436fe828d572 100755 (executable)
@@ -1,3 +1,3 @@
-#define VERSION PACKAGE_VERSION" Dec-18-2009"
+#define VERSION PACKAGE_VERSION" Dec-20-2009"
 #define PGM PACKAGE_NAME
 #define URL "http://sarg.sourceforge.net"
diff --git a/log.c b/log.c
index a7a1002b4eb5ded83f7b3067e946d6a14ed50a77..033acd83feb454e7460da546f2674c21e692c1cb 100644 (file)
--- a/log.c
+++ b/log.c
@@ -215,7 +215,7 @@ int main(int argc,char *argv[])
    strcpy(AuthName,"SARG, Restricted Access");
    strcpy(AuthType,"basic");
    strcpy(Require,"require user admin %u");
-   strcpy(DownloadSuffix,"7z,ace,arj,avi,bat,bin,bz2,bzip,cab,com,cpio,dll,doc,dot,exe,gz,iso,lha,lzh,mdb,mov,mp3,mpeg,mpg,mso,nrg,ogg,ppt,rar,rtf,shs,src,sys,tar,tgz,vcd,vob,wma,wmv,zip");
+   set_download_suffix("7z,ace,arj,avi,bat,bin,bz2,bzip,cab,com,cpio,dll,doc,dot,exe,gz,iso,lha,lzh,mdb,mov,mp3,mpeg,mpg,mso,nrg,ogg,ppt,rar,rtf,shs,src,sys,tar,tgz,vcd,vob,wma,wmv,zip");
    strcpy(Graphs,"yes");
    strcpy(Ulimit,"20000");
    strcpy(NtlmUserFormat,"domainname+username");
@@ -1471,6 +1471,7 @@ int main(int argc,char *argv[])
             free(excludefile);
          if(excludeuser)
             free(excludeuser);
+         free_download();
          unlink(tmp4);
          unlink(tmp6);
          unlink(tmp3);
@@ -1493,6 +1494,7 @@ int main(int argc,char *argv[])
          free(excludefile);
       if(excludeuser)
          free(excludeuser);
+      free_download();
       exit(0);
    }
 
@@ -1597,6 +1599,7 @@ int main(int argc,char *argv[])
       free(excludefile);
    if(excludeuser)
       free(excludeuser);
+   free_download();
 
    if(debug)
       debuga("%s",text[21]);
index bc61665cd240b7c68ed1f5136842ff1ad1dae367..4cf2dae46f39f92e67d12e46e17b84c6cf7bf8e0 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -36,8 +36,6 @@ void report_day(const char *user)
    char data[20];
    char odata[20];
    char hour[20];
-   char elap[20];
-   char oelap[20];
    char html[8000];
    char arqout[MAXLEN];
    char wdirname[MAXLEN];
@@ -45,6 +43,7 @@ void report_day(const char *user)
    char c[ 24 ][20];
    int  count=0;
    int  ihour=0;
+   long long int elap;
    long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
                             0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
    long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
@@ -136,14 +135,12 @@ void report_day(const char *user)
          count++;
       }
 
-      if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(elap,sizeof(elap),&gwarea,'\t')<0) {
+      if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword_atoll(&elap,&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
          exit(1);
       }
 
       if(strcmp(data,odata) != 0) {
-         strcpy(oelap,elap);
-
          for( i = 0; i < hours.len; i++ )
             sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
 
@@ -159,15 +156,14 @@ void report_day(const char *user)
          tt=0;
          for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
          strcpy(odata,data);
-         strcpy(elap,oelap);
       }
 
       ihour=atoi(hour);
 
-      v[ ihour ]+=my_atoll(elap);
-      tt+=my_atoll(elap);
-      t[ ihour ]+=my_atoll(elap);
-      ttt+=my_atoll(elap);
+      v[ ihour ]+=elap;
+      tt+=elap;
+      t[ ihour ]+=elap;
+      ttt+=elap;
 
    }
 
index f5e7d17d64423a267e8300b117035f5fc02eb26c..79e42dc9bb4aafc85e0d13b3da4c4d1064b439e5 100644 (file)
--- a/report.c
+++ b/report.c
@@ -28,9 +28,9 @@
 
 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, const char *elap, const char *accbytes, 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);
 static void gravatmpf(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
-static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, const char *tam, const char *elap, int indexonly);
+static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly);
 static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache);
 static void grava_SmartFilter(const char *dirname, const char *user, const char *ip, const char *data, const char *hora, const char *url, const char *smart);
 
@@ -40,10 +40,10 @@ void gerarel(void)
    FILE *fp_in;
    FILE *fp_gen;
 
-   char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN], accbytes[12], accelap[10];
+   char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN];
    char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN], wdir[MAXLEN], per1[MAXLEN];
    char wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN];
-   char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldaccelap[10], oldacccode[MAXLEN/2 - 1], user[MAXLEN];
+   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];
@@ -54,6 +54,7 @@ void gerarel(void)
    long long int rtotal=0;
    long long int incache=0;
    long long int oucache=0;
+   long long int accbytes, accelap;
    char *str;
    DIR *dirp;
    struct dirent *direntp;
@@ -135,13 +136,13 @@ 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(accbytes,sizeof(accbytes),&gwarea,'\t')<0 ||
+             getword(accurl,sizeof(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.\n",tmp3);
             exit(1);
          }
          if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue;
-         if (getword(accelap,sizeof(accelap),&gwarea,'\t')<0 || getword_skip(20000,&gwarea,'\t')<0 ||
+         if (getword_atoll(&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);
@@ -172,7 +173,6 @@ void gerarel(void)
          if(!rtotal){
             strcpy(oldurl,accurl);
             strcpy(oldacccode,acccode);
-            strcpy(oldaccelap,accelap);
             strcpy(oldaccuser,accuser);
             strcpy(oldaccip,accip);
             strcpy(oldaccdia,accdia);
@@ -210,8 +210,8 @@ void gerarel(void)
             }
          }
          nacc++;
-         nbytes+=my_atoll(accbytes);
-         nelap+=my_atoll(accelap);
+         nbytes+=accbytes;
+         nelap+=accelap;
 
          if(strstr(ReportType,"site_user_time_date") != 0) {
             if(!ttopen) {
@@ -286,8 +286,8 @@ void gerarel(void)
          if (str) *str='\0';
 
          if(strstr(crc2,"MISS") != 0)
-            oucache+=my_atoll(accbytes);
-         else incache+=my_atoll(accbytes);
+            oucache+=accbytes;
+         else incache+=accbytes;
 
          strcpy(oldurl,accurl);
 
@@ -298,7 +298,6 @@ void gerarel(void)
 
          strcpy(oldaccuser,accuser);
          strcpy(oldacccode,acccode);
-         strcpy(oldaccelap,accelap);
          strcpy(oldaccip,accip);
          strcpy(oldaccdia,accdia);
          strcpy(oldacchora,acchora);
@@ -481,7 +480,7 @@ void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, lo
 }
 
 
-static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, const char *elap, const char *bytes, 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 bytes, int indexonly)
 {
 
    FILE *fp_ou;
@@ -499,8 +498,8 @@ static void gravatmp_hora(const char *dirname, const char *user, const char *dat
       exit(1);
    }
 
-   if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%s\n",data,hora,bytes);
-   else fprintf(fp_ou,"%s\t%s\t%s\n",data,hora,elap);
+   if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes);
+   else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap);
 
    fclose(fp_ou);
 
@@ -508,7 +507,7 @@ static void gravatmp_hora(const char *dirname, const char *user, const char *dat
 }
 
 
-static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, const char *tam, const char *elap, int indexonly)
+static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly)
 {
 
    FILE *fp_ou;
@@ -526,7 +525,7 @@ static void gravaporuser(const char *user, const char *dirname, const char *url,
       exit(1);
    }
 
-   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",ip,url,data,hora,tam,elap);
+   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap);
 
    fclose(fp_ou);
 
index 6afde003e05d5ffacc2a5615a0aed1a4ab6d8ca2..be36d9a3452224a7944d8d8abb2fd19f0383e3f9 100644 (file)
@@ -35,9 +35,6 @@ void siteuser(void)
    char url[MAXLEN];
    char wuser[MAXLEN];
    char ourl[MAXLEN];
-   char nacc[20];
-   char nbytes[20];
-   char obytes[20];
    char csort[255];
    char general[MAXLEN];
    char general2[MAXLEN];
@@ -48,7 +45,9 @@ void siteuser(void)
    int regs=0;
    int ucount=0;
    char *users;
-   long long int llbytes=0;
+   long long int nbytes;
+   long long int obytes;
+   long long int nacc;
    int cstatus;
    struct getwordstruct gwarea;
 
@@ -120,7 +119,7 @@ void siteuser(void)
 
    user[0]='\0';
    ourl[0]='\0';
-   obytes[0]='\0';
+   obytes=0;
 
    if((users=(char *) malloc(204800))==NULL){
       fprintf(stderr, "SARG: ERROR: %s",text[87]);
@@ -160,12 +159,12 @@ void siteuser(void)
          ip2name(user,sizeof(user));
       */
 
-      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0){
+      if (getword_atoll(&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),&gwarea,'\t')<0){
+      if (nacc > 0) nsitesusers = 1;
+      if (getword_atoll(&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);
       }
@@ -176,7 +175,7 @@ void siteuser(void)
 
       if(!regs) {
          strcpy(ourl,url);
-         strcpy(obytes,nbytes);
+         obytes=nbytes;
          regs++;
       }
 
@@ -202,8 +201,7 @@ void siteuser(void)
 
       if(strcmp(url,ourl) != 0 && nsitesusers) {
          if(strncmp(strlow(BytesInSitesUsersReport),"yes",3) == 0) {
-            llbytes=my_atoll(obytes);
-            sprintf(wwork2,"%s",fixnum(llbytes,1));
+            sprintf(wwork2,"%s",fixnum(obytes,1));
             fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data\">%s</td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,wwork2,users);
          } else
             fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,users);
@@ -212,7 +210,7 @@ void siteuser(void)
          strcpy(users,name);
          strcat(users," ");
          strcpy(ourl,url);
-         strcpy(obytes,nbytes);
+         obytes=nbytes;
       }
    }
 
index f9c6739b682161ee0eeb90d1e6a30ba9dd0dbe42..36a76f4acbf436e808c101aff81910d036ec0798 100644 (file)
@@ -33,9 +33,6 @@ void topsites(void)
 
    char url[MAXLEN];
    char ourl[MAXLEN];
-   char nacc[20];
-   char nbytes[20];
-   char ntime[20];
    char ntemp[255];
    char ttnacc[20];
    char ttnbytes[20];
@@ -50,6 +47,9 @@ void topsites(void)
    char period[100];
    char sortf[10];
    char sortt[10];
+   long long int nacc;
+   long long int nbytes;
+   long long int ntime;
    long long int tnacc=0;
    long long int tnbytes=0;
    long long int tntime=0;
@@ -123,11 +123,11 @@ void topsites(void)
          }
          continue;
       }
-      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&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);
       }
@@ -147,7 +147,7 @@ void topsites(void)
          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),&gwarea,'\t')<0) {
+      if (getword_atoll(&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);
       }
@@ -168,9 +168,9 @@ void topsites(void)
          tntime=0;
       }
 
-      tnacc+=my_atoll(nacc);
-      tnbytes+=my_atoll(nbytes);
-      tntime+=my_atoll(ntime);
+      tnacc+=nacc;
+      tnbytes+=nbytes;
+      tntime+=ntime;
    }
 
    my_lltoa(tnacc,val1,15);
@@ -249,20 +249,20 @@ void topsites(void)
       if(regs>atoi(TopSitesNum))
          break;
       getword_start(&gwarea,buf);
-      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0 ||
-          getword(ntime,sizeof(ntime),&gwarea,'\t')<0 || getword(url,sizeof(url),&gwarea,'\t')<0) {
+      if (nacc == 0) continue;
+      if (getword_atoll(&nbytes,&gwarea,'\t')<0 ||
+          getword_atoll(&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);
       }
 
-      twork1=my_atoll(nacc);
-      twork2=my_atoll(nbytes);
-      twork3=my_atoll(ntime);
+      twork1=nacc;
+      twork2=nbytes;
+      twork3=ntime;
 
       strcpy(wwork1,fixnum(twork1,1));
       strcpy(wwork2,fixnum(twork2,1));
index be3b7179c23996610260667050c8c4e0f467d424..bf6478737d81e788bcc32c4c7fad01715f3947df 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -35,14 +35,17 @@ void topuser(void)
    long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0;
    long long int twork;
    long long int twork2;
+   long long int nbytes;
+   long long int nacc;
+   long long int elap, incac, oucac;
    float perc=0.00;
    float perc2=0.00;
    float inperc=0.00, ouperc=0.00;
    int posicao=0;
    char olduser[MAXLEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN];
    char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN];
-   char user[MAXLEN], nacc[20], nbytes[20], preg[MAXLEN], tusr[MAXLEN];
-   char ip[MAXLEN], time[30], date[30], elap[30], incac[30], oucac[30];
+   char user[MAXLEN], preg[MAXLEN], tusr[MAXLEN];
+   char ip[MAXLEN], time[30], date[30];
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char sfield[10]="2,2";
    char order[255]="-r";
@@ -99,11 +102,11 @@ void topuser(void)
       if(strcmp(user,"TOTAL") == 0) {
          continue;
       }
-      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
          exit(1);
       }
@@ -123,15 +126,15 @@ void topuser(void)
          printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&oucac,&gwarea,'\n')<0) {
          printf("SARG: Maybe you have a broken not in cache download in your %s file.\n",wger);
          exit(1);
       }
@@ -160,11 +163,11 @@ void topuser(void)
          tnoucache=0;
       }
 
-      tnbytes+=my_atoll(nbytes);
-      tnacc+=my_atoll(nacc);
-      tnelap+=my_atoll(elap);
-      tnincache+=my_atoll(incac);
-      tnoucache+=my_atoll(oucac);
+      tnbytes+=nbytes;
+      tnacc+=nacc;
+      tnelap+=elap;
+      tnincache+=incac;
+      tnoucache+=oucac;
    }
 
    if (olduser[0] != '\0') {
@@ -373,51 +376,51 @@ void topuser(void)
          printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
          exit(1);
       }
-      if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&oucac,&gwarea,'\n')<0) {
          printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",wger);
          exit(1);
       }
-      if(atoi(nacc) < 1) {
+      if(nacc < 1) {
          continue;
       }
       ntopuser = 1;
       if(TopUsersNum > 0 && topcount >= TopUsersNum) goto final;
       strcpy(user2,user);
-      tnbytes=my_atoll(nbytes);
+      tnbytes=nbytes;
 
       if(tnbytes) {
          perc=tnbytes * 100;
          perc=perc / ttnbytes;
       } else perc = 0;
 
-      if(atol(elap)) {
-         perc2=atol(elap);
+      if(elap) {
+         perc2=elap;
          perc2=((perc2 * 100) / ttnelap);
       } else perc2 = 0;
 
-      if(atol(incac)) {
-         inperc=atol(incac);
+      if(incac) {
+         inperc=incac;
          inperc=((inperc * 100) / tnbytes);
       } else inperc = 0;
 
-      if(atol(oucac)) {
-         ouperc=atol(oucac);
+      if(oucac) {
+         ouperc=oucac;
          ouperc=((ouperc * 100) / tnbytes);
       } else ouperc = 0;
 
@@ -443,7 +446,7 @@ void topuser(void)
          strcpy(href3end,"");
       }
 
-      tnelap=my_atoll(elap);
+      tnelap=elap;
 
       if(userip) {
          fixip(user2);
@@ -479,9 +482,7 @@ void topuser(void)
          name[0]='\0';
       }
 
-      twork=my_atoll(nacc);
-      my_lltoa(twork,nacc,0);
-      strcpy(wwork1,fixnum(twork,1));
+      strcpy(wwork1,fixnum(nacc,1));
       strcpy(wwork2,fixnum(tnbytes,1));
       strcpy(wwork3,fixnum2(tnelap,1));
 
@@ -564,14 +565,14 @@ void topuser(void)
 
       if(strstr(user,"TOTAL") != 0) {
 
-         if(atol(incac)) {
+         if(incac) {
             inperc=ttnbytes / 100;
-            inperc=atol(incac) / inperc;
+            inperc=incac / inperc;
          } else inperc = 0;
 
-         if(atol(oucac)) {
+         if(oucac) {
             ouperc=ttnbytes / 100;
-            ouperc=atol(oucac) / ouperc;
+            ouperc=oucac / ouperc;
          } else ouperc = 0;
 
          sprintf(wwork1,"%s",fixnum(ttnacc,1));
index 132407283a2689b33cb3be458f47eeac3693ac15..5bd886d2468e9199611b9217b1091f5c6170dfb5 100644 (file)
--- a/totger.c
+++ b/totger.c
@@ -33,9 +33,11 @@ int totalger(const char *dirname, int debug, const char *outdir)
    long long int tnbytes=0;
    long long int telap=0;
    long long int tincache=0, toucache=0;
-   char wger[MAXLEN], user[MAXLEN], nacc[16], nbytes[16], url[MAXLEN];
-   char ip[MAXLEN], hora[9], data[15], elap[16];
-   char incac[30], oucac[30];
+   long long int nacc, nbytes;
+   long long int elap;
+   long long int incac, oucac;
+   char wger[MAXLEN], user[MAXLEN], url[MAXLEN];
+   char ip[MAXLEN], hora[9], data[15];
    char warea[MAXLEN];
    struct getwordstruct gwarea;
 
@@ -55,11 +57,11 @@ int totalger(const char *dirname, int debug, const char *outdir)
          printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
          exit(1);
       }
@@ -79,23 +81,23 @@ int totalger(const char *dirname, int debug, const char *outdir)
          printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
          exit(1);
       }
-      if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,'\t')<0) {
+      if (getword_atoll(&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),&gwarea,0)<0) {
+      if (getword_atoll(&oucac,&gwarea,'\n')<0) {
          printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",wger);
          exit(1);
       }
-      tnacc+=my_atoll(nacc);
-      tnbytes+=my_atoll(nbytes);
-      telap+=my_atoll(elap);
-      tincache+=my_atoll(incac);
-      toucache+=my_atoll(oucac);
+      tnacc+=nacc;
+      tnbytes+=nbytes;
+      telap+=elap;
+      tincache+=incac;
+      toucache+=oucac;
    }
 
    fclose(fp_in);
diff --git a/util.c b/util.c
index a7feedcff2b90d2c3a0016b49fca2a44ba93ce84..f48754ce1213ff2e19fd1ff0022190c1817ded41 100644 (file)
--- a/util.c
+++ b/util.c
@@ -256,30 +256,6 @@ void my_lltoa(unsigned long long int n, char s[], int len)
       for(j=0 ; j<i ; j++)
          s[j]='0';
    }
-
-#if 0 //old code
-   do {
-      s[slen++] = (n % 10) + '0';
-   } while ((n /= 10) > 0);
-   s[slen] = '\0';
-
-   for (i = 0, j = slen-1; i<j; i++, j--)
-   {
-      c = s[i];
-      s[i] = s[j];
-      s[j] = c;
-   }
-
-   if(len) {
-      i=len-strlen(s)-1;
-      for(x=0; x<=i; x++)
-         ww[x]='0';
-      ww[x]='\0';
-      i=strlen(s);
-      strncat(ww,s,i>sizeof(ww)?sizeof(ww):i);
-      strcpy(s,ww);
-   }
-#endif
 }
 
 
@@ -692,12 +668,12 @@ void obtuser(const char *dirname, const char *name, char *tuser)
 }
 
 
-void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, char *media)
+void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media)
 {
-
    FILE *fp_in;
    char buf[MAXLEN];
    char wdir[MAXLEN];
+   char warea[MAXLEN];
    long long int med=0;
    long long int wtuser=0;
    long long int twork;
@@ -707,7 +683,8 @@ void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser,
    if ((fp_in = fopen(wdir, "r")) == 0) {
       sprintf(wdir,"%s%s/general",dirname,name);
       if ((fp_in = fopen(wdir, "r")) == 0) {
-         tbytes=0;
+         tbytes[0]='\0';
+         media[0]='\0';
          return;
       }
    }
@@ -724,12 +701,12 @@ void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser,
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir);
          exit(1);
       }
-      if (getword(warea,sizeof(warea),&gwarea,'\t')<0) {
+      if (getword_atoll(&twork,&gwarea,'\t')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir);
          exit(1);
       }
-      twork=my_atoll(warea);
       strcpy(tbytes,fixnum(twork,1));
+      break;
    }
    fclose(fp_in);
 
@@ -739,11 +716,10 @@ void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser,
       return;
    }
 
-   med=my_atoll(warea) / wtuser;
+   med=twork / wtuser;
    strcpy(media,fixnum(med,1));
 
    return;
-
 }
 
 
@@ -1606,31 +1582,3 @@ void get_usertab_name(const char *user,char *name,int namelen)
       }
    }
 }
-
-int is_download_suffix(const char *url)
-{
-   int urllen;
-   int i;
-   char suffix[10];
-   const char *str;
-   int suflen;
-
-   if(DownloadSuffix[0]==0) return(0);
-
-   urllen=strlen(url)-1;
-   for (i=0 ; i<sizeof(suffix)-1 && i<urllen ; i++) {
-      if (url[urllen-i]=='.') {
-         if (i==0) return(0); //detect a single trailing dot
-         strcpy(suffix,url+urllen-i+1);
-         suflen=strlen(suffix);
-         for (str=DownloadSuffix ; str ; str=strchr(str,',')) {
-            if (*str==',') str++;
-            if(strncasecmp(str,suffix,suflen)==0 && (str[suflen]==',' || str[suflen]==0))
-               return(1);
-         }
-         return(0);
-      }
-   }
-   return(0);
-}
-