char user[MAX_USER_LEN];
char data[255];
char ip[60];
- char tam[255];
char hora[30];
char mes[30];
char tbuf2[128];
long int totregsl=0;
long int totregsg=0;
long int totregsx=0;
- long int nbytes;
- long int elap_time;
long long int iyear, imonth, iday;
FILE *fp_in=NULL;
FILE *fp_log=NULL;
if((str=(char *) strchr(data, '.')) != (char *) NULL && (str=(char *) strchr(str+1, '.')) != (char *) NULL ) {
strcpy(ip,data);
log_entry.Ip=ip;
- strcpy(elap,"0");
if(squid24) {
if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) {
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
exit(EXIT_FAILURE);
}
- if (getword(tam,sizeof(tam),&gwarea,' ')<0) {
+ if (getword_atoll(&log_entry.DataSize,&gwarea,' ')<0) {
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
exit(EXIT_FAILURE);
}
if ((str = strchr(code, ':')) != NULL)
*str = '/';
- if(strcmp(tam,"\0") == 0)
- strcpy(tam,"0");
-
ilf=ILF_Common;
ilf_count[ilf]++;
exit(EXIT_FAILURE);
}
if(strlen(elap) < 1) continue;
+ log_entry.ElapsedTime=atol(elap);
if (getword(ip,sizeof(ip),&gwarea,' ')<0){
debuga(_("Maybe you have a broken client IP address in your %s file\n"),arq);
exit(EXIT_FAILURE);
debuga(_("Maybe you have a broken result code in your %s file\n"),arq);
exit(EXIT_FAILURE);
}
- if (getword(tam,sizeof(tam),&gwarea,' ')<0){
+ if (getword_atoll(&log_entry.DataSize,&gwarea,' ')<0){
debuga(_("Maybe you have a broken amount of data in your %s file\n"),arq);
exit(EXIT_FAILURE);
}
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
exit(EXIT_FAILURE);
}
- if (getword(tam,sizeof(tam),&gwarea,'\t')<0){
+ if (getword_atoll(&log_entry.DataSize,&gwarea,'\t')<0){
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
exit(EXIT_FAILURE);
}
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
exit(EXIT_FAILURE);
}
- if (getword(elap,sizeof(elap),&gwarea,'\t')<0){
+ if (getword_atol(&log_entry.ElapsedTime,&gwarea,'\t')<0){
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
exit(EXIT_FAILURE);
}
}
strcpy(hora,str);
} else if (x==isa_cols[ISACOL_TimeTaken]) {
- if (strlen(str)>=sizeof(elap)) {
- debuga(_("Maybe you have a broken download duration in your %s file\n"),arq);
- exit(EXIT_FAILURE);
- }
- strcpy(elap,str);
+ log_entry.ElapsedTime=atol(str);
} else if (x==isa_cols[ISACOL_Bytes]) {
- if (strlen(str)>=sizeof(tam)) {
- debuga(_("Maybe you have a broken download size in your %s file\n"),arq);
- exit(EXIT_FAILURE);
- }
- strcpy(tam,str);
+ log_entry.DataSize=atoll(str);
} else if (x==isa_cols[ISACOL_Uri]) {
full_url=str;
} else if (x==isa_cols[ISACOL_Status]) {
strcmp(log_entry.User,"") ==0 || strcmp(log_entry.User,":") ==0)
continue;
- nbytes=atol(tam);
- if (nbytes<0) nbytes=0;
+ if (log_entry.DataSize<0) log_entry.DataSize=0;
- elap_time=atol(elap);
- if (elap_time<0) elap_time=0;
- if (Filter->max_elapsed>0 && elap_time>Filter->max_elapsed) {
- elap_time=0;
+ if (log_entry.ElapsedTime<0) log_entry.ElapsedTime=0;
+ if (Filter->max_elapsed>0 && log_entry.ElapsedTime>Filter->max_elapsed) {
+ log_entry.ElapsedTime=0;
}
if((str=(char *) strstr(linebuf, "[SmartFilter:")) != (char *) NULL ) {
}
}
#ifdef ENABLE_DOUBLE_CHECK_DATA
- ufile->user->nbytes+=nbytes;
- ufile->user->elap+=elap_time;
+ ufile->user->nbytes+=log_entry.DataSize;
+ ufile->user->elap+=log_entry.ElapsedTime;
#endif
if (ufile->file==NULL) {
strftime(dia, sizeof(dia), "%d/%m/%Y", log_entry.EntryTime);
strftime(hora,sizeof(hora),"%H:%M:%S",log_entry.EntryTime);
- if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,log_entry.Ip,url,nbytes,code,elap_time,smartfilter)<=0) {
+ if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,log_entry.Ip,url,(uint64_t)log_entry.DataSize,code,log_entry.ElapsedTime,smartfilter)<=0) {
debuga(_("Write error in the log file of user %s\n"),log_entry.User);
exit(EXIT_FAILURE);
}
if(fp_log && ilf!=ILF_Sarg)
- fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,log_entry.User,log_entry.Ip,url,nbytes,code,elap_time,smartfilter);
+ fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,log_entry.User,log_entry.Ip,url,(uint64_t)log_entry.DataSize,code,log_entry.ElapsedTime,smartfilter);
totregsg++;
if(debugm){
printf("IP=\t%s\n",log_entry.Ip);
printf("USER=\t%s\n",log_entry.User);
- printf("ELAP=\t%ld\n",elap_time);
+ printf("ELAP=\t%ld\n",log_entry.ElapsedTime);
printf("DATE=\t%s\n",dia);
printf("TIME=\t%s\n",hora);
printf("FUNC=\t%s\n",fun);
printf("URL=\t%s\n",url);
printf("CODE=\t%s\n",code);
- printf("LEN=\t%ld\n",nbytes);
+ printf("LEN=\t%"PRIu64"\n",(uint64_t)log_entry.DataSize);
}
}
return(0);
}
+int getword_atol(long int *number, struct getwordstruct *gwarea, char stop)
+{
+ long int x;
+ long int sign=+1;
+ int digit;
+
+ if (gwarea->current[0] == '-') {
+ gwarea->current++;
+ sign=-1;
+ } else if (gwarea->current[0] == '+') {
+ gwarea->current++;
+ }
+ *number=0;
+ for(x=0;isdigit(gwarea->current[x]);x++) {
+ digit=gwarea->current[x]-'0';
+ if (*number > (LONG_MAX-digit)/10) {
+ debuga(_("Integer overflow detected in getword_atol in line %s\n"),gwarea->beginning);
+ return(-1);
+ }
+ *number=(*number * 10) + digit;
+ }
+ if(gwarea->current[x] && gwarea->current[x]!=stop) {
+ printf("SARG: getword_atol loop detected after %ld 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");
+#if USE_GETWORD_BACKTRACE
+ getword_backtrace();
+#endif
+ return(-1);
+ }
+ *number*=sign;
+
+ if (gwarea->current[x]) ++x;
+ gwarea->current+=x;
+ return(0);
+}
+
+int getword_atolu(unsigned long int *number, struct getwordstruct *gwarea, char stop)
+{
+ unsigned long int x;
+ int digit;
+
+ if (gwarea->current[0] == '-') {
+ printf("SARG: getword_atolu got a negative number.\n");
+ printf("SARG: Line=\"%s\"\n",gwarea->beginning);
+ printf("SARG: Record=\"%s\"\n",gwarea->current);
+ return(-1);
+ }
+ if (gwarea->current[0] == '+') {
+ gwarea->current++;
+ }
+ *number=0;
+ for(x=0;isdigit(gwarea->current[x]);x++) {
+ digit=gwarea->current[x]-'0';
+ if (*number > (ULONG_MAX-digit)/10) {
+ debuga(_("Integer overflow detected in getword_atolu in line %s\n"),gwarea->beginning);
+ return(-1);
+ }
+ *number=(*number * 10) + digit;
+ }
+ if(gwarea->current[x] && gwarea->current[x]!=stop) {
+ printf("SARG: getword_atolu loop detected after %ld 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");
+#if USE_GETWORD_BACKTRACE
+ getword_backtrace();
+#endif
+ return(-1);
+ }
+
+ if (gwarea->current[x]) ++x;
+ gwarea->current+=x;
+ return(0);
+}
+
int getword_ptr(char *orig_line,char **word, struct getwordstruct *gwarea, char stop)
{