void XMPPStream::onResourceBind (Error e, const xmpp::Iq & iq, const XMLChunk & chunk, const XMPPStream::BindCallback & originalCallback) { String jid = chunk.getChild ("bind").getChild("jid").text(); if (jid.empty() && !e){ Log (LogWarning) << LOGID << "Could not bind, got no JID" << std::endl; } if (!e) { Log (LogInfo) << LOGID << "Bound resource to " << mFullJid << std::endl; mFullJid = jid; } notify (originalCallback, e, jid); }
static bool hasMechanism (const String & name, const XMLChunk & features) { XMLChunk mechanisms = features.getChild ("mechanisms"); if (mechanisms.error()) return false; String nameUppered (name); boost::algorithm::to_upper(nameUppered); typedef std::vector<const XMLChunk*> Vec; Vec elements = mechanisms.getChildren("mechanism"); for (Vec::const_iterator i = elements.begin(); i != elements.end(); i++) { const XMLChunk * chunk (*i); String text = chunk->text(); boost::algorithm::to_upper (text); if (text == nameUppered) return true; } return false; }
int testNodeBuildAndParse () { BoshNodeBuilder builder; builder.addAttribute("hello", "world"); builder.addAttribute("and", "anotherone"); builder.addContent (sf::createByteArrayPtr ("<bla>Hi dude</bla>")); builder.addContent (sf::createByteArrayPtr ("<bli></bli>")); String s = builder.toString(); printf ("Serialized code: %s\n", s.c_str()); BoshNodeParser parser; Error e = parser.parse(s); tcheck1(!e); tcheck1(parser.attribute("hello") == "world"); tcheck1(parser.attribute("and") == "anotherone"); String back = parser.content(); XMLChunk chunk = xml::parseDocument(back.c_str(), back.length()); tcheck1 (chunk.getChild("bla").text() == "Hi dude"); tcheck1 (chunk.getHasChild("bli")); return 0; }
void XMPPStream::onXmlChunkRead (const XMLChunk & chunk) { if (mNextChunkHandler){ mNextChunkHandler (chunk); mNextChunkHandler.clear(); return; } if (chunk.name() == "stream:features") { if (mReceivedFeatures) { Log (LogWarning) << LOGID << "Double receive features!" << std::endl; } mFeatures = chunk; mReceivedFeatures = true; finishOp (XMO_WaitFeatures, NoError); return; } else if (chunk.name() == "iq") { xmpp::Iq iq; bool suc = iq.decode(chunk); if (!suc) { Log (LogWarning) << LOGID << "Could not decode " << chunk << std::endl; return; } String id = chunk.getAttribute("id"); if (id.empty()){ Log (LogWarning) << LOGID << "Received empty id in iq" << std::endl; } OpenIqMap::iterator i = mOpenIqs.find (id); if (i != mOpenIqs.end()){ IqResultCallback cb = i->second; mOpenIqs.erase(i); // make this behaviour selectable? if (cb){ notifyAsync (cb, NoError, iq, chunk); } else { Log (LogInfo) << LOGID << "Ignoring iq reply as there is no callback set (id=" << iq.id << ")" << std::endl; } } else { if (mIncomingIq) { notifyAsync (mIncomingIq, iq, chunk); } else { Log (LogWarning) << LOGID << "No iq handler set!" << std::endl; } } } else if (chunk.name() == "message") { xmpp::Message m; bool suc = m.decode(chunk); if (!suc) { Log (LogWarning) << LOGID << "Could not decode message " << chunk << std::endl; return; } notifyAsync (mIncomingMessage, m, chunk); } else if (chunk.name() == "presence") { xmpp::PresenceInfo p; bool suc = p.decode(chunk); if (!suc) { Log (LogWarning) << LOGID << "Could not decode presence " << chunk << std::endl; return; } notifyAsync (mIncomingPresence, p, chunk); } else if (chunk.name() == "stream:error"){ String text = chunk.getChild("text").text(); if (mIncomingStreamError){ notifyAsync (mIncomingStreamError, text, chunk); } else { Log (LogWarning) << LOGID << "Discarding incoming stream error, no delegate " << text << std::endl; } } else { Log (LogWarning) << LOGID << "Unknown chunk type " << chunk << std::endl; } }