]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
merged from trunk
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 10 Aug 2009 11:11:47 +0000 (23:11 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 10 Aug 2009 11:11:47 +0000 (23:11 +1200)
15 files changed:
CREDITS
compat/compat.h
compat/helper_debug.h [new file with mode: 0644]
configure.in
helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c
helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.h
helpers/url_rewrite/Makefile.am [new file with mode: 0644]
helpers/url_rewrite/fake/Makefile.am [new file with mode: 0644]
helpers/url_rewrite/fake/config.test [new file with mode: 0755]
helpers/url_rewrite/fake/fake.cc [new file with mode: 0644]
helpers/url_rewrite/fake/fake.h [new file with mode: 0644]
helpers/url_rewrite/fake/url_fake_rewrite.sh [new file with mode: 0644]
src/Common.am
src/helper.cc
src/main.cc

diff --git a/CREDITS b/CREDITS
index e9daf0d32d3fa88bbba022a7fc084d52a14ec374..4a00651cc0bbc047024e302015612ead910b9a60 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -391,8 +391,9 @@ lib/libTrie/*:
 include/IPAddress.h lib/IPAddress.cc:
 include/rfc3596.h lib/rfc3596.cc:
 src/ICMPv6.h src/ICMPv6.cc:
+helpers/url_rewrite/fake/ fake.h, fake.cc, url_fake_rewrite.sh:
 
- This code is copyright (C) 2007 by Treehouse Networks Ltd
+ This code is copyright (C) 2007-2009 by Treehouse Networks Ltd
  of New Zealand. It is published and Licensed as an extension of
  squid under the same conditions as the main squid application.
 
index bacbc5aae2f75d485f401602856dad467c7e9c55..69f0be36eb98eef6c17692fa3537c5bbd0cd88cc 100644 (file)
 #include "compat/stdvarargs.h"
 #include "compat/assert.h"
 
+
 /*****************************************************/
 /* component-specific portabilities                  */
 /*****************************************************/
 
+/* helper debugging requires some hacks to be clean */
+#include "compat/helper_debug.h"
+
 /* Valgrind API macros changed between two versions squid supports */
 #include "compat/valgrind.h"
 
diff --git a/compat/helper_debug.h b/compat/helper_debug.h
new file mode 100644 (file)
index 0000000..59b5ff2
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef SQUID_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef COMPAT_HELPER_DEBUG_H
+#define COMPAT_HELPER_DEBUG_H
+
+/*
+ * A debug method for use of external helpers.
+ * It shunts the debug messages down stderr for logging by Squid
+ * of display to the user instead of corrupting the stdout data stream.
+ */
+
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* Debugging stuff */
+
+/* the macro overload style is really a gcc-ism */
+#ifdef __GNUC__
+
+SQUIDCEXTERN int debug_enabled;
+
+#define helper_debug(X...) \
+                     if (debug_enabled) { \
+                         fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
+                         fprintf(stderr,X); \
+                     }
+
+#else /* __GNUC__ */
+
+/* TODO: non-GCC compilers can't do the above macro define yet. */
+inline void
+helper_debug(char *format,...)
+{
+    ; // nothing to do.
+}
+#endif
+
+
+#endif /* COMPAT_HELPER_DEBUG_H */
index ade54a2148ca82cf61c55d0b41ada51d09e8cbd7..fca3906b54635d555f01646d66355b4db0776658 100644 (file)
@@ -1814,6 +1814,48 @@ if test -n "$EXTERNAL_ACL_HELPERS"; then
 fi
 AC_SUBST(EXTERNAL_ACL_HELPERS)
 
+dnl Select url_rewrite helpers to build
+URL_REWRITE_HELPERS=all
+AC_ARG_ENABLE(url-rewrite-helpers,
+  AC_HELP_STRING([--enable-url-rewrite-helpers="list of helpers"],
+                 [This option selects which url_rewrite helpers to
+                  build and install as part of the normal build
+                  process. For a list of available helpers see the
+                  helpers/url_rewrite directory.]),
+[ case "$enableval" in
+  yes)
+       URL_REWRITE_HELPERS=all
+       ;;
+  no)
+       URL_REWRITE_HELPERS=""
+       ;;
+  *)
+       URL_REWRITE_HELPERS="`echo $enableval| sed -e 's/,/ /g;s/  */ /g'`"
+       ;;
+  esac
+])
+if test "$URL_REWRITE_HELPERS" = "all" ; then
+       URL_REWRITE_HELPERS=""
+       for dir in $srcdir/helpers/url_rewrite/*; do
+           helper="`basename $dir`"
+           if test -f $dir/config.test && sh $dir/config.test "$@"; then
+               URL_REWRITE_HELPERS="$URL_REWRITE_HELPERS $helper"
+           fi
+       done
+fi
+if test -n "$URL_REWRITE_HELPERS"; then
+    for helper in $URL_REWRITE_HELPERS; do
+       if test -f $srcdir/helpers/url_rewrite/$helper/Makefile.in; then
+               :
+       else
+               AC_MSG_ERROR(url_rewrite helper $helper does not exist)
+       fi
+    done
+    AC_MSG_NOTICE([url_rewrite helpers built: $URL_REWRITE_HELPERS])
+fi
+AC_SUBST(URL_REWRITE_HELPERS)
+
+
 AC_ARG_WITH(valgrind-debug,
   AS_HELP_STRING([--with-valgrind-debug],[Include debug instrumentation for use with valgrind]),
 [ case $withval in
@@ -3809,6 +3851,8 @@ AC_CONFIG_FILES([\
        helpers/external_acl/wbinfo_group/Makefile \
        helpers/external_acl/mswin_ad_group/Makefile \
        helpers/external_acl/mswin_lm_group/Makefile \
+       helpers/url_rewrite/Makefile \
+       helpers/url_rewrite/fake/Makefile \
        tools/Makefile
 ])
 
index 80a9c3008c8a57ca3adfe233836e9051a4f3e6c2..597150bf8f42dc05a0603f9f31b17d87eb15a5bd 100644 (file)
@@ -155,7 +155,7 @@ usage()
             my_program_name, my_program_name);
 }
 
-char debug_enabled=0;
+int debug_enabled=0;
 
 void
 process_options(int argc, char *argv[])
index de63809b057bf5f146a8296f6795e8e4d6498ccc..50a2aa199c64ff322a034b8145760d56a99d7afd 100644 (file)
 
 
 /* Debugging stuff */
-
+#ifndef debug /* already provided */
 #ifdef __GNUC__                        /* this is really a gcc-ism */
 #ifdef DEBUG
 #include <stdio.h>
 #include <unistd.h>
 static const char *__foo;
-extern char debug_enabled;
+extern int debug_enabled;
 #define debug(X...) if (debug_enabled) { \
                     fprintf(stderr,"ntlm-auth[%ld](%s:%d): ", (long)getpid(), \
                     ((__foo=strrchr(__FILE__,'/'))==NULL?__FILE__:__foo+1),\
@@ -65,9 +65,8 @@ static void
 debug(char *format,...)
 {
 }
-
 #endif
-
+#endif /* debug already defined */
 
 /* A couple of harmless helper macros */
 #define SEND(X) debug("sending '%s' to squid\n",X); printf(X "\n");
diff --git a/helpers/url_rewrite/Makefile.am b/helpers/url_rewrite/Makefile.am
new file mode 100644 (file)
index 0000000..f439bcb
--- /dev/null
@@ -0,0 +1,3 @@
+
+DIST_SUBDIRS   = fake
+SUBDIRS                = @URL_REWRITE_HELPERS@
diff --git a/helpers/url_rewrite/fake/Makefile.am b/helpers/url_rewrite/fake/Makefile.am
new file mode 100644 (file)
index 0000000..a2085c6
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/src/Common.am
+libexec_PROGRAMS = url_fake_rewrite url_fake_rewrite.sh
+
+url_fake_rewrite_SOURCES = fake.cc
+url_fake_rewrite_LDADD = $(COMPAT_LIBS)
diff --git a/helpers/url_rewrite/fake/config.test b/helpers/url_rewrite/fake/config.test
new file mode 100755 (executable)
index 0000000..039e4d0
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+exit 0
diff --git a/helpers/url_rewrite/fake/fake.cc b/helpers/url_rewrite/fake/fake.cc
new file mode 100644 (file)
index 0000000..5b9cfd9
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * AUTHOR: Amos Jeffries <squid3@treenet.co.nz>
+ *
+ * Example url re-writer program for Squid.
+ *
+ * This code gets the url and returns it. No re-writing is done.
+ * It is intended for testing use and as a base for further implementation.
+ *
+ *
+ * This code is copyright (C) 2009 by Treehouse Networks Ltd
+ * of New Zealand. It is published and Licensed as an extension of
+ * squid under the same conditions as the main squid application.
+ */
+
+#include "config.h"
+
+#define BUFFER_SIZE 10240
+
+/**
+ * options:
+ * -d enable debugging.
+ * -h interface help.
+ */
+char *my_program_name = NULL;
+int concurrent_detected = -1;
+
+
+static void
+usage(void)
+{
+    fprintf(stderr,
+            "Usage: %s [-d] [-v] [-h]\n"
+            " -d  enable debugging.\n"
+            " -h  this message\n\n",
+            my_program_name);
+}
+
+static void
+process_options(int argc, char *argv[])
+{
+    int opt, had_error = 0;
+
+    opterr = 0;
+    while (-1 != (opt = getopt(argc, argv, "hd"))) {
+        switch (opt) {
+        case 'd':
+            debug_enabled = 1;
+            break;
+        case 'h':
+            usage();
+            exit(0);
+        case '?':
+            opt = optopt;
+            /* fall thru to default */
+        default:
+            fprintf(stderr, "unknown option: -%c. Exiting\n", opt);
+            usage();
+            had_error = 1;
+        }
+    }
+    if (had_error)
+        exit(1);
+}
+
+bool
+detect_concurrent(const char *)
+{
+    // TODO: scan the char* input and see if it is 100% numeric.
+    //   if so, enable concurrent support IDs.
+}
+
+int
+main(int argc, char *argv[])
+{
+    char buf[BUFFER_SIZE];
+    int buflen = 0;
+    char helper_command[3];
+
+    setbuf(stdout, NULL);
+    setbuf(stderr, NULL);
+
+    my_program_name = argv[0];
+
+    process_options(argc, argv);
+
+    helper_debug("%s build " __DATE__ ", " __TIME__ " starting up...\n", my_program_name);
+
+    while (fgets(buf, BUFFER_SIZE, stdin) != NULL) {
+
+        if ((p = strchr(buf, '\n')) != NULL) {
+            *p = '\0';         /* strip \n */
+            buflen = p - buf;   /* length is known already */
+        }
+        else
+            buflen = strlen(buf);   /* keep this so we only scan the buffer for \0 once per loop */
+
+/* TODO: later.
+        if (concurrent_detected < 0)
+            detect_concurrent(buf);
+// */
+
+        helper_debug("Got %d bytes '%s' from Squid\n", buflen, buf);
+
+        /* send 'no-change' result back to Squid */
+        fprintf(stdout,"\n");
+    }
+    helper_debug("%s build " __DATE__ ", " __TIME__ " shutting down...\n", my_program_name);
+    exit(0);
+}
diff --git a/helpers/url_rewrite/fake/fake.h b/helpers/url_rewrite/fake/fake.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/helpers/url_rewrite/fake/url_fake_rewrite.sh b/helpers/url_rewrite/fake/url_fake_rewrite.sh
new file mode 100644 (file)
index 0000000..bcfdf26
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# Author: Amos Jeffries <squid3@treenet.co.nz>
+#
+# This code is copyright (C) 2009 by Treehouse Networks Ltd
+# of New Zealand. It is published and Licensed as an extension of
+# squid under the same conditions as the main squid application.
+#
+
+if test "${1}" = "-d" ; then
+       echo "Usage: $0 [-h] [-d logfile]"
+       echo "  -h           Help: this help text"
+       echo "  -d logfile   Debug: log all data received to the named file"
+       exit 1
+fi
+
+DEBUG=0
+if test "${1}" = "-d" ; then
+       DEBUG=1
+       LOG="${2}"
+fi
+
+while read url rest; do
+       if test ${DEBUG} ; then
+               echo "$url $rest" >>${LOG}
+       fi
+       echo  # blank line for no change, or replace with another URL.
+done
index 084f108ccae7a797bde88ec5940d726665d8d784..d9239cc54228f778a43d6339f028f0467f0b0518 100644 (file)
@@ -23,3 +23,8 @@ INCLUDES = \
 ## make all compiled sources depend on generated files
 ## XXX: Do we really need this? Does auto-dependency tracking work?
 $(OBJS): $(top_srcdir)/include/version.h $(top_builddir)/include/autoconf.h
+
+## Because compatibility is almost universal. And the link order is important.
+COMPAT_LIBS = \
+       -L$(top_builddir)/lib -lmiscutil \
+       $(top_builddir)/compat/libcompat.la
index 8f4c6db3e4aa9e379e71687f2b2f4fd06c55c59f..ade7eb6909cd73f00c7c5b262a26a25bd9417638 100644 (file)
@@ -182,7 +182,7 @@ helperOpenServers(helper * hlp)
     helperKickQueue(hlp);
 }
 
-/*
+/**
  * DPW 2007-05-08
  *
  * helperStatefulOpenServers: create the stateful child helper processes
@@ -321,8 +321,7 @@ helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data)
     debugs(84, 9, "helperSubmit: " << buf);
 }
 
-/* lastserver = "server last used as part of a reserved request sequence"
- */
+/// lastserver = "server last used as part of a reserved request sequence"
 void
 helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPSCB * callback, void *data, helper_stateful_server * lastserver)
 {
@@ -363,7 +362,7 @@ helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPSCB * callback, v
     debugs(84, 9, "helperStatefulSubmit: placeholder: '" << r->placeholder << "', buf '" << buf << "'.");
 }
 
-/*
+/**
  * DPW 2007-05-08
  *
  * helperStatefulReleaseServer tells the helper that whoever was
@@ -385,13 +384,16 @@ helperStatefulReleaseServer(helper_stateful_server * srv)
     helperStatefulServerDone(srv);
 }
 
+/** return a pointer to the stateful routines data area */
 void *
 helperStatefulServerGetData(helper_stateful_server * srv)
-/* return a pointer to the stateful routines data area */
 {
     return srv->data;
 }
 
+/**
+ * Dump some stats about the helper states to a StoreEntry
+ */
 void
 helperStats(StoreEntry * sentry, helper * hlp, const char *label)
 {
@@ -476,9 +478,9 @@ helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label
 
     for (dlink_node *link = hlp->servers.head; link; link = link->next) {
         helper_stateful_server *srv = (helper_stateful_server *)link->data;
-        double tt = 0.001 * tvSubMsec(srv->dispatch_time,
-                                      srv->flags.busy ? current_time : srv->answer_time);
-        storeAppendPrintf(sentry, "%7d\t%7d\t%7d\t%11d\t%c%c%c%c%c\t%7.3f\t%7d\t%s\n",
+        double tt = 0.001 * tvSubMsec(srv->dispatch_time, srv->flags.busy ? current_time : srv->answer_time);
+        double tr = 0.001 * tvSubMsec(srv->dispatch_time, current_time);
+        storeAppendPrintf(sentry, "%7d\t%7d\t%7d\t%11d\t%c%c%c%c%c\t%7.3f\t%7.3f\t%7d\t%s\n",
                           srv->index + 1,
                           srv->rfd,
                           srv->pid,
@@ -488,9 +490,10 @@ helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label
                           srv->flags.reserved ? 'R' : ' ',
                           srv->flags.shutdown ? 'S' : ' ',
                           srv->request ? (srv->request->placeholder ? 'P' : ' ') : ' ',
-                                  tt < 0.0 ? 0.0 : tt,
-                                  (int) srv->roffset,
-                                  srv->request ? log_quote(srv->request->buf) : "(none)");
+                          tt < 0.0 ? 0.0 : tt,
+                          srv->flags.reserved || tr > 0.0 ? tr : 0.0,
+                          (int) srv->roffset,
+                          srv->request ? log_quote(srv->request->buf) : "(none)");
     }
 
     storeAppendPrintf(sentry, "\nFlags key:\n\n");
index 00bb217c56f6ba5f6d0db5782691723d24a8ba31..d89ca8cb91bf07399361387b2422af9e08bc3119 100644 (file)
@@ -786,13 +786,12 @@ mainRotate(void)
 {
     icmpEngine.Close();
 #if USE_DNSSERVERS
-
     dnsShutdown();
 #endif
-
     redirectShutdown();
     authenticateShutdown();
     externalAclShutdown();
+
     _db_rotate_log();          /* cache.log */
     storeDirWriteCleanLogs(1);
     storeLogRotate();          /* store.log */
@@ -803,16 +802,13 @@ mainRotate(void)
     icapLogRotate();               /*icap.log*/
 #endif
 #if WIP_FWD_LOG
-
     fwdLogRotate();
 #endif
 
     icmpEngine.Open();
 #if USE_DNSSERVERS
-
     dnsInit();
 #endif
-
     redirectInit();
     authenticateInit(&Config.authConfiguration);
     externalAclInit();