From: Amos Jeffries Date: Fri, 15 May 2015 12:50:09 +0000 (-0700) Subject: Cleanup: Refactor IcmpConfig X-Git-Tag: merge-candidate-3-v1~117 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a9d36e3f368d14d1a6450a6be2fe5b0831f0405;p=thirdparty%2Fsquid.git Cleanup: Refactor IcmpConfig 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. --- diff --git a/src/SquidConfig.h b/src/SquidConfig.h index 30cffc1eb7..f4c5a9777b 100644 --- a/src/SquidConfig.h +++ b/src/SquidConfig.h @@ -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 { diff --git a/src/cache_cf.cc b/src/cache_cf.cc index b66c4ba457..1bdfcca892 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -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" diff --git a/src/cf.data.depend b/src/cf.data.depend index f30194fa42..3f47a4770c 100644 --- a/src/cf.data.depend +++ b/src/cf.data.depend @@ -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 diff --git a/src/cf.data.pre b/src/cf.data.pre index 0b6e1067cd..6975ca293d 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -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 index 0000000000..bc3ef2427d --- /dev/null +++ b/src/icmp/IcmpConfig.cc @@ -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 */ + diff --git a/src/icmp/IcmpConfig.h b/src/icmp/IcmpConfig.h index ef22bce4d9..04f782cb27 100644 --- a/src/icmp/IcmpConfig.h +++ b/src/icmp/IcmpConfig.h @@ -11,33 +11,43 @@ #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 */ diff --git a/src/icmp/IcmpSquid.cc b/src/icmp/IcmpSquid.cc index 6c388dfea3..43e5c35db2 100644 --- a/src/icmp/IcmpSquid.cc +++ b/src/icmp/IcmpSquid.cc @@ -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, diff --git a/src/icmp/Makefile.am b/src/icmp/Makefile.am index 18b9a7a475..06fdd493d0 100644 --- a/src/icmp/Makefile.am +++ b/src/icmp/Makefile.am @@ -50,6 +50,7 @@ libicmp_core_la_SOURCES = \ # Squid Internal ICMP helper interface libicmp_la_SOURCES = \ + IcmpConfig.cc \ IcmpConfig.h \ IcmpSquid.h \ IcmpSquid.cc \