]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: Refactor IcmpConfig
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 15 May 2015 12:50:09 +0000 (05:50 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 15 May 2015 12:50:09 +0000 (05:50 -0700)
Pull the IcmpConfig object out of the global SquidConfig structure and
updates it to processing its own parse logics. Bringing it inline with
the per-component configuration design in SourceLayout and HotConf projects.

This allows us to use SBuf for storing the pinger program details and
avoid valgrind complaints about some malloc.

It will also allow lazy re-starting of the helper to be implemented later.

src/SquidConfig.h
src/cache_cf.cc
src/cf.data.depend
src/cf.data.pre
src/icmp/IcmpConfig.cc [new file with mode: 0644]
src/icmp/IcmpConfig.h
src/icmp/IcmpSquid.cc
src/icmp/Makefile.am

index 30cffc1eb78de74c23abc4ff349e120be78b8030..f4c5a9777bf71ca735bb68a015e051e92fcf389c 100644 (file)
@@ -15,7 +15,6 @@
 #include "DelayConfig.h"
 #include "helper/ChildConfig.h"
 #include "HttpHeaderTools.h"
-#include "icmp/IcmpConfig.h"
 #include "ip/Address.h"
 #include "Notes.h"
 #include "YesNoNone.h"
@@ -148,10 +147,6 @@ public:
     } Wccp2;
 #endif
 
-#if USE_ICMP
-    IcmpConfig pinger;
-#endif
-
     char *as_whois_server;
 
     struct {
index b66c4ba457268ebf8157a9317a555a2b067e30c8..1bdfcca8926eb6665d0fbd108c9349e125f2f3ae 100644 (file)
@@ -32,6 +32,7 @@
 #include "ftp/Elements.h"
 #include "globals.h"
 #include "HttpHeaderTools.h"
+#include "icmp/IcmpConfig.h"
 #include "ident/Config.h"
 #include "ip/Intercept.h"
 #include "ip/QosConfig.h"
index f30194fa42948058123aa0b6389e06a5b9e97533..3f47a4770ca2ef52b0ee1d4baf0237e5a7e05c62 100644 (file)
@@ -48,6 +48,7 @@ icap_access_type      icap_class acl
 icap_class_type                icap_service
 icap_service_type
 icap_service_failure_limit
+icmp
 ecap_service_type
 int
 kb_int64_t
index 0b6e1067cdfd2df7cad8e1edd2bad3e5820647f6..6975ca293d2f2caf26d745f4531839436c0aaa7d 100644 (file)
@@ -4929,10 +4929,10 @@ DOC_START
 DOC_END
 
 NAME: pinger_program
-TYPE: string
-DEFAULT: @DEFAULT_PINGER@
-LOC: Config.pinger.program
 IFDEF: USE_ICMP
+TYPE: icmp
+DEFAULT: @DEFAULT_PINGER@
+LOC: IcmpCfg
 DOC_START
        Specify the location of the executable for the pinger process.
 DOC_END
@@ -4940,7 +4940,7 @@ DOC_END
 NAME: pinger_enable
 TYPE: onoff
 DEFAULT: on
-LOC: Config.pinger.enable
+LOC: IcmpCfg.enable
 IFDEF: USE_ICMP
 DOC_START
        Control whether the pinger is active at run-time.
diff --git a/src/icmp/IcmpConfig.cc b/src/icmp/IcmpConfig.cc
new file mode 100644 (file)
index 0000000..bc3ef24
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+/* DEBUG: section 03    Configuration Settings */
+
+#include "squid.h"
+
+#if USE_ICMP
+#include "ConfigParser.h"
+#include "IcmpConfig.h"
+
+IcmpConfig IcmpCfg;
+
+void
+IcmpConfig::parse()
+{
+    if (char *token = ConfigParser::NextQuotedOrToEol()) {
+        program.clear();
+        program.append(token);
+    } else
+        self_destruct();
+}
+
+#endif /* USE_ICMP */
+
index ef22bce4d91a0d2176402642158bc0451fa4f086..04f782cb27fb49e5e85acda8995bbd80cfec8366 100644 (file)
 #ifndef ICMPCONFIG_H
 #define ICMPCONFIG_H
 
+#if USE_ICMP
+
+#include "cache_cf.h"
+#include "SBuf.h"
+
 /**
  * Squid pinger Configuration settings
- *
- \par
- * This structure is included as a child field of the global Config
- * such that if ICMP is built it can be accessed as Config.pinger.*
  */
 class IcmpConfig
 {
-
 public:
+    IcmpConfig() : enable(0) {}
+    ~IcmpConfig() {}
 
-    /** \todo These methods should really be defined in an ICMPConfig.cc file
-     * alongside any custom parsing routines needed for this component.
-     * First though, the whole global Config dependancy tree needs fixing */
-    IcmpConfig() : program(NULL), enable(0) {};
-    ~IcmpConfig() { if (program) delete program; program = NULL; };
-
-    /* variables */
+    void clear() {enable=0; program.clear();}
+    void parse();
 
     /** pinger helper application path */
-    char *program;
+    SBuf program;
 
     /** Whether the pinger helper is enabled for use or not */
-    /** \todo make this much more memory efficient for a boolean */
     int enable;
 };
 
+extern IcmpConfig IcmpCfg;
+
+/* wrappers for the legacy squid.conf parser */
+#define dump_icmp(e,n,v) \
+        if (!(v).program.isEmpty()) { \
+            (e)->append((n), strlen((n))); \
+            (e)->append(" ", 1); \
+            (e)->append((v).program.rawContent(), (v).program.length()); \
+            (e)->append("\n", 1); \
+        } else {}
+#define parse_icmp(v) (v)->parse()
+#define free_icmp(x) (x)->clear()
+
+#endif /* USE_ICMP */
 #endif /* ICMPCONFIG_H */
 
index 6c388dfea3120447d2078a20f2cae0f8d4f3aa3c..43e5c35db2baffa2125a8af3a8bf9a93eb0b6961 100644 (file)
@@ -13,6 +13,7 @@
 #include "comm/Loops.h"
 #include "defines.h"
 #include "fd.h"
+#include "icmp/IcmpConfig.h"
 #include "icmp/IcmpSquid.h"
 #include "icmp/net_db.h"
 #include "ip/tools.h"
@@ -193,7 +194,7 @@ IcmpSquid::Open(void)
     Ip::Address localhost;
 
     /* User configured disabled. */
-    if (!Config.pinger.enable) {
+    if (!IcmpCfg.enable) {
         Close();
         return -1;
     }
@@ -208,7 +209,7 @@ IcmpSquid::Open(void)
      * least on FreeBSD).
      */
     pid = ipcCreate(IPC_UDP_SOCKET,
-                    Config.pinger.program,
+                    IcmpCfg.program.c_str(),
                     args,
                     "Pinger Socket",
                     localhost,
index 18b9a7a475546442312b39d933a9741053e5ec25..06fdd493d0cda6cf3b982b2570516150c33b468a 100644 (file)
@@ -50,6 +50,7 @@ libicmp_core_la_SOURCES = \
 
 # Squid Internal ICMP helper interface
 libicmp_la_SOURCES = \
+       IcmpConfig.cc \
        IcmpConfig.h \
        IcmpSquid.h \
        IcmpSquid.cc \