]> git.ipfire.org Git - thirdparty/sarg.git/blob - totger.c
Fixed bug #1847374
[thirdparty/sarg.git] / totger.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
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 #include "include/defs.h"
28
29 int totalger(const char *dirname, int debug, const char *outdir)
30 {
31 FILE *fp_in, *fp_ou;
32 long long int tnacc=0;
33 long long int tnbytes=0;
34 long long int telap=0;
35 long long int tincache=0, toucache=0;
36 char wger[MAXLEN], user[MAXLEN], nacc[16], nbytes[16], url[MAXLEN];
37 char ip[MAXLEN], hora[9], data[11], elap[16];
38 char incac[16], oucac[16];
39 char warea[MAXLEN];
40
41 strcpy(wger,dirname);
42 strcat(wger,"/sarg-general");
43
44 if((fp_in=fopen(wger,"r"))==NULL) {
45 fprintf(stderr, "SARG: (totger) %s: %s\n",text[45],wger);
46 exit(1);
47 }
48
49 while(fgets(warea,sizeof(warea),fp_in))
50 {
51 //printf("%s\n",warea);
52 if (getword(user,sizeof(user),warea,' ')<0) {
53 printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
54 exit(1);
55 }
56 if (getword(nacc,sizeof(nacc),warea,' ')<0) {
57 printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger);
58 exit(1);
59 }
60 if (getword(nbytes,sizeof(nbytes),warea,' ')<0) {
61 printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
62 exit(1);
63 }
64 if (getword(url,sizeof(url),warea,' ')<0) {
65 printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
66 exit(1);
67 }
68 if (getword(ip,sizeof(ip),warea,' ')<0) {
69 printf("SARG: Maybe you have a broken source IP address in your %s file.\n",wger);
70 exit(1);
71 }
72 if (getword(hora,sizeof(hora),warea,' ')<0) {
73 printf("SARG: Maybe you have a broken time in your %s file.\n",wger);
74 exit(1);
75 }
76 if (getword(data,sizeof(data),warea,' ')<0) {
77 printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
78 exit(1);
79 }
80 if (getword(elap,sizeof(elap),warea,' ')<0) {
81 printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",wger);
82 exit(1);
83 }
84 if (getword(incac,sizeof(incac),warea,' ')<0) {
85 printf("SARG: Maybe you have a broken in cache column in your %s file.\n",wger);
86 exit(1);
87 }
88 if (getword(oucac,sizeof(oucac),warea,0)<0) {
89 printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",wger);
90 exit(1);
91 }
92 tnacc+=my_atoll(nacc);
93 tnbytes+=my_atoll(nbytes);
94 telap+=my_atoll(elap);
95 tincache+=my_atoll(incac);
96 toucache+=my_atoll(oucac);
97 }
98
99 fclose(fp_in);
100
101 strcpy(wger,dirname);
102 strcat(wger,"/sarg-general");
103
104 if((fp_ou=fopen(wger,"a"))==NULL) {
105 fprintf(stderr, "SARG: (totger) %s: %s\n",text[45],wger);
106 exit(1);
107 }
108
109 url[0]='\0';
110
111 my_lltoa(tnacc,val1,15);
112 my_lltoa(tnbytes,val2,15);
113 my_lltoa(telap,val3,15);
114 my_lltoa(tincache,val4,15);
115 my_lltoa(toucache,val5,15);
116 fprintf(fp_ou,"TOTAL %s %s %s %s %s\n",val1,val2,val3,val4,val5);
117 fclose(fp_ou);
118
119 return (0);
120 }