Some small optimizations.
SET_TARGET_PROPERTIES(sarg PROPERTIES VERSION "${sarg_VERSION}.${sarg_REVISION}.${sarg_BUILD}")
-SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
+SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "$ENV{CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
+SET_TARGET_PROPERTIES(sarg PROPERTIES LINK_FLAGS "$ENV{LDFLAGS}")
+
CHECK_C_COMPILER_FLAG("-Werror=implicit-function-declaration" HAVE_WERROR_IMPLICIT_FUNCTION)
IF(HAVE_WERROR_IMPLICIT_FUNCTION)
GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
int cstatus;
struct getwordstruct gwarea;
- if(strlen(DataFile) > 0) return;
+ if(DataFile[0] != '\0') return;
ouser[0]='\0';
if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){
strcpy(oldmsg,"OK");
if(strstr(oldacccode,"DENIED") != 0) strcpy(oldmsg,text[46]);
- strcpy(wdirname,dirname);
- gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+ gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
strcpy(wdirname,dirname);
saverecs(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
nacc=0;
*/
+/*! \fn static int isparam_string(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.
+\param buf The string read from the input file.
+
+\retval 1 Parameter match.
+\retval 0 The line is not for that parameter.
+*/
+
+
+
+
/*! \fn static int getparam_string(const char *param,char *buf,char *value,int value_size)
Extract a string value from a line if it it the right parameter.
+
+/*! \fn int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop)
+Extract one number from the text line.
+
+\param number Where the store the extracted number.
+\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 -1 The stop character was not found after the number.
+*/
+
+
+
+
/*! \fn long long int my_atoll (const char *nptr)
Convert a string into a long long.
extern numlist hours, weekdays;
+static int isparam_string(const char *param,const char *buf)
+{
+ int plen;
+
+ plen=strlen(param);
+ if (strncmp(buf,param,plen) != 0) return(0);
+ buf+=plen;
+ if ((unsigned char)*buf>' ') return(0);
+ return(1);
+}
+
static int getparam_string(const char *param,char *buf,char *value,int value_size)
{
int plen;
if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
- if (getparam_string("access_log",buf,AccessLog,sizeof(AccessLog))>0) return;
+ if (isparam_string("access_log",buf)>0) {
+ if (AccessLogFromCmdLine==0) {
+ if (NAccessLog>=MAXLOGS) {
+ fprintf(stderr,"SARG: Too many log files.\n");
+ exit(1);
+ }
+ getparam_string("access_log",buf,AccessLog[NAccessLog],MAXLEN);
+ NAccessLog++;
+ }
+ return;
+ }
if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return;
long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0;
long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0, twork2=0;
+ long long int ltemp;
+ long long int ntotuser;
+ long long int userbytes, userelap;
char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
- char nacc[20], nbytes[20], url[MAXLEN], tmsg[50], nelap[20], csort[MAXLEN];
+ char url[MAXLEN], tmsg[50], csort[MAXLEN];
char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
- char userbytes[20], userelap[20], userurl[1024], userhora[9], userdia[9];
- char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN], incac[20], oucac[20];
+ char userurl[1024], userhora[9], userdia[9];
+ char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
char denied_report[255], name2[MAXLEN];
//char ttd1[3], ttd2[3], ttd3[5], ttt1[3], ttt2[3], ttt3[3];
char *str;
char warea[MAXLEN];
- char wtemp[MAXLEN], totuser[8];
+ char totuser[8];
long long int tnacc=0, ttnacc=0, unacc=0;
float perc=0, perc2=0, ouperc=0, inperc=0;
char *s;
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
if(strstr(buf,"TOTAL") == 0) {
getword_start(&gwarea,buf);
- if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
+ if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(<emp,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
exit(1);
}
- ttnacc+=my_atoll(gwarea.current);
- if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+ ttnacc+=ltemp;
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
exit(1);
}
- totbytes+=my_atoll(wtemp);
+ totbytes+=ltemp;
if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
- getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
+ getword_atoll(<emp,&gwarea,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqper,__LINE__);
exit(1);
}
- totelap+=my_atoll(wtemp);
+ totelap+=ltemp;
}
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
getword_start(&gwarea,buf);
- if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
- tnacc+=my_atoll(wtemp);
- if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+ tnacc+=ltemp;
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
- tnbytes+=my_atoll(wtemp);
+ tnbytes+=ltemp;
if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
- getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+ getword_atoll(<emp,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
- tnelap+=my_atoll(wtemp);
- if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
+ tnelap+=ltemp;
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
- tnincache+=my_atoll(wtemp);
- if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+ tnincache+=ltemp;
+ if (getword_atoll(<emp,&gwarea,'\n')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqin,__LINE__);
exit(1);
}
- tnoucache+=my_atoll(wtemp);
+ tnoucache+=ltemp;
}
rewind(fp_in);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
getword_start(&gwarea,buf);
- if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
+ 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);
}
- if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
+ if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
exit(1);
}
printf("SARG: Maybe you have a broken status in your %s file.\n",arqin);
exit(1);
}
- if (getword(nelap,sizeof(nelap),&gwarea,'\t')<0) {
+ if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
exit(1);
}
- if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
+ if (getword_atoll(&incache,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin);
exit(1);
}
- if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",arqin);
+ if (getword_atoll(&oucache,&gwarea,'\n')<0) {
+ printf("SARG: Maybe you have a broken not in cache column in your %s file (%d).\n",arqin,__LINE__);
exit(1);
}
sprintf(tmsg,"<td class=\"data\">%s</td>",text[46]);
else bzero(tmsg, 50);
- nnbytes=my_atoll(nbytes);
- nnelap=my_atoll(nelap);
- incache=my_atoll(incac);
- oucache=my_atoll(oucac);
-
if(nnbytes) {
perc=nnbytes * 100;
perc=perc / tnbytes;
ouperc=ouperc / nnbytes;
} else ouperc=0;
- twork=my_atoll(nacc);
strcpy(wwork1,fixnum(twork,1));
strcpy(wwork2,fixnum(nnbytes,1));
strcpy(wwork3,fixnum2(nnelap,1));
printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3);
exit(1);
}
- if (getword(userbytes,sizeof(userbytes),&gwarea,'\t')<0) {
+ if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken size in your %s file.\n",tmp3);
exit(1);
}
- if (getword(userelap,sizeof(userelap),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",tmp3);
+ if (getword_atoll(&userelap,&gwarea,'\t')<0) {
+ printf("SARG: Maybe you have a broken elapsed time in your %s file (%d).\n",tmp3,__LINE__);
exit(1);
}
if(strcmp(user_ip,olduserip) != 0) {
unelap=0;
}
- unbytes=unbytes+my_atoll(userbytes);
- unelap=unelap+my_atoll(userelap);
+ unbytes=unbytes+userbytes;
+ unelap=unelap+userelap;
}
fclose(fp_ip);
exit(1);
}
- if (!fgets(totuser,8,fp_in)) {
+ if (!fgets(totuser,sizeof(totuser),fp_in)) {
fprintf(stderr,"SARG: (html11) read error in %s\n",arqper);
exit(1);
}
fclose(fp_in);
- totbytes2=totbytes/my_atoll(totuser);
- totelap2=totelap/my_atoll(totuser);
+ ntotuser=my_atoll(totuser);
+ if (ntotuser<=0) ntotuser=1;
+ totbytes2=totbytes/ntotuser;
+ totelap2=totelap/ntotuser;
if(totbytes2) {
perc = totbytes / 100;
perc2 = totelap2 / perc2;
} else perc2=0;
- twork2=my_atoll(totuser);
+ twork2=ntotuser;
twork=ttnacc/twork2;
strcpy(wwork1,fixnum(twork,1));
#endif /*__MINGW32__*/
#define MAXLEN 20000
+#define MAXLOGS 255
+
long long int my_atoll (const char *nptr);
FILE *fp_tt;
char Ip2Name[20];
char language[255];
char bufy[MAXLEN];
-char AccessLog[MAXLEN];
+int NAccessLog;
+char AccessLog[MAXLOGS][MAXLEN];
+int AccessLogFromCmdLine;
char Title[MAXLEN];
char BgColor[MAXLEN];
char BgImage[MAXLEN];
void report_day(const char *user);
// report.c
-void gravatmp(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);
+void gravatmp(const char *oldaccuser, 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);
void gerarel(void);
// siteuser.c
int getword(char *word, int limit, struct getwordstruct *gwarea, int stop);
int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop);
int getword_skip(int limit, struct getwordstruct *gwarea, int stop);
+int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop);
void name_month(char *month,int month_len);
void conv_month_name(char *month);
void buildymd(const char *dia, const char *mes, const char *ano, char *wdata);
char day[16], mon[16], year[40], hour[10];
char *str;
int cstatus;
- int iyear, imonth, iday, ihour, iminute, isecond;
+ int iyear, imonth, iday, ihour, iminute, isecond, idst;
char y1[5], y2[5];
char d1[3], d2[3];
char m1[4], m2[4];
struct getwordstruct gwarea;
- int iyear, imonth, iday, ihour, iminute, isecond, idst;
if(LastLog[0] != '\0') mklastlog(outdir);
char date[255];
char arq[255];
char arq_log[255];
- char warq[255][255];
char hm[15], hmf[15], hmr[15];
int chm=0;
char uagent[MAXLEN];
int fuser=0;
int idata=0;
int mindate=0;
- int narq=0;
int iarq=0;
int exstring=0;
int isa_ncols=0,isa_cols[ISACOL_Last];
ExternalCSSFile[0]='\0';
SquidGuardLogFormat[0]='\0';
SquidGuardLogAlternate[0]='\0';
- arq[0]='\0';
for (ilf=0 ; ilf<ILF_Last ; ilf++) ilf_count[ilf]=0;
- strcpy(AccessLog,"/var/log/squid/access.log");
sprintf(ExcludeCodes,"%s/exclude_codes",SYSCONFDIR);
strcpy(GraphDaysBytesBarColor,"orange");
strcpy(BgColor,"#ffffff");
setlocale(LC_TIME,"");
#endif
- for(x=0; x<=254; x++)
- warq[x][0]='\0';
+ NAccessLog=0;
+ for(x=0; x<=MAXLOGS; x++)
+ AccessLog[x][0]='\0';
+ AccessLogFromCmdLine=0;
language_load(language);
strcpy(Title,text[88]);
iprel++;
break;
case 'l':
- if (narq>=sizeof(warq)/sizeof(warq[0])) {
+ if (NAccessLog>=MAXLOGS) {
printf("SARG: Too many log files.\n");
exit(1);
}
- strcpy(warq[narq],optarg);
- narq++;
+ strcpy(AccessLog[NAccessLog],optarg);
+ NAccessLog++;
+ AccessLogFromCmdLine++;
break;
case 'L':
strcpy(SquidGuardLogAlternate,optarg);
subs(UserReportFields,sizeof(UserReportFields),"%BYTES","SETYB");
- if(!narq) {
- strcpy(warq[0],AccessLog);
- narq++;
+ if(!NAccessLog) {
+ strcpy(AccessLog[0],"/var/log/squid/access.log");
+ NAccessLog++;
}
if(strcmp(hexclude,"onvert") == 0 && strcmp(site,"plit") != 0) {
- convlog(warq[0], df, dfrom, duntil);
+ convlog(AccessLog[0], df, dfrom, duntil);
exit(0);
}
if(strcmp(site,"plit") == 0) {
- splitlog(warq[0], df, dfrom, duntil, hexclude);
+ splitlog(AccessLog[0], df, dfrom, duntil, hexclude);
exit(0);
}
if(strlen(outdir)<1) strcpy(outdir,OutputDir);
strcat(outdir,"/");
-
- if(arq[0] == '\0') strcpy(arq,AccessLog);
-
if(uagent[0] == '\0') strcpy(uagent,UserAgentLog);
if(tmp[0] == '\0') strcpy(tmp,TempDir);
fprintf(stderr, "SARG: %35s (-g) = %s (yyyy/ww)\n",text[25],text[85]);
if(iprel)
fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[1]);
- else
+ else
fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[2]);
- fprintf(stderr, "SARG: %35s (-l) = %s\n",text[37],arq);
+ for (iarq=0 ; iarq<NAccessLog ; iarq++)
+ fprintf(stderr, "SARG: %35s (-l) = %s\n",text[37],AccessLog[iarq]);
if(strcmp(Ip2Name,"yes") == 0)
fprintf(stderr, "SARG: %35s (-n) = %s\n",text[65],text[1]);
else
printf("%35s (-g) = %s (yyyy/ww)\n",text[25],text[85]);
if(iprel)
printf("%35s (-i) = %s\n",text[28],text[1]);
- else
+ else
printf("%35s (-i) = %s\n",text[28],text[2]);
- printf("%35s (-l) = %s\n",text[37],arq);
+ for (iarq=0 ; iarq<NAccessLog ; iarq++)
+ printf("%35s (-l) = %s\n",text[37],AccessLog[iarq]);
if(strcmp(Ip2Name,"yes") == 0)
printf("%35s (-n) = %s\n",text[65],text[1]);
else
}
}
- while(narq--) {
- strcpy(arq,warq[iarq]);
- iarq++;
+ for (iarq=0 ; iarq<NAccessLog ; iarq++) {
+ strcpy(arq,AccessLog[iarq]);
strcpy(arqtt,arq);
exit(1);
}
- sprintf(cmd,"tail -%d %s",realtime_access_log_lines,AccessLog);
+ sprintf(cmd,"tail -%d %s",realtime_access_log_lines,AccessLog[0]);
fp = popen(cmd, "r");
while(fgets(buf,sizeof(buf),fp) != NULL )
if (getdata(buf,tmp)<0) {
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 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 gravager(char *dirname, 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 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);
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 oldaccdia[11], oldacchora[9], oldaccip[MAXLEN], wdir[MAXLEN], per1[MAXLEN];
char ipantes[MAXLEN], nameantes[MAXLEN];
char accsmart[MAXLEN];
char crc2[MAXLEN/2 -1];
+ char dirname[MAXLEN];
long long int nbytes=0;
long long int nelap=0;
long long int nacc=0;
if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent();
+ sprintf(wdirname,"%s/sarg-general",dirname);
+ if((fp_gen=MY_FOPEN(wdirname,"a"))==NULL){
+ fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
+ exit(1);
+ }
+
olduser[0]='\0';
strncat(tmp,"/sarg",5);
strcpy(oldmsg,"OK");
if(strstr(oldacccode,"DENIED") != 0)
sprintf(oldmsg,"%s",text[46]);
- gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
- gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+ gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+ gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
nacc=0;
nbytes=0;
nelap=0;
strcpy(oldmsg,"OK");
if(strstr(oldacccode,"DENIED") != 0)
sprintf(oldmsg,"%s",text[46]);
- strcpy(wdirname,dirname);
- gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
- strcpy(wdirname,dirname);
- gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+ gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+ gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
nacc=0;
nbytes=0;
nelap=0;
strcpy(oldaccuser,accuser);
gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
strcpy(wdirname,dirname);
- gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
- strcpy(wdirname,dirname);
+ gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+ fclose(fp_gen);
day_totalize(tmp,oldaccuser,indexonly);
tmpsort();
}
-void gravatmp(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)
+void gravatmp(const char *oldaccuser, 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)
{
FILE *fp_ou;
char val3[16];
char val4[16];
char val5[16];
-
char wdirname[MAXLEN];
if(indexonly) return;
if(strstr(ReportType,"users_sites") == 0) return;
- strcpy(wdirname,tmp);
- strcat(wdirname,"/");
- strcat(wdirname,oldaccuser);
- strcat(wdirname,".utmp");
+ if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) {
+ fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser);
+ exit(1);
+ }
if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
exit(1);
}
- my_lltoa(nacc,val1,15);
- my_lltoa(nbytes,val2,15);
- my_lltoa(nelap,val3,15);
- my_lltoa(incache,val4,15);
- my_lltoa(oucache,val5,15);
+ 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);
fclose(fp_ou);
if(indexonly || (strstr(ReportType,"users_sites") == 0)) return;
- strcpy(wdirname,tmp);
- strcat(wdirname,"/");
- strcat(wdirname,user);
- strcat(wdirname,".htmp");
+ if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) {
+ fprintf(stderr,"SARG: Path too long %s/%s.htmp\n",tmp,user);
+ exit(1);
+ }
if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno));
{
FILE *fp_ou;
-
char wdirname[MAXLEN];
if(indexonly || (strstr(ReportType,"users_sites") == 0)) return;
- strcpy(wdirname,tmp);
- strcat(wdirname,"/");
- strcat(wdirname,user);
- strcat(wdirname,".ip");
+ if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,user)>=sizeof(wdirname)) {
+ fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,user);
+ exit(1);
+ }
if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
{
FILE *fp_ou;
-
char wdirname[MAXLEN];
if(indexonly || (strstr(ReportType,"users_sites") == 0)) return;
- strcpy(wdirname,tmp);
- strcat(wdirname,"/");
- strcat(wdirname,oldaccuser);
- strcat(wdirname,".utmp");
+ if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) {
+ fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser);
+ exit(1);
+ }
if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
exit(1);
}
- my_lltoa(nacc,val1,15);
- my_lltoa(nbytes,val2,15);
- my_lltoa(nelap,val3,15);
- my_lltoa(incache,val4,15);
- my_lltoa(oucache,val5,15);
+ 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);
fclose(fp_ou);
}
-static void gravager(char *dirname, 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 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)
{
-
- FILE *fp_ou;
-
- strcat(dirname,"/");
- strcat(dirname,"sarg-general");
-
- if((fp_ou=MY_FOPEN(dirname,"a"))==NULL){
- fprintf(stderr, "SARG: (report) %s: %s\n",text[45],dirname);
- exit(1);
- }
-
- my_lltoa(nacc,val1,15);
- my_lltoa(nbytes,val2,15);
- my_lltoa(nelap,val3,15);
- my_lltoa(incache,val4,15);
- my_lltoa(oucache,val5,15);
- fprintf(fp_ou,"%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);
-
- fclose(fp_ou);
+ 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);
return;
}
{
FILE *fp_ou;
-
char wdirname[MAXLEN];
sprintf(wdirname,"%s/smartfilter.unsort",dirname);
if (dlen>0) {
if (dlen>=sizeof(wnome)) continue;
strncpy(wnome,direntp->d_name,dlen);
- wnome[dlen]=0;
+ wnome[dlen]='\0';
} else {
wnome[0]='\0';
}
return(0);
}
-
-#ifdef LEGACY_MY_ATOLL
-
-// BMG (bguillory@email.com)
-// 3 August 1999
-long long int my_atoll (const char *nptr)
-#define MAXLLL 30 //maximum number of digits in long long (a guess)
+int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop)
{
- int offset=0, x;
- long long int returnval=0;
- char one_digit[2];
-
- one_digit[1]='\0';
-
- // Soak up all the white space
- while (isspace(nptr[offset])) {
- offset++;
- } //while
-
- //For each character left to right
- //change the character to a single digit
- //multiply what we had before by 10 and add the new digit
- for(x=offset; x<=MAXLLL+offset && isdigit(nptr[x]); x++) {
- sprintf(one_digit, "%c", nptr[x]); //I don't know how else to do this
- returnval = (returnval * 10) + atoi(one_digit);
- } //for
+ int x;
- return returnval;
+ *number=0LL;
+ for(x=0;isdigit(gwarea->current[x]);x++) {
+ *number=(*number * 10) + gwarea->current[x]-'0';
+ }
+ if(gwarea->current[x] && gwarea->current[x]!=stop) {
+ printf("SARG: getword_atoll loop detected after %d bytes.\n",x);
+ printf("SARG: Line=\"%s\"\n",gwarea->beginning);
+ printf("SARG: Record=\"%s\"\n",gwarea->current);
+ printf("SARG: searching for \'x%x\'\n",stop);
+ //printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
+ return(-1);
+ }
-} //my_atoll
+ if (gwarea->current[x]) ++x;
+ gwarea->current+=x;
+ return(0);
+}
-#else
#define MAXLLL 30 //!< Maximum number of digits in long long (a guess).
long long int my_atoll (const char *nptr)
{
- long long int returnval=0;
- const char * t = nptr ;
+ long long int returnval=0LL;
int max_digits = MAXLLL ;
// Soak up all the white space
- while (isspace( *t )) {
- t++;
- } //while
+ while (isspace( *nptr )) {
+ nptr++;
+ }
//For each character left to right
//change the character to a single digit
//multiply what we had before by 10 and add the new digit
- for( ; --max_digits && isdigit( *t ) ; t++ )
+ while (--max_digits && isdigit( *nptr ))
{
- returnval = ( returnval * 10 ) + ( *t - '0' ) ;
+ returnval = ( returnval * 10 ) + ( *nptr++ - '0' ) ;
}
return returnval;
-
-} //my_atoll
-
-#endif
+}
static int is_absolute(const char *path)
{
void my_lltoa(unsigned long long int n, char s[], int len)
{
- int i = 0;
- int x = 0;
- char ww[50];
- do {
- s[i++] = (n % 10) + '0';
- } while ((n /= 10) > 0);
- s[i] = '\0';
- {
- int c,i,j;
- for (i = 0, j = strlen(s)-1; i<j; i++, j--)
- {
- c = s[i];
- s[i] = s[j];
- s[j] = c;
- }
- }
+ int i;
+ int slen = 0;
+ int j;
+ char c;
- if(len) {
- bzero(ww,sizeof(ww));
- i=len-strlen(s)-1;
- for(x=0; x<=i; x++)
- ww[x]='0';
- i=strlen(s);
- strncat(ww,s,i>sizeof(ww)?sizeof(ww):i);
- strcpy(s,ww);
- }
+ 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>slen) {
+ i=len-slen;
+ for(j=slen; j>=0; j--)
+ s[j+i]=s[j];
+ 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
}
char wdirname[MAXLEN];
strcpy(wdirname,dirname);
- strcat(wdirname,"/");
- strcat(wdirname,"sarg-period");
+ strcat(wdirname,"/sarg-period");
if((fp_ou=fopen(wdirname,"w"))==NULL){
fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);