aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-13 17:00:58 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-13 17:00:58 +0000
commit174735b46026f9aeb62ddede04f6c0be7fa2418f (patch)
treef79171ef968327eab6b9103613bc130108e55ec3 /src
parent0acf07023dca6b6d35c347cb28dce44a04363019 (diff)
downloadqxmpp-174735b46026f9aeb62ddede04f6c0be7fa2418f.tar.gz
add QXmppStreamFeatures
Diffstat (limited to 'src')
-rw-r--r--src/QXmppStreamFeatures.cpp159
-rw-r--r--src/QXmppStreamFeatures.h59
-rw-r--r--src/src.pro2
3 files changed, 220 insertions, 0 deletions
diff --git a/src/QXmppStreamFeatures.cpp b/src/QXmppStreamFeatures.cpp
new file mode 100644
index 00000000..537972cb
--- /dev/null
+++ b/src/QXmppStreamFeatures.cpp
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2008-2010 The QXmpp developers
+ *
+ * Author:
+ * Jeremy Lainé
+ *
+ * Source:
+ * http://code.google.com/p/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ */
+
+#include <QDebug>
+#include <QDomElement>
+
+#include "QXmppConstants.h"
+#include "QXmppStreamFeatures.h"
+
+QXmppStreamFeatures::QXmppStreamFeatures()
+ : m_bindAvailable(false),
+ m_sessionAvailable(false),
+ m_securityMode(QXmppConfiguration::TLSEnabled)
+{
+}
+
+bool QXmppStreamFeatures::isBindAvailable() const
+{
+ return m_bindAvailable;
+}
+
+void QXmppStreamFeatures::setBindAvailable(bool available)
+{
+ m_bindAvailable = available;
+}
+
+bool QXmppStreamFeatures::isSessionAvailable() const
+{
+ return m_sessionAvailable;
+}
+
+void QXmppStreamFeatures::setSessionAvailable(bool available)
+{
+ m_sessionAvailable = available;
+}
+
+QList<QXmppConfiguration::SASLAuthMechanism> QXmppStreamFeatures::authMechanisms() const
+{
+ return m_authMechanisms;
+}
+
+void QXmppStreamFeatures::setAuthMechanisms(QList<QXmppConfiguration::SASLAuthMechanism> &mechanisms)
+{
+ m_authMechanisms = mechanisms;
+}
+
+QXmppConfiguration::StreamSecurityMode QXmppStreamFeatures::securityMode() const
+{
+ return m_securityMode;
+}
+
+void QXmppStreamFeatures::setSecurityMode(QXmppConfiguration::StreamSecurityMode mode)
+{
+ m_securityMode = mode;
+}
+
+void QXmppStreamFeatures::parse(const QDomElement &element)
+{
+ m_bindAvailable = !element.firstChildElement("bind").isNull();
+ m_sessionAvailable = !element.firstChildElement("session").isNull();
+
+ // parse advertised SASL Authentication mechanisms
+ QDomElement mechs = element.firstChildElement("mechanisms");
+ QDomElement subElement = mechs.firstChildElement("mechanism");
+ qDebug("SASL Authentication mechanisms:");
+ while(!subElement.isNull())
+ {
+ qDebug() << subElement.text();
+ 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;
+ subElement = subElement.nextSiblingElement("mechanism");
+ }
+
+ // parse advertised TLS mode
+ QDomElement tlsElement = element.firstChildElement("starttls");
+ if (!tlsElement.isNull())
+ {
+ if (tlsElement.firstChildElement().tagName() == "required")
+ m_securityMode = QXmppConfiguration::TLSRequired;
+ else
+ m_securityMode = QXmppConfiguration::TLSEnabled;
+ } else {
+ m_securityMode = QXmppConfiguration::TLSDisabled;
+ }
+}
+
+void QXmppStreamFeatures::toXml(QXmlStreamWriter *writer) const
+{
+ writer->writeStartElement("stream:features");
+ if (m_bindAvailable)
+ {
+ writer->writeStartElement("bind");
+ writer->writeAttribute("xmlns", ns_bind);
+ writer->writeEndElement();
+ }
+ if (m_sessionAvailable)
+ {
+ writer->writeStartElement("session");
+ writer->writeAttribute("xmlns", ns_session);
+ writer->writeEndElement();
+ }
+ if (!m_authMechanisms.isEmpty())
+ {
+ writer->writeStartElement("mechanisms");
+ writer->writeAttribute("xmlns", ns_sasl);
+ for (int i = 0; i < m_authMechanisms.size(); i++)
+ {
+ writer->writeStartElement("mechanism");
+ switch (m_authMechanisms[i])
+ {
+ case QXmppConfiguration::SASLPlain:
+ writer->writeCharacters("PLAIN");
+ break;
+ case QXmppConfiguration::SASLDigestMD5:
+ writer->writeCharacters("DIGEST-MD5");
+ break;
+ case QXmppConfiguration::SASLAnonymous:
+ writer->writeCharacters("ANONYMOUS");
+ break;
+ }
+ writer->writeEndElement();
+ }
+ writer->writeEndElement();
+ }
+ if (m_securityMode != QXmppConfiguration::TLSDisabled)
+ {
+ writer->writeStartElement("starttls");
+ writer->writeAttribute("xmlns", ns_tls);
+ if (m_securityMode == QXmppConfiguration::TLSRequired)
+ writer->writeEmptyElement("required");
+ writer->writeEndElement();
+ }
+ writer->writeEndElement();
+}
+
diff --git a/src/QXmppStreamFeatures.h b/src/QXmppStreamFeatures.h
new file mode 100644
index 00000000..b31ca450
--- /dev/null
+++ b/src/QXmppStreamFeatures.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2008-2010 The QXmpp developers
+ *
+ * Author:
+ * Jeremy Lainé
+ *
+ * Source:
+ * http://code.google.com/p/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ */
+
+#ifndef QXMPPSTREAMFEATURES_H
+#define QXMPPSTREAMFEATURES_H
+
+#include "QXmppConfiguration.h"
+#include "QXmppStanza.h"
+
+class QXmppStreamFeatures : public QXmppStanza
+{
+public:
+ QXmppStreamFeatures();
+
+ bool isBindAvailable() const;
+ void setBindAvailable(bool available);
+
+ bool isSessionAvailable() const;
+ void setSessionAvailable(bool available);
+
+ QList<QXmppConfiguration::SASLAuthMechanism> authMechanisms() const;
+ void setAuthMechanisms(QList<QXmppConfiguration::SASLAuthMechanism> &mecanisms);
+
+ QXmppConfiguration::StreamSecurityMode securityMode() const;
+ void setSecurityMode(QXmppConfiguration::StreamSecurityMode mode);
+
+ /// \cond
+ void parse(const QDomElement &element);
+ void toXml(QXmlStreamWriter *writer) const;
+ /// \endcond
+
+private:
+ bool m_bindAvailable;
+ bool m_sessionAvailable;
+ QList<QXmppConfiguration::SASLAuthMechanism> m_authMechanisms;
+ QXmppConfiguration::StreamSecurityMode m_securityMode;
+};
+
+#endif
diff --git a/src/src.pro b/src/src.pro
index 7e421632..c850b896 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -50,6 +50,7 @@ HEADERS += QXmppUtils.h \
QXmppSocks.h \
QXmppStanza.h \
QXmppStream.h \
+ QXmppStreamFeatures.h \
QXmppStreamInitiationIq.h \
QXmppStun.h \
QXmppTransferManager.h \
@@ -92,6 +93,7 @@ SOURCES += QXmppUtils.cpp \
QXmppSocks.cpp \
QXmppStanza.cpp \
QXmppStream.cpp \
+ QXmppStreamFeatures.cpp \
QXmppStreamInitiationIq.cpp \
QXmppStun.cpp \
QXmppTransferManager.cpp \