From: Frédéric Marchal Date: Tue, 13 Oct 2009 08:18:33 +0000 (+0000) Subject: Documentation of grepday.c. X-Git-Tag: v2_2_6~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c274f011f72dec78de4b7b28f861507a8e4edd93;p=thirdparty%2Fsarg.git Documentation of grepday.c. Fixed inconsequential memory leaks that clutered the valgrind reports. Added more warning options at compile time. Fixed the warnings highlighted by -Wextra. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7be88a0..fca7c35 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION 2) SET(sarg_BUILD "6rc1") -SET(sarg_BUILDDATE "Oct-12-2009") +SET(sarg_BUILDDATE "Oct-13-2009") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) @@ -247,7 +247,7 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "solaris") OPTION(ENABLE_EXTRA_PROTECT "Enable compile and runtime extra protections" OFF) IF(ENABLE_EXTRA_PROTECT) - SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAG "${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror") + SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAG "${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter") ENDIF(ENABLE_EXTRA_PROTECT) # Save the configuration for the project diff --git a/configure b/configure index 5928d75..9518577 100755 --- a/configure +++ b/configure @@ -6462,7 +6462,7 @@ echo "using $IMAGEDIR as the directory of the images" if test "${enable_extraprotection+set}" = set; then enableval=$enable_extraprotection; if test "$enableval"; then - CFLAGS="${CFLAGS} -Werror=format-security -fstack-protector -Werror" + CFLAGS="${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter" fi else diff --git a/configure.in b/configure.in index 0b43315..dabbc0a 100644 --- a/configure.in +++ b/configure.in @@ -154,7 +154,7 @@ AC_ARG_ENABLE(extraprotection, Enable compile and runtime extra protections ], [ if test "$enableval"; then - CFLAGS="${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror" + CFLAGS="${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter" fi ],[IMAGEDIR="${datarootdir}/sarg/images"]) echo "using $IMAGEDIR as the directory of the images" diff --git a/documentation/grepday.txt b/documentation/grepday.txt new file mode 100644 index 0000000..ade174a --- /dev/null +++ b/documentation/grepday.txt @@ -0,0 +1,62 @@ +/*!\file grepday.c +\brief Produce the graphics of the reports. +*/ + + +/*! \def SARGgdImageStringFT +Link to the proper function to draw a text on the GD image depending on the version of libgd. +*/ + + + + + +/*! \var static char *font1; +The name of the TTF font file to use to draw the text on the GD image. +*/ + + + + + +/*! \fn char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, + double ptsize, double angle, int x, int y, char *string) +Draw a text on the GD image after converting the current character set defined by ::CharSet into UTF-8 +as requested by libgd. + +\param im The GD image to draw the text on. +\param brect A variable to store the bounding rectangle of the text. +\param fg The color to render the text. +\param fontlist The name of the font to use to render the text. +\param ptsize A scale factor to scale the text. +\param angle The angle to rotate the text counter-clockwise in radian. +\param x The X position of the text on the image. +\param y The Y position of the text on the image. +\param string The string to write. + +\return The return code of \c gdImageStringFTEx. It is NULL on success or an error +string on failure. + +\note See the official documentation of gdImageStringFT at http://www.libgd.org/Font#char_.2AgdImageStringFT.28gdImagePtr_im.2C_int_.2Abrect.2C_int_fg.2C_char_.2Afontname.2C_double_ptsize.2C_double_angle.2C_int_x.2C_int_y.2C_char_.2Astring.29_.28FUNCTION.29 +*/ + + + + + +/*! \fn static void bar(int x1,long long int n) +Draw one bar of the graph. + +\param x1 The X position of the bar. +\param n The height of the bar. +*/ + + + + + +/*! \fn void greport_day(const char *user) +Draw the graphic of the report for the user. + +\param user The name of the user for which to draw the graphic. +*/ diff --git a/grepday.c b/grepday.c index 656cafa..916df8c 100644 --- a/grepday.c +++ b/grepday.c @@ -26,26 +26,24 @@ #include "include/conf.h" #include "include/defs.h" -int blue; -int white; -int lavender; -int darkblue; -int dimgray; -int goldenrod; -int goldenrod2; -int gray; -int silver; -int black; -int x1; -//char *font1 = FONTDIR"/FreeSans.ttf"; -char *font1 = FONTDIR"/DejaVuSans.ttf"; -char s[15]; +static int blue; +static int white; +static int lavender; +static int darkblue; +static int dimgray; +static int goldenrod; +static int goldenrod2; +static int gray; +static int silver; +static int black; +//static char *font1 = FONTDIR"/FreeSans.ttf"; +static char *font1 = FONTDIR"/DejaVuSans.ttf"; #if defined(HAVE_GD) && defined(HAVE_ICONV_H) && defined(gdFTEX_Unicode) #include #define SARGgdImageStringFT I18NgdImageStringFT -char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, +static char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, double ptsize, double angle, int x, int y, char *string) { iconv_t localtoutf; @@ -76,7 +74,7 @@ char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, #define SARGgdImageStringFT gdImageStringFT #endif -void bar(long long int n) +static void bar(int x1,long long int n) { #ifdef HAVE_GD gdPoint points[4]; @@ -236,6 +234,7 @@ void greport_day(const char *user) { FILE *fp_in, *pngout; int x, y; + int x1; int brect[8]; char wdirname[MAXLEN]; char graph[MAXLEN]; @@ -250,6 +249,8 @@ void greport_day(const char *user) time_t t; struct tm *local; int cstatus; + char s[15]; + #ifdef HAVE_GD if(strcmp(Graphs,"yes") != 0) { @@ -450,7 +451,7 @@ void greport_day(const char *user) if(strcmp(oday,day) != 0) { strcpy(warea,oday); x1 = 44 +(atoi(oday) * 20); - bar(tot); + bar(x1,tot); strcpy(oday,day); tot=0; } @@ -459,7 +460,7 @@ void greport_day(const char *user) if(tot) { x1 = 44 +(atoi(day) * 20); - bar(tot); + bar(x1,tot); } gdImagePng(im, pngout); @@ -474,3 +475,10 @@ void greport_day(const char *user) return; } + +void greport_cleanup(void) +{ +#ifdef HAVE_GD + gdFontCacheShutdown(); +#endif +} diff --git a/html.c b/html.c index 4328642..4a91342 100644 --- a/html.c +++ b/html.c @@ -751,6 +751,7 @@ void htmlrel(void) (void)rewinddir(dirp); (void)closedir(dirp); + greport_cleanup(); return; } diff --git a/include/defs.h b/include/defs.h index 9ecba63..39ce32d 100755 --- a/include/defs.h +++ b/include/defs.h @@ -44,6 +44,7 @@ void getconf(void); // grepday.c void greport_day(const char *user); +void greport_cleanup(void); // html.c void htmlrel(void); diff --git a/include/info.h b/include/info.h index 8f3d68e..1ba848d 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Oct-12-2009" +#define VERSION PACKAGE_VERSION" Oct-13-2009" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/log.c b/log.c index 84ceb0a..b120d17 100644 --- a/log.c +++ b/log.c @@ -440,7 +440,7 @@ int main(int argc,char *argv[]) strcpy(ImageFile,"../../../images"); dataonly=0; - if(DataFile[0] != '\0'); + if(DataFile[0] != '\0') dataonly++; subs(TopUserFields,sizeof(TopUserFields),"%BYTES","SETYB"); diff --git a/report.c b/report.c index b231400..9fbafe6 100644 --- a/report.c +++ b/report.c @@ -368,8 +368,11 @@ void gerarel(void) index_only(wdirname, debug); } + /* + 2009-10-13(Frederic) This piece of code is never called so it is commented out for good. if(strlen(email) < 0) removetmp(dirname); + */ return; } diff --git a/squidguard_log.c b/squidguard_log.c index 3629dde..51abe24 100644 --- a/squidguard_log.c +++ b/squidguard_log.c @@ -282,6 +282,12 @@ void squidguard_log(void) if (fp_guard) fclose(fp_guard); if (fp_ou) fclose(fp_ou); + if (files_done) { + for (y=0; y