diff options
author | Alex Borisov <b0ric.alex@gmail.com> | 2012-02-06 00:22:51 +0200 |
---|---|---|
committer | Alex Borisov <b0ric.alex@gmail.com> | 2012-02-06 00:22:51 +0200 |
commit | f62b8299abb67e69482f0c52359542834967fd73 (patch) | |
tree | 0f0e27bbb6d0e04a6169f0d35392b234856d8709 | |
parent | b18bd36aed6671eed7c1b985181506c4860b9331 (diff) |
FIX: http proxy to be the one and the last in the chain
-rw-r--r-- | client/Dialog.cpp | 43 | ||||
-rw-r--r-- | client/Proxifier.cpp | 17 |
2 files changed, 57 insertions, 3 deletions
diff --git a/client/Dialog.cpp b/client/Dialog.cpp index e996add..de421dd 100644 --- a/client/Dialog.cpp +++ b/client/Dialog.cpp @@ -168,6 +168,26 @@ void ProxyDialog::ProxyToggled(bool on) if (on) { vector<Proxy> active = proxifier->GetActiveProxies(); + + // check if we are going to add another http/https proxy + if (active.size() != 0) + { + bool isHttp = (stricmp(proxy->type.c_str(), "http") == 0); + for (unsigned i = 0; i < active.size(); i++) + { + if (isHttp && (stricmp(active[i].type.c_str(), "http") == 0)) + { + QMessageBox otherHttpProxy; + otherHttpProxy.setText("Two HTTP proxy in one chain are not allowed"); + otherHttpProxy.setWindowTitle("Information"); + otherHttpProxy.setStandardButtons(QMessageBox::Ok); + otherHttpProxy.setIcon(QMessageBox::Information); + otherHttpProxy.exec(); + return; + } + } + } + for (unsigned i = 0; i < active.size(); i++) { ProxyEntryGeneric* genProxy = cfg->GetGenericProxy(active[i].host, active[i].port); @@ -197,11 +217,34 @@ void ProxyDialog::StaticProxyToggled(bool on) Logger::Error("Static proxy with name '%s' was not found\n", proxyName.toStdString().c_str()); return; } + Proxifier *proxifier = Proxifier::GetInstance(); if (!proxifier->IsValid()) { Logger::Fatal("No valid proxifier configuration file found!\n"); } + + // check if we are going to add another http proxy + vector<Proxy> active = proxifier->GetActiveProxies(); + if (on && (active.size() != 0)) + { + bool isHttp = (stricmp(proxy->type.c_str(), "http") == 0); + for (unsigned i = 0; i < active.size(); i++) + { + if (isHttp && (stricmp(active[i].type.c_str(), "http") == 0)) + { + //QString msg = QString::fromLocal8Bit(cfg->ConfigLoadedMsg.c_str()); + QMessageBox otherHttpProxy; + otherHttpProxy.setText("Two HTTP proxy in one chain are not allowed"); + otherHttpProxy.setWindowTitle("Information"); + otherHttpProxy.setStandardButtons(QMessageBox::Ok); + otherHttpProxy.setIcon(QMessageBox::Information); + otherHttpProxy.exec(); + return; + } + } + } + if (on) { proxifier->TurnProxyOn(*proxy); diff --git a/client/Proxifier.cpp b/client/Proxifier.cpp index 4485647..0d3005d 100644 --- a/client/Proxifier.cpp +++ b/client/Proxifier.cpp @@ -320,13 +320,15 @@ bool Proxifier::TurnProxyOn(Proxy& proxy) { // proxy is not enabled - remove it and add again RemoveProxyFromChain(proxyId, chainId); - AddProxyToChain(proxyId, chainId); + bool isHttp = (stricmp(proxy.type.c_str(), "http") == 0); + AddProxyToChain(proxyId, chainId, isHttp); } } else { // proxy not found in the target chain - add it - AddProxyToChain(proxyId, chainId); + bool isHttp = (stricmp(proxy.type.c_str(), "http") == 0); + AddProxyToChain(proxyId, chainId, isHttp); } } @@ -1013,7 +1015,16 @@ bool Proxifier::AddProxyToChain(int proxyId, int chainId, bool isHttp) idTxt.setNum(proxyId); QDomText nameTxt = configDom.createTextNode(idTxt); proxyElem.appendChild(nameTxt); - chainElem.appendChild(proxyElem); + // append Http proxies to then end, but prepend other ones + if (isHttp) + { + chainElem.appendChild(proxyElem); + } + else + { + // first child is 'Name' + chainElem.insertAfter(proxyElem, chainElem.firstChildElement()); + } break; } } |