Added getword_atoll to extract a number without requiring an additionnal string buffer.
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)
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];
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';
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);
if(!rtotal){
strcpy(oldurl,accurl);
strcpy(oldacccode,acccode);
- strcpy(oldaccelap,accelap);
strcpy(oldaccuser,accuser);
strcpy(oldaccip,accip);
strcpy(oldaccdia,accdia);
}
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);
--- /dev/null
+/*!\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.
+*/
+
+
+
+
*/
-/*! \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.
-/*! \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.
-
-/*! \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.
#include "include/conf.h"
#include "include/defs.h"
+static char *DownloadSuffix=NULL;
+static char **DownloadSuffixIndex=NULL;
+static int NDownloadSuffix=0;
+
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);
+}
+
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;
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");
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;
char AuthName[512];
char AuthType[255];
char Require[512];
-char DownloadSuffix[MAXLEN];
char *userfile;
char *str;
char *str2;
// 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);
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);
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);
-#define VERSION PACKAGE_VERSION" Dec-18-2009"
+#define VERSION PACKAGE_VERSION" Dec-20-2009"
#define PGM PACKAGE_NAME
#define URL "http://sarg.sourceforge.net"
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");
free(excludefile);
if(excludeuser)
free(excludeuser);
+ free_download();
unlink(tmp4);
unlink(tmp6);
unlink(tmp3);
free(excludefile);
if(excludeuser)
free(excludeuser);
+ free_download();
exit(0);
}
free(excludefile);
if(excludeuser)
free(excludeuser);
+ free_download();
if(debug)
debuga("%s",text[21]);
char data[20];
char odata[20];
char hour[20];
- char elap[20];
- char oelap[20];
char html[8000];
char arqout[MAXLEN];
char wdirname[MAXLEN];
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,
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 ] ]));
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;
}
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);
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];
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;
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);
if(!rtotal){
strcpy(oldurl,accurl);
strcpy(oldacccode,acccode);
- strcpy(oldaccelap,accelap);
strcpy(oldaccuser,accuser);
strcpy(oldaccip,accip);
strcpy(oldaccdia,accdia);
}
}
nacc++;
- nbytes+=my_atoll(accbytes);
- nelap+=my_atoll(accelap);
+ nbytes+=accbytes;
+ nelap+=accelap;
if(strstr(ReportType,"site_user_time_date") != 0) {
if(!ttopen) {
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);
strcpy(oldaccuser,accuser);
strcpy(oldacccode,acccode);
- strcpy(oldaccelap,accelap);
strcpy(oldaccip,accip);
strcpy(oldaccdia,accdia);
strcpy(oldacchora,acchora);
}
-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;
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);
}
-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;
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);
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];
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;
user[0]='\0';
ourl[0]='\0';
- obytes[0]='\0';
+ obytes=0;
if((users=(char *) malloc(204800))==NULL){
fprintf(stderr, "SARG: ERROR: %s",text[87]);
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);
}
if(!regs) {
strcpy(ourl,url);
- strcpy(obytes,nbytes);
+ obytes=nbytes;
regs++;
}
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);
strcpy(users,name);
strcat(users," ");
strcpy(ourl,url);
- strcpy(obytes,nbytes);
+ obytes=nbytes;
}
}
char url[MAXLEN];
char ourl[MAXLEN];
- char nacc[20];
- char nbytes[20];
- char ntime[20];
char ntemp[255];
char ttnacc[20];
char ttnbytes[20];
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;
}
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);
}
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);
}
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);
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));
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";
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);
}
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);
}
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') {
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;
strcpy(href3end,"");
}
- tnelap=my_atoll(elap);
+ tnelap=elap;
if(userip) {
fixip(user2);
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));
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));
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;
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);
}
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);
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
}
}
-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;
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;
}
}
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);
return;
}
- med=my_atoll(warea) / wtuser;
+ med=twork / wtuser;
strcpy(media,fixnum(med,1));
return;
-
}
}
}
}
-
-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);
-}
-