From a873169bef07aa8c49f01bc39da89e248735b6b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Mon, 26 Jul 2010 14:38:42 +0000 Subject: [PATCH] Don't save the unnecessary columns in the intermediary file that is sorted to produce the report with the IP addresses from which the user connected to the internet. It should reduce the required amount of free disk space to run sarg. --- html.c | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/html.c b/html.c index 1d90b0d..ac108f5 100644 --- a/html.c +++ b/html.c @@ -49,6 +49,7 @@ void htmlrel(void) char warea[MAXLEN]; char totuser[8]; char tmp6[MAXLEN]; + char *user_url; long long int tnacc=0, ttnacc=0, unacc=0; double perc=0, perc2=0, ouperc=0, inperc=0; int count; @@ -368,16 +369,40 @@ void htmlrel(void) exit(EXIT_FAILURE); } while((buf=longline_read(fp_ip,line1))!=NULL) { - if(strstr(buf,url) != 0) { - fprintf(fp_ip2,"%s\n",buf); + getword_start(&gwarea,buf); + if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) { + debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3); + exit(EXIT_FAILURE); + } + if (getword_ptr(buf,&user_url,&gwarea,'\t')<0) { + debuga(_("Maybe you have a broken url in your %s file\n"),tmp3); + exit(EXIT_FAILURE); + } + if (strncmp(user_url,url,strlen(url))!=0) continue; + if (getword_skip(15,&gwarea,'\t')<0) { + debuga(_("Maybe you have a broken day in your %s file\n"),tmp3); + exit(EXIT_FAILURE); + } + if (getword_skip(15,&gwarea,'\t')<0) { + debuga(_("Maybe you have a broken time in your %s file\n"),tmp3); + exit(EXIT_FAILURE); + } + if (getword_atoll(&userbytes,&gwarea,'\t')<0) { + debuga(_("Maybe you have a broken size in your %s file\n"),tmp3); + exit(EXIT_FAILURE); } + if (getword_atoll(&userelap,&gwarea,'\0')<0) { + debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3); + exit(EXIT_FAILURE); + } + fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\n",user_ip,(uint64_t)userbytes,(uint64_t)userelap); } longline_destroy(&line1); fclose(fp_ip); fclose(fp_ip2); - sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 5,5 -o \"%s\" \"%s\"",tmp,tmp3,tmp2); + sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); @@ -402,18 +427,6 @@ void htmlrel(void) debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3); exit(EXIT_FAILURE); } - if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken url in your %s file\n"),tmp3); - exit(EXIT_FAILURE); - } - if (getword_skip(15,&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken day in your %s file\n"),tmp3); - exit(EXIT_FAILURE); - } - if (getword_skip(15,&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken time in your %s file\n"),tmp3); - exit(EXIT_FAILURE); - } if (getword_atoll(&userbytes,&gwarea,'\t')<0) { debuga(_("Maybe you have a broken size in your %s file\n"),tmp3); exit(EXIT_FAILURE); -- 2.47.2