X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fpeer.h;h=b9dfed1612d4c1ff38a2b190b398d4356233f915;hp=41c82cfabb7c66eab57ec832902ef0267e37d93a;hb=d367542ce54ed86fd3c8dbdbbf8210fc9a19a882;hpb=fd25e92f19d6afd4eb02844bcbf20ba132868303 diff --git a/src/common/peer.h b/src/common/peer.h index 41c82cfa..b9dfed16 100644 --- a/src/common/peer.h +++ b/src/common/peer.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * + * Copyright (C) 2005-2015 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,8 +21,10 @@ #ifndef PEER_H #define PEER_H -#include +#include +#include +#include "authhandler.h" #include "protocol.h" #include "signalproxy.h" @@ -31,13 +33,15 @@ class Peer : public QObject Q_OBJECT public: - Peer(QObject *parent = 0) : QObject(parent) {} + Peer(AuthHandler *authHandler, QObject *parent = 0); virtual QString description() const = 0; virtual SignalProxy *signalProxy() const = 0; virtual void setSignalProxy(SignalProxy *proxy) = 0; + AuthHandler *authHandler() const; + virtual bool isOpen() const = 0; virtual bool isSecure() const = 0; virtual bool isLocal() const = 0; @@ -45,27 +49,49 @@ public: virtual int lag() const = 0; public slots: - virtual void dispatch(const Protocol::SyncMessage &msg) = 0; - virtual void dispatch(const Protocol::RpcCall &msg) = 0; - virtual void dispatch(const Protocol::InitRequest &msg) = 0; - virtual void dispatch(const Protocol::InitData &msg) = 0; + /* Handshake messages */ + virtual void dispatch(const Protocol::RegisterClient &) = 0; + virtual void dispatch(const Protocol::ClientDenied &) = 0; + virtual void dispatch(const Protocol::ClientRegistered &) = 0; + virtual void dispatch(const Protocol::SetupData &) = 0; + virtual void dispatch(const Protocol::SetupFailed &) = 0; + virtual void dispatch(const Protocol::SetupDone &) = 0; + virtual void dispatch(const Protocol::Login &) = 0; + virtual void dispatch(const Protocol::LoginFailed &) = 0; + virtual void dispatch(const Protocol::LoginSuccess &) = 0; + virtual void dispatch(const Protocol::SessionState &) = 0; + + /* Sigproxy messages */ + virtual void dispatch(const Protocol::SyncMessage &) = 0; + virtual void dispatch(const Protocol::RpcCall &) = 0; + virtual void dispatch(const Protocol::InitRequest &) = 0; + virtual void dispatch(const Protocol::InitData &) = 0; virtual void close(const QString &reason = QString()) = 0; signals: void disconnected(); - void error(QAbstractSocket::SocketError); void secureStateChanged(bool secure = true); void lagUpdated(int msecs); protected: - template + template void handle(const T &protoMessage); + +private: + QPointer _authHandler; }; +// We need to special-case Peer* in attached signals/slots, so typedef it for the meta type system +typedef Peer * PeerPtr; +Q_DECLARE_METATYPE(PeerPtr) + +QDataStream &operator<<(QDataStream &out, PeerPtr ptr); +QDataStream &operator>>(QDataStream &in, PeerPtr &ptr); + // Template method needed in the header -template inline +template inline void Peer::handle(const T &protoMessage) { switch(protoMessage.handler()) { @@ -77,6 +103,14 @@ void Peer::handle(const T &protoMessage) signalProxy()->handle(this, protoMessage); break; + case Protocol::AuthHandler: + if (!authHandler()) { + qWarning() << Q_FUNC_INFO << "Cannot handle auth messages without an active AuthHandler!"; + return; + } + authHandler()->handle(protoMessage); + break; + default: qWarning() << Q_FUNC_INFO << "Unknown handler for protocol message!"; return;