]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
1164c474 | 3 | * 1998, 2010 |
25697a35 GS |
4 | * |
5 | * SARG donations: | |
6 | * please look at http://sarg.sourceforge.net/donations.php | |
1164c474 FM |
7 | * Support: |
8 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |
25697a35 GS |
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" | |
5f3cfd1d | 28 | #include "include/defs.h" |
25697a35 | 29 | |
32e71fa4 | 30 | void decomp(char *arq, char *zip, const char *tmp) |
25697a35 | 31 | { |
25697a35 | 32 | char cmd[1024]; |
456d78a5 | 33 | int cstatus; |
b008f87f | 34 | int arqlen; |
25697a35 GS |
35 | |
36 | if(access(arq, R_OK) != 0) { | |
10210234 | 37 | debuga(_("File not found: %s\n"),arq); |
06b39c87 | 38 | exit(EXIT_FAILURE); |
25697a35 GS |
39 | } |
40 | ||
b008f87f FM |
41 | arqlen=strlen(arq); |
42 | if(arqlen>3 && strcmp(arq+arqlen-3,".gz") == 0) { | |
10210234 | 43 | debuga(_("Decompressing log file: %s > %s/sarg/sarg-file.in (zcat)\n"),arq,tmp); |
eb08bfe3 | 44 | if (snprintf(cmd,sizeof(cmd),"zcat \"%s\" > \"%s/sarg/sarg-file.in\"",arq,tmp)>=sizeof(cmd)) { |
10210234 | 45 | debuga(_("decompression command too long for log file %s\n"),arq); |
06b39c87 | 46 | exit(EXIT_FAILURE); |
b008f87f | 47 | } |
456d78a5 FM |
48 | cstatus=system(cmd); |
49 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
fcdc0918 FM |
50 | debuga(_("command return status %d\n"),WEXITSTATUS(cstatus)); |
51 | debuga(_("command: %s\n"),cmd); | |
06b39c87 | 52 | exit(EXIT_FAILURE); |
456d78a5 | 53 | } |
25697a35 | 54 | strcpy(zip,"zcat"); |
b008f87f | 55 | sprintf(arq,"%s/sarg/sarg-file.in",tmp); |
25697a35 GS |
56 | return; |
57 | } | |
58 | ||
b008f87f | 59 | if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) { |
10210234 | 60 | debuga(_("Decompressing log file: %s > %s/sarg/sarg-file.in (bzcat)\n"),arq,tmp); |
eb08bfe3 | 61 | if (snprintf(cmd,sizeof(cmd),"bzcat \"%s\" > \"%s/sarg/sarg-file.in\"",arq,tmp)>=sizeof(cmd)) { |
10210234 | 62 | debuga(_("decompression command too long for log file %s\n"),arq); |
06b39c87 | 63 | exit(EXIT_FAILURE); |
b008f87f | 64 | } |
456d78a5 FM |
65 | cstatus=system(cmd); |
66 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
fcdc0918 FM |
67 | debuga(_("command return status %d\n"),WEXITSTATUS(cstatus)); |
68 | debuga(_("command: %s\n"),cmd); | |
06b39c87 | 69 | exit(EXIT_FAILURE); |
456d78a5 | 70 | } |
25697a35 | 71 | strcpy(zip,"zcat"); |
b008f87f | 72 | sprintf(arq,"%s/sarg/sarg-file.in",tmp); |
25697a35 GS |
73 | return; |
74 | } | |
75 | ||
b008f87f | 76 | if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) { |
10210234 | 77 | debuga(_("Decompressing log file: %s (uncompress)\n"),arq); |
eb08bfe3 | 78 | if (snprintf(cmd,sizeof(cmd),"zcat \"%s\" > \"%s/sarg/sarg-file.in\"",arq,tmp)>=sizeof(cmd)) { |
10210234 | 79 | debuga(_("decompression command too long for log file %s\n"),arq); |
06b39c87 | 80 | exit(EXIT_FAILURE); |
b008f87f | 81 | } |
456d78a5 FM |
82 | cstatus=system(cmd); |
83 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
fcdc0918 FM |
84 | debuga(_("command return status %d\n"),WEXITSTATUS(cstatus)); |
85 | debuga(_("command: %s\n"),cmd); | |
06b39c87 | 86 | exit(EXIT_FAILURE); |
456d78a5 | 87 | } |
b008f87f FM |
88 | strcpy(zip,"zcat"); |
89 | sprintf(arq,"%s/sarg/sarg-file.in",tmp); | |
25697a35 GS |
90 | } |
91 | ||
92 | return; | |
93 | ||
94 | } | |
95 | ||
96 | ||
10210234 | 97 | void recomp(const char *arq, const char *zip) |
25697a35 | 98 | { |
25697a35 | 99 | char cmd[1024]; |
456d78a5 | 100 | int cstatus; |
25697a35 GS |
101 | |
102 | if(access(arq, R_OK) != 0) { | |
10210234 | 103 | debuga(_("File not found: %s\n"),arq); |
06b39c87 | 104 | exit(EXIT_FAILURE); |
25697a35 GS |
105 | } |
106 | ||
d0bdf26f FM |
107 | if((strcmp(zip,"gzip") != 0) && |
108 | (strcmp(zip,"compress") != 0)) | |
109 | return; | |
d2fe0c32 | 110 | |
10210234 | 111 | debuga(_("Compressing log file: %s\n"),arq); |
25697a35 | 112 | |
eb08bfe3 | 113 | if (snprintf(cmd,sizeof(cmd),"%s \"%s\"",zip,arq)>=sizeof(cmd)) { |
10210234 | 114 | debuga(_("compression command too long for log file %s\n"),arq); |
06b39c87 | 115 | exit(EXIT_FAILURE); |
b008f87f | 116 | } |
456d78a5 FM |
117 | cstatus=system(cmd); |
118 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
10210234 FM |
119 | debuga(_("command return status %d\n"),WEXITSTATUS(cstatus)); |
120 | debuga(_("command: %s\n"),cmd); | |
06b39c87 | 121 | exit(EXIT_FAILURE); |
456d78a5 | 122 | } |
25697a35 GS |
123 | return; |
124 | ||
125 | } |