diff options
| -rw-r--r-- | Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp | 10 | ||||
| -rw-r--r-- | Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h | 17 | ||||
| -rw-r--r-- | Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h | 17 | ||||
| -rw-r--r-- | Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h | 19 | ||||
| -rw-r--r-- | Swiften/LinkLocal/LinkLocalServiceBrowser.cpp | 22 | ||||
| -rw-r--r-- | Swiften/LinkLocal/LinkLocalServiceInfo.cpp | 65 | ||||
| -rw-r--r-- | Swiften/LinkLocal/LinkLocalServiceInfo.h | 2 | ||||
| -rw-r--r-- | Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp | 4 | ||||
| -rw-r--r-- | Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp | 26 | ||||
| -rw-r--r-- | Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp | 17 | ||||
| -rw-r--r-- | Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp | 6 | ||||
| -rw-r--r-- | Swiften/QA/DNSSDTest/DNSSDTest.cpp | 8 | ||||
| -rw-r--r-- | Swiften/QA/DNSSDTest/SConscript | 2 |
13 files changed, 140 insertions, 75 deletions
diff --git a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp index c8e7700..b1a51c9 100644 --- a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp +++ b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -225,7 +225,9 @@ class LinkLocalPresenceManagerTest : public CppUnit::TestFixture { | |||
| 225 | info.setFirstName(firstName); | 225 | info.setFirstName(firstName); |
| 226 | info.setLastName(lastName); | 226 | info.setLastName(lastName); |
| 227 | info.setNick(nickName); | 227 | info.setNick(nickName); |
| 228 | querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord())); | 228 | auto txtRecord = info.toTXTRecord(); |
| 229 | CPPUNIT_ASSERT(txtRecord); | ||
| 230 | querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, *txtRecord)); | ||
| 229 | querier->addService(service); | 231 | querier->addService(service); |
| 230 | eventLoop->processEvents(); | 232 | eventLoop->processEvents(); |
| 231 | } | 233 | } |
| @@ -241,7 +243,9 @@ class LinkLocalPresenceManagerTest : public CppUnit::TestFixture { | |||
| 241 | LinkLocalServiceInfo info; | 243 | LinkLocalServiceInfo info; |
| 242 | info.setStatus(status); | 244 | info.setStatus(status); |
| 243 | info.setMessage(message); | 245 | info.setMessage(message); |
| 244 | querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord())); | 246 | auto txtRecord = info.toTXTRecord(); |
| 247 | CPPUNIT_ASSERT(txtRecord); | ||
| 248 | querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, *txtRecord)); | ||
| 245 | eventLoop->processEvents(); | 249 | eventLoop->processEvents(); |
| 246 | } | 250 | } |
| 247 | 251 | ||
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h index c049ed2..63f34db 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -50,12 +50,17 @@ namespace Swift { | |||
| 50 | } | 50 | } |
| 51 | else { | 51 | else { |
| 52 | //std::cout << "Discovered service: name:" << name << " domain:" << domain << " type: " << type << std::endl; | 52 | //std::cout << "Discovered service: name:" << name << " domain:" << domain << " type: " << type << std::endl; |
| 53 | DNSSDServiceID service(name, domain, type, boost::numeric_cast<int>(interfaceIndex)); | 53 | try { |
| 54 | if (flags & kDNSServiceFlagsAdd) { | 54 | DNSSDServiceID service(name, domain, type, boost::numeric_cast<int>(interfaceIndex)); |
| 55 | eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); | 55 | if (flags & kDNSServiceFlagsAdd) { |
| 56 | eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); | ||
| 57 | } | ||
| 58 | else { | ||
| 59 | eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); | ||
| 60 | } | ||
| 56 | } | 61 | } |
| 57 | else { | 62 | catch (...) { |
| 58 | eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); | 63 | eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); |
| 59 | } | 64 | } |
| 60 | } | 65 | } |
| 61 | } | 66 | } |
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h index dbf3f0e..61f000e 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -23,11 +23,16 @@ namespace Swift { | |||
| 23 | class BonjourResolveHostnameQuery : public DNSSDResolveHostnameQuery, public BonjourQuery { | 23 | class BonjourResolveHostnameQuery : public DNSSDResolveHostnameQuery, public BonjourQuery { |
| 24 | public: | 24 | public: |
| 25 | BonjourResolveHostnameQuery(const std::string& hostname, int interfaceIndex, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { | 25 | BonjourResolveHostnameQuery(const std::string& hostname, int interfaceIndex, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { |
| 26 | DNSServiceErrorType result = DNSServiceGetAddrInfo( | 26 | try { |
| 27 | &sdRef, 0, boost::numeric_cast<unsigned int>(interfaceIndex), kDNSServiceProtocol_IPv4, | 27 | DNSServiceErrorType result = DNSServiceGetAddrInfo( |
| 28 | hostname.c_str(), | 28 | &sdRef, 0, boost::numeric_cast<unsigned int>(interfaceIndex), kDNSServiceProtocol_IPv4, |
| 29 | &BonjourResolveHostnameQuery::handleHostnameResolvedStatic, this); | 29 | hostname.c_str(), |
| 30 | if (result != kDNSServiceErr_NoError) { | 30 | &BonjourResolveHostnameQuery::handleHostnameResolvedStatic, this); |
| 31 | if (result != kDNSServiceErr_NoError) { | ||
| 32 | sdRef = nullptr; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | catch (...) { | ||
| 31 | sdRef = nullptr; | 36 | sdRef = nullptr; |
| 32 | } | 37 | } |
| 33 | } | 38 | } |
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h index 7a5555e..4baf87b 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -20,12 +20,17 @@ namespace Swift { | |||
| 20 | class BonjourResolveServiceQuery : public DNSSDResolveServiceQuery, public BonjourQuery { | 20 | class BonjourResolveServiceQuery : public DNSSDResolveServiceQuery, public BonjourQuery { |
| 21 | public: | 21 | public: |
| 22 | BonjourResolveServiceQuery(const DNSSDServiceID& service, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { | 22 | BonjourResolveServiceQuery(const DNSSDServiceID& service, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { |
| 23 | DNSServiceErrorType result = DNSServiceResolve( | 23 | try { |
| 24 | &sdRef, 0, boost::numeric_cast<unsigned int>(service.getNetworkInterfaceID()), | 24 | DNSServiceErrorType result = DNSServiceResolve( |
| 25 | service.getName().c_str(), service.getType().c_str(), | 25 | &sdRef, 0, boost::numeric_cast<unsigned int>(service.getNetworkInterfaceID()), |
| 26 | service.getDomain().c_str(), | 26 | service.getName().c_str(), service.getType().c_str(), |
| 27 | &BonjourResolveServiceQuery::handleServiceResolvedStatic, this); | 27 | service.getDomain().c_str(), |
| 28 | if (result != kDNSServiceErr_NoError) { | 28 | &BonjourResolveServiceQuery::handleServiceResolvedStatic, this); |
| 29 | if (result != kDNSServiceErr_NoError) { | ||
| 30 | sdRef = nullptr; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | catch (...) { | ||
| 29 | sdRef = nullptr; | 34 | sdRef = nullptr; |
| 30 | } | 35 | } |
| 31 | } | 36 | } |
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp index b3328cd..0498384 100644 --- a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp +++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp | |||
| @@ -67,15 +67,27 @@ bool LinkLocalServiceBrowser::isRegistered() const { | |||
| 67 | 67 | ||
| 68 | void LinkLocalServiceBrowser::registerService(const std::string& name, unsigned short port, const LinkLocalServiceInfo& info) { | 68 | void LinkLocalServiceBrowser::registerService(const std::string& name, unsigned short port, const LinkLocalServiceInfo& info) { |
| 69 | assert(!registerQuery); | 69 | assert(!registerQuery); |
| 70 | registerQuery = querier->createRegisterQuery(name, port, info.toTXTRecord()); | 70 | if (auto txtRecord = info.toTXTRecord()) { |
| 71 | registerQuery->onRegisterFinished.connect( | 71 | registerQuery = querier->createRegisterQuery(name, port, *txtRecord); |
| 72 | boost::bind(&LinkLocalServiceBrowser::handleRegisterFinished, this, _1)); | 72 | registerQuery->onRegisterFinished.connect( |
| 73 | registerQuery->registerService(); | 73 | boost::bind(&LinkLocalServiceBrowser::handleRegisterFinished, this, _1)); |
| 74 | registerQuery->registerService(); | ||
| 75 | } | ||
| 76 | else { | ||
| 77 | haveError = true; | ||
| 78 | stop(); | ||
| 79 | } | ||
| 74 | } | 80 | } |
| 75 | 81 | ||
| 76 | void LinkLocalServiceBrowser::updateService(const LinkLocalServiceInfo& info) { | 82 | void LinkLocalServiceBrowser::updateService(const LinkLocalServiceInfo& info) { |
| 77 | assert(registerQuery); | 83 | assert(registerQuery); |
| 78 | registerQuery->updateServiceInfo(info.toTXTRecord()); | 84 | if (auto txtRecord = info.toTXTRecord()) { |
| 85 | registerQuery->updateServiceInfo(*txtRecord); | ||
| 86 | } | ||
| 87 | else { | ||
| 88 | haveError = true; | ||
| 89 | stop(); | ||
| 90 | } | ||
| 79 | } | 91 | } |
| 80 | 92 | ||
| 81 | void LinkLocalServiceBrowser::unregisterService() { | 93 | void LinkLocalServiceBrowser::unregisterService() { |
diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp index 102b7f3..914fab4 100644 --- a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp +++ b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp | |||
| @@ -11,40 +11,47 @@ | |||
| 11 | 11 | ||
| 12 | #include <Swiften/Base/Algorithm.h> | 12 | #include <Swiften/Base/Algorithm.h> |
| 13 | #include <Swiften/Base/Concat.h> | 13 | #include <Swiften/Base/Concat.h> |
| 14 | #include <Swiften/Base/Log.h> | ||
| 14 | 15 | ||
| 15 | namespace Swift { | 16 | namespace Swift { |
| 16 | 17 | ||
| 17 | ByteArray LinkLocalServiceInfo::toTXTRecord() const { | 18 | boost::optional<ByteArray> LinkLocalServiceInfo::toTXTRecord() const { |
| 18 | ByteArray result(getEncoded("txtvers=1")); | 19 | try { |
| 19 | if (!firstName.empty()) { | 20 | ByteArray result(getEncoded("txtvers=1")); |
| 20 | append(result, getEncoded("1st=" + firstName)); | 21 | if (!firstName.empty()) { |
| 21 | } | 22 | append(result, getEncoded("1st=" + firstName)); |
| 22 | if (!lastName.empty()) { | 23 | } |
| 23 | append(result, getEncoded("last=" + lastName)); | 24 | if (!lastName.empty()) { |
| 24 | } | 25 | append(result, getEncoded("last=" + lastName)); |
| 25 | if (!email.empty()) { | 26 | } |
| 26 | append(result, getEncoded("email=" + email)); | 27 | if (!email.empty()) { |
| 27 | } | 28 | append(result, getEncoded("email=" + email)); |
| 28 | if (jid.isValid()) { | 29 | } |
| 29 | append(result, getEncoded("jid=" + jid.toString())); | 30 | if (jid.isValid()) { |
| 30 | } | 31 | append(result, getEncoded("jid=" + jid.toString())); |
| 31 | if (!message.empty()) { | 32 | } |
| 32 | append(result, getEncoded("msg=" + message)); | 33 | if (!message.empty()) { |
| 33 | } | 34 | append(result, getEncoded("msg=" + message)); |
| 34 | if (!nick.empty()) { | 35 | } |
| 35 | append(result, getEncoded("nick=" + nick)); | 36 | if (!nick.empty()) { |
| 36 | } | 37 | append(result, getEncoded("nick=" + nick)); |
| 37 | if (port) { | 38 | } |
| 38 | append(result, getEncoded("port.p2pj=" + std::string(std::to_string(*port)))); | 39 | if (port) { |
| 39 | } | 40 | append(result, getEncoded("port.p2pj=" + std::string(std::to_string(*port)))); |
| 41 | } | ||
| 40 | 42 | ||
| 41 | switch (status) { | 43 | switch (status) { |
| 42 | case Available: append(result, getEncoded("status=avail")); break; | 44 | case Available: append(result, getEncoded("status=avail")); break; |
| 43 | case Away: append(result, getEncoded("status=away")); break; | 45 | case Away: append(result, getEncoded("status=away")); break; |
| 44 | case DND: append(result, getEncoded("status=dnd")); break; | 46 | case DND: append(result, getEncoded("status=dnd")); break; |
| 45 | } | 47 | } |
| 46 | 48 | ||
| 47 | return result; | 49 | return result; |
| 50 | } | ||
| 51 | catch (const std::exception& e) { | ||
| 52 | SWIFT_LOG(warning) << "Failed to create TXT record for link local service info: " << e.what() << std::endl; | ||
| 53 | return boost::none; | ||
| 54 | } | ||
| 48 | } | 55 | } |
| 49 | 56 | ||
| 50 | ByteArray LinkLocalServiceInfo::getEncoded(const std::string& s) { | 57 | ByteArray LinkLocalServiceInfo::getEncoded(const std::string& s) { |
diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.h b/Swiften/LinkLocal/LinkLocalServiceInfo.h index eb65706..adfd062 100644 --- a/Swiften/LinkLocal/LinkLocalServiceInfo.h +++ b/Swiften/LinkLocal/LinkLocalServiceInfo.h | |||
| @@ -46,7 +46,7 @@ namespace Swift { | |||
| 46 | boost::optional<unsigned short> getPort() const { return port; } | 46 | boost::optional<unsigned short> getPort() const { return port; } |
| 47 | void setPort(unsigned short p) { port = p; } | 47 | void setPort(unsigned short p) { port = p; } |
| 48 | 48 | ||
| 49 | ByteArray toTXTRecord() const; | 49 | boost::optional<ByteArray> toTXTRecord() const; |
| 50 | 50 | ||
| 51 | static LinkLocalServiceInfo createFromTXTRecord(const ByteArray& record); | 51 | static LinkLocalServiceInfo createFromTXTRecord(const ByteArray& record); |
| 52 | 52 | ||
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp index ab1ee0c..59cf996 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp | |||
| @@ -115,11 +115,13 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture { | |||
| 115 | 115 | ||
| 116 | private: | 116 | private: |
| 117 | std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, unsigned short port) { | 117 | std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, unsigned short port) { |
| 118 | auto txtRecord = LinkLocalServiceInfo().toTXTRecord(); | ||
| 119 | CPPUNIT_ASSERT(txtRecord); | ||
| 118 | LinkLocalService service( | 120 | LinkLocalService service( |
| 119 | DNSSDServiceID("myname", "local."), | 121 | DNSSDServiceID("myname", "local."), |
| 120 | DNSSDResolveServiceQuery::Result( | 122 | DNSSDResolveServiceQuery::Result( |
| 121 | "myname._presence._tcp.local", hostname, port, | 123 | "myname._presence._tcp.local", hostname, port, |
| 122 | LinkLocalServiceInfo().toTXTRecord())); | 124 | *txtRecord)); |
| 123 | std::shared_ptr<LinkLocalConnector> result( | 125 | std::shared_ptr<LinkLocalConnector> result( |
| 124 | new LinkLocalConnector(service, querier, connection)); | 126 | new LinkLocalConnector(service, querier, connection)); |
| 125 | result->onConnectFinished.connect( | 127 | result->onConnectFinished.connect( |
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp index a80d748..3491634 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -47,10 +47,12 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture { | |||
| 47 | eventLoop = new DummyEventLoop(); | 47 | eventLoop = new DummyEventLoop(); |
| 48 | querier = std::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop); | 48 | querier = std::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop); |
| 49 | aliceServiceID = new DNSSDServiceID("alice", "wonderland.lit"); | 49 | aliceServiceID = new DNSSDServiceID("alice", "wonderland.lit"); |
| 50 | aliceServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.wonderland.lit", "xmpp.wonderland.lit", 1234, LinkLocalServiceInfo().toTXTRecord()); | 50 | auto txtRecord = LinkLocalServiceInfo().toTXTRecord(); |
| 51 | CPPUNIT_ASSERT(txtRecord); | ||
| 52 | aliceServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.wonderland.lit", "xmpp.wonderland.lit", 1234, *txtRecord); | ||
| 51 | testServiceID = new DNSSDServiceID("foo", "bar.local"); | 53 | testServiceID = new DNSSDServiceID("foo", "bar.local"); |
| 52 | testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, LinkLocalServiceInfo().toTXTRecord()); | 54 | testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, *txtRecord); |
| 53 | testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, LinkLocalServiceInfo().toTXTRecord()); | 55 | testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, *txtRecord); |
| 54 | errorStopReceived = false; | 56 | errorStopReceived = false; |
| 55 | normalStopReceived = false; | 57 | normalStopReceived = false; |
| 56 | } | 58 | } |
| @@ -292,7 +294,9 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture { | |||
| 292 | testling->registerService("foo@bar", 1234, info); | 294 | testling->registerService("foo@bar", 1234, info); |
| 293 | eventLoop->processEvents(); | 295 | eventLoop->processEvents(); |
| 294 | 296 | ||
| 295 | CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord())); | 297 | auto txtRecord = info.toTXTRecord(); |
| 298 | CPPUNIT_ASSERT(txtRecord); | ||
| 299 | CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, *txtRecord)); | ||
| 296 | CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(registeredServices.size())); | 300 | CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(registeredServices.size())); |
| 297 | CPPUNIT_ASSERT(registeredServices[0] == DNSSDServiceID("foo@bar", "wonderland.lit")); | 301 | CPPUNIT_ASSERT(registeredServices[0] == DNSSDServiceID("foo@bar", "wonderland.lit")); |
| 298 | testling->stop(); | 302 | testling->stop(); |
| @@ -311,7 +315,9 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture { | |||
| 311 | CPPUNIT_ASSERT(!testling->isRunning()); | 315 | CPPUNIT_ASSERT(!testling->isRunning()); |
| 312 | CPPUNIT_ASSERT(testling->hasError()); | 316 | CPPUNIT_ASSERT(testling->hasError()); |
| 313 | CPPUNIT_ASSERT(errorStopReceived); | 317 | CPPUNIT_ASSERT(errorStopReceived); |
| 314 | CPPUNIT_ASSERT(!querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord())); | 318 | auto txtRecord = info.toTXTRecord(); |
| 319 | CPPUNIT_ASSERT(txtRecord); | ||
| 320 | CPPUNIT_ASSERT(!querier->isServiceRegistered("foo@bar", 1234, *txtRecord)); | ||
| 315 | } | 321 | } |
| 316 | 322 | ||
| 317 | void testRegisterService_Reregister() { | 323 | void testRegisterService_Reregister() { |
| @@ -329,7 +335,9 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture { | |||
| 329 | testling->registerService("bar@baz", 3456, info); | 335 | testling->registerService("bar@baz", 3456, info); |
| 330 | eventLoop->processEvents(); | 336 | eventLoop->processEvents(); |
| 331 | 337 | ||
| 332 | CPPUNIT_ASSERT(querier->isServiceRegistered("bar@baz", 3456, info.toTXTRecord())); | 338 | auto txtRecord = info.toTXTRecord(); |
| 339 | CPPUNIT_ASSERT(txtRecord); | ||
| 340 | CPPUNIT_ASSERT(querier->isServiceRegistered("bar@baz", 3456, *txtRecord)); | ||
| 333 | 341 | ||
| 334 | testling->stop(); | 342 | testling->stop(); |
| 335 | } | 343 | } |
| @@ -346,7 +354,9 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture { | |||
| 346 | info.setFirstName("Bar"); | 354 | info.setFirstName("Bar"); |
| 347 | testling->updateService(info); | 355 | testling->updateService(info); |
| 348 | 356 | ||
| 349 | CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord())); | 357 | auto txtRecord = info.toTXTRecord(); |
| 358 | CPPUNIT_ASSERT(txtRecord); | ||
| 359 | CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, *txtRecord)); | ||
| 350 | 360 | ||
| 351 | testling->stop(); | 361 | testling->stop(); |
| 352 | } | 362 | } |
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp index 0a94a98..35cb1b4 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -29,7 +29,9 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture { | |||
| 29 | info.setLastName("Tron\xc3\xe7on"); | 29 | info.setLastName("Tron\xc3\xe7on"); |
| 30 | info.setStatus(LinkLocalServiceInfo::Away); | 30 | info.setStatus(LinkLocalServiceInfo::Away); |
| 31 | 31 | ||
| 32 | CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), info.toTXTRecord()); | 32 | auto txtRecord = info.toTXTRecord(); |
| 33 | CPPUNIT_ASSERT(txtRecord); | ||
| 34 | CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), *txtRecord); | ||
| 33 | } | 35 | } |
| 34 | 36 | ||
| 35 | void testCreateFromTXTRecord() { | 37 | void testCreateFromTXTRecord() { |
| @@ -57,7 +59,9 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture { | |||
| 57 | info.setStatus(LinkLocalServiceInfo::DND); | 59 | info.setStatus(LinkLocalServiceInfo::DND); |
| 58 | info.setPort(1234); | 60 | info.setPort(1234); |
| 59 | 61 | ||
| 60 | LinkLocalServiceInfo info2 = LinkLocalServiceInfo::createFromTXTRecord(info.toTXTRecord()); | 62 | auto txtRecord = info.toTXTRecord(); |
| 63 | CPPUNIT_ASSERT(txtRecord); | ||
| 64 | LinkLocalServiceInfo info2 = LinkLocalServiceInfo::createFromTXTRecord(*txtRecord); | ||
| 61 | CPPUNIT_ASSERT_EQUAL(info.getFirstName(), info2.getFirstName()); | 65 | CPPUNIT_ASSERT_EQUAL(info.getFirstName(), info2.getFirstName()); |
| 62 | CPPUNIT_ASSERT_EQUAL(info.getLastName(), info2.getLastName()); | 66 | CPPUNIT_ASSERT_EQUAL(info.getLastName(), info2.getLastName()); |
| 63 | CPPUNIT_ASSERT_EQUAL(info.getEMail(), info2.getEMail()); | 67 | CPPUNIT_ASSERT_EQUAL(info.getEMail(), info2.getEMail()); |
| @@ -67,6 +71,13 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture { | |||
| 67 | CPPUNIT_ASSERT(info.getStatus() == info2.getStatus()); | 71 | CPPUNIT_ASSERT(info.getStatus() == info2.getStatus()); |
| 68 | CPPUNIT_ASSERT(info.getPort() == info2.getPort()); | 72 | CPPUNIT_ASSERT(info.getPort() == info2.getPort()); |
| 69 | } | 73 | } |
| 74 | |||
| 75 | void testToTXTRecordWithInvalidParameter() { | ||
| 76 | LinkLocalServiceInfo info; | ||
| 77 | info.setFirstName(std::string(256, 'x')); | ||
| 78 | auto txtRecord = info.toTXTRecord(); | ||
| 79 | CPPUNIT_ASSERT(!txtRecord); | ||
| 80 | } | ||
| 70 | }; | 81 | }; |
| 71 | 82 | ||
| 72 | CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceInfoTest); | 83 | CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceInfoTest); |
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp index 206d824..cb5f40a 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -58,10 +58,12 @@ class LinkLocalServiceTest : public CppUnit::TestFixture { | |||
| 58 | info.setFirstName(firstName); | 58 | info.setFirstName(firstName); |
| 59 | info.setLastName(lastName); | 59 | info.setLastName(lastName); |
| 60 | info.setNick(nickName); | 60 | info.setNick(nickName); |
| 61 | auto txtRecord = info.toTXTRecord(); | ||
| 62 | CPPUNIT_ASSERT(txtRecord); | ||
| 61 | return LinkLocalService(service, | 63 | return LinkLocalService(service, |
| 62 | DNSSDResolveServiceQuery::Result( | 64 | DNSSDResolveServiceQuery::Result( |
| 63 | name + "._presence._tcp.local", "rabbithole.local", 1234, | 65 | name + "._presence._tcp.local", "rabbithole.local", 1234, |
| 64 | info.toTXTRecord())); | 66 | *txtRecord)); |
| 65 | } | 67 | } |
| 66 | }; | 68 | }; |
| 67 | 69 | ||
diff --git a/Swiften/QA/DNSSDTest/DNSSDTest.cpp b/Swiften/QA/DNSSDTest/DNSSDTest.cpp index ae2fafd..5a78d2f 100644 --- a/Swiften/QA/DNSSDTest/DNSSDTest.cpp +++ b/Swiften/QA/DNSSDTest/DNSSDTest.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -35,7 +35,7 @@ class DNSSDTest : public CppUnit::TestFixture { | |||
| 35 | public: | 35 | public: |
| 36 | void setUp() { | 36 | void setUp() { |
| 37 | eventLoop = new DummyEventLoop(); | 37 | eventLoop = new DummyEventLoop(); |
| 38 | querier = std::make_shared<DNSSDQuerier>(); | 38 | querier = std::make_shared<DNSSDQuerierType>(eventLoop); |
| 39 | querier->start(); | 39 | querier->start(); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| @@ -55,7 +55,7 @@ class DNSSDTest : public CppUnit::TestFixture { | |||
| 55 | 55 | ||
| 56 | // Publish the service | 56 | // Publish the service |
| 57 | LinkLocalServiceInfo info; | 57 | LinkLocalServiceInfo info; |
| 58 | std::shared_ptr<DNSSDRegisterQuery> registerQuery = querier->createRegisterQuery("DNSSDTest", 1234, info.toTXTRecord()); | 58 | std::shared_ptr<DNSSDRegisterQuery> registerQuery = querier->createRegisterQuery("DNSSDTest", 1234, *info.toTXTRecord()); |
| 59 | registerQuery->onRegisterFinished.connect(boost::bind(&DNSSDTest::handleRegisterFinished, this, _1)); | 59 | registerQuery->onRegisterFinished.connect(boost::bind(&DNSSDTest::handleRegisterFinished, this, _1)); |
| 60 | registerQuery->registerService(); | 60 | registerQuery->registerService(); |
| 61 | 61 | ||
| @@ -137,7 +137,7 @@ class DNSSDTest : public CppUnit::TestFixture { | |||
| 137 | 137 | ||
| 138 | private: | 138 | private: |
| 139 | DummyEventLoop* eventLoop; | 139 | DummyEventLoop* eventLoop; |
| 140 | std::shared_ptr<DNSSDQuerier> querier; | 140 | std::shared_ptr<DNSSDQuerierType> querier; |
| 141 | std::vector<DNSSDServiceID> added; | 141 | std::vector<DNSSDServiceID> added; |
| 142 | std::vector<DNSSDServiceID> registered; | 142 | std::vector<DNSSDServiceID> registered; |
| 143 | std::vector<DNSSDServiceID> toRemove; | 143 | std::vector<DNSSDServiceID> toRemove; |
diff --git a/Swiften/QA/DNSSDTest/SConscript b/Swiften/QA/DNSSDTest/SConscript index 275a314..d9c9b04 100644 --- a/Swiften/QA/DNSSDTest/SConscript +++ b/Swiften/QA/DNSSDTest/SConscript | |||
| @@ -7,6 +7,7 @@ if env["TEST"] : | |||
| 7 | myenv.MergeFlags(myenv["CHECKER_FLAGS"]) | 7 | myenv.MergeFlags(myenv["CHECKER_FLAGS"]) |
| 8 | myenv.MergeFlags(myenv["SWIFTEN_FLAGS"]) | 8 | myenv.MergeFlags(myenv["SWIFTEN_FLAGS"]) |
| 9 | myenv.MergeFlags(myenv["CPPUNIT_FLAGS"]) | 9 | myenv.MergeFlags(myenv["CPPUNIT_FLAGS"]) |
| 10 | myenv.MergeFlags(myenv["GOOGLETEST_FLAGS"]) | ||
| 10 | myenv.MergeFlags(myenv["BOOST_FLAGS"]) | 11 | myenv.MergeFlags(myenv["BOOST_FLAGS"]) |
| 11 | myenv.MergeFlags(myenv["LIBIDN_FLAGS"]) | 12 | myenv.MergeFlags(myenv["LIBIDN_FLAGS"]) |
| 12 | if myenv.get("HAVE_BONJOUR", 0) : | 13 | if myenv.get("HAVE_BONJOUR", 0) : |
| @@ -14,6 +15,7 @@ if env["TEST"] : | |||
| 14 | elif myenv.get("HAVE_AVAHI", 0) : | 15 | elif myenv.get("HAVE_AVAHI", 0) : |
| 15 | myenv.Append(CPPDEFINES = ["HAVE_AVAHI"]) | 16 | myenv.Append(CPPDEFINES = ["HAVE_AVAHI"]) |
| 16 | myenv.MergeFlags(myenv["AVAHI_FLAGS"]) | 17 | myenv.MergeFlags(myenv["AVAHI_FLAGS"]) |
| 18 | myenv.MergeFlags(myenv["PLATFORM_FLAGS"]) | ||
| 17 | 19 | ||
| 18 | tester = myenv.Program("DNSSDTest", [ | 20 | tester = myenv.Program("DNSSDTest", [ |
| 19 | "DNSSDTest.cpp", | 21 | "DNSSDTest.cpp", |
Swift