summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/Config.cpp33
-rw-r--r--client/Config.h24
-rw-r--r--client/SslClient.cpp10
-rw-r--r--client/SslClient.h13
-rw-r--r--client/client.pro3
5 files changed, 71 insertions, 12 deletions
diff --git a/client/Config.cpp b/client/Config.cpp
index 429d615..7e617a3 100644
--- a/client/Config.cpp
+++ b/client/Config.cpp
@@ -3,7 +3,9 @@
#include <fstream>
#include <sstream>
#include <stdlib.h>
+#include <QtCore>
#include "Config.h"
+#include "SslClient.h"
using namespace std;
@@ -16,8 +18,10 @@ Config *Config::CurrentConfig()
return self;
}
-Config::Config(): StaticProxySpeedLow(50), configValid(0)
+Config::Config(): QObject(), StaticProxySpeedLow(50)
{
+ configValid = false;
+
Logger::Info("Parsing config.cfg to determine initial configuration\n");
ifstream configFile("config.cfg", std::ios::in);
if (!configFile)
@@ -86,6 +90,18 @@ Config::Config(): StaticProxySpeedLow(50), configValid(0)
Logger::Warn("Unrecognized config option: %s\n", key.c_str());
}
}
+
+ configUpdateTimer = new QTimer;
+ configUpdateTimer->setInterval(updateInterval * 1000);
+ connect(configUpdateTimer, SIGNAL(timeout()),
+ this, SLOT(updateConfig()));
+
+ client = new SslClient(servers[0].host);
+ /*
+ connect(client, SIGNAL(ReplyRecieved(SslClient::RequestType&, QByteArray&)),
+ this, SLOT(gotServerReply(SslClient::RequestType&, QByteArray&)));
+ */
+ client->SendRequest(SslClient::Config);
}
void Config::AcquireConfig()
@@ -275,6 +291,21 @@ int Config::ReadStaticProxy()
return 0;
}
+void Config::updateConfig()
+{
+ Logger::Trace("Going to update entire configuration\n");
+
+ /**
+ * @todo Count retries and switch between server records
+ */
+}
+
+void Config::gotServerReply(SslClient::RequestType &type, QByteArray &confdata)
+{
+ Logger::Trace("Got server reply w type: %x\n", type);
+ Logger::Trace("%s\n", confdata.data());
+}
+
/***
* Nested class section
diff --git a/client/Config.h b/client/Config.h
index c95d9c6..11bed90 100644
--- a/client/Config.h
+++ b/client/Config.h
@@ -4,13 +4,15 @@
#define CONFIG_H
#include <client.h>
+#include <QObject>
#include "Proxy.h"
+#include <SslClient.h>
using std::vector;
using std::string;
-class ProxyEntryGeneric;
-class ProxyEntryStatic;
+class SslClient;
+class QTimer;
/**
* @brief Singleton class that represents client configuration<br/>
@@ -19,8 +21,9 @@ class ProxyEntryStatic;
* Then retries is made to connect to server and acqire actual config,
* firewall list, etc.
*/
-class Config
+class Config: public QObject
{
+ Q_OBJECT
public:
/**
* @brief Class to represent 'firewall' record in the config file
@@ -207,11 +210,21 @@ private:
* @brief Pointer to the singleton Config instance
*/
static Config *self;
-
+
/**
* @brief time interval between consequtive config updates
*/
unsigned updateInterval;
+
+ /**
+ * @brief SslCLient instance that connects to server and retrieves config
+ */
+ SslClient *client;
+
+ /**
+ * @brief timer that is responsible on config updates
+ */
+ QTimer *configUpdateTimer;
bool configValid;
vector<ProxyEntryGeneric> genericProxy;
vector<ProxyEntryStatic> staticProxy;
@@ -219,6 +232,9 @@ private:
vector<ServerEntry> servers;
int ReadGenericProxy();
int ReadStaticProxy();
+private slots:
+ void updateConfig();
+ void gotServerReply(SslClient::RequestType &type, QByteArray &confdata);
};
diff --git a/client/SslClient.cpp b/client/SslClient.cpp
index fff44ea..70d32a7 100644
--- a/client/SslClient.cpp
+++ b/client/SslClient.cpp
@@ -1,7 +1,6 @@
#include <QtCore>
#include <QtNetwork>
-#include "client.h"
#include "SslClient.h"
SslClient::SslClient(): port(13666)
@@ -9,6 +8,11 @@ SslClient::SslClient(): port(13666)
SslClient((char*)"127.0.0.1");
}
+SslClient::SslClient(string &addr): port(13666)
+{
+ SslClient((char*)addr.c_str());
+}
+
SslClient::SslClient(char* addr): port(13666)
{
server = addr;
@@ -52,7 +56,7 @@ SslClient::SslClient(char* addr): port(13666)
connect(sslSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(Error(QAbstractSocket::SocketError)));
connect(sslSocket, SIGNAL(peerVerifyError(const QSslError &)),
- this, SLOT(PeerVerifyError(const QsslError)));
+ this, SLOT(PeerVerifyError(const QSslError)));
connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)),
this, SLOT(SslErrors(const QList<QSslError> &)));
}
@@ -64,7 +68,7 @@ void SslClient::SetServerAddr(char* addr)
void SslClient::SendRequest(RequestType type)
{
- if (sslSocket->state() == QAbstractSocket::ConnectedState)
+ if (sslSocket->state() != QAbstractSocket::ConnectedState)
sslSocket->connectToHostEncrypted(server, port);
unsigned char rcode = 0x00;
diff --git a/client/SslClient.h b/client/SslClient.h
index 3b8f0bb..3a00de5 100644
--- a/client/SslClient.h
+++ b/client/SslClient.h
@@ -4,6 +4,9 @@
#include <QAbstractSocket>
#include <QObject>
+#include "client.h"
+
+using std::string;
class QByteArray;
class QSslSocket;
@@ -23,7 +26,7 @@ class QString;
* -# 0x04 - request static proxy list
* -# 0x08 - request firewall host list
*/
-class SslClient: QObject
+class SslClient: public QObject
{
Q_OBJECT
public:
@@ -57,6 +60,12 @@ public:
SslClient();
/**
+ * @brief setup ssl socket ans it's type, certificates and key
+ * @param addr server address or hostname to connect to
+ */
+ SslClient(string &addr);
+
+ /**
* @brief setup ssl socket ans it's type, certificates and key
* @param addr server address or hostname to connect to
*/
@@ -79,7 +88,7 @@ signals:
* particular request
* @param type of request this reply corresponds to
*/
- void ReplyRecieved(RequestType &type, QByteArray &confdata);
+ void ReplyRecieved(SslClient::RequestType &type, QByteArray &confdata);
private slots:
void Connected();
void Disconnected();
diff --git a/client/client.pro b/client/client.pro
index 403b581..c722957 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -21,5 +21,4 @@ SOURCES += Dialog.cpp main.cpp Proxy.cpp ProxyClientApp.cpp Logger.cpp Config.cp
OTHER_FILES +=
-RESOURCES += \
- client.qrc
+RESOURCES += client.qrc