]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Move longline module to a separate file
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 17 Mar 2010 13:29:48 +0000 (13:29 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 17 Mar 2010 13:29:48 +0000 (13:29 +0000)
CMakeLists.txt
Makefile.in
documentation/longline.txt [new file with mode: 0644]
documentation/util.txt
include/defs.h
longline.c [new file with mode: 0644]
splintrc
util.c

index e7c988ddae00055d72f3abe2e15dc05a56b8cbb7..775ca6fe36dac8eadd0b567a3b610d6ead62e6df 100755 (executable)
@@ -53,7 +53,7 @@ SET(SRC util.c log.c report.c topuser.c email.c sort.c html.c
        smartfilter.c denied.c authfail.c charset.c
        squidguard_log.c squidguard_report.c auth.c download.c grepday.c
        dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c
-       usertab.c userinfo.c)
+       usertab.c userinfo.c longline.c)
 
 FOREACH(f ${SRC})
    ADD_FILE_DEPENDENCIES(${f} ${CMAKE_BINARY_DIR}/config.h ${CMAKE_SOURCE_DIR}/include/conf.h ${CMAKE_SOURCE_DIR}/include/info.h ${CMAKE_SOURCE_DIR}/include/defs.h)
index d481fb98405066ea3f577e7e1b34a1ea0dc75927..29c95f3f707ee02deb6bc84fc0ae20f1572ff37c 100644 (file)
@@ -38,7 +38,7 @@ SRCS = util.c log.c report.c topuser.c email.c sort.c html.c \
        smartfilter.c denied.c authfail.c charset.c \
        squidguard_log.c squidguard_report.c auth.c download.c grepday.c \
        dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c \
-       usertab.c userinfo.c
+       usertab.c userinfo.c longline.c
 
 OBJS = $(patsubst %.c,%.o,$(SRCS))
 
diff --git a/documentation/longline.txt b/documentation/longline.txt
new file mode 100644 (file)
index 0000000..95d8359
--- /dev/null
@@ -0,0 +1,59 @@
+/*! \file util.c
+\brief Various useful functions.
+*/
+
+
+/*! \def INITIAL_LINE_BUFFER_SIZE
+The initial buffer size to allocate to read a long line from a text file.
+*/
+
+
+
+
+
+
+/*! \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.
+*/
index 5a4ed044a33bf4e9fd80a1f55607a4e1720572ee..1f1c242ca473d2b5ab01b99b3a27f511983f4552 100644 (file)
@@ -6,13 +6,6 @@
 
 
 
-/*! \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.
 */
@@ -889,52 +882,3 @@ Delete a directory and its content.
 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.
-*/
index ed95ca072dff62d94499cd3ad9fcdd3c0c0984a0..750c7b6e472938cd2441ead68287ad0cfafe35f9 100755 (executable)
@@ -181,10 +181,10 @@ void usage(const char *prog);
 void useragent(void);
 
 // userinfo.c
-struct userinfostruct *userinfo_create(const char *userid);
+/*@shared@*/struct userinfostruct *userinfo_create(const char *userid);
 void userinfo_free(void);
-struct userinfostruct *userinfo_find_from_file(const char *filename);
-struct userinfostruct *userinfo_find_from_id(const char *id);
+/*@shared@*/struct userinfostruct *userinfo_find_from_file(const char *filename);
+/*@shared@*/struct userinfostruct *userinfo_find_from_id(const char *id);
 
 // usertab.c
 void init_usertab(const char *UserTabFile);
diff --git a/longline.c b/longline.c
new file mode 100644 (file)
index 0000000..4ca20de
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#include "include/conf.h"
+#include "include/defs.h"
+
+#define INITIAL_LINE_BUFFER_SIZE 32768
+
+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;
+   char *newbuf;
+   size_t nread;
+
+   if (!line->buffer) return(NULL);
+
+   while (1) {
+      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);
+      if (nread==0) return(NULL);
+      line->length=nread;
+      line->end=0;
+   }
+
+   line->start=line->end;
+   while (1) {
+      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;
+
+      if (line->start>0) {
+         for (i=line->start ; i<line->length ; 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\n"));
+            exit(EXIT_FAILURE);
+         }
+         line->buffer=newbuf;
+      }
+      nread=(feof(fp_in)) ? 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) {
+            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\n"));
+               exit(EXIT_FAILURE);
+            }
+            line->buffer=newbuf;
+         }
+         line->buffer[line->end]='\0';
+         return(line->buffer+line->start);
+      }
+      line->length+=nread;
+   }
+   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;
+   }
+}
index 673aa93184971d70a0ccde816cf069e7f15e6fd5..151099f8d18bd8ccad0f872f4fac6369ab738d1a 100644 (file)
--- a/splintrc
+++ b/splintrc
@@ -55,3 +55,4 @@
 -DRLIM_STRING="%d"
 -DICONV_CONST
 -DHAVE_LC_MESSAGES=1
+-D__GNUC__
diff --git a/util.c b/util.c
index 96dec5e7f9882e081a2dfa15daa57f11e414e045..35b8f552364ed07ab487583e57df2fcb6e262af2 100644 (file)
--- a/util.c
+++ b/util.c
@@ -36,8 +36,6 @@
 #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.
@@ -1664,85 +1662,3 @@ void unlinkdir(const char *dir,int contentonly)
    }
 }
 
-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;
-   char *newbuf;
-   size_t nread;
-
-   if (!line->buffer) return(NULL);
-
-   while (1) {
-      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);
-      if (nread==0) return(NULL);
-      line->length=nread;
-      line->end=0;
-   }
-
-   line->start=line->end;
-   while (1) {
-      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;
-
-      if (line->start>0) {
-         for (i=line->start ; i<line->length ; 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\n"));
-            exit(EXIT_FAILURE);
-         }
-         line->buffer=newbuf;
-      }
-      nread=(feof(fp_in)) ? 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) {
-            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\n"));
-               exit(EXIT_FAILURE);
-            }
-            line->buffer=newbuf;
-         }
-         line->buffer[line->end]='\0';
-         return(line->buffer+line->start);
-      }
-      line->length+=nread;
-   }
-   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;
-   }
-}