]> git.ipfire.org Git - thirdparty/sarg.git/blob - totday.c
Imported sarg 2.0.9
[thirdparty/sarg.git] / totday.c
1 /*
2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
3 * 1998, 2005
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
23 *
24 */
25
26 #include "include/conf.h"
27
28 void totaliza_day(const char *tmp, char *user, int indexonly)
29 {
30
31 FILE *fp_in, *fp_ou;
32
33 char data[20];
34 char hora[20];
35 char min[20];
36 char elap[20];
37 char odata[20];
38 char ohora[20];
39 char oelap[20];
40 char hm[20];
41 char ohm[20];
42 char csort[255];
43 char wdirname[MAXLEN];
44 char sortout[MAXLEN];
45 char arqout[MAXLEN];
46 int regs=0;
47 long long int telap=0;
48 long long int tused=0;
49
50 if(indexonly) return;
51 if(strstr(ReportType,"users_sites") == 0) return;
52
53 sprintf(wdirname,"%s/%s.htmp",tmp,user);
54 sprintf(arqout,"%s/%s.day",tmp,user);
55 sprintf(sortout,"%s/%s.sort",tmp,user);
56
57 sprintf(csort,"sort -k 1,1 -k 2,2 -o '%s' '%s'",sortout,wdirname);
58 system(csort);
59
60 unlink(wdirname);
61
62 if((fp_in=fopen(sortout,"r"))==NULL) {
63 fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],sortout);
64 exit(1);
65 }
66
67 if((fp_ou=fopen(arqout,"w"))==NULL) {
68 fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],arqout);
69 exit(1);
70 }
71
72 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
73 if(strstr(buf,"\n") != 0)
74 buf[strlen(buf)-1]='\0';
75
76 getword(data,buf,' ');
77 getword(hora,buf,':');
78 getword(min,buf,':');
79 getword(elap,buf,' ');
80 strcpy(elap,buf);
81 sprintf(hm,"%s%s",hora,min);
82
83 if(!regs) {
84 strcpy(odata,data);
85 strcpy(ohora,hora);
86 strcpy(oelap,elap);
87 strcpy(ohm,hm);
88 regs++;
89 }
90
91 if(strcmp(hora,ohora) != 0) {
92 if(tused > telap)
93 tused=telap;
94
95 my_lltoa(telap,val1,15);
96 sprintf(buf,"%s %s %s\n",odata,ohora,val1);
97 fputs(buf, fp_ou);
98 strcpy(odata,data);
99 strcpy(ohora,hora);
100 strcpy(ohm,hm);
101 telap=0;
102 tused=0;
103 }
104
105 if(strcmp(ohm,hm) != 0) {
106 tused+=60000;
107 strcpy(ohm,hm);
108 }
109
110 telap+=my_atoll(elap);
111
112 }
113
114 if(tused > telap)
115 tused=telap;
116
117 my_lltoa(telap,val1,15);
118 sprintf(buf,"%s %s %s\n",data,hora,val1);
119 fputs(buf, fp_ou);
120
121 fclose(fp_in);
122 fclose(fp_ou);
123
124 unlink(sortout);
125
126 return;
127
128 }