diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2013-11-14 15:59:05 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2013-11-14 23:31:32 +0100 |
commit | 83219052c32a2073f52aae8e4b1c15822343f04f (patch) | |
tree | 6925c26677985d48d8b7e25be8674be9ba8dfa00 /src | |
parent | 8c33a01e68125fbc76be1f455f5ca85bcb952e65 (diff) | |
download | biboumi-83219052c32a2073f52aae8e4b1c15822343f04f.tar.gz biboumi-83219052c32a2073f52aae8e4b1c15822343f04f.tar.bz2 biboumi-83219052c32a2073f52aae8e4b1c15822343f04f.tar.xz biboumi-83219052c32a2073f52aae8e4b1c15822343f04f.zip |
Fix JID parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/test.cpp | 18 | ||||
-rw-r--r-- | src/xmpp/jid.cpp | 16 |
2 files changed, 27 insertions, 7 deletions
diff --git a/src/test.cpp b/src/test.cpp index 99454a5..7818451 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -12,6 +12,7 @@ #include <config/config.hpp> +#include <xmpp/jid.hpp> #include <xmpp/xmpp_parser.hpp> int main() @@ -66,6 +67,23 @@ int main() xml.feed(doc.data(), doc.size(), true); /** + * JID parsing + */ + // Full JID + Jid jid1("♥@ツ.coucou/coucou@coucou/coucou"); + std::cerr << jid1.local << " @ " << jid1.domain << " / " << jid1.resource << std::endl; + assert(jid1.local == "♥"); + assert(jid1.domain == "ツ.coucou"); + assert(jid1.resource == "coucou@coucou/coucou"); + + // Domain and resource + Jid jid2("ツ.coucou/coucou@coucou/coucou"); + std::cerr << jid2.local << " @ " << jid2.domain << " / " << jid2.resource << std::endl; + assert(jid2.local == ""); + assert(jid2.domain == "ツ.coucou"); + assert(jid2.resource == "coucou@coucou/coucou"); + + /** * Config */ Config::filename = "test.cfg"; diff --git a/src/xmpp/jid.cpp b/src/xmpp/jid.cpp index 78b28a0..29a5302 100644 --- a/src/xmpp/jid.cpp +++ b/src/xmpp/jid.cpp @@ -2,18 +2,20 @@ Jid::Jid(const std::string& jid) { - std::string::size_type at = jid.find("@"); - if (at != std::string::npos) + std::string::size_type slash = jid.find('/'); + if (slash != std::string::npos) + { + this->resource = jid.substr(slash + 1); + } + + std::string::size_type at = jid.find('@'); + if (at != std::string::npos && at < slash) { this->local = jid.substr(0, at); at++; } else at = 0; - std::string::size_type slash = jid.find("/", at); - if (slash != std::string::npos) - { - this->resource = jid.substr(slash + 1); - } + this->domain = jid.substr(at, slash - at); } |