summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/LinkLocal/LinkLocalServiceInfo.cpp')
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceInfo.cpp65
1 files changed, 36 insertions, 29 deletions
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
15namespace Swift { 16namespace Swift {
16 17
17ByteArray LinkLocalServiceInfo::toTXTRecord() const { 18boost::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
50ByteArray LinkLocalServiceInfo::getEncoded(const std::string& s) { 57ByteArray LinkLocalServiceInfo::getEncoded(const std::string& s) {