]>
git.ipfire.org Git - thirdparty/sarg.git/blob - totday.c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
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.
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.
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.
27 #include "include/conf.h"
28 #include "include/defs.h"
30 void day_totalize(const char *tmp
, const struct userinfostruct
*uinfo
, int indexonly
)
44 char wdirname
[MAXLEN
];
48 long long int telap
=0;
50 struct getwordstruct gwarea
;
53 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
55 if (snprintf(wdirname
,sizeof(wdirname
),"%s/%s.htmp",tmp
,uinfo
->filename
)>=sizeof(wdirname
)) {
56 debuga(_("File name too long: %s/%s.htmp\n"),tmp
,uinfo
->filename
);
59 if (snprintf(arqout
,sizeof(arqout
),"%s/%s.day",tmp
,uinfo
->filename
)>=sizeof(arqout
)) {
60 debuga(_("File name too long: %s/%s.day\n"),tmp
,uinfo
->filename
);
63 if (snprintf(sortout
,sizeof(sortout
),"%s/%s.sort",tmp
,uinfo
->filename
)>=sizeof(sortout
)) {
64 debuga(_("File name too long: %s/%s.sort\n"),tmp
,uinfo
->filename
);
68 sprintf(csort
,"sort -k 1,1 -k 2,2 -o \"%s\" \"%s\"",sortout
,wdirname
);
69 cstatus
=system(csort
);
70 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
71 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
72 debuga(_("sort command: %s\n"),csort
);
75 if((fp_in
=fopen(sortout
,"r"))==NULL
) {
76 debuga(_("(totday) Cannot open log file %s\n"),sortout
);
77 debuga(_("sort command: %s\n"),csort
);
83 if((fp_ou
=fopen(arqout
,"w"))==NULL
) {
84 debuga(_("(totday) Cannot open log file %s\n"),arqout
);
88 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
90 getword_start(&gwarea
,buf
);
91 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0 || getword(hora
,sizeof(hora
),&gwarea
,':')<0 ||
92 getword(min
,sizeof(min
),&gwarea
,':')<0 || getword_skip(20,&gwarea
,'\t')<0 ||
93 getword(elap
,sizeof(elap
),&gwarea
,0)<0) {
94 debuga(_("There is a broken record or garbage in file %s\n"),sortout
);
105 if(strcmp(hora
,ohora
) != 0 || strcmp(data
,odata
) != 0) {
106 fprintf(fp_ou
,"%s\t%s\t%015lld\n",odata
,ohora
,telap
);
112 telap
+=my_atoll(elap
);
115 fprintf(fp_ou
,"%s\t%s\t%015lld\n",data
,hora
,telap
);
118 if (fclose(fp_ou
)==EOF
) {
119 debuga(_("Failed to close file %s - %s\n"),arqout
,strerror(errno
));