]> git.ipfire.org Git - thirdparty/sarg.git/blob - decomp.c
Ported r225 from branches/v2_2_7 (remove Pedro Orso's mail from headers)
[thirdparty/sarg.git] / decomp.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
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 void decomp(char *arq, char *zip, const char *tmp)
31 {
32 char cmd[1024];
33 int cstatus;
34 int arqlen;
35
36 if(access(arq, R_OK) != 0) {
37 debuga("%s: %s",text[64],arq);
38 exit(1);
39 }
40
41 arqlen=strlen(arq);
42 if(arqlen>3 && strcmp(arq+arqlen-3,".gz") == 0) {
43 debuga("%s: %s > %s/sarg/sarg-file.in (zcat)",text[62],arq,tmp);
44 if (snprintf(cmd,sizeof(cmd),"zcat \"%s\" > \"%s/sarg/sarg-file.in\"",arq,tmp)>=sizeof(cmd)) {
45 fprintf(stderr,"SARG: decompression command too long for log file %s\n",arq);
46 exit(1);
47 }
48 cstatus=system(cmd);
49 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
50 fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
51 fprintf(stderr, "SARG: command: %s\n",cmd);
52 exit(1);
53 }
54 strcpy(zip,"zcat");
55 sprintf(arq,"%s/sarg/sarg-file.in",tmp);
56 return;
57 }
58
59 if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) {
60 debuga("%s: %s > %s/sarg/sarg-file.in (bzcat)",text[62],arq,tmp);
61 if (snprintf(cmd,sizeof(cmd),"bzcat \"%s\" > \"%s/sarg/sarg-file.in\"",arq,tmp)>=sizeof(cmd)) {
62 fprintf(stderr,"SARG: decompression command too long for log file %s\n",arq);
63 exit(1);
64 }
65 cstatus=system(cmd);
66 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
67 fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
68 fprintf(stderr, "SARG: command: %s\n",cmd);
69 exit(1);
70 }
71 strcpy(zip,"zcat");
72 sprintf(arq,"%s/sarg/sarg-file.in",tmp);
73 return;
74 }
75
76 if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) {
77 debuga("%s: %s (uncompress)",text[62],arq);
78 if (snprintf(cmd,sizeof(cmd),"zcat \"%s\" > \"%s/sarg/sarg-file.in\"",arq,tmp)>=sizeof(cmd)) {
79 fprintf(stderr,"SARG: decompression command too long for log file %s\n",arq);
80 exit(1);
81 }
82 cstatus=system(cmd);
83 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
84 fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
85 fprintf(stderr, "SARG: command: %s\n",cmd);
86 exit(1);
87 }
88 strcpy(zip,"zcat");
89 sprintf(arq,"%s/sarg/sarg-file.in",tmp);
90 }
91
92 return;
93
94 }
95
96
97 void recomp(const char *arq, const char *zip)
98 {
99 char cmd[1024];
100 int cstatus;
101
102 if(access(arq, R_OK) != 0) {
103 debuga("%s: %s",text[64],arq);
104 exit(1);
105 }
106
107 if((strcmp(zip,"gzip") != 0) &&
108 (strcmp(zip,"compress") != 0))
109 return;
110
111 debuga("%s: %s",text[63],arq);
112
113 if (snprintf(cmd,sizeof(cmd),"%s \"%s\"",zip,arq)>=sizeof(cmd)) {
114 fprintf(stderr,"SARG: compression command too long for log file %s\n",arq);
115 exit(1);
116 }
117 cstatus=system(cmd);
118 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
119 fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
120 fprintf(stderr, "SARG: command: %s\n",cmd);
121 exit(1);
122 }
123 return;
124
125 }