Example #1
0
bool RosterItemExchangeTask::take(const QDomElement& e) 
{
	for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
		QDomElement i = n.toElement();
		if(i.isNull())
			continue;
		if(i.tagName() == "x" && i.attribute("xmlns") == "http://jabber.org/protocol/rosterx") {
			qDebug("Roster Exchange request with correct attribute");
			Jid from(e.attribute("from"));
			if (client()->roster().find(from,false) == client()->roster().end() && ignoreNonRoster_) {
				qDebug("Invalid roster Exchange request");
				// Send a not-authorized error
				QDomElement iq = createIQ(doc(), "error", e.attribute("from"), e.attribute("id"));
				QDomElement error = doc()->createElement("error");
				error.setAttribute("type","cancel");
				QDomElement notauthorized = doc()->createElement("not-authorized");
				notauthorized.setAttribute("xmlns","urn:ietf:params:xml:ns:xmpp-stanzas");
				error.appendChild(notauthorized);
				iq.appendChild(error);
				send(iq);
				setError(e);
				return true;
			}

			qDebug("Parsing items");
			// Parse all items
			RosterExchangeItems items;
			for(QDomNode m = i.firstChild(); !m.isNull(); m = m.nextSibling()) {
				QDomElement j = m.toElement();
				if(j.isNull())
					continue;
				RosterExchangeItem it(j);
				if (!it.isNull())
					items += it;
			}

			// Return success
			QDomElement iq = createIQ(doc(), "result", e.attribute("from"), e.attribute("id"));
			send(iq);

			emit rosterItemExchange(from,items);
			setSuccess(true);
			qDebug("Succesfully updated roster");
			return true;
		}
	}
	return false;
}
Example #2
0
void HttpAuthListener::reply(bool confirm, const PsiHttpAuthRequest &req)
{
    const XMPP::Stanza &s = req.stanza();
    if (s.kind() == XMPP::Stanza::Message) {
        XMPP::Message m(s.from());
        if (!confirm) {
            m.setType("error");
            m.setError(XMPP::HttpAuthRequest::denyError);
        }
        m.setHttpAuthRequest(req);

        QDomElement t = s.element().elementsByTagNameNS(s.baseNS(), "thread").item(0).toElement();
        if (!t.isNull()) {
            m.setThread(t.text(), true);
        }    //FIX-ME: it doesn't make sense to create Message object just to read the thread, does it?

        client()->sendMessage(m);
     }
    else {
        QDomElement e;
        e = createIQ(client()->doc(), confirm ? "result" : "error", s.from().full(), s.id());
        e.appendChild(req.toXml(*client()->doc()));
        if (!confirm) {
            e.appendChild(XMPP::HttpAuthRequest::denyError.toXml(*client()->doc(), client()->stream().baseNS()));
        }
        send(e);
    }
}
JT_ServerVars::JT_ServerVars(Task *parent, const Jid & to)
: Task(parent)
{
	_jid = to;
	_iq = createIQ(doc(), "get", _jid.bare(), id());
	QDomElement query = doc()->createElement("query");
	query.setAttribute("xmlns", "http://messenger.sapo.pt/protocols/server-vars");
	query.setAttribute("appbrand", "SAPO");
	query.setAttribute("version", "1");
	_iq.appendChild(query);
}
Example #4
0
	void get() {
		iq_ = createIQ(doc(), "get", "", id());

		QDomElement prvt = doc()->createElement("query");
		prvt.setAttribute("xmlns", "jabber:iq:private");
		iq_.appendChild(prvt);

		QDomElement bookmarks = doc()->createElement("storage");
		bookmarks.setAttribute("xmlns", "storage:bookmarks");
		prvt.appendChild(bookmarks);
	}
JT_CheckTransportRegistration::JT_CheckTransportRegistration(Task *parent, const Jid & transport_jid)
: Task(parent)
{
	_transport_jid = transport_jid;
	_iq = createIQ(doc(), "get", _transport_jid.bare(), id());
	QDomElement query = doc()->createElement("query");
	query.setAttribute("xmlns", "jabber:iq:register");
	_iq.appendChild(query);
	_isRegistered = false;
	_registeredUsername = "";
}
Example #6
0
void JT_XSearch::setForm(const Form &frm, const XData &_form)
{
	JT_Search::set( frm );

	_iq = createIQ(doc(), "set", frm.jid().full(), id());
	QDomElement query = doc()->createElement("query");
	query.setAttribute("xmlns", "jabber:iq:search");
	_iq.appendChild(query);

	XData form( _form );
	form.setType( XData::Data_Submit );
	query.appendChild( form.toXml( doc() ) );
}
Example #7
0
        void testHandleAckReceived_AcksMultipleStanzas() {
            std::shared_ptr<StanzaAckRequester> testling(createRequester());
            testling->handleStanzaSent(createIQ("iq1"));
            testling->handleStanzaSent(createPresence("p1"));
            testling->handleStanzaSent(createMessage("m1"));

            testling->handleAckReceived(3);

            CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(ackedStanzas.size()));
            CPPUNIT_ASSERT_EQUAL(std::string("iq1"), ackedStanzas[0]->getID());
            CPPUNIT_ASSERT_EQUAL(std::string("p1"), ackedStanzas[1]->getID());
            CPPUNIT_ASSERT_EQUAL(std::string("m1"), ackedStanzas[2]->getID());
        }
Example #8
0
bool JingleIQResponder::take(const QDomElement &e)
{
	if(e.tagName() != "iq")
		return false;
	
	QDomElement first = e.firstChild().toElement();
	if (!first.isNull() && first.attribute("xmlns") == JINGLE_NS) {
		QDomElement iq = createIQ(doc(), "result", e.attribute("from"), e.attribute("id"));
		send(iq);
		return true;
	}
	
	return false;
}
Example #9
0
PEPPublishTask::PEPPublishTask(Task *parent, const QString &node, const XMPP::PubSubItem &it, PEPManager::Access access) :
    XMPP::Task(parent), node_(node), item_(it)
{
    iq_ = createIQ(doc(), "set", QString(), id());

    QDomElement pubsub = doc()->createElement("pubsub");
    pubsub.setAttribute("xmlns", "http://jabber.org/protocol/pubsub");
    iq_.appendChild(pubsub);

    QDomElement publish = doc()->createElement("publish");
    publish.setAttribute("node", node);
    pubsub.appendChild(publish);

    QDomElement item = doc()->createElement("item");
    item.setAttribute("id", it.id());
    publish.appendChild(item);

    if (access != PEPManager::DefaultAccess)
    {
        QDomElement conf = doc()->createElement("configure");
        QDomElement conf_x = doc()->createElementNS("jabber:x:data","x");

        // Form type
        QDomElement conf_x_field_type = doc()->createElement("field");
        conf_x_field_type.setAttribute("var","FORM_TYPE");
        conf_x_field_type.setAttribute("type","hidden");
        QDomElement conf_x_field_type_value = doc()->createElement("value");
        conf_x_field_type_value.appendChild(doc()->createTextNode("http://jabber.org/protocol/pubsub#node_config"));
        conf_x_field_type.appendChild(conf_x_field_type_value);
        conf_x.appendChild(conf_x_field_type);

        // Access model
        QDomElement access_model = doc()->createElement("field");
        access_model.setAttribute("var","pubsub#access_model");
        QDomElement access_model_value = doc()->createElement("value");
        access_model.appendChild(access_model_value);
        if (access == PEPManager::PublicAccess)
            access_model_value.appendChild(doc()->createTextNode("open"));
        else if (access == PEPManager::PresenceAccess)
            access_model_value.appendChild(doc()->createTextNode("presence"));
        conf_x.appendChild(access_model);


        conf.appendChild(conf_x);
        pubsub.appendChild(conf);
    }

    item.appendChild(it.payload());
}
Example #10
0
	void set(const QList<URLBookmark>& urls, const QList<ConferenceBookmark>& conferences) {
		iq_ = createIQ(doc(), "set", "", id());

		QDomElement prvt = doc()->createElement("query");
		prvt.setAttribute("xmlns", "jabber:iq:private");
		iq_.appendChild(prvt);

		QDomElement storage = doc()->createElement("storage");
		storage.setAttribute("xmlns", "storage:bookmarks");
		prvt.appendChild(storage);

		foreach(URLBookmark u, urls)
			storage.appendChild(u.toXml(*doc()));
		foreach(ConferenceBookmark c, conferences)
			storage.appendChild(c.toXml(*doc()));
	}
void JT_JingleRtp::request(const XMPP::Jid &to, const JingleRtpEnvelope &envelope)
{
    to_ = to;
    iq_ = createIQ(doc(), "set", to.full(), id());
    QDomElement query = doc()->createElement("jingle");
    query.setAttribute("xmlns", "urn:xmpp:jingle:1");
    query.setAttribute("action", envelope.action);
    if(!envelope.initiator.isEmpty())
        query.setAttribute("initiator", envelope.initiator);
    if(!envelope.responder.isEmpty())
        query.setAttribute("responder", envelope.responder);
    query.setAttribute("sid", envelope.sid);

    if(envelope.action == "session-terminate")
    {
        // for session terminate, there is no content list, just
        //   a reason for termination
        query.appendChild(reasonToElement(doc(), envelope.reason));
    }
    else
    {
        foreach(const JingleRtpContent &c, envelope.contentList)
        {
            QDomElement content = doc()->createElement("content");
            content.setAttribute("creator", c.creator);
            if(!c.disposition.isEmpty())
                content.setAttribute("disposition", c.disposition);
            content.setAttribute("name", c.name);
            if(!c.senders.isEmpty())
                content.setAttribute("senders", c.senders);

            if(!c.desc.media.isEmpty())
            {
                // TODO: ssrc, bitrate, crypto
                QDomElement description = doc()->createElement("description");
                description.setAttribute("xmlns", "urn:xmpp:jingle:apps:rtp:1");
                description.setAttribute("media", c.desc.media);
                foreach(const JingleRtpPayloadType &pt, c.desc.payloadTypes)
                {
                    QDomElement p = payloadTypeToElement(doc(), pt);
                    if(!p.isNull())
                        description.appendChild(p);
                }
                content.appendChild(description);
            }

            if(!c.trans.user.isEmpty())
            {
                QDomElement transport = doc()->createElement("transport");
                transport.setAttribute("xmlns", "urn:xmpp:jingle:transports:ice-udp:1");
                transport.setAttribute("ufrag", c.trans.user);
                transport.setAttribute("pwd", c.trans.pass);
                foreach(const XMPP::Ice176::Candidate &ic, c.trans.candidates)
                {
                    QDomElement e = candidateToElement(doc(), ic);
                    if(!e.isNull())
                        transport.appendChild(e);
                }
                content.appendChild(transport);
            }

            query.appendChild(content);
        }
Example #12
0
        void testHandleStanzaSent_IQDoesNotRequestAck() {
            std::shared_ptr<StanzaAckRequester> testling(createRequester());
            testling->handleStanzaSent(createIQ("iq1"));

            CPPUNIT_ASSERT_EQUAL(0, acksRequested);
        }