Exemplo n.º 1
0
/// \cond
void QXmppJingleIq::Content::parse(const QDomElement &element)
{
    m_creator = element.attribute("creator");
    m_disposition = element.attribute("disposition");
    m_name = element.attribute("name");
    m_senders = element.attribute("senders");

    // description
    QDomElement descriptionElement = element.firstChildElement("description");
    m_descriptionType = descriptionElement.namespaceURI();
    m_descriptionMedia = descriptionElement.attribute("media");
    QDomElement child = descriptionElement.firstChildElement("payload-type");
    while (!child.isNull())
    {
        QXmppJinglePayloadType payload;
        payload.parse(child);
        m_payloadTypes << payload;
        child = child.nextSiblingElement("payload-type");
    }

    // transport
    QDomElement transportElement = element.firstChildElement("transport");
    m_transportType = transportElement.namespaceURI();
    m_transportUser = transportElement.attribute("ufrag");
    m_transportPassword = transportElement.attribute("pwd");
    child = transportElement.firstChildElement("candidate");
    while (!child.isNull())
    {
        QXmppJingleCandidate candidate;
        candidate.parse(child);
        m_transportCandidates << candidate;
        child = child.nextSiblingElement("candidate");
    }
}
Exemplo n.º 2
0
/**
 * Constructs stream-error object from a DOM element.
 *
 * @param element   \<stream:error/\> DOM element.
 */
StreamError::StreamError(const QDomElement& element)
    : d(new Private)
{
    QDomNode root = d->doc.importNode(element, true);
    d->doc.appendChild(root);

    QDomNodeList childs = root.childNodes();
    for (int i = 0; i < childs.count(); ++i) {
        QDomElement element = childs.item(i).toElement();
        if (element.namespaceURI() == NS_STREAMS) {
            int condition = Private::stringToCondition(element.tagName() );
            if ( condition != -1 ) {
                d->errorCondition = element;
                break;
            }
        }
    }

    QDomElement eText = root.firstChildElement("text");
    if (eText.namespaceURI() == NS_STREAMS) {
        d->text = eText;
    }

    for (int i = 0; i < childs.count(); ++i) {
        QDomElement element = childs.item(i).toElement();
        /* first element outside NS_STREAMS ns will be an app-specific error condition */
        if (element.namespaceURI() != NS_STREAMS) {
            d->appSpec = element;
        }
    }
}
Exemplo n.º 3
0
QString XmlUtil::stripAnswers(const QString &input) {
	QDomDocument doc;
	doc.setContent(input);
	QDomElement docElem = doc.documentElement();

	QDomNode n = docElem.firstChild();
	while ( !n.isNull() ) {
		QDomElement e = n.toElement();
		if ( !e.isNull() && (e.namespaceURI().isEmpty() || e.namespaceURI() == XML_NS) ) {
			if ( e.nodeName() == "choose" ) {
				QDomElement c = e.firstChildElement("choice");
				while ( !c.isNull() ) {
					c.removeAttribute("answer");
					c = c.nextSiblingElement("choice");
				}
			} else if ( e.nodeName() == "identification" ) {
				QDomElement a = e.firstChildElement("a");
				while ( !a.isNull() ) {
					e.removeChild(a);
					a = e.firstChildElement("a");
				}
			}
		}
		n = n.nextSibling();
	}
	return doc.toString(2);
}
Exemplo n.º 4
0
QString PrivateStorage::saveData(const Jid &AStreamJid, const QDomElement &AElement)
{
	if (FStanzaProcessor && isOpen(AStreamJid) && !AElement.tagName().isEmpty() && !AElement.namespaceURI().isEmpty())
	{
		Stanza request(STANZA_KIND_IQ);
		request.setType(STANZA_TYPE_SET).setUniqueId();
		QDomElement elem = request.addElement("query",NS_JABBER_PRIVATE);
		elem.appendChild(AElement.cloneNode(true));
		if (FStanzaProcessor->sendStanzaRequest(this,AStreamJid,request,PRIVATE_STORAGE_TIMEOUT))
		{
			LOG_STRM_INFO(AStreamJid,QString("Private data save request sent, ns=%1, id=%2").arg(AElement.namespaceURI(),request.id()));
			if (FPreClosedStreams.contains(AStreamJid))
				notifyDataChanged(AStreamJid,AElement.tagName(),AElement.namespaceURI());
			FSaveRequests.insert(request.id(),insertElement(AStreamJid,AElement));
			return request.id();
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Failed to send private data save request, ns=%1").arg(AElement.namespaceURI()));
		}
	}
	else if (!isOpen(AStreamJid))
	{
		REPORT_ERROR("Failed to save private data: Storage is not opened");
	}
	else if (AElement.tagName().isEmpty() || AElement.namespaceURI().isEmpty())
	{
		REPORT_ERROR("Failed to save private data: Invalid data");
	}
	return QString::null;
}
Exemplo n.º 5
0
void QXmppStreamFeatures::parse(const QDomElement &element)
{
    m_bindMode = readFeature(element, "bind", ns_bind);
    m_sessionMode = readFeature(element, "session", ns_session);
    m_nonSaslAuthMode = readFeature(element, "auth", ns_authFeature);
    m_tlsMode = readFeature(element, "starttls", ns_tls);
    m_streamManagementMode = readFeature(element, "sm", ns_stream_management);

    // parse advertised compression methods
    QDomElement compression = element.firstChildElement("compression");
    if (compression.namespaceURI() == ns_compressFeature)
    {
        QDomElement subElement = compression.firstChildElement("method");
        while(!subElement.isNull())
        {
            m_compressionMethods << subElement.text();
            subElement = subElement.nextSiblingElement("method");
        }
    }

    // parse advertised SASL Authentication mechanisms
    QDomElement mechs = element.firstChildElement("mechanisms");
    if (mechs.namespaceURI() == ns_sasl)
    {
        QDomElement subElement = mechs.firstChildElement("mechanism");
        while(!subElement.isNull()) {
            m_authMechanisms << subElement.text();
            subElement = subElement.nextSiblingElement("mechanism");
        }
    }
}
Exemplo n.º 6
0
void FileWriter::writeElementChilds(const QDomElement &AParent)
{
	QDomNode node = AParent.firstChild();
	while (!node.isNull())
	{
		if (node.isElement())
		{
			QDomElement elem = node.toElement();
			if (elem.tagName() != "thread")
			{
				FXmlWriter->writeStartElement(elem.tagName());

				QString elemNs = elem.namespaceURI();
				if (!elemNs.isEmpty() && elem.parentNode().namespaceURI()!=elemNs)
					FXmlWriter->writeAttribute("xmlns",elem.namespaceURI());

				QDomNamedNodeMap attrMap = elem.attributes();
				for (uint i=0; i<attrMap.length(); i++)
				{
					QDomNode attrNode = attrMap.item(i);
					FXmlWriter->writeAttribute(attrNode.nodeName(), attrNode.nodeValue());
				}

				writeElementChilds(elem);
				FXmlWriter->writeEndElement();
			}
		}
		else if (node.isCharacterData())
		{
			FXmlWriter->writeCharacters(node.toCharacterData().data());
		}

		node = node.nextSibling();
	}
}
Exemplo n.º 7
0
void PrivateStorage::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza)
{
	if (FSaveRequests.contains(AStanza.id()))
	{
		QDomElement dataElem = FSaveRequests.take(AStanza.id());
		if (AStanza.isResult())
		{
			LOG_STRM_INFO(AStreamJid,QString("Private data saved on server, ns=%1, id=%2").arg(dataElem.namespaceURI(),AStanza.id()));
			notifyDataChanged(AStreamJid,dataElem.tagName(),dataElem.namespaceURI());
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Private data saved in local storage, ns=%1, id=%2: %3").arg(dataElem.namespaceURI(),AStanza.id(),XmppStanzaError(AStanza).condition()));
		}
		saveOptionsElement(AStreamJid,dataElem);
		emit dataSaved(AStanza.id(),AStreamJid,dataElem);
	}
	else if (FLoadRequests.contains(AStanza.id()))
	{
		QDomElement dataElem; 
		QDomElement loadElem = FLoadRequests.take(AStanza.id());
		if (AStanza.isResult())
		{
			dataElem = AStanza.firstElement("query",NS_JABBER_PRIVATE).firstChildElement(loadElem.tagName());
			LOG_STRM_INFO(AStreamJid,QString("Private data loaded from server, ns=%1, id=%2").arg(loadElem.namespaceURI(),AStanza.id()));
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Private data loaded from local storage, ns=%1, id=%2: %3").arg(loadElem.namespaceURI(),AStanza.id(),XmppStanzaError(AStanza).condition()));
		}
		if (dataElem.isNull())
			dataElem = loadOptionsElement(AStreamJid,loadElem.tagName(),loadElem.namespaceURI());
		emit dataLoaded(AStanza.id(),AStreamJid,insertElement(AStreamJid,dataElem));
	}
	else if (FRemoveRequests.contains(AStanza.id()))
	{
		QDomElement dataElem = FRemoveRequests.take(AStanza.id());
		if (AStanza.isResult())
		{
			LOG_STRM_INFO(AStreamJid,QString("Private data removed from server, ns=%1, id=%2").arg(dataElem.namespaceURI(),AStanza.id()));
			notifyDataChanged(AStreamJid,dataElem.tagName(),dataElem.namespaceURI());
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Private data removed from local storage, ns=%1, id=%2: %3").arg(dataElem.namespaceURI(),AStanza.id(),XmppStanzaError(AStanza).condition()));
		}
		removeElement(AStreamJid,dataElem.tagName(),dataElem.namespaceURI());
		removeOptionsElement(AStreamJid,dataElem.tagName(),dataElem.namespaceURI());
		emit dataRemoved(AStanza.id(),AStreamJid,dataElem);
	}
}
Exemplo n.º 8
0
static void helperToXmlAddDomElement(QXmlStreamWriter* stream, const QDomElement& element, const QStringList &omitNamespaces)
{
    stream->writeStartElement(element.tagName());

    /* attributes */
    QString xmlns = element.namespaceURI();
    if (!xmlns.isEmpty() && !omitNamespaces.contains(xmlns))
        stream->writeAttribute("xmlns", xmlns);
    QDomNamedNodeMap attrs = element.attributes();
    for (int i = 0; i < attrs.size(); i++)
    {
        QDomAttr attr = attrs.item(i).toAttr();
        stream->writeAttribute(attr.name(), attr.value());
    }

    /* children */
    QDomNode childNode = element.firstChild();
    while (!childNode.isNull())
    {
        if (childNode.isElement())
        {
            helperToXmlAddDomElement(stream, childNode.toElement(), QStringList() << xmlns);
        } else if (childNode.isText()) {
            stream->writeCharacters(childNode.toText().data());
        }
        childNode = childNode.nextSibling();
    }
    stream->writeEndElement();
}
Exemplo n.º 9
0
bool QXmppCarbonManager::handleStanza(const QDomElement &element)
{
    if(element.tagName() != "message")
        return false;

    bool sent = true;
    QDomElement carbon = element.firstChildElement("sent");
    if(carbon.isNull()) {
        carbon = element.firstChildElement("received");
        sent = false;
    }

    if(carbon.isNull() || carbon.namespaceURI() != ns_carbons)
        return false;   // Neither sent nor received -> no carbon message

    QDomElement forwarded = carbon.firstChildElement("forwarded");
    if(forwarded.isNull())
        return false;

    QDomElement messageelement = forwarded.firstChildElement("message");
    if(messageelement.isNull())
        return false;

    QXmppMessage message;
    message.parse(messageelement);

    if(sent)
        emit messageSent(message);
    else
        emit messageReceived(message);

    return true;
}
Exemplo n.º 10
0
QDomElement PrivateStorage::getData(const Jid &AStreamJid, const QString &ATagName, const QString &ANamespace) const
{
	QDomElement elem = FStreamElements.value(AStreamJid).firstChildElement(ATagName);
	while (!elem.isNull() && elem.namespaceURI()!=ANamespace)
		elem= elem.nextSiblingElement(ATagName);
	return elem;
}
Exemplo n.º 11
0
/// \cond
bool QXmppRpcResponseIq::isRpcResponseIq(const QDomElement &element)
{
    QString type = element.attribute("type");
    QDomElement dataElement = element.firstChildElement("query");
    return dataElement.namespaceURI() == ns_rpc &&
           type == "result";
}
Exemplo n.º 12
0
QList<QDomElement> Item::unhandledElements() const
{
    // TODO: do not hardcode this list here
    QList<ElementType> handled;
    handled.append(ElementType(QLatin1String("title")));
    handled.append(ElementType(QLatin1String("link")));
    handled.append(ElementType(QLatin1String("description")));
    handled.append(ElementType(QLatin1String("pubDate")));
    handled.append(ElementType(QLatin1String("expirationDate")));
    handled.append(ElementType(QLatin1String("rating")));
    handled.append(ElementType(QLatin1String("source")));
    handled.append(ElementType(QLatin1String("guid")));
    handled.append(ElementType(QLatin1String("comments")));
    handled.append(ElementType(QLatin1String("author")));
    handled.append(ElementType(QLatin1String("date"), dublinCoreNamespace()));
    
    QList<QDomElement> notHandled;
    
    QDomNodeList children = element().childNodes();
    for (int i = 0; i < children.size(); ++i)
    {
        QDomElement el = children.at(i).toElement();
        if (!el.isNull() 
             && !handled.contains(ElementType(el.localName(), el.namespaceURI())))
        {
            notHandled.append(el);
        }
    }
    
    return notHandled;
}
Exemplo n.º 13
0
void Reader::loadAnnotations(const QDomElement& annotations)
{
	QDomNodeList nodes = annotations.childNodes();
	for(int n=0;n<nodes.count();++n) {
		QDomElement e = nodes.at(n).toElement();
		if(e.isNull())
			continue;
		if(e.namespaceURI()==DP_NAMESPACE && e.localName()=="a") {
			_commands.append(MessagePtr(new protocol::AnnotationCreate(
				0,
				++_annotationid,
				e.attribute("x").toInt(),
				e.attribute("y").toInt(),
				e.attribute("w").toInt(),
				e.attribute("h").toInt()
			)));
			_commands.append(MessagePtr(new protocol::AnnotationEdit(
				_annotationid,
				e.attribute("bg").mid(1).toUInt(0,16),
				e.text()
			)));
		} else {
			qWarning() << "unhandled annotations (DP ext.) element:" << e.tagName();
		}
	}
}
Exemplo n.º 14
0
QList<QDomElement> Entry::unhandledElements() const
{
    // TODO: do not hardcode this list here
    QList<ElementType> handled;
    handled.append(ElementType(QLatin1String("author"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("contributor"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("category"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("id"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("link"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("rights"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("source"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("published"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("updated"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("summary"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("title"), atom1Namespace()));
    handled.append(ElementType(QLatin1String("content"), atom1Namespace()));
    
    QList<QDomElement> notHandled;
    
    QDomNodeList children = element().childNodes();
    for (int i = 0; i < children.size(); ++i)
    {
        QDomElement el = children.at(i).toElement();
        if (!el.isNull() 
             && !handled.contains(ElementType(el.localName(), el.namespaceURI())))
        {
            notHandled.append(el);
        }
    }
    
    return notHandled;
}
Exemplo n.º 15
0
// stripExtraNS
//
// This function removes namespace information from various nodes for
// display purposes only (the element is pretty much useless for processing
// after this).  We do this because QXml is a bit overzealous about outputting
// redundant namespaces.
static QDomElement stripExtraNS(const QDomElement &e)
{
	// find closest parent with a namespace
	QDomNode par = e.parentNode();
	while(!par.isNull() && par.namespaceURI().isNull())
		par = par.parentNode();
	bool noShowNS = false;
	if(!par.isNull() && par.namespaceURI() == e.namespaceURI())
		noShowNS = true;

	// build qName (prefix:localName)
	QString qName;
	if(!e.prefix().isEmpty())
		qName = e.prefix() + ':' + e.localName();
	else
		qName = e.tagName();

	QDomElement i;
	int x;
	if(noShowNS)
		i = e.ownerDocument().createElement(qName);
	else
		i = e.ownerDocument().createElementNS(e.namespaceURI(), qName);

	// copy attributes
	QDomNamedNodeMap al = e.attributes();
	for(x = 0; x < al.count(); ++x) {
		QDomAttr a = al.item(x).cloneNode().toAttr();

		// don't show xml namespace
		if(a.namespaceURI() == NS_XML)
			i.setAttribute(QString("xml:") + a.name(), a.value());
		else
			i.setAttributeNodeNS(a);
	}

	// copy children
	QDomNodeList nl = e.childNodes();
	for(x = 0; x < nl.count(); ++x) {
		QDomNode n = nl.item(x);
		if(n.isElement())
			i.appendChild(stripExtraNS(n.toElement()));
		else
			i.appendChild(n.cloneNode());
	}
	return i;
}
Exemplo n.º 16
0
bool CoreProtocol::isValidStanza(const QDomElement &e) const
{
	QString s = e.tagName();
	if(e.namespaceURI() == (server ? NS_SERVER : NS_CLIENT) && (s == "message" || s == "presence" || s == "iq"))
		return true;
	else
		return false;
}
Exemplo n.º 17
0
/// \cond
bool QXmppRpcErrorIq::isRpcErrorIq(const QDomElement &element)
{
    QString type = element.attribute("type");
    QDomElement errorElement = element.firstChildElement("error");
    QDomElement queryElement = element.firstChildElement("query");
    return (type == "error") &&
            !errorElement.isNull() &&
            queryElement.namespaceURI() == ns_rpc;
}
Exemplo n.º 18
0
bool KPrTextDocument::loadSpanTag( const QDomElement& tag, KoOasisContext& context,
                                  KoTextParag* parag, uint pos,
                                  QString& textData, KoTextCustomItem* & customItem )
{
    const QString localName( tag.localName() );
    const bool isTextNS = tag.namespaceURI() == KoXmlNS::text;
    kdDebug( 32500 ) << "KPrTextDocument::loadSpanTag: " << localName << endl;

    if ( isTextNS )
    {
        if ( localName == "a" )
        {
            QString href( tag.attributeNS( KoXmlNS::xlink, "href", QString::null ) );
            if ( href.startsWith( "#" ) )
            {
                context.styleStack().save();
                // We have a reference to a bookmark (### TODO)
                // As we do not support it now, treat it as a <span> without formatting
                parag->loadOasisSpan( tag, context, pos ); // recurse
                context.styleStack().restore();
            }
            else
            {
                // The text is contained in a <span> inside the <a> element. In theory
                // we could have multiple spans there, but OO ensures that there is always only one,
                // splitting the hyperlink if necessary (at format changes).
                // Note that we ignore the formatting of the span.
                QDomElement spanElem = KoDom::namedItemNS( tag, KoXmlNS::text, "span" );
                QString text;
                if ( spanElem.isNull() )
                    text = tag.text();
                if ( spanElem.isNull() )
                    text = tag.text();
                else {
                    // The save/restore of the stack is done by the caller (KoTextParag::loadOasisSpan)
                    // This allows to use the span's format for the variable.
                    //kdDebug(32500) << "filling stack with " << spanElem.attributeNS( KoXmlNS::text, "style-name", QString::null ) << endl;
                    context.fillStyleStack( spanElem, KoXmlNS::text, "style-name", "text" );
                    text = spanElem.text();
                }
                textData = KoTextObject::customItemChar(); // hyperlink placeholder
                // unused tag.attributeNS( KoXmlNS::office, "name", QString::null )
                KoVariableCollection& coll = context.variableCollection();
                customItem = new KoLinkVariable( this, text, href,
                        coll.formatCollection()->format( "STRING" ),
                        &coll );
            }
            return true;
        }
    }
    else // non "text:" tags
    {
        kdDebug()<<"Extension found tagName : "<< localName <<endl;
    }
    return false;
}
Exemplo n.º 19
0
/// \cond
bool QXmppMamResultIq::isMamResultIq(const QDomElement &element)
{
    if (element.tagName() == "iq") {
        QDomElement finElement = element.firstChildElement("fin");
        if (!finElement.isNull() && finElement.namespaceURI() == ns_mam) {
            return true;
        }
    }
    return false;
}
Exemplo n.º 20
0
void XmppStream::processFeatures()
{
	bool started = false;
	while (!started && !FAvailFeatures.isEmpty())
	{
		QString featureNS = FAvailFeatures.takeFirst();
		QDomElement featureElem = FServerFeatures.firstChildElement();
		while (!featureElem.isNull() && featureElem.namespaceURI()!=featureNS)
			featureElem = featureElem.nextSiblingElement();
		started = featureElem.namespaceURI()==featureNS ? startFeature(featureNS, featureElem) : false;
	}
	if (!started)
	{
		LogDetail(QString("[XmppStream][%1] XMPP stream opened").arg(FStreamJid.bare()));
		FOpen = true;
		FStreamState = SS_ONLINE;
		emit opened();
	}
}
Exemplo n.º 21
0
bool JingleContent::setOutgoingTransport(const QDomElement &ATransport)
{
    if (ATransport.namespaceURI() == FTransportIncoming.namespaceURI())
    {
        FTransportOutgoing = FDocument.importNode(ATransport, true).toElement();
        return true;
    }
    else
        return false;
}
Exemplo n.º 22
0
/// \cond
bool QXmppMamQueryIq::isMamQueryIq(const QDomElement &element)
{
    if (element.tagName() == "iq") {
        QDomElement queryElement = element.firstChildElement("query");
        if (!queryElement.isNull() && queryElement.namespaceURI() == ns_mam) {
            return true;
        }
    }
    return false;
}
Exemplo n.º 23
0
QDomElement Stanza::findElement(const QDomElement &AParent, const QString &ATagName, const QString &ANamespace)
{
	QDomElement elem = AParent.firstChildElement(ATagName);
	if (!ANamespace.isNull())
	{
		while (!elem.isNull() && elem.namespaceURI()!=ANamespace)
			elem = elem.nextSiblingElement(ATagName);
	}
	return elem;
}
void QXmppIncomingServer::handleStanza(const QDomElement &stanza)
{
    const QString ns = stanza.namespaceURI();

    if (ns == ns_tls && stanza.tagName() == QLatin1String("starttls"))
    {
        sendData("<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
        socket()->flush();
        socket()->startServerEncryption();
        return;
    }
    else if (QXmppDialback::isDialback(stanza))
    {
        QXmppDialback request;
        request.parse(stanza);
        // check the request is valid
        if (!request.type().isEmpty() ||
            request.from().isEmpty() ||
            request.to() != d->domain ||
            request.key().isEmpty())
        {
            warning(QString("Invalid dialback received on %1").arg(d->origin()));
            return;
        }

        const QString domain = request.from();
        if (request.command() == QXmppDialback::Result)
        {
            debug(QString("Received a dialback result from '%1' on %2").arg(domain, d->origin()));

            // establish dialback connection
            QXmppOutgoingServer *stream = new QXmppOutgoingServer(d->domain, this);
            bool check = connect(stream, SIGNAL(dialbackResponseReceived(QXmppDialback)),
                                 this, SLOT(slotDialbackResponseReceived(QXmppDialback)));
            Q_ASSERT(check);
            Q_UNUSED(check);
            stream->setVerify(d->localStreamId, request.key());
            stream->connectToHost(domain);
        }
        else if (request.command() == QXmppDialback::Verify)
        {
            debug(QString("Received a dialback verify from '%1' on %2").arg(domain, d->origin()));
            emit dialbackRequestReceived(request);
        }

    }
    else if (d->authenticated.contains(QXmppUtils::jidToDomain(stanza.attribute("from"))))
    {
        // relay stanza if the remote party is authenticated
        emit elementReceived(stanza);
    } else {
        warning(QString("Received an element from unverified domain '%1' on %2").arg(QXmppUtils::jidToDomain(stanza.attribute("from")), d->origin()));
        disconnectFromHost();
    }
}
Exemplo n.º 25
0
/// \cond
void QXmppJingleIq::Content::parse(const QDomElement &element)
{
    d->creator = element.attribute("creator");
    d->disposition = element.attribute("disposition");
    d->name = element.attribute("name");
    d->senders = element.attribute("senders");

    // description
    QDomElement descriptionElement = element.firstChildElement("description");
    d->descriptionType = descriptionElement.namespaceURI();
    d->descriptionMedia = descriptionElement.attribute("media");
    d->descriptionSsrc = descriptionElement.attribute("ssrc").toULong();
    QDomElement child = descriptionElement.firstChildElement("payload-type");
    while (!child.isNull())
    {
        QXmppJinglePayloadType payload;
        payload.parse(child);
        d->payloadTypes << payload;
        child = child.nextSiblingElement("payload-type");
    }

    // transport
    QDomElement transportElement = element.firstChildElement("transport");
    d->transportType = transportElement.namespaceURI();
    d->transportUser = transportElement.attribute("ufrag");
    d->transportPassword = transportElement.attribute("pwd");
    child = transportElement.firstChildElement("candidate");
    while (!child.isNull()) {
        QXmppJingleCandidate candidate;
        candidate.parse(child);
        d->transportCandidates << candidate;
        child = child.nextSiblingElement("candidate");
    }
    child = transportElement.firstChildElement("fingerprint");

    /// XEP-0320
    if (!child.isNull()) {
        d->transportFingerprint = parseFingerprint(child.text());
        d->transportFingerprintHash = child.attribute("hash");
        d->transportFingerprintSetup = child.attribute("setup");
    }
}
Exemplo n.º 26
0
/**
 * \brief obtain direct child elements of a certain kind.  unlike
 *        elementsByTagNameNS, this function does not descend beyond the first
 *        level of children.
 * \param e parent element
 * \param nsURI namespace of the elements to find
 * \param localName local name of the elements to find
 * \return the node list of found elements (empty list if none are found)
 */
XDomNodeList childElementsByTagNameNS(const QDomElement &e, const QString &nsURI, const QString &localName)
{
	XDomNodeList out;
	for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
		if(!n.isElement())
			continue;
		QDomElement i = n.toElement();
		if(i.namespaceURI() == nsURI && i.localName() == localName)
			out.append(i);
	}
	return out;
}
QXmppMessage QXmppMessage::parseForward(QDomElement &element)
{
    QXmppMessage result;
    if (!element.isNull() && element.namespaceURI() == ns_stanza_forwarding)
    {
        QDomElement msgElement = element.firstChildElement("message");

        QXmppMessage fwd;
        fwd.parse(msgElement);

        QDomElement delayElement = element.firstChildElement("delay");
        if (!delayElement.isNull() && delayElement.namespaceURI() == ns_delayed_delivery) {
            const QString str = delayElement.attribute("stamp");
            fwd.d->stamp = QXmppUtils::datetimeFromString(str);
            fwd.d->stampType = DelayedDelivery;
        }

        result = fwd;
    }
    return result;
}
Exemplo n.º 28
0
Stanza::Stanza(Stream *s, const QDomElement &e)
{
	Q_ASSERT(s);
	d = 0;
	if(e.namespaceURI() != s->baseNS())
		return;
	int x = Private::stringToKind(e.tagName());
	if(x == -1)
		return;
	d = new Private;
	d->s = s;
	d->e = e;
}
void QXmppStreamFeatures::parse(const QDomElement &element)
{
    m_bindMode = readFeature(element, "bind", ns_bind);
    m_sessionMode = readFeature(element, "session", ns_session);
    m_nonSaslAuthMode = readFeature(element, "auth", ns_authFeature);
    m_tlsMode = readFeature(element, "starttls", ns_tls);

    // parse advertised compression methods
    QDomElement compression = element.firstChildElement("compression");
    if (compression.namespaceURI() == ns_compressFeature)
    {
        QDomElement subElement = compression.firstChildElement("method");
        while(!subElement.isNull())
        {
            if (subElement.text() == QLatin1String("zlib"))
                m_compressionMethods << QXmppConfiguration::ZlibCompression;
            subElement = subElement.nextSiblingElement("method");
        }
    }

    // parse advertised SASL Authentication mechanisms
    QDomElement mechs = element.firstChildElement("mechanisms");
    if (mechs.namespaceURI() == ns_sasl)
    {
        QDomElement subElement = mechs.firstChildElement("mechanism");
        while(!subElement.isNull())
        {
            if (subElement.text() == QLatin1String("PLAIN"))
                m_authMechanisms << QXmppConfiguration::SASLPlain;
            else if (subElement.text() == QLatin1String("DIGEST-MD5"))
                m_authMechanisms << QXmppConfiguration::SASLDigestMD5;
            else if (subElement.text() == QLatin1String("ANONYMOUS"))
                m_authMechanisms << QXmppConfiguration::SASLAnonymous;
            else if (subElement.text() == QLatin1String("X-FACEBOOK-PLATFORM"))
                m_authMechanisms << QXmppConfiguration::SASLXFacebookPlatform;
            subElement = subElement.nextSiblingElement("mechanism");
        }
    }
}
Exemplo n.º 30
0
static QXmppStreamFeatures::Mode readFeature(const QDomElement &element, const char *tagName, const char *tagNs)
{
    QDomElement subElement = element.firstChildElement(tagName);
    if (subElement.namespaceURI() == tagNs)
    {
        if (!subElement.firstChildElement("required").isNull())
            return QXmppStreamFeatures::Required;
        else
            return QXmppStreamFeatures::Enabled;
    } else {
        return QXmppStreamFeatures::Disabled;
    }
}