#include "include/conf.h"
#include "include/defs.h"
+#if defined(HAVE_BACKTRACE)
+#define USE_GETWORD_BACKTRACE 1
+#else
+#define USE_GETWORD_BACKTRACE 0
+#endif
+
static char mtab1[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
//! The list of the HTTP codes to exclude from the report.
}
}*/
+#if USE_GETWORD_BACKTRACE
+static void getword_backtrace(void)
+{
+ void *buffer[5];
+ int i, n;
+ char **calls;
+
+ n=backtrace(buffer,sizeof(buffer)/sizeof(buffer[0]));
+ if (n<=0) return;
+ calls=backtrace_symbols(buffer,n);
+ if (calls) {
+ fprintf(stderr,"SARG: getword backtrace:\n");
+ for (i=0 ; i<n ; i++) {
+ fprintf(stderr,"SARG: %d:%s\n",i+1,calls[i]);
+ }
+ free(calls);
+ }
+}
+#endif //USE_GETWORD_BACKTRACE
+
void getword_start(struct getwordstruct *gwarea, const char *line)
{
gwarea->beginning=line;
printf("SARG: searching for \'x%x\'\n",stop);
//printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
word[(limit>0) ? limit-1 : 0]='\0';
+#if USE_GETWORD_BACKTRACE
+ getword_backtrace();
+#endif
return(-1);
}
word[x] = gwarea->current[x];
printf("SARG: searching for \'x%x\'\n",stop);
//printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
if (limit>0) word[limit-1]='\0';
+#if USE_GETWORD_BACKTRACE
+ getword_backtrace();
+#endif
//exit(1);
return(-1);
}
printf("SARG: Record=\"%s\"\n",gwarea->current);
printf("SARG: searching for \'x%x\'\n",stop);
//printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
+#if USE_GETWORD_BACKTRACE
+ getword_backtrace();
+#endif
return(-1);
}
}
int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop)
{
int x;
+ int sign=+1;
+ if (gwarea->current[0] == '-') {
+ gwarea->current++;
+ sign=-1;
+ } else if (gwarea->current[0] == '+') {
+ gwarea->current++;
+ }
*number=0LL;
for(x=0;isdigit(gwarea->current[x]);x++) {
*number=(*number * 10) + gwarea->current[x]-'0';
printf("SARG: Record=\"%s\"\n",gwarea->current);
printf("SARG: searching for \'x%x\'\n",stop);
//printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
+#if USE_GETWORD_BACKTRACE
+ getword_backtrace();
+#endif
return(-1);
}
+ *number*=sign;
if (gwarea->current[x]) ++x;
gwarea->current+=x;
return returnval;
}
-static int is_absolute(const char *path)
+int is_absolute(const char *path)
{
if (*path=='/') return(1);
#ifdef WINDOWS
void fixper(char *tbuf, char *period, const char *duntil)
{
-
char warea[50];
char dia[5], mes[5], ano[5];
- int x;
-
- warea[0]='\0';
+ int x;
strncpy(dia,duntil+6,2);
dia[2]='\0';
if(strcmp(df,"e") == 0)
sprintf(warea,"%s%s%s",dia,mes,ano);
- if(strcmp(df,"u") == 0)
+ else if(strcmp(df,"u") == 0)
sprintf(warea,"%s%s%s",ano,mes,dia);
+ else
+ warea[0]='\0';
strcat(period,warea);
}
if ( k == 2 && i != 0 ) {
k = 0;
pbuf[j++] = num[i];
- if(strcmp(UseComma,"yes") == 0)
- pbuf[j++] = ',';
- else pbuf[j++] = '.';
+ pbuf[j++] = (UseComma) ? ',' : '.';
continue;
}
pbuf[j] = num[i];
if ( k == 2 && i != 0 ) {
k = 0;
pbuf[j++] = num[i];
- if(strcmp(UseComma,"yes") == 0)
- pbuf[j++] = ',';
- else pbuf[j++] = '.';
+ pbuf[j++] = (UseComma) ? ',' : '.';
continue;
}
pbuf[j] = num[i];
}
-void vrfydir(const char *dir, const char *per1, const char *addr, const char *site, const char *us, const char *form)
+void vrfydir(const char *per1, const char *addr, const char *site, const char *us, const char *form)
{
FILE *img_in, *img_ou;
FILE *fp_ou;
struct dirent *direntp;
char y1[5], y2[5];
char d1[3], d2[3];
- char m1[4], m2[4];
+ char m1[8], m2[8];
time_t curtime;
struct tm *loctm;
int cstatus;
if(strcmp(IndexTree,"date") == 0) {
- bzero(y1,5);
- bzero(y2,5);
- bzero(d1,3);
- bzero(d2,3);
- bzero(m1,4);
- bzero(m2,4);
+ bzero(y1,sizeof(y1));
+ bzero(y2,sizeof(y2));
+ bzero(d1,sizeof(d1));
+ bzero(d2,sizeof(d2));
+ bzero(m1,sizeof(m1));
+ bzero(m2,sizeof(m2));
if(strncmp(df,"u",1) == 0) {
strncpy(y1,period,4);
strncpy(y2,period+10,4);
sprintf(wdir,"%s%s",outdir,y1);
if(strcmp(y1,y2) != 0) {
- strncat(wdir,"-",1);
- strncat(wdir,y2,strlen(y2));
+ strcat(wdir,"-");
+ strcat(wdir,y2);
}
if(access(wdir, R_OK) != 0)
my_mkdir(wdir);
- strncat(wdir,"/",1);
- strncat(wdir,m1,strlen(m1));
+ strcat(wdir,"/");
+ strcat(wdir,m1);
if(strcmp(m1,m2) != 0) {
- strncat(wdir,"-",1);
- strncat(wdir,m2,strlen(m2));
+ strcat(wdir,"-");
+ strcat(wdir,m2);
}
if(access(wdir, R_OK) != 0)
my_mkdir(wdir);
- strncat(wdir,"/",1);
- strncat(wdir,d1,strlen(d1));
+ strcat(wdir,"/");
+ strcat(wdir,d1);
if(strcmp(d1,d2) != 0) {
- strncat(wdir,"-",1);
- strncat(wdir,d2,strlen(d2));
+ strcat(wdir,"-");
+ strcat(wdir,d2);
}
- } else
- strcpy(wdir,dir);
+ } else {
+ sprintf(wdir, "%s%s", outdir, per1);
+ }
- if(strlen(us) > 0) {
+ if(us[0] != '\0') {
strcat(wdir,"-");
strcat(wdir,us);
}
- if(strlen(addr) > 0) {
+ if(addr[0] != '\0') {
strcat(wdir,"-");
strcat(wdir,addr);
}
- if(strlen(site) > 0) {
+ if(site[0] != '\0') {
strcat(wdir,"-");
strcat(wdir,site);
}
strcpy(dirname,wdir);
if(strcmp(IndexTree,"date") != 0) {
- strcpy(dirname2,dirname);
- if(strcmp(OverwriteReport,"no") == 0) {
+ if(!OverwriteReport) {
while(num) {
if(access(wdir,R_OK) == 0) {
sprintf(wdir,"%s.%d",dirname,num);
if(count > 0) {
if(debug)
- fprintf(stderr, "SARG: %s: %s %s %s\n",text[51],dirname2,text[52],wdir);
- rename(dirname2,wdir);
+ fprintf(stderr, "SARG: %s: %s %s %s\n",text[51],dirname,text[52],wdir);
+ rename(dirname,wdir);
}
} else {
- if(access(dir,R_OK) == 0) {
- sprintf(csort,"rm -r \"%s\"",dir);
+ if(access(wdir,R_OK) == 0) {
+ sprintf(csort,"rm -r \"%s\"",wdir);
cstatus=system(csort);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
my_mkdir(dirname);
} else {
strcpy(dirname2,wdir);
- if(strcmp(OverwriteReport,"no") == 0) {
+ if(!OverwriteReport) {
while(num) {
if(access(wdir,R_OK) == 0) {
sprintf(wdir,"%s.%d",dirname2,num);
t = time(NULL);
local = localtime(&t);
- /*
if(strcmp(DateFormat,"u") == 0)
strftime(ftime, ftimesize, "%b/%d/%Y %H:%M", local);
if(strcmp(DateFormat,"e") == 0)
strftime(ftime, ftimesize, "%d/%b/%Y-%H:%M", local);
if(strcmp(DateFormat,"w") == 0)
strftime(ftime, ftimesize, "%V-%H-%M", local);
- */
- strftime(ftime, ftimesize, "%x %X", local);
return;
}
int anou;
char wdate[50];
-
strncpy(wdate,date,sizeof(wdate)-1);
wdate[sizeof(wdate)-1]='\0';
if(strchr(wdate,'-') == NULL) {
FILE *fp_in;
char warea[256];
- if(strcmp(RemoveTempFiles,"yes") != 0)
+ if(!RemoveTempFiles)
return;
if(debug) {
{
char ftime[127];
- if(strcmp(ShowSargInfo,"yes") != 0) return;
+ if(!ShowSargInfo) return;
zdate(ftime, sizeof(ftime), DateFormat);
fprintf(fp_ou,"<div align=\"center\"><table><tr><td><br><br></td><td class=\"info\">%s <a href='%s'><font class=\"info\">%s-%s</font></a> %s %s</td></tr></table></div>\n",text[108],URL,PGM,VERSION,text[109],ftime);
}
void show_sarg(FILE *fp_ou, const char *ind)
{
- if(strcmp(ShowSargLogo,"yes") == 0) fprintf(fp_ou,"<div align=\"center\"><table class=\"logo\">\n<tr><th><a href=\"http://sarg.sourceforge.net\"><img src=\"%s/images/sarg.png\" title=\"SARG, Squid Analysis Report Generator. Logo by Osamu Matsuzaki\" alt=\"Sarg\"></a> Squid Analysis Report Generator</th></tr>\n<tr><th class=\"title\"> </th></tr>\n</table></div>\n",ind);
+ if(ShowSargLogo) fprintf(fp_ou,"<div align=\"center\"><table class=\"logo\">\n<tr><th><a href=\"http://sarg.sourceforge.net\"><img src=\"%s/images/sarg.png\" title=\"SARG, Squid Analysis Report Generator. Logo by Osamu Matsuzaki\" alt=\"Sarg\"></a> Squid Analysis Report Generator</th></tr>\n<tr><th class=\"title\"> </th></tr>\n</table></div>\n",ind);
}
void write_logo_image(FILE *fp_ou)