aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-26 11:27:41 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-26 11:27:41 +0000
commit30c69f182049d456ce8d37df72a9c4456afab789 (patch)
tree22e3e06a476ff005abf7098a7426e957bbab5aa8 /src
parentd4c0573bbd8336576126417ad325bf04f0f5a753 (diff)
downloadqxmpp-30c69f182049d456ce8d37df72a9c4456afab789.tar.gz
remove experimental QXmppClient::elementReceived() in favour of an extension mechanisms
Diffstat (limited to 'src')
-rw-r--r--src/QXmppClient.cpp31
-rw-r--r--src/QXmppClient.h31
2 files changed, 47 insertions, 15 deletions
diff --git a/src/QXmppClient.cpp b/src/QXmppClient.cpp
index 9732b959..d15e16e0 100644
--- a/src/QXmppClient.cpp
+++ b/src/QXmppClient.cpp
@@ -44,6 +44,7 @@ class QXmppClientPrivate
public:
QXmppClientPrivate();
+ QList<QXmppClientExtension*> extensions;
QXmppOutgoingClient* stream; ///< Pointer to QXmppOutgoingClient object a wrapper over
///< TCP socket and XMPP protocol
QXmppPresence clientPresence; ///< Stores the current presence of the connected client
@@ -115,7 +116,7 @@ QXmppClient::QXmppClient(QObject *parent)
d->clientPresence.setExtensions(d->stream->presenceExtensions());
bool check = connect(d->stream, SIGNAL(elementReceived(const QDomElement&, bool&)),
- this, SIGNAL(elementReceived(const QDomElement&, bool&)));
+ this, SLOT(slotElementReceived(const QDomElement&, bool&)));
Q_ASSERT(check);
check = connect(d->stream, SIGNAL(messageReceived(const QXmppMessage&)),
@@ -177,9 +178,20 @@ QXmppClient::QXmppClient(QObject *parent)
QXmppClient::~QXmppClient()
{
+ foreach (QXmppClientExtension *extension, d->extensions)
+ delete d;
delete d;
}
+/// Registers a new extension with the client.
+///
+/// \param extension
+
+void QXmppClient::addExtension(QXmppClientExtension *extension)
+{
+ d->extensions << extension;
+}
+
/// Returns a modifiable reference to the current configuration of QXmppClient.
/// \return Reference to the QXmppClient's configuration for the connection.
@@ -464,6 +476,23 @@ QXmppVCardManager& QXmppClient::vCardManager()
return *d->vCardManager;
}
+/// Give extensions a chance to handle incoming stanzas.
+///
+/// \param element
+/// \param handled
+
+void QXmppClient::slotElementReceived(const QDomElement &element, bool &handled)
+{
+ foreach (QXmppClientExtension *extension, d->extensions)
+ {
+ if (extension->handleStanza(d->stream, element))
+ {
+ handled = true;
+ return;
+ }
+ }
+}
+
void QXmppClient::addInvokableInterface( QXmppInvokable *interface )
{
d->interfaces[ interface->metaObject()->className() ] = interface;
diff --git a/src/QXmppClient.h b/src/QXmppClient.h
index 8698f7d5..e6360037 100644
--- a/src/QXmppClient.h
+++ b/src/QXmppClient.h
@@ -25,14 +25,14 @@
#define QXMPPCLIENT_H
#include <QObject>
-#include <QTcpSocket>
-#include <QHash>
+#include <QAbstractSocket>
#include <QVariant>
#include "QXmppConfiguration.h"
#include "QXmppLogger.h"
#include "QXmppPresence.h"
+class QXmppClientExtension;
class QXmppClientPrivate;
class QXmppPresence;
class QXmppMessage;
@@ -42,6 +42,7 @@ class QXmppInvokable;
class QXmppRpcInvokeIq;
class QXmppRemoteMethod;
struct QXmppRemoteMethodResult;
+class QXmppStream;
// managers
class QXmppArchiveManager;
@@ -91,6 +92,9 @@ public:
QXmppClient(QObject *parent = 0);
~QXmppClient();
+
+ void addExtension(QXmppClientExtension *extension);
+
void connectToServer(const QString& host,
const QString& user,
const QString& passwd,
@@ -200,18 +204,6 @@ signals:
/// know the error.
void error(QXmppClient::Error);
- /// This signal is emitted when a raw XML element is received. You can
- /// connect to this signal if you want to handle raw XML elements yourself.
- ///
- /// WARNING: this signal is experimental and you can seriously disrupt
- /// packet handling when using it, so use with care and at your own risk.
- ///
- /// Set 'handled' to true if you handled the element yourself and you wish
- /// to bypass normal handling for the element. If you do this, QXmpp will
- /// do absolutely no processing itself, so do not expect the usual signals
- /// to be emitted.
- void elementReceived(const QDomElement &element, bool &handled);
-
/// Notifies that an XMPP message stanza is received. The QXmppMessage
/// parameter contains the details of the message sent to this client.
/// In other words whenever someone sends you a message this signal is
@@ -241,6 +233,7 @@ public slots:
void sendMessage(const QString& bareJid, const QString& message);
private slots:
+ void slotElementReceived(const QDomElement &element, bool &handled);
void invokeInterfaceMethod( const QXmppRpcInvokeIq &iq );
void xmppConnected();
@@ -248,4 +241,14 @@ private:
QXmppClientPrivate * const d;
};
+/// \brief The QXmppClientExtension is the base class for QXmppClient
+/// extensions.
+///
+
+class QXmppClientExtension
+{
+public:
+ virtual bool handleStanza(QXmppStream *stream, const QDomElement &stanza) = 0;
+};
+
#endif // QXMPPCLIENT_H