diff options
Diffstat (limited to 'Swiften/LinkLocal/DNSSD')
42 files changed, 1208 insertions, 1166 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.cpp index e31bf87..a1bdb3e 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.cpp @@ -1,60 +1,61 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h> -#include <boost/bind.hpp> #include <iostream> +#include <boost/bind.hpp> + #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> namespace Swift { void AvahiBrowseQuery::startBrowsing() { - std::cout << "Start browsing" << std::endl; - assert(!browser); - avahi_threaded_poll_lock(querier->getThreadedPoll()); - browser = avahi_service_browser_new(querier->getClient(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_presence._tcp", NULL, static_cast<AvahiLookupFlags>(0), &handleServiceDiscoveredStatic, this); - if (!browser) { - std::cout << "Error" << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); - } - avahi_threaded_poll_unlock(querier->getThreadedPoll()); + std::cout << "Start browsing" << std::endl; + assert(!browser); + avahi_threaded_poll_lock(querier->getThreadedPoll()); + browser = avahi_service_browser_new(querier->getClient(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_presence._tcp", NULL, static_cast<AvahiLookupFlags>(0), &handleServiceDiscoveredStatic, this); + if (!browser) { + std::cout << "Error" << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); + } + avahi_threaded_poll_unlock(querier->getThreadedPoll()); } void AvahiBrowseQuery::stopBrowsing() { - std::cout << "Stop browsing" << std::endl; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - avahi_service_browser_free(browser); - browser = NULL; - avahi_threaded_poll_unlock(querier->getThreadedPoll()); + std::cout << "Stop browsing" << std::endl; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + avahi_service_browser_free(browser); + browser = NULL; + avahi_threaded_poll_unlock(querier->getThreadedPoll()); } void AvahiBrowseQuery::handleServiceDiscovered(AvahiServiceBrowser *, AvahiIfIndex interfaceIndex, AvahiProtocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags) { - switch (event) { - case AVAHI_BROWSER_FAILURE: - std::cout << "Service browse error" << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); - break; - case AVAHI_BROWSER_NEW: { - DNSSDServiceID service(name, domain, type, interfaceIndex); - std::cout << "Service discovered " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); - break; - } - case AVAHI_BROWSER_REMOVE: { - std::cout << "Service went away " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl; - DNSSDServiceID service(name, domain, type, interfaceIndex); - eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); - break; - } - case AVAHI_BROWSER_ALL_FOR_NOW: - case AVAHI_BROWSER_CACHE_EXHAUSTED: - break; - } + switch (event) { + case AVAHI_BROWSER_FAILURE: + std::cout << "Service browse error" << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); + break; + case AVAHI_BROWSER_NEW: { + DNSSDServiceID service(name, domain, type, interfaceIndex); + std::cout << "Service discovered " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); + break; + } + case AVAHI_BROWSER_REMOVE: { + std::cout << "Service went away " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl; + DNSSDServiceID service(name, domain, type, interfaceIndex); + eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); + break; + } + case AVAHI_BROWSER_ALL_FOR_NOW: + case AVAHI_BROWSER_CACHE_EXHAUSTED: + break; + } } } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h index 38e796d..a227613 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <avahi-client/lookup.h> +#include <Swiften/EventLoop/EventLoop.h> #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> #include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> -#include <Swiften/EventLoop/EventLoop.h> namespace Swift { - class AvahiQuerier; + class AvahiQuerier; + + class AvahiBrowseQuery : public DNSSDBrowseQuery, public AvahiQuery { + public: + AvahiBrowseQuery(std::shared_ptr<AvahiQuerier> q, EventLoop* eventLoop) : AvahiQuery(q, eventLoop), browser(NULL) { + } - class AvahiBrowseQuery : public DNSSDBrowseQuery, public AvahiQuery { - public: - AvahiBrowseQuery(boost::shared_ptr<AvahiQuerier> q, EventLoop* eventLoop) : AvahiQuery(q, eventLoop), browser(NULL) { - } + void startBrowsing(); + void stopBrowsing(); - void startBrowsing(); - void stopBrowsing(); + private: + static void handleServiceDiscoveredStatic(AvahiServiceBrowser *b, AvahiIfIndex interfaceIndex, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* context) { + static_cast<AvahiBrowseQuery*>(context)->handleServiceDiscovered(b, interfaceIndex, protocol, event, name, type, domain, flags); + } - private: - static void handleServiceDiscoveredStatic(AvahiServiceBrowser *b, AvahiIfIndex interfaceIndex, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* context) { - static_cast<AvahiBrowseQuery*>(context)->handleServiceDiscovered(b, interfaceIndex, protocol, event, name, type, domain, flags); - } + void handleServiceDiscovered(AvahiServiceBrowser *, AvahiIfIndex interfaceIndex, AvahiProtocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags); - void handleServiceDiscovered(AvahiServiceBrowser *, AvahiIfIndex interfaceIndex, AvahiProtocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags); + private: + AvahiServiceBrowser* browser; - private: - AvahiServiceBrowser* browser; - - }; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp index e9f5564..66b4ae8 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> @@ -9,9 +9,9 @@ #include <iostream> #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h> -#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h> -#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h> #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h> +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h> +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h> namespace Swift { @@ -21,46 +21,46 @@ AvahiQuerier::AvahiQuerier(EventLoop* eventLoop) : eventLoop(eventLoop), client( AvahiQuerier::~AvahiQuerier() { } -boost::shared_ptr<DNSSDBrowseQuery> AvahiQuerier::createBrowseQuery() { - return boost::shared_ptr<DNSSDBrowseQuery>(new AvahiBrowseQuery(shared_from_this(), eventLoop)); +std::shared_ptr<DNSSDBrowseQuery> AvahiQuerier::createBrowseQuery() { + return std::make_shared<AvahiBrowseQuery>(shared_from_this(), eventLoop); } -boost::shared_ptr<DNSSDRegisterQuery> AvahiQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { - return boost::shared_ptr<DNSSDRegisterQuery>(new AvahiRegisterQuery(name, port, info, shared_from_this(), eventLoop)); +std::shared_ptr<DNSSDRegisterQuery> AvahiQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) { + return std::make_shared<AvahiRegisterQuery>(name, port, info, shared_from_this(), eventLoop); } -boost::shared_ptr<DNSSDResolveServiceQuery> AvahiQuerier::createResolveServiceQuery(const DNSSDServiceID& service) { - return boost::shared_ptr<DNSSDResolveServiceQuery>(new AvahiResolveServiceQuery(service, shared_from_this(), eventLoop)); +std::shared_ptr<DNSSDResolveServiceQuery> AvahiQuerier::createResolveServiceQuery(const DNSSDServiceID& service) { + return std::make_shared<AvahiResolveServiceQuery>(service, shared_from_this(), eventLoop); } -boost::shared_ptr<DNSSDResolveHostnameQuery> AvahiQuerier::createResolveHostnameQuery(const std::string& hostname, int interfaceIndex) { - return boost::shared_ptr<DNSSDResolveHostnameQuery>(new AvahiResolveHostnameQuery(hostname, interfaceIndex, shared_from_this(), eventLoop)); +std::shared_ptr<DNSSDResolveHostnameQuery> AvahiQuerier::createResolveHostnameQuery(const std::string& hostname, int interfaceIndex) { + return std::make_shared<AvahiResolveHostnameQuery>(hostname, interfaceIndex, shared_from_this(), eventLoop); } void AvahiQuerier::start() { - std::cout << "Starrting querier" << std::endl; - assert(!threadedPoll); - threadedPoll = avahi_threaded_poll_new(); - int error; - assert(!client); - client = avahi_client_new( - avahi_threaded_poll_get(threadedPoll), - static_cast<AvahiClientFlags>(0), NULL, this, &error); // TODO - if (!client) { - // TODO - std::cerr << "Avahi Error: " << avahi_strerror(error) << std::endl; - return; - } - std::cout << "Starrting event loop" << std::endl; - avahi_threaded_poll_start(threadedPoll); + std::cout << "Starrting querier" << std::endl; + assert(!threadedPoll); + threadedPoll = avahi_threaded_poll_new(); + int error; + assert(!client); + client = avahi_client_new( + avahi_threaded_poll_get(threadedPoll), + static_cast<AvahiClientFlags>(0), NULL, this, &error); // TODO + if (!client) { + // TODO + std::cerr << "Avahi Error: " << avahi_strerror(error) << std::endl; + return; + } + std::cout << "Starrting event loop" << std::endl; + avahi_threaded_poll_start(threadedPoll); } void AvahiQuerier::stop() { - assert(threadedPoll); - avahi_threaded_poll_stop(threadedPoll); - assert(client); - avahi_client_free(client); - avahi_threaded_poll_free(threadedPoll); + assert(threadedPoll); + avahi_threaded_poll_stop(threadedPoll); + assert(client); + avahi_client_free(client); + avahi_threaded_poll_free(threadedPoll); } } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h index 6ddd23d..73dd11d 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h @@ -1,55 +1,55 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> +#include <memory> + #include <avahi-client/client.h> #include <avahi-client/lookup.h> +#include <avahi-common/error.h> +#include <avahi-common/malloc.h> #include <avahi-common/thread-watch.h> #include <avahi-common/watch.h> -#include <avahi-common/malloc.h> -#include <avahi-common/error.h> -#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> #include <Swiften/Base/ByteArray.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> namespace Swift { - class EventLoop; - - class AvahiQuerier : - public DNSSDQuerier, - public boost::enable_shared_from_this<AvahiQuerier> { - public: - AvahiQuerier(EventLoop* eventLoop); - ~AvahiQuerier(); - - boost::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); - boost::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( - const std::string& name, int port, const ByteArray& info); - boost::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( - const DNSSDServiceID&); - boost::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( - const std::string& hostname, int interfaceIndex); - - void start(); - void stop(); - - AvahiThreadedPoll* getThreadedPoll() const { - return threadedPoll; - } - - AvahiClient* getClient() const { - return client; - } - - private: - EventLoop* eventLoop; - AvahiClient* client; - AvahiThreadedPoll* threadedPoll; - }; + class EventLoop; + + class AvahiQuerier : + public DNSSDQuerier, + public std::enable_shared_from_this<AvahiQuerier> { + public: + AvahiQuerier(EventLoop* eventLoop); + ~AvahiQuerier(); + + std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); + std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( + const std::string& name, unsigned short port, const ByteArray& info); + std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( + const DNSSDServiceID&); + std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( + const std::string& hostname, int interfaceIndex); + + void start(); + void stop(); + + AvahiThreadedPoll* getThreadedPoll() const { + return threadedPoll; + } + + AvahiClient* getClient() const { + return client; + } + + private: + EventLoop* eventLoop; + AvahiClient* client; + AvahiThreadedPoll* threadedPoll; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.cpp index 3b0e8da..08997f6 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.cpp @@ -1,15 +1,16 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> + #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> namespace Swift { -AvahiQuery::AvahiQuery(boost::shared_ptr<AvahiQuerier> q, EventLoop* eventLoop) : querier(q), eventLoop(eventLoop) { +AvahiQuery::AvahiQuery(std::shared_ptr<AvahiQuerier> q, EventLoop* eventLoop) : querier(q), eventLoop(eventLoop) { } AvahiQuery::~AvahiQuery() { diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h index 047e1cd..1b98bbf 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h @@ -1,30 +1,29 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> +#include <memory> #include <Swiften/EventLoop/EventOwner.h> namespace Swift { - class AvahiQuerier; - class EventLoop; + class AvahiQuerier; + class EventLoop; - class AvahiQuery : - public EventOwner, - public boost::enable_shared_from_this<AvahiQuery> { - public: - AvahiQuery(boost::shared_ptr<AvahiQuerier>, EventLoop* eventLoop); - virtual ~AvahiQuery(); - - protected: - boost::shared_ptr<AvahiQuerier> querier; - EventLoop* eventLoop; - }; + class AvahiQuery : + public EventOwner, + public std::enable_shared_from_this<AvahiQuery> { + public: + AvahiQuery(std::shared_ptr<AvahiQuerier>, EventLoop* eventLoop); + virtual ~AvahiQuery(); + + protected: + std::shared_ptr<AvahiQuerier> querier; + EventLoop* eventLoop; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.cpp index 8a7ed3b..04790d5 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.cpp @@ -1,12 +1,13 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h> #include <iostream> + #include <boost/bind.hpp> #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> @@ -14,87 +15,87 @@ namespace Swift { void AvahiRegisterQuery::registerService() { - std::cout << "Registering service " << name << ":" << port << std::endl; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - if (!group) { - std::cout << "Creating entry group" << std::endl; - group = avahi_entry_group_new(querier->getClient(), handleEntryGroupChange, this); - if (!group) { - std::cout << "Error ceating entry group" << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } - } - - doRegisterService(); - avahi_threaded_poll_unlock(querier->getThreadedPoll()); + std::cout << "Registering service " << name << ":" << port << std::endl; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + if (!group) { + std::cout << "Creating entry group" << std::endl; + group = avahi_entry_group_new(querier->getClient(), handleEntryGroupChange, this); + if (!group) { + std::cout << "Error ceating entry group" << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } + } + + doRegisterService(); + avahi_threaded_poll_unlock(querier->getThreadedPoll()); } void AvahiRegisterQuery::unregisterService() { - if (group) { - avahi_entry_group_free(group); - group = NULL; - } + if (group) { + avahi_entry_group_free(group); + group = NULL; + } } void AvahiRegisterQuery::updateServiceInfo(const ByteArray& txtRecord) { - this->txtRecord = txtRecord; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - assert(group); - avahi_entry_group_reset(group); - doRegisterService(); - avahi_threaded_poll_unlock(querier->getThreadedPoll()); + this->txtRecord = txtRecord; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + assert(group); + avahi_entry_group_reset(group); + doRegisterService(); + avahi_threaded_poll_unlock(querier->getThreadedPoll()); } void AvahiRegisterQuery::doRegisterService() { - AvahiStringList* txtList; - avahi_string_list_parse(vecptr(txtRecord), txtRecord.size(), &txtList); - - int result = avahi_entry_group_add_service_strlst(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), name.c_str(), "_presence._tcp", NULL, NULL, port, txtList); - if (result < 0) { - std::cout << "Error registering service: " << avahi_strerror(result) << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } - result = avahi_entry_group_commit(group); - if (result < 0) { - std::cout << "Error registering service: " << avahi_strerror(result) << std::endl; - } + AvahiStringList* txtList; + avahi_string_list_parse(vecptr(txtRecord), txtRecord.size(), &txtList); + + int result = avahi_entry_group_add_service_strlst(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), name.c_str(), "_presence._tcp", NULL, NULL, port, txtList); + if (result < 0) { + std::cout << "Error registering service: " << avahi_strerror(result) << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } + result = avahi_entry_group_commit(group); + if (result < 0) { + std::cout << "Error registering service: " << avahi_strerror(result) << std::endl; + } } void AvahiRegisterQuery::handleEntryGroupChange(AvahiEntryGroup* g, AvahiEntryGroupState state) { - std::cout << "ENtry group callback: " << state << std::endl; - switch (state) { - case AVAHI_ENTRY_GROUP_ESTABLISHED : - // Domain is a hack! - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, "local", "_presence._tcp", 0))), shared_from_this()); - std::cout << "Entry group established" << std::endl; - break; - case AVAHI_ENTRY_GROUP_COLLISION : { - std::cout << "Entry group collision" << std::endl; - /*char *n; - n = avahi_alternative_service_name(name); - avahi_free(name); - name = n;*/ - break; - } - - case AVAHI_ENTRY_GROUP_FAILURE : - std::cout << "Entry group failure " << avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))) << std::endl; - break; - - case AVAHI_ENTRY_GROUP_UNCOMMITED: - case AVAHI_ENTRY_GROUP_REGISTERING: - ; - - /* - DNSServiceErrorType result = DNSServiceRegister( - &sdRef, 0, 0, name.c_str(), "_presence._tcp", NULL, NULL, port, - txtRecord.getSize(), txtRecord.getData(), - &AvahiRegisterQuery::handleServiceRegisteredStatic, this); - if (result != kDNSServiceErr_NoError) { - sdRef = NULL; - }*/ - //eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } + std::cout << "ENtry group callback: " << state << std::endl; + switch (state) { + case AVAHI_ENTRY_GROUP_ESTABLISHED : + // Domain is a hack! + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, "local", "_presence._tcp", 0))), shared_from_this()); + std::cout << "Entry group established" << std::endl; + break; + case AVAHI_ENTRY_GROUP_COLLISION : { + std::cout << "Entry group collision" << std::endl; + /*char *n; + n = avahi_alternative_service_name(name); + avahi_free(name); + name = n;*/ + break; + } + + case AVAHI_ENTRY_GROUP_FAILURE : + std::cout << "Entry group failure " << avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))) << std::endl; + break; + + case AVAHI_ENTRY_GROUP_UNCOMMITED: + case AVAHI_ENTRY_GROUP_REGISTERING: + ; + + /* + DNSServiceErrorType result = DNSServiceRegister( + &sdRef, 0, 0, name.c_str(), "_presence._tcp", NULL, NULL, port, + txtRecord.getSize(), txtRecord.getData(), + &AvahiRegisterQuery::handleServiceRegisteredStatic, this); + if (result != kDNSServiceErr_NoError) { + sdRef = NULL; + }*/ + //eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h index b47ed12..b780043 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h @@ -1,57 +1,57 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <avahi-client/publish.h> -#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> -#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> #include <Swiften/Base/ByteArray.h> #include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> namespace Swift { - class AvahiQuerier; + class AvahiQuerier; - class AvahiRegisterQuery : public DNSSDRegisterQuery, public AvahiQuery { - public: - AvahiRegisterQuery(const std::string& name, int port, const ByteArray& txtRecord, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), name(name), port(port), txtRecord(txtRecord), group(0) { - } + class AvahiRegisterQuery : public DNSSDRegisterQuery, public AvahiQuery { + public: + AvahiRegisterQuery(const std::string& name, unsigned short port, const ByteArray& txtRecord, std::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), name(name), port(port), txtRecord(txtRecord), group(0) { + } - void registerService(); - void unregisterService(); - void updateServiceInfo(const ByteArray& txtRecord); + void registerService(); + void unregisterService(); + void updateServiceInfo(const ByteArray& txtRecord); - private: - void doRegisterService(); + private: + void doRegisterService(); - static void handleEntryGroupChange(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { - static_cast<AvahiRegisterQuery*>(userdata)->handleEntryGroupChange(g, state); - } + static void handleEntryGroupChange(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { + static_cast<AvahiRegisterQuery*>(userdata)->handleEntryGroupChange(g, state); + } - void handleEntryGroupChange(AvahiEntryGroup* g, AvahiEntryGroupState state); + void handleEntryGroupChange(AvahiEntryGroup* g, AvahiEntryGroupState state); /* - static void handleServiceRegisteredStatic(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { - static_cast<AvahiRegisterQuery*>(context)->handleServiceRegistered(errorCode, name, regtype, domain); - } - - void handleServiceRegistered(DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain) { - if (errorCode != kDNSServiceErr_NoError) { - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } - else { - } - } - */ - - private: - std::string name; - int port; - ByteArray txtRecord; - AvahiEntryGroup* group; - }; + static void handleServiceRegisteredStatic(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { + static_cast<AvahiRegisterQuery*>(context)->handleServiceRegistered(errorCode, name, regtype, domain); + } + + void handleServiceRegistered(DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain) { + if (errorCode != kDNSServiceErr_NoError) { + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } + else { + } + } + */ + + private: + std::string name; + unsigned short port; + ByteArray txtRecord; + AvahiEntryGroup* group; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.cpp index d9a1c5c..262add3 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.cpp @@ -1,22 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h> -#include <iostream> #include <boost/bind.hpp> +#include <netinet/in.h> + +#include <Swiften/Base/Log.h> + namespace Swift { -AvahiResolveHostnameQuery::AvahiResolveHostnameQuery(const std::string& hostname, int, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), hostname(hostname) { - std::cout << "Resolving hostname " << hostname << std::endl; +AvahiResolveHostnameQuery::AvahiResolveHostnameQuery(const std::string& hostname, int, std::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), hostname(hostname) { + SWIFT_LOG(debug) << "Resolving hostname " << hostname; } void AvahiResolveHostnameQuery::run() { - eventLoop->postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>(HostAddress(hostname))), shared_from_this()); + eventLoop->postEvent(boost::bind(boost::ref(onHostnameResolved), HostAddress::fromString(hostname)), shared_from_this()); } } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h index 5ee6346..33c425f 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h @@ -1,33 +1,32 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <string> + +#include <Swiften/EventLoop/EventLoop.h> #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> #include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> -#include <Swiften/EventLoop/EventLoop.h> #include <Swiften/Network/HostAddress.h> -#include <netinet/in.h> - namespace Swift { - class AvahiQuerier; + class AvahiQuerier; - class AvahiResolveHostnameQuery : public DNSSDResolveHostnameQuery, public AvahiQuery { - public: - AvahiResolveHostnameQuery(const std::string& hostname, int, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop); + class AvahiResolveHostnameQuery : public DNSSDResolveHostnameQuery, public AvahiQuery { + public: + AvahiResolveHostnameQuery(const std::string& hostname, int, std::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop); - void run(); + void run(); - void finish() { - } + void finish() { + } - private: - HostAddress hostAddress; - std::string hostname; - }; + private: + HostAddress hostAddress; + std::string hostname; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.cpp index ebd2329..a5e52b2 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.cpp @@ -1,65 +1,66 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h> -#include <boost/bind.hpp> #include <iostream> +#include <boost/bind.hpp> + #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> namespace Swift { void AvahiResolveServiceQuery::start() { - std::cout << "Start resolving " << service.getName() << " " << service.getType() << " " << service.getDomain() << std::endl; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - assert(!resolver); - resolver = avahi_service_resolver_new(querier->getClient(), service.getNetworkInterfaceID(), AVAHI_PROTO_UNSPEC, service.getName().c_str(), service.getType().c_str(), service.getDomain().c_str(), AVAHI_PROTO_UNSPEC, static_cast<AvahiLookupFlags>(0), handleServiceResolvedStatic, this); - if (!resolver) { - std::cout << "Error starting resolver" << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); - } - avahi_threaded_poll_unlock(querier->getThreadedPoll()); + std::cout << "Start resolving " << service.getName() << " " << service.getType() << " " << service.getDomain() << std::endl; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + assert(!resolver); + resolver = avahi_service_resolver_new(querier->getClient(), service.getNetworkInterfaceID(), AVAHI_PROTO_UNSPEC, service.getName().c_str(), service.getType().c_str(), service.getDomain().c_str(), AVAHI_PROTO_UNSPEC, static_cast<AvahiLookupFlags>(0), handleServiceResolvedStatic, this); + if (!resolver) { + std::cout << "Error starting resolver" << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); + } + avahi_threaded_poll_unlock(querier->getThreadedPoll()); } void AvahiResolveServiceQuery::stop() { - std::cout << "Stop resolving" << std::endl; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - avahi_service_resolver_free(resolver); - resolver = NULL; - avahi_threaded_poll_unlock(querier->getThreadedPoll()); + std::cout << "Stop resolving" << std::endl; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + avahi_service_resolver_free(resolver); + resolver = NULL; + avahi_threaded_poll_unlock(querier->getThreadedPoll()); } void AvahiResolveServiceQuery::handleServiceResolved(AvahiServiceResolver* resolver, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent event, const char *name, const char * type, const char* domain, const char * /*host_name*/, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags) { - std::cout << "Resolve finished" << std::endl; - switch(event) { - case AVAHI_RESOLVER_FAILURE: - std::cout << "Resolve error " << avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(resolver))) << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); - break; - case AVAHI_RESOLVER_FOUND: { - std::cout << "Success" << std::endl; - char a[AVAHI_ADDRESS_STR_MAX]; - avahi_address_snprint(a, sizeof(a), address); + std::cout << "Resolve finished" << std::endl; + switch(event) { + case AVAHI_RESOLVER_FAILURE: + std::cout << "Resolve error " << avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(resolver))) << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); + break; + case AVAHI_RESOLVER_FOUND: { + std::cout << "Success" << std::endl; + char a[AVAHI_ADDRESS_STR_MAX]; + avahi_address_snprint(a, sizeof(a), address); - ByteArray txtRecord; - txtRecord.resize(1024); - avahi_string_list_serialize(txt, vecptr(txtRecord), txtRecord.size()); + ByteArray txtRecord; + txtRecord.resize(1024); + avahi_string_list_serialize(txt, vecptr(txtRecord), txtRecord.size()); - // FIXME: Probably not accurate - std::string fullname = std::string(name) + "." + std::string(type) + "." + std::string(domain) + "."; - std::cout << "Result: " << fullname << "->" << std::string(a) << ":" << port << std::endl; - eventLoop->postEvent( - boost::bind( - boost::ref(onServiceResolved), - Result(fullname, std::string(a), port, txtRecord)), - shared_from_this()); - break; - } - } + // FIXME: Probably not accurate + std::string fullname = std::string(name) + "." + std::string(type) + "." + std::string(domain) + "."; + std::cout << "Result: " << fullname << "->" << std::string(a) << ":" << port << std::endl; + eventLoop->postEvent( + boost::bind( + boost::ref(onServiceResolved), + Result(fullname, std::string(a), port, txtRecord)), + shared_from_this()); + break; + } + } } } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h index a39d732..c05c73e 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h @@ -1,39 +1,39 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <avahi-client/lookup.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/EventLoop.h> #include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> #include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> #include <Swiften/LinkLocal/LinkLocalServiceInfo.h> -#include <Swiften/Base/ByteArray.h> -#include <Swiften/EventLoop/EventLoop.h> namespace Swift { - class AvahiQuerier; + class AvahiQuerier; - class AvahiResolveServiceQuery : public DNSSDResolveServiceQuery, public AvahiQuery { - public: - AvahiResolveServiceQuery(const DNSSDServiceID& service, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), service(service), resolver(NULL) { - } + class AvahiResolveServiceQuery : public DNSSDResolveServiceQuery, public AvahiQuery { + public: + AvahiResolveServiceQuery(const DNSSDServiceID& service, std::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), service(service), resolver(NULL) { + } - void start(); - void stop(); + void start(); + void stop(); - private: - static void handleServiceResolvedStatic(AvahiServiceResolver* resolver, AvahiIfIndex interfaceIndex, AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void* context) { - static_cast<AvahiResolveServiceQuery*>(context)->handleServiceResolved(resolver, interfaceIndex, protocol, event, name, type, domain, host_name, address, port, txt, flags); - } + private: + static void handleServiceResolvedStatic(AvahiServiceResolver* resolver, AvahiIfIndex interfaceIndex, AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void* context) { + static_cast<AvahiResolveServiceQuery*>(context)->handleServiceResolved(resolver, interfaceIndex, protocol, event, name, type, domain, host_name, address, port, txt, flags); + } - void handleServiceResolved(AvahiServiceResolver* resolver, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent event, const char *name, const char * type, const char* domain, const char * /*host_name*/, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags); + void handleServiceResolved(AvahiServiceResolver* resolver, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent event, const char *name, const char * type, const char* domain, const char * /*host_name*/, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags); - private: - DNSSDServiceID service; - AvahiServiceResolver* resolver; - }; + private: + DNSSDServiceID service; + AvahiServiceResolver* resolver; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h index 52d6654..63f34db 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h @@ -1,62 +1,68 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <boost/numeric/conversion/cast.hpp> + +#include <Swiften/EventLoop/EventLoop.h> #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> #include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> -#include <Swiften/EventLoop/EventLoop.h> -#include <boost/numeric/conversion/cast.hpp> namespace Swift { - class BonjourQuerier; - - class BonjourBrowseQuery : public DNSSDBrowseQuery, public BonjourQuery { - public: - BonjourBrowseQuery(boost::shared_ptr<BonjourQuerier> q, EventLoop* eventLoop) : BonjourQuery(q, eventLoop) { - DNSServiceErrorType result = DNSServiceBrowse( - &sdRef, 0, 0, "_presence._tcp", 0, - &BonjourBrowseQuery::handleServiceDiscoveredStatic, this); - if (result != kDNSServiceErr_NoError) { - sdRef = NULL; - } - } - - void startBrowsing() { - if (!sdRef) { - eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); - } - else { - run(); - } - } - - void stopBrowsing() { - finish(); - } - - private: - static void handleServiceDiscoveredStatic(DNSServiceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain, void *context) { - static_cast<BonjourBrowseQuery*>(context)->handleServiceDiscovered(flags, interfaceIndex, errorCode, name, type, domain); - } - - void handleServiceDiscovered(DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain) { - if (errorCode != kDNSServiceErr_NoError) { - eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); - } - else { - //std::cout << "Discovered service: name:" << name << " domain:" << domain << " type: " << type << std::endl; - DNSSDServiceID service(name, domain, type, boost::numeric_cast<int>(interfaceIndex)); - if (flags & kDNSServiceFlagsAdd) { - eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); - } - else { - eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); - } - } - } - }; + class BonjourQuerier; + + class BonjourBrowseQuery : public DNSSDBrowseQuery, public BonjourQuery { + public: + BonjourBrowseQuery(std::shared_ptr<BonjourQuerier> q, EventLoop* eventLoop) : BonjourQuery(q, eventLoop) { + DNSServiceErrorType result = DNSServiceBrowse( + &sdRef, 0, 0, "_presence._tcp", nullptr, + &BonjourBrowseQuery::handleServiceDiscoveredStatic, this); + if (result != kDNSServiceErr_NoError) { + sdRef = nullptr; + } + } + + void startBrowsing() { + if (!sdRef) { + eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); + } + else { + run(); + } + } + + void stopBrowsing() { + finish(); + } + + private: + static void handleServiceDiscoveredStatic(DNSServiceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain, void *context) { + static_cast<BonjourBrowseQuery*>(context)->handleServiceDiscovered(flags, interfaceIndex, errorCode, name, type, domain); + } + + void handleServiceDiscovered(DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain) { + if (errorCode != kDNSServiceErr_NoError) { + eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); + } + else { + //std::cout << "Discovered service: name:" << name << " domain:" << domain << " type: " << type << std::endl; + try { + DNSSDServiceID service(name, domain, type, boost::numeric_cast<int>(interfaceIndex)); + if (flags & kDNSServiceFlagsAdd) { + eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); + } + else { + eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); + } + } + catch (...) { + eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); + } + } + } + }; } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp index 530e066..551421e 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp @@ -1,136 +1,136 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h> -#include <unistd.h> -#include <sys/socket.h> #include <fcntl.h> +#include <sys/socket.h> +#include <unistd.h> +#include <Swiften/Base/Algorithm.h> +#include <Swiften/Base/Log.h> #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h> #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h> -#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h> #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h> -#include <Swiften/Base/foreach.h> -#include <Swiften/Base/Algorithm.h> +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h> namespace Swift { -BonjourQuerier::BonjourQuerier(EventLoop* eventLoop) : eventLoop(eventLoop), stopRequested(false), thread(0) { - int fds[2]; - int result = pipe(fds); - assert(result == 0); - (void) result; - interruptSelectReadSocket = fds[0]; - fcntl(interruptSelectReadSocket, F_SETFL, fcntl(interruptSelectReadSocket, F_GETFL)|O_NONBLOCK); - interruptSelectWriteSocket = fds[1]; +BonjourQuerier::BonjourQuerier(EventLoop* eventLoop) : eventLoop(eventLoop), stopRequested(false), thread(nullptr) { + int fds[2]; + int result = pipe(fds); + assert(result == 0); + (void) result; + interruptSelectReadSocket = fds[0]; + fcntl(interruptSelectReadSocket, F_SETFL, fcntl(interruptSelectReadSocket, F_GETFL)|O_NONBLOCK); + interruptSelectWriteSocket = fds[1]; } BonjourQuerier::~BonjourQuerier() { - assert(!thread); + assert(!thread); } -boost::shared_ptr<DNSSDBrowseQuery> BonjourQuerier::createBrowseQuery() { - return boost::shared_ptr<DNSSDBrowseQuery>(new BonjourBrowseQuery(shared_from_this(), eventLoop)); +std::shared_ptr<DNSSDBrowseQuery> BonjourQuerier::createBrowseQuery() { + return std::make_shared<BonjourBrowseQuery>(shared_from_this(), eventLoop); } -boost::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { - return boost::shared_ptr<DNSSDRegisterQuery>(new BonjourRegisterQuery(name, port, info, shared_from_this(), eventLoop)); +std::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) { + return std::make_shared<BonjourRegisterQuery>(name, port, info, shared_from_this(), eventLoop); } -boost::shared_ptr<DNSSDResolveServiceQuery> BonjourQuerier::createResolveServiceQuery(const DNSSDServiceID& service) { - return boost::shared_ptr<DNSSDResolveServiceQuery>(new BonjourResolveServiceQuery(service, shared_from_this(), eventLoop)); +std::shared_ptr<DNSSDResolveServiceQuery> BonjourQuerier::createResolveServiceQuery(const DNSSDServiceID& service) { + return std::make_shared<BonjourResolveServiceQuery>(service, shared_from_this(), eventLoop); } -boost::shared_ptr<DNSSDResolveHostnameQuery> BonjourQuerier::createResolveHostnameQuery(const std::string& hostname, int interfaceIndex) { - return boost::shared_ptr<DNSSDResolveHostnameQuery>(new BonjourResolveHostnameQuery(hostname, interfaceIndex, shared_from_this(), eventLoop)); +std::shared_ptr<DNSSDResolveHostnameQuery> BonjourQuerier::createResolveHostnameQuery(const std::string& hostname, int interfaceIndex) { + return std::make_shared<BonjourResolveHostnameQuery>(hostname, interfaceIndex, shared_from_this(), eventLoop); } -void BonjourQuerier::addRunningQuery(boost::shared_ptr<BonjourQuery> query) { - { - boost::lock_guard<boost::mutex> lock(runningQueriesMutex); - runningQueries.push_back(query); - } - runningQueriesAvailableEvent.notify_one(); - interruptSelect(); +void BonjourQuerier::addRunningQuery(std::shared_ptr<BonjourQuery> query) { + { + std::lock_guard<std::mutex> lock(runningQueriesMutex); + runningQueries.push_back(query); + } + runningQueriesAvailableEvent.notify_one(); + interruptSelect(); } -void BonjourQuerier::removeRunningQuery(boost::shared_ptr<BonjourQuery> query) { - { - boost::lock_guard<boost::mutex> lock(runningQueriesMutex); - erase(runningQueries, query); - } +void BonjourQuerier::removeRunningQuery(std::shared_ptr<BonjourQuery> query) { + { + std::lock_guard<std::mutex> lock(runningQueriesMutex); + erase(runningQueries, query); + } } void BonjourQuerier::interruptSelect() { - char c = 0; - write(interruptSelectWriteSocket, &c, 1); + char c = 0; + write(interruptSelectWriteSocket, &c, 1); } void BonjourQuerier::start() { - assert(!thread); - thread = new boost::thread(boost::bind(&BonjourQuerier::run, shared_from_this())); + assert(!thread); + thread = new std::thread(boost::bind(&BonjourQuerier::run, shared_from_this())); } void BonjourQuerier::stop() { - if (thread) { - stopRequested = true; - assert(runningQueries.empty()); - runningQueriesAvailableEvent.notify_one(); - interruptSelect(); - thread->join(); - delete thread; - thread = NULL; - stopRequested = false; - } + if (thread) { + stopRequested = true; + assert(runningQueries.empty()); + runningQueriesAvailableEvent.notify_one(); + interruptSelect(); + thread->join(); + delete thread; + thread = nullptr; + stopRequested = false; + } } void BonjourQuerier::run() { - while (!stopRequested) { - fd_set fdSet; - int maxSocket; - { - boost::unique_lock<boost::mutex> lock(runningQueriesMutex); - if (runningQueries.empty()) { - runningQueriesAvailableEvent.wait(lock); - if (runningQueries.empty()) { - continue; - } - } - - // Run all running queries - FD_ZERO(&fdSet); - maxSocket = interruptSelectReadSocket; - FD_SET(interruptSelectReadSocket, &fdSet); - - foreach(const boost::shared_ptr<BonjourQuery>& query, runningQueries) { - int socketID = query->getSocketID(); - maxSocket = std::max(maxSocket, socketID); - FD_SET(socketID, &fdSet); - } - } - - if (select(maxSocket+1, &fdSet, NULL, NULL, 0) <= 0) { - continue; - } - - if (FD_ISSET(interruptSelectReadSocket, &fdSet)) { - char dummy; - while (read(interruptSelectReadSocket, &dummy, 1) > 0) {} - } - - { - boost::lock_guard<boost::mutex> lock(runningQueriesMutex); - foreach(boost::shared_ptr<BonjourQuery> query, runningQueries) { - if (FD_ISSET(query->getSocketID(), &fdSet)) { - query->processResult(); - } - } - } - } + while (!stopRequested) { + fd_set fdSet; + int maxSocket; + { + std::unique_lock<std::mutex> lock(runningQueriesMutex); + if (runningQueries.empty()) { + runningQueriesAvailableEvent.wait(lock); + if (runningQueries.empty()) { + continue; + } + } + + // Run all running queries + FD_ZERO(&fdSet); + maxSocket = interruptSelectReadSocket; + FD_SET(interruptSelectReadSocket, &fdSet); + + for (const auto& query : runningQueries) { + int socketID = query->getSocketID(); + maxSocket = std::max(maxSocket, socketID); + FD_SET(socketID, &fdSet); + } + } + + if (select(maxSocket+1, &fdSet, nullptr, nullptr, nullptr) <= 0) { + continue; + } + + if (FD_ISSET(interruptSelectReadSocket, &fdSet)) { + char dummy; + while (read(interruptSelectReadSocket, &dummy, 1) > 0) {} + } + + { + std::lock_guard<std::mutex> lock(runningQueriesMutex); + for (auto&& query : runningQueries) { + if (FD_ISSET(query->getSocketID(), &fdSet)) { + query->processResult(); + } + } + } + } } } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h index 57fde49..6af1c1f 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h @@ -1,56 +1,55 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> #include <list> -#include <boost/thread/thread.hpp> -#include <boost/thread/mutex.hpp> +#include <memory> +#include <mutex> +#include <thread> -#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> -#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> #include <Swiften/Base/ByteArray.h> +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> namespace Swift { - class BonjourQuerier : - public DNSSDQuerier, - public boost::enable_shared_from_this<BonjourQuerier> { - public: - BonjourQuerier(EventLoop* eventLoop); - ~BonjourQuerier(); - - boost::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); - boost::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( - const std::string& name, int port, const ByteArray& info); - boost::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( - const DNSSDServiceID&); - boost::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( - const std::string& hostname, int interfaceIndex); - - void start(); - void stop(); - - private: - friend class BonjourQuery; - - void addRunningQuery(boost::shared_ptr<BonjourQuery>); - void removeRunningQuery(boost::shared_ptr<BonjourQuery>); - void interruptSelect(); - void run(); - - private: - EventLoop* eventLoop; - bool stopRequested; - boost::thread* thread; - boost::mutex runningQueriesMutex; - std::list< boost::shared_ptr<BonjourQuery> > runningQueries; - int interruptSelectReadSocket; - int interruptSelectWriteSocket; - boost::condition_variable runningQueriesAvailableEvent; - }; + class BonjourQuerier : + public DNSSDQuerier, + public std::enable_shared_from_this<BonjourQuerier> { + public: + BonjourQuerier(EventLoop* eventLoop); + ~BonjourQuerier(); + + std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); + std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( + const std::string& name, unsigned short port, const ByteArray& info); + std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( + const DNSSDServiceID&); + std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( + const std::string& hostname, int interfaceIndex); + + void start(); + void stop(); + + private: + friend class BonjourQuery; + + void addRunningQuery(std::shared_ptr<BonjourQuery>); + void removeRunningQuery(std::shared_ptr<BonjourQuery>); + void interruptSelect(); + void run(); + + private: + EventLoop* eventLoop; + bool stopRequested; + std::thread* thread; + std::mutex runningQueriesMutex; + std::list< std::shared_ptr<BonjourQuery> > runningQueries; + int interruptSelectReadSocket; + int interruptSelectWriteSocket; + std::condition_variable runningQueriesAvailableEvent; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp index 9ff4b9f..b4448c7 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp @@ -1,37 +1,38 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> + #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h> namespace Swift { -BonjourQuery::BonjourQuery(boost::shared_ptr<BonjourQuerier> q, EventLoop* eventLoop) : eventLoop(eventLoop), querier(q), sdRef(0) { +BonjourQuery::BonjourQuery(std::shared_ptr<BonjourQuerier> q, EventLoop* eventLoop) : eventLoop(eventLoop), querier(q), sdRef(nullptr) { } BonjourQuery::~BonjourQuery() { - DNSServiceRefDeallocate(sdRef); + DNSServiceRefDeallocate(sdRef); } void BonjourQuery::processResult() { - boost::lock_guard<boost::mutex> lock(sdRefMutex); - DNSServiceProcessResult(sdRef); + std::lock_guard<std::mutex> lock(sdRefMutex); + DNSServiceProcessResult(sdRef); } int BonjourQuery::getSocketID() const { - boost::lock_guard<boost::mutex> lock(sdRefMutex); - return DNSServiceRefSockFD(sdRef); + std::lock_guard<std::mutex> lock(sdRefMutex); + return DNSServiceRefSockFD(sdRef); } void BonjourQuery::run() { - querier->addRunningQuery(shared_from_this()); + querier->addRunningQuery(shared_from_this()); } void BonjourQuery::finish() { - querier->removeRunningQuery(shared_from_this()); + querier->removeRunningQuery(shared_from_this()); } } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h index d91c57c..d3cebe4 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h @@ -1,40 +1,40 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <memory> +#include <mutex> + #include <dns_sd.h> -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> -#include <boost/thread/mutex.hpp> #include <Swiften/EventLoop/EventOwner.h> namespace Swift { - class BonjourQuerier; - class EventLoop; - - class BonjourQuery : - public EventOwner, - public boost::enable_shared_from_this<BonjourQuery> { - public: - BonjourQuery(boost::shared_ptr<BonjourQuerier>, EventLoop* eventLoop); - virtual ~BonjourQuery(); - - void processResult(); - int getSocketID() const; - - protected: - void run(); - void finish(); - - protected: - EventLoop* eventLoop; - boost::shared_ptr<BonjourQuerier> querier; - mutable boost::mutex sdRefMutex; - DNSServiceRef sdRef; - }; + class BonjourQuerier; + class EventLoop; + + class BonjourQuery : + public EventOwner, + public std::enable_shared_from_this<BonjourQuery> { + public: + BonjourQuery(std::shared_ptr<BonjourQuerier>, EventLoop* eventLoop); + virtual ~BonjourQuery(); + + void processResult(); + int getSocketID() const; + + protected: + void run(); + void finish(); + + protected: + EventLoop* eventLoop; + std::shared_ptr<BonjourQuerier> querier; + mutable std::mutex sdRefMutex; + DNSServiceRef sdRef; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h index 1bec5f7..cc95d64 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h @@ -1,62 +1,79 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> -#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> +#include <mutex> + +#include <boost/numeric/conversion/cast.hpp> + #include <Swiften/Base/ByteArray.h> #include <Swiften/EventLoop/EventLoop.h> -#include <boost/numeric/conversion/cast.hpp> +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> namespace Swift { - class BonjourQuerier; - - class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery { - public: - BonjourRegisterQuery(const std::string& name, int port, const ByteArray& txtRecord, boost::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { - DNSServiceErrorType result = DNSServiceRegister( - &sdRef, 0, 0, name.c_str(), "_presence._tcp", NULL, NULL, boost::numeric_cast<unsigned short>(port), - boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), - &BonjourRegisterQuery::handleServiceRegisteredStatic, this); - if (result != kDNSServiceErr_NoError) { - sdRef = NULL; - } - } - - void registerService() { - if (sdRef) { - run(); - } - else { - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } - } - - void unregisterService() { - finish(); - } - - void updateServiceInfo(const ByteArray& txtRecord) { - boost::lock_guard<boost::mutex> lock(sdRefMutex); - DNSServiceUpdateRecord(sdRef, NULL, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0); - } - - private: - static void handleServiceRegisteredStatic(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { - static_cast<BonjourRegisterQuery*>(context)->handleServiceRegistered(errorCode, name, regtype, domain); - } - - void handleServiceRegistered(DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain) { - if (errorCode != kDNSServiceErr_NoError) { - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } - else { - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, domain, regtype, 0))), shared_from_this()); - } - } - }; + class BonjourQuerier; + + class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery { + public: + BonjourRegisterQuery(const std::string& name, unsigned short port, const ByteArray& txtRecord, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { + unsigned short recordSize = 0; + try { + recordSize = boost::numeric_cast<unsigned short>(txtRecord.size()); + } + catch (const boost::numeric::bad_numeric_cast&) { + SWIFT_LOG(warning) << "Bonjour TXT record is too long (" << txtRecord.size() << " bytes), not registring service"; + return; + } + DNSServiceErrorType result = DNSServiceRegister( + &sdRef, 0, 0, name.c_str(), "_presence._tcp", nullptr, nullptr, port, + recordSize, vecptr(txtRecord), + &BonjourRegisterQuery::handleServiceRegisteredStatic, this); + if (result != kDNSServiceErr_NoError) { + SWIFT_LOG(warning) << "Failed to register Bonjour service"; + sdRef = nullptr; + } + } + + void registerService() { + if (sdRef) { + run(); + } + else { + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } + } + + void unregisterService() { + finish(); + } + + void updateServiceInfo(const ByteArray& txtRecord) { + std::lock_guard<std::mutex> lock(sdRefMutex); + try { + DNSServiceUpdateRecord(sdRef, nullptr, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0); + } + catch (const boost::numeric::bad_numeric_cast&) { + SWIFT_LOG(warning) << "Bonjour TXT record is too long (" << txtRecord.size() << " bytes), not updating service record"; + } + } + + private: + static void handleServiceRegisteredStatic(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { + static_cast<BonjourRegisterQuery*>(context)->handleServiceRegistered(errorCode, name, regtype, domain); + } + + void handleServiceRegistered(DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain) { + if (errorCode != kDNSServiceErr_NoError) { + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } + else { + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, domain, regtype, 0))), shared_from_this()); + } + } + }; } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h index 59d1af5..61f000e 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -18,55 +18,60 @@ #include <netinet/in.h> namespace Swift { - class BonjourQuerier; + class BonjourQuerier; - class BonjourResolveHostnameQuery : public DNSSDResolveHostnameQuery, public BonjourQuery { - public: - BonjourResolveHostnameQuery(const std::string& hostname, int interfaceIndex, boost::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { - DNSServiceErrorType result = DNSServiceGetAddrInfo( - &sdRef, 0, boost::numeric_cast<unsigned int>(interfaceIndex), kDNSServiceProtocol_IPv4, - hostname.c_str(), - &BonjourResolveHostnameQuery::handleHostnameResolvedStatic, this); - if (result != kDNSServiceErr_NoError) { - sdRef = NULL; - } - } + class BonjourResolveHostnameQuery : public DNSSDResolveHostnameQuery, public BonjourQuery { + public: + BonjourResolveHostnameQuery(const std::string& hostname, int interfaceIndex, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { + try { + DNSServiceErrorType result = DNSServiceGetAddrInfo( + &sdRef, 0, boost::numeric_cast<unsigned int>(interfaceIndex), kDNSServiceProtocol_IPv4, + hostname.c_str(), + &BonjourResolveHostnameQuery::handleHostnameResolvedStatic, this); + if (result != kDNSServiceErr_NoError) { + sdRef = nullptr; + } + } + catch (...) { + sdRef = nullptr; + } + } - //void DNSSDResolveHostnameQuery::run() { - void run() { - if (sdRef) { - BonjourQuery::run(); - } - else { - eventLoop->postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>()), shared_from_this()); - } - } + //void DNSSDResolveHostnameQuery::run() { + void run() { + if (sdRef) { + BonjourQuery::run(); + } + else { + eventLoop->postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>()), shared_from_this()); + } + } - void finish() { - BonjourQuery::finish(); - } + void finish() { + BonjourQuery::finish(); + } - private: - static void handleHostnameResolvedStatic(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType errorCode, const char*, const struct sockaddr *address, uint32_t, void *context) { - static_cast<BonjourResolveHostnameQuery*>(context)->handleHostnameResolved(errorCode, address); - } + private: + static void handleHostnameResolvedStatic(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType errorCode, const char*, const struct sockaddr *address, uint32_t, void *context) { + static_cast<BonjourResolveHostnameQuery*>(context)->handleHostnameResolved(errorCode, address); + } - void handleHostnameResolved(DNSServiceErrorType errorCode, const struct sockaddr *rawAddress) { - if (errorCode) { - eventLoop->postEvent( - boost::bind(boost::ref(onHostnameResolved), - boost::optional<HostAddress>()), - shared_from_this()); - } - else { - assert(rawAddress->sa_family == AF_INET); - const sockaddr_in* sa = reinterpret_cast<const sockaddr_in*>(rawAddress); - uint32_t address = ntohl(sa->sin_addr.s_addr); - eventLoop->postEvent(boost::bind( - boost::ref(onHostnameResolved), - HostAddress(reinterpret_cast<unsigned char*>(&address), 4)), - shared_from_this()); - } - } - }; + void handleHostnameResolved(DNSServiceErrorType errorCode, const struct sockaddr *rawAddress) { + if (errorCode) { + eventLoop->postEvent( + boost::bind(boost::ref(onHostnameResolved), + boost::optional<HostAddress>()), + shared_from_this()); + } + else { + assert(rawAddress->sa_family == AF_INET); + const sockaddr_in* sa = reinterpret_cast<const sockaddr_in*>(rawAddress); + uint32_t address = ntohl(sa->sin_addr.s_addr); + eventLoop->postEvent(boost::bind( + boost::ref(onHostnameResolved), + HostAddress(reinterpret_cast<unsigned char*>(&address), 4)), + shared_from_this()); + } + } + }; } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h index 2eeac64..4baf87b 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h @@ -1,64 +1,71 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <boost/numeric/conversion/cast.hpp> + +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/EventLoop.h> #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> #include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> #include <Swiften/LinkLocal/LinkLocalServiceInfo.h> -#include <Swiften/Base/ByteArray.h> -#include <Swiften/EventLoop/EventLoop.h> namespace Swift { - class BonjourQuerier; + class BonjourQuerier; - class BonjourResolveServiceQuery : public DNSSDResolveServiceQuery, public BonjourQuery { - public: - BonjourResolveServiceQuery(const DNSSDServiceID& service, boost::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { - DNSServiceErrorType result = DNSServiceResolve( - &sdRef, 0, boost::numeric_cast<unsigned int>(service.getNetworkInterfaceID()), - service.getName().c_str(), service.getType().c_str(), - service.getDomain().c_str(), - &BonjourResolveServiceQuery::handleServiceResolvedStatic, this); - if (result != kDNSServiceErr_NoError) { - sdRef = NULL; - } - } + class BonjourResolveServiceQuery : public DNSSDResolveServiceQuery, public BonjourQuery { + public: + BonjourResolveServiceQuery(const DNSSDServiceID& service, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { + try { + DNSServiceErrorType result = DNSServiceResolve( + &sdRef, 0, boost::numeric_cast<unsigned int>(service.getNetworkInterfaceID()), + service.getName().c_str(), service.getType().c_str(), + service.getDomain().c_str(), + &BonjourResolveServiceQuery::handleServiceResolvedStatic, this); + if (result != kDNSServiceErr_NoError) { + sdRef = nullptr; + } + } + catch (...) { + sdRef = nullptr; + } + } - void start() { - if (sdRef) { - run(); - } - else { - eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); - } - } + void start() { + if (sdRef) { + run(); + } + else { + eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); + } + } - void stop() { - finish(); - } + void stop() { + finish(); + } - private: - static void handleServiceResolvedStatic(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord, void *context) { - static_cast<BonjourResolveServiceQuery*>(context)->handleServiceResolved(errorCode, fullname, hosttarget, port, txtLen, txtRecord); - } + private: + static void handleServiceResolvedStatic(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord, void *context) { + static_cast<BonjourResolveServiceQuery*>(context)->handleServiceResolved(errorCode, fullname, hosttarget, port, txtLen, txtRecord); + } - void handleServiceResolved(DNSServiceErrorType errorCode, const char* fullName, const char* host, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord) { - if (errorCode != kDNSServiceErr_NoError) { - eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); - } - else { - //std::cout << "Service resolved: name:" << fullName << " host:" << host << " port:" << port << std::endl; - eventLoop->postEvent( - boost::bind( - boost::ref(onServiceResolved), - Result(std::string(fullName), std::string(host), port, - createByteArray(reinterpret_cast<const char*>(txtRecord), txtLen))), - shared_from_this()); - } - } - }; + void handleServiceResolved(DNSServiceErrorType errorCode, const char* fullName, const char* host, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord) { + if (errorCode != kDNSServiceErr_NoError) { + eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); + } + else { + //std::cout << "Service resolved: name:" << fullName << " host:" << host << " port:" << port << std::endl; + eventLoop->postEvent( + boost::bind( + boost::ref(onServiceResolved), + Result(std::string(fullName), std::string(host), port, + createByteArray(reinterpret_cast<const char*>(txtRecord), txtLen))), + shared_from_this()); + } + } + }; } diff --git a/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.cpp b/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.cpp index 10edb0c..f92a386 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> diff --git a/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h index c2b3be7..f598be1 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Base/boost_bsignals.h> +#include <boost/signals2.hpp> #include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> namespace Swift { - class DNSSDBrowseQuery { - public: - virtual ~DNSSDBrowseQuery(); + class DNSSDBrowseQuery { + public: + virtual ~DNSSDBrowseQuery(); - virtual void startBrowsing() = 0; - virtual void stopBrowsing() = 0; + virtual void startBrowsing() = 0; + virtual void stopBrowsing() = 0; - boost::signal<void (const DNSSDServiceID&)> onServiceAdded; - boost::signal<void (const DNSSDServiceID&)> onServiceRemoved; - boost::signal<void ()> onError; - }; + boost::signals2::signal<void (const DNSSDServiceID&)> onServiceAdded; + boost::signals2::signal<void (const DNSSDServiceID&)> onServiceRemoved; + boost::signals2::signal<void ()> onError; + }; } diff --git a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.cpp b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.cpp index 0f32aa6..e8df884 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> diff --git a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h index e6d548b..3924c05 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h @@ -1,35 +1,35 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <Swiften/Base/ByteArray.h> namespace Swift { - class DNSSDServiceID; - class DNSSDBrowseQuery; - class DNSSDRegisterQuery; - class DNSSDResolveServiceQuery; - class DNSSDResolveHostnameQuery; + class DNSSDServiceID; + class DNSSDBrowseQuery; + class DNSSDRegisterQuery; + class DNSSDResolveServiceQuery; + class DNSSDResolveHostnameQuery; - class DNSSDQuerier { - public: - virtual ~DNSSDQuerier(); + class DNSSDQuerier { + public: + virtual ~DNSSDQuerier(); - virtual void start() = 0; - virtual void stop() = 0; + virtual void start() = 0; + virtual void stop() = 0; - virtual boost::shared_ptr<DNSSDBrowseQuery> createBrowseQuery() = 0; - virtual boost::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( - const std::string& name, int port, const ByteArray& info) = 0; - virtual boost::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( - const DNSSDServiceID&) = 0; - virtual boost::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( - const std::string& hostname, int interfaceIndex) = 0; - }; + virtual std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery() = 0; + virtual std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( + const std::string& name, unsigned short port, const ByteArray& info) = 0; + virtual std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( + const DNSSDServiceID&) = 0; + virtual std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( + const std::string& hostname, int interfaceIndex) = 0; + }; } diff --git a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.cpp b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.cpp index 9a807a4..8274bed 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> diff --git a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h index e794a90..6639a85 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h @@ -1,26 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> +#include <boost/signals2.hpp> -#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> #include <Swiften/Base/ByteArray.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> namespace Swift { - class DNSSDRegisterQuery { - public: - virtual ~DNSSDRegisterQuery(); + class DNSSDRegisterQuery { + public: + virtual ~DNSSDRegisterQuery(); - virtual void registerService() = 0; - virtual void unregisterService() = 0; - virtual void updateServiceInfo(const ByteArray& info) = 0; + virtual void registerService() = 0; + virtual void unregisterService() = 0; + virtual void updateServiceInfo(const ByteArray& info) = 0; - boost::signal<void (boost::optional<DNSSDServiceID>)> onRegisterFinished; - }; + boost::signals2::signal<void (boost::optional<DNSSDServiceID>)> onRegisterFinished; + }; } diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.cpp b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.cpp index dd34e3d..b8b79ac 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h index ee8ffb9..f14c248 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h @@ -1,24 +1,24 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> +#include <boost/signals2.hpp> #include <Swiften/Network/HostAddress.h> namespace Swift { - class DNSSDResolveHostnameQuery { - public: - virtual ~DNSSDResolveHostnameQuery(); + class DNSSDResolveHostnameQuery { + public: + virtual ~DNSSDResolveHostnameQuery(); - virtual void run() = 0; - virtual void finish() = 0; + virtual void run() = 0; + virtual void finish() = 0; - boost::signal<void (const boost::optional<HostAddress>&)> onHostnameResolved; - }; + boost::signals2::signal<void (const boost::optional<HostAddress>&)> onHostnameResolved; + }; } diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.cpp b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.cpp index feb1712..060de7d 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h index c8d78aa..6416d69 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> +#include <boost/signals2.hpp> -#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> #include <Swiften/Base/ByteArray.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> namespace Swift { - class DNSSDResolveServiceQuery { - public: - struct Result { - Result(const std::string& fullName, const std::string& host, int port, const ByteArray& info) : - fullName(fullName), host(host), port(port), info(info) {} - std::string fullName; - std::string host; - int port; - ByteArray info; - }; + class DNSSDResolveServiceQuery { + public: + struct Result { + Result(const std::string& fullName, const std::string& host, unsigned short port, const ByteArray& info) : + fullName(fullName), host(host), port(port), info(info) {} + std::string fullName; + std::string host; + unsigned short port; + ByteArray info; + }; - virtual ~DNSSDResolveServiceQuery(); + virtual ~DNSSDResolveServiceQuery(); - virtual void start() = 0; - virtual void stop() = 0; + virtual void start() = 0; + virtual void stop() = 0; - boost::signal<void (const boost::optional<Result>&)> onServiceResolved; - }; + boost::signals2::signal<void (const boost::optional<Result>&)> onServiceResolved; + }; } diff --git a/Swiften/LinkLocal/DNSSD/DNSSDServiceID.cpp b/Swiften/LinkLocal/DNSSD/DNSSDServiceID.cpp index 2f2784c..38d14c1 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDServiceID.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDServiceID.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> diff --git a/Swiften/LinkLocal/DNSSD/DNSSDServiceID.h b/Swiften/LinkLocal/DNSSD/DNSSDServiceID.h index 6c36de0..5f8c2eb 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDServiceID.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDServiceID.h @@ -1,73 +1,74 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Base/API.h> #include <string> +#include <Swiften/Base/API.h> + namespace Swift { - class SWIFTEN_API DNSSDServiceID { - public: - static const char* PresenceServiceType; + class SWIFTEN_API DNSSDServiceID { + public: + static const char* PresenceServiceType; - DNSSDServiceID( - const std::string& name, - const std::string& domain, - const std::string& type = PresenceServiceType, - int networkInterface = -1) : - name(name), - domain(domain), - type(type), - networkInterface(networkInterface) { - } + DNSSDServiceID( + const std::string& name, + const std::string& domain, + const std::string& type = PresenceServiceType, + int networkInterface = -1) : + name(name), + domain(domain), + type(type), + networkInterface(networkInterface) { + } - bool operator==(const DNSSDServiceID& o) const { - return name == o.name && domain == o.domain && type == o.type && (networkInterface != 0 && o.networkInterface != 0 ? networkInterface == o.networkInterface : true); - } + bool operator==(const DNSSDServiceID& o) const { + return name == o.name && domain == o.domain && type == o.type && (networkInterface != 0 && o.networkInterface != 0 ? networkInterface == o.networkInterface : true); + } - bool operator<(const DNSSDServiceID& o) const { - if (o.name == name) { - if (o.domain == domain) { - if (o.type == type) { - return networkInterface < o.networkInterface; - } - else { - return type < o.type; - } - } - else { - return domain < o.domain; - } - } - else { - return o.name < name; - } - } + bool operator<(const DNSSDServiceID& o) const { + if (o.name == name) { + if (o.domain == domain) { + if (o.type == type) { + return networkInterface < o.networkInterface; + } + else { + return type < o.type; + } + } + else { + return domain < o.domain; + } + } + else { + return o.name < name; + } + } - const std::string& getName() const { - return name; - } + const std::string& getName() const { + return name; + } - const std::string& getDomain() const { - return domain; - } + const std::string& getDomain() const { + return domain; + } - const std::string& getType() const { - return type; - } + const std::string& getType() const { + return type; + } - int getNetworkInterfaceID() const { - return networkInterface; - } + int getNetworkInterfaceID() const { + return networkInterface; + } - private: - std::string name; - std::string domain; - std::string type; - int networkInterface; - }; + private: + std::string name; + std::string domain; + std::string type; + int networkInterface; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h index b2a6d61..15d8128 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h @@ -1,28 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> #include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> namespace Swift { - class FakeDNSSDQuerier; + class FakeDNSSDQuerier; - class FakeDNSSDBrowseQuery : public DNSSDBrowseQuery, public FakeDNSSDQuery { - public: - FakeDNSSDBrowseQuery(boost::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier) { - } + class FakeDNSSDBrowseQuery : public DNSSDBrowseQuery, public FakeDNSSDQuery { + public: + FakeDNSSDBrowseQuery(std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier) { + } - void startBrowsing() { - run(); - } + void startBrowsing() { + run(); + } - void stopBrowsing() { - finish(); - } - }; + void stopBrowsing() { + finish(); + } + }; } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp index 1ddeffa..3381a26 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h> -#include <boost/bind.hpp> #include <iostream> -#include <Swiften/Base/foreach.h> +#include <boost/bind.hpp> + #include <Swiften/Base/Algorithm.h> +#include <Swiften/EventLoop/EventLoop.h> #include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h> #include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h> -#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h> #include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h> -#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h> namespace Swift { @@ -23,117 +23,117 @@ FakeDNSSDQuerier::FakeDNSSDQuerier(const std::string& domain, EventLoop* eventLo } FakeDNSSDQuerier::~FakeDNSSDQuerier() { - if (!runningQueries.empty()) { - std::cerr << "FakeDNSSDQuerier: Running queries not empty at destruction time" << std::endl; - } + if (!runningQueries.empty()) { + std::cerr << "FakeDNSSDQuerier: Running queries not empty at destruction time" << std::endl; + } } -boost::shared_ptr<DNSSDBrowseQuery> FakeDNSSDQuerier::createBrowseQuery() { - return boost::shared_ptr<DNSSDBrowseQuery>(new FakeDNSSDBrowseQuery(shared_from_this())); +std::shared_ptr<DNSSDBrowseQuery> FakeDNSSDQuerier::createBrowseQuery() { + return std::make_shared<FakeDNSSDBrowseQuery>(shared_from_this()); } -boost::shared_ptr<DNSSDRegisterQuery> FakeDNSSDQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { - return boost::shared_ptr<DNSSDRegisterQuery>(new FakeDNSSDRegisterQuery(name, port, info, shared_from_this())); +std::shared_ptr<DNSSDRegisterQuery> FakeDNSSDQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) { + return std::make_shared<FakeDNSSDRegisterQuery>(name, port, info, shared_from_this()); } -boost::shared_ptr<DNSSDResolveServiceQuery> FakeDNSSDQuerier::createResolveServiceQuery(const DNSSDServiceID& service) { - return boost::shared_ptr<DNSSDResolveServiceQuery>(new FakeDNSSDResolveServiceQuery(service, shared_from_this())); +std::shared_ptr<DNSSDResolveServiceQuery> FakeDNSSDQuerier::createResolveServiceQuery(const DNSSDServiceID& service) { + return std::make_shared<FakeDNSSDResolveServiceQuery>(service, shared_from_this()); } -boost::shared_ptr<DNSSDResolveHostnameQuery> FakeDNSSDQuerier::createResolveHostnameQuery(const std::string& hostname, int interfaceIndex) { - return boost::shared_ptr<DNSSDResolveHostnameQuery>(new FakeDNSSDResolveHostnameQuery(hostname, interfaceIndex, shared_from_this())); +std::shared_ptr<DNSSDResolveHostnameQuery> FakeDNSSDQuerier::createResolveHostnameQuery(const std::string& hostname, int interfaceIndex) { + return std::make_shared<FakeDNSSDResolveHostnameQuery>(hostname, interfaceIndex, shared_from_this()); } -void FakeDNSSDQuerier::addRunningQuery(boost::shared_ptr<FakeDNSSDQuery> query) { - runningQueries.push_back(query); - allQueriesEverRun.push_back(query); - if (boost::shared_ptr<FakeDNSSDBrowseQuery> browseQuery = boost::dynamic_pointer_cast<FakeDNSSDBrowseQuery>(query)) { - foreach(const DNSSDServiceID& service, services) { - eventLoop->postEvent(boost::bind(boost::ref(browseQuery->onServiceAdded), service), shared_from_this()); - } - } - else if (boost::shared_ptr<FakeDNSSDResolveServiceQuery> resolveQuery = boost::dynamic_pointer_cast<FakeDNSSDResolveServiceQuery>(query)) { - for(ServiceInfoMap::const_iterator i = serviceInfo.begin(); i != serviceInfo.end(); ++i) { - if (i->first == resolveQuery->service) { - eventLoop->postEvent(boost::bind(boost::ref(resolveQuery->onServiceResolved), i->second), shared_from_this()); - } - } - } - else if (boost::shared_ptr<FakeDNSSDRegisterQuery> registerQuery = boost::dynamic_pointer_cast<FakeDNSSDRegisterQuery>(query)) { - DNSSDServiceID service(registerQuery->name, domain); - eventLoop->postEvent(boost::bind(boost::ref(registerQuery->onRegisterFinished), service), shared_from_this()); - } - else if (boost::shared_ptr<FakeDNSSDResolveHostnameQuery> resolveHostnameQuery = boost::dynamic_pointer_cast<FakeDNSSDResolveHostnameQuery>(query)) { - std::map<std::string,boost::optional<HostAddress> >::const_iterator i = addresses.find(resolveHostnameQuery->hostname); - if (i != addresses.end()) { - eventLoop->postEvent( - boost::bind( - boost::ref(resolveHostnameQuery->onHostnameResolved), i->second), - shared_from_this()); - } - } +void FakeDNSSDQuerier::addRunningQuery(std::shared_ptr<FakeDNSSDQuery> query) { + runningQueries.push_back(query); + allQueriesEverRun.push_back(query); + if (std::shared_ptr<FakeDNSSDBrowseQuery> browseQuery = std::dynamic_pointer_cast<FakeDNSSDBrowseQuery>(query)) { + for (const auto& service : services) { + eventLoop->postEvent(boost::bind(boost::ref(browseQuery->onServiceAdded), service), shared_from_this()); + } + } + else if (std::shared_ptr<FakeDNSSDResolveServiceQuery> resolveQuery = std::dynamic_pointer_cast<FakeDNSSDResolveServiceQuery>(query)) { + for (const auto& i : serviceInfo) { + if (i.first == resolveQuery->service) { + eventLoop->postEvent(boost::bind(boost::ref(resolveQuery->onServiceResolved), i.second), shared_from_this()); + } + } + } + else if (std::shared_ptr<FakeDNSSDRegisterQuery> registerQuery = std::dynamic_pointer_cast<FakeDNSSDRegisterQuery>(query)) { + DNSSDServiceID service(registerQuery->name, domain); + eventLoop->postEvent(boost::bind(boost::ref(registerQuery->onRegisterFinished), service), shared_from_this()); + } + else if (std::shared_ptr<FakeDNSSDResolveHostnameQuery> resolveHostnameQuery = std::dynamic_pointer_cast<FakeDNSSDResolveHostnameQuery>(query)) { + std::map<std::string,boost::optional<HostAddress> >::const_iterator i = addresses.find(resolveHostnameQuery->hostname); + if (i != addresses.end()) { + eventLoop->postEvent( + boost::bind( + boost::ref(resolveHostnameQuery->onHostnameResolved), i->second), + shared_from_this()); + } + } } -void FakeDNSSDQuerier::removeRunningQuery(boost::shared_ptr<FakeDNSSDQuery> query) { - erase(runningQueries, query); +void FakeDNSSDQuerier::removeRunningQuery(std::shared_ptr<FakeDNSSDQuery> query) { + erase(runningQueries, query); } void FakeDNSSDQuerier::addService(const DNSSDServiceID& id) { - services.insert(id); - foreach(const boost::shared_ptr<FakeDNSSDBrowseQuery>& query, getQueries<FakeDNSSDBrowseQuery>()) { - eventLoop->postEvent(boost::bind(boost::ref(query->onServiceAdded), id), shared_from_this()); - } + services.insert(id); + for (const auto& query : getQueries<FakeDNSSDBrowseQuery>()) { + eventLoop->postEvent(boost::bind(boost::ref(query->onServiceAdded), id), shared_from_this()); + } } void FakeDNSSDQuerier::removeService(const DNSSDServiceID& id) { - services.erase(id); - serviceInfo.erase(id); - foreach(const boost::shared_ptr<FakeDNSSDBrowseQuery>& query, getQueries<FakeDNSSDBrowseQuery>()) { - eventLoop->postEvent(boost::bind(boost::ref(query->onServiceRemoved), id), shared_from_this()); - } + services.erase(id); + serviceInfo.erase(id); + for (const auto& query : getQueries<FakeDNSSDBrowseQuery>()) { + eventLoop->postEvent(boost::bind(boost::ref(query->onServiceRemoved), id), shared_from_this()); + } } void FakeDNSSDQuerier::setServiceInfo(const DNSSDServiceID& id, const DNSSDResolveServiceQuery::Result& info) { - std::pair<ServiceInfoMap::iterator, bool> r = serviceInfo.insert(std::make_pair(id, info)); - if (!r.second) { - r.first->second = info; - } - foreach(const boost::shared_ptr<FakeDNSSDResolveServiceQuery>& query, getQueries<FakeDNSSDResolveServiceQuery>()) { - if (query->service == id) { - eventLoop->postEvent(boost::bind(boost::ref(query->onServiceResolved), info), shared_from_this()); - } - } -} - -bool FakeDNSSDQuerier::isServiceRegistered(const std::string& name, int port, const ByteArray& info) { - foreach(const boost::shared_ptr<FakeDNSSDRegisterQuery>& query, getQueries<FakeDNSSDRegisterQuery>()) { - if (query->name == name && query->port == port && query->info == info) { - return true; - } - } - return false; + std::pair<ServiceInfoMap::iterator, bool> r = serviceInfo.insert(std::make_pair(id, info)); + if (!r.second) { + r.first->second = info; + } + for (const auto& query : getQueries<FakeDNSSDResolveServiceQuery>()) { + if (query->service == id) { + eventLoop->postEvent(boost::bind(boost::ref(query->onServiceResolved), info), shared_from_this()); + } + } +} + +bool FakeDNSSDQuerier::isServiceRegistered(const std::string& name, unsigned short port, const ByteArray& info) { + for (const auto& query : getQueries<FakeDNSSDRegisterQuery>()) { + if (query->name == name && query->port == port && query->info == info) { + return true; + } + } + return false; } void FakeDNSSDQuerier::setBrowseError() { - foreach(const boost::shared_ptr<FakeDNSSDBrowseQuery>& query, getQueries<FakeDNSSDBrowseQuery>()) { - eventLoop->postEvent(boost::ref(query->onError), shared_from_this()); - } + for (const auto& query : getQueries<FakeDNSSDBrowseQuery>()) { + eventLoop->postEvent(boost::ref(query->onError), shared_from_this()); + } } void FakeDNSSDQuerier::setRegisterError() { - foreach(const boost::shared_ptr<FakeDNSSDRegisterQuery>& query, getQueries<FakeDNSSDRegisterQuery>()) { - eventLoop->postEvent(boost::bind(boost::ref(query->onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } + for (const auto& query : getQueries<FakeDNSSDRegisterQuery>()) { + eventLoop->postEvent(boost::bind(boost::ref(query->onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } } void FakeDNSSDQuerier::setAddress(const std::string& hostname, boost::optional<HostAddress> address) { - addresses[hostname] = address; - foreach(const boost::shared_ptr<FakeDNSSDResolveHostnameQuery>& query, getQueries<FakeDNSSDResolveHostnameQuery>()) { - if (query->hostname == hostname) { - eventLoop->postEvent(boost::bind( - boost::ref(query->onHostnameResolved), address), shared_from_this()); - } - } + addresses[hostname] = address; + for (const auto& query : getQueries<FakeDNSSDResolveHostnameQuery>()) { + if (query->hostname == hostname) { + eventLoop->postEvent(boost::bind( + boost::ref(query->onHostnameResolved), address), shared_from_this()); + } + } } } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h index 9fc4608..07cb75c 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h @@ -1,17 +1,16 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> #include <list> +#include <memory> #include <set> - #include <string> + #include <Swiften/Base/API.h> #include <Swiften/Base/ByteArray.h> #include <Swiften/EventLoop/EventOwner.h> @@ -20,78 +19,77 @@ #include <Swiften/Network/HostAddress.h> namespace Swift { - class FakeDNSSDQuery; - class FakeDNSSDBrowseQuery; - class EventLoop; + class FakeDNSSDQuery; + class EventLoop; - class SWIFTEN_API FakeDNSSDQuerier : - public DNSSDQuerier, - public EventOwner, - public boost::enable_shared_from_this<FakeDNSSDQuerier> { - public: - FakeDNSSDQuerier(const std::string& domain, EventLoop* eventLoop); - ~FakeDNSSDQuerier(); + class SWIFTEN_API FakeDNSSDQuerier : + public DNSSDQuerier, + public EventOwner, + public std::enable_shared_from_this<FakeDNSSDQuerier> { + public: + FakeDNSSDQuerier(const std::string& domain, EventLoop* eventLoop); + ~FakeDNSSDQuerier(); - void start() {} - void stop() {} + void start() {} + void stop() {} - void clearAllQueriesEverRun() { - allQueriesEverRun.clear(); - } + void clearAllQueriesEverRun() { + allQueriesEverRun.clear(); + } - boost::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); - boost::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( - const std::string& name, int port, const ByteArray& info); - boost::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( - const DNSSDServiceID&); - boost::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( - const std::string& hostname, int interfaceIndex); + std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); + std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( + const std::string& name, unsigned short port, const ByteArray& info); + std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( + const DNSSDServiceID&); + std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( + const std::string& hostname, int interfaceIndex); - void addRunningQuery(boost::shared_ptr<FakeDNSSDQuery>); - void removeRunningQuery(boost::shared_ptr<FakeDNSSDQuery>); + void addRunningQuery(std::shared_ptr<FakeDNSSDQuery>); + void removeRunningQuery(std::shared_ptr<FakeDNSSDQuery>); - void addService(const DNSSDServiceID& id); - void removeService(const DNSSDServiceID& id); - void setServiceInfo(const DNSSDServiceID& id, const DNSSDResolveServiceQuery::Result& info); - bool isServiceRegistered(const std::string& name, int port, const ByteArray& info); - void setAddress(const std::string& hostname, boost::optional<HostAddress> address); + void addService(const DNSSDServiceID& id); + void removeService(const DNSSDServiceID& id); + void setServiceInfo(const DNSSDServiceID& id, const DNSSDResolveServiceQuery::Result& info); + bool isServiceRegistered(const std::string& name, unsigned short port, const ByteArray& info); + void setAddress(const std::string& hostname, boost::optional<HostAddress> address); - void setBrowseError(); - void setRegisterError(); + void setBrowseError(); + void setRegisterError(); - public: - template<typename T> - std::vector< boost::shared_ptr<T> > getAllQueriesEverRun() const { - std::vector< boost::shared_ptr<T> > result; - for (QueryList::const_iterator i = allQueriesEverRun.begin(); i != allQueriesEverRun.end(); ++i) { - if (boost::shared_ptr<T> resultQuery = boost::dynamic_pointer_cast<T>(*i)) { - result.push_back(resultQuery); - } - } - return result; - } + public: + template<typename T> + std::vector< std::shared_ptr<T> > getAllQueriesEverRun() const { + std::vector< std::shared_ptr<T> > result; + for (const auto& i : allQueriesEverRun) { + if (std::shared_ptr<T> resultQuery = std::dynamic_pointer_cast<T>(i)) { + result.push_back(resultQuery); + } + } + return result; + } - private: - template<typename T> - std::vector< boost::shared_ptr<T> > getQueries() const { - std::vector< boost::shared_ptr<T> > result; - for (QueryList::const_iterator i = runningQueries.begin(); i != runningQueries.end(); ++i) { - if (boost::shared_ptr<T> resultQuery = boost::dynamic_pointer_cast<T>(*i)) { - result.push_back(resultQuery); - } - } - return result; - } + private: + template<typename T> + std::vector< std::shared_ptr<T> > getQueries() const { + std::vector< std::shared_ptr<T> > result; + for (const auto& runningQuerie : runningQueries) { + if (std::shared_ptr<T> resultQuery = std::dynamic_pointer_cast<T>(runningQuerie)) { + result.push_back(resultQuery); + } + } + return result; + } - private: - std::string domain; - EventLoop* eventLoop; - typedef std::list< boost::shared_ptr<FakeDNSSDQuery> > QueryList; - QueryList runningQueries; - QueryList allQueriesEverRun; - std::set<DNSSDServiceID> services; - typedef std::map<DNSSDServiceID,DNSSDResolveServiceQuery::Result> ServiceInfoMap; - ServiceInfoMap serviceInfo; - std::map<std::string, boost::optional<HostAddress> > addresses; - }; + private: + std::string domain; + EventLoop* eventLoop; + typedef std::list< std::shared_ptr<FakeDNSSDQuery> > QueryList; + QueryList runningQueries; + QueryList allQueriesEverRun; + std::set<DNSSDServiceID> services; + typedef std::map<DNSSDServiceID,DNSSDResolveServiceQuery::Result> ServiceInfoMap; + ServiceInfoMap serviceInfo; + std::map<std::string, boost::optional<HostAddress> > addresses; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.cpp b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.cpp index 99f55fa..0e05968 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.cpp @@ -1,26 +1,27 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> + #include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h> namespace Swift { -FakeDNSSDQuery::FakeDNSSDQuery(boost::shared_ptr<FakeDNSSDQuerier> querier) : querier(querier) { +FakeDNSSDQuery::FakeDNSSDQuery(std::shared_ptr<FakeDNSSDQuerier> querier) : querier(querier) { } FakeDNSSDQuery::~FakeDNSSDQuery() { } void FakeDNSSDQuery::run() { - querier->addRunningQuery(shared_from_this()); + querier->addRunningQuery(shared_from_this()); } void FakeDNSSDQuery::finish() { - querier->removeRunningQuery(shared_from_this()); + querier->removeRunningQuery(shared_from_this()); } } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h index b6d5c98..5d869d4 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h @@ -1,31 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> +#include <memory> #include <Swiften/EventLoop/EventOwner.h> namespace Swift { - class FakeDNSSDQuerier; + class FakeDNSSDQuerier; - class FakeDNSSDQuery : - public EventOwner, - public boost::enable_shared_from_this<FakeDNSSDQuery> { - public: - FakeDNSSDQuery(boost::shared_ptr<FakeDNSSDQuerier>); - virtual ~FakeDNSSDQuery(); - - protected: - void run(); - void finish(); - - protected: - boost::shared_ptr<FakeDNSSDQuerier> querier; - }; + class FakeDNSSDQuery : + public EventOwner, + public std::enable_shared_from_this<FakeDNSSDQuery> { + public: + FakeDNSSDQuery(std::shared_ptr<FakeDNSSDQuerier>); + virtual ~FakeDNSSDQuery(); + + protected: + void run(); + void finish(); + + protected: + std::shared_ptr<FakeDNSSDQuerier> querier; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h index c568f5b..ee6bb92 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h @@ -1,38 +1,39 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> -#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> -#include <Swiften/Base/ByteArray.h> #include <string> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> + namespace Swift { - class FakeDNSSDQuerier; + class FakeDNSSDQuerier; - class FakeDNSSDRegisterQuery : public DNSSDRegisterQuery, public FakeDNSSDQuery { - public: - FakeDNSSDRegisterQuery(const std::string& name, int port, const ByteArray& info, boost::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) { - } + class FakeDNSSDRegisterQuery : public DNSSDRegisterQuery, public FakeDNSSDQuery { + public: + FakeDNSSDRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) { + } - void registerService() { - run(); - } + void registerService() { + run(); + } - void updateServiceInfo(const ByteArray& i) { - info = i; - } + void updateServiceInfo(const ByteArray& i) { + info = i; + } - void unregisterService() { - finish(); - } + void unregisterService() { + finish(); + } - std::string name; - int port; - ByteArray info; - }; + std::string name; + unsigned short port; + ByteArray info; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h index aa427cc..60dc144 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h @@ -1,33 +1,34 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <string> -#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> + #include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> #include <Swiften/Network/HostAddress.h> namespace Swift { - class FakeDNSSDQuerier; + class FakeDNSSDQuerier; - class FakeDNSSDResolveHostnameQuery : public DNSSDResolveHostnameQuery, public FakeDNSSDQuery { - public: - FakeDNSSDResolveHostnameQuery(const std::string& hostname, int interfaceIndex, boost::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), hostname(hostname), interfaceIndex(interfaceIndex) { - } + class FakeDNSSDResolveHostnameQuery : public DNSSDResolveHostnameQuery, public FakeDNSSDQuery { + public: + FakeDNSSDResolveHostnameQuery(const std::string& hostname, int interfaceIndex, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), hostname(hostname), interfaceIndex(interfaceIndex) { + } - void run() { - FakeDNSSDQuery::run(); - } + void run() { + FakeDNSSDQuery::run(); + } - void finish() { - FakeDNSSDQuery::finish(); - } + void finish() { + FakeDNSSDQuery::finish(); + } - std::string hostname; - int interfaceIndex; - }; + std::string hostname; + int interfaceIndex; + }; } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h index 5c69843..8a02e7b 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h @@ -1,31 +1,31 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> #include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> #include <Swiften/LinkLocal/LinkLocalServiceInfo.h> namespace Swift { - class FakeDNSSDQuerier; + class FakeDNSSDQuerier; - class FakeDNSSDResolveServiceQuery : public DNSSDResolveServiceQuery, public FakeDNSSDQuery { - public: - FakeDNSSDResolveServiceQuery(const DNSSDServiceID& service, boost::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), service(service) { - } + class FakeDNSSDResolveServiceQuery : public DNSSDResolveServiceQuery, public FakeDNSSDQuery { + public: + FakeDNSSDResolveServiceQuery(const DNSSDServiceID& service, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), service(service) { + } - void start() { - run(); - } + void start() { + run(); + } - void stop() { - finish(); - } + void stop() { + finish(); + } - DNSSDServiceID service; - }; + DNSSDServiceID service; + }; } diff --git a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp index cc12573..e20326b 100644 --- a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp +++ b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h> @@ -18,21 +18,22 @@ namespace Swift { PlatformDNSSDQuerierFactory::PlatformDNSSDQuerierFactory(EventLoop* eventLoop) : eventLoop(eventLoop) { } -boost::shared_ptr<DNSSDQuerier> PlatformDNSSDQuerierFactory::createQuerier() { +std::shared_ptr<DNSSDQuerier> PlatformDNSSDQuerierFactory::createQuerier() { #if defined(HAVE_BONJOUR) - return boost::shared_ptr<DNSSDQuerier>(new BonjourQuerier(eventLoop)); + return std::make_shared<BonjourQuerier>(eventLoop); #elif defined(HAVE_AVAHI) - return boost::shared_ptr<DNSSDQuerier>(new AvahiQuerier(eventLoop)); + return std::make_shared<AvahiQuerier>(eventLoop); #else - return boost::shared_ptr<DNSSDQuerier>(); + (void)eventLoop; + return std::shared_ptr<DNSSDQuerier>(); #endif } bool PlatformDNSSDQuerierFactory::canCreate() { #if defined(HAVE_BONJOUR) || defined(HAVE_AVAHI) - return true; + return true; #else - return false; + return false; #endif } diff --git a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h index 2eb21ed..68e10cf 100644 --- a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h +++ b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h @@ -1,28 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <Swiften/Base/API.h> namespace Swift { - class DNSSDQuerier; - class EventLoop; + class DNSSDQuerier; + class EventLoop; - class SWIFTEN_API PlatformDNSSDQuerierFactory { - public: - PlatformDNSSDQuerierFactory(EventLoop* eventLoop); + class SWIFTEN_API PlatformDNSSDQuerierFactory { + public: + PlatformDNSSDQuerierFactory(EventLoop* eventLoop); - boost::shared_ptr<DNSSDQuerier> createQuerier(); + std::shared_ptr<DNSSDQuerier> createQuerier(); - bool canCreate(); + bool canCreate(); - private: - EventLoop* eventLoop; - }; + private: + EventLoop* eventLoop; + }; } |