summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Borisov <borisov.alexandr@rambler.ru>2011-12-21 04:06:39 +0200
committerAlex Borisov <borisov.alexandr@rambler.ru>2011-12-21 04:06:39 +0200
commit2fd868ae27d74305310e5bcd2a81cd07a87659b3 (patch)
tree03141523c396af45835e070e858216633a05fc6b
parent2f559d0e236c797e670f47cd70f52cde01092389 (diff)
Generic proxy button work now. Proxy types support
-rw-r--r--client/Config.cpp22
-rw-r--r--client/Config.h14
-rw-r--r--client/Dialog.cpp56
-rw-r--r--client/Dialog.h3
-rw-r--r--client/Proxy.cpp28
-rw-r--r--client/SslClient.cpp6
6 files changed, 97 insertions, 32 deletions
diff --git a/client/Config.cpp b/client/Config.cpp
index 489818e..ab06fb3 100644
--- a/client/Config.cpp
+++ b/client/Config.cpp
@@ -179,25 +179,24 @@ vector<string> Config::GetCities(string &country, string &state)
return cities;
}
-vector<string> Config::GetProxies(string &country, string &city)
+vector<Proxy> Config::GetProxies(string &country, string &city)
{
string defState = "-";
return GetProxies(country, defState, city);
}
-vector<string> Config::GetProxies(string &country, string &state, string &city)
+vector<Proxy> Config::GetProxies(string &country, string &state, string &city)
{
- vector<string> proxies;
+ vector<Proxy> proxies;
for (unsigned i = 0; i < genericProxy.size(); i++)
{
if ((genericProxy[i].state == state) &&
(genericProxy[i].country == country) &&
(genericProxy[i].city == city))
{
- proxies.push_back(genericProxy[i].host);
+ proxies.push_back(genericProxy[i]);
}
}
- sort(proxies.begin(), proxies.end());
return proxies;
}
@@ -213,6 +212,19 @@ ProxyEntryStatic* Config::GetStaticProxy(string& name)
return NULL;
}
+ProxyEntryGeneric* Config::GetGenericProxy(string host, short port)
+{
+ for (unsigned i = 0; i < genericProxy.size(); i++)
+ {
+ if ((host.compare(genericProxy[i].host) == 0) && (port == genericProxy[i].port))
+ {
+ return &genericProxy[i];
+ }
+ }
+ return NULL;
+
+}
+
vector<ProxyEntryStatic> Config::GetStaticProxyGuiLine(unsigned line)
{
vector<ProxyEntryStatic> staticProxyLine;
diff --git a/client/Config.h b/client/Config.h
index f7653e0..a6e9e6a 100644
--- a/client/Config.h
+++ b/client/Config.h
@@ -166,7 +166,7 @@ public:
* @param city name of city to get list of proxies for
* @return Alphabetically sorted vector<string> with unique proxy names
*/
- vector<string> GetProxies(string &country, string &city);
+ vector<Proxy> GetProxies(string &country, string &city);
/**
* @brief Get list of proxy server addresses in particular country, state and city<br/>
@@ -176,16 +176,24 @@ public:
* @param city name of city to get list of proxies for
* @return Alphabetically sorted vector<string> with unique proxy names
*/
- vector<string> GetProxies(string &country, string &state, string &city);
+ vector<Proxy> GetProxies(string &country, string &state, string &city);
/**
* @brief Get static proxy entry by name
* @param name static proxy name
- * @return ProxyEntryStatic object on success or false otherwise
+ * @return pointer to ProxyEntryStatic object on success or NULL otherwise
*/
ProxyEntryStatic* GetStaticProxy(string& name);
/**
+ * @brief Getgeneric proxy entry by host name and port values
+ * @param host host name of proxy to check for
+ * port port value of proxy to check for
+ * @return pointer to ProxyEntryGeneric object on success or NULL otherwise
+ */
+ ProxyEntryGeneric* GetGenericProxy(string host, short port);
+
+ /**
* @brief Get list of static proxy entries
* @param line number of GUI line proxy list associated with
* @return List of static proxy entries sorted by speed in descending order
diff --git a/client/Dialog.cpp b/client/Dialog.cpp
index 279bfc8..6df4ceb 100644
--- a/client/Dialog.cpp
+++ b/client/Dialog.cpp
@@ -10,6 +10,7 @@
using namespace std;
+
ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent)
{
UpdatedConfig *cfg = UpdatedConfig::CurrentConfig();
@@ -18,6 +19,7 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent)
if (!proxifier->IsValid())
{
Logger::Fatal("No valid proxifier configuration file found!\n");
+ return;
}
/* generic proxy panel */
@@ -94,7 +96,7 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent)
btn->setChecked(proxifier->IsOn(staticProxyLine[j].host, staticProxyLine[j].port));
btn->setProperty("proxyName", QString::fromLocal8Bit(staticProxyLine[j].name.c_str()));
btn->setLayout(btnLayout);
- connect(btn, SIGNAL(toggled(bool)), this, SLOT(StaticToggled(bool)));
+ connect(btn, SIGNAL(toggled(bool)), this, SLOT(StaticProxyToggled(bool)));
staticProxyGroup->addButton(btn);
bottomPanelLayout->addWidget(btn, i, j);
}
@@ -109,7 +111,42 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent)
setLayout(mainLayout);
}
-void ProxyDialog::StaticToggled(bool on)
+
+void ProxyDialog::ProxyToggled(bool on)
+{
+ QPushButton* btn = (QPushButton*) sender();
+ QVariant propVal;
+ propVal = btn->property("proxyHost");
+ QString proxyHost = propVal.toString();
+ propVal = btn->property("proxyPort");
+ short port = (short)propVal.toUInt();
+ Logger::Debug("Proxy button toggled\n");
+ Logger::Debug("State '%s', associated proxy: %s:%u\n", on ? "down" : "up", proxyHost.toStdString().c_str(), port);
+
+ UpdatedConfig *cfg = UpdatedConfig::CurrentConfig();
+ string host = proxyHost.toStdString();
+ ProxyEntryGeneric* proxy = cfg->GetGenericProxy(host, port);
+ if (proxy == NULL)
+ {
+ Logger::Error("Generic proxy %s:%u was not found\n", host.c_str(), port);
+ return;
+ }
+ Proxifier *proxifier = Proxifier::GetInstance();
+ if (!proxifier->IsValid())
+ {
+ Logger::Fatal("No valid proxifier configuration file found!\n");
+ }
+ if (on)
+ {
+ proxifier->TurnProxyOn(*proxy);
+ }
+ else
+ {
+ proxifier->TurnProxyOff(*proxy);
+ }
+}
+
+void ProxyDialog::StaticProxyToggled(bool on)
{
QPushButton* btn = (QPushButton*) sender();
QVariant propVal = btn->property("proxyName");
@@ -217,7 +254,7 @@ void ProxyDialog::CityActivated(int index)
return;
}
- vector<string> proxies;
+ vector<Proxy> proxies;
UpdatedConfig *cfg = UpdatedConfig::CurrentConfig();
string country(countryBox->currentText().toLocal8Bit().constData());
string city(cityBox->currentText().toLocal8Bit().constData());
@@ -243,11 +280,22 @@ void ProxyDialog::CityActivated(int index)
}
Logger::Trace("Adding new buttons\n");
+ Proxifier *proxifier = Proxifier::GetInstance();
+ if (!proxifier->IsValid())
+ {
+ Logger::Fatal("No valid proxifier configuration file found!\n");
+ return;
+ }
for (unsigned i = 0; i < proxies.size(); i++)
{
- QString btnStr = QString::fromLocal8Bit(proxies[i].c_str());
+ QString btnStr = QString::fromLocal8Bit(proxies[i].host.c_str());
QPushButton *btn = new QPushButton(btnStr);
btn->setCheckable(true);
+ btn->setChecked(proxifier->IsOn(proxies[i].host, proxies[i].port));
+ btn->setProperty("proxyHost", QString::fromLocal8Bit(proxies[i].host.c_str()));
+ btn->setProperty("proxyPort", proxies[i].port);
+
+ connect(btn, SIGNAL(toggled(bool)), this, SLOT(ProxyToggled(bool)));
genericProxyGroup->addButton(btn);
topPanelLayout->addWidget(btn, i / 3, i % 3 + 1);
}
diff --git a/client/Dialog.h b/client/Dialog.h
index 8fd5aff..a6b5ecd 100644
--- a/client/Dialog.h
+++ b/client/Dialog.h
@@ -26,11 +26,12 @@ public:
ProxyDialog(QWidget *parent = 0);
private slots:
+ void ProxyToggled(bool on);
+ void StaticProxyToggled(bool on);
void CountryActivated(int index);
void StateActivated(int index);
void CityActivated(int index);
- void StaticToggled(bool toggle);
private:
QButtonGroup *genericProxyGroup;
QButtonGroup *staticProxyGroup;
diff --git a/client/Proxy.cpp b/client/Proxy.cpp
index 46a580e..0854cbb 100644
--- a/client/Proxy.cpp
+++ b/client/Proxy.cpp
@@ -1,4 +1,5 @@
+#include <algorithm>
#include <stdlib.h>
#include "client.h"
#include "Proxy.h"
@@ -8,19 +9,23 @@
**************************************/
//
-// Parse proxy string and set calss members according to it's contents
+// Parse proxy string and set class members according to it's contents
// Some examples:
-// user:password@server.com:1234
-// server.com:1234
+// type://user:password@server.com:1234
+// type://server.com:1234
void Proxy::Parse(std::string entry)
{
Logger::Trace("Parsing proxy string: %s\n", entry.c_str());
-
+ type.clear();
login.clear();
password.clear();
host.clear();
size_t lp1 = 0, lp2 = 0;
+ lp2 = entry.find("://");
+ type = entry.substr(lp1, lp2-lp1);
+ transform(type.begin(), type.end(), type.begin(), toupper);
+ lp1 = lp2 + 3;
if(entry.find('@') != std::string::npos)
{
lp2 = entry.find(':', lp1);
@@ -29,18 +34,11 @@ void Proxy::Parse(std::string entry)
lp2 = entry.find('@', lp1);
password = entry.substr(lp1, lp2-lp1);
lp1 = lp2+1;
- lp2 = entry.find(':', lp1);
- host = entry.substr(lp1, lp2-lp1);
- lp1 = lp2+1;
- port = atoi(entry.substr(lp1).c_str());
- }
- else
- {
- lp2 = entry.find(':', lp1);
- host = entry.substr(lp1, lp2-lp1);
- lp1 = lp2+1;
- port = atoi(entry.substr(lp1).c_str());
}
+ lp2 = entry.find(':', lp1);
+ host = entry.substr(lp1, lp2-lp1);
+ lp1 = lp2+1;
+ port = atoi(entry.substr(lp1).c_str());
}
diff --git a/client/SslClient.cpp b/client/SslClient.cpp
index b8aa582..e13a028 100644
--- a/client/SslClient.cpp
+++ b/client/SslClient.cpp
@@ -205,10 +205,9 @@ void SslClient::DataRecieved()
return;
}
-/*
fprintf(stderr, "[ ");
- const char * tmp = data.constData();
- for (int i = 0; i < data.size(); i++)
+ const char * tmp = pkt.constData();
+ for (int i = 0; i < pkt.size(); i++)
{
if (tmp[i] < 0x20)
{
@@ -220,7 +219,6 @@ void SslClient::DataRecieved()
}
}
fprintf(stderr, "]\n");
-*/
/* remove header and tail */
pkt.remove(pkt.size()-3, 3);