]> git.ipfire.org Git - thirdparty/sarg.git/blame - totday.c
Ignore comments in exclude_code file
[thirdparty/sarg.git] / totday.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
1164c474 3 * 1998, 2010
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27#include "include/conf.h"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
f2ec8c75 30void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int indexonly)
25697a35
GS
31{
32
33 FILE *fp_in, *fp_ou;
120d768c 34
06b39c87 35 char buf[200];
25697a35
GS
36 char data[20];
37 char hora[20];
38 char min[20];
39 char elap[20];
40 char odata[20];
41 char ohora[20];
42 char oelap[20];
25697a35
GS
43 char csort[255];
44 char wdirname[MAXLEN];
45 char sortout[MAXLEN];
46 char arqout[MAXLEN];
47 int regs=0;
48 long long int telap=0;
456d78a5 49 int cstatus;
9c7c6346 50 struct getwordstruct gwarea;
25697a35
GS
51
52 if(indexonly) return;
085c1e1f 53 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
25697a35 54
f2ec8c75
FM
55 sprintf(wdirname,"%s/%s.htmp",tmp,uinfo->filename);
56 sprintf(arqout,"%s/%s.day",tmp,uinfo->filename);
57 sprintf(sortout,"%s/%s.sort",tmp,uinfo->filename);
25697a35 58
9a2efbd0 59 sprintf(csort,"sort -k 1,1 -k 2,2 -o \"%s\" \"%s\"",sortout,wdirname);
456d78a5
FM
60 cstatus=system(csort);
61 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
10210234
FM
62 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
63 debuga(_("sort command: %s\n"),csort);
06b39c87 64 exit(EXIT_FAILURE);
456d78a5 65 }
25697a35 66 if((fp_in=fopen(sortout,"r"))==NULL) {
fcdc0918 67 debuga(_("(totday) Cannot open log file %s\n"),sortout);
10210234 68 debuga(_("sort command: %s\n"),csort);
06b39c87 69 exit(EXIT_FAILURE);
25697a35
GS
70 }
71
456d78a5
FM
72 unlink(wdirname);
73
25697a35 74 if((fp_ou=fopen(arqout,"w"))==NULL) {
fcdc0918 75 debuga(_("(totday) Cannot open log file %s\n"),arqout);
06b39c87 76 exit(EXIT_FAILURE);
25697a35
GS
77 }
78
79 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
9c7c6346
FM
80 fixendofline(buf);
81 getword_start(&gwarea,buf);
82 if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,':')<0 ||
085af286 83 getword(min,sizeof(min),&gwarea,':')<0 || getword_skip(20,&gwarea,'\t')<0 ||
9c7c6346 84 getword(elap,sizeof(elap),&gwarea,0)<0) {
10210234 85 debuga(_("There is a broken record or garbage in file %s\n"),sortout);
06b39c87 86 exit(EXIT_FAILURE);
4bcb77cf 87 }
25697a35
GS
88
89 if(!regs) {
90 strcpy(odata,data);
91 strcpy(ohora,hora);
92 strcpy(oelap,elap);
25697a35
GS
93 regs++;
94 }
95
d6e703cc 96 if(strcmp(hora,ohora) != 0 || strcmp(data,odata) != 0) {
e5b2c6f0 97 fprintf(fp_ou,"%s\t%s\t%015lld\n",odata,ohora,telap);
25697a35
GS
98 strcpy(odata,data);
99 strcpy(ohora,hora);
25697a35 100 telap=0;
25697a35
GS
101 }
102
103 telap+=my_atoll(elap);
25697a35
GS
104 }
105
e5b2c6f0 106 fprintf(fp_ou,"%s\t%s\t%015lld\n",data,hora,telap);
25697a35
GS
107
108 fclose(fp_in);
109 fclose(fp_ou);
110
111 unlink(sortout);
112
113 return;
114
115}