convlog.c (sarg-2.3.11) | : | convlog.c (sarg-2.4.0) | ||
---|---|---|---|---|
/* | /* | |||
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net | |||
* 1998, 2013 | * 1998, 2015 | |||
* | * | |||
* SARG donations: | * SARG donations: | |||
* please look at http://sarg.sourceforge.net/donations.php | * please look at http://sarg.sourceforge.net/donations.php | |||
* Support: | * Support: | |||
* http://sourceforge.net/projects/sarg/forums/forum/363374 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |||
* --------------------------------------------------------------------- | * --------------------------------------------------------------------- | |||
* | * | |||
* This program is free software; you can redistribute it and/or modify | * This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | * the Free Software Foundation; either version 2 of the License, or | |||
skipping to change at line 30 | skipping to change at line 30 | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |||
* | * | |||
*/ | */ | |||
#include "include/conf.h" | #include "include/conf.h" | |||
#include "include/defs.h" | #include "include/defs.h" | |||
void convlog(const char *arq, char *df, int dfrom, int duntil) | void convlog(const char *arq, char df, const struct ReadLogDataStruct *ReadFilte r) | |||
{ | { | |||
FILE *fp_in; | FileObject *fp_in; | |||
char *buf; | char *buf; | |||
char data[30]; | char data[30]; | |||
char dia[11]; | char dia[11]; | |||
time_t tt; | time_t tt; | |||
int idata=0; | int idata=0; | |||
struct tm *t; | struct tm *t; | |||
struct getwordstruct gwarea; | struct getwordstruct gwarea; | |||
longline line; | longline line; | |||
if(arq[0] == '\0') | if (arq[0] == '\0') | |||
arq="/var/log/squid/access.log"; | arq="/var/log/squid/access.log"; | |||
if (arq[0]=='-' && arq[1]=='\0') { | if ((fp_in=FileObject_Open(arq))==NULL) { | |||
fp_in=stdin; | debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),arq,F | |||
} else if((fp_in=MY_FOPEN(arq,"r"))==NULL) { | ileObject_GetLastOpenError()); | |||
debugapos("convlog",_("Cannot open file \"%s\": %s\n"),arq,strerr | ||||
or(errno)); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
if ((line=longline_create())==NULL) { | if ((line=longline_create())==NULL) { | |||
debuga(_("Not enough memory to read file \"%s\"\n"),arq); | debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\" \n"),arq); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
while((buf=longline_read(fp_in,line))!=NULL) { | while((buf=longline_read(fp_in,line))!=NULL) { | |||
getword_start(&gwarea,buf); | getword_start(&gwarea,buf); | |||
if (getword(data,sizeof(data),&gwarea,' ')<0) { | if (getword(data,sizeof(data),&gwarea,' ')<0) { | |||
debuga(_("Invalid record in file \"%s\"\n"),arq); | debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\" \n"),arq); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
tt=atoi(data); | tt=atoi(data); | |||
t=localtime(&tt); | t=localtime(&tt); | |||
if(dfrom) { | if (ReadFilter->DateRange[0]) | |||
{ | ||||
idata=(t->tm_year+1900)*10000+(t->tm_mon+1)*100+t->tm_mda y; | idata=(t->tm_year+1900)*10000+(t->tm_mon+1)*100+t->tm_mda y; | |||
if(idata < dfrom || idata > duntil) | if (idata<ReadFilter->StartDate || idata>ReadFilter->EndD | |||
ate) | ||||
continue; | ||||
} | ||||
if (ReadFilter->StartTime>=0 || ReadFilter->EndTime>=0) | ||||
{ | ||||
int hmr=t->tm_hour*100+t->tm_min; | ||||
if (hmr<ReadFilter->StartTime || hmr>=ReadFilter->EndTime | ||||
) | ||||
continue; | continue; | |||
} | } | |||
if(df[0]=='e') | if (df=='e') | |||
strftime(dia, sizeof(dia), "%d/%m/%Y", t); | strftime(dia, sizeof(dia), "%d/%m/%Y", t); | |||
else | else if (df=='u') | |||
strftime(dia, sizeof(dia), "%m/%d/%Y", t); | strftime(dia, sizeof(dia), "%m/%d/%Y", t); | |||
else //if (df=='w') | ||||
strftime(dia, sizeof(dia), "%Y.%U", t); | ||||
printf("%s %02d:%02d:%02d %s\n",dia,t->tm_hour,t->tm_min,t->tm_se c,gwarea.current); | printf("%s %02d:%02d:%02d %s\n",dia,t->tm_hour,t->tm_min,t->tm_se c,gwarea.current); | |||
} | } | |||
longline_destroy(&line); | longline_destroy(&line); | |||
if (fp_in!=stdin && fclose(fp_in)==EOF) { | if (FileObject_Close(fp_in)) { | |||
debuga(_("Failed to close file \"%s\": %s\n"),arq,strerror(errno) | debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),arq,File | |||
); | Object_GetLastCloseError()); | |||
exit(EXIT_FAILURE); | ||||
} | } | |||
} | } | |||
End of changes. 13 change blocks. | ||||
18 lines changed or deleted | 28 lines changed or added |