aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2015-10-24 00:19:25 +0200
committerLinus Jahn <lnj@kaidan.im>2018-10-29 21:41:31 +0100
commit5559ed29681d031f36e7a7d011e3ec4bec3635f5 (patch)
treeb639a8c68f1d1255b5528bde34412ffc64a34fb6 /src/client
parent3e2ca3c04a5a681fa97ebabf6f31b301ec9753a0 (diff)
downloadqxmpp-5559ed29681d031f36e7a7d011e3ec4bec3635f5.tar.gz
Implement XEP-0352: Client State Indication
This commit is based on a pull request by fbeutel (GitHub) (see #87) and was rebased and slightly modified by me.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/QXmppClient.cpp23
-rw-r--r--src/client/QXmppClient.h3
-rw-r--r--src/client/QXmppOutgoingClient.cpp14
-rw-r--r--src/client/QXmppOutgoingClient.h1
4 files changed, 41 insertions, 0 deletions
diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp
index bd28288f..e851e5fe 100644
--- a/src/client/QXmppClient.cpp
+++ b/src/client/QXmppClient.cpp
@@ -54,6 +54,9 @@ public:
int reconnectionTries;
QTimer *reconnectionTimer;
+ // Client state indication
+ bool isActive;
+
void addProperCapability(QXmppPresence& presence);
int getNextReconnectTime() const;
@@ -68,6 +71,7 @@ QXmppClientPrivate::QXmppClientPrivate(QXmppClient *qq)
, receivedConflict(false)
, reconnectionTries(0)
, reconnectionTimer(0)
+ , isActive(true)
, q(qq)
{
}
@@ -320,6 +324,25 @@ bool QXmppClient::isConnected() const
return d->stream->isConnected();
}
+/// Returns true if the current client state is "active", false if it is
+/// "inactive". See XEP-0352 for details.
+
+bool QXmppClient::isActive() const
+{
+ return d->isActive;
+}
+
+/// Sets the client state as described in XEP-0352
+
+void QXmppClient::setActive(bool active)
+{
+ if (active != d->isActive && d->stream->isClientStateIndicationEnabled()) {
+ d->isActive = active;
+ QString packet = "<%1 xmlns='%2'/>";
+ d->stream->sendData(packet.arg(active ? "active" : "inactive", ns_csi).toUtf8());
+ }
+}
+
/// Returns the reference to QXmppRosterManager object of the client.
/// \return Reference to the roster object of the connected client. Use this to
/// get the list of friends in the roster and their presence information.
diff --git a/src/client/QXmppClient.h b/src/client/QXmppClient.h
index 22a7af65..6771f20c 100644
--- a/src/client/QXmppClient.h
+++ b/src/client/QXmppClient.h
@@ -140,6 +140,9 @@ public:
bool isAuthenticated() const;
bool isConnected() const;
+ bool isActive() const;
+ void setActive(bool active);
+
QXmppPresence clientPresence() const;
void setClientPresence(const QXmppPresence &presence);
diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp
index 9d5043d0..04929362 100644
--- a/src/client/QXmppOutgoingClient.cpp
+++ b/src/client/QXmppOutgoingClient.cpp
@@ -106,6 +106,9 @@ public:
QString resumeHost;
quint16 resumePort;
+ // Client State Indication
+ bool clientStateIndicationEnabled;
+
// Timers
QTimer *pingTimer;
QTimer *timeoutTimer;
@@ -126,6 +129,7 @@ QXmppOutgoingClientPrivate::QXmppOutgoingClientPrivate(QXmppOutgoingClient *qq)
, canResume(false)
, isResuming(false)
, resumePort(0)
+ , clientStateIndicationEnabled(false)
, pingTimer(0)
, timeoutTimer(0)
, q(qq)
@@ -294,6 +298,13 @@ bool QXmppOutgoingClient::isConnected() const
return QXmppStream::isConnected() && d->sessionStarted;
}
+/// Returns true if client state indication (xep-0352) is supported by the server
+
+bool QXmppOutgoingClient::isClientStateIndicationEnabled() const
+{
+ return d->clientStateIndicationEnabled;
+}
+
void QXmppOutgoingClient::_q_socketDisconnected()
{
debug("Socket disconnected");
@@ -400,6 +411,9 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv)
QXmppStreamFeatures features;
features.parse(nodeRecv);
+ if(features.clientStateIndicationMode() == QXmppStreamFeatures::Enabled)
+ d->clientStateIndicationEnabled = true;
+
if (!socket()->isEncrypted())
{
// determine TLS mode to use
diff --git a/src/client/QXmppOutgoingClient.h b/src/client/QXmppOutgoingClient.h
index 0edd0a5d..84607b83 100644
--- a/src/client/QXmppOutgoingClient.h
+++ b/src/client/QXmppOutgoingClient.h
@@ -55,6 +55,7 @@ public:
void connectToHost();
bool isAuthenticated() const;
bool isConnected() const;
+ bool isClientStateIndicationEnabled() const;
QSslSocket *socket() const { return QXmppStream::socket(); };
QXmppStanza::Error::Condition xmppStreamError();