"Fossies" - the Fresh Open Source Software Archive 
Member "sarg-2.4.0/repday.c" (24 Dec 2019, 8743 Bytes) of package /linux/privat/sarg-2.4.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "repday.c" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.3.11_vs_2.4.0.
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2015
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
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"
28 #include "include/defs.h"
29
30 extern int hours[24];
31
32 void report_day(const struct userinfostruct *uinfo)
33 {
34 FILE *fp_in, *fp_ou;
35
36 char buf[200];
37 char data[20];
38 long long int hour;
39 const char *label;
40 char arqout[MAXLEN];
41 char wdirname[2048];
42 char colsep;
43 int ihour=0;
44 int day,month,year;
45 int daylist[MAX_DATETIME_DAYS];
46 int daysort[MAX_DATETIME_DAYS];
47 int ndaylist;
48 int daynum;
49 int dayidx;
50 long long int bytes;
51 long long int elap;
52 long long int tbytes[MAX_DATETIME_DAYS*24];
53 long long int telap[MAX_DATETIME_DAYS*24];
54 long long int tt;
55 long long int tttime[24];
56 int i, j;
57 struct getwordstruct gwarea;
58 struct tm t;
59
60 if (datetimeby==0) return;
61 format_path(__FILE__, __LINE__, wdirname, sizeof(wdirname), "%s/%s.day", tmp, uinfo->filename);
62 if (access(wdirname, R_OK) != 0) return;
63
64 if (snprintf(arqout,sizeof(arqout),"%s/%s/d%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqout)) {
65 debuga(__FILE__,__LINE__,_("Path too long: "));
66 debuga_more("%s/%s/d%s.html\n",outdirname,uinfo->filename,uinfo->filename);
67 exit(EXIT_FAILURE);
68 }
69
70 if ((fp_in=fopen(wdirname,"r"))==NULL) {
71 debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wdirname,strerror(errno));
72 exit(EXIT_FAILURE);
73 }
74
75 memset(tbytes,0,sizeof(tbytes));
76 memset(telap,0,sizeof(telap));
77 ndaylist=0;
78
79 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
80 fixendofline(buf);
81 getword_start(&gwarea,buf);
82 if (getword(data,sizeof(data),&gwarea,'\t')<0) {
83 debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),wdirname);
84 exit(EXIT_FAILURE);
85 }
86 if (sscanf(data,"%d/%d/%d",&day,&month,&year)!=3) continue;
87 if (day<1 || day>31 || month<1 || month>12 || year>9999) continue;
88 daynum=(year*10000)+(month*100)+day;
89 for (dayidx=0 ; dayidx<ndaylist && daynum!=daylist[dayidx] ; dayidx++);
90 if (dayidx>=ndaylist) {
91 if (dayidx>=sizeof(daylist)/sizeof(*daylist)) {
92 debuga(__FILE__,__LINE__,_("Too many different dates in file \"%s\"\n"),wdirname);
93 exit(EXIT_FAILURE);
94 }
95 daylist[ndaylist++]=daynum;
96 }
97
98 if (getword_atoll(&hour,&gwarea,'\t')<0) {
99 debuga(__FILE__,__LINE__,_("Invalid time in file \"%s\"\n"),wdirname);
100 exit(EXIT_FAILURE);
101 }
102 ihour=(int)hour;
103 i=dayidx*24+ihour;
104
105 if ((datetimeby & DATETIME_BYTE)!=0) {
106 colsep=((datetimeby & DATETIME_ELAP)!=0) ? '\t' : '\0';
107 if (getword_atoll(&bytes,&gwarea,colsep)<0) {
108 debuga(__FILE__,__LINE__,_("Invalid number of bytes in file \"%s\"\n"),wdirname);
109 exit(EXIT_FAILURE);
110 }
111 tbytes[i]+=bytes;
112 }
113 if ((datetimeby & DATETIME_ELAP)!=0) {
114 if (getword_atoll(&elap,&gwarea,'\0')<0) {
115 debuga(__FILE__,__LINE__,_("Invalid elapsed time in file \"%s\"\n"),wdirname);
116 exit(EXIT_FAILURE);
117 }
118 telap[i]+=elap;
119 }
120 }
121 if (fclose(fp_in)==EOF) {
122 debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wdirname,strerror(errno));
123 exit(EXIT_FAILURE);
124 }
125
126 if ((fp_ou=fopen(arqout,"w"))==NULL) {
127 debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),arqout,strerror(errno));
128 exit(EXIT_FAILURE);
129 }
130
131 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Day report"),HTML_JS_NONE);
132 fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s: %s</td></tr>\n",_("Period"),period.html);
133 fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s: %s</th></tr>\n",_("User"),uinfo->label);
134 close_html_header(fp_ou);
135
136 dayidx=0;
137 for (i=0 ; i<ndaylist ; i++) {
138 daynum=daylist[i];
139 for (j=dayidx ; j>0 && daynum<daylist[daysort[j-1]] ; j--) daysort[j]=daysort[j-1];
140 daysort[j]=i;
141 dayidx++;
142 }
143
144 if ((datetimeby & DATETIME_BYTE)!=0) {
145 label=_("BYTES");
146 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
147 fputs("<tr><th class=\"header_c\"></th>",fp_ou);
148 for (i=0 ; i<24 ; i++)
149 {
150 if (hours[i])
151 {
152 /* TRANSLATORS: It is an hour in the hourly report */
153 sprintf(data,_("%02dH"),i);
154 fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td>\n", data, label );
155 }
156 }
157 fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), label );
158
159 memset(tttime,0,sizeof(tttime));
160 for (dayidx=0 ; dayidx<ndaylist ; dayidx++) {
161 daynum=daysort[dayidx];
162 day=daylist[daynum]%100;
163 month=(daylist[daynum]/100)%100;
164 year=daylist[daynum]/10000;
165 computedate(year,month,day,&t);
166 strftime(data,sizeof(data),"%x",&t);
167 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data );
168 tt=0;
169 for (i=0 ; i<24 ; i++)
170 {
171 if (!hours[i]) continue;
172 ihour=i;
173 if (tbytes[daynum*24+ihour]>0)
174 {
175 fprintf(fp_ou, "<td class=\"data\">%s</td>\n",fixnum(tbytes[daynum*24+ihour],1));
176 tt+=tbytes[daynum*24+ihour];
177 tttime[ihour]+=tbytes[daynum*24+ihour];
178 }
179 else
180 fputs("<td class=\"data\"></td>\n",fp_ou);
181 }
182 fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n",fixnum(tt,1));
183 }
184
185 fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
186 tt=0;
187 for (i=0 ; i<24 ; i++)
188 {
189 if (!hours[i]) continue;
190 if (tttime[i]>0)
191 {
192 fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n",fixnum(tttime[i],1));
193 tt+=tttime[i];
194 }
195 else
196 fputs("<td class=\"header_r\"></td>\n",fp_ou);
197 }
198 fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n",fixnum(tt,1));
199 fputs("</table>\n",fp_ou);
200 #ifdef ENABLE_DOUBLE_CHECK_DATA
201 if (tt!=uinfo->nbytes) {
202 debuga(__FILE__,__LINE__,_("Total downloaded bytes is %"PRIi64" instead of %"PRIi64" in the hourly report of user %s\n"),
203 (int64_t)tt,(int64_t)uinfo->nbytes,uinfo->label);
204 exit(EXIT_FAILURE);
205 }
206 #endif
207 }
208
209 if ((datetimeby & DATETIME_ELAP)!=0) {
210 label=_("H:M:S");
211 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
212 fputs("<tr><th class=\"header_c\"></th>",fp_ou);
213 for (i=0 ; i<24 ; i++)
214 {
215 if (hours[i])
216 {
217 sprintf(data,_("%02dH"),i);
218 fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td>\n", data, label );
219 }
220 }
221 fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), label );
222
223 memset(tttime,0,sizeof(tttime));
224 for (dayidx=0 ; dayidx<ndaylist ; dayidx++) {
225 daynum=daysort[dayidx];
226 day=daylist[daynum]%100;
227 month=(daylist[daynum]/100)%100;
228 year=daylist[daynum]/10000;
229 computedate(year,month,day,&t);
230 strftime(data,sizeof(data),"%x",&t);
231 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data );
232 tt=0;
233 for (i=0 ; i<24 ; i++)
234 {
235 if (!hours[i]) continue;
236 ihour=i;
237 if (telap[daynum*24+ihour]>0) {
238 fprintf(fp_ou, "<td class=\"data\">%s</td>\n",fixtime(telap[daynum*24+ihour]));
239 tt+=telap[daynum*24+ihour];
240 tttime[ihour]+=telap[daynum*24+ihour];
241 } else
242 fputs("<td class=\"data\"></td>\n",fp_ou);
243 }
244 fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n",fixtime(tt));
245 }
246
247 fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
248 tt=0;
249 for (i=0 ; i<24 ; i++)
250 {
251 if (!hours[i]) continue;
252 if (tttime[i]>0)
253 {
254 fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n",fixtime(tttime[i]));
255 tt+=tttime[i];
256 }
257 else
258 fputs("<td class=\"header_r\"></td>\n",fp_ou);
259 }
260 fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n",fixtime(tt));
261 fputs("</table>\n",fp_ou);
262 #ifdef ENABLE_DOUBLE_CHECK_DATA
263 if (tt!=uinfo->elap) {
264 debuga(__FILE__,__LINE__,_("Total elapsed time is %"PRIi64" instead of %"PRIi64" in the hourly report of user %s\n"),
265 (int64_t)tt,(int64_t)uinfo->elap,uinfo->label);
266 exit(EXIT_FAILURE);
267 }
268 #endif
269 }
270
271 write_html_trailer(fp_ou);
272 if (fclose(fp_ou)==EOF) {
273 debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),arqout,strerror(errno));
274 exit(EXIT_FAILURE);
275 }
276 return;
277 }