int cstatus;
bool new_user;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
struct userinfostruct *uinfo;
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",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE"));
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read file %s\n"),authfail_in);
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ while((buf=longline_read(fp_in,line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,'\t')<0) {
debuga(_("There is a broken date in file %s\n"),authfail_in);
fputs("</a></td></th>\n",fp_ou);
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
int ourl_size;
struct getwordstruct gwarea;
struct userinfostruct *uinfo;
- struct longlinestruct line;
+ longline line;
const char logext[]=".log";
ipantes[0]='\0';
exit(EXIT_FAILURE);
}
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the downloaded files.\n"));
exit(EXIT_FAILURE);
}
ttopen=0;
new_user=1;
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ 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(accip,sizeof(accip),&gwarea,'\t')<0 ||
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
}
(void)closedir( dirp );
if (oldurl) free(oldurl);
int count=0;
int new_user;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
struct userinfostruct *uinfo;
ouser[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",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE"));
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the denied accesses\n"));
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ 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) {
fputs("</a></td></tr>\n",fp_ou);
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
-/*! \fn int longline_prepare(struct longlinestruct *line)
+/*! \fn longline longline_create(void)
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().
+\return The object create by the function. It must be freed
+with a call to longline_destroy().
+*/
+
+
+
+
-\param line The buffer to initialize.
+/*! \fn void longline_reset(longline line)
+Reset the internal state of the object to start a new reading on a new file.
-\retval 0 No error.
-\retval -1 Not enough memory.
+\param line The object created by longline_create().
*/
-/*! \fn char *longline_read(FILE *fp_in,struct longlinestruct *line)
+/*! \fn char *longline_read(FILE *fp_in,longline 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.
Any empty line is skipped.
\param fp_in The file to read.
-\param line The buffer initialized by longline_preapre().
+\param line The object created by longline_create().
\return A pointer to the beginning of the string in the buffer or NULL if it is
the last string read.
-/*! \fn void longline_free(struct longlinestruct *line)
-Free the memory allocated by longline_prepare().
+/*! \fn void longline_destroy(longline line)
+Free the memory allocated by longline_create().
-\param line The buffer to free.
+\param line The object to destroy.
*/
int i;
int new_user;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
struct userinfostruct *uinfo;
ouser[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",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE"));
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the downloaded files\n"));
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ 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) {
fputs("</a></td></tr>\n",fp_ou);
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
int dlen;
char siteind[MAX_TRUNCATED_URL];
struct getwordstruct gwarea;
- struct longlinestruct line,line1;
+ longline line,line1;
struct generalitemstruct item;
const struct userinfostruct *uinfo;
debuga(_("(html2) Cannot open file %s\n"),arqper);
exit(EXIT_FAILURE);
}
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read file %s\n"),arqper);
exit(EXIT_FAILURE);
}
ttnacc=0;
totbytes=0;
totelap=0;
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ while((buf=longline_read(fp_in,line))!=NULL) {
ger_read(buf,&item,arqper);
if(item.total) {
ttnacc+=item.nacc;
}
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
snprintf(arqper,sizeof(arqper),"%s/sarg-users",outdirname);
if ((fp_in = fopen(arqper, "r")) == 0){
exit(EXIT_FAILURE);
}
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read file %s\n"),arqin);
exit(EXIT_FAILURE);
}
tnelap=0;
tnincache=0;
tnoucache=0;
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ while((buf=longline_read(fp_in,line))!=NULL) {
getword_start(&gwarea,buf);
if (getword_atoll(<emp,&gwarea,'\t')<0) {
debuga(_("There is a broken number of access in file %s\n"),arqin);
debuga(_("Making report: %s\n"),uinfo->id);
}
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ while((buf=longline_read(fp_in,line))!=NULL) {
getword_start(&gwarea,buf);
if (getword_atoll(&twork,&gwarea,'\t')<0) {
debuga(_("Maybe you have a broken number of access in your %s file\n"),arqin);
exit(EXIT_FAILURE);
}
- if (longline_prepare(&line1)<0) {
+ if ((line1=longline_create())==NULL) {
debuga(_("Not enough memory to read file %s\n"),arqip);
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_ip,&line1))!=NULL) {
+ while((buf=longline_read(fp_ip,line1))!=NULL) {
if(strstr(buf,url) != 0)
fputs(buf,fp_ip2);
}
- longline_free(&line1);
+ longline_destroy(&line1);
fclose(fp_ip);
fclose(fp_ip2);
olduserip[0]='\0';
- if (longline_prepare(&line1)<0) {
+ if ((line1=longline_create())==NULL) {
debuga(_("Not enough memory to read file %s\n"),arqip);
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_ip,&line1))!=NULL) {
+ while((buf=longline_read(fp_ip,line1))!=NULL) {
getword_start(&gwarea,buf);
if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3);
}
fclose(fp_ip);
- longline_free(&line1);
+ longline_destroy(&line1);
unlink(tmp2);
unlink(tmp3);
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
if(iprel)
unlink(arqip);
int modified;
};
-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;
-};
+typedef struct longlinestruct *longline;
struct generalitemstruct
{
// lastlog.c
void mklastlog(const char *outdir);
+// longline.c
+/*@null@*//*@only@*/longline longline_create(void);
+void longline_reset(longline line);
+/*@null@*/char *longline_read(FILE *fp_in,/*@null@*/longline line);
+void longline_destroy(/*@out@*//*@only@*//*@null@*/longline *line_ptr);
+
// index.c
void make_index(void);
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(/*@out@*/struct longlinestruct *line);
-char *longline_read(FILE *fp_in,struct longlinestruct *line);
-void longline_free(struct longlinestruct *line);
int download_flag=0;
char *download_url=NULL;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
struct userinfostruct *uinfo;
struct userfilestruct *first_user_file, *ufile, *ufile1, *prev_ufile;
init_usertab(UserTabFile);
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read a log file\n"));
exit(EXIT_FAILURE);
}
if(ShowReadStatistics && !from_stdin) {
size_t nread,i;
int skipcr=0;
+ char tmp4[MAXLEN];
recs1=0UL;
recs2=0UL;
- while ((nread=fread(line.buffer,1,line.size,fp_in))>0) {
+ while ((nread=fread(tmp4,1,sizeof(tmp4),fp_in))>0) {
for (i=0 ; i<nread ; i++)
if (skipcr) {
- if (line.buffer[i]!='\n' && line.buffer[i]!='\r') {
+ if (tmp4[i]!='\n' && tmp4[i]!='\r') {
skipcr=0;
}
} else {
- if (line.buffer[i]=='\n' || line.buffer[i]=='\r') {
+ if (tmp4[i]=='\n' || tmp4[i]=='\r') {
skipcr=1;
recs1++;
}
fflush( stdout ) ;
}
- line.start=0;
- line.end=0;
- line.length=0;
+ longline_reset(line);
- while ((linebuf=longline_read(fp_in,&line))!=NULL) {
+ while ((linebuf=longline_read(fp_in,line))!=NULL) {
blen=strlen(linebuf);
if (ilf==ILF_Unknown) {
}
}
- longline_free(&line);
+ longline_destroy(&line);
if ( fp_Download_Unsort )
fclose (fp_Download_Unsort);
#define INITIAL_LINE_BUFFER_SIZE 32768
-int longline_prepare(struct longlinestruct *line)
+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;
+};
+
+longline longline_create(void)
+{
+ longline line;
+
+ line=malloc(sizeof(*line));
+ if (line==NULL) return(NULL);
line->size=INITIAL_LINE_BUFFER_SIZE;
line->buffer=malloc(line->size);
- if (!line->buffer)
- return(-1);
+ if (line->buffer==NULL) {
+ free(line);
+ return(NULL);
+ }
line->start=0;
line->end=0;
line->length=0;
- return(0);
+ return(line);
}
-char *longline_read(FILE *fp_in,struct longlinestruct *line)
+void longline_reset(longline line)
+{
+ if (line!=NULL) {
+ line->start=0;
+ line->end=0;
+ line->length=0;
+ }
+}
+
+char *longline_read(FILE *fp_in,longline line)
{
int i;
char *newbuf;
size_t nread;
- if (!line->buffer) return(NULL);
+ if (line==NULL || line->buffer==NULL) return(NULL);
- while (1) {
+ while (true) {
for (i=line->end ; i<line->length && (line->buffer[i]=='\n' || line->buffer[i]=='\r') ; i++);
if (i<line->length) {
line->end=i;
break;
}
- nread=(feof(fp_in)) ? 0 : fread(line->buffer,1,line->size,fp_in);
+ nread=(feof(fp_in)!=0) ? 0 : fread(line->buffer,1,line->size,fp_in);
if (nread==0) return(NULL);
line->length=nread;
line->end=0;
}
line->start=line->end;
- while (1) {
+ while (true) {
for (i=line->end ; i<line->length && line->buffer[i]!='\n' && line->buffer[i]!='\r' ; i++);
line->end=i;
if (line->end<line->length) break;
}
line->buffer=newbuf;
}
- nread=(feof(fp_in)) ? 0 : fread(line->buffer+line->length,1,line->size-line->length,fp_in);
+ nread=(feof(fp_in)!=0) ? 0 : fread(line->buffer+line->length,1,line->size-line->length,fp_in);
if (nread==0) {
if (line->end<=line->start) return(NULL);
if (line->end>=line->size) {
return(line->buffer+line->start);
}
-void longline_free(struct longlinestruct *line)
+void longline_destroy(longline *line_ptr)
{
- if (line->buffer) {
- free(line->buffer);
- line->buffer=NULL;
- }
+ longline line;
+
+ if (line_ptr==NULL || *line_ptr==NULL) return;
+ line=*line_ptr;
+ *line_ptr=NULL;
+ if (line->buffer!=NULL) free(line->buffer);
+ free(line);
}
char *buf;
int fd1,fd2;
int cstatus;
- struct longlinestruct line;
+ longline line;
init_usertab(UserTabFile);
exit(EXIT_FAILURE);
}
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the log file\n"));
exit(EXIT_FAILURE);
}
sprintf(cmd,"tail -%d %s",realtime_access_log_lines,AccessLog[0]);
fp = popen(cmd, "r");
- while((buf=longline_read(fp,&line)) != NULL )
+ while((buf=longline_read(fp,line)) != NULL )
if (getdata(buf,tmp)<0) {
debuga(_("Maybe a broken record or garbage was returned by %s\n"),cmd);
exit(EXIT_FAILURE);
}
pclose(fp);
fclose(tmp);
- longline_free(&line);
+ longline_destroy(&line);
sprintf(cmd,"sort -r -k 1,1 -k 2,2 -o \"%s\" \"%s\"",template2,template1);
cstatus=system(cmd);
int url_len;
int ourl_size=0;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
if((fin=fopen(tmp,"r"))==NULL) {
debuga(_("(realtime) open error %s - %s\n"),tmp,strerror(errno));
header();
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the log file\n"));
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fin,&line))!=NULL) {
+ while((buf=longline_read(fin,line))!=NULL) {
fixendofline(buf);
getword_start(&gwarea,buf);
if (getword(dat,sizeof(dat),&gwarea,'\t')<0) {
}
strcpy(ourl,url);
}
- longline_free(&line);
+ longline_destroy(&line);
if (ourl) free(ourl);
puts("</table>\n</div>\n</body>\n</html>\n");
int same_url;
int new_user;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
struct userinfostruct *uinfo,*puinfo;
ipantes[0]='\0';
memset(oldacchoratt,0,sizeof(oldacchoratt));
new_user=1;
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the downloaded files\n"));
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ 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(accip,sizeof(accip),&gwarea,'\t')<0 ||
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
if (oldurltt) free(oldurltt);
unlink(tmp3);
}
char *users;
long long int obytes;
int cstatus;
- struct longlinestruct line;
+ longline line;
struct generalitemstruct item;
const struct userinfostruct *uinfo;
}
strcpy(users," ");
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read file %s\n"),general2);
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ while((buf=longline_read(fp_in,line))!=NULL) {
ger_read(buf,&item,general2);
if(item.total) continue;
uinfo=userinfo_find_from_id(item.user);
}
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
if(nsitesusers) {
fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://",regs);
int url_len;
int ourl_size=0;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
struct generalitemstruct item;
if(Privacy)
exit(EXIT_FAILURE);
}
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read file %s\n"),general2);
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ while((buf=longline_read(fp_in,line))!=NULL) {
ger_read(buf,&item,general2);
if(item.total) continue;
}
fclose(fp_in);
unlink(general2);
- longline_free(&line);
+ longline_destroy(&line);
if (ourl) {
fprintf(fp_ou,"%lld\t%lld\t%lld\t%s\n",tnacc,tnbytes,tntime,ourl);
regs=0;
ntopsites = 0;
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read file %s\n"),sites);
exit(EXIT_FAILURE);
}
- while(regs<TopSitesNum && (buf=longline_read(fp_in,&line))!=NULL) {
+ while(regs<TopSitesNum && (buf=longline_read(fp_in,line))!=NULL) {
getword_start(&gwarea,buf);
if (getword_atoll(&nacc,&gwarea,'\t')<0) {
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),sites);
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);
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
char *s;
int cstatus;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
struct generalitemstruct item;
const struct userinfostruct *uinfo;
olduser[0]='\0';
totuser=0;
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the file %s\n"),wger);
exit(EXIT_FAILURE);
}
- while((warea=longline_read(fp_in,&line))!=NULL) {
+ while((warea=longline_read(fp_in,line))!=NULL) {
ger_read(warea,&item,wger);
if(item.total) continue;
if(strcmp(olduser,item.user) != 0) {
tnoucache+=item.oucache;
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
if (olduser[0] != '\0') {
fprintf(fp_top2,"%s\t%lld\t%lld\t%lld\t%lld\t%lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
ntopuser = 0;
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the downloaded files\n"));
exit(EXIT_FAILURE);
}
- while((warea=longline_read(fp_top1,&line))!=NULL) {
+ while((warea=longline_read(fp_top1,line))!=NULL) {
getword_start(&gwarea,warea);
if (getword(user,sizeof(user),&gwarea,'\t')<0) {
debuga(_("There is a broken user in file %s\n"),top1);
}
fclose(fp_top1);
unlink(top1);
- longline_free(&line);
+ longline_destroy(&line);
if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) {
fputs("<tr>",fp_top3);
long long int tincache=0, toucache=0;
char wger[MAXLEN];
char *warea;
- struct longlinestruct line;
+ longline line;
struct generalitemstruct item;
snprintf(wger,sizeof(wger),"%s/sarg-general",dirname);
exit(EXIT_FAILURE);
}
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the temporary file %s\n"),wger);
exit(EXIT_FAILURE);
}
- while((warea=longline_read(fp_in,&line))!=NULL)
+ while((warea=longline_read(fp_in,line))!=NULL)
{
ger_read(warea,&item,wger);
tnacc+=item.nacc;
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
if((fp_ou=fopen(wger,"a"))==NULL) {
debuga(_("(totger) Cannot open file %s\n"),wger);
long long int med=0;
long long int twork=0;
struct getwordstruct gwarea;
- struct longlinestruct line;
+ longline line;
twork=0;
tbytes[0]='\0';
}
}
- if (longline_prepare(&line)<0) {
+ if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the file %s\n"),wdir);
exit(EXIT_FAILURE);
}
- while((buf=longline_read(fp_in,&line))!=NULL) {
+ while((buf=longline_read(fp_in,line))!=NULL) {
if (strncmp(buf,"TOTAL\t",6) == 0)
sep='\t'; //new file
else if (strncmp(buf,"TOTAL ",6) == 0)
break;
}
fclose(fp_in);
- longline_free(&line);
+ longline_destroy(&line);
if(nuser <= 0) {
strcpy(media,"0");