summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-17 19:15:54 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-17 19:15:54 (GMT)
commita328466bc492c50c443e406b9325542a75182327 (patch)
tree8388cb92845a20d5c495e5940f5f16a6b95363a3 /Swiften/LinkLocal/LinkLocalServiceInfo.cpp
parent436ae921afbc5c2b461ee9b2d8fa9b1c869ed274 (diff)
downloadswift-contrib-a328466bc492c50c443e406b9325542a75182327.zip
swift-contrib-a328466bc492c50c443e406b9325542a75182327.tar.bz2
Implemented clean session/connection shutdown.
Diffstat (limited to 'Swiften/LinkLocal/LinkLocalServiceInfo.cpp')
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceInfo.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
index 99f83b8..8ee7ae0 100644
--- a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
+++ b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
@@ -45,4 +45,70 @@ ByteArray LinkLocalServiceInfo::getEncoded(const String& s) {
return sizeByte + ByteArray(s);
}
+LinkLocalServiceInfo LinkLocalServiceInfo::createFromTXTRecord(const ByteArray& record) {
+ LinkLocalServiceInfo info;
+ size_t i = 0;
+ while (i < record.getSize()) {
+ std::pair<String,String> entry = readEntry(record, &i);
+ if (entry.first.isEmpty()) {
+ break;
+ }
+ else if (entry.first == "1st") {
+ info.setFirstName(entry.second);
+ }
+ else if (entry.first == "last") {
+ info.setLastName(entry.second);
+ }
+ else if (entry.first == "email") {
+ info.setEMail(entry.second);
+ }
+ else if (entry.first == "jid") {
+ info.setJID(JID(entry.second));
+ }
+ else if (entry.first == "msg") {
+ info.setMessage(entry.second);
+ }
+ else if (entry.first == "nick") {
+ info.setNick(entry.second);
+ }
+ else if (entry.first == "port.p2pj") {
+ info.setPort(boost::lexical_cast<int>(entry.second));
+ }
+ else if (entry.first == "status") {
+ if (entry.second == "away") {
+ info.setStatus(Away);
+ }
+ else if (entry.second == "dnd") {
+ info.setStatus(DND);
+ }
+ }
+ }
+ return info;
+}
+
+std::pair<String,String> LinkLocalServiceInfo::readEntry(const ByteArray& record, size_t* index) {
+ size_t& i = *index;
+ String key;
+ String value;
+
+ size_t entryEnd = i + 1 + record[i];
+ ++i;
+ bool inKey = true;
+ while (i < entryEnd && i < record.getSize()) {
+ if (inKey) {
+ if (record[i] == '=') {
+ inKey = false;
+ }
+ else {
+ key += record[i];
+ }
+ }
+ else {
+ value += record[i];
+ }
+ ++i;
+ }
+ return std::make_pair(key, value);
+}
+
}