]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Mimic an opaque object to read long lines
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 17 Mar 2010 19:11:02 +0000 (19:11 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 17 Mar 2010 19:11:02 +0000 (19:11 +0000)
16 files changed:
authfail.c
datafile.c
denied.c
documentation/longline.txt
download.c
html.c
include/defs.h
log.c
longline.c
realtime.c
report.c
siteuser.c
topsites.c
topuser.c
totger.c
util.c

index e8b3deec81fe0bf2b493f12683e2dba62a1b4db3..693444fcedaf73881bc4a04b7f44745ea7386fe7 100644 (file)
@@ -52,7 +52,7 @@ void authfail_report(void)
    int  cstatus;
    bool new_user;
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   longline line;
    struct userinfostruct *uinfo;
 
    if(DataFile[0] != '\0') return;
@@ -112,12 +112,12 @@ void authfail_report(void)
    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);
@@ -192,7 +192,7 @@ void authfail_report(void)
       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);
index 082a4007c2948a0569099ff9f068cb251356728e..5756204c68d50ea1b63280cc004c4ff663ffde58 100644 (file)
@@ -63,7 +63,7 @@ void data_file(char *tmp)
    int ourl_size;
    struct getwordstruct gwarea;
    struct userinfostruct *uinfo;
-   struct longlinestruct line;
+   longline line;
    const char logext[]=".log";
 
    ipantes[0]='\0';
@@ -112,14 +112,14 @@ void data_file(char *tmp)
          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 ||
@@ -211,7 +211,7 @@ void data_file(char *tmp)
       }
 
       fclose(fp_in);
-      longline_free(&line);
+      longline_destroy(&line);
    }
    (void)closedir( dirp );
    if (oldurl) free(oldurl);
index aac0c062f5de7ffb84b979d4ea2d855fcdc71197..a12625670cf5aaf48e7598b40f0e4ea307573603 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -49,7 +49,7 @@ void gen_denied_report(void)
    int  count=0;
    int new_user;
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   longline line;
    struct userinfostruct *uinfo;
 
    ouser[0]='\0';
@@ -94,12 +94,12 @@ void gen_denied_report(void)
    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) {
@@ -163,7 +163,7 @@ void gen_denied_report(void)
       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);
index 95d8359eda416dd66d43e19b519ff445d6a71df4..01cf9032f56d43d5d8613e9bb9c994ca83045b3f 100644 (file)
@@ -12,23 +12,28 @@ The initial buffer size to allocate to read a long line from a text file.
 
 
 
-/*! \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.
 
@@ -39,7 +44,7 @@ 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().
+\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.
@@ -52,8 +57,8 @@ with an error message.
 
 
 
-/*! \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.
 */
index 6f550b50a26e553e65fa979d2d528fc75c14aa60..2e379dfbdc532bece64603f1f41a424f53bf41e8 100644 (file)
@@ -54,7 +54,7 @@ void download_report(void)
    int i;
    int new_user;
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   longline line;
    struct userinfostruct *uinfo;
 
    ouser[0]='\0';
@@ -99,12 +99,12 @@ void download_report(void)
    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) {
@@ -169,7 +169,7 @@ void download_report(void)
       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);
diff --git a/html.c b/html.c
index 5ab1ab4a6673a4df3e3e708d8e6a5182651d1106..e0119c353f3abd0437eaf4fcd4070a2ab3a2f3aa 100644 (file)
--- a/html.c
+++ b/html.c
@@ -60,7 +60,7 @@ void htmlrel(void)
    int dlen;
    char siteind[MAX_TRUNCATED_URL];
    struct getwordstruct gwarea;
-   struct longlinestruct line,line1;
+   longline line,line1;
    struct generalitemstruct item;
    const struct userinfostruct *uinfo;
 
@@ -88,14 +88,14 @@ void htmlrel(void)
       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;
@@ -104,7 +104,7 @@ void htmlrel(void)
       }
    }
    fclose(fp_in);
-   longline_free(&line);
+   longline_destroy(&line);
 
    snprintf(arqper,sizeof(arqper),"%s/sarg-users",outdirname);
    if ((fp_in = fopen(arqper, "r")) == 0){
@@ -175,7 +175,7 @@ void htmlrel(void)
          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);
       }
@@ -185,7 +185,7 @@ void htmlrel(void)
       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(&ltemp,&gwarea,'\t')<0) {
             debuga(_("There is a broken number of access in file %s\n"),arqin);
@@ -266,7 +266,7 @@ void htmlrel(void)
          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);
@@ -377,15 +377,15 @@ void htmlrel(void)
                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);
@@ -405,11 +405,11 @@ void htmlrel(void)
 
             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);
@@ -450,7 +450,7 @@ void htmlrel(void)
             }
 
             fclose(fp_ip);
-            longline_free(&line1);
+            longline_destroy(&line1);
 
             unlink(tmp2);
             unlink(tmp3);
@@ -465,7 +465,7 @@ void htmlrel(void)
       }
 
       fclose(fp_in);
-      longline_free(&line);
+      longline_destroy(&line);
 
       if(iprel)
          unlink(arqip);
index 750c7b6e472938cd2441ead68287ad0cfafe35f9..b0246d264d162b9e6bce91cb6257ad26705417ba 100755 (executable)
@@ -9,19 +9,7 @@ struct getwordstruct
    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
 {
@@ -129,6 +117,12 @@ void name2ip(char *name);
 // 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);
 
@@ -253,6 +247,3 @@ void baddata(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);
diff --git a/log.c b/log.c
index 9b06f4276c7886ee4fb31ee951b5527a6e74fc72..d439a1d429d705f95f550e644f4fc89b881ec612 100644 (file)
--- a/log.c
+++ b/log.c
@@ -147,7 +147,7 @@ int main(int argc,char *argv[])
    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;
 
@@ -686,7 +686,7 @@ int main(int argc,char *argv[])
 
    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);
    }
@@ -735,18 +735,19 @@ int main(int argc,char *argv[])
       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++;
                   }
@@ -758,11 +759,9 @@ int main(int argc,char *argv[])
          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) {
@@ -1486,7 +1485,7 @@ int main(int argc,char *argv[])
       }
    }
 
-   longline_free(&line);
+   longline_destroy(&line);
    if ( fp_Download_Unsort )
      fclose (fp_Download_Unsort);
 
index 4ca20de77406ba23e8d337c43f5b19d114ecf371..04aceb433fb34a736b2a61d4f0555881e87cc083 100644 (file)
 
 #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;
@@ -82,7 +111,7 @@ char *longline_read(FILE *fp_in,struct longlinestruct *line)
          }
          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) {
@@ -104,10 +133,13 @@ char *longline_read(FILE *fp_in,struct longlinestruct *line)
    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);
 }
index 81ee8dffbd5adad899d432fb3a74b785654f5e84..0fa8439739fe93e0972c8ce1607eabbdf1dda881 100755 (executable)
@@ -48,7 +48,7 @@ static void getlog(void)
    char *buf;
    int  fd1,fd2;
    int cstatus;
-   struct longlinestruct line;
+   longline line;
 
    init_usertab(UserTabFile);
 
@@ -60,21 +60,21 @@ static void getlog(void)
        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);
@@ -191,7 +191,7 @@ static void datashow(const char *tmp)
    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));
@@ -200,12 +200,12 @@ static void datashow(const char *tmp)
 
    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) {
@@ -260,7 +260,7 @@ static void datashow(const char *tmp)
       }
       strcpy(ourl,url);
    }
-   longline_free(&line);
+   longline_destroy(&line);
    if (ourl) free(ourl);
 
    puts("</table>\n</div>\n</body>\n</html>\n");
index e17911b737735bc6f254f8aee43625c98429dace..5943768dfa1207a3926c6c260f8da4b3cc2d38e8 100644 (file)
--- a/report.c
+++ b/report.c
@@ -77,7 +77,7 @@ void gerarel(void)
    int same_url;
    int new_user;
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   longline line;
    struct userinfostruct *uinfo,*puinfo;
 
    ipantes[0]='\0';
@@ -153,12 +153,12 @@ void gerarel(void)
       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 ||
@@ -336,7 +336,7 @@ void gerarel(void)
 
       }
       fclose(fp_in);
-      longline_free(&line);
+      longline_destroy(&line);
       if (oldurltt) free(oldurltt);
       unlink(tmp3);
    }
index 13a57b75891ed8ef68cbb3b9fd60e89dcd4a6a0a..6b04660a301eb03d7b7b4c64ead1175c455947bf 100644 (file)
@@ -49,7 +49,7 @@ void siteuser(void)
    char *users;
    long long int obytes;
    int cstatus;
-   struct longlinestruct line;
+   longline line;
    struct generalitemstruct item;
    const struct userinfostruct *uinfo;
 
@@ -115,12 +115,12 @@ void siteuser(void)
    }
    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);
@@ -196,7 +196,7 @@ void siteuser(void)
       }
    }
    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);
index 9e424aeeadea98322c20542122408ed4f0e1d12d..567aab4d1be10354355f7a8d1f6c878228256032 100644 (file)
@@ -57,7 +57,7 @@ void topsites(void)
    int url_len;
    int ourl_size=0;
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   longline line;
    struct generalitemstruct item;
 
    if(Privacy)
@@ -104,12 +104,12 @@ void topsites(void)
      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;
 
@@ -150,7 +150,7 @@ void topsites(void)
    }
    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);
@@ -212,12 +212,12 @@ void topsites(void)
    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);
@@ -256,7 +256,7 @@ void topsites(void)
       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);
index 73d23391ff236cbf0ca8db0b3b419f54cb9ebd0c..f6769cc59fc26f323563c614b03a2665ff3c30da 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -56,7 +56,7 @@ void topuser(void)
    char *s;
    int cstatus;
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   longline line;
    struct generalitemstruct item;
    const struct userinfostruct *uinfo;
 
@@ -102,12 +102,12 @@ void topuser(void)
    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) {
@@ -137,7 +137,7 @@ void topuser(void)
       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);
@@ -242,12 +242,12 @@ void topuser(void)
 
    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);
@@ -346,7 +346,7 @@ void topuser(void)
    }
    fclose(fp_top1);
    unlink(top1);
-   longline_free(&line);
+   longline_destroy(&line);
 
    if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) {
       fputs("<tr>",fp_top3);
index 74bc110b14705e7f2dddd065b6fee838d0a74255..24890515abb2bfb8237eead07a11aaaa2622f022 100644 (file)
--- a/totger.c
+++ b/totger.c
@@ -36,7 +36,7 @@ int totalger(const char *dirname, int debug, const char *outdir)
    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);
@@ -46,12 +46,12 @@ int totalger(const char *dirname, int debug, const char *outdir)
       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;
@@ -62,7 +62,7 @@ int totalger(const char *dirname, int debug, const char *outdir)
    }
 
    fclose(fp_in);
-   longline_free(&line);
+   longline_destroy(&line);
 
    if((fp_ou=fopen(wger,"a"))==NULL) {
      debuga(_("(totger) Cannot open file %s\n"),wger);
diff --git a/util.c b/util.c
index 35b8f552364ed07ab487583e57df2fcb6e262af2..d453149bad62587e9edf83deafa33633e4e60962 100644 (file)
--- a/util.c
+++ b/util.c
@@ -768,7 +768,7 @@ void obttotal(const char *dirname, const char *name, char *tbytes, int nuser, ch
    long long int med=0;
    long long int twork=0;
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   longline line;
 
    twork=0;
    tbytes[0]='\0';
@@ -782,12 +782,12 @@ void obttotal(const char *dirname, const char *name, char *tbytes, int nuser, ch
       }
    }
 
-   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)
@@ -813,7 +813,7 @@ void obttotal(const char *dirname, const char *name, char *tbytes, int nuser, ch
       break;
    }
    fclose(fp_in);
-   longline_free(&line);
+   longline_destroy(&line);
 
    if(nuser <= 0) {
       strcpy(media,"0");