From: Amos Jeffries Date: Thu, 29 Jan 2015 16:09:11 +0000 (-0800) Subject: SourceLayout: shuffle DNS primitives to dns/libdns.la X-Git-Tag: merge-candidate-3-v1~313 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a3b98d76e26ec48d021ff03ab6ff4de7bcacf5c;p=thirdparty%2Fsquid.git SourceLayout: shuffle DNS primitives to dns/libdns.la * create dns/libdns.la with namespace Dns:: * move the RFC specific base functions performing DNS actions into libdns. * move the SquidDns.h definitions to dns/forward.h - rename dns*() functions to Dns:: namespace * move DnsLookupDetails to Dns:: namespace - move class files to libdns. There are no logic changes in this patch. --- diff --git a/configure.ac b/configure.ac index 629021e5ef..9d5565cee6 100644 --- a/configure.ac +++ b/configure.ac @@ -3859,6 +3859,7 @@ AC_CONFIG_FILES([ src/base/Makefile src/clients/Makefile src/comm/Makefile + src/dns/Makefile src/esi/Makefile src/eui/Makefile src/format/Makefile diff --git a/lib/Makefile.am b/lib/Makefile.am index d73181d231..804c1a5213 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -71,31 +71,16 @@ libmiscutil_la_SOURCES = \ heap.c \ iso3307.c \ radix.c \ - rfc1035.c \ rfc1123.c \ - rfc2671.c \ - rfc3596.c \ $(SNPRINTFSOURCE) \ Splay.cc \ stub_memaccount.c \ util.c \ xusleep.c -TESTS += tests/testRFC1035 tests/testRFC1738 +TESTS += tests/testRFC1738 -check_PROGRAMS += tests/testRFC1035 tests/testRFC1738 - -tests_testRFC1035_SOURCES= \ - tests/testRFC1035.h \ - tests/testRFC1035.cc - -tests_testRFC1035_LDADD= \ - $(SQUID_CPPUNIT_LA) $(SQUID_CPPUNIT_LIBS) \ - $(top_builddir)/lib/libmiscencoding.la \ - $(top_builddir)/lib/libmiscutil.la \ - $(COMPAT_LIB) - -tests_testRFC1035_LDFLAGS = $(LIBADD_DL) +check_PROGRAMS += tests/testRFC1738 tests_testRFC1738_SOURCES= \ tests/testRFC1738.h \ diff --git a/src/ClientRequestContext.h b/src/ClientRequestContext.h index 2a017d6cf0..8862893ed6 100644 --- a/src/ClientRequestContext.h +++ b/src/ClientRequestContext.h @@ -11,6 +11,7 @@ #include "base/RefCount.h" #include "cbdata.h" +#include "dns/forward.h" #include "helper/forward.h" #include "ipcache.h" @@ -20,7 +21,6 @@ class ACLChecklist; class ClientHttpRequest; -class DnsLookupDetails; class ErrorState; class ClientRequestContext : public RefCountable @@ -33,7 +33,7 @@ public: bool httpStateIsValid(); void hostHeaderVerify(); - void hostHeaderIpVerify(const ipcache_addrs* ia, const DnsLookupDetails &dns); + void hostHeaderIpVerify(const ipcache_addrs* ia, const Dns::LookupDetails &dns); void hostHeaderVerifyFailed(const char *A, const char *B); void clientAccessCheck(); void clientAccessCheck2(); diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 459cae8558..17abf97b93 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -13,7 +13,7 @@ #include "acl/AclSizeLimit.h" #include "acl/FilledChecklist.h" #include "client_side.h" -#include "DnsLookupDetails.h" +#include "dns/LookupDetails.h" #include "err_detail_type.h" #include "globals.h" #include "gopher.h" @@ -616,7 +616,7 @@ HttpRequest::conditional() const } void -HttpRequest::recordLookup(const DnsLookupDetails &dns) +HttpRequest::recordLookup(const Dns::LookupDetails &dns) { if (dns.wait >= 0) { // known delay if (dnsWait >= 0) // have recorded DNS wait before diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 73f3065363..de9339afbe 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -11,6 +11,7 @@ #include "base/CbcPointer.h" #include "Debug.h" +#include "dns/forward.h" #include "err_type.h" #include "HierarchyLogEntry.h" #include "http/RequestMethod.h" @@ -39,7 +40,6 @@ class ConnStateData; void httpRequestPack(void *obj, Packer *p); class HttpHdrRange; -class DnsLookupDetails; class HttpRequest: public HttpMsg { @@ -100,7 +100,7 @@ public: Adaptation::Icap::History::Pointer icapHistory() const; #endif - void recordLookup(const DnsLookupDetails &detail); + void recordLookup(const Dns::LookupDetails &detail); /// sets error detail if no earlier detail was available void detailError(err_type aType, int aDetail); diff --git a/src/Makefile.am b/src/Makefile.am index 6619f46778..9e89a9a6cf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,10 +10,7 @@ include $(top_srcdir)/src/Common.am AUTOMAKE_OPTIONS = subdir-objects DNSSOURCE = \ - dns_internal.cc \ - SquidDns.h \ - DnsLookupDetails.h \ - DnsLookupDetails.cc + dns_internal.cc SBUF_SOURCE= \ base/CharacterSet.h \ @@ -47,8 +44,8 @@ LOADABLE_MODULES_SOURCES = \ LoadableModules.h \ LoadableModules.cc -SUBDIRS = mem base anyp helper ftp parser comm eui acl format clients servers fs repl -DIST_SUBDIRS = mem base anyp helper ftp parser comm eui acl format clients servers fs repl +SUBDIRS = mem base anyp helper dns ftp parser comm eui acl format clients servers fs repl +DIST_SUBDIRS = mem base anyp helper dns ftp parser comm eui acl format clients servers fs repl if ENABLE_AUTH SUBDIRS += auth @@ -614,6 +611,7 @@ squid_LDADD = \ helper/libhelper.la \ http/libsquid-http.la \ parser/libsquid-parser.la \ + dns/libdns.la \ base/libbase.la \ libsquid.la \ ip/libip.la \ @@ -1059,6 +1057,7 @@ check_PROGRAMS+=\ tests/testBoilerplate \ tests/testCacheManager \ tests/testDiskIO \ + tests/testDns \ tests/testEvent \ tests/testEventLoop \ tests/test_http_range \ @@ -1586,6 +1585,7 @@ tests_testCacheManager_LDADD = \ acl/libacls.la \ acl/libstate.la \ acl/libapi.la \ + dns/libdns.la \ base/libbase.la \ ip/libip.la \ fs/libfs.la \ @@ -1768,7 +1768,6 @@ tests_testDiskIO_LDADD = \ parser/libsquid-parser.la \ SquidConfig.o \ CommCalls.o \ - DnsLookupDetails.o \ ident/libident.la \ acl/libacls.la \ acl/libstate.la \ @@ -1784,6 +1783,7 @@ tests_testDiskIO_LDADD = \ mgr/libmgr.la \ $(SSL_LIBS) \ ipc/libipc.la \ + dns/libdns.la \ base/libbase.la \ mem/libmem.la \ $(top_builddir)/lib/libmisccontainers.la \ @@ -1802,7 +1802,23 @@ tests_testDiskIO_DEPENDENCIES = \ $(SWAP_TEST_DS) \ $(SQUID_CPPUNIT_LA) -## Tests of the Even module. +tests_testDns_SOURCES= \ + tests/testRFC1035.cc \ + tests/testRFC1035.h +nodist_tests_testDns_SOURCES= \ + tests/stub_debug.cc \ + tests/stub_SBuf.cc \ + tests/stub_tools.cc +tests_testDns_LDADD= \ + dns/libdns.la \ + base/libbase.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(COMPAT_LIB) \ + $(XTRA_LIBS) \ + $(SQUID_CPPUNIT_LA) \ + $(SQUID_CPPUNIT_LIBS) +tests_testDns_LDFLAGS= $(LIBADD_DL) + tests_testEvent_SOURCES = \ AccessLogEntry.cc \ BodyPipe.cc \ @@ -2012,6 +2028,7 @@ tests_testEvent_LDADD = \ acl/libacls.la \ acl/libstate.la \ acl/libapi.la \ + dns/libdns.la \ base/libbase.la \ ip/libip.la \ fs/libfs.la \ @@ -2254,6 +2271,7 @@ tests_testEventLoop_LDADD = \ acl/libacls.la \ acl/libstate.la \ acl/libapi.la \ + dns/libdns.la \ base/libbase.la \ ip/libip.la \ fs/libfs.la \ @@ -2506,6 +2524,7 @@ tests_test_http_range_LDADD = \ $(ESI_LIBS) \ $(SSL_LIBS) \ ipc/libipc.la \ + dns/libdns.la \ base/libbase.la \ mgr/libmgr.la \ $(SNMP_LIBS) \ @@ -2782,6 +2801,7 @@ tests_testHttpRequest_LDADD = \ $(SSL_LIBS) \ ipc/libipc.la \ parser/libsquid-parser.la \ + dns/libdns.la \ base/libbase.la \ mgr/libmgr.la \ anyp/libanyp.la \ @@ -2960,6 +2980,7 @@ tests_testStore_LDADD= \ acl/libacls.la \ acl/libstate.la \ acl/libapi.la \ + dns/libdns.la \ base/libbase.la \ ip/libip.la \ fs/libfs.la \ @@ -2975,7 +2996,6 @@ tests_testStore_LDADD= \ $(SQUID_CPPUNIT_LIBS) \ $(SSLLIB) \ CommCalls.o \ - DnsLookupDetails.o \ $(COMPAT_LIB) \ $(XTRA_LIBS) tests_testStore_LDFLAGS = $(LIBADD_DL) @@ -3182,7 +3202,6 @@ tests_testUfs_LDADD = \ http/libsquid-http.la \ parser/libsquid-parser.la \ CommCalls.o \ - DnsLookupDetails.o \ ident/libident.la \ acl/libacls.la \ acl/libstate.la \ @@ -3200,6 +3219,7 @@ tests_testUfs_LDADD = \ ipc/libipc.la \ comm/libcomm.la \ anyp/libanyp.la \ + dns/libdns.la \ base/libbase.la \ ip/libip.la \ mem/libmem.la \ @@ -3606,6 +3626,7 @@ tests_testURL_LDADD = \ eui/libeui.la \ acl/libstate.la \ acl/libapi.la \ + dns/libdns.la \ base/libbase.la \ ip/libip.la \ fs/libfs.la \ diff --git a/src/acl/DestinationDomain.cc b/src/acl/DestinationDomain.cc index de9f8eddab..5104cefc4f 100644 --- a/src/acl/DestinationDomain.cc +++ b/src/acl/DestinationDomain.cc @@ -33,7 +33,7 @@ DestinationDomainLookup::checkForAsync(ACLChecklist *cl) const } void -DestinationDomainLookup::LookupDone(const char *, const DnsLookupDetails &details, void *data) +DestinationDomainLookup::LookupDone(const char *, const Dns::LookupDetails &details, void *data) { ACLFilledChecklist *checklist = Filled((ACLChecklist*)data); checklist->markDestinationDomainChecked(); diff --git a/src/acl/DestinationDomain.h b/src/acl/DestinationDomain.h index bfe0768387..d8e967bf83 100644 --- a/src/acl/DestinationDomain.h +++ b/src/acl/DestinationDomain.h @@ -48,7 +48,7 @@ public: private: static DestinationDomainLookup instance_; - static void LookupDone(const char *, const DnsLookupDetails &, void *); + static void LookupDone(const char *, const Dns::LookupDetails &, void *); }; /// \ingroup ACLAPI diff --git a/src/acl/DestinationIp.cc b/src/acl/DestinationIp.cc index 97ae96d25c..f7b7ef5002 100644 --- a/src/acl/DestinationIp.cc +++ b/src/acl/DestinationIp.cc @@ -91,7 +91,7 @@ DestinationIPLookup::checkForAsync(ACLChecklist *cl)const } void -DestinationIPLookup::LookupDone(const ipcache_addrs *, const DnsLookupDetails &details, void *data) +DestinationIPLookup::LookupDone(const ipcache_addrs *, const Dns::LookupDetails &details, void *data) { ACLFilledChecklist *checklist = Filled((ACLChecklist*)data); checklist->request->flags.destinationIpLookedUp = true; diff --git a/src/acl/SourceDomain.cc b/src/acl/SourceDomain.cc index ec815d2d10..c53d11ebe7 100644 --- a/src/acl/SourceDomain.cc +++ b/src/acl/SourceDomain.cc @@ -31,7 +31,7 @@ SourceDomainLookup::checkForAsync(ACLChecklist *checklist) const } void -SourceDomainLookup::LookupDone(const char *, const DnsLookupDetails &details, void *data) +SourceDomainLookup::LookupDone(const char *, const Dns::LookupDetails &details, void *data) { ACLFilledChecklist *checklist = Filled((ACLChecklist*)data); checklist->markSourceDomainChecked(); diff --git a/src/acl/SourceDomain.h b/src/acl/SourceDomain.h index 48550f9699..3c459ae8c2 100644 --- a/src/acl/SourceDomain.h +++ b/src/acl/SourceDomain.h @@ -40,7 +40,7 @@ public: private: static SourceDomainLookup instance_; - static void LookupDone(const char *, const DnsLookupDetails &, void *); + static void LookupDone(const char *, const Dns::LookupDetails &, void *); }; class ACLSourceDomain diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index 8dee87fad1..ada97ce687 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -103,7 +103,7 @@ void Adaptation::Icap::Xaction::start() } static void -icapLookupDnsResults(const ipcache_addrs *ia, const DnsLookupDetails &, void *data) +icapLookupDnsResults(const ipcache_addrs *ia, const Dns::LookupDetails &, void *data) { Adaptation::Icap::Xaction *xa = static_cast(data); xa->dnsLookupDone(ia); diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 7e488fcdad..a702ea2621 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -500,14 +500,14 @@ clientFollowXForwardedForCheck(allow_t answer, void *data) #endif /* FOLLOW_X_FORWARDED_FOR */ static void -hostHeaderIpVerifyWrapper(const ipcache_addrs* ia, const DnsLookupDetails &dns, void *data) +hostHeaderIpVerifyWrapper(const ipcache_addrs* ia, const Dns::LookupDetails &dns, void *data) { ClientRequestContext *c = static_cast(data); c->hostHeaderIpVerify(ia, dns); } void -ClientRequestContext::hostHeaderIpVerify(const ipcache_addrs* ia, const DnsLookupDetails &dns) +ClientRequestContext::hostHeaderIpVerify(const ipcache_addrs* ia, const Dns::LookupDetails &dns) { Comm::ConnectionPointer clientConn = http->getConn()->clientConnection; diff --git a/src/DnsLookupDetails.cc b/src/dns/LookupDetails.cc similarity index 69% rename from src/DnsLookupDetails.cc rename to src/dns/LookupDetails.cc index c0df2c341a..6829f11778 100644 --- a/src/DnsLookupDetails.cc +++ b/src/dns/LookupDetails.cc @@ -9,19 +9,10 @@ /* DEBUG: section 78 DNS lookups */ #include "squid.h" -#include "DnsLookupDetails.h" - -DnsLookupDetails::DnsLookupDetails(): wait(-1) -{ -} - -DnsLookupDetails::DnsLookupDetails(const String &e, int w): - error(e), wait(w) -{ -} +#include "dns/LookupDetails.h" std::ostream & -DnsLookupDetails::print(std::ostream &os) const +Dns::LookupDetails::print(std::ostream &os) const { if (wait > 0) os << "lookup_wait=" << wait; diff --git a/src/DnsLookupDetails.h b/src/dns/LookupDetails.h similarity index 54% rename from src/DnsLookupDetails.h rename to src/dns/LookupDetails.h index d6feb51a9f..1f3b509109 100644 --- a/src/DnsLookupDetails.h +++ b/src/dns/LookupDetails.h @@ -8,30 +8,35 @@ /* DEBUG: section 78 DNS lookups */ -#ifndef SQUID_DNS_LOOKUP_DETAILS_H -#define SQUID_DNS_LOOKUP_DETAILS_H +#ifndef SQUID_DNS_LOOKUPDETAILS_H +#define SQUID_DNS_LOOKUPDETAILS_H #include "SquidString.h" +namespace Dns +{ + /// encapsulates DNS lookup results -class DnsLookupDetails +class LookupDetails { public: - DnsLookupDetails(); ///< no error, no lookup delay (i.e., no lookup) - DnsLookupDetails(const String &error, int wait); + LookupDetails() : wait(-1) {} ///< no error, no lookup delay (i.e., no lookup) + LookupDetails(const String &anError, int aWait) : error(anError), wait(aWait) {} std::ostream &print(std::ostream &os) const; public: - String error; ///< error message for unsuccessdul lookups; empty otherwise + String error; ///< error message for unsuccessful lookups; empty otherwise int wait; ///< msecs spent waiting for the lookup (if any) or -1 (if none) }; -inline -std::ostream &operator << (std::ostream &os, const DnsLookupDetails &dns) +} // namespace Dns + +inline std::ostream & +operator <<(std::ostream &os, const Dns::LookupDetails &dns) { return dns.print(os); } -#endif +#endif /* SQUID_DNS_LOOKUPDETAILS_H */ diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am new file mode 100644 index 0000000000..1f9921af18 --- /dev/null +++ b/src/dns/Makefile.am @@ -0,0 +1,24 @@ +## 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. +## + +include $(top_srcdir)/src/Common.am +include $(top_srcdir)/src/TestHeaders.am + +AUTOMAKE_OPTIONS = subdir-objects + +noinst_LTLIBRARIES = libdns.la + +libdns_la_SOURCES = \ + forward.h \ + LookupDetails.cc \ + LookupDetails.h \ + rfc1035.cc \ + rfc1035.h \ + rfc2671.cc \ + rfc2671.h \ + rfc3596.cc \ + rfc3596.h diff --git a/src/SquidDns.h b/src/dns/forward.h similarity index 61% rename from src/SquidDns.h rename to src/dns/forward.h index 9fb4a2a92f..2a6eb81292 100644 --- a/src/SquidDns.h +++ b/src/dns/forward.h @@ -6,21 +6,31 @@ * Please see the COPYING and CONTRIBUTORS files for details. */ -#ifndef SQUID_DNS_H -#define SQUID_DNS_H +#ifndef _SQUID_SRC_DNS_FORWARD_H +#define _SQUID_SRC_DNS_FORWARD_H namespace Ip { class Address; } +class rfc1035_rr; + +typedef void IDNSCB(void *, const rfc1035_rr *, int, const char *); + // generic DNS API -void dnsInit(void); -void dnsShutdown(void); +namespace Dns +{ + +class LookupDetails; + +void Init(void); +void Shutdown(void); + +} // namespace Dns // internal DNS client API void idnsALookup(const char *, IDNSCB *, void *); void idnsPTRLookup(const Ip::Address &, IDNSCB *, void *); -#endif /* SQUID_DNS_H */ - +#endif /* _SQUID_SRC_DNS_FORWARD_H */ diff --git a/lib/rfc1035.c b/src/dns/rfc1035.cc similarity index 99% rename from lib/rfc1035.c rename to src/dns/rfc1035.cc index d3b44b7a1e..ba20e66420 100644 --- a/lib/rfc1035.c +++ b/src/dns/rfc1035.cc @@ -15,6 +15,8 @@ */ #include "squid.h" +#include "dns/rfc1035.h" +#include "dns/rfc2671.h" #include "util.h" #if HAVE_STRING_H @@ -39,9 +41,6 @@ #include #endif -#include "rfc1035.h" -#include "rfc2671.h" - #define RFC1035_MAXLABELSZ 63 #define rfc1035_unpack_error 15 diff --git a/include/rfc1035.h b/src/dns/rfc1035.h similarity index 98% rename from include/rfc1035.h rename to src/dns/rfc1035.h index cd6783cf2a..a3843c0318 100644 --- a/include/rfc1035.h +++ b/src/dns/rfc1035.h @@ -33,8 +33,9 @@ #define RFC1035_DEFAULT_PACKET_SZ 512 -typedef struct _rfc1035_rr rfc1035_rr; -struct _rfc1035_rr { +class rfc1035_rr +{ +public: char name[RFC1035_MAXHOSTNAMESZ]; unsigned short type; unsigned short _class; diff --git a/lib/rfc2671.c b/src/dns/rfc2671.cc similarity index 94% rename from lib/rfc2671.c rename to src/dns/rfc2671.cc index 67b24e1ae9..0201d94306 100644 --- a/lib/rfc2671.c +++ b/src/dns/rfc2671.cc @@ -7,8 +7,8 @@ */ #include "squid.h" -#include "rfc1035.h" -#include "rfc2671.h" +#include "dns/rfc1035.h" +#include "dns/rfc2671.h" int rfc2671RROptPack(char *buf, size_t sz, ssize_t edns_sz) diff --git a/include/rfc2671.h b/src/dns/rfc2671.h similarity index 100% rename from include/rfc2671.h rename to src/dns/rfc2671.h diff --git a/lib/rfc3596.c b/src/dns/rfc3596.cc similarity index 99% rename from lib/rfc3596.c rename to src/dns/rfc3596.cc index d04afb0362..e54aaaccf5 100644 --- a/lib/rfc3596.c +++ b/src/dns/rfc3596.cc @@ -7,6 +7,8 @@ */ #include "squid.h" +#include "dns/rfc2671.h" +#include "dns/rfc3596.h" #include "util.h" #if HAVE_UNISTD_H @@ -25,9 +27,6 @@ #include #endif -#include "rfc2671.h" -#include "rfc3596.h" - #ifndef SQUID_RFC1035_H #error RFC3596 Library depends on RFC1035 #endif diff --git a/include/rfc3596.h b/src/dns/rfc3596.h similarity index 98% rename from include/rfc3596.h rename to src/dns/rfc3596.h index 90bc48abd9..5bc07f03cf 100644 --- a/include/rfc3596.h +++ b/src/dns/rfc3596.h @@ -10,7 +10,7 @@ #define SQUID_RFC3596_H /* RFC 3596 extends RFC 1035 */ -#include "rfc1035.h" +#include "dns/rfc1035.h" SQUIDCEXTERN ssize_t rfc3596BuildAQuery(const char *hostname, char *buf, diff --git a/src/dns_internal.cc b/src/dns_internal.cc index fe590d953c..3e8280969a 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -6,7 +6,7 @@ * Please see the COPYING and CONTRIBUTORS files for details. */ -/* DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c */ +/* DEBUG: section 78 DNS lookups; interacts with dns/rfc1035.cc */ #include "squid.h" #include "base/InstanceId.h" @@ -17,13 +17,14 @@ #include "comm/Read.h" #include "comm/Write.h" #include "dlink.h" +#include "dns/forward.h" +#include "dns/rfc3596.h" #include "event.h" #include "fd.h" #include "fde.h" #include "ip/tools.h" #include "MemBuf.h" #include "mgr/Registration.h" -#include "rfc3596.h" #include "SquidConfig.h" #include "SquidTime.h" #include "Store.h" @@ -852,7 +853,7 @@ idnsVCClosed(const CommCloseCbParams ¶ms) delete vc->queue; delete vc->msg; vc->conn = NULL; - if (vc->ns < nns) // XXX: dnsShutdown may have freed nameservers[] + if (vc->ns < nns) // XXX: Dns::Shutdown may have freed nameservers[] nameservers[vc->ns].vc = NULL; cbdataFree(vc); } @@ -1497,16 +1498,8 @@ idnsRcodeCount(int rcode, int attempt) ++ RcodeMatrix[rcode][attempt]; } -/* ====================================================================== */ - -static void -idnsRegisterWithCacheManager(void) -{ - Mgr::RegisterAction("idns", "Internal DNS Statistics", idnsStats, 0, 1); -} - void -dnsInit(void) +Dns::Init(void) { static int init = 0; @@ -1600,11 +1593,11 @@ dnsInit(void) } #endif - idnsRegisterWithCacheManager(); + Mgr::RegisterAction("idns", "Internal DNS Statistics", idnsStats, 0, 1); } void -dnsShutdown(void) +Dns::Shutdown(void) { if (DnsSocketA < 0 && DnsSocketB < 0) return; diff --git a/src/fqdncache.cc b/src/fqdncache.cc index 3daff60828..e9cb18e6f9 100644 --- a/src/fqdncache.cc +++ b/src/fqdncache.cc @@ -10,12 +10,13 @@ #include "squid.h" #include "cbdata.h" -#include "DnsLookupDetails.h" +#include "dns/forward.h" +#include "dns/LookupDetails.h" +#include "dns/rfc1035.h" #include "event.h" #include "helper.h" #include "mgr/Registration.h" #include "SquidConfig.h" -#include "SquidDns.h" #include "SquidTime.h" #include "StatCounters.h" #include "Store.h" @@ -310,7 +311,7 @@ fqdncacheCallback(fqdncache_entry * f, int wait) f->handler = NULL; if (cbdataReferenceValidDone(f->handlerData, &cbdata)) { - const DnsLookupDetails details(f->error_message, wait); + const Dns::LookupDetails details(f->error_message, wait); callback(f->name_count ? f->names[0] : NULL, details, cbdata); } @@ -427,7 +428,7 @@ fqdncache_nbgethostbyaddr(const Ip::Address &addr, FQDNH * handler, void *handle if (name[0] == '\0') { debugs(35, 4, "fqdncache_nbgethostbyaddr: Invalid name!"); - const DnsLookupDetails details("Invalid hostname", -1); // error, no lookup + const Dns::LookupDetails details("Invalid hostname", -1); // error, no lookup if (handler) handler(NULL, details, handlerData); return; diff --git a/src/icmp/net_db.cc b/src/icmp/net_db.cc index b2ab320076..c39349505e 100644 --- a/src/icmp/net_db.cc +++ b/src/icmp/net_db.cc @@ -264,7 +264,7 @@ netdbAdd(Ip::Address &addr) } static void -netdbSendPing(const ipcache_addrs *ia, const DnsLookupDetails &, void *data) +netdbSendPing(const ipcache_addrs *ia, const Dns::LookupDetails &, void *data) { Ip::Address addr; char *hostname = NULL; diff --git a/src/ipcache.cc b/src/ipcache.cc index b778320ad2..c167e84416 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -12,15 +12,14 @@ #include "CacheManager.h" #include "cbdata.h" #include "dlink.h" -#include "DnsLookupDetails.h" +#include "dns/LookupDetails.h" +#include "dns/rfc3596.h" #include "event.h" #include "ip/Address.h" #include "ip/tools.h" #include "ipcache.h" #include "mgr/Registration.h" -#include "rfc3596.h" #include "SquidConfig.h" -#include "SquidDns.h" #include "SquidTime.h" #include "StatCounters.h" #include "Store.h" @@ -321,7 +320,7 @@ ipcacheCallback(ipcache_entry *i, int wait) i->handler = NULL; if (cbdataReferenceValidDone(i->handlerData, &cbdata)) { - const DnsLookupDetails details(i->error_message, wait); + const Dns::LookupDetails details(i->error_message, wait); callback((i->addrs.count ? &i->addrs : NULL), details, cbdata); } @@ -504,7 +503,7 @@ ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData) if (name == NULL || name[0] == '\0') { debugs(14, 4, "ipcache_nbgethostbyname: Invalid name!"); ++IpcacheStats.invalid; - const DnsLookupDetails details("Invalid hostname", -1); // error, no lookup + const Dns::LookupDetails details("Invalid hostname", -1); // error, no lookup if (handler) handler(NULL, details, handlerData); return; @@ -513,7 +512,7 @@ ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData) if ((addrs = ipcacheCheckNumeric(name))) { debugs(14, 4, "ipcache_nbgethostbyname: BYPASS for '" << name << "' (already numeric)"); ++IpcacheStats.numeric_hits; - const DnsLookupDetails details(NULL, -1); // no error, no lookup + const Dns::LookupDetails details; // no error, no lookup if (handler) handler(addrs, details, handlerData); return; diff --git a/src/ipcache.h b/src/ipcache.h index 449a56705e..cfdc096d2e 100644 --- a/src/ipcache.h +++ b/src/ipcache.h @@ -9,13 +9,13 @@ #ifndef _SQUID_IPCACHE_H #define _SQUID_IPCACHE_H +#include "dns/forward.h" + namespace Ip { class Address; } -class DnsLookupDetails; - typedef struct _ipcache_addrs { Ip::Address *in_addrs; unsigned char *bad_mask; @@ -24,7 +24,7 @@ typedef struct _ipcache_addrs { unsigned char badcount; } ipcache_addrs; -typedef void IPH(const ipcache_addrs *, const DnsLookupDetails &details, void *); +typedef void IPH(const ipcache_addrs *, const Dns::LookupDetails &details, void *); void ipcache_purgelru(void *); void ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData); diff --git a/src/main.cc b/src/main.cc index 2fd0bc5b9a..45e20a44f6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -25,6 +25,7 @@ #include "CpuAffinity.h" #include "disk.h" #include "DiskIO/DiskIOModule.h" +#include "dns/forward.h" #include "errorpage.h" #include "event.h" #include "EventLoop.h" @@ -59,7 +60,6 @@ #include "refresh.h" #include "send-announce.h" #include "SquidConfig.h" -#include "SquidDns.h" #include "SquidTime.h" #include "stat.h" #include "StatCounters.h" @@ -803,7 +803,7 @@ mainReconfigureStart(void) #if USE_HTCP htcpClosePorts(); #endif - dnsShutdown(); + Dns::Shutdown(); #if USE_SSL_CRTD Ssl::Helper::GetInstance()->Shutdown(); #endif @@ -890,7 +890,7 @@ mainReconfigureFinish(void *) icapLogOpen(); #endif storeLogOpen(); - dnsInit(); + Dns::Init(); #if USE_SSL_CRTD Ssl::Helper::GetInstance()->Init(); #endif @@ -1094,7 +1094,7 @@ mainInitialize(void) parseEtcHosts(); - dnsInit(); + Dns::Init(); #if USE_SSL_CRTD Ssl::Helper::GetInstance()->Init(); @@ -1915,7 +1915,7 @@ SquidShutdown() #endif debugs(1, DBG_IMPORTANT, "Shutting down..."); - dnsShutdown(); + Dns::Shutdown(); #if USE_SSL_CRTD Ssl::Helper::GetInstance()->Shutdown(); #endif diff --git a/src/multicast.cc b/src/multicast.cc index 08ab9bb31d..0c1ae5c4c3 100644 --- a/src/multicast.cc +++ b/src/multicast.cc @@ -31,7 +31,7 @@ mcastSetTtl(int fd, int mcast_ttl) } void -mcastJoinGroups(const ipcache_addrs *ia, const DnsLookupDetails &, void *) +mcastJoinGroups(const ipcache_addrs *ia, const Dns::LookupDetails &, void *) { #ifdef IP_MULTICAST_TTL struct ip_mreq mr; diff --git a/src/neighbors.cc b/src/neighbors.cc index 68778a6114..fde225c9ee 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1203,7 +1203,7 @@ peerNoteDigestGone(CachePeer * p) } static void -peerDNSConfigure(const ipcache_addrs *ia, const DnsLookupDetails &, void *data) +peerDNSConfigure(const ipcache_addrs *ia, const Dns::LookupDetails &, void *data) { // TODO: connections to no-longer valid IP addresses should be // closed when we can detect such IP addresses. diff --git a/src/peer_select.cc b/src/peer_select.cc index 5b00a3f5c5..05e1506769 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -13,7 +13,7 @@ #include "CachePeer.h" #include "carp.h" #include "client_side.h" -#include "DnsLookupDetails.h" +#include "dns/LookupDetails.h" #include "errorpage.h" #include "event.h" #include "FwdState.h" @@ -61,7 +61,7 @@ static void peerGetSomeParent(ps_state *); static void peerGetAllParents(ps_state *); static void peerAddFwdServer(FwdServer **, CachePeer *, hier_code); static void peerSelectPinned(ps_state * ps); -static void peerSelectDnsResults(const ipcache_addrs *ia, const DnsLookupDetails &details, void *data); +static void peerSelectDnsResults(const ipcache_addrs *ia, const Dns::LookupDetails &details, void *data); CBDATA_CLASS_INIT(ps_state); @@ -306,7 +306,7 @@ peerSelectDnsPaths(ps_state *psstate) } static void -peerSelectDnsResults(const ipcache_addrs *ia, const DnsLookupDetails &details, void *data) +peerSelectDnsResults(const ipcache_addrs *ia, const Dns::LookupDetails &details, void *data) { ps_state *psstate = (ps_state *)data; diff --git a/src/send-announce.cc b/src/send-announce.cc index b414d6aeb6..0b2b7d51e7 100644 --- a/src/send-announce.cc +++ b/src/send-announce.cc @@ -39,7 +39,7 @@ start_announce(void *) } static void -send_announce(const ipcache_addrs *ia, const DnsLookupDetails &, void *) +send_announce(const ipcache_addrs *ia, const Dns::LookupDetails &, void *) { LOCAL_ARRAY(char, tbuf, 256); LOCAL_ARRAY(char, sndbuf, BUFSIZ); diff --git a/lib/tests/testRFC1035.cc b/src/tests/testRFC1035.cc similarity index 97% rename from lib/tests/testRFC1035.cc rename to src/tests/testRFC1035.cc index e238ec097f..cc74966d23 100644 --- a/lib/tests/testRFC1035.cc +++ b/src/tests/testRFC1035.cc @@ -7,15 +7,12 @@ */ #include "squid.h" +#include "dns/rfc1035.h" #include "testRFC1035.h" #include "unitTestMain.h" #include -/* Being a C library code it is best bodily included and tested with C++ type-safe techniques. */ -#include "lib/rfc1035.c" -#include "lib/rfc2671.c" - CPPUNIT_TEST_SUITE_REGISTRATION( testRFC1035 ); // TODO Test each function in the Library independently diff --git a/lib/tests/testRFC1035.h b/src/tests/testRFC1035.h similarity index 100% rename from lib/tests/testRFC1035.h rename to src/tests/testRFC1035.h diff --git a/src/typedefs.h b/src/typedefs.h index 1826e2ea91..7d38ff3ae9 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -7,7 +7,6 @@ */ #include "enums.h" -#include "rfc1035.h" #ifndef SQUID_TYPEDEFS_H #define SQUID_TYPEDEFS_H @@ -44,8 +43,11 @@ typedef void DCCB(int, int errflag, void *data); /* disk close CB */ typedef void DUCB(int errflag, void *data); /* disk unlink CB */ typedef void DTCB(int errflag, void *data); /* disk trunc CB */ -class DnsLookupDetails; -typedef void FQDNH(const char *, const DnsLookupDetails &details, void *); +namespace Dns +{ +class LookupDetails; +} +typedef void FQDNH(const char *, const Dns::LookupDetails &details, void *); #include "anyp/ProtocolType.h" class CachePeer; @@ -68,7 +70,6 @@ typedef void STVLDCB(void *, int, int); typedef int HLPSAVAIL(void *); typedef void HLPSONEQ(void *); typedef void HLPCMDOPTS(int *argc, char **argv); -typedef void IDNSCB(void *, const rfc1035_rr *, int, const char *); /* MD5 cache keys */ typedef unsigned char cache_key;