From: APTX Date: Wed, 20 Feb 2013 17:24:53 +0000 (+0100) Subject: Remove the proxy client. It wasn't used, lml provides an alternative solution. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=95d344c62cbfb097379412e88ac12859923420a0;p=anidbudpclient.git Remove the proxy client. It wasn't used, lml provides an alternative solution. --- diff --git a/anidbudpclient.pro b/anidbudpclient.pro index 81e5eb2..a4e13dc 100644 --- a/anidbudpclient.pro +++ b/anidbudpclient.pro @@ -89,27 +89,6 @@ CONV_HEADERS += include/AniDBUdpClient/Client \ 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 } diff --git a/include/AniDBUdpClient/ProxyClient b/include/AniDBUdpClient/ProxyClient deleted file mode 100644 index 84303a9..0000000 --- a/include/AniDBUdpClient/ProxyClient +++ /dev/null @@ -1 +0,0 @@ -#include "../../proxyclient.h" \ No newline at end of file diff --git a/include/AniDBUdpClient/ProxyServer b/include/AniDBUdpClient/ProxyServer deleted file mode 100644 index 000738a..0000000 --- a/include/AniDBUdpClient/ProxyServer +++ /dev/null @@ -1 +0,0 @@ -#include "../../proxyserver.h" diff --git a/proxyclient.cpp b/proxyclient.cpp deleted file mode 100644 index 3ec8d7b..0000000 --- a/proxyclient.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "proxyclient.h" - -#include - -#include "abstractcommand.h" - -#include - -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::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 diff --git a/proxyclient.h b/proxyclient.h deleted file mode 100644 index c91c5ab..0000000 --- a/proxyclient.h +++ /dev/null @@ -1,59 +0,0 @@ -#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::ReplyType *send(const T &command, QObject *parent = 0) - { - typename T::ReplyType *reply = createReply(command, parent); - send(reply); - return reply; - } - -protected: - template 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 commands; -}; - -} // namespace AniDBUdpClient - -#endif // PROXYCLIENT_H diff --git a/proxyserver.cpp b/proxyserver.cpp deleted file mode 100644 index ae6e307..0000000 --- a/proxyserver.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include "proxyserver.h" -#include - -#include "client.h" -#include "rawcommand.h" - -#include - -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::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::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 diff --git a/proxyserver.h b/proxyserver.h deleted file mode 100644 index df3a1a4..0000000 --- a/proxyserver.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef PROXYSERVER_H -#define PROXYSERVER_H - -#include "anidbudpclient_global.h" -#include -#include - -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 clientInfo; - QMap clientCommands; - QMap idMapping; - QMap replyMapping; -}; - -} // namespace AniDBUdpClient - -#endif // PROXYSERVER_H