summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Network/CAresDomainNameResolver.cpp171
-rw-r--r--Swiften/Network/CAresDomainNameResolver.h40
-rw-r--r--Swiften/Network/SConscript7
-rw-r--r--Swiften/SConscript2
4 files changed, 2 insertions, 218 deletions
diff --git a/Swiften/Network/CAresDomainNameResolver.cpp b/Swiften/Network/CAresDomainNameResolver.cpp
deleted file mode 100644
index da0f49e..0000000
--- a/Swiften/Network/CAresDomainNameResolver.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-// TODO: Check the second param of postEvent. We sometimes omit it. Same
-// goes for the PlatformDomainNameResolver.
-
-#include <Swiften/Network/CAresDomainNameResolver.h>
-#include <Swiften/Base/Platform.h>
-
-#ifndef SWIFTEN_PLATFORM_WINDOWS
-#include <netdb.h>
-#include <arpa/inet.h>
-#endif
-#include <algorithm>
-
-#include <Swiften/Network/DomainNameServiceQuery.h>
-#include <Swiften/Network/DomainNameAddressQuery.h>
-#include <Swiften/Base/ByteArray.h>
-#include <Swiften/EventLoop/EventLoop.h>
-#include <Swiften/Base/foreach.h>
-
-namespace Swift {
-
-class CAresQuery : public boost::enable_shared_from_this<CAresQuery>, public EventOwner {
- public:
- CAresQuery(const std::string& query, int dnsclass, int type, CAresDomainNameResolver* resolver) : query(query), dnsclass(dnsclass), type(type), resolver(resolver) {
- }
-
- virtual ~CAresQuery() {
- }
-
- void addToQueue() {
- resolver->addToQueue(shared_from_this());
- }
-
- void doRun(ares_channel* channel) {
- ares_query(*channel, query.c_str(), dnsclass, type, &CAresQuery::handleResult, this);
- }
-
- static void handleResult(void* arg, int status, int timeouts, unsigned char* buffer, int len) {
- reinterpret_cast<CAresQuery*>(arg)->handleResult(status, timeouts, buffer, len);
- }
-
- virtual void handleResult(int status, int, unsigned char* buffer, int len) = 0;
-
- private:
- std::string query;
- int dnsclass;
- int type;
- CAresDomainNameResolver* resolver;
-};
-
-class CAresDomainNameServiceQuery : public DomainNameServiceQuery, public CAresQuery {
- public:
- CAresDomainNameServiceQuery(const std::string& service, CAresDomainNameResolver* resolver) : CAresQuery(service, 1, 33, resolver) {
- }
-
- virtual void run() {
- addToQueue();
- }
-
- void handleResult(int status, int, unsigned char* buffer, int len) {
- if (status == ARES_SUCCESS) {
- std::vector<DomainNameServiceQuery::Result> records;
- ares_srv_reply* rawRecords;
- if (ares_parse_srv_reply(buffer, len, &rawRecords) == ARES_SUCCESS) {
- for( ; rawRecords != NULL; rawRecords = rawRecords->next) {
- DomainNameServiceQuery::Result record;
- record.priority = rawRecords->priority;
- record.weight = rawRecords->weight;
- record.port = rawRecords->port;
- record.hostname = std::string(rawRecords->host);
- records.push_back(record);
- }
- }
- std::sort(records.begin(), records.end(), ResultPriorityComparator());
- eventLoop->postEvent(boost::bind(boost::ref(onResult), records));
- }
- else if (status != ARES_EDESTRUCTION) {
- eventLoop->postEvent(boost::bind(boost::ref(onResult), std::vector<DomainNameServiceQuery::Result>()), shared_from_this());
- }
- }
-};
-
-class CAresDomainNameAddressQuery : public DomainNameAddressQuery, public CAresQuery {
- public:
- CAresDomainNameAddressQuery(const std::string& host, CAresDomainNameResolver* resolver) : CAresQuery(host, 1, 1, resolver) {
- }
-
- virtual void run() {
- addToQueue();
- }
-
- void handleResult(int status, int, unsigned char* buffer, int len) {
- if (status == ARES_SUCCESS) {
- struct hostent* hosts;
- if (ares_parse_a_reply(buffer, len, &hosts, NULL, NULL) == ARES_SUCCESS) {
- // Check whether the different fields are what we expect them to be
- struct in_addr addr;
- addr.s_addr = *(unsigned int*)hosts->h_addr_list[0];
-
- std::vector<HostAddress> results;
- results.push_back(HostAddress(inet_ntoa(addr)));
-
- eventLoop->postEvent(boost::bind(boost::ref(onResult), results, boost::optional<DomainNameResolveError>()), boost::dynamic_pointer_cast<CAresDomainNameAddressQuery>(shared_from_this()));
- ares_free_hostent(hosts);
- }
- else {
- eventLoop->postEvent(boost::bind(boost::ref(onResult), std::vector<HostAddress>(), boost::optional<DomainNameResolveError>(DomainNameResolveError())), shared_from_this());
- }
- }
- else if (status != ARES_EDESTRUCTION) {
- eventLoop->postEvent(boost::bind(boost::ref(onResult), std::vector<HostAddress>(), boost::optional<DomainNameResolveError>(DomainNameResolveError())), shared_from_this());
- }
- }
-};
-
-CAresDomainNameResolver::CAresDomainNameResolver() : stopRequested(false) {
- ares_init(&channel);
- thread = new boost::thread(boost::bind(&CAresDomainNameResolver::run, this));
-}
-
-CAresDomainNameResolver::~CAresDomainNameResolver() {
- stopRequested = true;
- thread->join();
- ares_destroy(channel);
-}
-
-boost::shared_ptr<DomainNameServiceQuery> CAresDomainNameResolver::createServiceQuery(const std::string& name) {
- return boost::shared_ptr<DomainNameServiceQuery>(new CAresDomainNameServiceQuery(getNormalized(name), this));
-}
-
-boost::shared_ptr<DomainNameAddressQuery> CAresDomainNameResolver::createAddressQuery(const std::string& name) {
- return boost::shared_ptr<DomainNameAddressQuery>(new CAresDomainNameAddressQuery(getNormalized(name), this));
-}
-
-void CAresDomainNameResolver::addToQueue(boost::shared_ptr<CAresQuery> query) {
- boost::lock_guard<boost::mutex> lock(pendingQueriesMutex);
- pendingQueries.push_back(query);
-}
-
-void CAresDomainNameResolver::run() {
- fd_set readers, writers;
- struct timeval timeout;
- timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
- while(!stopRequested) {
- {
- boost::unique_lock<boost::mutex> lock(pendingQueriesMutex);
- foreach(const boost::shared_ptr<CAresQuery>& query, pendingQueries) {
- query->doRun(&channel);
- }
- pendingQueries.clear();
- }
- FD_ZERO(&readers);
- FD_ZERO(&writers);
- int nfds = ares_fds(channel, &readers, &writers);
- //if (nfds) {
- // break;
- //}
- struct timeval tv;
- struct timeval* tvp = ares_timeout(channel, &timeout, &tv);
- select(nfds, &readers, &writers, NULL, tvp);
- ares_process(channel, &readers, &writers);
- }
-}
-
-}
diff --git a/Swiften/Network/CAresDomainNameResolver.h b/Swiften/Network/CAresDomainNameResolver.h
deleted file mode 100644
index d0ff82c..0000000
--- a/Swiften/Network/CAresDomainNameResolver.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include <ares.h>
-#include <boost/thread/thread.hpp>
-#include <boost/thread/mutex.hpp>
-#include <list>
-
-#include <Swiften/Network/DomainNameResolver.h>
-
-namespace Swift {
- class CAresQuery;
-
- class CAresDomainNameResolver : public DomainNameResolver {
- public:
- CAresDomainNameResolver();
- ~CAresDomainNameResolver();
-
- virtual boost::shared_ptr<DomainNameServiceQuery> createServiceQuery(const std::string& name);
- virtual boost::shared_ptr<DomainNameAddressQuery> createAddressQuery(const std::string& name);
-
- private:
- friend class CAresQuery;
-
- void run();
- void addToQueue(boost::shared_ptr<CAresQuery>);
-
- private:
- bool stopRequested;
- ares_channel channel;
- boost::thread* thread;
- boost::mutex pendingQueriesMutex;
- std::list< boost::shared_ptr<CAresQuery> > pendingQueries;
- };
-}
diff --git a/Swiften/Network/SConscript b/Swiften/Network/SConscript
index 0d0abbd..ecd7be9 100644
--- a/Swiften/Network/SConscript
+++ b/Swiften/Network/SConscript
@@ -2,8 +2,6 @@ Import("swiften_env")
myenv = swiften_env.Clone()
myenv.MergeFlags(myenv["LIBIDN_FLAGS"])
-if myenv.get("HAVE_CARES", False) :
- myenv.MergeFlags(myenv.get("CARES_FLAGS", {}))
sourceList = [
"HTTPConnectProxiedConnection.cpp",
@@ -17,7 +15,7 @@ sourceList = [
"BoostIOServiceThread.cpp",
"BOSHConnection.cpp",
"BOSHConnectionPool.cpp",
- "CachingNameOnlyDomainNameResolver.cpp",
+ "CachingNameOnlyDomainNameResolver.cpp",
"ConnectionFactory.cpp",
"ConnectionServer.cpp",
"ConnectionServerFactory.cpp",
@@ -54,9 +52,6 @@ sourceList = [
"NATTraversalRemovePortForwardingRequest.cpp",
"NATTraversalInterface.cpp",
]
-
-if myenv.get("HAVE_CARES", False) :
- sourceList.append("CAresDomainNameResolver.cpp")
if myenv["PLATFORM"] == "darwin" :
myenv.Append(FRAMEWORKS = ["CoreServices", "SystemConfiguration"])
diff --git a/Swiften/SConscript b/Swiften/SConscript
index c12d3b2..41ec947 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -418,7 +418,7 @@ if env["SCONS_STAGE"] == "build" :
continue
# Library-specific files
- if file.startswith("Schannel") or file.startswith("CAPI") or file.startswith("CAres") or file.startswith("LibXML") or file.startswith("Expat") or file.startswith("GConf") or file.startswith("MacOSX") or file.startswith("Windows") or file.endswith("_Windows.h") or file.startswith("SQLite") or file.startswith("NATPMP") or file.startswith("MiniUPnP") :
+ if file.startswith("Schannel") or file.startswith("CAPI") or file.startswith("LibXML") or file.startswith("Expat") or file.startswith("GConf") or file.startswith("MacOSX") or file.startswith("Windows") or file.endswith("_Windows.h") or file.startswith("SQLite") or file.startswith("NATPMP") or file.startswith("MiniUPnP") :
continue
# Specific headers we don't want to globally include