]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
110ce984 | 3 | * 1998, 2015 |
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 | |
d2cd218e FM |
30 | /*! |
31 | Open the log file. If it is compressed, uncompress it through a pipe. | |
32 | ||
33 | Log files compressed with gzip, bzip2 or compress are uncompressed with zcat or bzcat. | |
34 | ||
35 | If the log file does not exist, the process terminates with an error message. | |
36 | ||
37 | \param arq The log file to process. | |
38 | \param pipe A variable set to \c true if the log file is opened through a pipe or set to \c false if the file is open directly. | |
39 | ||
40 | \date 2009-09-24 - F Marchal\n This function used to uncompress .Z files in | |
41 | place using uncompress but that required a write access to the log directory, | |
42 | could conflict with logrotate and could leave the log file uncompressed if sarg | |
43 | crashed. According to the documentation, zcat is capable of uncompressing .Z | |
44 | files so it is now used. | |
45 | ||
46 | \date 2010-05-10 - F Marchal\n | |
47 | The function doesn't use a temporary file any more and read the compressed file through a pipe. | |
48 | */ | |
d2855b39 | 49 | FILE *decomp(const char *arq, bool *pipe) |
25697a35 | 50 | { |
d2cd218e | 51 | FILE *fi; |
9bd92830 FM |
52 | char cmd[1024]; |
53 | int arqlen; | |
25697a35 | 54 | |
9bd92830 FM |
55 | arqlen=strlen(arq); |
56 | if(arqlen>3 && strcmp(arq+arqlen-3,".gz") == 0) { | |
96dadc9f FM |
57 | /* |
58 | TRANSLATORS: The last %s is the command used to uncompress | |
59 | the log file such as zcat ou bzip2. | |
60 | */ | |
af961877 | 61 | debuga(__FILE__,__LINE__,_("Decompressing log file \"%s\" with %s\n"),arq,"zcat"); |
9bd92830 | 62 | if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) { |
af961877 | 63 | debuga(__FILE__,__LINE__,_("decompression command too long for log file %s\n"),arq); |
9bd92830 FM |
64 | exit(EXIT_FAILURE); |
65 | } | |
66 | *pipe=true; | |
d2cd218e | 67 | fi=popen(cmd,"r"); |
9bd92830 | 68 | } |
d2cd218e | 69 | else if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) { |
af961877 | 70 | debuga(__FILE__,__LINE__,_("Decompressing log file \"%s\" with %s\n"),arq,"bzcat"); |
9bd92830 | 71 | if (snprintf(cmd,sizeof(cmd),"bzcat \"%s\"",arq)>=sizeof(cmd)) { |
af961877 | 72 | debuga(__FILE__,__LINE__,_("decompression command too long for log file %s\n"),arq); |
9bd92830 FM |
73 | exit(EXIT_FAILURE); |
74 | } | |
75 | *pipe=true; | |
d2cd218e | 76 | fi=popen(cmd,"r"); |
9bd92830 | 77 | } |
d2cd218e | 78 | else if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) { |
af961877 | 79 | debuga(__FILE__,__LINE__,_("Decompressing log file \"%s\" with %s\n"),arq,"zcat"); |
9bd92830 | 80 | if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) { |
af961877 | 81 | debuga(__FILE__,__LINE__,_("decompression command too long for log file %s\n"),arq); |
9bd92830 FM |
82 | exit(EXIT_FAILURE); |
83 | } | |
84 | *pipe=true; | |
d2cd218e | 85 | fi=popen(cmd,"r"); |
9bd92830 | 86 | } |
d2cd218e FM |
87 | else { |
88 | *pipe=false; | |
89 | fi=MY_FOPEN(arq,"r"); | |
90 | } | |
91 | return(fi); | |
25697a35 | 92 | } |