Commit 83219052 authored by Link Mauve's avatar Link Mauve Committed by louiz’

Fix JID parsing

parent 8c33a01e
......@@ -12,6 +12,7 @@
#include <config/config.hpp>
#include <xmpp/jid.hpp>
#include <xmpp/xmpp_parser.hpp>
int main()
......@@ -65,6 +66,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
*/
......
......@@ -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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment