summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-17 07:03:16 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-17 07:41:26 (GMT)
commit436ae921afbc5c2b461ee9b2d8fa9b1c869ed274 (patch)
tree9d209712286cc49d4c1f08be5ab8f5b90ef4971c /Swiften/LinkLocal/LinkLocalServiceInfo.cpp
parent2c954f7e9464b8fdd970eed829e2ba632e8979d8 (diff)
downloadswift-contrib-436ae921afbc5c2b461ee9b2d8fa9b1c869ed274.zip
swift-contrib-436ae921afbc5c2b461ee9b2d8fa9b1c869ed274.tar.bz2
Implement LinkLocalServiceInfo TXT record.
Diffstat (limited to 'Swiften/LinkLocal/LinkLocalServiceInfo.cpp')
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceInfo.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
new file mode 100644
index 0000000..99f83b8
--- /dev/null
+++ b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
@@ -0,0 +1,48 @@
+#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"
+
+#include <boost/lexical_cast.hpp>
+
+namespace Swift {
+
+ByteArray LinkLocalServiceInfo::toTXTRecord() const {
+ ByteArray result(getEncoded("txtvers=1"));
+ if (!firstName.isEmpty()) {
+ result += getEncoded("1st=" + firstName);
+ }
+ if (!lastName.isEmpty()) {
+ result += getEncoded("last=" + lastName);
+ }
+ if (!email.isEmpty()) {
+ result += getEncoded("email=" + email);
+ }
+ if (jid.isValid()) {
+ result += getEncoded("jid=" + jid.toString());
+ }
+ if (!message.isEmpty()) {
+ result += getEncoded("msg=" + message);
+ }
+ if (!nick.isEmpty()) {
+ result += getEncoded("nick=" + nick);
+ }
+ if (port) {
+ result += getEncoded("port.p2pj=" + 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;
+ }
+
+ return result;
+}
+
+ByteArray LinkLocalServiceInfo::getEncoded(const String& s) {
+ ByteArray sizeByte;
+ sizeByte.resize(1);
+ assert(s.getLength() < 256);
+ sizeByte[0] = s.getUTF8Size();
+ return sizeByte + ByteArray(s);
+}
+
+}