summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorAlex Borisov <borisov.alexandr@rambler.ru>2011-11-28 23:02:47 +0200
committerAlex Borisov <borisov.alexandr@rambler.ru>2011-11-28 23:02:47 +0200
commit29043c381edb0fa8934a187be3cfd757cf787996 (patch)
treeb513c11fea783fbb079d8f69a3cd1634776637c5 /client
parentee207db191173eb964c50261bc624c1ffcef715b (diff)
Code to test file transfer
Diffstat (limited to 'client')
-rw-r--r--client/DownloadClient.cpp46
-rw-r--r--client/ProxyClientApp.cpp1
-rw-r--r--client/SslClient.cpp16
-rw-r--r--client/SslClient.h6
4 files changed, 38 insertions, 31 deletions
diff --git a/client/DownloadClient.cpp b/client/DownloadClient.cpp
index df4da25..b834622 100644
--- a/client/DownloadClient.cpp
+++ b/client/DownloadClient.cpp
@@ -19,7 +19,7 @@ void DownloadClient::Download(const string &filename)
pair<string, string> file(filename, 0);
vector<pair<string, string> > fileList;
fileList.push_back(file);
- Download(fileList);
+ Download(fileList);
}
void DownloadClient::Download(const pair<string, string> &file)
@@ -46,6 +46,28 @@ void DownloadClient::Download(const vector<pair<string, string> > &fileList)
DoDownload();
}
+void DownloadClient::DoDownload()
+{
+ if (currentId < (int)files.size())
+ {
+ currentId++;
+ pair<string, string> file = files[currentId];
+ QString filename = QString::fromLocal8Bit(file.first.c_str());
+ string md5 = file.second;
+ current = new QFile(filename);
+ current->open(QIODevice::ReadWrite);
+
+ Logger::Info("Downloading file %s\n", file.first.c_str());
+ SendFileRequest(file.first);
+ }
+ else
+ {
+ Logger::Info("All files have been downloaded.");
+ isDownloading = false;
+ emit downloadFinished();
+ }
+}
+
void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray &data)
{
if (type != RegularFile)
@@ -86,25 +108,3 @@ void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray &
DoDownload();
}
}
-
-void DownloadClient::DoDownload()
-{
- if (currentId < (int)files.size())
- {
- currentId++;
- pair<string, string> file = files[currentId];
- QString filename = QString::fromLocal8Bit(file.first.c_str());
- string md5 = file.second;
- current = new QFile(filename);
- current->open(QIODevice::ReadWrite);
-
- Logger::Info("Downloading file %s\n", file.first.c_str());
- SendFileRequest(file.first);
- }
- else
- {
- Logger::Info("All files have been downloaded.");
- isDownloading = false;
- emit downloadFinished();
- }
-}
diff --git a/client/ProxyClientApp.cpp b/client/ProxyClientApp.cpp
index 73df138..6dcfed2 100644
--- a/client/ProxyClientApp.cpp
+++ b/client/ProxyClientApp.cpp
@@ -25,7 +25,6 @@ ProxyClientApp::ProxyClientApp(int &argc, char *argv[]): QApplication(argc, argv
Logger::Fatal("No system tray available! Terminating.\n");
return;
}
-
QApplication::setQuitOnLastWindowClosed(false);
// create system tray menu
diff --git a/client/SslClient.cpp b/client/SslClient.cpp
index b1841ed..c087c40 100644
--- a/client/SslClient.cpp
+++ b/client/SslClient.cpp
@@ -4,6 +4,8 @@
#include <QtNetwork>
#include "SslClient.h"
+QSslSocket SslClient::sslSocket;
+
SslClient::SslClient(): port(13666)
{
SslClient(QString("127.0.0.1"));
@@ -35,7 +37,6 @@ SslClient::SslClient(QString addr): port(13666)
cert_file.close();
/* create ssl socket */
- //sslSocket = new QSslSocket;
sslSocket.setLocalCertificate(cert);
sslSocket.setPrivateKey(key);
sslSocket.setCaCertificates(ca_certs);
@@ -73,8 +74,11 @@ void SslClient::SendRequest(RequestType type)
if (sslSocket.state() != QAbstractSocket::ConnectedState)
{
Logger::Trace("Connecting to server %s:%u\n", server.toLocal8Bit().data(), port);
- //sslSocket.connectToHostEncrypted(server, port);
- sslSocket.connectToHostEncrypted("127.0.0.1", port);
+ sslSocket.connectToHostEncrypted(server, port);
+ while (! sslSocket.waitForConnected(5000))
+ {
+ Logger::Trace("Waiting for connection to be established...\n");
+ }
}
else
{
@@ -109,6 +113,10 @@ void SslClient::SendFileRequest(string filename)
{
Logger::Trace("Connecting to server %s:%u\n", server.toLocal8Bit().data(), port);
sslSocket.connectToHostEncrypted(server, port);
+ while (! sslSocket.waitForConnected(5000))
+ {
+ Logger::Trace("Waiting for connection to be established...\n");
+ }
}
else
{
@@ -125,7 +133,7 @@ void SslClient::SendFileRequest(string filename)
data[path_len - 1] = data[path_len - 2] = 0x14;
QByteArray pkt(data);
- sslSocket.write(pkt);
+ sslSocket.write(pkt);
}
diff --git a/client/SslClient.h b/client/SslClient.h
index a6b981c..3c4976c 100644
--- a/client/SslClient.h
+++ b/client/SslClient.h
@@ -120,8 +120,8 @@ public:
/**
* @brief disconnect from server
*/
- void Disconnect();
-
+ void Disconnect();
+
signals:
/**
* @brief This signal is emited when data is recieved as a reply to
@@ -148,7 +148,7 @@ protected:
QString server;
private:
- QSslSocket sslSocket;
+ static QSslSocket sslSocket;
unsigned short port;
};