diff options
Diffstat (limited to 'Swiften/LinkLocal')
8 files changed, 28 insertions, 26 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h index 1109fb7..57fde49 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h @@ -14,10 +14,9 @@ #include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { - class ByteArray; - class BonjourQuerier : public DNSSDQuerier, public boost::enable_shared_from_this<BonjourQuerier> { diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h index b31e441..fd0e9d0 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h @@ -19,7 +19,7 @@ namespace Swift { 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, port, - txtRecord.getSize(), txtRecord.getData(), + txtRecord.size(), vecptr(txtRecord), &BonjourRegisterQuery::handleServiceRegisteredStatic, this); if (result != kDNSServiceErr_NoError) { sdRef = NULL; @@ -41,7 +41,7 @@ namespace Swift { void updateServiceInfo(const ByteArray& txtRecord) { boost::lock_guard<boost::mutex> lock(sdRefMutex); - DNSServiceUpdateRecord(sdRef, NULL, NULL, txtRecord.getSize(), txtRecord.getData(), 0); + DNSServiceUpdateRecord(sdRef, NULL, NULL, txtRecord.size(), vecptr(txtRecord), 0); } private: diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h index 2d40e72..1fb050c 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h @@ -56,7 +56,7 @@ namespace Swift { boost::bind( boost::ref(onServiceResolved), Result(std::string(fullName), std::string(host), port, - ByteArray(reinterpret_cast<const char*>(txtRecord), txtLen))), + createByteArray(reinterpret_cast<const char*>(txtRecord), txtLen))), shared_from_this()); } } diff --git a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h index cd55fb7..e6d548b 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h @@ -8,9 +8,9 @@ #include <boost/shared_ptr.hpp> +#include <Swiften/Base/ByteArray.h> + namespace Swift { - - class ByteArray; class DNSSDServiceID; class DNSSDBrowseQuery; class DNSSDRegisterQuery; diff --git a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h index 93555c2..e794a90 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h @@ -10,10 +10,9 @@ #include <boost/optional.hpp> #include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { - class ByteArray; - class DNSSDRegisterQuery { public: virtual ~DNSSDRegisterQuery(); diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h index 97a2c6e..f5166ee 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h @@ -12,13 +12,13 @@ #include <set> #include <string> +#include <Swiften/Base/ByteArray.h> #include <Swiften/EventLoop/EventOwner.h> #include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> #include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> #include <Swiften/Network/HostAddress.h> namespace Swift { - class ByteArray; class FakeDNSSDQuery; class FakeDNSSDBrowseQuery; class EventLoop; diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp index 2be0049..f437fc2 100644 --- a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp +++ b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp @@ -8,36 +8,39 @@ #include <boost/lexical_cast.hpp> +#include <Swiften/Base/Algorithm.h> +#include <Swiften/Base/Concat.h> + namespace Swift { ByteArray LinkLocalServiceInfo::toTXTRecord() const { ByteArray result(getEncoded("txtvers=1")); if (!firstName.empty()) { - result += getEncoded("1st=" + firstName); + append(result, getEncoded("1st=" + firstName)); } if (!lastName.empty()) { - result += getEncoded("last=" + lastName); + append(result, getEncoded("last=" + lastName)); } if (!email.empty()) { - result += getEncoded("email=" + email); + append(result, getEncoded("email=" + email)); } if (jid.isValid()) { - result += getEncoded("jid=" + jid.toString()); + append(result, getEncoded("jid=" + jid.toString())); } if (!message.empty()) { - result += getEncoded("msg=" + message); + append(result, getEncoded("msg=" + message)); } if (!nick.empty()) { - result += getEncoded("nick=" + nick); + append(result, getEncoded("nick=" + nick)); } if (port) { - result += getEncoded("port.p2pj=" + std::string(boost::lexical_cast<std::string>(*port))); + append(result, getEncoded("port.p2pj=" + std::string(boost::lexical_cast<std::string>(*port)))); } switch (status) { - case Available: result += getEncoded("status=avail"); break; - case Away: result += getEncoded("status=away"); break; - case DND: result += getEncoded("status=dnd"); break; + case Available: append(result, getEncoded("status=avail")); break; + case Away: append(result, getEncoded("status=away")); break; + case DND: append(result, getEncoded("status=dnd")); break; } return result; @@ -47,13 +50,13 @@ ByteArray LinkLocalServiceInfo::getEncoded(const std::string& s) { ByteArray sizeByte; sizeByte.resize(1); sizeByte[0] = s.size(); - return sizeByte + ByteArray(s); + return concat(sizeByte, createByteArray(s)); } LinkLocalServiceInfo LinkLocalServiceInfo::createFromTXTRecord(const ByteArray& record) { LinkLocalServiceInfo info; size_t i = 0; - while (i < record.getSize()) { + while (i < record.size()) { std::pair<std::string,std::string> entry = readEntry(record, &i); if (entry.first.empty()) { break; @@ -99,7 +102,7 @@ std::pair<std::string,std::string> LinkLocalServiceInfo::readEntry(const ByteArr size_t entryEnd = i + 1 + record[i]; ++i; bool inKey = true; - while (i < entryEnd && i < record.getSize()) { + while (i < entryEnd && i < record.size()) { if (inKey) { if (record[i] == '=') { inKey = false; diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp index 1e69cd0..bce7331 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp @@ -9,6 +9,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> +#include <QA/Checker/IO.h> #include <Swiften/LinkLocal/LinkLocalServiceInfo.h> using namespace Swift; @@ -28,11 +29,11 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture { info.setLastName("Tron\xc3\xe7on"); info.setStatus(LinkLocalServiceInfo::Away); - CPPUNIT_ASSERT_EQUAL(ByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), info.toTXTRecord()); + CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), info.toTXTRecord()); } void testCreateFromTXTRecord() { - LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(ByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away"))); + LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away"))); CPPUNIT_ASSERT_EQUAL(std::string("Remko"), info.getFirstName()); CPPUNIT_ASSERT_EQUAL(std::string("Tron\xc3\xe7on"), info.getLastName()); @@ -40,7 +41,7 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture { } void testCreateFromTXTRecord_InvalidSize() { - LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(ByteArray("\x10last=a")); + LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(createByteArray("\x10last=a")); CPPUNIT_ASSERT_EQUAL(std::string("a"), info.getLastName()); } |