summaryrefslogtreecommitdiff
path: root/plugins/Listener/catchcopy-v0002
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Listener/catchcopy-v0002')
-rw-r--r--plugins/Listener/catchcopy-v0002/DebugEngineMacro.h7
-rw-r--r--plugins/Listener/catchcopy-v0002/Environment.h3
-rw-r--r--plugins/Listener/catchcopy-v0002/Variable.h3
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.cpp12
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.h3
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.cpp47
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.h17
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.cpp1269
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.h264
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/catchcopy-api-0002/VariablesCatchcopy.h3
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/documentation.dox6
-rw-r--r--plugins/Listener/catchcopy-v0002/informations.xml3
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/listener.cpp127
-rw-r--r--[-rwxr-xr-x]plugins/Listener/catchcopy-v0002/listener.h79
-rw-r--r--plugins/Listener/catchcopy-v0002/listener.pro6
-rw-r--r--plugins/Listener/catchcopy-v0002/plugin.json1
16 files changed, 923 insertions, 927 deletions
diff --git a/plugins/Listener/catchcopy-v0002/DebugEngineMacro.h b/plugins/Listener/catchcopy-v0002/DebugEngineMacro.h
index a3dd648..4582010 100644
--- a/plugins/Listener/catchcopy-v0002/DebugEngineMacro.h
+++ b/plugins/Listener/catchcopy-v0002/DebugEngineMacro.h
@@ -1,12 +1,15 @@
/** \file DebugEngineMacro.h
\brief Define the macro for the debug
\author alpha_one_x86
-\version 0.3
-\date 2010 */
+\licence GPL3, see the file COPYING */
#ifndef DEBUGENGINEMACRO_H
#define DEBUGENGINEMACRO_H
+#ifdef WIN32
+# define __func__ __FUNCTION__
+#endif
+
/// \brief Macro for the debug log
#ifdef ULTRACOPIER_PLUGIN_DEBUG
#if defined (__FILE__) && defined (__LINE__)
diff --git a/plugins/Listener/catchcopy-v0002/Environment.h b/plugins/Listener/catchcopy-v0002/Environment.h
index 94fd104..265a5a6 100644
--- a/plugins/Listener/catchcopy-v0002/Environment.h
+++ b/plugins/Listener/catchcopy-v0002/Environment.h
@@ -1,8 +1,7 @@
/** \file Environment.h
\brief Define the environment variable and global function
\author alpha_one_x86
-\version 0.3
-\date 2010 */
+\licence GPL3, see the file COPYING */
#include "Variable.h"
/// \brief The global include
diff --git a/plugins/Listener/catchcopy-v0002/Variable.h b/plugins/Listener/catchcopy-v0002/Variable.h
index 8179c93..963d0c8 100644
--- a/plugins/Listener/catchcopy-v0002/Variable.h
+++ b/plugins/Listener/catchcopy-v0002/Variable.h
@@ -1,8 +1,7 @@
/** \file Variable.h
\brief Define the environment variable
\author alpha_one_x86
-\version 0.3
-\date 2010 */
+\licence GPL3, see the file COPYING */
#ifndef VARIABLE_H
#define VARIABLE_H
diff --git a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.cpp b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.cpp
index 214caca..d7492d0 100755..100644
--- a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.cpp
+++ b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.cpp
@@ -1,13 +1,13 @@
/** \file ClientCatchcopy.cpp
\brief Define the catchcopy client
-\author alpha_one_x86
-\version 0002
-\date 2010 */
+\author alpha_one_x86 */
#include "ClientCatchcopy.h"
#include "VariablesCatchcopy.h"
#include "ExtraSocketCatchcopy.h"
+#include <QDataStream>
+
ClientCatchcopy::ClientCatchcopy()
{
disconnectedFromSocket();
@@ -207,7 +207,7 @@ void ClientCatchcopy::readyRead()
}
else
{
- error_string=QString("First send protocol send with the query id %1 have been already previously replied").arg(orderIdFirstSendProtocol);
+ error_string=QStringLiteral("First send protocol send with the query id %1 have been already previously replied").arg(orderIdFirstSendProtocol);
emit error(error_string);
disconnectFromServer();
return;
@@ -250,8 +250,8 @@ bool ClientCatchcopy::checkDataIntegrity(QByteArray data)
}
if(stringSize>(in.device()->size()-in.device()->pos()))
{
- emit error(QString("String size is greater than the data: %1>(%2-%3)").arg(stringSize).arg(in.device()->size()).arg(in.device()->pos()));
- qWarning() << QString("String size is greater than the data: %1>(%2-%3)").arg(stringSize).arg(in.device()->size()).arg(in.device()->pos());
+ emit error(QStringLiteral("String size is greater than the data: %1>(%2-%3)").arg(stringSize).arg(in.device()->size()).arg(in.device()->pos()));
+ qWarning() << QStringLiteral("String size is greater than the data: %1>(%2-%3)").arg(stringSize).arg(in.device()->size()).arg(in.device()->pos());
return false;
}
in.device()->seek(in.device()->pos()+stringSize);
diff --git a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.h b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.h
index 278b0cd..4c15890 100755..100644
--- a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.h
+++ b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.h
@@ -1,8 +1,7 @@
/** \file ClientCatchcopy.h
\brief Define the catchcopy client
\author alpha_one_x86
-\version 0002
-\date 2010 */
+\licence GPL3, see the file COPYING */
#ifndef CLIENTCATCHCOPY_H
#define CLIENTCATCHCOPY_H
diff --git a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.cpp b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.cpp
index 7ee05ed..5330492 100755..100644
--- a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.cpp
+++ b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.cpp
@@ -1,31 +1,38 @@
/** \file ExtraSocketCatchcopy.cpp
\brief Define the socket of catchcopy
-\author alpha_one_x86
-\version 0002
-\date 2010 */
+\author alpha_one_x86 */
#include "ExtraSocketCatchcopy.h"
+#include <stdio.h>
+
const QString ExtraSocketCatchcopy::pathSocket()
{
#ifdef Q_OS_UNIX
- return "advanced-copier-"+QString::number(getuid());
+ return "advanced-copier-"+QString::number(getuid());
#else
- QString userName;
- DWORD size=0;
- if(GetUserNameW(NULL,&size) || (GetLastError()!=ERROR_INSUFFICIENT_BUFFER))
- {
- }
- else
- {
- WCHAR * userNameW=new WCHAR[size];
- if(GetUserNameW(userNameW,&size))
- {
- userName.fromWCharArray(userNameW,size*2);
- userName=QString(QByteArray((char*)userNameW,size*2-2).toHex());
- }
- delete userNameW;
- }
- return "advanced-copier-"+userName;
+ QString userName;
+ char uname[1024];
+ DWORD len=1023;
+ if(GetUserNameA(uname, &len)!=FALSE)
+ userName=QString::fromLatin1(toHex(uname));
+ return "advanced-copier-"+userName;
#endif
}
+
+char * ExtraSocketCatchcopy::toHex(const char *str)
+{
+ char *p, *sz;
+ size_t len;
+ if (str==NULL)
+ return NULL;
+ len= strlen(str);
+ p = sz = (char *) malloc((len+1)*4);
+ for (size_t i=0; i<len; i++)
+ {
+ sprintf(p, "%.2x00", str[i]);
+ p+=4;
+ }
+ *p=0;
+ return sz;
+}
diff --git a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.h b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.h
index 623c668..59c8f93 100755..100644
--- a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.h
+++ b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ExtraSocketCatchcopy.h
@@ -1,8 +1,7 @@
/** \file ExtraSocketCatchcopy.h
\brief Define the socket of catchcopy
\author alpha_one_x86
-\version 0002
-\date 2010 */
+\licence GPL3, see the file COPYING */
#ifndef EXTRASOCKETCATCHCOPY_H
#define EXTRASOCKETCATCHCOPY_H
@@ -10,18 +9,22 @@
#include <QString>
#ifdef Q_OS_UNIX
- #include <unistd.h>
- #include <sys/types.h>
+ #include <unistd.h>
+ #include <sys/types.h>
#else
- #include <windows.h>
+ #ifndef NOMINMAX
+ #define NOMINMAX
+ #endif
+ #include <windows.h>
#endif
/// \brief to have extra socket function
class ExtraSocketCatchcopy
{
public:
- /// \brief to get the socket path
- static const QString pathSocket();
+ /// \brief to get the socket path
+ static const QString pathSocket();
+ static char * toHex(const char *str);
};
#endif // EXTRASOCKETCATCHCOPY_H
diff --git a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.cpp b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.cpp
index 7120fa1..83c8790 100755..100644
--- a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.cpp
+++ b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.cpp
@@ -1,735 +1,704 @@
/** \file ServerCatchcopy.cpp
\brief Define the server of catchcopy
-\author alpha_one_x86
-\version 0002
-\date 2010 */
+\author alpha_one_x86*/
#include "ServerCatchcopy.h"
#include "VariablesCatchcopy.h"
#include "ExtraSocketCatchcopy.h"
#include <QFile>
+#include <QDataStream>
ServerCatchcopy::ServerCatchcopy()
{
- name="Default avanced copier";
- autoReply=true;
- idNextClient=0;
- error_string="Unknown error";
- connect(&server, SIGNAL(newConnection()), this, SLOT(newConnection()));
+ name="Default avanced copier";
+ idNextClient=0;
+ error_string="Unknown error";
+ connect(&server, &QLocalServer::newConnection, this, &ServerCatchcopy::newConnection);
}
ServerCatchcopy::~ServerCatchcopy()
{
- close();
+ close();
}
-bool ServerCatchcopy::isListening()
+bool ServerCatchcopy::isListening() const
{
- return server.isListening();
+ return server.isListening();
}
void ServerCatchcopy::setName(const QString & name)
{
- this->name=name;
+ this->name=name;
}
-QString ServerCatchcopy::getName()
+QString ServerCatchcopy::getName() const
{
- return name;
+ return name;
+}
+
+/// \brief to get a client list
+QStringList ServerCatchcopy::clientsList() const
+{
+ QStringList clients;
+ int index=0;
+ int size=clientList.size();
+ while(index<size)
+ {
+ clients << clientList[index].name;
+ index++;
+ }
+ return clients;
}
bool ServerCatchcopy::listen()
{
- QLocalSocket socketTestConnection;
- pathSocket=ExtraSocketCatchcopy::pathSocket();
- socketTestConnection.connectToServer(pathSocket);
- if(socketTestConnection.waitForConnected(CATCHCOPY_COMMUNICATION_TIMEOUT))
- {
- error_string="Other server is listening";
- emit error(error_string);
- return false;
- }
- else
- {
- if(!server.removeServer(pathSocket))
- {
- error_string="Unable to remove the old server";
- emit error(error_string);
- }
- if(server.listen(pathSocket))
- return true;
- else
- {
- error_string=QString("Unable to listen %1: %2").arg(pathSocket).arg(server.errorString());
- emit error(error_string);
- return false;
- }
- }
+ QLocalSocket socketTestConnection;
+ pathSocket=ExtraSocketCatchcopy::pathSocket();
+ socketTestConnection.connectToServer(pathSocket);
+ if(socketTestConnection.waitForConnected(CATCHCOPY_COMMUNICATION_TIMEOUT))
+ {
+ error_string="Other server is listening";
+ emit error(error_string);
+ return false;
+ }
+ else
+ {
+ if(!server.removeServer(pathSocket))
+ {
+ error_string="Unable to remove the old server";
+ emit error(error_string);
+ }
+ #ifndef Q_OS_MAC
+ server.setSocketOptions(QLocalServer::UserAccessOption);
+ #endif
+ if(server.listen(pathSocket))
+ return true;
+ else
+ {
+ error_string=QStringLiteral("Unable to listen %1: %2").arg(pathSocket).arg(server.errorString());
+ emit error(error_string);
+ return false;
+ }
+ }
}
void ServerCatchcopy::close()
{
- if(server.isListening())
- {
- int index=0;
- while(index<ClientList.size())
- {
- ClientList.at(index).socket->disconnectFromServer();
- index++;
- }
- server.close();
- if(!server.removeServer(pathSocket))
- {
- error_string="Unable to remove the old server";
- emit error(error_string);
- }
- }
+ if(server.isListening())
+ {
+ int index=0;
+ while(index<clientList.size())
+ {
+ clientList.at(index).socket->disconnectFromServer();
+ index++;
+ }
+ server.close();
+ if(!server.removeServer(pathSocket))
+ {
+ error_string="Unable to remove the old server";
+ emit error(error_string);
+ }
+ }
}
-const QString ServerCatchcopy::errorStringServer()
+const QString ServerCatchcopy::errorStringServer() const
{
- return server.errorString();
+ return server.errorString();
}
-const QString ServerCatchcopy::errorString()
+const QString ServerCatchcopy::errorString() const
{
- return error_string;
+ return error_string;
}
/// \brief New connexion
void ServerCatchcopy::newConnection()
{
- while(server.hasPendingConnections())
- {
- QLocalSocket *clientSocket = server.nextPendingConnection();
- if(clientSocket!=NULL)
- {
- do
- {
- idNextClient++;
- if(idNextClient>2000000000)
- idNextClient=0;
- } while(clientIdFound(idNextClient));
- Client newClient;
- newClient.id = idNextClient;
- newClient.socket = clientSocket;
- newClient.haveData = false;
- newClient.firstProtocolReplied = false;
- newClient.detectTimeOut = new QTimer(this);
- newClient.detectTimeOut->setSingleShot(true);
- newClient.detectTimeOut->setInterval(CATCHCOPY_COMMUNICATION_TIMEOUT);
- connect(newClient.socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(connectionError(QLocalSocket::LocalSocketError)));
- connect(newClient.socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
- connect(newClient.socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
- connect(newClient.detectTimeOut,SIGNAL(timeout()), this, SLOT(checkTimeOut()));
- ClientList << newClient;
- emit connectedClient(newClient.id);
- }
- }
-}
-
-bool ServerCatchcopy::clientIdFound(quint32 id)
-{
- int index=0;
- while(index<ClientList.size())
- {
- if(ClientList.at(index).id==id)
- return true;
- index++;
- }
- return false;
+ while(server.hasPendingConnections())
+ {
+ QLocalSocket *clientSocket = server.nextPendingConnection();
+ if(clientSocket!=NULL)
+ {
+ do
+ {
+ idNextClient++;
+ if(idNextClient>2000000000)
+ idNextClient=0;
+ } while(clientIdFound(idNextClient));
+ Client newClient;
+ newClient.id = idNextClient;
+ newClient.socket = clientSocket;
+ newClient.haveData = false;
+ newClient.firstProtocolReplied = false;
+ newClient.detectTimeOut = new QTimer(this);
+ newClient.detectTimeOut->setSingleShot(true);
+ newClient.detectTimeOut->setInterval(CATCHCOPY_COMMUNICATION_TIMEOUT);
+ newClient.name="Unknown";
+ connect(newClient.socket, static_cast<void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>(&QLocalSocket::error), this, &ServerCatchcopy::connectionError,Qt::QueuedConnection);
+ connect(newClient.socket, &QIODevice::readyRead, this, &ServerCatchcopy::readyRead,Qt::QueuedConnection);
+ connect(newClient.socket, &QLocalSocket::disconnected, this, &ServerCatchcopy::disconnected,Qt::QueuedConnection);
+ connect(newClient.detectTimeOut,&QTimer::timeout, this, &ServerCatchcopy::checkTimeOut,Qt::QueuedConnection);
+ clientList << newClient;
+ emit connectedClient(newClient.id);
+ }
+ }
+}
+
+bool ServerCatchcopy::clientIdFound(const quint32 &id) const
+{
+ int index=0;
+ while(index<clientList.size())
+ {
+ if(clientList.at(index).id==id)
+ return true;
+ index++;
+ }
+ return false;
}
/// \brief new error at connexion
-void ServerCatchcopy::connectionError(QLocalSocket::LocalSocketError error)
-{
- QLocalSocket *socket=qobject_cast<QLocalSocket *>(QObject::sender());
- if(socket==NULL)
- {
- qWarning() << "Unlocated client socket!";
- return;
- }
- int index=0;
- while(index<ClientList.size())
- {
- if(ClientList.at(index).socket==socket)
- {
- if(error!=QLocalSocket::PeerClosedError)
- qWarning() << "error detected for the client: " << index << ", type: " << error;
- ClientList.at(index).socket->disconnectFromServer();
- return;
- }
- index++;
- }
+void ServerCatchcopy::connectionError(const QLocalSocket::LocalSocketError &error)
+{
+ QLocalSocket *socket=qobject_cast<QLocalSocket *>(QObject::sender());
+ if(socket==NULL)
+ {
+ qWarning() << "Unlocated client socket!";
+ return;
+ }
+ int index=0;
+ while(index<clientList.size())
+ {
+ if(clientList.at(index).socket==socket)
+ {
+ if(error!=QLocalSocket::PeerClosedError)
+ {
+ qWarning() << "error detected for the client: " << index << ", type: " << error;
+ clientList.at(index).socket->disconnectFromServer();
+ }
+ return;
+ }
+ index++;
+ }
}
void ServerCatchcopy::disconnected()
{
- QLocalSocket *socket=qobject_cast<QLocalSocket *>(QObject::sender());
- if(socket==NULL)
- {
- qWarning() << "Unlocated client socket!";
- return;
- }
- int index=0;
- while(index<ClientList.size())
- {
- if(ClientList.at(index).socket==socket)
- {
- emit disconnectedClient(ClientList.at(index).id);
- disconnect(ClientList.at(index).socket);
- disconnect(ClientList.at(index).detectTimeOut);
- delete ClientList.at(index).detectTimeOut;
- ClientList.at(index).socket->abort();
- ClientList.at(index).socket->disconnectFromServer();
- ClientList.at(index).socket->deleteLater();
- ClientList.removeAt(index);
- return;
- }
- index++;
- }
- qWarning() << "Unlocated client!";
-}
-
-void ServerCatchcopy::disconnectClient(quint32 id)
-{
- int index=0;
- while(index<ClientList.size())
- {
- if(ClientList.at(index).id==id)
- {
- ClientList.at(index).socket->disconnectFromServer();
- return;
- }
- index++;
- }
- qWarning() << "Unlocated client!";
+ QLocalSocket *socket=qobject_cast<QLocalSocket *>(QObject::sender());
+ if(socket==NULL)
+ {
+ qWarning() << "Unlocated client socket!";
+ return;
+ }
+ int index=0;
+ while(index<clientList.size())
+ {
+ if(clientList.at(index).socket==socket)
+ {
+ const quint32 &id=clientList.at(index).id;
+ //ClientList.at(index).socket->disconnectFromServer();//already disconnected
+ delete clientList.at(index).detectTimeOut;
+ clientList.at(index).socket->deleteLater();
+ clientList.removeAt(index);
+ emit disconnectedClient(id);
+ return;
+ }
+ index++;
+ }
+ qWarning() << "Unlocated client!";
+}
+
+void ServerCatchcopy::disconnectClient(const quint32 &id)
+{
+ int index=0;
+ while(index<clientList.size())
+ {
+ if(clientList.at(index).id==id)
+ {
+ clientList.at(index).socket->disconnectFromServer();
+ return;
+ }
+ index++;
+ }
+ qWarning() << "Unlocated client!";
}
void ServerCatchcopy::readyRead()
{
- QLocalSocket *socket=qobject_cast<QLocalSocket *>(QObject::sender());
- if(socket==NULL)
- {
- qWarning() << "Unlocated client socket!";
- return;
- }
- int index=0;
- while(index<ClientList.size())
- {
- if(ClientList.at(index).socket==socket)
- {
- while(socket->bytesAvailable()>0)
- {
- if(!ClientList.at(index).haveData)
- {
- if(socket->bytesAvailable()<(int)sizeof(int))//ignore because first int is cuted!
- {
- /*error_string="Bytes available is not sufficient to do a int";
- emit error(error_string);
- disconnectClient(ClientList.at(index).id);*/
- return;
- }
- QDataStream in(socket);
- in.setVersion(QDataStream::Qt_4_4);
- in >> ClientList[index].dataSize;
- ClientList[index].dataSize-=sizeof(int);
- if(ClientList.at(index).dataSize>64*1024*1024) // 64MB
- {
- error_string="Reply size is >64MB, seam corrupted";
- emit error(error_string);
- disconnectClient(ClientList.at(index).id);
- return;
- }
- if(ClientList.at(index).dataSize<(int)(sizeof(int) //orderId
- + sizeof(quint32) //returnCode
- + sizeof(quint32) //string list size
- ))
- {
- error_string="Reply size is too small to have correct code";
- emit error(error_string);
- disconnectClient(ClientList.at(index).id);
- return;
- }
- ClientList[index].haveData=true;
- }
- if(ClientList.at(index).dataSize<(ClientList.at(index).data.size()+socket->bytesAvailable()))
- ClientList[index].data.append(socket->read(ClientList.at(index).dataSize-ClientList.at(index).data.size()));
- else
- ClientList[index].data.append(socket->readAll());
- if(ClientList.at(index).dataSize==(quint32)ClientList.at(index).data.size())
- {
- if(!checkDataIntegrity(ClientList.at(index).data))
- {
- emit error("Data integrity wrong: "+QString(ClientList.at(index).data.toHex()));
- ClientList[index].data.clear();
- ClientList[index].haveData=false;
- qWarning() << "Data integrity wrong";
- return;
- }
- QStringList returnList;
- quint32 orderId;
- QDataStream in(ClientList.at(index).data);
- in.setVersion(QDataStream::Qt_4_4);
- in >> orderId;
- in >> returnList;
- ClientList[index].data.clear();
- ClientList[index].haveData=false;
- if(ClientList.at(index).queryNoReplied.contains(orderId))
- {
- emit error("Duplicate query id");
- qWarning() << "Duplicate query id";
- return;
- }
- ClientList[index].queryNoReplied << orderId;
- if(!ClientList.at(index).firstProtocolReplied && returnList.size()==2 && returnList.first()=="protocol" && autoReply)
- {
- ClientList[index].firstProtocolReplied=true;
- protocolSupported(ClientList.at(index).id,orderId,(returnList.last()==CATCHCOPY_PROTOCOL_VERSION));
- }
- else
- parseInput(ClientList.at(index).id,orderId,returnList);
- }
- }
- if(ClientList.at(index).haveData)
- ClientList.at(index).detectTimeOut->start();
- else
- ClientList.at(index).detectTimeOut->stop();
- return;
- }
- index++;
- }
- emit error("Unallocated client!");
- qWarning() << "Unallocated client!";
-}
-
-bool ServerCatchcopy::checkDataIntegrity(QByteArray data)
-{
- quint32 orderId;
- qint32 listSize;
- QDataStream in(data);
- in.setVersion(QDataStream::Qt_4_4);
- in >> orderId;
- in >> listSize;
- if(listSize>65535)
- {
- emit error("List size is wrong");
- qWarning() << "List size is wrong";
- return false;
- }
- int index=0;
- while(index<listSize)
- {
- qint32 stringSize;
- in >> stringSize;
- if(stringSize>65535)
- {
- emit error("String size is wrong");
- return false;
- }
- if(stringSize>(in.device()->size()-in.device()->pos()))
- {
- emit error(QString("String size is greater than the data: %1>(%2-%3)").arg(stringSize).arg(in.device()->size()).arg(in.device()->pos()));
- return false;
- }
- in.device()->seek(in.device()->pos()+stringSize);
- index++;
- }
- if(in.device()->size()!=in.device()->pos())
- {
- emit error("Remaining data after string list parsing");
- return false;
- }
- return true;
-}
-
-void ServerCatchcopy::parseInput(quint32 client,quint32 orderId,QStringList returnList)
-{
- switch(parseInputCurrentProtocol(client,orderId,returnList))
- {
- case Ok:
- emit newQuery(client,orderId,returnList);
- break;
- case Replied:
- break;
- case ExtensionWrong:
- if(autoReply)
- protocolExtensionSupported(client,orderId,false);
- else
- emit newQuery(client,orderId,returnList);
- break;
- case WrongArgument:
- if(autoReply)
- incorrectArgument(client,orderId);
- else
- emit newQuery(client,orderId,returnList);
- break;
- case WrongArgumentListSize:
- if(autoReply)
- incorrectArgumentListSize(client,orderId);
- else
- emit newQuery(client,orderId,returnList);
- break;
- case UnknowOrder:
- emit error("Unknown query");
- qWarning() << "Unknown query";
- if(autoReply)
- unknowOrder(client,orderId);
- else
- emit newQuery(client,orderId,returnList);
- break;
- }
-}
-
-ServerCatchcopy::inputReturnType ServerCatchcopy::parseInputCurrentProtocol(quint32 client,quint32 orderId,QStringList returnList)
-{
- if(returnList.size()==0)
- return WrongArgumentListSize;
- //if is supported
- QString firstArgument=returnList.first();
- if(firstArgument=="protocol")
- {
- if(returnList.size()!=2)
- return WrongArgumentListSize;
- emit askProtocolCompatibility(client,orderId,returnList.last());
- return Ok;
- }
- else if(firstArgument=="protocol extension")
- {
- if(returnList.size()>3 || returnList.size()<2)
- return WrongArgumentListSize;
- if(!autoReply)
- {
- if(returnList.size()==2)
- emit askProtocolExtension(client,orderId,returnList.last());
- else
- emit askProtocolExtension(client,orderId,returnList.at(1),returnList.last());
- }
- return ExtensionWrong;
- }
- else if(firstArgument=="client")
- {
- if(returnList.size()!=2)
- return WrongArgumentListSize;
- emit clientName(client,returnList.last());
- if(autoReply)
- {
- clientRegistered(client,orderId);
- return Replied;
- }
- else
- {
- emit clientName(client,orderId,returnList.last());
- return Ok;
- }
- }
- else if(firstArgument=="server")
- {
- if(returnList.size()!=2)
- return WrongArgumentListSize;
- if(returnList.last()!="name?")
- return WrongArgument;
- if(autoReply)
- {
- serverName(client,orderId,name);
- return Replied;
- }
- else
- {
- askServerName(client,orderId);
- return Ok;
- }
- }
- else if(firstArgument=="cp")
- {
- if(returnList.size()<3)
- return WrongArgumentListSize;
- QStringList sourceList=returnList;
- sourceList.removeFirst();
- sourceList.removeLast();
- emitNewCopy(client,orderId,sourceList,returnList.last());
- return Ok;
- }
- else if(firstArgument=="cp-?")
- {
- if(returnList.size()<2)
- return WrongArgumentListSize;
- QStringList sourceList=returnList;
- sourceList.removeFirst();
- emitNewCopy(client,orderId,sourceList);
- return Ok;
- }
- else if(firstArgument=="mv")
- {
- if(returnList.size()<3)
- return WrongArgumentListSize;
- QStringList sourceList=returnList;
- sourceList.removeFirst();
- sourceList.removeLast();
- emitNewMove(client,orderId,sourceList,returnList.last());
- return Ok;
- }
- else if(firstArgument=="mv-?")
- {
- if(returnList.size()<2)
- return WrongArgumentListSize;
- QStringList sourceList=returnList;
- sourceList.removeFirst();
- emitNewMove(client,orderId,sourceList);
- return Ok;
- }
- else //if is not supported
- return UnknowOrder;
-}
-
-void ServerCatchcopy::emitNewCopy(quint32 client,quint32 orderId,QStringList sources)
-{
- emit newCopy(client,orderId,sources);
- LinkGlobalToLocalClient newAssociation;
- newAssociation.idClient=client;
- newAssociation.orderId=orderId;
- newAssociation.globalOrderId=incrementOrderId();
- LinkGlobalToLocalClientList << newAssociation;
- emit newCopy(newAssociation.globalOrderId,sources);
-}
-
-void ServerCatchcopy::emitNewCopy(quint32 client,quint32 orderId,QStringList sources,QString destination)
-{
- emit newCopy(client,orderId,sources,destination);
- LinkGlobalToLocalClient newAssociation;
- newAssociation.idClient=client;
- newAssociation.orderId=orderId;
- newAssociation.globalOrderId=incrementOrderId();
- LinkGlobalToLocalClientList << newAssociation;
- emit newCopy(newAssociation.globalOrderId,sources,destination);
-}
-
-void ServerCatchcopy::emitNewMove(quint32 client,quint32 orderId,QStringList sources)
-{
- emit newMove(client,orderId,sources);
- LinkGlobalToLocalClient newAssociation;
- newAssociation.idClient=client;
- newAssociation.orderId=orderId;
- newAssociation.globalOrderId=incrementOrderId();
- LinkGlobalToLocalClientList << newAssociation;
- emit newMove(newAssociation.globalOrderId,sources);
-}
-
-void ServerCatchcopy::emitNewMove(quint32 client,quint32 orderId,QStringList sources,QString destination)
-{
- emit newMove(client,orderId,sources,destination);
- LinkGlobalToLocalClient newAssociation;
- newAssociation.idClient=client;
- newAssociation.orderId=orderId;
- newAssociation.globalOrderId=incrementOrderId();
- LinkGlobalToLocalClientList << newAssociation;
- emit newMove(newAssociation.globalOrderId,sources,destination);
-}
-
-void ServerCatchcopy::copyFinished(quint32 globalOrderId,bool withError)
-{
- int index=0;
- while(index<LinkGlobalToLocalClientList.size())
- {
- if(LinkGlobalToLocalClientList.at(index).globalOrderId==globalOrderId)
- {
- copyFinished(LinkGlobalToLocalClientList.at(index).idClient,LinkGlobalToLocalClientList.at(index).orderId,withError);
- LinkGlobalToLocalClientList.removeAt(index);
- orderList.removeOne(globalOrderId);
- return;
- }
- index++;
- }
-}
-
-void ServerCatchcopy::copyCanceled(quint32 globalOrderId)
-{
- int index=0;
- while(index<LinkGlobalToLocalClientList.size())
- {
- if(LinkGlobalToLocalClientList.at(index).globalOrderId==globalOrderId)
- {
- copyCanceled(LinkGlobalToLocalClientList.at(index).idClient,LinkGlobalToLocalClientList.at(index).orderId);
- LinkGlobalToLocalClientList.removeAt(index);
- orderList.removeOne(globalOrderId);
- return;
- }
- index++;
- }
-}
-
-void ServerCatchcopy::setAutoReply(bool value)
-{
- autoReply=value;
-}
-
-bool ServerCatchcopy::getAutoReply()
-{
- return autoReply;
-}
-
-void ServerCatchcopy::reply(quint32 client,quint32 orderId,quint32 returnCode,QString returnString)
-{
- reply(client,orderId,returnCode,QStringList() << returnString);
-}
-
-void ServerCatchcopy::reply(quint32 client,quint32 orderId,quint32 returnCode,QStringList returnList)
-{
- int index=0;
- while(index<ClientList.size())
- {
- if(ClientList.at(index).id==client)
- {
- if(ClientList.at(index).socket->isValid() && ClientList.at(index).socket->state()==QLocalSocket::ConnectedState)
- {
- if(!ClientList.at(index).queryNoReplied.contains(orderId))
- {
- qWarning() << "Reply to missing query or previously replied";
- return;
- }
- ClientList[index].queryNoReplied.removeOne(orderId);
- //cut string list and send it as block of 32KB
- QByteArray block;
- QDataStream out(&block, QIODevice::WriteOnly);
- out.setVersion(QDataStream::Qt_4_4);
- out << int(0);
- out << orderId;
- out << returnCode;
- out << returnList;
- out.device()->seek(0);
- out << block.size();
- emit dataSend(client,orderId,returnCode,block);
- emit dataSend(client,orderId,returnCode,returnList);
- do
- {
- QByteArray blockToSend;
- int byteWriten;
- blockToSend=block.left(32*1024);//32KB
- block.remove(0,blockToSend.size());
- byteWriten = ClientList[index].socket->write(blockToSend);
- if(!ClientList[index].socket->isValid())
- {
- error_string="Socket is not valid";
- emit error(error_string);
- return;
- }
- if(ClientList[index].socket->errorString()!="Unknown error" && ClientList[index].socket->errorString()!="")
- {
- error_string="Error with socket: "+ClientList[index].socket->errorString();
- emit error(error_string);
- return;
- }
- if(blockToSend.size()!=byteWriten)
- {
- error_string="All the bytes have not be written";
- emit error(error_string);
- return;
- }
- }
- while(block.size());
- }
- else
- {
- error_string="Socket is not valid or not connected";
- emit error(error_string);
- }
- return;
- }
- index++;
- }
- qWarning() << "Client id not found:" << client;
-}
+ QLocalSocket *socket=qobject_cast<QLocalSocket *>(QObject::sender());
+ if(socket==NULL)
+ {
+ qWarning() << "Unlocated client socket!";
+ return;
+ }
+ int index=0;
+ while(index<clientList.size())
+ {
+ if(clientList.at(index).socket==socket)
+ {
+ while(socket->bytesAvailable()>0)
+ {
+ if(!clientList.at(index).haveData)
+ {
+ if(socket->bytesAvailable()<(int)sizeof(int))//ignore because first int is cuted!
+ {
+ /*error_string="Bytes available is not sufficient to do a int";
+ emit error(error_string);
+ disconnectClient(ClientList.at(index).id);*/
+ return;
+ }
+ QDataStream in(socket);
+ in.setVersion(QDataStream::Qt_4_4);
+ in >> clientList[index].dataSize;
+ clientList[index].dataSize-=sizeof(int);
+ if(clientList.at(index).dataSize>64*1024*1024) // 64MB
+ {
+ error_string="Reply size is >64MB, seam corrupted";
+ emit communicationError(error_string);
+ disconnectClient(clientList.at(index).id);
+ return;
+ }
+ if(clientList.at(index).dataSize<(int)(sizeof(int) //orderId
+ + sizeof(quint32) //returnCode
+ + sizeof(quint32) //string list size
+ ))
+ {
+ error_string="Reply size is too small to have correct code";
+ emit communicationError(error_string);
+ disconnectClient(clientList.at(index).id);
+ return;
+ }
+ clientList[index].haveData=true;
+ }
+ if(clientList.at(index).dataSize<(clientList.at(index).data.size()+socket->bytesAvailable()))
+ clientList[index].data.append(socket->read(clientList.at(index).dataSize-clientList.at(index).data.size()));
+ else
+ clientList[index].data.append(socket->readAll());
+ if(clientList.at(index).dataSize==(quint32)clientList.at(index).data.size())
+ {
+ if(!checkDataIntegrity(clientList.at(index).data))
+ {
+ emit communicationError("Data integrity wrong: "+QString(clientList.at(index).data.toHex()));
+ clientList[index].data.clear();
+ clientList[index].haveData=false;
+ qWarning() << "Data integrity wrong";
+ return;
+ }
+ QStringList returnList;
+ quint32 orderId;
+ QDataStream in(clientList.at(index).data);
+ in.setVersion(QDataStream::Qt_4_4);
+ in >> orderId;
+ in >> returnList;
+ clientList[index].data.clear();
+ clientList[index].haveData=false;
+ if(clientList.at(index).queryNoReplied.contains(orderId))
+ {
+ emit communicationError("Duplicate query id");
+ qWarning() << "Duplicate query id";
+ return;
+ }
+ clientList[index].queryNoReplied << orderId;
+ if(!clientList.at(index).firstProtocolReplied && returnList.size()==2 && returnList.first()=="protocol")
+ {
+ clientList[index].firstProtocolReplied=true;
+ protocolSupported(clientList.at(index).id,orderId,(returnList.last()==CATCHCOPY_PROTOCOL_VERSION));
+ }
+ else
+ parseInput(clientList.at(index).id,orderId,returnList);
+ }
+ }
+ if(clientList.at(index).haveData)
+ clientList.at(index).detectTimeOut->start();
+ else
+ clientList.at(index).detectTimeOut->stop();
+ return;
+ }
+ index++;
+ }
+ emit error("Unallocated client!");
+ qWarning() << "Unallocated client!";
+}
+
+bool ServerCatchcopy::checkDataIntegrity(const QByteArray &data)
+{
+ quint32 orderId;
+ qint32 listSize;
+ QDataStream in(data);
+ in.setVersion(QDataStream::Qt_4_4);
+ in >> orderId;
+ in >> listSize;
+ if(listSize>65535)
+ {
+ emit error("List size is wrong");
+ qWarning() << "List size is wrong";
+ return false;
+ }
+ int index=0;
+ while(index<listSize)
+ {
+ qint32 stringSize;
+ in >> stringSize;
+ if(stringSize>65535)
+ {
+ emit error("String size is wrong");
+ return false;
+ }
+ if(stringSize>(in.device()->size()-in.device()->pos()))
+ {
+ emit error(QStringLiteral("String size is greater than the data: %1>(%2-%3)").arg(stringSize).arg(in.device()->size()).arg(in.device()->pos()));
+ return false;
+ }
+ in.device()->seek(in.device()->pos()+stringSize);
+ index++;
+ }
+ if(in.device()->size()!=in.device()->pos())
+ {
+ emit error("Remaining data after string list parsing");
+ return false;
+ }
+ return true;
+}
+
+void ServerCatchcopy::parseInput(const quint32 &client,const quint32 &orderId,const QStringList &returnList)
+{
+ const ServerCatchcopy::inputReturnType returnVal=parseInputCurrentProtocol(client,orderId,returnList);
+ switch(returnVal)
+ {
+ case Ok:
+ emit newQuery(client,orderId,returnList);
+ break;
+ case Replied:
+ break;
+ case ExtensionWrong:
+ //protocolExtensionSupported(client,orderId,false);
+ break;
+ case WrongArgument:
+ incorrectArgument(client,orderId);
+ break;
+ case WrongArgumentListSize:
+ incorrectArgumentListSize(client,orderId);
+ break;
+ case UnknowOrder:
+ emit error("Unknown query: "+QString::number(returnVal)+", with client: "+QString::number(client)+", orderId: "+QString::number(orderId)+", returnList: "+returnList.join(", "));
+ qWarning() << "Unknown query";
+ unknowOrder(client,orderId);
+ break;
+ }
+}
+
+ServerCatchcopy::inputReturnType ServerCatchcopy::parseInputCurrentProtocol(const quint32 &client,const quint32 &orderId,const QStringList &returnList)
+{
+ if(returnList.size()==0)
+ return WrongArgumentListSize;
+ //if is supported
+ QString firstArgument=returnList.first();
+ if(firstArgument=="protocol")
+ {
+ if(returnList.size()!=2)
+ return WrongArgumentListSize;
+ emit askProtocolCompatibility(client,orderId,returnList.last());
+ return Ok;
+ }
+ else if(firstArgument=="protocol extension")
+ {
+ if(returnList.size()>3 || returnList.size()<2)
+ return WrongArgumentListSize;
+ return ExtensionWrong;
+ }
+ else if(firstArgument=="client")
+ {
+ if(returnList.size()!=2)
+ return WrongArgumentListSize;
+ int index=0;
+ int size=clientList.size();
+ while(index<size)
+ {
+ if(clientList.at(index).id==client)
+ {
+ clientList[index].name=returnList.last();
+ break;
+ }
+ index++;
+ }
+ emit clientName(client,returnList.last());
+ clientRegistered(client,orderId);
+ return Replied;
+ }
+ else if(firstArgument=="server")
+ {
+ if(returnList.size()!=2)
+ return WrongArgumentListSize;
+ if(returnList.last()!="name?")
+ return WrongArgument;
+ serverName(client,orderId,name);
+ return Replied;
+ }
+ else if(firstArgument=="cp")
+ {
+ if(returnList.size()<3)
+ return WrongArgumentListSize;
+ QStringList sourceList=returnList;
+ sourceList.removeFirst();
+ sourceList.removeLast();
+ emitNewCopy(client,orderId,sourceList,returnList.last());
+ return Ok;
+ }
+ else if(firstArgument=="cp-?")
+ {
+ if(returnList.size()<2)
+ return WrongArgumentListSize;
+ QStringList sourceList=returnList;
+ sourceList.removeFirst();
+ emitNewCopyWithoutDestination(client,orderId,sourceList);
+ return Ok;
+ }
+ else if(firstArgument=="mv")
+ {
+ if(returnList.size()<3)
+ return WrongArgumentListSize;
+ QStringList sourceList=returnList;
+ sourceList.removeFirst();
+ sourceList.removeLast();
+ emitNewMove(client,orderId,sourceList,returnList.last());
+ return Ok;
+ }
+ else if(firstArgument=="mv-?")
+ {
+ if(returnList.size()<2)
+ return WrongArgumentListSize;
+ QStringList sourceList=returnList;
+ sourceList.removeFirst();
+ emitNewMoveWithoutDestination(client,orderId,sourceList);
+ return Ok;
+ }
+ else //if is not supported
+ return UnknowOrder;
+}
+
+void ServerCatchcopy::emitNewCopyWithoutDestination(const quint32 &client,const quint32 &orderId,const QStringList &sources)
+{
+ LinkGlobalToLocalClient newAssociation;
+ newAssociation.idClient=client;
+ newAssociation.orderId=orderId;
+ newAssociation.globalOrderId=incrementOrderId();
+ LinkGlobalToLocalClientList << newAssociation;
+ emit newCopyWithoutDestination(newAssociation.globalOrderId,sources);
+}
+
+void ServerCatchcopy::emitNewCopy(const quint32 &client,const quint32 &orderId,const QStringList &sources,const QString &destination)
+{
+ LinkGlobalToLocalClient newAssociation;
+ newAssociation.idClient=client;
+ newAssociation.orderId=orderId;
+ newAssociation.globalOrderId=incrementOrderId();
+ LinkGlobalToLocalClientList << newAssociation;
+ emit newCopy(newAssociation.globalOrderId,sources,destination);
+}
+
+void ServerCatchcopy::emitNewMoveWithoutDestination(const quint32 &client,const quint32 &orderId,const QStringList &sources)
+{
+ LinkGlobalToLocalClient newAssociation;
+ newAssociation.idClient=client;
+ newAssociation.orderId=orderId;
+ newAssociation.globalOrderId=incrementOrderId();
+ LinkGlobalToLocalClientList << newAssociation;
+ emit newMoveWithoutDestination(newAssociation.globalOrderId,sources);
+}
+
+void ServerCatchcopy::emitNewMove(const quint32 &client,const quint32 &orderId,const QStringList &sources,const QString &destination)
+{
+ LinkGlobalToLocalClient newAssociation;
+ newAssociation.idClient=client;
+ newAssociation.orderId=orderId;
+ newAssociation.globalOrderId=incrementOrderId();
+ LinkGlobalToLocalClientList << newAssociation;
+ emit newMove(newAssociation.globalOrderId,sources,destination);
+}
+
+void ServerCatchcopy::copyFinished(const quint32 &globalOrderId,const bool &withError)
+{
+ int index=0;
+ while(index<LinkGlobalToLocalClientList.size())
+ {
+ if(LinkGlobalToLocalClientList.at(index).globalOrderId==globalOrderId)
+ {
+ copyFinished(LinkGlobalToLocalClientList.at(index).idClient,LinkGlobalToLocalClientList.at(index).orderId,withError);
+ LinkGlobalToLocalClientList.removeAt(index);
+ orderList.removeOne(globalOrderId);
+ return;
+ }
+ index++;
+ }
+}
+
+void ServerCatchcopy::copyCanceled(const quint32 &globalOrderId)
+{
+ int index=0;
+ while(index<LinkGlobalToLocalClientList.size())
+ {
+ if(LinkGlobalToLocalClientList.at(index).globalOrderId==globalOrderId)
+ {
+ copyCanceled(LinkGlobalToLocalClientList.at(index).idClient,LinkGlobalToLocalClientList.at(index).orderId);
+ LinkGlobalToLocalClientList.removeAt(index);
+ orderList.removeOne(globalOrderId);
+ return;
+ }
+ index++;
+ }
+}
+
+void ServerCatchcopy::reply(const quint32 &client,const quint32 &orderId,const quint32 &returnCode,const QString &returnString)
+{
+ reply(client,orderId,returnCode,QStringList() << returnString);
+}
+
+void ServerCatchcopy::reply(const quint32 &client,const quint32 &orderId,const quint32 &returnCode,const QStringList &returnList)
+{
+ int index=0;
+ while(index<clientList.size())
+ {
+ if(clientList.at(index).id==client)
+ {
+ if(clientList.at(index).socket->isValid() && clientList.at(index).socket->state()==QLocalSocket::ConnectedState)
+ {
+ if(!clientList.at(index).queryNoReplied.contains(orderId))
+ {
+ qWarning() << "Reply to missing query or previously replied";
+ return;
+ }
+ clientList[index].queryNoReplied.removeOne(orderId);
+ //cut string list and send it as block of 32KB
+ QByteArray block;
+ QDataStream out(&block, QIODevice::WriteOnly);
+ out.setVersion(QDataStream::Qt_4_4);
+ out << int(0);
+ out << orderId;
+ out << returnCode;
+ out << returnList;
+ out.device()->seek(0);
+ out << block.size();
+ do
+ {
+ QByteArray blockToSend;
+ int byteWriten;
+ blockToSend=block.left(32*1024);//32KB
+ block.remove(0,blockToSend.size());
+ byteWriten = clientList[index].socket->write(blockToSend);
+ if(!clientList[index].socket->isValid())
+ {
+ error_string="Socket is not valid";
+ emit error(error_string);
+ return;
+ }
+ if(clientList[index].socket->error()!=QLocalSocket::UnknownSocketError && clientList[index].socket->error()!=QLocalSocket::PeerClosedError)
+ {
+ error_string="Error with socket: "+clientList[index].socket->errorString();
+ emit error(error_string);
+ return;
+ }
+ if(blockToSend.size()!=byteWriten)
+ {
+ error_string="All the bytes have not be written";
+ emit error(error_string);
+ return;
+ }
+ }
+ while(block.size());
+ }
+ else
+ {
+ error_string="Socket is not valid or not connected";
+ emit error(error_string);
+ }
+ return;
+ }
+ index++;
+ }
+ qWarning() << "Client id not found:" << client;
+}
-void ServerCatchcopy::protocolSupported(quint32 client,quint32 orderId,bool value)
-{
- if(value)
- reply(client,orderId,1000,"protocol supported");
- else
- reply(client,orderId,5003,"protocol not supported");
+void ServerCatchcopy::protocolSupported(const quint32 &client,const quint32 &orderId,const bool &value)
+{
+ if(value)
+ reply(client,orderId,1000,"protocol supported");
+ else
+ reply(client,orderId,5003,"protocol not supported");
}
-void ServerCatchcopy::incorrectArgumentListSize(quint32 client,quint32 orderId)
+void ServerCatchcopy::incorrectArgumentListSize(const quint32 &client,const quint32 &orderId)
{
- reply(client,orderId,5000,"incorrect argument list size");
+ reply(client,orderId,5000,"incorrect argument list size");
}
-void ServerCatchcopy::incorrectArgument(quint32 client,quint32 orderId)
+void ServerCatchcopy::incorrectArgument(const quint32 &client,const quint32 &orderId)
{
- reply(client,orderId,5001,"incorrect argument");
+ reply(client,orderId,5001,"incorrect argument");
}
-void ServerCatchcopy::protocolExtensionSupported(quint32 client,quint32 orderId,bool value)
+void ServerCatchcopy::clientRegistered(const quint32 &client,const quint32 &orderId)
{
- if(value)
- reply(client,orderId,1001,"protocol extension supported");
- else
- reply(client,orderId,1002,"protocol extension not supported");
+ reply(client,orderId,1003,"client registered");
}
-void ServerCatchcopy::clientRegistered(quint32 client,quint32 orderId)
+void ServerCatchcopy::serverName(const quint32 &client,const quint32 &orderId,const QString &name)
{
- reply(client,orderId,1003,"client registered");
+ reply(client,orderId,1004,name);
}
-void ServerCatchcopy::serverName(quint32 client,quint32 orderId,QString name)
+void ServerCatchcopy::copyFinished(const quint32 &client,const quint32 &orderId,const bool &withError)
{
- reply(client,orderId,1004,name);
+ if(!withError)
+ reply(client,orderId,1005,"finished");
+ else
+ reply(client,orderId,1006,"finished with error(s)");
}
-void ServerCatchcopy::copyFinished(quint32 client,quint32 orderId,bool withError)
-{
- if(!withError)
- reply(client,orderId,1005,"finished");
- else
- reply(client,orderId,1006,"finished with error(s)");
-}
-
-void ServerCatchcopy::copyCanceled(quint32 client,quint32 orderId)
-{
- reply(client,orderId,1007,"canceled");
+void ServerCatchcopy::copyCanceled(const quint32 &client,const quint32 &orderId)
+{
+ reply(client,orderId,1007,"canceled");
}
-void ServerCatchcopy::unknowOrder(quint32 client,quint32 orderId)
+void ServerCatchcopy::unknowOrder(const quint32 &client,const quint32 &orderId)
{
- reply(client,orderId,5002,"unknown order");
+ reply(client,orderId,5002,"unknown order");
}
void ServerCatchcopy::checkTimeOut()
{
- QTimer *timer=qobject_cast<QTimer *>(QObject::sender());
- if(timer==NULL)
- {
- qWarning() << "Unallocated client timer!";
- return;
- }
- int index=0;
- while(index<ClientList.size())
- {
- if(ClientList.at(index).detectTimeOut==timer)
- {
- ClientList.at(index).detectTimeOut->stop();
- if(ClientList.at(index).haveData)
- {
- error_string="The client is too long to send the next part of the reply: "+ClientList.at(index).data;
- ClientList[index].haveData=false;
- ClientList[index].data.clear();
- ClientList.at(index).socket->disconnectFromServer();
- emit error(error_string);
- }
- return;
- }
- index++;
- }
+ QTimer *timer=qobject_cast<QTimer *>(QObject::sender());
+ if(timer==NULL)
+ {
+ qWarning() << "Unallocated client timer!";
+ return;
+ }
+ int index=0;
+ while(index<clientList.size())
+ {
+ if(clientList.at(index).detectTimeOut==timer)
+ {
+ clientList.at(index).detectTimeOut->stop();
+ if(clientList.at(index).haveData)
+ {
+ error_string="The client is too long to send the next part of the reply: "+clientList.at(index).data;
+ clientList[index].haveData=false;
+ clientList[index].data.clear();
+ clientList.at(index).socket->disconnectFromServer();
+ emit error(error_string);
+ }
+ return;
+ }
+ index++;
+ }
}
quint32 ServerCatchcopy::incrementOrderId()
{
- do
- {
- nextOrderId++;
- if(nextOrderId>2000000)
- nextOrderId=0;
- } while(orderList.contains(nextOrderId));
- return nextOrderId;
+ do
+ {
+ nextOrderId++;
+ if(nextOrderId>2000000)
+ nextOrderId=0;
+ } while(orderList.contains(nextOrderId));
+ return nextOrderId;
}
diff --git a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.h b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.h
index 5f7af35..1314d73 100755..100644
--- a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.h
+++ b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ServerCatchcopy.h
@@ -1,8 +1,7 @@
/** \file ServerCatchcopy.h
\brief Define the server of catchcopy
\author alpha_one_x86
-\version 0002
-\date 2010 */
+\licence GPL3, see the file COPYING */
#ifndef SERVERCATCHCOPY_H
#define SERVERCATCHCOPY_H
@@ -18,145 +17,128 @@
/// \brief Define the server of catchcopy
class ServerCatchcopy : public QObject
{
- Q_OBJECT
- public:
- ServerCatchcopy();
- ~ServerCatchcopy();
- /// \brief return if is listening
- bool isListening();
- /// \brief try listen
- bool listen();
- /// \brief try close the server
- void close();
- /// \brief get the error string on the QLocalServer
- const QString errorStringServer();
- /// \brief get the general error string
- const QString errorString();
- /// \brief set if automatic reply is used
- void setAutoReply(bool value);
- /// \brief get if autoReply is set
- bool getAutoReply();
- /// \brief set the name of the server
- void setName(const QString & name);
- /// \brief get the name
- QString getName();
- private:
- QString pathSocket;
- QString name;
- QString error_string;
- QLocalServer server;
- quint32 idNextClient;
- struct Client
- {
- quint32 id;
- QLocalSocket *socket;
- QByteArray data;
- bool haveData;
- quint32 dataSize;
- bool firstProtocolReplied;
- QList<quint32> queryNoReplied;
- QTimer *detectTimeOut;
- };
- QList<Client> ClientList;
- struct LinkGlobalToLocalClient
- {
- quint32 idClient;
- quint32 orderId;
- quint32 globalOrderId;
- };
- QList<LinkGlobalToLocalClient> LinkGlobalToLocalClientList;
- enum inputReturnType{Ok,Replied,ExtensionWrong,WrongArgument,WrongArgumentListSize,UnknowOrder};
- inputReturnType parseInputCurrentProtocol(quint32 client,quint32 orderId,QStringList returnList);
- bool autoReply;
- bool clientIdFound(quint32 id);
- quint32 nextOrderId;
- QList<quint32> orderList;
- quint32 incrementOrderId();
- void emitNewCopy(quint32 client,quint32 orderId,QStringList sources);
- void emitNewCopy(quint32 client,quint32 orderId,QStringList sources,QString destination);
- void emitNewMove(quint32 client,quint32 orderId,QStringList sources);
- void emitNewMove(quint32 client,quint32 orderId,QStringList sources,QString destination);
- bool checkDataIntegrity(QByteArray data);
- protected:
- void parseInput(quint32 client,quint32 orderId,QStringList returnList);
- private slots:
- void newConnection();
- void connectionError(QLocalSocket::LocalSocketError error);
- void disconnected();
- void readyRead();
- void checkTimeOut();
- public slots:
- /// \brief disconnect one client
- void disconnectClient(quint32 id);
- /// \brief reply to a client with QStringList
- void reply(quint32 client,quint32 orderId,quint32 returnCode,QStringList returnList);
- /// \brief reply to a client
- void reply(quint32 client,quint32 orderId,quint32 returnCode,QString returnString);
- //reply
- /// \brief send if the protocol is supported
- void protocolSupported(quint32 client,quint32 orderId,bool value);
- /// \brief send incorrect arguement list size
- void incorrectArgumentListSize(quint32 client,quint32 orderId);
- /// \brief send incorrect arguement
- void incorrectArgument(quint32 client,quint32 orderId);
- /// \brief send if protocol extension is supported
- void protocolExtensionSupported(quint32 client,quint32 orderId,bool value);
- /// \brief the client is registred
- void clientRegistered(quint32 client,quint32 orderId);
- /// \brief send the server name
- void serverName(quint32 client,quint32 orderId,QString name);
- /// \brief send the copy is finished
- void copyFinished(quint32 client,quint32 orderId,bool withError);
- /// \brief send the copy is canceled
- void copyCanceled(quint32 client,quint32 orderId);
- /// \brief send the copy is finished by global is order
- void copyFinished(quint32 globalOrderId,bool withError);
- /// \brief send copy cancel by global is order
- void copyCanceled(quint32 globalOrderId);
- /// \brief send the unknow order
- void unknowOrder(quint32 client,quint32 orderId);
- signals:
- /// \brief send connected client
- void connectedClient(quint32 id);
- /// \brief send disconnect client
- void disconnectedClient(quint32 id);
- /// \brief have new query
- void newQuery(quint32 client,quint32 orderId,QStringList returnList);
- /// \brief send new data as string list
- void dataSend(quint32 client,quint32 orderId,quint32 returnCode,QStringList returnList);
- /// \brief send new data as raw data
- void dataSend(quint32 client,quint32 orderId,quint32 returnCode,QByteArray block);
- /// \brief have new error
- void error(QString error);
- //query
- /// \brief ask the protocol compatility
- void askProtocolCompatibility(quint32 client,quint32 orderId,QString version);
- /// \brief ask protocol extension
- void askProtocolExtension(quint32 client,quint32 orderId,QString extension);
- /// \brief ask protocol extension with version
- void askProtocolExtension(quint32 client,quint32 orderId,QString extension,QString version);
- /// \brief send the client name, with query id
- void clientName(quint32 client,quint32 orderId,QString name);
- /// \brief send the client name, without query id
- void clientName(quint32 client,QString name);
- /// \brief send the client have ask the server name
- void askServerName(quint32 client,quint32 orderId);
- /// \brief copy is send, without destination
- void newCopy(quint32 client,quint32 orderId,QStringList sources);
- /// \brief copy is send, with destination
- void newCopy(quint32 client,quint32 orderId,QStringList sources,QString destination);
- /// \brief move is send, without destination
- void newMove(quint32 client,quint32 orderId,QStringList sources);
- /// \brief move is send, with destination
- void newMove(quint32 client,quint32 orderId,QStringList sources,QString destination);
- /// \brief copy is send, by globalOrderId, without destination
- void newCopy(quint32 globalOrderId,QStringList sources);
- /// \brief copy is send, by globalOrderId, with destination
- void newCopy(quint32 globalOrderId,QStringList sources,QString destination);
- /// \brief move is send, by globalOrderId, without destination
- void newMove(quint32 globalOrderId,QStringList sources);
- /// \brief move is send, by globalOrderId, with destination
- void newMove(quint32 globalOrderId,QStringList sources,QString destination);
+ Q_OBJECT
+ public:
+ ServerCatchcopy();
+ ~ServerCatchcopy();
+ /// \brief return if is listening
+ bool isListening() const;
+ /// \brief try listen
+ bool listen();
+ /// \brief try close the server
+ void close();
+ /// \brief get the error string on the QLocalServer
+ const QString errorStringServer() const;
+ /// \brief get the general error string
+ const QString errorString() const;
+ /// \brief set the name of the server
+ void setName(const QString & name);
+ /// \brief get the name
+ QString getName() const;
+ /// \brief to get a client list
+ QStringList clientsList() const;
+ private:
+ QString pathSocket;
+ QString name;
+ QString error_string;
+ QLocalServer server;
+ quint32 idNextClient;
+ struct Client
+ {
+ quint32 id;
+ QLocalSocket *socket;
+ QByteArray data;
+ bool haveData;
+ quint32 dataSize;
+ bool firstProtocolReplied;
+ QList<quint32> queryNoReplied;
+ QTimer *detectTimeOut;
+ QString name;
+ };
+ QList<Client> clientList;
+ struct LinkGlobalToLocalClient
+ {
+ quint32 idClient;
+ quint32 orderId;
+ quint32 globalOrderId;
+ };
+ QList<LinkGlobalToLocalClient> LinkGlobalToLocalClientList;
+ enum inputReturnType{Ok,Replied,ExtensionWrong,WrongArgument,WrongArgumentListSize,UnknowOrder};
+ inputReturnType parseInputCurrentProtocol(const quint32 &client,const quint32 &orderId,const QStringList &returnList);
+ bool clientIdFound(const quint32 &id) const;
+ quint32 nextOrderId;
+ QList<quint32> orderList;
+ quint32 incrementOrderId();
+ void emitNewCopyWithoutDestination(const quint32 &client,const quint32 &orderId,const QStringList &sources);
+ void emitNewCopy(const quint32 &client,const quint32 &orderId,const QStringList &sources,const QString &destination);
+ void emitNewMoveWithoutDestination(const quint32 &client,const quint32 &orderId,const QStringList &sources);
+ void emitNewMove(const quint32 &client,const quint32 &orderId,const QStringList &sources,const QString &destination);
+ bool checkDataIntegrity(const QByteArray &data);
+ protected:
+ void parseInput(const quint32 &client,const quint32 &orderId,const QStringList &returnList);
+ private slots:
+ void newConnection();
+ void connectionError(const QLocalSocket::LocalSocketError &error);
+ void disconnected();
+ void readyRead();
+ void checkTimeOut();
+ public slots:
+ /// \brief disconnect one client
+ void disconnectClient(const quint32 &id);
+ /// \brief reply to a client with QStringList
+ void reply(const quint32 &client,const quint32 &orderId,const quint32 &returnCode,const QStringList &returnList);
+ /// \brief reply to a client
+ void reply(const quint32 &client,const quint32 &orderId,const quint32 &returnCode,const QString &returnString);
+ //reply
+ /// \brief send if the protocol is supported
+ void protocolSupported(const quint32 &client,const quint32 &orderId,const bool &value);
+ /// \brief send incorrect arguement list size
+ void incorrectArgumentListSize(const quint32 &client,const quint32 &orderId);
+ /// \brief send incorrect arguement
+ void incorrectArgument(const quint32 &client,const quint32 &orderId);
+ /// \brief the client is registred
+ void clientRegistered(const quint32 &client,const quint32 &orderId);
+ /// \brief send the server name
+ void serverName(const quint32 &client,const quint32 &orderId,const QString &name);
+ /// \brief send the copy is finished
+ void copyFinished(const quint32 &client,const quint32 &orderId,const bool &withError);
+ /// \brief send the copy is canceled
+ void copyCanceled(const quint32 &client,const quint32 &orderId);
+ /// \brief send the copy is finished by global is order
+ void copyFinished(const quint32 &globalOrderId,const bool &withError);
+ /// \brief send copy cancel by global is order
+ void copyCanceled(const quint32 &globalOrderId);
+ /// \brief send the unknow order
+ void unknowOrder(const quint32 &client,const quint32 &orderId);
+ signals:
+ /// \brief send connected client
+ void connectedClient(const quint32 &id);
+ /// \brief send disconnect client
+ void disconnectedClient(const quint32 &id);
+ /// \brief have new query
+ void newQuery(const quint32 &client,const quint32 &orderId,const QStringList &returnList);
+ /// \brief have new error
+ void error(const QString &error);
+ void communicationError(const QString &error);
+ //query
+ /// \brief ask the protocol compatility
+ void askProtocolCompatibility(const quint32 &client,const quint32 &orderId,const QString &version);
+ /// \brief ask protocol extension
+ void askProtocolExtension(const quint32 &client,const quint32 &orderId,const QString &extension);
+ /// \brief ask protocol extension with version
+ void askProtocolExtension(const quint32 &client,const quint32 &orderId,const QString &extension,const QString &version);
+ /// \brief send the client name, without query id
+ void clientName(const quint32 &client,const QString &name);
+ /// \brief send the client have ask the server name
+ void askServerName(const quint32 &client,const quint32 &orderId);
+ /// \brief copy is send, by globalOrderId, without destination
+ void newCopyWithoutDestination(const quint32 &globalOrderId,const QStringList &sources);
+ /// \brief copy is send, by globalOrderId, with destination
+ void newCopy(const quint32 &globalOrderId,const QStringList &sources,const QString &destination);
+ /// \brief move is send, by globalOrderId, without destination
+ void newMoveWithoutDestination(const quint32 &globalOrderId,const QStringList &sources);
+ /// \brief move is send, by globalOrderId, with destination
+ void newMove(const quint32 &globalOrderId,const QStringList &sources,const QString &destination);
};
#endif // SERVERCATCHCOPY_H
diff --git a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/VariablesCatchcopy.h b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/VariablesCatchcopy.h
index ce73aee..135c087 100755..100644
--- a/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/VariablesCatchcopy.h
+++ b/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/VariablesCatchcopy.h
@@ -1,8 +1,7 @@
/** \file VariablesCatchcopy.h
\brief Define the variable for catchcopy
\author alpha_one_x86
-\version 0002
-\date 2010 */
+\licence GPL3, see the file COPYING */
#ifndef VARIABLECATCHCOPY_H
#define VARIABLECATCHCOPY_H
diff --git a/plugins/Listener/catchcopy-v0002/documentation.dox b/plugins/Listener/catchcopy-v0002/documentation.dox
index a15792a..b143ecc 100755..100644
--- a/plugins/Listener/catchcopy-v0002/documentation.dox
+++ b/plugins/Listener/catchcopy-v0002/documentation.dox
@@ -11,12 +11,12 @@
\section mainpage_overview Overview
Is the default listener to wait a copy/move. It use the catchcopy protocol.\n
- More informations on <a href="http://ultracopier-wiki.first-world.info/">the wiki of ultracopier</a>. Is part of Ultracopier 0.3 project.
+ More informations on <a href="http://ultracopier-wiki.first-world.info/">the wiki of ultracopier</a>.
\section mainpage_platforms Platforms
- This plugin might be usable in all environments where you find Qt 4.\n
- To be compatible with the official Ultracopier plugins, you need compil it with Gcc, Qt4.8, and same env as Ultracopier have been compiled, see the documentation.
+ Ultracopier might be usable in all environments where you find Qt 5.\n
+ Ultracopier requires Qt 5.0 or newer. Tested on Qt 5.0.
\section mainpage_downloads Downloads
diff --git a/plugins/Listener/catchcopy-v0002/informations.xml b/plugins/Listener/catchcopy-v0002/informations.xml
index e465da8..bc0efc6 100644
--- a/plugins/Listener/catchcopy-v0002/informations.xml
+++ b/plugins/Listener/catchcopy-v0002/informations.xml
@@ -17,11 +17,10 @@
<description xml:lang="en"><![CDATA[Listener for catchcopy v0002. Allow to receive copy list from plugin/explorer compatible with catchcopy.]]></description>
<description xml:lang="fr"><![CDATA[Écouteur pour catchcopy v0002. Permet de recevoir un liste de copie venant d'un plugin/explorateur avec catchcopy.]]></description>
<!-- Version of this release of this plugin, need be like that's: A.B.C.D, where A, B, C and D is number -->
- <version>0.3.1.0</version>
+ <version>1.2.3.6</version>
<!-- This internal name should never change, because it is used to detect when a particular plugin is updated. It must comprise only lower case ASCII characters (a-z), numerical digits (0-9), "-", "." or "_", and it must be be unique within the category. And have size lower than 64 char. -->
<name>catchcopy-v0002</name>
<!-- Dependency checking. This is used to check when a plugin may not be compatible with an updated version of either Ultracopier or another plugin. This example only checks Ultracopier. -->
<dependencies><![CDATA[
- >=ultracopier-0.3.1.0
]]></dependencies>
</package> \ No newline at end of file
diff --git a/plugins/Listener/catchcopy-v0002/listener.cpp b/plugins/Listener/catchcopy-v0002/listener.cpp
index 51f204e..55c254b 100755..100644
--- a/plugins/Listener/catchcopy-v0002/listener.cpp
+++ b/plugins/Listener/catchcopy-v0002/listener.cpp
@@ -1,83 +1,118 @@
-#include <QtCore>
-#include <QMessageBox>
-
#include "listener.h"
+#include "catchcopy-api-0002/ExtraSocketCatchcopy.h"
-CatchCopyPlugin::CatchCopyPlugin()
+Listener::Listener()
{
- server.setName(tr("Ultracopier"));
- connect(&server,SIGNAL(newCopy(quint32,QStringList)), this,SIGNAL(newCopy(quint32,QStringList)));
- connect(&server,SIGNAL(newCopy(quint32,QStringList,QString)), this,SIGNAL(newCopy(quint32,QStringList,QString)));
- connect(&server,SIGNAL(newMove(quint32,QStringList)), this,SIGNAL(newMove(quint32,QStringList)));
- connect(&server,SIGNAL(newMove(quint32,QStringList,QString)), this,SIGNAL(newMove(quint32,QStringList,QString)));
- connect(&server,SIGNAL(error(QString)), this,SLOT(error(QString)));
- connect(&server,SIGNAL(clientName(quint32,QString)), this,SLOT(clientName(quint32,QString)));
+ server.setName(tr("Ultracopier"));
+ connect(&server,&ServerCatchcopy::newCopyWithoutDestination, this,&Listener::copyWithoutDestination);
+ connect(&server,&ServerCatchcopy::newCopy, this,&Listener::copy);
+ connect(&server,&ServerCatchcopy::newMoveWithoutDestination, this,&Listener::moveWithoutDestination);
+ connect(&server,&ServerCatchcopy::newMove, this,&Listener::move);
+ connect(&server,&ServerCatchcopy::error, this,&Listener::errorInternal);
+ connect(&server,&ServerCatchcopy::communicationError, this,&Listener::communicationErrorInternal);
+ connect(&server,&ServerCatchcopy::clientName, this,&Listener::clientName);
+ connect(&server,&ServerCatchcopy::clientName, this,&Listener::newClientList);
+ connect(&server,&ServerCatchcopy::connectedClient, this,&Listener::newClientList);
+ connect(&server,&ServerCatchcopy::disconnectedClient, this,&Listener::newClientList);
+
}
-void CatchCopyPlugin::listen()
+void Listener::listen()
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- if(server.listen())
- emit newState(FullListening);
- else
- emit newState(NotListening);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start: %1").arg(ExtraSocketCatchcopy::pathSocket()));
+ if(server.listen())
+ emit newState(Ultracopier::FullListening);
+ else
+ emit newState(Ultracopier::NotListening);
}
-void CatchCopyPlugin::close()
+void Listener::close()
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- server.close();
- emit newState(NotListening);
+ server.close();
+ emit newState(Ultracopier::NotListening);
}
-const QString CatchCopyPlugin::errorString()
+const QString Listener::errorString() const
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- return server.errorString();
+ return server.errorString();
}
-void CatchCopyPlugin::setResources(OptionInterface * options,QString writePath,QString pluginPath,bool portableVersion)
+void Listener::setResources(OptionInterface * options,const QString &writePath,const QString &pluginPath,const bool &portableVersion)
{
- Q_UNUSED(options);
- Q_UNUSED(writePath);
- Q_UNUSED(pluginPath);
- Q_UNUSED(portableVersion);
+ Q_UNUSED(options);
+ Q_UNUSED(writePath);
+ Q_UNUSED(pluginPath);
+ Q_UNUSED(portableVersion);
}
/// \brief to get the options widget, NULL if not have
-QWidget * CatchCopyPlugin::options()
+QWidget * Listener::options()
{
- return NULL;
+ return NULL;
}
-Q_EXPORT_PLUGIN2(listener, CatchCopyPlugin);
+/// \brief to get a client list
+QStringList Listener::clientsList() const
+{
+ return server.clientsList();
+}
-void CatchCopyPlugin::transferFinished(quint32 orderId,bool withError)
+void Listener::transferFinished(const quint32 &orderId,const bool &withError)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start, orderId: "+QString::number(orderId)+", withError: "+QString::number(withError));
- server.copyFinished(orderId,withError);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, orderId: "+QString::number(orderId)+", withError: "+QString::number(withError));
+ server.copyFinished(orderId,withError);
}
-void CatchCopyPlugin::transferCanceled(quint32 orderId)
+void Listener::transferCanceled(const quint32 &orderId)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start, orderId: "+QString::number(orderId));
- server.copyCanceled(orderId);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, orderId: "+QString::number(orderId));
+ server.copyCanceled(orderId);
}
/// \brief to reload the translation, because the new language have been loaded
-void CatchCopyPlugin::newLanguageLoaded()
+void Listener::newLanguageLoaded()
+{
+}
+
+void Listener::errorInternal(const QString &string)
+{
+ Q_UNUSED(string);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"warning emited from Catchcopy lib: "+string);
+}
+
+void Listener::communicationErrorInternal(const QString &string)
+{
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"warning emited from Catchcopy lib: "+string);
+ emit error(string);
+}
+
+void Listener::clientName(quint32 client,QString name)
+{
+ Q_UNUSED(client);
+ Q_UNUSED(name);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("clientName: %1, for the id: %2").arg(name).arg(client));
+}
+
+void Listener::copyWithoutDestination(const quint32 &orderId,const QStringList &sources)
+{
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("copyWithoutDestination(%1,%2)").arg(orderId).arg(sources.join(";")));
+ emit newCopyWithoutDestination(orderId,sources);
+}
+
+void Listener::copy(const quint32 &orderId,const QStringList &sources,const QString &destination)
{
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("copy(%1,%2,%3)").arg(orderId).arg(sources.join(";")).arg(destination));
+ emit newCopy(orderId,sources,destination);
}
-void CatchCopyPlugin::error(QString error)
+void Listener::moveWithoutDestination(const quint32 &orderId,const QStringList &sources)
{
- Q_UNUSED(error);
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"warning emited from Catchcopy lib: "+error);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("moveWithoutDestination(%1,%2)").arg(orderId).arg(sources.join(";")));
+ emit newMoveWithoutDestination(orderId,sources);
}
-void CatchCopyPlugin::clientName(quint32 client,QString name)
+void Listener::move(const quint32 &orderId,const QStringList &sources,const QString &destination)
{
- Q_UNUSED(client);
- Q_UNUSED(name);
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,QString("clientName: %1, for the id: %2").arg(name).arg(client));
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("move(%1,%2,%3)").arg(orderId).arg(sources.join(";")).arg(destination));
+ emit newMove(orderId,sources,destination);
}
diff --git a/plugins/Listener/catchcopy-v0002/listener.h b/plugins/Listener/catchcopy-v0002/listener.h
index 0ef0dc7..8956abc 100755..100644
--- a/plugins/Listener/catchcopy-v0002/listener.h
+++ b/plugins/Listener/catchcopy-v0002/listener.h
@@ -1,62 +1,59 @@
/** \file listener.h
\brief Define the server compatible with Ultracopier interface
\author alpha_one_x86
-\version 0.3
-\date 2010 */
+\licence GPL3, see the file COPYING */
#ifndef SERVER_H
#define SERVER_H
-#include <QObject>
+#include <QString>
+#ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE_DIRECT
+#include <QtPlugin>
+#endif
#include "Environment.h"
#include "../../../interface/PluginInterface_Listener.h"
#include "catchcopy-api-0002/ServerCatchcopy.h"
/// \brief Define the server compatible with Ultracopier interface
-class CatchCopyPlugin : public PluginInterface_Listener
+class Listener : public PluginInterface_Listener
{
- Q_OBJECT
- Q_INTERFACES(PluginInterface_Listener)
+ Q_OBJECT
+ #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE_DIRECT
+ Q_PLUGIN_METADATA(IID "first-world.info.ultracopier.PluginInterface.Listener/1.0.0.0" FILE "plugin.json")
+ Q_INTERFACES(PluginInterface_Listener)
+ #endif
public:
- CatchCopyPlugin();
- /// \brief try listen the copy/move
- void listen();
- /// \brief stop listen to copy/move
- void close();
- /// \brief return the error strong
- const QString errorString();
- /// \brief set resources for this plugins
- void setResources(OptionInterface * options,QString writePath,QString pluginPath,bool portableVersion);
- /// \brief to get the options widget, NULL if not have
- QWidget * options();
+ Listener();
+ /// \brief try listen the copy/move
+ void listen();
+ /// \brief stop listen to copy/move
+ void close();
+ /// \brief return the error strong
+ const QString errorString() const;
+ /// \brief set resources for this plugins
+ void setResources(OptionInterface * options,const QString &writePath,const QString &pluginPath,const bool &portableVersion);
+ /// \brief to get the options widget, NULL if not have
+ QWidget * options();
+ /// \brief to get a client list
+ QStringList clientsList() const;
public slots:
- /// \brief say to the client that's the copy/move is finished
- void transferFinished(quint32 orderId,bool withError);
- /// \brief say to the client that's the copy/move is finished
- void transferCanceled(quint32 orderId);
- /// \brief to reload the translation, because the new language have been loaded
- void newLanguageLoaded();
+ /// \brief say to the client that's the copy/move is finished
+ void transferFinished(const quint32 &orderId,const bool &withError);
+ /// \brief say to the client that's the copy/move is finished
+ void transferCanceled(const quint32 &orderId);
+ /// \brief to reload the translation, because the new language have been loaded
+ void newLanguageLoaded();
private:
- ServerCatchcopy server;
+ ServerCatchcopy server;
private slots:
- void error(QString error);
- void clientName(quint32 client,QString name);
-signals:
- #ifdef ULTRACOPIER_PLUGIN_DEBUG
- /// \brief To debug source
- void debugInformation(DebugLevel level,QString fonction,QString text,QString file,int ligne);
- #endif
- /// \brief new state
- void newState(ListeningState state);
- /// \brief new copy is incoming
- void newCopy(quint32 orderId,QStringList sources);
- /// \brief new copy is incoming, with destination
- void newCopy(quint32 orderId,QStringList sources,QString destination);
- /// \brief new move is incoming
- void newMove(quint32 orderId,QStringList sources);
- /// \brief new move is incoming, with destination
- void newMove(quint32 orderId,QStringList sources,QString destination);
+ void errorInternal(const QString &string);
+ void communicationErrorInternal(const QString &string);
+ void clientName(quint32 client,QString name);
+ void copyWithoutDestination(const quint32 &orderId,const QStringList &sources);
+ void copy(const quint32 &orderId,const QStringList &sources,const QString &destination);
+ void moveWithoutDestination(const quint32 &orderId,const QStringList &sources);
+ void move(const quint32 &orderId,const QStringList &sources,const QString &destination);
};
#endif // SERVER_H
diff --git a/plugins/Listener/catchcopy-v0002/listener.pro b/plugins/Listener/catchcopy-v0002/listener.pro
index 5903fa4..f1706c5 100644
--- a/plugins/Listener/catchcopy-v0002/listener.pro
+++ b/plugins/Listener/catchcopy-v0002/listener.pro
@@ -1,6 +1,11 @@
+CONFIG += c++11
+QMAKE_CXXFLAGS+="-std=c++0x -Wall -Wextra"
+mac:QMAKE_CXXFLAGS+="-stdlib=libc++"
+
TEMPLATE = lib
CONFIG += plugin
QT += network
+win32:LIBS += -ladvapi32
HEADERS = listener.h \
catchcopy-api-0002/VariablesCatchcopy.h \
catchcopy-api-0002/ServerCatchcopy.h \
@@ -14,4 +19,3 @@ SOURCES = listener.cpp \
catchcopy-api-0002/ServerCatchcopy.cpp \
catchcopy-api-0002/ExtraSocketCatchcopy.cpp
TARGET = $$qtLibraryTarget(listener)
-
diff --git a/plugins/Listener/catchcopy-v0002/plugin.json b/plugins/Listener/catchcopy-v0002/plugin.json
new file mode 100644
index 0000000..9e26dfe
--- /dev/null
+++ b/plugins/Listener/catchcopy-v0002/plugin.json
@@ -0,0 +1 @@
+{} \ No newline at end of file