/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
- * 1998, 2012
+ * 1998, 2013
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
#include "include/conf.h"
#include "include/defs.h"
+/*!
+Open the log file. If it is compressed, uncompress it through a pipe.
+
+Log files compressed with gzip, bzip2 or compress are uncompressed with zcat or bzcat.
+
+If the log file does not exist, the process terminates with an error message.
+
+\param arq The log file to process.
+\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.
+
+\date 2009-09-24 - F Marchal\n This function used to uncompress .Z files in
+place using uncompress but that required a write access to the log directory,
+could conflict with logrotate and could leave the log file uncompressed if sarg
+crashed. According to the documentation, zcat is capable of uncompressing .Z
+files so it is now used.
+
+\date 2010-05-10 - F Marchal\n
+The function doesn't use a temporary file any more and read the compressed file through a pipe.
+*/
FILE *decomp(const char *arq, bool *pipe)
{
+ FILE *fi;
char cmd[1024];
int arqlen;
- if(access(arq, R_OK) != 0) {
- debuga(_("File not found: %s\n"),arq);
- exit(EXIT_FAILURE);
- }
-
arqlen=strlen(arq);
if(arqlen>3 && strcmp(arq+arqlen-3,".gz") == 0) {
- debuga(_("Decompressing log file \"%s\" with zcat\n"),arq);
+ /*
+ TRANSLATORS: The last %s is the command used to uncompress
+ the log file such as zcat ou bzip2.
+ */
+ debuga(_("Decompressing log file \"%s\" with %s\n"),arq,"zcat");
if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) {
debuga(_("decompression command too long for log file %s\n"),arq);
exit(EXIT_FAILURE);
}
*pipe=true;
- return(popen(cmd,"r"));
+ fi=popen(cmd,"r");
}
-
- if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) {
- debuga(_("Decompressing log file \"%s\" with bzcat\n"),arq);
+ else if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) {
+ debuga(_("Decompressing log file \"%s\" with %s\n"),arq,"bzcat");
if (snprintf(cmd,sizeof(cmd),"bzcat \"%s\"",arq)>=sizeof(cmd)) {
debuga(_("decompression command too long for log file %s\n"),arq);
exit(EXIT_FAILURE);
}
*pipe=true;
- return(popen(cmd,"r"));
+ fi=popen(cmd,"r");
}
-
- if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) {
- debuga(_("Decompressing log file \"%s\" with zcat\n"),arq);
+ else if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) {
+ debuga(_("Decompressing log file \"%s\" with %s\n"),arq,"zcat");
if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) {
debuga(_("decompression command too long for log file %s\n"),arq);
exit(EXIT_FAILURE);
}
*pipe=true;
- return(popen(cmd,"r"));
+ fi=popen(cmd,"r");
}
-
- *pipe=false;
- return(MY_FOPEN(arq,"r"));
+ else {
+ *pipe=false;
+ fi=MY_FOPEN(arq,"r");
+ }
+ return(fi);
}