From: Amos Jeffries Date: Mon, 1 Nov 2010 05:44:28 +0000 (-0600) Subject: Bug 3038: Detatch libmisc from libcompat X-Git-Tag: take1~123 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25f983407b3c3df95d9f81edf1bd917316f2dfda;p=thirdparty%2Fsquid.git Bug 3038: Detatch libmisc from libcompat * Migrates many of the remaining libmisc portability wrappers into libcompat. * Splits libmisc into: libprofiler - Squid internal profiler (developer-only) libmiscencoding - Various binary encoding / crypto algorithms libmisccontainers - Various data container algorithms * Makes all binaries which need to link the libmisc* pieces directly instead of via $(COMPAT_LIB) which now only links the libcompat and internal profiler due to profiling being used on some libcompat functions. * Adds a stub_debug for binaries needing the Debug.h API without squid timers and globals. Some effort has been made to identify binaries whose dependencies can be reduced. More of this dependency removal can be done in future. --- diff --git a/Makefile.am b/Makefile.am index 344cc3c975..d839afef42 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,12 +2,12 @@ # AUTOMAKE_OPTIONS = dist-bzip2 subdir-objects 1.5 foreign -DIST_SUBDIRS = compat lib libltdl snmplib scripts src icons errors contrib doc helpers test-suite tools +DIST_SUBDIRS = compat lib libltdl snmplib scripts icons errors contrib doc helpers src test-suite tools SUBDIRS = compat lib $(makesnmplib) if USE_LOADABLE_MODULES SUBDIRS += libltdl endif -SUBDIRS += scripts src icons errors doc helpers test-suite tools +SUBDIRS += scripts icons errors doc helpers src tools test-suite DISTCLEANFILES = include/stamp-h include/stamp-h[0-9]* DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'` diff --git a/compat/Makefile.am b/compat/Makefile.am index 03494f72a4..3d7fc2c3e6 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -11,16 +11,21 @@ include $(top_srcdir)/src/Common.am noinst_LIBRARIES = libcompat-squid.a libcompat_squid_a_SOURCES = \ + assert.cc \ assert.h \ + compat.cc \ compat.h \ compat_shared.h \ cpu.h \ + debug.cc \ debug.h \ drand48.h \ eui64_aton.h \ fdsetsize.h \ getaddrinfo.h \ getnameinfo.h \ + GnuRegex.c \ + GnuRegex.h \ inet_ntop.h \ inet_pton.h \ initgroups.h \ @@ -33,6 +38,14 @@ libcompat_squid_a_SOURCES = \ types.h \ unsafe.h \ valgrind.h \ + xalloc.cc \ + xalloc.h \ + xstrerror.cc \ + xstrerror.h \ + xstring.cc \ + xstring.h \ + xstrto.cc \ + xstrto.h \ \ os/aix.h \ os/dragonfly.h \ @@ -49,13 +62,7 @@ libcompat_squid_a_SOURCES = \ os/sgi.h \ os/solaris.h \ os/sunos.h \ - os/windows.h \ - \ - assert.cc \ - compat.cc \ - debug.cc \ - GnuRegex.h \ - GnuRegex.c + os/windows.h libcompat_squid_a_LIBADD= $(LIBOBJS) diff --git a/compat/compat.cc b/compat/compat.cc index e69de29bb2..e36ae43794 100644 --- a/compat/compat.cc +++ b/compat/compat.cc @@ -0,0 +1,4 @@ +#include "config.h" +#include "compat.h" + +void (*failure_notify) (const char *) = NULL; diff --git a/compat/compat_shared.h b/compat/compat_shared.h index 35fdabb6f2..f5d00ee1ab 100644 --- a/compat/compat_shared.h +++ b/compat/compat_shared.h @@ -17,6 +17,17 @@ * of the requirements for wrapping your hack for safe portability. */ +/* + * Define an error display handler override. + * If error_notify is set by the linked program it will be used by the local + * portability functions. Otherwise perror() will be used. + */ +#ifdef __cplusplus +extern "C" +#else +extern +#endif +void (*failure_notify) (const char *); /* * sys/resource.h and sys/time.h are apparently order-dependant. @@ -194,5 +205,13 @@ extern "C" { #endif #endif +/* + * Several function definitions which we provide for security and code safety. + */ +#include "compat/xalloc.h" +#include "compat/xstrerror.h" +#include "compat/xstring.h" +#include "compat/xstrto.h" + #endif /* _SQUID_COMPAT_SHARED_H */ diff --git a/compat/os/mswin.h b/compat/os/mswin.h index 35751b919f..d01f57c8a8 100644 --- a/compat/os/mswin.h +++ b/compat/os/mswin.h @@ -238,6 +238,10 @@ struct timezone { typedef char * caddr_t; +#ifndef _PATH_DEVNULL +#define _PATH_DEVNULL "NUL" +#endif + #undef FD_CLOSE #undef FD_OPEN #undef FD_READ diff --git a/compat/xalloc.cc b/compat/xalloc.cc new file mode 100644 index 0000000000..ee04da3697 --- /dev/null +++ b/compat/xalloc.cc @@ -0,0 +1,228 @@ +#include "config.h" +#include "compat/xalloc.h" +#include "profiler/Profiler.h" + +#if XMALLOC_STATISTICS +#define XMS_DBG_MAXSIZE (1024*1024) +#define XMS_DBG_SPLIT (256) /* mallocs below this value are tracked with DBG_GRAIN_SM precision instead of DBG_GRAIN */ +#define XMS_DBG_GRAIN (16) +#define XMS_DBG_GRAIN_SM (4) +#define XMS_DBG_OFFSET (XMS_DBG_SPLIT/XMS_DBG_GRAIN_SM - XMS_DBG_SPLIT/XMS_DBG_GRAIN ) +#define XMS_DBG_MAXINDEX (XMS_DBG_MAXSIZE/XMS_DBG_GRAIN + XMS_DBG_OFFSET) +static int malloc_sizes[XMS_DBG_MAXINDEX + 1]; +static int malloc_histo[XMS_DBG_MAXINDEX + 1]; +static int dbg_stat_init = 0; + +static int +XMS_DBG_INDEX(int sz) +{ + if (sz >= XMS_DBG_MAXSIZE) + return XMS_DBG_MAXINDEX; + + if (sz <= XMS_DBG_SPLIT) + return (sz + XMS_DBG_GRAIN_SM - 1) / XMS_DBG_GRAIN_SM; + + return (sz + XMS_DBG_GRAIN - 1) / XMS_DBG_GRAIN + XMS_DBG_OFFSET; +} + +static void +stat_init(void) +{ + for (int i = 0; i <= XMS_DBG_MAXINDEX; i++) + malloc_sizes[i] = malloc_histo[i] = 0; + + dbg_stat_init = 1; +} + +static int +malloc_stat(int sz) +{ + if (!dbg_stat_init) + stat_init(); + + return malloc_sizes[XMS_DBG_INDEX(sz)] += 1; +} + +void +malloc_statistics(void (*func) (int, int, int, void *), void *data) +{ + int i = 0; + + for (; i <= XMS_DBG_SPLIT; i += XMS_DBG_GRAIN_SM) + func(i, malloc_sizes[XMS_DBG_INDEX(i)], malloc_histo[XMS_DBG_INDEX(i)], data); + + i -= XMS_DBG_GRAIN_SM; + + for (; i <= XMS_DBG_MAXSIZE; i += XMS_DBG_GRAIN) + func(i, malloc_sizes[XMS_DBG_INDEX(i)], malloc_histo[XMS_DBG_INDEX(i)], data); + + xmemcpy(&malloc_histo, &malloc_sizes, sizeof(malloc_sizes)); +} +#endif /* XMALLOC_STATISTICS */ + +void * +xcalloc(size_t n, size_t sz) +{ + PROF_start(xcalloc); + + if (n < 1) + n = 1; + + if (sz < 1) + sz = 1; + + PROF_start(calloc); + void *p = calloc(n, sz); + PROF_stop(calloc); + + if (p == NULL) { + if (failure_notify) { + static char msg[128]; + snprintf(msg, 128, "xcalloc: Unable to allocate %Zu blocks of %Zu bytes!\n", n, sz); + (*failure_notify) (msg); + } else { + perror("xcalloc"); + } + exit(1); + } + +#if XMALLOC_DEBUG + check_malloc(p, sz * n); +#endif +#if XMALLOC_STATISTICS + malloc_stat(sz * n); +#endif +#if XMALLOC_TRACE + xmalloc_show_trace(p, 1); +#endif +#if MEM_GEN_TRACE + if (tracefp) + fprintf(tracefp, "c:%u:%u:%p\n", (unsigned int) n, (unsigned int) sz, p); +#endif + + PROF_stop(xcalloc); + return p; +} + +void * +xmalloc(size_t sz) +{ + PROF_start(xmalloc); + + if (sz < 1) + sz = 1; + + PROF_start(malloc); + void *p = malloc(sz); + PROF_stop(malloc); + + if (p == NULL) { + if (failure_notify) { + static char msg[128]; + snprintf(msg, 128, "xmalloc: Unable to allocate %Zu bytes!\n", sz); + (*failure_notify) (msg); + } else { + perror("malloc"); + } + exit(1); + } + +#if XMALLOC_DEBUG + check_malloc(p, sz); +#endif +#if XMALLOC_STATISTICS + malloc_stat(sz); +#endif +#if XMALLOC_TRACE + xmalloc_show_trace(p, 1); +#endif +#if MEM_GEN_TRACE + if (tracefp) + fprintf(tracefp, "m:%d:%p\n", sz, p); +#endif + + PROF_stop(xmalloc); + return (p); +} + +void * +xrealloc(void *s, size_t sz) +{ + PROF_start(xrealloc); +#if XMALLOC_TRACE + xmalloc_show_trace(s, -1); +#endif + + if (sz < 1) + sz = 1; + +#if XMALLOC_DEBUG + if (s != NULL) + check_free(s); +#endif + PROF_start(realloc); + void *p= realloc(s, sz); + PROF_stop(realloc); + + if (p == NULL) { + if (failure_notify) { + static char msg[128]; + snprintf(msg, 128, "xrealloc: Unable to reallocate %Zu bytes!\n", sz); + (*failure_notify) (msg); + } else { + perror("realloc"); + } + + exit(1); + } + +#if XMALLOC_DEBUG + check_malloc(p, sz); +#endif +#if XMALLOC_STATISTICS + malloc_stat(sz); +#endif +#if XMALLOC_TRACE + xmalloc_show_trace(p, 1); +#endif +#if MEM_GEN_TRACE + if (tracefp) /* new ptr, old ptr, new size */ + fprintf(tracefp, "r:%p:%p:%d\n", p, s, sz); +#endif + PROF_stop(xrealloc); + return (p); +} + +void +xfree(void *s) +{ + if (s == NULL) + return; + + free_const(s); +} + +void +free_const(const void *s_const) +{ + void *s = const_cast(s_const); + + PROF_start(free_const); +#if XMALLOC_TRACE + xmalloc_show_trace(s, -1); +#endif + +#if XMALLOC_DEBUG + check_free(s); +#endif + + PROF_start(free); + free(s); + PROF_stop(free); + +#if MEM_GEN_TRACE + if (tracefp) + fprintf(tracefp, "f:%p\n", s); +#endif + PROF_stop(free_const); +} diff --git a/compat/xalloc.h b/compat/xalloc.h new file mode 100644 index 0000000000..14cb5dd65e --- /dev/null +++ b/compat/xalloc.h @@ -0,0 +1,74 @@ +#ifndef _SQUID_COMPAT_XALLOC_H +#define _SQUID_COMPAT_XALLOC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * xcalloc() - same as calloc(3). Used for portability. + * Never returns NULL; fatal on error. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +void *xcalloc(size_t n, size_t sz); + +/** + * xmalloc() - same as malloc(3). Used for portability. + * Never returns NULL; fatal on error. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +void *xmalloc(size_t sz); + +/** + * xrealloc() - same as realloc(3). Used for portability. + * Never returns NULL; fatal on error. + */ +void *xrealloc(void *s, size_t sz); + +/** + * xfree() - same as free(3). Used for portability. + * Will not call free(3) if s == NULL. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +void xfree(void *s); + +/** + * xxfree() / free_const() - Same as free(3). Used for portability. + * Accepts pointers to dynamically allocated const data. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +void free_const(const void *s); + +/// Backward compatibility alias for free_const(const void *s) +#define xxfree(x) free_const((x)) + +/** + * Accepts pointers to dynamically allocated const data. + * Will not call free(3) if the pointer is NULL. + * Sets the pointer to NULL on completion. + * + * Use xfree() if the pointer does not need to be set afterward. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +#define safe_free(x) if ((x)) { xxfree((x)); (x) = NULL; } else (void)0 + + +#if XMALLOC_STATISTICS +void malloc_statistics(void (*func) (int, int, int, void *), void *data); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _SQUID_COMPAT_XALLOC_H */ diff --git a/compat/xstrerror.cc b/compat/xstrerror.cc new file mode 100644 index 0000000000..0cf722d1e3 --- /dev/null +++ b/compat/xstrerror.cc @@ -0,0 +1,20 @@ +#include "config.h" +#include "compat/xstrerror.h" + +#if HAVE_STRING_H +#include +#endif + +const char * +xstrerr(int error) +{ + static char xstrerror_buf[BUFSIZ]; + const char *errmsg = strerror(error); + + if (!errmsg || !*errmsg) + errmsg = "Unknown error"; + + snprintf(xstrerror_buf, BUFSIZ, "(%d) %s", error, errmsg); + + return xstrerror_buf; +} diff --git a/compat/xstrerror.h b/compat/xstrerror.h new file mode 100644 index 0000000000..8a55f166cb --- /dev/null +++ b/compat/xstrerror.h @@ -0,0 +1,16 @@ +#ifndef _SQUID_COMPAT_XSTRERROR_H +#define _SQUID_COMPAT_XSTRERROR_H + +/** strerror() wrapper replacement. + * + * Provides the guarantee that a string is always returned. + * Where strerror() would have provided NULL this will report the error as unknown. + */ +#define xstrerror() xstrerr(errno) + +/** Provide the textual display of a system error number. + * A string is always returned. + */ +extern const char * xstrerr(int error); + +#endif /* _SQUID_COMPAT_XSTRERROR_H */ diff --git a/compat/xstring.cc b/compat/xstring.cc new file mode 100644 index 0000000000..1e8376cace --- /dev/null +++ b/compat/xstring.cc @@ -0,0 +1,80 @@ +#include "config.h" +#include "compat/xalloc.h" +#include "compat/xstring.h" + +#if HAVE_ERRNO_H +#include +#endif + +char * +xstrdup(const char *s) +{ + size_t sz; + char *p; + + if (s == NULL) { + if (failure_notify) { + (*failure_notify) ("xstrdup: tried to dup a NULL pointer!\n"); + } else { + errno = EINVAL; + perror("xstrdup: tried to dup a NULL pointer!"); + } + exit(1); + } + + /* copy string, including terminating character */ + sz = strlen(s) + 1; + p = (char *)xmalloc(sz); + memcpy(p, s, sz); + + return p; +} + +char * +xstrncpy(char *dst, const char *src, size_t n) +{ + char *r = dst; + + if (!n || !dst) + return dst; + + if (src) + while (--n != 0 && *src != '\0') + *dst++ = *src++; + + *dst = '\0'; + return r; +} + +char * +xstrndup(const char *s, size_t n) +{ + size_t sz; + char *p; + + if (s == NULL) { + errno = EINVAL; + if (failure_notify) { + (*failure_notify) ("xstrndup: tried to dup a NULL pointer!\n"); + } else { + perror("xstrndup: tried to dup a NULL pointer!"); + } + exit(1); + } + if (n < 0) { + errno = EINVAL; + if (failure_notify) { + (*failure_notify) ("xstrndup: tried to dup a negative length string!\n"); + } else { + perror("xstrndup: tried to dup a negative length string!"); + } + exit(1); + } + + sz = strlen(s) + 1; + if (sz > n) + sz = n; + + p = xstrncpy((char *)xmalloc(sz), s, sz); + return p; +} diff --git a/compat/xstring.h b/compat/xstring.h new file mode 100644 index 0000000000..4c8d71ad60 --- /dev/null +++ b/compat/xstring.h @@ -0,0 +1,57 @@ +#ifndef _SQUID_COMPAT_XSTRING_H +#define _SQUID_COMPAT_XSTRING_H + +#if HAVE_STRING_H +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * xstrdup() - same as strdup(3). Used for portability. + * Never returns NULL; fatal on error. + * + * Sets errno to EINVAL if a NULL pointer is passed. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +char *xstrdup(const char *s); + +#ifdef strdup +#undef strdup +#endif +#define strdup(X) xstrdup((X)) + +/* + * xstrncpy() - similar to strncpy(3) but terminates string + * always with '\0' if (n != 0 and dst != NULL), + * and doesn't do padding + */ +char *xstrncpy(char *dst, const char *src, size_t n); + +/** + * xstrndup() - same as strndup(3). Used for portability. + * Never returns NULL; fatal on error. + * + * Sets errno to EINVAL if a NULL pointer or negative + * length is passed. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +char *xstrndup(const char *s, size_t n); + +#ifdef strndup +#undef strndup +#endif +#define strndup(X) xstrndup((X)) + + +#ifdef __cplusplus +} +#endif + +#endif /* _SQUID_COMPAT_XSTRING_H */ diff --git a/lib/xstrto.cc b/compat/xstrto.cc similarity index 99% rename from lib/xstrto.cc rename to compat/xstrto.cc index dcbd03247a..20bdeddab8 100644 --- a/lib/xstrto.cc +++ b/compat/xstrto.cc @@ -29,7 +29,7 @@ */ #include "config.h" -#include "xstrto.h" +#include "compat/xstrto.h" /* * (C) 2000-2006 by the netfilter coreteam : diff --git a/include/xstrto.h b/compat/xstrto.h similarity index 100% rename from include/xstrto.h rename to compat/xstrto.h diff --git a/configure.in b/configure.in index 3e64fe0b15..981889715b 100644 --- a/configure.in +++ b/configure.in @@ -2185,6 +2185,7 @@ AC_CHECK_HEADERS( \ bstring.h \ cassert \ crypt.h \ + cstdlib \ cstring \ ctype.h \ errno.h \ @@ -3304,6 +3305,7 @@ AC_CONFIG_FILES([\ compat/Makefile \ lib/Makefile \ lib/ntlmauth/Makefile \ + lib/profiler/Makefile \ lib/rfcnb/Makefile \ lib/smblib/Makefile \ scripts/Makefile \ diff --git a/helpers/basic_auth/MSNT/Makefile.am b/helpers/basic_auth/MSNT/Makefile.am index 6d74bd6472..9237952c16 100644 --- a/helpers/basic_auth/MSNT/Makefile.am +++ b/helpers/basic_auth/MSNT/Makefile.am @@ -29,6 +29,7 @@ CXXFLAGS += -DSYSCONFDIR=\"$(sysconfdir)\" LDADD = \ $(top_builddir)/lib/smblib/libsmblib.la \ $(top_builddir)/lib/rfcnb/librfcnb.la \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(XTRA_LIBS) diff --git a/helpers/basic_auth/NCSA/Makefile.am b/helpers/basic_auth/NCSA/Makefile.am index 1e0226a280..d89f6ee366 100644 --- a/helpers/basic_auth/NCSA/Makefile.am +++ b/helpers/basic_auth/NCSA/Makefile.am @@ -5,10 +5,12 @@ basic_ncsa_auth_SOURCES = basic_ncsa_auth.cc crypt_md5.cc crypt_md5.h man_MANS = basic_ncsa_auth.8 EXTRA_DIST = basic_ncsa_auth.8 config.test LDADD = \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(CRYPTLIB) \ - $(XTRA_LIBS) \ - $(SSLLIB) + $(SSLLIB) \ + $(XTRA_LIBS) ## we need our local files too (but avoid -I. at all costs) INCLUDES += -I$(srcdir) diff --git a/helpers/basic_auth/NCSA/basic_ncsa_auth.cc b/helpers/basic_auth/NCSA/basic_ncsa_auth.cc index 19fb48e383..bdd7311f94 100644 --- a/helpers/basic_auth/NCSA/basic_ncsa_auth.cc +++ b/helpers/basic_auth/NCSA/basic_ncsa_auth.cc @@ -37,6 +37,9 @@ #if HAVE_CRYPT_H #include #endif +#if HAVE_ERRNO_H +#include +#endif static hash_table *hash = NULL; static HASHFREE my_free; diff --git a/helpers/basic_auth/NIS/Makefile.am b/helpers/basic_auth/NIS/Makefile.am index 79791ee52d..1680500c9f 100644 --- a/helpers/basic_auth/NIS/Makefile.am +++ b/helpers/basic_auth/NIS/Makefile.am @@ -11,6 +11,7 @@ basic_nis_auth_SOURCES = \ nis_support.cc basic_nis_auth_LDADD = \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(CRYPTLIB) \ $(XTRA_LIBS) diff --git a/helpers/basic_auth/PAM/Makefile.am b/helpers/basic_auth/PAM/Makefile.am index b7a294a53a..d1dbf3c57e 100644 --- a/helpers/basic_auth/PAM/Makefile.am +++ b/helpers/basic_auth/PAM/Makefile.am @@ -6,6 +6,7 @@ libexec_PROGRAMS = basic_pam_auth basic_pam_auth_SOURCES = basic_pam_auth.cc basic_pam_auth_LDADD = \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ -lpam \ $(XTRA_LIBS) diff --git a/helpers/basic_auth/RADIUS/Makefile.am b/helpers/basic_auth/RADIUS/Makefile.am index 85745704c8..b6e32241a4 100644 --- a/helpers/basic_auth/RADIUS/Makefile.am +++ b/helpers/basic_auth/RADIUS/Makefile.am @@ -13,6 +13,7 @@ basic_radius_auth_SOURCES = \ radius-util.h basic_radius_auth_LDADD = \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(SSLLIB) \ $(XTRA_LIBS) diff --git a/helpers/basic_auth/getpwnam/Makefile.am b/helpers/basic_auth/getpwnam/Makefile.am index 0819be60df..21047fdffb 100644 --- a/helpers/basic_auth/getpwnam/Makefile.am +++ b/helpers/basic_auth/getpwnam/Makefile.am @@ -4,6 +4,7 @@ libexec_PROGRAMS = basic_getpwnam_auth basic_getpwnam_auth_SOURCES = basic_getpwnam_auth.cc basic_getpwnam_auth_LDADD = \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(CRYPTLIB) diff --git a/helpers/basic_auth/getpwnam/basic_getpwnam_auth.cc b/helpers/basic_auth/getpwnam/basic_getpwnam_auth.cc index c05f2e04d5..7e57b2e59f 100644 --- a/helpers/basic_auth/getpwnam/basic_getpwnam_auth.cc +++ b/helpers/basic_auth/getpwnam/basic_getpwnam_auth.cc @@ -27,7 +27,7 @@ #include "config.h" #include "helpers/defines.h" #include "rfc1738.h" -#include "util.h" +//#include "util.h" #if HAVE_STDIO_H #include diff --git a/helpers/defines.h b/helpers/defines.h index 9cd7fbcd08..57823acf80 100644 --- a/helpers/defines.h +++ b/helpers/defines.h @@ -8,8 +8,6 @@ #define HELPER_INPUT_BUFFER 8196 -#define safe_free(x) if (x) { free(x); x = NULL; } - /* send OK result to Squid with a string parameter. */ #define SEND_OK(x) fprintf(stdout, "OK %s\n",x) diff --git a/helpers/digest_auth/file/Makefile.am b/helpers/digest_auth/file/Makefile.am index f0206a419e..9ed0c15445 100644 --- a/helpers/digest_auth/file/Makefile.am +++ b/helpers/digest_auth/file/Makefile.am @@ -11,6 +11,8 @@ digest_file_auth_SOURCES = digest_file_auth.cc \ text_backend.h LDADD = \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(CRYPTLIB) \ $(SSLLIB) \ diff --git a/helpers/external_acl/file_userip/Makefile.am b/helpers/external_acl/file_userip/Makefile.am index af5813efa6..90c915d374 100644 --- a/helpers/external_acl/file_userip/Makefile.am +++ b/helpers/external_acl/file_userip/Makefile.am @@ -11,5 +11,6 @@ EXTRA_DIST = \ config.test LDADD = \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(XTRA_LIBS) diff --git a/helpers/external_acl/unix_group/Makefile.am b/helpers/external_acl/unix_group/Makefile.am index 532bf71288..16c7dbc6ef 100644 --- a/helpers/external_acl/unix_group/Makefile.am +++ b/helpers/external_acl/unix_group/Makefile.am @@ -6,5 +6,6 @@ EXTRA_DIST = ext_unix_group_acl.8 config.test ext_unix_group_acl_SOURCES = check_group.cc LDADD = \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(XTRA_LIBS) diff --git a/helpers/ntlm_auth/fake/Makefile.am b/helpers/ntlm_auth/fake/Makefile.am index 8cb2b7fb04..97d198e41b 100644 --- a/helpers/ntlm_auth/fake/Makefile.am +++ b/helpers/ntlm_auth/fake/Makefile.am @@ -5,6 +5,7 @@ ntlm_fake_auth_SOURCES = ntlm_fake_auth.cc ntlm_fake_auth_LDADD = \ $(top_builddir)/lib/ntlmauth/libntlmauth.la \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(CRYPTLIB) \ $(XTRA_LIBS) diff --git a/helpers/ntlm_auth/fake/ntlm_fake_auth.cc b/helpers/ntlm_auth/fake/ntlm_fake_auth.cc index 816a6ae71d..85b7761528 100644 --- a/helpers/ntlm_auth/fake/ntlm_fake_auth.cc +++ b/helpers/ntlm_auth/fake/ntlm_fake_auth.cc @@ -54,10 +54,11 @@ #define IGNORANCE_IS_BLISS #include "config.h" +#include "base64.h" #include "helpers/defines.h" #include "ntlmauth/ntlmauth.h" #include "ntlmauth/support_bits.cci" -#include "util.h" +//#include "util.h" #if HAVE_CTYPE_H #include diff --git a/helpers/ntlm_auth/smb_lm/Makefile.am b/helpers/ntlm_auth/smb_lm/Makefile.am index 78bae08f73..5f60194623 100644 --- a/helpers/ntlm_auth/smb_lm/Makefile.am +++ b/helpers/ntlm_auth/smb_lm/Makefile.am @@ -7,6 +7,7 @@ ntlm_smb_lm_auth_LDADD = \ $(top_builddir)/lib/smblib/libsmblib.la \ $(top_builddir)/lib/rfcnb/librfcnb.la \ $(top_builddir)/lib/ntlmauth/libntlmauth.la \ + $(top_builddir)/lib/libmiscencoding.la \ $(COMPAT_LIB) \ $(CRYPTLIB) \ $(XTRA_LIBS) diff --git a/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc b/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc index 36f1845f9b..6319e30565 100644 --- a/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc +++ b/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.cc @@ -14,12 +14,13 @@ * */ #include "config.h" +#include "base64.h" #include "compat/debug.h" #include "ntlmauth/ntlmauth.h" #include "ntlmauth/support_bits.cci" #include "rfcnb/rfcnb.h" #include "smblib/smblib.h" -#include "util.h" +//#include "util.h" #if HAVE_STRING_H #include diff --git a/include/SquidNew.h b/include/SquidNew.h index e30f7b46c1..74c92135c0 100644 --- a/include/SquidNew.h +++ b/include/SquidNew.h @@ -33,7 +33,7 @@ #ifndef SQUID_NEW_H #define SQUID_NEW_H -#include "util.h" +#include "config.h" #ifndef __SUNPRO_CC /* Any code using libstdc++ must have externally resolvable overloads @@ -50,7 +50,7 @@ _SQUID_EXTERNNEW_ void *operator new(size_t size) throw (std::bad_alloc) } _SQUID_EXTERNNEW_ void operator delete (void *address) throw() { - xfree (address); + xfree(address); } _SQUID_EXTERNNEW_ void *operator new[] (size_t size) throw (std::bad_alloc) { @@ -58,7 +58,7 @@ _SQUID_EXTERNNEW_ void *operator new[] (size_t size) throw (std::bad_alloc) } _SQUID_EXTERNNEW_ void operator delete[] (void *address) throw() { - xfree (address); + xfree(address); } diff --git a/include/base64.h b/include/base64.h new file mode 100644 index 0000000000..82766109dd --- /dev/null +++ b/include/base64.h @@ -0,0 +1,15 @@ +#ifndef _SQUID_BASE64_H +#define _SQUID_BASE64_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern char *base64_decode(const char *coded); +extern const char *base64_encode(const char *decoded); +extern const char *base64_encode_bin(const char *data, int len); + +#ifdef __cplusplus +} +#endif +#endif /* _SQUID_BASE64_H */ diff --git a/include/charset.h b/include/charset.h new file mode 100644 index 0000000000..5d385b2108 --- /dev/null +++ b/include/charset.h @@ -0,0 +1,12 @@ +#ifndef _SQUID_CHARSET_H +#define _SQUID_CHARSET_H + +#ifdef __cplusplus +extern "C" +#else +extern +#endif + +char *latin1_to_utf8(char *out, size_t size, const char *in); + +#endif /* _SQUID_CHARSET_H */ diff --git a/include/config.h b/include/config.h index 386aa89e56..4ae2da08ff 100644 --- a/include/config.h +++ b/include/config.h @@ -167,9 +167,4 @@ */ #include "strnstr.h" -/* - * xstrtoul() and xstrtoui() are strtoul() and strtoui() with limits. - */ -#include "xstrto.h" - #endif /* SQUID_CONFIG_H */ diff --git a/include/html_quote.h b/include/html_quote.h new file mode 100644 index 0000000000..4ad42ed7df --- /dev/null +++ b/include/html_quote.h @@ -0,0 +1,12 @@ +#ifndef _SQUID_HTML_QUOTE_H +#define _SQUID_HTML_QUOTE_H + +#ifdef __cplusplus +extern "C" +#else +extern +#endif + +char *html_quote(const char *); + +#endif /* _SQUID_HTML_QUOTE_H */ diff --git a/include/rfc1123.h b/include/rfc1123.h new file mode 100644 index 0000000000..04f0b56eef --- /dev/null +++ b/include/rfc1123.h @@ -0,0 +1,15 @@ +#ifndef _SQUID_RFC1123_H +#define _SQUID_RFC1123_ + +#ifdef __cplusplus +extern "C" { +#endif + +extern const char *mkhttpdlogtime(const time_t *); +extern const char *mkrfc1123(time_t); +extern time_t parse_rfc1123(const char *str); + +#ifdef __cplusplus +} +#endif +#endif /* _SQUID_RFC1123_H */ diff --git a/include/rfc1738.h b/include/rfc1738.h index b3538ecad0..7189bb98af 100644 --- a/include/rfc1738.h +++ b/include/rfc1738.h @@ -1,9 +1,9 @@ #ifndef _SQUID_INCLUDE_RFC1738_H #define _SQUID_INCLUDE_RFC1738_H -/* for SQUIDCEXTERN */ -#include "config.h" - +#ifdef __cplusplus +extern "C" { +#endif /* Encoder rfc1738_do_escape flag values. */ #define RFC1738_ESCAPE_UNSAFE 0 @@ -27,7 +27,7 @@ * \param flags RFC1738_ESCAPE_RESERVED Encode all unsafe and reserved characters. * \param flags RFC1738_ESCAPE_UNESCAPED Encode all unsafe characters which have not already been encoded. */ -SQUIDCEXTERN char *rfc1738_do_escape(const char *url, int flags); +extern char *rfc1738_do_escape(const char *url, int flags); /* Old API functions */ #define rfc1738_escape(x) rfc1738_do_escape(x, RFC1738_ESCAPE_UNSAFE) @@ -39,7 +39,9 @@ SQUIDCEXTERN char *rfc1738_do_escape(const char *url, int flags); * Unescape a URL string according to RFC 1738 specification. * String is unescaped in-place */ -SQUIDCEXTERN void rfc1738_unescape(char *url); - +extern void rfc1738_unescape(char *url); +#ifdef __cplusplus +} +#endif #endif /* _SQUID_INCLUDE_RFC1738_H */ diff --git a/include/rfc2617.h b/include/rfc2617.h index 5c5152343b..fcb79ed37b 100644 --- a/include/rfc2617.h +++ b/include/rfc2617.h @@ -51,13 +51,17 @@ #include "config.h" +#ifdef __cplusplus +extern "C" { +#endif + #define HASHLEN 16 typedef char HASH[HASHLEN]; #define HASHHEXLEN 32 typedef char HASHHEX[HASHHEXLEN + 1]; /* calculate H(A1) as per HTTP Digest spec */ -SQUIDCEXTERN void DigestCalcHA1( +extern void DigestCalcHA1( const char *pszAlg, const char *pszUserName, const char *pszRealm, @@ -69,7 +73,7 @@ SQUIDCEXTERN void DigestCalcHA1( ); /* calculate request-digest/response-digest as per HTTP Digest spec */ -SQUIDCEXTERN void DigestCalcResponse( +extern void DigestCalcResponse( const HASHHEX HA1, /* H(A1) */ const char *pszNonce, /* nonce from server */ const char *pszNonceCount, /* 8 hex digits */ @@ -81,8 +85,11 @@ SQUIDCEXTERN void DigestCalcResponse( HASHHEX Response /* request-digest or response-digest */ ); -SQUIDCEXTERN void CvtHex(const HASH Bin, HASHHEX Hex); +extern void CvtHex(const HASH Bin, HASHHEX Hex); -SQUIDCEXTERN void CvtBin(const HASHHEX Hex, HASH Bin); +extern void CvtBin(const HASHHEX Hex, HASH Bin); +#ifdef __cplusplus +} +#endif #endif /* SQUID_RFC2617_H */ diff --git a/include/util.h b/include/util.h index 5211069157..300affb745 100644 --- a/include/util.h +++ b/include/util.h @@ -46,25 +46,10 @@ #include #endif -SQUIDCEXTERN const char *mkhttpdlogtime(const time_t *); -SQUIDCEXTERN const char *mkrfc1123(time_t); -SQUIDCEXTERN char *uudecode(const char *); -SQUIDCEXTERN char *xstrdup(const char *); -SQUIDCEXTERN char *xstrndup(const char *, size_t); -SQUIDCEXTERN const char *xstrerr(int xerrno); -SQUIDCEXTERN const char *xstrerror(void); -SQUIDCEXTERN int tvSubMsec(struct timeval, struct timeval); SQUIDCEXTERN int tvSubUsec(struct timeval, struct timeval); SQUIDCEXTERN double tvSubDsec(struct timeval, struct timeval); -SQUIDCEXTERN char *xstrncpy(char *, const char *, size_t); SQUIDCEXTERN size_t xcountws(const char *str); -SQUIDCEXTERN time_t parse_rfc1123(const char *str); -SQUIDCEXTERN void *xcalloc(size_t, size_t); -SQUIDCEXTERN void *xmalloc(size_t); -SQUIDCEXTERN void *xrealloc(void *, size_t); SQUIDCEXTERN void Tolower(char *); -SQUIDCEXTERN void xfree(void *); -SQUIDCEXTERN void xxfree(const void *); #ifdef __cplusplus /* * Any code using libstdc++ must have externally resolvable overloads @@ -83,13 +68,7 @@ SQUIDCEXTERN void xxfree(const void *); #include "SquidNew.h" #endif -/* charset.c */ -SQUIDCEXTERN char *latin1_to_utf8(char *out, size_t size, const char *in); - -/* html.c */ -SQUIDCEXTERN char *html_quote(const char *); - -#if XMALLOC_STATISTICS +#if 0 && XMALLOC_STATISTICS SQUIDCEXTERN void malloc_statistics(void (*)(int, int, int, void *), void *); #endif @@ -109,9 +88,6 @@ extern void xmalloc_find_leaks(void); #endif SQUIDCEXTERN time_t parse_iso3307_time(const char *buf); -SQUIDCEXTERN char *base64_decode(const char *coded); -SQUIDCEXTERN const char *base64_encode(const char *decoded); -SQUIDCEXTERN const char *base64_encode_bin(const char *data, int len); SQUIDCEXTERN double xpercent(double part, double whole); SQUIDCEXTERN int xpercentInt(double part, double whole); diff --git a/include/uudecode.h b/include/uudecode.h new file mode 100644 index 0000000000..edef387b0d --- /dev/null +++ b/include/uudecode.h @@ -0,0 +1,12 @@ +#ifndef _SQUID_UUDECODE_H +#define _SQUID_UUDECODE_ + +#ifdef __cplusplus +extern "C" +#else +extern +#endif + +char *uudecode(const char *); + +#endif /* _SQUID_UUDECODE_H */ diff --git a/lib/Makefile.am b/lib/Makefile.am index eb3dca3b4a..f30ad06f00 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,11 +1,7 @@ -## Process this file with automake to produce Makefile.in -# -# $Id$ -# - include $(top_srcdir)/src/Common.am -DIST_SUBDIRS = ntlmauth rfcnb smblib libTrie +DIST_SUBDIRS = ntlmauth profiler rfcnb smblib libTrie +EXTRA_DIST= SUBDIRS = rfcnb smblib if ENABLE_AUTH_NTLM @@ -14,60 +10,61 @@ endif if USE_ESI SUBDIRS += libTrie endif +if ENABLE_XPROF_STATS +SUBDIRS += profiler +endif install: all install-strip: all - -if ENABLE_XPROF_STATS -XPROF_STATS_SOURCE = Profiler.c -else -XPROF_STATS_SOURCE = -endif - if ENABLE_WIN32SPECIFIC -LIBSSPWIN32=libsspwin32.a +LIBSSPWIN32=libsspwin32.la WIN32SRC = win32lib.c else LIBSSPWIN32= WIN32SRC= +EXTRA_LTLIBRARIES = \ + libsspwin32.la endif -EXTRA_LIBRARIES = \ - libsspwin32.a -noinst_LIBRARIES = \ - libmiscutil.a \ +noinst_LTLIBRARIES = \ + libmiscencoding.la \ + libmisccontainers.la \ + libmiscutil.la \ $(LIBSSPWIN32) # # dirent.c, encrypt.c and getopt.c are needed for native Windows support. # -EXTRA_libmiscutil_a_SOURCES = \ +EXTRA_libmiscutil_la_SOURCES = \ dirent.c \ encrypt.c \ getopt.c \ - md5.c \ - Profiler.c \ win32lib.c -libmiscutil_a_SOURCES = \ +libmiscencoding_la_SOURCES = \ + base64.c \ + charset.c \ + html_quote.c \ + md5.c \ + rfc1738.c \ + rfc2617.c \ + uudecode.c + +libmisccontainers_la_SOURCES = \ + hash.c + +libmiscutil_la_SOURCES = \ MemPool.cc \ MemPoolChunked.cc \ MemPoolMalloc.cc \ - base64.c \ - charset.c \ getfullhostname.c \ - hash.c \ heap.c \ - html_quote.c \ iso3307.c \ - md5.c \ radix.c \ rfc1035.c \ rfc1123.c \ - rfc1738.c \ - rfc2617.c \ rfc2671.c \ rfc3596.c \ $(SNPRINTFSOURCE) \ @@ -75,15 +72,11 @@ libmiscutil_a_SOURCES = \ strnstr.cc \ stub_memaccount.c \ util.c \ - uudecode.c \ - xstrto.cc \ xusleep.c \ - $(XPROF_STATS_SOURCE) \ $(WIN32SRC) # $(top_srcdir)/include/version.h should be a dependency -libsspwin32_a_SOURCES = \ - base64.c \ +libsspwin32_la_SOURCES = \ sspwin32.c TESTS += tests/testAll @@ -97,12 +90,13 @@ tests_testAll_SOURCES= \ tests/testRFC1035.cc \ tests/testRFC1738.h \ tests/testRFC1738.cc \ - tests/testMain.cc \ - $(XPROF_STATS_SOURCE) \ - $(WIN32SRC) \ - util.c + tests/testMain.cc -tests_testAll_LDADD= $(SQUID_CPPUNIT_LA) $(SQUID_CPPUNIT_LIBS) +tests_testAll_LDADD= \ + $(SQUID_CPPUNIT_LA) $(SQUID_CPPUNIT_LIBS) \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(COMPAT_LIB) tests_testAll_LDFLAGS = $(LIBADD_DL) diff --git a/lib/base64.c b/lib/base64.c index b4ff2f04cb..7ca5c9829e 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -3,7 +3,7 @@ */ #include "config.h" -#include "util.h" +#include "base64.h" #if HAVE_STDIO_H #include diff --git a/lib/charset.c b/lib/charset.c index b885941efe..b58b535dc5 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -26,7 +26,7 @@ */ #include "config.h" -#include "util.h" +#include "charset.h" /** Convert ISO-LATIN-1 to UTF-8 */ char * diff --git a/lib/hash.c b/lib/hash.c index 5a410ab362..f962ad2548 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -34,6 +34,8 @@ */ #include "config.h" +#include "hash.h" +#include "profiler/Profiler.h" #if HAVE_STDIO_H #include @@ -59,10 +61,6 @@ #include #endif -#include "hash.h" -#include "util.h" -#include "profiling.h" - static void hash_next_bucket(hash_table * hid); unsigned int diff --git a/lib/html_quote.c b/lib/html_quote.c index 9425105bbe..bd9bee06b3 100644 --- a/lib/html_quote.c +++ b/lib/html_quote.c @@ -33,6 +33,7 @@ */ #include "config.h" +#include "html_quote.h" #if HAVE_STDIO_H #include @@ -41,8 +42,6 @@ #include #endif -#include "util.h" - /* * HTML defines these characters as special entities that should be quoted. */ diff --git a/lib/md5.c b/lib/md5.c index 2322e5edd3..6df0ce5256 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -30,7 +30,6 @@ * */ #include "config.h" - #include "md5.h" #if HAVE_STRING_H diff --git a/lib/profiler/Makefile.am b/lib/profiler/Makefile.am new file mode 100644 index 0000000000..9bd9f761ef --- /dev/null +++ b/lib/profiler/Makefile.am @@ -0,0 +1,15 @@ +include $(top_srcdir)/src/Common.am +include $(top_srcdir)/src/TestHeaders.am + +XPROFSRC= \ + get_tick.h \ + Profiler.cc \ + Profiler.h \ + xprof_type.h + +if ENABLE_XPROF_STATS +libprofiler_la_SOURCES = $(XPROFSRC) +noinst_LTLIBRARIES = libprofiler.la +else +EXTRA_DIST = $(XPROFSRC) +endif diff --git a/lib/Profiler.c b/lib/profiler/Profiler.cc similarity index 97% rename from lib/Profiler.c rename to lib/profiler/Profiler.cc index 32b82ad7ad..1c01ecdfe1 100644 --- a/lib/Profiler.c +++ b/lib/profiler/Profiler.cc @@ -54,7 +54,7 @@ * ... section of code measured ... * PROF_stop(probename); * - * probename must be added to profiling.h into xprof_type enum list + * probename must be added to the xprof_type.h enum list * with prepended "XPROF_" string. * * \section description Description. @@ -114,9 +114,7 @@ */ #include "config.h" - -/* This include needs to be BELOW config, as it may undef USE_XPROF_STATS */ -#include "profiling.h" +#include "profiler/Profiler.h" #if USE_XPROF_STATS @@ -175,7 +173,7 @@ xprof_InitLib(void) if (xprof_inited) return; - xprof_Timers = calloc(XPROF_LAST + 2, sizeof(xprof_stats_node)); + xprof_Timers = static_cast(calloc(XPROF_LAST + 2, sizeof(xprof_stats_node))); xprof_Timers[XPROF_PROF_UNACCOUNTED]->name = "PROF_UNACCOUNTED"; xprof_Timers[XPROF_PROF_UNACCOUNTED]->accu.start = get_tick(); diff --git a/lib/profiler/Profiler.h b/lib/profiler/Profiler.h new file mode 100644 index 0000000000..d59abc3817 --- /dev/null +++ b/lib/profiler/Profiler.h @@ -0,0 +1,62 @@ +#ifndef _PROFILER_H_ +#define _PROFILER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// NP: CPU support for get_tick() determines whether we can profile. +// always include get_tick.h first since it may undefine USE_XPROF_STATS + +#include "profiler/get_tick.h" +#include "profiler/xprof_type.h" + +#if !USE_XPROF_STATS + +#define PROF_start(ARGS) ((void)0) +#define PROF_stop(ARGS) ((void)0) + +#else /* USE_XPROF_STATS */ + +#define XP_NOBEST (hrtime_t)-1 + +typedef struct _xprof_stats_node xprof_stats_node; + +typedef struct _xprof_stats_data xprof_stats_data; + +struct _xprof_stats_data { + hrtime_t start; + hrtime_t stop; + hrtime_t delta; + hrtime_t best; + hrtime_t worst; + hrtime_t count; + hrtime_t accum; + int64_t summ; +}; + +struct _xprof_stats_node { + const char *name; + xprof_stats_data accu; + xprof_stats_data hist; +}; + +typedef xprof_stats_node TimersArray[1]; + +/* public Data */ +extern TimersArray *xprof_Timers; + +/* Exported functions */ +extern void xprof_start(xprof_type type, const char *timer); +extern void xprof_stop(xprof_type type, const char *timer); +extern void xprof_event(void *data); + +#define PROF_start(type) xprof_start(XPROF_##type, #type) +#define PROF_stop(type) xprof_stop(XPROF_##type, #type) + +#endif /* USE_XPROF_STATS */ + +#ifdef __cplusplus +} +#endif +#endif /* _PROFILING_H_ */ diff --git a/lib/profiler/get_tick.h b/lib/profiler/get_tick.h new file mode 100644 index 0000000000..e05e493de0 --- /dev/null +++ b/lib/profiler/get_tick.h @@ -0,0 +1,68 @@ +#ifndef _PROFILER_GET_TICK_H_ +#define _PROFILER_GET_TICK_H_ + +#include "config.h" + +#if USE_XPROF_STATS + +#if !_SQUID_SOLARIS_ +typedef int64_t hrtime_t; +#endif + +#if defined(__GNUC__) && ( defined(__i386) || defined(__i386__) ) +static inline hrtime_t +get_tick(void) +{ + hrtime_t regs; + +asm volatile ("rdtsc":"=A" (regs)); + return regs; + /* We need return value, we rely on CC to optimise out needless subf calls */ + /* Note that "rdtsc" is relatively slow OP and stalls the CPU pipes, so use it wisely */ +} + +#elif defined(__GNUC__) && ( defined(__x86_64) || defined(__x86_64__) ) +static inline hrtime_t +get_tick(void) +{ + uint32_t lo, hi; + // Based on an example in Wikipedia + /* We cannot use "=A", since this would use %rax on x86_64 */ +asm volatile ("rdtsc" : "=a" (lo), "=d" (hi)); + return (hrtime_t)hi << 32 | lo; +} + +#elif defined(__GNUC__) && defined(__alpha) +static inline hrtime_t +get_tick(void) +{ + hrtime_t regs; + +asm volatile ("rpcc %0" : "=r" (regs)); + return regs; +} + +#elif defined(_M_IX86) && defined(_MSC_VER) /* x86 platform on Microsoft C Compiler ONLY */ +static __inline hrtime_t +get_tick(void) +{ + hrtime_t regs; + + __asm { + cpuid + rdtsc + mov eax,DWORD PTR regs[0] + mov edx,DWORD PTR regs[4] + } + return regs; +} + +#else +/* This CPU is unsupported. Short-circuit, no profiling here */ +#define get_tick() 0 +#undef USE_XPROF_STATS +#define USE_XPROF_STATS 0 +#endif + +#endif /* USE_XPROF_STATS */ +#endif /* _PROFILING_H_ */ diff --git a/include/profiling.h b/lib/profiler/xprof_type.h similarity index 50% rename from include/profiling.h rename to lib/profiler/xprof_type.h index 02d5687f35..9315aafe6b 100644 --- a/include/profiling.h +++ b/lib/profiler/xprof_type.h @@ -1,78 +1,12 @@ -#ifndef _PROFILING_H_ -#define _PROFILING_H_ - -#include "config.h" - -/* forward decls (C++ only) */ -#if __cplusplus - -class CacheManager; -#endif +#ifndef _PROFILER_XPROF_TYPE_H_ +#define _PROFILER_XPROF_TYPE_H_ #if USE_XPROF_STATS -#if !_SQUID_SOLARIS_ -typedef int64_t hrtime_t; -#endif - -#if defined(__GNUC__) && ( defined(__i386) || defined(__i386__) ) -static inline hrtime_t -get_tick(void) -{ - hrtime_t regs; - -asm volatile ("rdtsc":"=A" (regs)); - return regs; - /* We need return value, we rely on CC to optimise out needless subf calls */ - /* Note that "rdtsc" is relatively slow OP and stalls the CPU pipes, so use it wisely */ -} - -#elif defined(__GNUC__) && ( defined(__x86_64) || defined(__x86_64__) ) -static inline hrtime_t -get_tick(void) -{ - uint32_t lo, hi; - // Based on an example in Wikipedia - /* We cannot use "=A", since this would use %rax on x86_64 */ -asm volatile ("rdtsc" : "=a" (lo), "=d" (hi)); - return (hrtime_t)hi << 32 | lo; -} - -#elif defined(__GNUC__) && defined(__alpha) -static inline hrtime_t -get_tick(void) -{ - hrtime_t regs; +// TODO: auto-generate this list from a scan of the source code. -asm volatile ("rpcc %0" : "=r" (regs)); - return regs; -} - -#elif defined(_M_IX86) && defined(_MSC_VER) /* x86 platform on Microsoft C Compiler ONLY */ -static __inline hrtime_t -get_tick(void) -{ - hrtime_t regs; - - __asm { - cpuid - rdtsc - mov eax,DWORD PTR regs[0] - mov edx,DWORD PTR regs[4] - } - return regs; -} - -#else -/* This CPU is unsupported. Short-circuit, no profiling here */ -#define get_tick() 0 -#undef USE_XPROF_STATS -#define USE_XPROF_STATS 0 -#endif - -#endif /* USE_XPROF_STATS - maybe disabled above */ - -#if USE_XPROF_STATS +// This list MUST be kept in sync with the PROF_start()/PROF_stop() macros +// used throughout the rest of the sources. typedef enum { XPROF_PROF_UNACCOUNTED, @@ -81,9 +15,10 @@ typedef enum { XPROF_splay_splay, XPROF_xmalloc, XPROF_malloc, - XPROF_xfree, - XPROF_xxfree, + XPROF_free, + XPROF_free_const, XPROF_xrealloc, + XPROF_realloc, XPROF_xcalloc, XPROF_calloc, XPROF_xstrdup, @@ -126,11 +61,9 @@ typedef enum { XPROF_file_read, XPROF_file_write, XPROF_file_close, -#if USE_SQUID_ESI XPROF_esiExpressionEval, XPROF_esiProcessing, XPROF_esiParsing, -#endif XPROF_storeClient_kickReads, XPROF_eventRun, XPROF_storeDirCallback, @@ -178,47 +111,5 @@ typedef enum { XPROF_LAST } xprof_type; -#define XP_NOBEST (hrtime_t)-1 - -typedef struct _xprof_stats_node xprof_stats_node; - -typedef struct _xprof_stats_data xprof_stats_data; - -struct _xprof_stats_data { - hrtime_t start; - hrtime_t stop; - hrtime_t delta; - hrtime_t best; - hrtime_t worst; - hrtime_t count; - hrtime_t accum; - int64_t summ; -}; - -struct _xprof_stats_node { - const char *name; - xprof_stats_data accu; - xprof_stats_data hist; -}; - -typedef xprof_stats_node TimersArray[1]; - -/* public Data */ -SQUIDCEXTERN TimersArray *xprof_Timers; - -/* Exported functions */ -SQUIDCEXTERN void xprof_start(xprof_type type, const char *timer); -SQUIDCEXTERN void xprof_stop(xprof_type type, const char *timer); -SQUIDCEXTERN void xprof_event(void *data); - -#define PROF_start(type) xprof_start(XPROF_##type, #type) -#define PROF_stop(type) xprof_stop(XPROF_##type, #type) - -#else /* USE_XPROF_STATS */ - -#define PROF_start(ARGS) ((void)0) -#define PROF_stop(ARGS) ((void)0) - #endif /* USE_XPROF_STATS */ - #endif /* _PROFILING_H_ */ diff --git a/lib/rfc1123.c b/lib/rfc1123.c index 91c588dc17..7d55737437 100644 --- a/lib/rfc1123.c +++ b/lib/rfc1123.c @@ -33,7 +33,7 @@ */ #include "config.h" - +#include "rfc1123.h" /* * Adapted from HTSUtils.c in CERN httpd 3.0 (http://info.cern.ch/httpd/) @@ -51,7 +51,6 @@ #if HAVE_TIME_H #include #endif -#include "util.h" #define RFC850_STRFTIME "%A, %d-%b-%y %H:%M:%S GMT" #define RFC1123_STRFTIME "%a, %d %b %Y %H:%M:%S GMT" diff --git a/lib/rfc1738.c b/lib/rfc1738.c index 70289b4545..382a5c72a9 100644 --- a/lib/rfc1738.c +++ b/lib/rfc1738.c @@ -34,7 +34,7 @@ #include "config.h" #include "rfc1738.h" -#include "util.h" +//#include "util.h" #if HAVE_STDIO_H #include diff --git a/lib/util.c b/lib/util.c index 6685dff34a..cc5979e411 100644 --- a/lib/util.c +++ b/lib/util.c @@ -35,7 +35,8 @@ #define _etext etext #include "config.h" -#include "profiling.h" +#include "profiler/Profiler.h" +#include "util.h" #if HAVE_STDIO_H #include @@ -64,12 +65,9 @@ #include #endif -#include "util.h" - static void default_failure_notify(const char *); void (*failure_notify) (const char *) = default_failure_notify; -static char msg[128]; #if MEM_GEN_TRACE @@ -95,72 +93,6 @@ log_trace_done() #endif -#if XMALLOC_STATISTICS -#define DBG_MAXSIZE (1024*1024) -#define DBG_SPLIT (256) /* mallocs below this value are tracked with DBG_GRAIN_SM precision instead of DBG_GRAIN */ -#define DBG_GRAIN (16) -#define DBG_GRAIN_SM (4) -#define DBG_OFFSET (DBG_SPLIT/DBG_GRAIN_SM - DBG_SPLIT/DBG_GRAIN ) -#define DBG_MAXINDEX (DBG_MAXSIZE/DBG_GRAIN + DBG_OFFSET) -#if 0 /* function version defined below */ -#define DBG_INDEX(sz) (sz= DBG_MAXSIZE) - return DBG_MAXINDEX; - - if (sz <= DBG_SPLIT) - return (sz + DBG_GRAIN_SM - 1) / DBG_GRAIN_SM; - - return (sz + DBG_GRAIN - 1) / DBG_GRAIN + DBG_OFFSET; -} - -static void -stat_init(void) -{ - int i; - - for (i = 0; i <= DBG_MAXINDEX; i++) - malloc_sizes[i] = malloc_histo[i] = 0; - - dbg_stat_init = 1; -} - -static int -malloc_stat(int sz) -{ - if (!dbg_stat_init) - stat_init(); - - return malloc_sizes[DBG_INDEX(sz)] += 1; -} - -void -malloc_statistics(void (*func) (int, int, int, void *), void *data) -{ - int i; - - for (i = 0; i <= DBG_SPLIT; i += DBG_GRAIN_SM) - func(i, malloc_sizes[DBG_INDEX(i)], malloc_histo[DBG_INDEX(i)], data); - - i -= DBG_GRAIN_SM; - - for (i = i; i <= DBG_MAXSIZE; i += DBG_GRAIN) - func(i, malloc_sizes[DBG_INDEX(i)], malloc_histo[DBG_INDEX(i)], data); - - xmemcpy(&malloc_histo, &malloc_sizes, sizeof(malloc_sizes)); -} - -#endif /* XMALLOC_STATISTICS */ - - - #if XMALLOC_TRACE char *xmalloc_file = ""; int xmalloc_line = 0; @@ -242,6 +174,7 @@ check_free(void *s) } if (I == DBG_ARRY_SZ) { + static char msg[128]; snprintf(msg, 128, "xfree: ERROR: s=%p not found!", s); (*failure_notify) (msg); } @@ -265,6 +198,7 @@ check_malloc(void *p, size_t sz) Q = P + malloc_size[B][I]; if (P <= p && p < Q) { + static char msg[128]; snprintf(msg, 128, "xmalloc: ERROR: p=%p falls in P=%p+%d", p, P, malloc_size[B][I]); (*failure_notify) (msg); @@ -485,326 +419,6 @@ xmalloc_find_leaks(void) #endif /* XMALLOC_TRACE */ -/* - * xmalloc() - same as malloc(3). Used for portability. - * Never returns NULL; fatal on error. - */ -void * -xmalloc(size_t sz) -{ - void *p; - - PROF_start(xmalloc); - - if (sz < 1) - sz = 1; - - PROF_start(malloc); - - p = malloc(sz); - - PROF_stop(malloc); - - if (p == NULL) { - if (failure_notify) { - snprintf(msg, 128, "xmalloc: Unable to allocate %d bytes!\n", - (int) sz); - (*failure_notify) (msg); - } else { - perror("malloc"); - } - - exit(1); - } - -#if XMALLOC_DEBUG - check_malloc(p, sz); - -#endif -#if XMALLOC_STATISTICS - - malloc_stat(sz); - -#endif -#if XMALLOC_TRACE - - xmalloc_show_trace(p, 1); - -#endif -#if MEM_GEN_TRACE - - if (tracefp) - fprintf(tracefp, "m:%d:%p\n", sz, p); - -#endif - - PROF_stop(xmalloc); - - return (p); -} - -/* - * xfree() - same as free(3). Will not call free(3) if s == NULL. - */ -void -xfree(void *s) -{ - PROF_start(xfree); -#if XMALLOC_TRACE - - xmalloc_show_trace(s, -1); -#endif - -#if XMALLOC_DEBUG - - if (s != NULL) - check_free(s); - -#endif - - if (s != NULL) - free(s); - -#if MEM_GEN_TRACE - - if (tracefp && s) - fprintf(tracefp, "f:%p\n", s); - -#endif - - PROF_stop(xfree); -} - -/* xxfree() - like xfree(), but we already know s != NULL */ -void -xxfree(const void *s_const) -{ - void *s = (void *) s_const; - PROF_start(xxfree); -#if XMALLOC_TRACE - - xmalloc_show_trace(s, -1); -#endif -#if XMALLOC_DEBUG - - check_free(s); -#endif - - free(s); -#if MEM_GEN_TRACE - - if (tracefp && s) - fprintf(tracefp, "f:%p\n", s); - -#endif - - PROF_stop(xxfree); -} - -/* - * xrealloc() - same as realloc(3). Used for portability. - * Never returns NULL; fatal on error. - */ -void * -xrealloc(void *s, size_t sz) -{ - void *p; - - PROF_start(xrealloc); -#if XMALLOC_TRACE - - xmalloc_show_trace(s, -1); -#endif - - if (sz < 1) - sz = 1; - -#if XMALLOC_DEBUG - - if (s != NULL) - check_free(s); - -#endif - - if ((p = realloc(s, sz)) == NULL) { - if (failure_notify) { - snprintf(msg, 128, "xrealloc: Unable to reallocate %d bytes!\n", - (int) sz); - (*failure_notify) (msg); - } else { - perror("realloc"); - } - - exit(1); - } - -#if XMALLOC_DEBUG - check_malloc(p, sz); - -#endif -#if XMALLOC_STATISTICS - - malloc_stat(sz); - -#endif -#if XMALLOC_TRACE - - xmalloc_show_trace(p, 1); - -#endif -#if MEM_GEN_TRACE - - if (tracefp) /* new ptr, old ptr, new size */ - fprintf(tracefp, "r:%p:%p:%d\n", p, s, sz); - -#endif - - PROF_stop(xrealloc); - - return (p); -} - -/* - * xcalloc() - same as calloc(3). Used for portability. - * Never returns NULL; fatal on error. - */ -void * -xcalloc(size_t n, size_t sz) -{ - void *p; - - PROF_start(xcalloc); - - if (n < 1) - n = 1; - - if (sz < 1) - sz = 1; - - PROF_start(calloc); - - p = calloc(n, sz); - - PROF_stop(calloc); - - if (p == NULL) { - if (failure_notify) { - snprintf(msg, 128, "xcalloc: Unable to allocate %u blocks of %u bytes!\n", - (unsigned int) n, (unsigned int) sz); - (*failure_notify) (msg); - } else { - perror("xcalloc"); - } - - exit(1); - } - -#if XMALLOC_DEBUG - check_malloc(p, sz * n); - -#endif -#if XMALLOC_STATISTICS - - malloc_stat(sz * n); - -#endif -#if XMALLOC_TRACE - - xmalloc_show_trace(p, 1); - -#endif -#if MEM_GEN_TRACE - - if (tracefp) - fprintf(tracefp, "c:%u:%u:%p\n", (unsigned int) n, (unsigned int) sz, p); - -#endif - - PROF_stop(xcalloc); - - return (p); -} - -/* - * xstrdup() - same as strdup(3). Used for portability. - * Never returns NULL; fatal on error. - */ -char * -xstrdup(const char *s) -{ - size_t sz; - char *p; - PROF_start(xstrdup); - - if (s == NULL) { - if (failure_notify) { - (*failure_notify) ("xstrdup: tried to dup a NULL pointer!\n"); - } else { - fprintf(stderr, "xstrdup: tried to dup a NULL pointer!\n"); - } - - exit(1); - } - - /* copy string, including terminating character */ - sz = strlen(s) + 1; - - p = (char *)xmalloc(sz); - memcpy(p, s, sz); - - PROF_stop(xstrdup); - - return p; -} - -/* - * xstrndup() - string dup with length limit. - */ -char * -xstrndup(const char *s, size_t n) -{ - size_t sz; - char *p; - PROF_start(xstrndup); - assert(s != NULL); - assert(n); - sz = strlen(s) + 1; - - if (sz > n) - sz = n; - - p = xstrncpy((char *)xmalloc(sz), s, sz); - - PROF_stop(xstrndup); - - return p; -} - -/* - * xstrerror() - strerror() wrapper - */ -const char * -xstrerr(int error) -{ - static char xstrerror_buf[BUFSIZ]; - const char *errmsg; - - errmsg = strerror(error); - - if (!errmsg || !*errmsg) - errmsg = "Unknown error"; - - snprintf(xstrerror_buf, BUFSIZ, "(%d) %s", error, errmsg); - - return xstrerror_buf; -} - -const char * -xstrerror(void) -{ - return xstrerr(errno); -} - void Tolower(char *q) { @@ -817,15 +431,6 @@ Tolower(char *q) } int - -tvSubMsec(struct timeval t1, struct timeval t2) -{ - return (t2.tv_sec - t1.tv_sec) * 1000 + - (t2.tv_usec - t1.tv_usec) / 1000; -} - -int - tvSubUsec(struct timeval t1, struct timeval t2) { return (t2.tv_sec - t1.tv_sec) * 1000000 + @@ -833,38 +438,12 @@ tvSubUsec(struct timeval t1, struct timeval t2) } double - tvSubDsec(struct timeval t1, struct timeval t2) { return (double) (t2.tv_sec - t1.tv_sec) + (double) (t2.tv_usec - t1.tv_usec) / 1000000.0; } -/* - * xstrncpy() - similar to strncpy(3) but terminates string - * always with '\0' if (n != 0 and dst != NULL), - * and doesn't do padding - */ -char * -xstrncpy(char *dst, const char *src, size_t n) -{ - char *r = dst; - PROF_start(xstrncpy); - - if (!n || !dst) - return dst; - - if (src) - while (--n != 0 && *src != '\0') - *dst++ = *src++; - - *dst = '\0'; - - PROF_stop(xstrncpy); - - return r; -} - /* returns the number of leading white spaces in str; handy in skipping ws */ size_t xcountws(const char *str) diff --git a/lib/uudecode.c b/lib/uudecode.c index fc342d9b24..a9f5f94a77 100644 --- a/lib/uudecode.c +++ b/lib/uudecode.c @@ -3,7 +3,7 @@ */ #include "config.h" -#include "util.h" +#include "uudecode.h" /* aaaack but it's fast and const should make it shared text page. */ const int pr2six[256] = { diff --git a/lib/xusleep.c b/lib/xusleep.c index 8de597ab86..d4490a3a01 100644 --- a/lib/xusleep.c +++ b/lib/xusleep.c @@ -1,5 +1,5 @@ #include "config.h" -#include "profiling.h" +#include "profiler/Profiler.h" #include "xusleep.h" #if HAVE_UNISTD_H diff --git a/snmplib/parse.c b/snmplib/parse.c index 9c56c957af..cad1cc31e0 100644 --- a/snmplib/parse.c +++ b/snmplib/parse.c @@ -74,7 +74,9 @@ SOFTWARE. #if HAVE_ASSERT_H #include #endif - +#if HAVE_ERRNO_H +#include +#endif #include "asn1.h" #include "snmp_vars.h" diff --git a/src/Common.am b/src/Common.am index 9e71907d9a..036d501c9c 100644 --- a/src/Common.am +++ b/src/Common.am @@ -16,6 +16,7 @@ TESTS = INCLUDES = \ -I$(top_srcdir) \ -I$(top_srcdir)/include \ + -I$(top_srcdir)/lib \ -I$(top_srcdir)/src \ -I$(top_builddir)/include \ $(SQUID_CPPUNIT_INC) @@ -34,11 +35,15 @@ endif ## XXX: Do we really need this? Does auto-dependency tracking work? $(OBJS): $(top_srcdir)/include/version.h $(top_builddir)/include/autoconf.h +## Internal profiler is used even by some of the compat library stuff. +if ENABLE_XPROF_STATS +LIBPROFILER = $(top_builddir)/lib/profiler/libprofiler.la +else +LIBPROFILER= +endif + ## Because compatibility is almost universal. And the link order is important. -## NP: libmisc util.cc depends on rint from math library -COMPAT_LIB = \ - -L$(top_builddir)/lib -lmiscutil \ - -L$(top_builddir)/compat -lcompat-squid +COMPAT_LIB = -L$(top_builddir)/compat -lcompat-squid $(LIBPROFILER) ## Some helpers are written in Perl and need the local shell defined properly subst_perlshell = sed -e 's,[@]PERL[@],$(PERL),g' <$(srcdir)/$@.pl.in >$@ || ($(RM) -f $@ ; exit 1) diff --git a/src/Debug.h b/src/Debug.h index 79073ab108..484fe45945 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -63,6 +63,8 @@ /* context-based debugging, the actual type is subject to change */ typedef int Ctx; +extern Ctx ctx_enter(const char *descr); +extern void ctx_exit(Ctx ctx); /* defined debug section limits */ #define MAX_DEBUG_SECTIONS 100 @@ -141,6 +143,9 @@ inline std::ostream& operator <<(std::ostream &os, const uint8_t d) #define old_debug(SECTION, LEVEL) if( (Debug::level=(LEVEL)) <= Debug::Levels[SECTION] ) _db_print /* Legacy debug function definitions */ -SQUIDCEXTERN void _db_print(const char *,...) PRINTF_FORMAT_ARG1; +extern void _db_init(const char *logfile, const char *options); +extern void _db_print(const char *,...) PRINTF_FORMAT_ARG1; +extern void _db_set_syslog(const char *facility); +extern void _db_rotate_log(void); #endif /* SQUID_DEBUG_H */ diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index c2fa9904af..057ac4af36 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -34,11 +34,13 @@ */ #include "squid.h" +#include "base64.h" #include "HttpHdrContRange.h" #include "HttpHdrSc.h" #include "HttpHeader.h" #include "MemBuf.h" #include "mgr/Registration.h" +#include "rfc1123.h" #include "Store.h" /* diff --git a/src/Makefile.am b/src/Makefile.am index eef3d09d50..495c95d1f5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -567,13 +567,16 @@ squid_LDADD = \ $(SNMPLIB) \ ${ADAPTATION_LIBS} \ $(ESI_LIBS) \ - $(COMPAT_LIB) \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(SSLLIB) \ $(EPOLL_LIBS) \ $(MINGW_LIBS) \ $(KRB5LIBS) \ + $(COMPAT_LIB) \ $(XTRA_LIBS) -squid_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +squid_DEPENDENCIES = \ $(DISK_LIBS) \ $(DISK_LINKOBJS) \ $(REPL_OBJS) \ @@ -597,10 +600,9 @@ endif INCLUDES += $(KRB5INCS) -unlinkd_SOURCES = unlinkd_daemon.cc SquidNew.cc - -dnsserver_SOURCES = dnsserver.cc SquidNew.cc test_tools.cc time.cc -recv_announce_SOURCES = recv-announce.cc SquidNew.cc +unlinkd_SOURCES = unlinkd_daemon.cc +dnsserver_SOURCES = dnsserver.cc SquidNew.cc tests/stub_debug.cc test_tools.cc time.cc +recv_announce_SOURCES = recv-announce.cc ## What requires what.. ## many things want ACLChecklist.cc @@ -666,7 +668,7 @@ ufsdump_LDADD = \ $(EPOLL_LIBS) \ $(MINGW_LIBS) \ $(XTRA_LIBS) -ufsdump_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +ufsdump_DEPENDENCIES = \ $(COMMON_LIBS) \ $(DISK_LIBS) \ $(DISK_LINKOBJS) \ @@ -684,7 +686,6 @@ data_DATA = \ mib.txt LDADD = $(COMMON_LIBS) \ - -L../lib -lmiscutil \ $(EPOLL_LIBS) \ $(MINGW_LIBS) \ $(COMPAT_LIB) \ @@ -745,7 +746,12 @@ libDiskThreads_a_SOURCES = \ DiskIO_DiskDaemon_diskd_SOURCES = DiskIO/DiskDaemon/diskd.cc nodist_DiskIO_DiskDaemon_diskd_SOURCES = time.cc -DiskIO_DiskDaemon_diskd_LDADD = $(COMPAT_LIB) $(XTRA_LIBS) +DiskIO_DiskDaemon_diskd_LDADD = \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(COMPAT_LIB) \ + $(XTRA_LIBS) DEFAULT_HTTP_PORT = 3128 @@ -938,10 +944,8 @@ TESTS += $(check_PROGRAMS) #tests_testX_LDADD=\ # $(SQUID_CPPUNIT_LIBS) \ # $(SQUID_CPPUNIT_LA) \ -# -L../lib -lmiscutil # $(COMPAT_LIB) \ -#tests_testX_DEPENDENCIES= $(SQUID_CPPUNIT_LA) \ -# $(top_builddir)/lib/libmiscutil.a +#tests_testX_DEPENDENCIES= $(SQUID_CPPUNIT_LA) # - add other component .(h|cc) files needed to link and run tests @@ -980,6 +984,7 @@ tests_testHttpReply_SOURCES=\ Packer.h \ Packer.cc \ tests/stub_cache_manager.cc \ + tests/stub_debug.cc \ tests/stub_HelperChildConfig.cc \ tests/stub_StatHist.cc \ tests/stub_store.cc \ @@ -996,12 +1001,13 @@ tests_testHttpReply_LDADD=\ auth/libauth.la \ ip/libip.la \ base/libbase.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(SQUID_CPPUNIT_LIBS) \ $(SQUID_CPPUNIT_LA) \ $(COMPAT_LIB) \ $(XTRA_LIBS) -tests_testHttpReply_DEPENDENCIES= $(SQUID_CPPUNIT_LA) \ - $(top_builddir)/lib/libmiscutil.a +tests_testHttpReply_DEPENDENCIES= $(SQUID_CPPUNIT_LA) tests_testAuth_SOURCES = \ tests/testAuth.cc tests/testMain.cc tests/testAuth.h \ @@ -1009,6 +1015,7 @@ tests_testAuth_SOURCES = \ HelperChildConfig.h \ HelperChildConfig.cc \ tests/stub_acl.cc tests/stub_cache_cf.cc \ + tests/stub_debug.cc \ tests/stub_helper.cc cbdata.cc String.cc \ tests/stub_store.cc HttpHeaderTools.cc HttpHeader.cc mem.cc ClientInfo.h \ MemBuf.cc HttpHdrContRange.cc Packer.cc HttpHdrCc.cc HttpHdrSc.cc \ @@ -1028,23 +1035,21 @@ tests_testAuth_SOURCES = \ URLScheme.cc \ $(TEST_CALL_SOURCES) \ wordlist.cc -## acl.cc cache_cf.cc tools.cc \ -## helper.cc String.cc cbdata.cc HttpHeaderTools.cc store.cc cache_manager.cc \ -## HttpHeader.cc url.cc mem.cc HttpRequest.cc Packer.cc \ -## MemBuf.cc StatHist.cc nodist_tests_testAuth_SOURCES = \ $(TESTSOURCES) tests_testAuth_LDADD= \ $(COMMON_LIBS) \ - -L../lib -lmiscutil \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SQUID_CPPUNIT_LIBS) \ $(SSLLIB) \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testAuth_LDFLAGS = $(LIBADD_DL) -tests_testAuth_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testAuth_DEPENDENCIES = \ $(SQUID_CPPUNIT_LA) ## Tests for the ACLMaxUserIP class @@ -1088,6 +1093,7 @@ tests_testACLMaxUserIP_SOURCES= \ $(TEST_CALL_SOURCES) \ tests/stub_cache_cf.cc \ tests/stub_comm.cc \ + tests/stub_debug.cc \ tests/stub_DelayId.cc \ tests/stub_MemObject.cc \ tests/stub_store.cc \ @@ -1103,7 +1109,9 @@ nodist_tests_testACLMaxUserIP_SOURCES= \ $(TESTSOURCES) tests_testACLMaxUserIP_LDADD= \ $(COMMON_LIBS) \ - -L../lib -lmiscutil \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SQUID_CPPUNIT_LIBS) \ $(SSLLIB) \ @@ -1123,7 +1131,6 @@ tests_testBoilerplate_SOURCES = \ nodist_tests_testBoilerplate_SOURCES = \ $(TESTSOURCES) tests_testBoilerplate_LDADD= \ - -L../lib -lmiscutil \ $(SQUID_CPPUNIT_LIBS) \ $(SSLLIB) \ $(COMPAT_LIB) \ @@ -1278,9 +1285,11 @@ tests_testCacheManager_LDADD = \ $(REPL_OBJS) \ ${ADAPTATION_LIBS} \ $(ESI_LIBS) \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SNMPLIB) \ - -L../lib -lmiscutil \ $(SQUID_CPPUNIT_LIBS) \ $(SQUID_CPPUNIT_LA) \ $(SSLLIB) \ @@ -1288,7 +1297,7 @@ tests_testCacheManager_LDADD = \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testCacheManager_LDFLAGS = $(LIBADD_DL) -tests_testCacheManager_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testCacheManager_DEPENDENCIES = \ $(REPL_OBJS) \ $(SQUID_CPPUNIT_LA) @@ -1308,17 +1317,25 @@ nodist_tests_testDiskIO_SOURCES= \ SquidMath.h \ swap_log_op.cc tests_testDiskIO_LDADD = \ - $(SWAP_TEST_LDADD) \ - $(DISK_LIBS) \ - $(DISK_OS_LIBS) \ - $(COMMON_LIBS) \ SquidConfig.o \ CommCalls.o \ DnsLookupDetails.o \ + $(COMMON_LIBS) \ + $(REPL_OBJS) \ + $(DISK_LIBS) \ + $(DISK_OS_LIBS) \ + acl/libapi.la \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(REGEXLIB) \ + $(SQUID_CPPUNIT_LIBS) \ + $(SSLLIB) \ + $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testDiskIO_LDFLAGS = $(LIBADD_DL) -tests_testDiskIO_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testDiskIO_DEPENDENCIES = \ $(DISK_LIBS) \ $(SWAP_TEST_DS) \ $(SQUID_CPPUNIT_LA) @@ -1471,9 +1488,11 @@ tests_testEvent_LDADD = \ $(REPL_OBJS) \ ${ADAPTATION_LIBS} \ $(ESI_LIBS) \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SNMPLIB) \ - -L../lib -lmiscutil \ $(SQUID_CPPUNIT_LIBS) \ $(SQUID_CPPUNIT_LA) \ $(SSLLIB) \ @@ -1481,7 +1500,7 @@ tests_testEvent_LDADD = \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testEvent_LDFLAGS = $(LIBADD_DL) -tests_testEvent_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testEvent_DEPENDENCIES = \ $(REPL_OBJS) \ $(SQUID_CPPUNIT_LA) @@ -1632,9 +1651,11 @@ tests_testEventLoop_LDADD = \ $(REPL_OBJS) \ ${ADAPTATION_LIBS} \ $(ESI_LIBS) \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SNMPLIB) \ - -L../lib -lmiscutil \ $(SQUID_CPPUNIT_LIBS) \ $(SQUID_CPPUNIT_LA) \ $(SSLLIB) \ @@ -1642,7 +1663,7 @@ tests_testEventLoop_LDADD = \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testEventLoop_LDFLAGS = $(LIBADD_DL) -tests_testEventLoop_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testEventLoop_DEPENDENCIES = \ $(REPL_OBJS) \ $(SQUID_CPPUNIT_LA) @@ -1788,9 +1809,11 @@ tests_test_http_range_LDADD = \ $(REPL_OBJS) \ ${ADAPTATION_LIBS} \ $(ESI_LIBS) \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SNMPLIB) \ - -L../lib -lmiscutil \ $(SQUID_CPPUNIT_LIBS) \ $(SQUID_CPPUNIT_LA) \ $(SSLLIB) \ @@ -1805,7 +1828,6 @@ tests_test_http_range_DEPENDENCIES = \ ## Tests of the HttpRequest module. tests_testHttpRequest_SOURCES = \ $(ACL_REGISTRATION_SOURCES) \ - debug.cc \ HttpRequest.cc \ HttpRequestMethod.cc \ mem.cc \ @@ -1820,6 +1842,7 @@ tests_testHttpRequest_SOURCES = \ BodyPipe.cc \ cache_manager.cc \ cache_cf.cc \ + debug.cc \ ProtoPort.cc \ ProtoPort.h \ CacheDigest.cc \ @@ -1949,9 +1972,11 @@ tests_testHttpRequest_LDADD = \ $(REPL_OBJS) \ ${ADAPTATION_LIBS} \ $(ESI_LIBS) \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SNMPLIB) \ - -L../lib -lmiscutil \ $(SQUID_CPPUNIT_LIBS) \ $(SQUID_CPPUNIT_LA) \ $(SSLLIB) \ @@ -1959,7 +1984,7 @@ tests_testHttpRequest_LDADD = \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testHttpRequest_LDFLAGS = $(LIBADD_DL) -tests_testHttpRequest_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testHttpRequest_DEPENDENCIES = \ $(REPL_OBJS) \ $(SQUID_CPPUNIT_LA) @@ -1984,6 +2009,7 @@ STORE_TEST_SOURCES=\ tests/stub_acl.cc tests/stub_cache_cf.cc \ tests/stub_helper.cc cbdata.cc String.cc \ tests/stub_comm.cc \ + tests/stub_debug.cc \ tests/stub_client_side_request.cc \ tests/stub_http.cc \ mem_node.cc \ @@ -2037,7 +2063,9 @@ nodist_tests_testStore_SOURCES= \ tests_testStore_LDADD= \ $(COMMON_LIBS) \ - -L../lib -lmiscutil \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SQUID_CPPUNIT_LIBS) \ $(SSLLIB) \ @@ -2046,7 +2074,7 @@ tests_testStore_LDADD= \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testStore_LDFLAGS = $(LIBADD_DL) -tests_testStore_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testStore_DEPENDENCIES = \ $(SQUID_CPPUNIT_LA) ## string needs mem.cc. @@ -2060,20 +2088,21 @@ tests_testString_SOURCES = \ tests/testString.cc \ tests/testString.h \ tests/stub_cache_manager.cc \ + tests/stub_debug.cc \ tests/stub_HelperChildConfig.cc \ time.cc nodist_tests_testString_SOURCES = \ $(TESTSOURCES) tests_testString_LDADD = \ $(COMMON_LIBS) \ - -L../lib -lmiscutil \ + $(top_builddir)/lib/libmiscutil.la \ $(REGEXLIB) \ $(SQUID_CPPUNIT_LIBS) \ $(SSLLIB) \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testString_LDFLAGS = $(LIBADD_DL) -tests_testString_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testString_DEPENDENCIES = \ $(SQUID_CPPUNIT_LA) SWAP_TEST_SOURCES = \ @@ -2111,19 +2140,7 @@ SWAP_TEST_GEN_SOURCES = \ $(TESTSOURCES) \ $(DISKIO_GEN_SOURCE) -SWAP_TEST_LDADD = \ - $(REGEXLIB) \ - $(COMMON_LIBS) \ - $(REPL_OBJS) \ - $(DISK_LIBS) \ - $(DISK_OS_LIBS) \ - -L../lib -lmiscutil \ - acl/libapi.la \ - $(SQUID_CPPUNIT_LIBS) \ - $(COMPAT_LIB) \ - $(XTRA_LIBS) SWAP_TEST_DS =\ - $(top_builddir)/lib/libmiscutil.a \ repl_modules.o \ $(DISK_LIBS) \ $(COMMON_LIBS) \ @@ -2146,11 +2163,20 @@ nodist_tests_testUfs_SOURCES = \ SquidMath.h \ swap_log_op.cc tests_testUfs_LDADD = \ - $(SWAP_TEST_LDADD) \ - $(COMMON_LIBS) \ - $(SSLLIB) \ CommCalls.o \ DnsLookupDetails.o \ + $(COMMON_LIBS) \ + $(REPL_OBJS) \ + $(DISK_LIBS) \ + $(DISK_OS_LIBS) \ + acl/libapi.la \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(REGEXLIB) \ + $(SQUID_CPPUNIT_LIBS) \ + $(SSLLIB) \ + $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testUfs_LDFLAGS = $(LIBADD_DL) tests_testUfs_DEPENDENCIES = \ @@ -2161,6 +2187,7 @@ tests_testCoss_SOURCES = \ tests/testMain.cc \ tests/testCoss.h \ tests/stub_cache_manager.cc \ + tests/stub_debug.cc \ tests/stub_HelperChildConfig.cc \ $(SWAP_TEST_SOURCES) nodist_tests_testCoss_SOURCES = \ @@ -2170,8 +2197,18 @@ nodist_tests_testCoss_SOURCES = \ $(SWAP_TEST_GEN_SOURCES) tests_testCoss_LDADD = \ libsquid.la \ - $(SWAP_TEST_LDADD) \ + $(REGEXLIB) \ + $(COMMON_LIBS) \ + $(REPL_OBJS) \ + $(DISK_LIBS) \ + $(DISK_OS_LIBS) \ + acl/libapi.la \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(SQUID_CPPUNIT_LIBS) \ $(SSLLIB) \ + $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testCoss_LDFLAGS = $(LIBADD_DL) tests_testCoss_DEPENDENCIES = \ @@ -2185,8 +2222,18 @@ tests_testNull_SOURCES = \ nodist_tests_testNull_SOURCES = \ $(SWAP_TEST_GEN_SOURCES) tests_testNull_LDADD = \ - $(SWAP_TEST_LDADD) \ + $(REGEXLIB) \ + $(COMMON_LIBS) \ + $(REPL_OBJS) \ + $(DISK_LIBS) \ + $(DISK_OS_LIBS) \ + acl/libapi.la \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(SQUID_CPPUNIT_LIBS) \ $(SSLLIB) \ + $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testNull_LDFLAGS = $(LIBADD_DL) tests_testNull_DEPENDENCIES = \ @@ -2196,7 +2243,6 @@ tests_testNull_DEPENDENCIES = \ ## TODO: Trim this down once the insanity is over. tests_testURL_SOURCES = \ $(ACL_REGISTRATION_SOURCES) \ - debug.cc \ url.cc \ URLScheme.cc \ HttpRequest.cc \ @@ -2209,6 +2255,7 @@ tests_testURL_SOURCES = \ tests/testURLScheme.cc \ tests/testURLScheme.h \ tests/testMain.cc \ + tests/stub_debug.cc \ tests/stub_main_cc.cc \ time.cc \ BodyPipe.cc \ @@ -2342,7 +2389,10 @@ tests_testURL_LDADD = \ ${ADAPTATION_LIBS} \ $(ESI_LIBS) \ $(SNMPLIB) \ - -L../lib -lmiscutil \ + $(top_builddir)/lib/libmisccontainers.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(COMPAT_LIB) \ $(SQUID_CPPUNIT_LIBS) \ $(SQUID_CPPUNIT_LA) \ $(SSLLIB) \ @@ -2350,7 +2400,7 @@ tests_testURL_LDADD = \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testURL_LDFLAGS = $(LIBADD_DL) -tests_testURL_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \ +tests_testURL_DEPENDENCIES = \ $(REPL_OBJS) \ $(SQUID_CPPUNIT_LA) diff --git a/src/SquidTime.h b/src/SquidTime.h index 411bcfd072..4decb63abe 100644 --- a/src/SquidTime.h +++ b/src/SquidTime.h @@ -33,6 +33,7 @@ #define SQUID_TIME_H #include "config.h" +#include "rfc1123.h" #if HAVE_TIME_H #include @@ -42,10 +43,10 @@ /* globals for accessing time */ extern struct timeval current_time; extern double current_dtime; - -extern time_t squid_curtime; /* 0 */ +extern time_t squid_curtime; time_t getCurrentTime(void); +int tvSubMsec(struct timeval, struct timeval); /** event class for doing synthetic time etc */ class TimeEngine diff --git a/src/adaptation/icap/ModXact.cc b/src/adaptation/icap/ModXact.cc index d1c9f9d77f..8e679921f9 100644 --- a/src/adaptation/icap/ModXact.cc +++ b/src/adaptation/icap/ModXact.cc @@ -14,6 +14,7 @@ #include "adaptation/Initiator.h" #include "auth/UserRequest.h" #include "base/TextException.h" +#include "base64.h" #include "ChunkedCodingParser.h" #include "comm.h" #include "HttpMsg.h" diff --git a/src/auth/User.cci b/src/auth/User.cci index f7d31b3845..865e6fc08a 100644 --- a/src/auth/User.cci +++ b/src/auth/User.cci @@ -35,11 +35,6 @@ #include "config.h" -/* for xstrdup() */ -#include "util.h" -/* for safe_free() */ -#include "defines.h" - char const * AuthUser::username () const { diff --git a/src/auth/User.h b/src/auth/User.h index ba00233ab4..a01f45487a 100644 --- a/src/auth/User.h +++ b/src/auth/User.h @@ -122,7 +122,7 @@ private: * The username_ memory will be allocated via * xstrdup(). It is our responsibility. */ - char const *username_; + const char *username_; /** what ip addresses has this user been seen at?, plus a list length cache */ dlink_list ip_list; diff --git a/src/auth/basic/auth_basic.cc b/src/auth/basic/auth_basic.cc index 1c40a97844..414518d59c 100644 --- a/src/auth/basic/auth_basic.cc +++ b/src/auth/basic/auth_basic.cc @@ -43,10 +43,12 @@ #include "auth/basic/basicUserRequest.h" #include "auth/Gadgets.h" #include "auth/State.h" +#include "charset.h" #include "mgr/Registration.h" #include "Store.h" #include "HttpReply.h" #include "rfc1738.h" +#include "uudecode.h" #include "wordlist.h" #include "SquidTime.h" diff --git a/src/auth/digest/auth_digest.cc b/src/auth/digest/auth_digest.cc index 90ed714b99..c6ff1b3a1e 100644 --- a/src/auth/digest/auth_digest.cc +++ b/src/auth/digest/auth_digest.cc @@ -41,6 +41,7 @@ #include "rfc2617.h" #include "auth/digest/auth_digest.h" #include "auth/Gadgets.h" +#include "base64.h" #include "event.h" #include "mgr/Registration.h" #include "Store.h" diff --git a/src/auth/digest/digestUserRequest.cc b/src/auth/digest/digestUserRequest.cc index 0816f98743..d7d9d8fa4e 100644 --- a/src/auth/digest/digestUserRequest.cc +++ b/src/auth/digest/digestUserRequest.cc @@ -2,6 +2,7 @@ #include "auth/digest/auth_digest.h" #include "auth/digest/digestUserRequest.h" #include "auth/State.h" +#include "charset.h" #include "HttpReply.h" #include "HttpRequest.h" #include "SquidTime.h" diff --git a/src/comm.cc b/src/comm.cc index f6ddba5273..180b30151b 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -2152,8 +2152,8 @@ ClientInfo::setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBu assert(!selectWaiting); assert(!quotaQueue); - quotaQueue = new CommQuotaQueue(this); - cbdataReference(quotaQueue); + CommQuotaQueue *tmp = new CommQuotaQueue(this); + quotaQueue = cbdataReference(tmp); bucketSize = anInitialBurst; prevTime = current_dtime; diff --git a/src/defines.h b/src/defines.h index a6ac3eeaec..1496edf250 100644 --- a/src/defines.h +++ b/src/defines.h @@ -68,8 +68,6 @@ #define COMM_TRANSPARENT 0x08 #define COMM_DOBIND 0x10 -#define safe_free(x) if (x) { xxfree(x); x = NULL; } - #define DISK_OK (0) #define DISK_ERROR (-1) #define DISK_EOF (-2) @@ -255,14 +253,6 @@ #define URI_WHITESPACE_CHOP 3 #define URI_WHITESPACE_DENY 4 -#ifndef _PATH_DEVNULL -#ifdef _SQUID_MSWIN_ -#define _PATH_DEVNULL "NUL" -#else -#define _PATH_DEVNULL "/dev/null" -#endif -#endif - #ifndef O_TEXT #define O_TEXT 0 #endif diff --git a/src/dlink.cc b/src/dlink.cc index 6094bb6124..88120f1d70 100644 --- a/src/dlink.cc +++ b/src/dlink.cc @@ -6,8 +6,6 @@ /* dlink are Mem-pooled */ #include "MemPool.h" -/* for xstrdup() */ -#include "util.h" dlink_list ClientActiveRequests; diff --git a/src/dnsserver.cc b/src/dnsserver.cc index 4cde6f0ec5..6205138955 100644 --- a/src/dnsserver.cc +++ b/src/dnsserver.cc @@ -31,9 +31,11 @@ */ #include "config.h" -#include "compat/inet_ntop.h" -#include "compat/getaddrinfo.h" -#include "compat/getnameinfo.h" +//#include "compat/inet_ntop.h" +//#include "compat/getaddrinfo.h" +//#include "compat/getnameinfo.h" +#include "ip/Address.h" +//#include "util.h" #if HAVE_UNISTD_H #include @@ -123,8 +125,6 @@ #include #endif -#include "util.h" - /** \defgroup dnsserver dnsserver \ingroup ExternalPrograms @@ -150,8 +150,6 @@ usage: dnsserver -Dhv -s nameserver \endverbatim */ -#include "ip/Address.h" - #if LIBRESOLV_DNS_TTL_HACK /// \ingroup dnsserver extern int _dns_ttl_; /* this is a really *dirty* hack - bne */ diff --git a/src/errorpage.cc b/src/errorpage.cc index feec181c4a..cc8acc9688 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -37,6 +37,7 @@ #include "auth/UserRequest.h" #include "SquidTime.h" #include "Store.h" +#include "html_quote.h" #include "HttpReply.h" #include "HttpRequest.h" #include "MemObject.h" diff --git a/src/ftp.cc b/src/ftp.cc index 9a0e61e97b..8973d26624 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -40,6 +40,7 @@ #include "errorpage.h" #include "fde.h" #include "forward.h" +#include "html_quote.h" #include "HttpHdrContRange.h" #include "HttpHeaderRange.h" #include "HttpHeader.h" diff --git a/src/gopher.cc b/src/gopher.cc index 6b47c0afdd..26e232a268 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -36,6 +36,7 @@ #include "squid.h" #include "errorpage.h" #include "Store.h" +#include "html_quote.h" #include "HttpRequest.h" #include "HttpReply.h" #include "comm.h" diff --git a/src/http.cc b/src/http.cc index 59cef61db4..37f8996f3a 100644 --- a/src/http.cc +++ b/src/http.cc @@ -44,6 +44,7 @@ #include "auth/UserRequest.h" #include "base/AsyncJobCalls.h" #include "base/TextException.h" +#include "base64.h" #if DELAY_POOLS #include "DelayPools.h" #endif diff --git a/src/icmp/Makefile.am b/src/icmp/Makefile.am index b637923da6..bbc76b59e8 100644 --- a/src/icmp/Makefile.am +++ b/src/icmp/Makefile.am @@ -1,4 +1,3 @@ - include $(top_srcdir)/src/Common.am include $(top_srcdir)/src/TestHeaders.am @@ -7,7 +6,6 @@ include $(top_srcdir)/src/TestHeaders.am DEFS += -DDEFAULT_CONFIG_FILE=NULL - # ICMP Specific Configurations if ENABLE_PINGER @@ -62,12 +60,8 @@ pinger_LDFLAGS = $(LIBADD_DL) pinger_LDADD=\ libicmp-core.la \ ../ip/libip.la \ - $(XTRA_LIBS) \ - $(top_builddir)/lib/libmiscutil.a -pinger_DEPENDENCIES= \ - libicmp-core.la \ - $(top_builddir)/lib/libmiscutil.a - + $(COMPAT_LIB) \ + $(XTRA_LIBS) ##install-pinger: @@ -96,6 +90,7 @@ testIcmp_SOURCES = \ nodist_testIcmp_SOURCES = \ $(top_srcdir)/src/tests/testMain.cc \ $(top_srcdir)/src/SquidTime.h \ + $(top_srcdir)/src/tests/stub_debug.cc \ $(top_srcdir)/src/time.cc \ $(top_srcdir)/test-suite/test_tools.cc \ $(top_builddir)/src/globals.cc @@ -105,8 +100,6 @@ testIcmp_LDADD=\ $(SQUID_CPPUNIT_LA) \ libicmp-core.la \ ../ip/libip.la \ - $(XTRA_LIBS) \ - $(top_builddir)/lib/libmiscutil.a -testIcmp_DEPENDENCIES= $(SQUID_CPPUNIT_LA) \ - libicmp-core.la \ - $(top_builddir)/lib/libmiscutil.a + $(COMPAT_LIB) \ + $(XTRA_LIBS) +testIcmp_DEPENDENCIES= $(SQUID_CPPUNIT_LA) diff --git a/src/ip/Makefile.am b/src/ip/Makefile.am index 989f29d291..17b8823e19 100644 --- a/src/ip/Makefile.am +++ b/src/ip/Makefile.am @@ -23,6 +23,7 @@ testIpAddress_SOURCES= \ testAddress.cc \ testAddress.h nodist_testIpAddress_SOURCES= \ + $(top_srcdir)/src/tests/stub_debug.cc \ $(top_srcdir)/src/tests/testMain.cc \ $(top_srcdir)/test-suite/test_tools.cc testIpAddress_LDADD= \ diff --git a/src/main.cc b/src/main.cc index e8bc8b0d4e..182474ed60 100644 --- a/src/main.cc +++ b/src/main.cc @@ -97,15 +97,16 @@ #if USE_ADAPTATION #include "adaptation/Config.h" #endif - #if USE_SQUID_ESI #include "esi/Module.h" #endif - #include "fs/Module.h" -#if USE_WIN32_SERVICE +#if HAVE_PATHS_H +#include +#endif +#if USE_WIN32_SERVICE #include "squid_windows.h" #include diff --git a/src/protos.h b/src/protos.h index 9b71b3d496..c78891c23f 100644 --- a/src/protos.h +++ b/src/protos.h @@ -104,14 +104,6 @@ extern void clientAccessCheck(void *); #include "Debug.h" -/* see debug.c for info on context-based debugging */ -SQUIDCEXTERN Ctx ctx_enter(const char *descr); -SQUIDCEXTERN void ctx_exit(Ctx ctx); - -SQUIDCEXTERN void _db_set_syslog(const char *facility); -SQUIDCEXTERN void _db_init(const char *logfile, const char *options); -SQUIDCEXTERN void _db_rotate_log(void); - /* packs, then prints an object using debugs() */ SQUIDCEXTERN void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm); diff --git a/src/squid.h b/src/squid.h index 4cdda62bb7..81cba215ce 100644 --- a/src/squid.h +++ b/src/squid.h @@ -166,7 +166,7 @@ using namespace Squid; #include "enums.h" #include "typedefs.h" #include "util.h" -#include "profiling.h" +#include "profiler/Profiler.h" #include "MemPool.h" #include "ip/Address.h" #include "structs.h" diff --git a/src/tests/stub_debug.cc b/src/tests/stub_debug.cc new file mode 100644 index 0000000000..556d3b4e00 --- /dev/null +++ b/src/tests/stub_debug.cc @@ -0,0 +1,142 @@ +/* + * A stub implementation of the Debug.h API. + * For use by test binaries which do not need the full context debugging + */ +#include "config.h" +#include "Debug.h" + +#if HAVE_STDIO_H +#include +#endif + +FILE *debug_log = NULL; +int Debug::TheDepth = 0; + +char *Debug::debugOptions; +char *Debug::cache_log= NULL; +int Debug::rotateNumber = 0; +int Debug::Levels[MAX_DEBUG_SECTIONS]; +int Debug::level; +int Debug::override_X = 0; +int Debug::log_stderr = 1; +bool Debug::log_syslog = false; + +Ctx +ctx_enter(const char *descr) +{ + return -1; +} + +void +ctx_exit(Ctx ctx) +{ +} + +void +_db_init(const char *logfile, const char *options) +{} + +void +_db_set_syslog(const char *facility) +{} + +void +_db_rotate_log(void) +{} + +static void +_db_print_stderr(const char *format, va_list args); + +void +_db_print(const char *format,...) +{ + static char f[BUFSIZ]; + va_list args1; + va_list args2; + va_list args3; + + va_start(args1, format); + va_start(args2, format); + va_start(args3, format); + + snprintf(f, BUFSIZ, "%s| %s", + "stub time", //debugLogTime(squid_curtime), + format); + + _db_print_stderr(f, args2); + + va_end(args1); + va_end(args2); + va_end(args3); +} + +static void +_db_print_stderr(const char *format, va_list args) +{ + /* FIXME? */ + // if (opt_debug_stderr < Debug::level) + + if (1 < Debug::level) + return; + + vfprintf(stderr, format, args); +} + +std::ostream & +Debug::getDebugOut() +{ + assert(TheDepth >= 0); + ++TheDepth; + if (TheDepth > 1) { + assert(CurrentDebug); + *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{"; + } else { + assert(!CurrentDebug); + CurrentDebug = new std::ostringstream(); + // set default formatting flags + CurrentDebug->setf(std::ios::fixed); + CurrentDebug->precision(2); + } + return *CurrentDebug; +} + +void +Debug::parseOptions(char const *) +{ + return; +} + +void +Debug::finishDebug() +{ + assert(TheDepth >= 0); + assert(CurrentDebug); + if (TheDepth > 1) { + *CurrentDebug << "}-" << TheDepth << std::endl; + } else { + assert(TheDepth == 1); + _db_print("%s\n", CurrentDebug->str().c_str()); + delete CurrentDebug; + CurrentDebug = NULL; + } + --TheDepth; +} + +void +Debug::xassert(const char *msg, const char *file, int line) +{ + + if (CurrentDebug) { + *CurrentDebug << "assertion failed: " << file << ":" << line << + ": \"" << msg << "\""; + } + abort(); +} + +std::ostringstream *Debug::CurrentDebug (NULL); + +const char* +SkipBuildPrefix(const char* path) +{ + return path; +} diff --git a/src/time.cc b/src/time.cc index 20cf69a9e2..064e514be3 100644 --- a/src/time.cc +++ b/src/time.cc @@ -31,12 +31,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ - +#include "config.h" #include "SquidTime.h" struct timeval current_time; double current_dtime; - time_t squid_curtime = 0; time_t @@ -54,6 +53,13 @@ getCurrentTime(void) return squid_curtime = current_time.tv_sec; } +int +tvSubMsec(struct timeval t1, struct timeval t2) +{ + return (t2.tv_sec - t1.tv_sec) * 1000 + + (t2.tv_usec - t1.tv_usec) / 1000; +} + TimeEngine::~TimeEngine() {} diff --git a/src/unlinkd_daemon.cc b/src/unlinkd_daemon.cc index 8ad87dd08c..292b036968 100644 --- a/src/unlinkd_daemon.cc +++ b/src/unlinkd_daemon.cc @@ -1,4 +1,3 @@ - /* * $Id$ * @@ -35,7 +34,11 @@ #define SQUID_HELPER 1 -#include "squid.h" +#include "config.h" + +#if HAVE_PATHS_H +#include +#endif /** \defgroup unlinkd unlinkd @@ -88,5 +91,5 @@ main(int argc, char *argv[]) printf("OK\n"); } - exit(0); + return 0; } diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 0a7bc20886..cedd9833ef 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -1,9 +1,3 @@ -# -# Makefile for the Squid Object Cache server -# -# $Id$ -# - include $(top_srcdir)/src/Common.am AUTOMAKE_OPTIONS = subdir-objects @@ -12,9 +6,11 @@ AUTOMAKE_OPTIONS = subdir-objects INCLUDES += -I$(srcdir) LDADD = \ - $(COMPAT_LIB) \ $(top_builddir)/src/globals.o \ - $(top_builddir)/src/time.o + $(top_builddir)/src/time.o \ + $(top_builddir)/lib/libmiscutil.la \ + $(COMPAT_LIB) \ + $(XTRA_LIBS) EXTRA_PROGRAMS = mem_node_test membanger splay tcp-banger2 @@ -54,24 +50,42 @@ check_PROGRAMS += debug \ VirtualDeleteOperator -tcp_banger2_LDADD = -L$(top_builddir)/lib -lmiscutil -DEBUG_SOURCE = test_tools.cc +tcp_banger2_LDADD = $(top_builddir)/lib/libmiscutil.la + + +DEBUG_SOURCE = test_tools.cc stub_debug.cc + +stub_debug.cc: $(top_srcdir)/src/tests/stub_debug.cc + cp $(top_srcdir)/src/tests/stub_debug.cc . + +CLEANFILES += stub_debug.cc + +## XXX: somewhat broken. Its meant to test our debugs() implementation. +## but it has never been linked to the actual src/debug.cc implementation !! +## all it tests are the stream operators and macro in src/Debug.h debug_SOURCES = debug.cc $(DEBUG_SOURCE) + ESIExpressions_SOURCES = ESIExpressions.cc $(DEBUG_SOURCE) ESIExpressions_LDADD = $(top_builddir)/src/esi/Expression.o \ $(LDADD) + mem_node_test_SOURCES = mem_node_test.cc mem_node_test_LDADD = $(top_builddir)/src/mem_node.o $(LDADD) + mem_hdr_test_SOURCES = mem_hdr_test.cc $(DEBUG_SOURCE) mem_hdr_test_LDADD = $(top_builddir)/src/stmem.o \ $(top_builddir)/src/mem_node.o $(LDADD) + MemPoolTest_SOURCES = MemPoolTest.cc + refcount_SOURCES = refcount.cc splay_SOURCES = splay.cc StackTest_SOURCES = StackTest.cc $(DEBUG_SOURCE) + syntheticoperators_SOURCES = syntheticoperators.cc $(DEBUG_SOURCE) + VirtualDeleteOperator_SOURCES = VirtualDeleteOperator.cc $(DEBUG_SOURCE) ## membanger won't link today. Bitrot.. diff --git a/test-suite/test_tools.cc b/test-suite/test_tools.cc index 0f6754acfe..1f76733a1a 100644 --- a/test-suite/test_tools.cc +++ b/test-suite/test_tools.cc @@ -2,19 +2,11 @@ * $Id$ */ -// XXX: This file is made of large pieces of src/debug.cc and src/tools.cc +// XXX: This file is made of large pieces of src/tools.cc // with only a few minor modifications. TODO: redesign or delete. #include "squid.h" -/* AYJ: the debug stuff here should really be in a stub_debug.cc file for tests to link */ - -/* for correct pre-definitions of debug objects */ -/* and stream headers */ -#include "Debug.h" - -FILE *debug_log = NULL; - void xassert(const char *msg, const char *file, int line) { @@ -22,47 +14,6 @@ xassert(const char *msg, const char *file, int line) exit (1); } -int Debug::Levels[MAX_DEBUG_SECTIONS]; -int Debug::level; - -static void -_db_print_stderr(const char *format, va_list args); - -void -_db_print(const char *format,...) -{ - LOCAL_ARRAY(char, f, BUFSIZ); - va_list args1; - va_list args2; - va_list args3; - - va_start(args1, format); - va_start(args2, format); - va_start(args3, format); - - snprintf(f, BUFSIZ, "%s| %s", - "stub time", //debugLogTime(squid_curtime), - format); - - _db_print_stderr(f, args2); - - va_end(args1); - va_end(args2); - va_end(args3); -} - -static void -_db_print_stderr(const char *format, va_list args) -{ - /* FIXME? */ - // if (opt_debug_stderr < Debug::level) - - if (1 < Debug::level) - return; - - vfprintf(stderr, format, args); -} - void fatal_dump(const char *message) { @@ -102,65 +53,10 @@ debug_trap(const char *message) fatal(message); } -int Debug::TheDepth = 0; - -std::ostream & -Debug::getDebugOut() -{ - assert(TheDepth >= 0); - ++TheDepth; - if (TheDepth > 1) { - assert(CurrentDebug); - *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{"; - } else { - assert(!CurrentDebug); - CurrentDebug = new std::ostringstream(); - // set default formatting flags - CurrentDebug->setf(std::ios::fixed); - CurrentDebug->precision(2); - } - return *CurrentDebug; -} - -void -Debug::finishDebug() -{ - assert(TheDepth >= 0); - assert(CurrentDebug); - if (TheDepth > 1) { - *CurrentDebug << "}-" << TheDepth << std::endl; - } else { - assert(TheDepth == 1); - _db_print("%s\n", CurrentDebug->str().c_str()); - delete CurrentDebug; - CurrentDebug = NULL; - } - --TheDepth; -} - -void -Debug::xassert(const char *msg, const char *file, int line) -{ - - if (CurrentDebug) { - *CurrentDebug << "assertion failed: " << file << ":" << line << - ": \"" << msg << "\""; - } - abort(); -} - -std::ostringstream *Debug::CurrentDebug(NULL); - -MemAllocator *dlink_node_pool = NULL; - dlink_node * dlinkNodeNew() { - if (dlink_node_pool == NULL) - dlink_node_pool = memPoolCreate("Dlink list nodes", sizeof(dlink_node)); - - /* where should we call memPoolDestroy(dlink_node_pool); */ - return static_cast(dlink_node_pool->alloc()); + return new dlink_node; } /* the node needs to be unlinked FIRST */ @@ -170,7 +66,7 @@ dlinkNodeDelete(dlink_node * m) if (m == NULL) return; - dlink_node_pool->freeOne(m); + delete m; } void @@ -239,18 +135,3 @@ dlinkDelete(dlink_node * m, dlink_list * list) m->next = m->prev = NULL; } - -Ctx -ctx_enter(const char *descr) -{ - return 0; -} - -void -ctx_exit(Ctx ctx) {} - -// for debugs() -const char* SkipBuildPrefix(const char* path) -{ - return path; -} diff --git a/tools/Makefile.am b/tools/Makefile.am index abdab389c2..8763081bdd 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -17,8 +17,11 @@ man_MANS = DISTCLEANFILES = LDADD = \ + $(top_builddir)/src/tests/stub_debug.o \ $(top_builddir)/src/time.o \ $(top_builddir)/src/ip/libip.la \ + $(top_builddir)/lib/libmiscencoding.la \ + $(top_builddir)/lib/libmiscutil.la \ $(COMPAT_LIB) \ $(KRB5LIBS) \ $(XTRA_LIBS) diff --git a/tools/cachemgr.cc b/tools/cachemgr.cc index 39816cda7c..6a77e88329 100644 --- a/tools/cachemgr.cc +++ b/tools/cachemgr.cc @@ -31,9 +31,11 @@ */ #include "config.h" -#include "compat/tempnam.h" +#include "base64.h" #include "getfullhostname.h" +#include "html_quote.h" #include "ip/Address.h" +#include "rfc1123.h" #include "rfc1738.h" #include "util.h" @@ -143,7 +145,6 @@ static time_t now; /* * Function prototypes */ -#define safe_free(str) { if (str) { xfree(str); (str) = NULL; } } static const char *safe_str(const char *str); static const char *xstrtok(char **str, char del); static void print_trailer(void); diff --git a/tools/squidclient.cc b/tools/squidclient.cc index 4eea9e0bc3..07b6371c63 100644 --- a/tools/squidclient.cc +++ b/tools/squidclient.cc @@ -33,8 +33,10 @@ */ #include "config.h" +#include "base64.h" #include "ip/Address.h" -#include "util.h" +#include "rfc1123.h" +#include "SquidTime.h" #ifdef _SQUID_MSWIN_ /** \cond AUTODOCS-IGNORE */