include/AniDBUdpClient/ClientQueuedCommandsModel \
include/AniDBUdpClient/FileRenameDelegate
-# proxy files
-
-!noproxy {
-
- CONFIG += qxt
- QXT *= network
-
- HEADERS += proxyclient.h \
- proxyserver.h \
-
- SOURCES += proxyclient.cpp \
- proxyserver.cpp \
-
- CONV_HEADERS += include/AniDBUdpClient/ProxyClient \
- include/AniDBUdpClient/ProxyServer
-}
-noproxy {
- DEFINES += ANIDBUDPCLIENT_NO_PROXY
- message(Disabled proxy support)
-}
-
!noencrypt {
CONFIG += crypto
}
+++ /dev/null
-#include "../../proxyclient.h"
\ No newline at end of file
+++ /dev/null
-#include "../../proxyserver.h"
+++ /dev/null
-#include "proxyclient.h"
-
-#include <QxtRPCPeer>
-
-#include "abstractcommand.h"
-
-#include <QDebug>
-
-namespace AniDBUdpClient {
-
-ProxyClient::ProxyClient(QObject *parent) :
- ClientInterface(parent), peer(new QxtRPCPeer)
-{
- m_hostPort = 9001;
- peer->attachSlot("replyRecieved", this, SLOT(replyRecieved(QByteArray,int,QString)));
- peer->attachSlot("errorRecieved", this, SLOT(errorRecieved(int)));
-}
-
-ProxyClient::~ProxyClient()
-{
- disconnect();
- delete peer;
-}
-
-QString ProxyClient::user() const
-{
- return m_user;
-}
-
-void ProxyClient::setUser(const QString &user)
-{
- m_user = user;
-}
-
-QString ProxyClient::pass() const
-{
- return m_pass;
-}
-
-void ProxyClient::setPass(const QString &pass)
-{
- m_pass = pass;
-}
-
-void ProxyClient::connect()
-{
- peer->connect(m_host, m_hostPort);
- peer->call("auth", m_user, m_pass);
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[CLIENT] CALL auth" << m_user << m_pass;
-#endif
-}
-
-void ProxyClient::disconnect(bool graceful)
-{
- Q_UNUSED(graceful);
- peer->disconnectServer();
-
- for (QMap<QByteArray, AbstractReply *>::const_iterator i = commands.constBegin(); i != commands.constEnd(); ++i)
- {
- i.value()->setRawReply(CLIENT_DESTROYED, "");
- }
- commands.clear();
-}
-
-void ProxyClient::send(AbstractReply *reply)
-{
- if (reply->command().waitForResult())
- commands[reply->id()] = reply;
-
- Command cmd = reply->command().rawCommand();
- peer->call("sendCommand", reply->id(), buildCmd(cmd.first, cmd.second));
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[CLIENT] CALL sendCommand" << reply->id() << buildCmd(cmd.first, cmd.second);
-#endif
- if (!reply->command().waitForResult())
- delete reply;
-}
-
-void ProxyClient::cancel(AbstractReply *command)
-{
- peer->call("cancel", command->id());
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[CLIENT] CALL cancel";
-#endif
-}
-
-void ProxyClient::replyRecieved(const QByteArray &id, int replyCodeAsInt, const QString &reply)
-{
- ReplyCode replyCode = (ReplyCode) replyCodeAsInt;
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[CLIENT] RECV replyRecieved" << id << replyCode << reply;
-#endif
- AbstractReply *command = commands.value(id, 0);
-
- if (!command)
- {
- // Not interested in this reply
- return;
- }
-
- command->setRawReply(replyCode, reply);
-}
-
-void ProxyClient::errorRecieved(int errorAsInt)
-{
- Error error = (Error) errorAsInt;
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[CLIENT] RECV errorRecieved" << error;
-#endif
- m_error = error;
- emit connectionError();
-}
-
-} // namespace AniDBUdpClient
+++ /dev/null
-#ifndef PROXYCLIENT_H
-#define PROXYCLIENT_H
-
-#include "anidbudpclient_global.h"
-#include "clientinterface.h"
-
-class QxtRPCPeer;
-
-namespace AniDBUdpClient {
-
-class ANIDBUDPCLIENTSHARED_EXPORT ProxyClient : public ClientInterface
-{
- Q_OBJECT
-public:
- explicit ProxyClient(QObject *parent = 0);
- ~ProxyClient();
-
- QString user() const;
- void setUser(const QString &user);
- QString pass() const;
- void setPass(const QString &pass);
-
- template<typename T> typename T::ReplyType *send(const T &command, QObject *parent = 0)
- {
- typename T::ReplyType *reply = createReply(command, parent);
- send(reply);
- return reply;
- }
-
-protected:
- template<typename T> typename T::ReplyType *createReply(const T &command, QObject *parent = 0)
- {
- return new typename T::ReplyType(command, nextCommandId(), parent);
- }
-
-public slots:
- void connect();
- void disconnect(bool graceful = false);
-
- void send(AbstractReply *reply);
-
- void cancel(AbstractReply *command);
-
-private slots:
- void replyRecieved(const QByteArray &id, int replyCodeAsInt, const QString &reply);
- void errorRecieved(int errorAsInt);
-
-private:
- QString m_user;
- QString m_pass;
-
- QxtRPCPeer *peer;
-
- QMap<QByteArray, AbstractReply *> commands;
-};
-
-} // namespace AniDBUdpClient
-
-#endif // PROXYCLIENT_H
+++ /dev/null
-#include "proxyserver.h"
-#include <QxtRPCPeer>
-
-#include "client.h"
-#include "rawcommand.h"
-
-#include <QDebug>
-
-namespace AniDBUdpClient {
-
-ProxyServer::ProxyServer(QObject *parent) :
- QObject(parent), peer(new QxtRPCPeer)
-{
- connect(peer, SIGNAL(clientConnected(quint64)), this, SLOT(clientConnected(quint64)));
- connect(peer, SIGNAL(clientDisconnected(quint64)), this, SLOT(clientDisconnected(quint64)));
- peer->attachSlot("auth", this, SLOT(auth(quint64,QString,QString)));
- peer->attachSlot("sendCommand", this, SLOT(sendCommand(quint64,QByteArray,QByteArray)));
- peer->attachSlot("cancel", this, SLOT(cancel(quint64,QByteArray)));
-}
-
-ProxyServer::~ProxyServer()
-{
- peer->disconnectAll();
-
- clientInfo.clear();
- clientCommands.clear();
- qDeleteAll(idMapping);
- idMapping.clear();
-/* for (QMap<RawReply *, QByteArray>::const_iterator i = replyMapping.constBegin(); i != replyMapping.constEnd(); ++i)
- {
- i.key()->deleteLater();
- }
-*/
- replyMapping.clear();
-
- delete peer;
-}
-
-QString ProxyServer::user() const
-{
- return m_user;
-}
-
-void ProxyServer::setUser(const QString &user)
-{
- m_user = user;
-}
-
-QString ProxyServer::pass() const
-{
- return m_pass;
-}
-
-void ProxyServer::setPass(const QString &pass)
-{
- m_pass = pass;
-}
-
-bool ProxyServer::listen(QHostAddress iface, int port)
-{
- return peer->listen(iface, port);
-}
-
-void ProxyServer::diconnect()
-{
- peer->disconnectAll();
-}
-
-void ProxyServer::auth(quint64 client, const QString &user, const QString &pass)
-{
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[SERVER] RECV auth" << client << user << pass;
-#endif
- if (isAuthed(client))
- return;
-
- if (m_user != user || m_pass != pass)
- {
- peer->call(client, "errorRecieved", (int) AuthenticationError);
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[SERVER] CALL errorRecieved" << AuthenticationError;
-#endif
- peer->disconnectClient(client);
- return;
- }
- clientInfo[client].authed = true;
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[SERVER] Auth successful" << client;
-#endif
-
-}
-
-void ProxyServer::sendCommand(quint64 client, const QByteArray &id, const QByteArray &rawCommand)
-{
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[SERVER] RECV sendCommand" << client << id << rawCommand;
-#endif
- if (!isAuthed(client))
- return;
-
- RawReply *reply = Client::instance()->send(RawCommand(rawCommand));
- connect(reply, SIGNAL(replyReady(bool)), this, SLOT(replyReady(bool)));
-
- clientCommands[id] = client;
- replyMapping[reply] = id;
- idMapping[id] = reply;
-}
-
-void ProxyServer::cancel(quint64 client, const QByteArray &id)
-{
- if (!isAuthed(client))
- return;
-
- if (!idMapping.contains(id))
- return;
-
- RawReply *reply = idMapping.take(id);
- replyMapping.remove(reply);
- clientCommands.remove(id);
-
- Client::instance()->cancel(reply);
- reply->deleteLater();
-}
-
-void ProxyServer::clientConnected(quint64 client)
-{
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "client connected" << client;
-#endif
- clientInfo.insert(client, ClientInfo());
-}
-
-void ProxyServer::clientDisconnected(quint64 client)
-{
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[SERVER] RECV client disconnected" << client;
-#endif
- for (QMap<QByteArray, quint64>::iterator i = clientCommands.begin(); i != clientCommands.end(); )
- {
- if (i.value() != client)
- {
- ++i;
- continue;
- }
-
- RawReply *reply = idMapping.take(i.key());
- Client::instance()->cancel(reply);
- replyMapping.remove(reply);
- reply->deleteLater();
- clientCommands.erase(i);
- }
-
- clientInfo.remove(client);
-}
-
-void ProxyServer::replyReady(bool success)
-{
- Q_UNUSED(success);
-
- RawReply *reply = (RawReply *) sender();
-
- QByteArray id = replyMapping.take(reply);
- quint64 client = clientCommands.take(id);
- idMapping.remove(id);
-
- peer->call(client, "replyRecieved", id, (int) reply->replyCode(), reply->rawReply());
-#ifdef ANIDBUDPCLIENT_PROXY_DEBUG
-qDebug() << "[SERVER] CALL replyRecieved" << id << reply->replyCode() << reply->rawReply();
-#endif
- reply->deleteLater();
-}
-
-bool ProxyServer::isAuthed(quint64 client) const
-{
- return clientInfo[client].authed;
-}
-
-} // namespace AniDBUdpClient
+++ /dev/null
-#ifndef PROXYSERVER_H
-#define PROXYSERVER_H
-
-#include "anidbudpclient_global.h"
-#include <QObject>
-#include <QHostAddress>
-
-class QxtRPCPeer;
-
-namespace AniDBUdpClient {
-
-class RawReply;
-
-class ANIDBUDPCLIENTSHARED_EXPORT ProxyServer : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString user READ user WRITE setUser)
- Q_PROPERTY(QString pass READ pass WRITE setPass)
-
- struct ClientInfo {
- bool authed;
-
- explicit ClientInfo() : authed(false) {}
- };
-
-public:
- explicit ProxyServer(QObject *parent = 0);
- ~ProxyServer();
-
- QString user() const;
- void setUser(const QString &user);
- QString pass() const;
- void setPass(const QString &pass);
-
-signals:
-
-public slots:
- bool listen(QHostAddress iface = QHostAddress::Any, int port = 9001);
- void diconnect();
-
-private slots:
- void auth(quint64 client, const QString &user, const QString &pass);
- void sendCommand(quint64 client, const QByteArray &id, const QByteArray &rawCommand);
- void cancel(quint64 client, const QByteArray &id);
-
- void clientConnected(quint64 client);
- void clientDisconnected(quint64 client);
-
- void replyReady(bool success);
-
-private:
- bool isAuthed(quint64 client) const;
-
- QString m_user;
- QString m_pass;
-
- QxtRPCPeer *peer;
-
- QMap<quint64, ClientInfo> clientInfo;
- QMap<QByteArray, quint64> clientCommands;
- QMap<QByteArray, RawReply *> idMapping;
- QMap<RawReply *, QByteArray> replyMapping;
-};
-
-} // namespace AniDBUdpClient
-
-#endif // PROXYSERVER_H