summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <b0ris@b0ris-satellite.localdomain>2011-11-03 19:01:35 +0200
committerAlex <b0ris@b0ris-satellite.localdomain>2011-11-03 19:01:35 +0200
commit83f10691557953e9d164df36a12f8a0fd7d33dc4 (patch)
treede9b10b11f0528719a28f7d42502785f12ed42ed
parentda3277b21e4a947691df84eb35f675c6f06a4369 (diff)
Handle server reply (SslClient not tested)
-rw-r--r--client/SslClient.cpp40
-rw-r--r--client/SslClient.h9
2 files changed, 41 insertions, 8 deletions
diff --git a/client/SslClient.cpp b/client/SslClient.cpp
index d54523c..5a309c4 100644
--- a/client/SslClient.cpp
+++ b/client/SslClient.cpp
@@ -97,19 +97,51 @@ void SslClient::SendRequest(RequestType type)
*/
void SslClient::Connected()
{
- Logger::Info("Connected to server\n");
+ Logger::Info("Connected to server %s\n", server.toStdString().c_str());
}
void SslClient::Disconnected()
{
- Logger::Info("Disconnected from server\n");
+ Logger::Info("Disconnected from server %s\n", server.toStdString().c_str());
}
void SslClient::DataRecieved()
{
- Logger::Trace("Reply recieved\n");
+ Logger::Trace("Recieved reply from %s\n", server.toStdString().c_str());
QByteArray data = sslSocket->readAll();
- qDebug() << data;
+
+ int length = data.size();
+ char h1 = data[0];
+ char h2 = data[1];
+ char t1 = data[length-1];
+ char t2 = data[length];
+ if ((h1 != 0x13) || (h2 != 0x13) ||
+ (t1 != 0x14) || (t2 != 0x14))
+ {
+ Logger::Error("Invalid data packet recieved!");
+ return;
+ }
+
+ RequestType type;
+ char rcode = data[2];
+ switch (rcode)
+ {
+ case 0x01:
+ case 0x02:
+ case 0x04:
+ case 0x08:
+ type = (RequestType)rcode;
+ break;
+ default:
+ Logger::Error("Invalid reply code: %x\n", rcode);
+ return;
+ }
+
+ /* remove header and tail */
+ data.remove(0, 3);
+ data.remove(length-1, 2);
+
+ emit ReplyRecieved(type, data);
}
void SslClient::Error(QAbstractSocket::SocketError socketError)
diff --git a/client/SslClient.h b/client/SslClient.h
index c8126f6..3b8f0bb 100644
--- a/client/SslClient.h
+++ b/client/SslClient.h
@@ -5,6 +5,7 @@
#include <QAbstractSocket>
#include <QObject>
+class QByteArray;
class QSslSocket;
class QSslError;
class QString;
@@ -14,8 +15,8 @@ class QString;
* - Uses SSL protocol to communicate with server
* - Requests config/static or generic proxy lists/firewall list
* - Server port - 13666
- * - Request format: [0x13 0x13 code 0x14 0x14]
- * - Reply format: [0x13 0x13 code [data] 0x14 0x14]
+ * - Request format: [0x13 0x13 rcode 0x14 0x14]
+ * - Reply format: [0x13 0x13 rcode [data] 0x14 0x14]
* - Request codes:
* -# 0x01 - request client config
* -# 0x02 - request generic proxy list
@@ -27,7 +28,7 @@ class SslClient: QObject
Q_OBJECT
public:
/**
- * @enum RequestType Enumerate all possible request types
+ * @enum RequestType Enumerates all possible request types
*/
enum RequestType
{
@@ -78,7 +79,7 @@ signals:
* particular request
* @param type of request this reply corresponds to
*/
- void ReplyRecieved(RequestType type);
+ void ReplyRecieved(RequestType &type, QByteArray &confdata);
private slots:
void Connected();
void Disconnected();