FILE *fp_in = NULL, *fp_ou = NULL;
- char url[MAXLEN];
+ char *buf;
+ char url[MAX_URL_LEN];
char authfail_in[MAXLEN];
char per[MAXLEN];
char report[MAXLEN];
int count=0;
int cstatus;
struct getwordstruct gwarea;
+ struct longlinestruct line;
if(DataFile[0] != '\0') return;
fputs("<tr><td></td></tr>\n",fp_ou);
fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read file %s"),authfail_in);
+ exit(1);
+ }
+
+ while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
continue;
}
- fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">%s<a href=\"%s\">%s</a></td></th>\n",name,ip,data,hora,BlockImage,url,url);
+ fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">",name,ip,data,hora);
+ if(BlockIt[0]!='\0') {
+ fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
+ output_html_url(fp_ou,url);
+ fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",fp_ou);
+ }
+ fputs("<a href=\"",fp_ou);
+ output_html_url(fp_ou,url);
+ fputs("\">",fp_ou);
+ output_html_string(fp_ou,url,100);
+ fputs("</a></td></th>\n",fp_ou);
}
fclose(fp_in);
+ longline_free(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
/*
- * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
- * 1998, 2009
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
+ * 1998, 2010
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
+ * Support:
+ * http://sourceforge.net/projects/sarg/forums/forum/363374
* ---------------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
char user[MAXLEN], code1[255], code2[255];
char ip[30];
char wdata[127];
+ char url[MAX_URL_LEN];
int idata=0;
int cstatus;
struct getwordstruct gwarea;
if(debug) {
getword_start(&gwarea,text[7]);
- if (getword(urly,sizeof(urly),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
+ if (getword(url,sizeof(url),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s entry.\n",text[7]);
exit(1);
}
- debuga("%s DansGuardian %s: %s",urly,gwarea.current,loglocation);
+ debuga("%s DansGuardian %s: %s",url,gwarea.current,loglocation);
}
if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
FILE *fp_in = NULL, *fp_ou = NULL;
- char url[MAXLEN];
+ char *buf;
+ char url[MAX_URL_LEN];
char denied_in[MAXLEN];
char per[MAXLEN];
char report[MAXLEN];
int z=0;
int count=0;
struct getwordstruct gwarea;
+ struct longlinestruct line;
ouser[0]='\0';
ouser2[0]='\0';
fputs("<tr><td></td></tr>\n",fp_ou);
fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read the denied accesses"));
+ exit(1);
+ }
+
+ while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
continue;
}
- if(BlockIt[0] != '\0')
- sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",wwwDocumentRoot,BlockIt,url,ImageFile);
- else BlockImage[0]='\0';
-
- fprintf(fp_ou,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s-%s</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td></tr>\n",name,ip,data,hora,BlockImage,url,url);
+ fprintf(fp_ou,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s-%s</td><td class=\"data2\">",name,ip,data,hora);
+ if(BlockIt[0] != '\0') {
+ fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
+ output_html_url(fp_ou,url);
+ fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",ImageFile);
+ }
+ fputs("<a href=\"http://",fp_ou);
+ output_html_url(fp_ou,url);
+ fputs("\">",fp_ou);
+ output_html_string(fp_ou,url,100);
+ fputs("</a></td></tr>\n",fp_ou);
}
fclose(fp_in);
+ longline_free(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
+/*! \def INITIAL_LINE_BUFFER_SIZE
+The initial buffer size to allocate to read a long line from a text file.
+*/
+
+
+
+
/*! \var static char mtab1[12][4];
The list of the months.
*/
-/*! \fn void output_html_string(FILE *fp_ou,const char *str)
+
+/*! \fn void output_html_string(FILE *fp_ou,const char *str,int maxlen)
Write a string in a file and replace the problematic ASCII characters by their equivalent HTML entities.
\param fp_ou The handle of the output file.
\param str The string to output.
+\param maxlen The maximum number of bytes to write from the string. Set to zero to have no limit.
+
+If the string is longer than the requested length, only the requested number of bytes are output and
+the string is truncated and ended by ….
+*/
+
+
+
+
+
+/*! \fn void output_html_url(FILE *fp_ou,const char *url)
+Write an URL into the file and replace any & by &.
+
+\param fp_ou The handle of the output file.
+\param url The URL to output.
*/
\param contentonly \c True to delete only the content of the directory and leave the directory
itself in place. If set to \c zero, the directory is removed too.
*/
+
+
+
+
+
+/*! \fn int longline_prepare(struct longlinestruct *line)
+Prepare the buffer to read long text lines from a file.
+
+The memory allocated by this function must be freed with a call to
+longline_free().
+
+\param line The buffer to initialize.
+
+\retval 0 No error.
+\retval -1 Not enough memory.
+*/
+
+
+
+
+
+/*! \fn char *longline_read(FILE *fp_in,struct longlinestruct *line)
+Read one long line of text from a file. If the buffer is too short, it is
+expended until the line can fit in it.
+
+The function always read as many bytes as can fit in the buffer and split the lines
+to return one line at a time to the caller. The returned lines are always terminated
+by a null ASCII character. The CR or LF are removed.
+
+Any empty line is skipped.
+
+\param fp_in The file to read.
+\param line The buffer initialized by longline_preapre().
+
+\return A pointer to the beginning of the string in the buffer or NULL if it is
+the last string read.
+
+\note If not enough memory is available to read the line, the program is terminated
+with an error message.
+*/
+
+
+
+
+
+/*! \fn void longline_free(struct longlinestruct *line)
+Free the memory allocated by longline_prepare().
+
+\param line The buffer to free.
+*/
FILE *fp_in = NULL, *fp_ou = NULL;
- char url[MAXLEN];
+ char *buf;
+ char url[MAX_URL_LEN];
char report_in[MAXLEN];
char wdirname[MAXLEN];
char report[MAXLEN];
int count=0;
int i;
struct getwordstruct gwarea;
+ struct longlinestruct line;
ouser[0]='\0';
ouser2[0]='\0';
fputs("<tr><td></td></tr>\n",fp_ou);
fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read the downloaded files"));
+ exit(1);
+ }
+
+ while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
for (i=strlen(url)-1 ; i>=0 && (unsigned char)url[i]<' ' ; i--) url[i]=0;
fprintf(fp_ou,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s-%s</td><td class=\"data2\">",name,ip,data,hora);
- if(BlockIt[0]!='\0')
- fprintf(fp_ou,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",wwwDocumentRoot,BlockIt,url,ImageFile);
- fprintf(fp_ou,"<a href=\"%s\">",url);
- output_html_string(fp_ou,url);
+ if(BlockIt[0]!='\0') {
+ fprintf(fp_ou,"<a href=\"%s%s?url=\"",wwwDocumentRoot,BlockIt);
+ output_html_url(fp_ou,url);
+ fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",ImageFile);
+ }
+ fputs("<a href=\"",fp_ou);
+ output_html_url(fp_ou,url);
+ fputs("\">",fp_ou);
+ output_html_string(fp_ou,url,100);
fputs("</a></td></tr>\n",fp_ou);
}
fclose(fp_in);
+ longline_free(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
long long int ltemp;
long long int ntotuser;
long long int userbytes, userelap;
+ char *linebuf;
char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
- char url[MAXLEN], tmsg[50], csort[MAXLEN];
+ char url[MAX_URL_LEN], tmsg[50], csort[MAXLEN];
char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
char userurl[1024], userhora[9], userdia[9];
char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
char *str;
char warea[MAXLEN];
char totuser[8];
+ char ltext110[100];
long long int tnacc=0, ttnacc=0, unacc=0;
double perc=0, perc2=0, ouperc=0, inperc=0;
char *s;
int cstatus;
const char txtext[]=".txt";
int dlen;
- char urly[MAXLEN];
- char siteind[MAXLEN];
+ char urly[MAX_URL_LEN];
+ char siteind[MAX_URL_LEN];
struct getwordstruct gwarea;
+ struct longlinestruct line;
if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
exit(1);
}
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read file %s"),arqin);
+ exit(1);
+ }
+
tnacc=0;
tnbytes=0;
tnelap=0;
tnincache=0;
tnoucache=0;
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- getword_start(&gwarea,buf);
+ while((linebuf=longline_read(fp_in,&line))!=NULL) {
+ getword_start(&gwarea,linebuf);
if (getword_atoll(<emp,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
exit(1);
}
tnbytes+=ltemp;
- if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
- getword_atoll(<emp,&gwarea,'\t')<0) {
+ if (getword_skip(MAX_URL_LEN,&gwarea,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+ exit(1);
+ }
+ if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+ exit(1);
+ }
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
debuga("%s: %s",text[61],usuario);
}
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- getword_start(&gwarea,buf);
+ while((linebuf=longline_read(fp_in,&line))!=NULL) {
+ getword_start(&gwarea,linebuf);
if (getword_atoll(&twork,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
exit(1);
str=strchr(url,'/');
if (str){
*str='\0';
- strcat(url,"...");
+ strcat(url,"…");
strcat(url,module);
}
}
if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
- strcpy(ltext110,text[110]);
- for(s=ltext110; *s; ++s)
- *s=tolower(*s);
+ s=text[110];
+ for(z1=0 ; z1<sizeof(ltext110)-1 && s[z1] ; z1++)
+ ltext110[z1]=tolower(s[z1]);
+ ltext110[z1]='\0';
for(z1=0; urly[z1]; z1++) {
if(urly[z1]=='?' || urly[z1]=='-' || urly[z1]=='.' || urly[z1]==':' || urly[z1]=='/' || urly[z1]=='\\' ||
urly[z1]=='*' || urly[z1]=='\'' || urly[z1]=='\"' || urly[z1]=='$')
}
fclose(fp_in);
+ longline_free(&line);
if(iprel)
unlink(arqip);
#endif /*__MINGW32__*/
#define MAXLEN 20000
+#define MAX_URL_LEN 40000
#define MAXLOGS 255
#define REPORT_TYPE_USERS_SITES 0x0001UL
char outdir[MAXLEN];
char dirname[MAXLEN];
char buf[MAXLEN];
-char url[MAXLEN];
-char urly[MAXLEN];
char user[MAXLEN];
char period[MAXLEN];
char code[MAXLEN];
char href3[MAXLEN];
char df[20];
char day[3], month[4], year[5];
-char ltext110[50];
char cdfrom[30];
char cduntil[30];
int LastLog;
char wwwDocumentRoot[MAXLEN];
char ExternalCSSFile[MAXLEN];
char BlockIt[255];
-char BlockImage[512];
char NtlmUserFormat[30];
unsigned long int IndexTree;
int UserAuthentication;
char wwork2[MAXLEN];
char wwork3[MAXLEN];
char mask[MAXLEN];
-char html_old[MAXLEN];
char site[MAXLEN];
char us[50];
char email[MAXLEN];
const char *beginning;
};
+struct longlinestruct
+{
+ //! The buffer to store the data read from the log file.
+ char *buffer;
+ //! The size of the buffer.
+ size_t size;
+ //! The number of bytes stored in the buffer.
+ size_t length;
+ //! The position of the beginning of the current string.
+ size_t start;
+ //! The position of the end of the current string.
+ size_t end;
+};
+
// auth.c
void htaccess(const char *name);
void write_html_header(FILE *fp_ou, int depth, const char *title);
void close_html_header(FILE *fp_ou);
void write_html_trailer(FILE *fp_ou);
-void output_html_string(FILE *fp_ou,const char *str);
+void output_html_string(FILE *fp_ou,const char *str,int maxlen);
+void output_html_url(FILE *fp_ou,const char *url);
void subs(char *str, int size, char *from, char *to);
void conv_month(char *month);
void debuga(const char *msg,...);
char *get_param_value(const char *param,char *line);
int compar( const void *, const void * );
void unlinkdir(const char *dir,int contentonly);
+int longline_prepare(struct longlinestruct *line);
+char *longline_read(FILE *fp_in,struct longlinestruct *line);
+void longline_free(struct longlinestruct *line);
#define REPORT_EVERY_X_LINES 5000
-
char *userfile;
numlist weekdays = { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
char tbuf2[128];
char zip[20];
char *str;
- char bufz[2*MAXLEN];
char tmp2[MAXLEN];
char start_hour[128];
char end_hour[128];
+ char *linebuf;
+ char url[MAX_URL_LEN];
+ char urly[MAX_URL_LEN];
enum InputLogFormat ilf;
int ilf_count[ILF_Last];
int ch;
unsigned long recs2=0UL;
int OutputNonZero = REPORT_EVERY_X_LINES ;
int download_flag=0;
- char download_url[MAXLEN];
+ char download_url[MAX_URL_LEN];
char sz_Last_User[MAXLEN]="";
struct getwordstruct gwarea;
+ struct longlinestruct line;
BgImage[0]='\0';
LogoImage[0]='\0';
init_usertab(UserTabFile);
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read a log file"));
+ exit(1);
+ }
+
sprintf ( sz_Download_Unsort , "%s/sarg/download.unsort", tmp);
if((ReportType & REPORT_TYPE_DENIED) != 0) {
}
ilf=ILF_Unknown;
download_flag=0;
- // pre-Read the file only if I have to show stats
+ // pre-read the file only if we have to show stats
if(ShowReadStatistics && !from_stdin) {
- rewind(fp_in);
+ size_t nread,i;
+ int skipcr=0;
+
recs1=0UL;
recs2=0UL;
- while( fgets(bufz,sizeof(bufz),fp_in) != NULL ) recs1++;
+ while ((nread=fread(line.buffer,1,line.size,fp_in))>0) {
+ for (i=0 ; i<nread ; i++)
+ if (skipcr) {
+ if (line.buffer[i]!='\n' && line.buffer[i]!='\r') {
+ skipcr=0;
+ }
+ } else {
+ if (line.buffer[i]=='\n' || line.buffer[i]=='\r') {
+ skipcr=1;
+ recs1++;
+ }
+ }
+ }
rewind(fp_in);
printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1,(float) 0);
fflush( stdout ) ;
}
- while(fgets(bufz,sizeof(bufz),fp_in)!=NULL) {
- blen=strlen(bufz);
- if (blen>0 && bufz[blen-1]!='\r' && bufz[blen-1]!='\n' && !feof(fp_in)) {
- fprintf(stderr,"SARG: line too long (more than %d bytes) in %s\n",sizeof(bufz)-1,arq);
- exit(1);
- }
+ line.start=0;
+ line.end=0;
+ line.length=0;
+
+ while ((linebuf=longline_read(fp_in,&line))!=NULL) {
+ blen=strlen(linebuf);
if (ilf==ILF_Unknown) {
- if(strncmp(bufz,"#Software: Mic",14) == 0) {
- fixendofline(bufz);
+ if(strncmp(linebuf,"#Software: Mic",14) == 0) {
+ fixendofline(linebuf);
if (debug)
- debuga("%s: %s",text[143],bufz);
+ debuga("%s: %s",text[143],linebuf);
ilf=ILF_Isa;
ilf_count[ilf]++;
continue;
}
- if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
+ if(strncmp(linebuf,"*** SARG Log ***",16) == 0) {
getword_start(&gwarea,arqtt);
if (getword_skip(2000,&gwarea,'-')<0 || getword(val2,sizeof(val2),&gwarea,'_')<0 ||
getword_skip(10,&gwarea,'-')<0 || getword(val3,sizeof(val3),&gwarea,'_')<0) {
OutputNonZero = REPORT_EVERY_X_LINES ;
}
if(blen < 58) continue;
- if(strstr(bufz,"HTTP/0.0") != 0) continue;
- if(strstr(bufz,"logfile turned over") != 0) continue;
- if(bufz[0] == ' ') continue;
+ if(strstr(linebuf,"HTTP/0.0") != 0) continue;
+ if(strstr(linebuf,"logfile turned over") != 0) continue;
+ if(linebuf[0] == ' ') continue;
// Record only hours usage which is required
- tt = (time_t) strtoul( bufz, NULL, 10 );
+ tt = (time_t) strtoul( linebuf, NULL, 10 );
t = localtime( &tt );
if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len,
printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
exit(1);
}
- if((str=(char *) strstr(bufz,val1)) != (char *) NULL )
+ if((str=(char *) strstr(linebuf,val1)) != (char *) NULL )
exstring++;
}
- if((str=(char *) strstr(bufz,gwarea.current)) != (char *) NULL )
+ if((str=(char *) strstr(linebuf,gwarea.current)) != (char *) NULL )
exstring++;
}
if(exstring) continue;
- if ((str = strchr(bufz, '\n')) != NULL)
+ if ((str = strchr(linebuf, '\n')) != NULL)
*str = '\0'; /* strip \n */
totregsl++;
if(debugm)
- printf("BUF=%s\n",bufz);
+ printf("BUF=%s\n",linebuf);
if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) {
- getword_start(&gwarea,bufz);
+ getword_start(&gwarea,linebuf);
if (getword(data,sizeof(data),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken time in your access.log file.\n");
exit(1);
}
}
if (getword(data,sizeof(data),&gwarea,']')<0 || getword_skip(MAXLEN,&gwarea,'"')<0 ||
- getword(fun,sizeof(fun),&gwarea,' ')<0 || getword(url,sizeof(url),&gwarea,' ')<0 ||
- getword_skip(MAXLEN,&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0 ||
+ getword(fun,sizeof(fun),&gwarea,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(url,sizeof(url),&gwarea,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0 ||
getword(tam,sizeof(tam),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
printf("SARG: Maybe you have a broken URI in your %s file.\n",arq);
exit(1);
}
-// while (strstr(bufz,"%20") != 0) {
-// getword(warea,bufz,' ');
-// strcat(url,warea);
-// }
if (getword(user,sizeof(user),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken user ID in your %s file.\n",arq);
exit(1);
}
}
if (ilf==ILF_Sarg) {
- getword_start(&gwarea,bufz);
+ getword_start(&gwarea,linebuf);
if (getword(data,sizeof(data),&gwarea,'\t')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
}
if (ilf==ILF_Isa) {
- if (bufz[0] == '#') {
+ if (linebuf[0] == '#') {
int ncols,cols[ISACOL_Last];
- fixendofline(bufz);
- getword_start(&gwarea,bufz);
+ fixendofline(linebuf);
+ getword_start(&gwarea,linebuf);
// remove the #Fields: column at the beginning of the line
if (getword_skip(1000,&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
continue;
}
if (!isa_ncols) continue;
- getword_start(&gwarea,bufz);
+ getword_start(&gwarea,linebuf);
for (x=0 ; x<isa_ncols ; x++) {
if (getword(val1,sizeof(val1),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
if(l) {
if(strcmp(user,"-") !=0 && url[0] != '\0' && strcmp(user," ") !=0 && strcmp(user,"") !=0 && strcmp(user,":") !=0){
- if((str=(char *) strstr(bufz, "[SmartFilter:")) != (char *) NULL ) {
+ if((str=(char *) strstr(linebuf, "[SmartFilter:")) != (char *) NULL ) {
fixendofline(str);
sprintf(smartfilter,"\"%s\"",str+1);
} else sprintf(smartfilter,"\"\"");
- sprintf(bufz, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
-
if ( strcmp ( user , sz_Last_User ) != 0 ) {
if ( fp_Write_User )
fclose( fp_Write_User ) ;
}
strcpy( sz_Last_User , user ) ;
}
- fputs (bufz, fp_Write_User);
+ fprintf(fp_Write_User, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
+
+ if(fp_log && ilf!=ILF_Sarg)
+ fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
- if(fp_log && ilf!=ILF_Sarg) fputs(bufz,fp_log);
totregsg++;
}
}
+ longline_free(&line);
if ( fp_Download_Unsort )
fclose (fp_Download_Unsort);
static void getlog(void);
static void header(void);
-char dat[128];
-char tim[128];
char typ[128];
char ouser[MAXLEN]="";
char ourl[MAXLEN]="";
char template1[255]="/var/tmp/sargtpl1.XXXXXX";
char template2[255]="/var/tmp/sargtpl2.XXXXXX";
char cmd[512];
- char buf[MAXLEN];
+ char *buf;
int fd1,fd2;
int cstatus;
+ struct longlinestruct line;
init_usertab(UserTabFile);
exit(1);
}
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read the log file"));
+ exit(1);
+ }
+
sprintf(cmd,"tail -%d %s",realtime_access_log_lines,AccessLog[0]);
fp = popen(cmd, "r");
- while(fgets(buf,sizeof(buf),fp) != NULL )
+ while((buf=longline_read(fp,&line)) != NULL )
if (getdata(buf,tmp)<0) {
fprintf(stderr,"SARG: Maybe a broken record or garbage was returned by %s.\n",cmd);
exit(1);
}
pclose(fp);
fclose(tmp);
+ longline_free(&line);
sprintf(cmd,"sort -r -k 1,1 -k 2,2 -o \"%s\" \"%s\"",template2,template1);
cstatus=system(cmd);
{
time_t tt;
struct tm *t;
+ char dat[128];
char tbuf[128];
char warea[MAXLEN];
+ char url[MAX_URL_LEN];
struct getwordstruct gwarea;
getword_start(&gwarea,rec);
static void datashow(const char *tmp)
{
FILE *fin;
+ char dat[128];
+ char tim[128];
char buf[MAXLEN];
+ char url[MAX_URL_LEN];
struct getwordstruct gwarea;
if((fin=fopen(tmp,"r"))==NULL) {
FILE *fp_in;
FILE *fp_gen;
- char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN];
+ char *buf;
+ char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAX_URL_LEN];
char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN];
- char wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN];
+ char wdirname[MAXLEN], oldurl[MAX_URL_LEN], oldaccuser[MAXLEN];
char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAXLEN];
char ipantes[MAXLEN], nameantes[MAXLEN];
char accsmart[MAXLEN];
char crc2[MAXLEN/2 -1];
+ char siteind[MAX_URL_LEN];
+ char arqtt[256];
+ char oldurltt[MAX_URL_LEN],oldaccdiatt[11],oldacchoratt[9];
long long int nbytes=0;
long long int nelap=0;
long long int nacc=0;
struct dirent *direntp;
const char logext[]=".log";
int dlen;
- char siteind[MAXLEN];
struct getwordstruct gwarea;
+ struct longlinestruct line;
ipantes[0]='\0';
nameantes[0]='\0';
}
ttopen=0;
- bzero(html_old, MAXLEN);
+ memset(oldurltt,0,sizeof(oldurltt));
+ memset(oldaccdiatt,0,sizeof(oldaccdiatt));
+ memset(oldacchoratt,0,sizeof(oldacchoratt));
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read the downloaded files"));
+ exit(1);
+ }
+
+ while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 ||
getword(accuser,sizeof(accuser),&gwarea,'\t')<0 || getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
}
} else {
if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){
- strcpy(oldmsg,"OK");
if(strstr(oldacccode,"DENIED") != 0)
- sprintf(oldmsg,"%s",text[46]);
+ strcpy(oldmsg,text[46]);
+ else
+ strcpy(oldmsg,"OK");
gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
nacc=0;
nbytes+=accbytes;
nelap+=accelap;
- if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
+ if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0 &&
+ (strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) {
+
if(!ttopen) {
ind2++;
strcpy(siteind,accurl);
*str=='\'' || *str=='\"' || *str=='$' || *str=='@')
*str='_';
}
- sprintf(arqtt,"%s/%s",dirname,accuser);
+ snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,accuser);
if(access(arqtt, R_OK) != 0)
my_mkdir(arqtt);
- sprintf(arqtt,"%s/%s/tt%s-%s.html",dirname,accuser,accuser,siteind);
- if(strlen(arqtt) > 255) {
- arqtt[255]='\0';
- }
+ snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",dirname,accuser,accuser,siteind);
if ((fp_tt = fopen(arqtt, "w")) == 0) {
fprintf(stderr, "SARG: (report) %s: %s\n",text[45],arqtt);
exit(1);
sprintf(httplink,"<font size=%s><a href=\"http://%s\">%s</a>",FontSize,accurl,accurl);
*/
- sprintf(ltext110,"%s",text[110]);
- for(str=ltext110; *str; ++str)
- *str=tolower(*str);
-
write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report"));
fprintf(fp_tt,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",text[89],period);
fprintf(fp_tt,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",text[90],name);
fprintf(fp_tt,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[91],tmp4,text[110]+5);
}
- sprintf(html,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accurl,accdia,acchora);
+ fprintf(fp_tt,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accurl,accdia,acchora);
- if(strcmp(html,html_old) != 0)
- fputs(html,fp_tt);
- strcpy(html_old, html);
- } else bzero(ltext110, 50);
+ strcpy(oldurltt,accurl);
+ strcpy(oldaccdiatt,accdia);
+ strcpy(oldacchoratt,acchora);
+ }
strcpy(crc2,acccode);
str=strchr(crc2,'/');
if (str) *str='\0';
-
if(strstr(crc2,"MISS") != 0)
oucache+=accbytes;
else incache+=accbytes;
- strcpy(oldurl,accurl);
-
if(strcmp(accuser,oldaccuser) != 0) {
strcpy(wdirname,dirname);
day_totalize(tmp,oldaccuser,indexonly);
+ strcpy(oldaccuser,accuser);
}
- strcpy(oldaccuser,accuser);
strcpy(oldacccode,acccode);
strcpy(oldaccip,accip);
+ strcpy(oldurl,accurl);
strcpy(oldaccdia,accdia);
strcpy(oldacchora,acchora);
}
- bzero(user,MAXLEN);
+ bzero(user,sizeof(user));
fclose(fp_in);
unlink(tmp3);
+ longline_free(&line);
}
closedir(dirp);
- strcpy(oldmsg,"OK");
if(strstr(oldacccode,"DENIED") != 0)
- sprintf(oldmsg,"%s",text[46]);
+ strcpy(oldmsg,text[46]);
+ else
+ strcpy(oldmsg,"OK");
strcpy(wdirname,dirname);
- if(strlen(oldaccuser) == 0)
+ if(oldaccuser[0] == '\0')
strcpy(oldaccuser,accuser);
gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
strcpy(wdirname,dirname);
FILE *fp_in, *fp_ou;
+ char *buf;
char user[MAXLEN];
- char url[MAXLEN];
+ char url[MAX_URL_LEN];
char wuser[MAXLEN];
- char ourl[MAXLEN];
+ char ourl[MAX_URL_LEN];
char csort[255];
char general[MAXLEN];
char general2[MAXLEN];
long long int nacc;
int cstatus;
struct getwordstruct gwarea;
+ struct longlinestruct line;
if(Privacy)
return;
}
strcpy(users," ");
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read file %s"),general2);
+ exit(1);
+ }
+
+ while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid user in the %s file of the siteuser.\n",general2);
continue;
}
- if(BlockIt[0]!='\0')
- sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",wwwDocumentRoot,BlockIt,ourl);
- else BlockImage[0]='\0';
-
if(strcmp(url,ourl) != 0 && nsitesusers) {
- if(BytesInSitesUsersReport) {
- sprintf(wwork2,"%s",fixnum(obytes,1));
- fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data\">%s</td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,wwork2,users);
- } else
- fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,users);
+ fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs);
+ if(BlockIt[0]!='\0') {
+ fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
+ output_html_url(fp_ou,ourl);
+ fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",fp_ou);
+ }
+ fputs("<a href=\"http://",fp_ou);
+ output_html_url(fp_ou,ourl);
+ fputs("\">",fp_ou);
+ output_html_string(fp_ou,ourl,100);
+ fputs("</a></td>",fp_ou);
+
+ if(BytesInSitesUsersReport)
+ fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(obytes,1));
+ fprintf(fp_ou,"<td class=\"data2\">%s</td></tr>\n",users);
+
regs++;
ucount=0;
strcpy(users,name);
}
}
fclose(fp_in);
+ longline_free(&line);
if(nsitesusers) {
- fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",regs,ourl,ourl,users);
+ fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://",regs);
+ output_html_url(fp_ou,ourl);
+ fputs("\">",fp_ou);
+ output_html_string(fp_ou,ourl,100);
+ fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></tr>\n",users);
}
unlink(general2);
free(users);
return;
-
}
char list[MAXLEN];
char wdata[127];
int idata=0;
+ char url[MAX_URL_LEN];
int i;
char *str;
struct getwordstruct gwarea;
if(debug) {
getword_start(&gwarea,text[7]);
- if (getword(urly,sizeof(urly),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
+ if (getword(url,sizeof(url),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s string.\n",text[7]);
exit(1);
}
- debuga("%s squidGuard %s: %s",urly,gwarea.current,wentp);
+ debuga("%s squidGuard %s: %s",url,gwarea.current,wentp);
}
/* With squidGuard, you can log groups in only one log file.
FILE *fp_in, *fp_ou;
- char url[MAXLEN];
- char ourl[MAXLEN];
+ char *buf;
+ char url[MAX_URL_LEN];
+ char ourl[MAX_URL_LEN];
char ntemp[255];
char ttnacc[20];
char ttnbytes[20];
int regs=0;
int cstatus;
struct getwordstruct gwarea;
+ struct longlinestruct line;
if(Privacy)
return;
exit(1);
}
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read file %s"),general2);
+ exit(1);
+ }
+
+ while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid user in your %s file of the topsites.\n",general2);
tnbytes+=nbytes;
tntime+=ntime;
}
+ fclose(fp_in);
+ unlink(general2);
+ longline_free(&line);
my_lltoa(tnacc,val1,15);
my_lltoa(tnbytes,val2,15);
my_lltoa(tntime,val3,15);
fprintf(fp_ou,"%s\t%s\t%s\t%s\n",val1,val2,val3,ourl);
- fclose(fp_in);
fclose(fp_ou);
- unlink(general2);
strlow(TopsitesSortField);
strlow(TopsitesSortType);
regs=0;
ntopsites = 0;
- while(regs<TopSitesNum && fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read file %s"),sites);
+ exit(1);
+ }
+
+ while(regs<TopSitesNum && (buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword_atoll(&nacc,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
strcpy(wwork2,fixnum(twork2,1));
strcpy(wwork3,fixtime(twork3));
- if(BlockIt[0] != '\0')
- sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",wwwDocumentRoot,BlockIt,url);
- else BlockImage[0]='\0';
+ fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2 link\">",regs);
+ if(BlockIt[0] != '\0') {
+ fprintf(fp_ou,"<a href=\"%s%s?url=\"",wwwDocumentRoot,BlockIt);
+ output_html_url(fp_ou,url);
+ fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",fp_ou);
+ }
- fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2 link\">%s<a href=\"http://%s\">%s</a></td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",regs,BlockImage,url,url,wwork1,wwork2,wwork3);
+ fputs("<a href=\"http://",fp_ou);
+ output_html_url(fp_ou,url);
+ fputs("\">",fp_ou);
+ output_html_string(fp_ou,url,100);
+ fprintf(fp_ou,"</a></td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",wwork1,wwork2,wwork3);
regs++;
}
fclose(fp_in);
+ longline_free(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
char sfield[10]="2,2";
char order[255]="-r";
char title[80];
+ char *warea;
+ char user2[MAXLEN];
+ char name[MAXLEN];
+ char ltext110[100];
int totuser=0;
int topcount=0;
+ int i;
char *s;
int cstatus;
- char warea[MAXLEN];
- char user2[MAXLEN];
- char name[MAXLEN];
struct getwordstruct gwarea;
+ struct longlinestruct line;
ipantes[0]='\0';
nameantes[0]='\0';
olduser[0]='\0';
totuser=0;
- while(fgets(warea,sizeof(warea),fp_in)) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read the file %s"),wger);
+ exit(1);
+ }
+
+ while((warea=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,warea);
if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
exit(1);
}
- if (getword(url,sizeof(url),&gwarea,'\t')<0) {
+ if (getword_skip(MAX_URL_LEN,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
exit(1);
}
tnoucache+=oucac;
}
fclose(fp_in);
+ longline_free(&line);
if (olduser[0] != '\0') {
my_lltoa(tnbytes,val1,15);
ntopuser = 0;
- while(fgets(warea,sizeof(warea),fp_top1)) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read the downloaded files"));
+ exit(1);
+ }
+
+ while((warea=longline_read(fp_top1,&line))!=NULL) {
getword_start(&gwarea,warea);
if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
}
if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) {
- sprintf(ltext110,"%s",text[110]);
- for(s=ltext110; *s; ++s)
- *s=tolower(*s);
+ s=text[110];
+ for(i=0 ; i<sizeof(ltext110)-1 && s[i] ; i++)
+ ltext110[i]=tolower(s[i]);
+ ltext110[i]='\0';
fputs("<td class=\"data2\">",fp_top3);
#ifdef HAVE_GD
if(Graphs) {
}
fclose(fp_top1);
unlink(top1);
+ longline_free(&line);
if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) {
fputs("<tr>",fp_top3);
long long int nacc, nbytes;
long long int elap;
long long int incac, oucac;
- char wger[MAXLEN], user[MAXLEN], url[MAXLEN];
+ char wger[MAXLEN], user[MAXLEN], url[MAX_URL_LEN];
char ip[MAXLEN], hora[9], data[15];
- char warea[MAXLEN];
+ char *warea;
struct getwordstruct gwarea;
+ struct longlinestruct line;
strcpy(wger,dirname);
strcat(wger,"/sarg-general");
exit(1);
}
- while(fgets(warea,sizeof(warea),fp_in))
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read the temporary file %s"),wger);
+ exit(1);
+ }
+
+ while((warea=longline_read(fp_in,&line))!=NULL)
{
//printf("%s\n",warea);
getword_start(&gwarea,warea);
}
fclose(fp_in);
+ longline_free(&line);
strcpy(wger,dirname);
strcat(wger,"/sarg-general");
/*
- * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
- * 1998, 2010
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
+ * 1998, 2010
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
+ * Support:
+ * http://sourceforge.net/projects/sarg/forums/forum/363374
* ---------------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
#include "include/defs.h"
#if defined(HAVE_BACKTRACE)
-#define USE_GETWORD_BACKTRACE 0
+#define USE_GETWORD_BACKTRACE 1
#else
#define USE_GETWORD_BACKTRACE 0
#endif
+#define INITIAL_LINE_BUFFER_SIZE 32768
+
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.
fputs("</body>\n</html>\n",fp_ou);
}
-void output_html_string(FILE *fp_ou,const char *str)
+void output_html_string(FILE *fp_ou,const char *str,int maxlen)
{
+ int i=0;
- while (*str) {
+ while (*str && (maxlen<=0 || i<maxlen)) {
switch (*str) {
case '&':
fputs("&",fp_ou);
fputc(*str,fp_ou);
}
str++;
+ i++;
+ }
+ if (maxlen>0 && i>=maxlen)
+ fputs("…",fp_ou);
+}
+
+void output_html_url(FILE *fp_ou,const char *url)
+{
+ while (*url) {
+ if (*url=='&')
+ fputs("&",fp_ou);
+ else
+ fputc(*url,fp_ou);
+ url++;
}
}
}
}
}
+
+int longline_prepare(struct longlinestruct *line)
+{
+ line->size=INITIAL_LINE_BUFFER_SIZE;
+ line->buffer=malloc(line->size);
+ if (!line->buffer)
+ return(-1);
+ line->start=0;
+ line->end=0;
+ line->length=0;
+ return(0);
+}
+
+char *longline_read(FILE *fp_in,struct longlinestruct *line)
+{
+ int i;
+ int skipcr;
+ char *newbuf;
+ size_t nread;
+
+ if (!line->buffer) return(NULL);
+ if (feof(fp_in)) return(NULL);
+
+ line->start=line->end;
+ skipcr=1;
+ while (skipcr || (line->buffer[line->end]!='\n' && line->buffer[line->end]!='\r')) {
+ if (line->end>=line->length) {
+ if (line->start>0) {
+ for (i=line->start ; i<line->end ; i++)
+ line->buffer[i-line->start]=line->buffer[i];
+ line->length-=line->start;
+ line->end-=line->start;
+ line->start=0;
+ }
+ if (line->length>=line->size) {
+ line->size+=8192;
+ newbuf=realloc(line->buffer,line->size);
+ if (!newbuf) {
+ debuga(_("Not enough memory to read one more line from the input log file"));
+ exit(1);
+ }
+ line->buffer=newbuf;
+ }
+ nread=fread(line->buffer+line->end,1,line->size-line->end,fp_in);
+ if (nread==0) {
+ if (line->end<=line->start) return(NULL);
+ if (line->end>=line->size) {
+ line->size++;
+ newbuf=realloc(line->buffer,line->size);
+ if (!newbuf) {
+ debuga(_("Not enough memory to read one more line from the input log file"));
+ exit(1);
+ }
+ line->buffer=newbuf;
+ }
+ line->buffer[line->end]='\0';
+ return(line->buffer+line->start);
+ }
+ line->length+=nread;
+ }
+ if (skipcr && line->buffer[line->end]!='\n' && line->buffer[line->end]!='\r') {
+ skipcr=0;
+ line->start=line->end;
+ }
+ line->end++;
+ }
+ line->buffer[line->end++]='\0';
+ return(line->buffer+line->start);
+}
+
+void longline_free(struct longlinestruct *line)
+{
+ if (line->buffer) {
+ free(line->buffer);
+ line->buffer=NULL;
+ }
+}