summaryrefslogtreecommitdiff
path: root/src/xmpp/xmpp_stanza.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-11-07 01:53:09 +0100
committerFlorent Le Coz <louiz@louiz.org>2013-11-07 01:53:09 +0100
commita418b6ed5d70f0e61e71bb1adce2a693ade89e30 (patch)
treef4d979e1dae286df4faa6de3660288495d4ced77 /src/xmpp/xmpp_stanza.cpp
parent4b76a30d0479f366374c7dcf99ac211038722503 (diff)
downloadbiboumi-a418b6ed5d70f0e61e71bb1adce2a693ade89e30.tar.gz
biboumi-a418b6ed5d70f0e61e71bb1adce2a693ade89e30.tar.bz2
biboumi-a418b6ed5d70f0e61e71bb1adce2a693ade89e30.tar.xz
biboumi-a418b6ed5d70f0e61e71bb1adce2a693ade89e30.zip
Send and receive messages
Also correctly respond to PING with the id, escape some XML content, but not always
Diffstat (limited to 'src/xmpp/xmpp_stanza.cpp')
-rw-r--r--src/xmpp/xmpp_stanza.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/xmpp/xmpp_stanza.cpp b/src/xmpp/xmpp_stanza.cpp
index 2c98acc..4c0088e 100644
--- a/src/xmpp/xmpp_stanza.cpp
+++ b/src/xmpp/xmpp_stanza.cpp
@@ -2,6 +2,26 @@
#include <iostream>
+std::string xml_escape(const std::string& data)
+{
+ std::string res;
+ buffer.reserve(data.size());
+ for(size_t pos = 0; pos != data.size(); ++pos)
+ {
+ switch(data[pos])
+ {
+ case '&': buffer += "&amp;"; break;
+ case '\"': buffer += "&quot;"; break;
+ case '\'': buffer += "&apos;"; break;
+ case '<': buffer += "&lt;"; break;
+ case '>': buffer += "&gt;"; break;
+ default: buffer += data[pos]; break;
+ }
+ }
+ return buffer;
+}
+
+
XmlNode::XmlNode(const std::string& name, XmlNode* parent):
name(name),
parent(parent),
@@ -40,7 +60,22 @@ void XmlNode::set_tail(const std::string& data)
void XmlNode::set_inner(const std::string& data)
{
- this->inner = data;
+ this->inner = xml_escape(data);
+}
+
+std::string XmlNode::get_inner() const
+{
+ return this->inner;
+}
+
+XmlNode* XmlNode::get_child(const std::string& name) const
+{
+ for (auto& child: this->children)
+ {
+ if (child->name == name)
+ return child;
+ }
+ return nullptr;
}
void XmlNode::add_child(XmlNode* child)