From ccab2845bd4c1dec76c02fbadbdaeb5832f72e33 Mon Sep 17 00:00:00 2001 From: Kiwamu Okabe Date: Mon, 31 Aug 2009 01:15:02 +0900 Subject: [PATCH] support http_proxy. --- src/global.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/global.h b/src/global.h index 291ef8a..e3ebdef 100644 --- a/src/global.h +++ b/src/global.h @@ -2,7 +2,10 @@ #define GLOBAL_H #include +#include +#include #include +#include #include "networkaccess.h" namespace The { @@ -23,10 +26,68 @@ namespace The { return g_menus; } + void networkHttpProxySetting() { + char *http_proxy_env; + http_proxy_env = getenv("http_proxy"); + + if (http_proxy_env) { + QString proxy_host = ""; + QString proxy_port = ""; + QString proxy_user = ""; + QString proxy_pass = ""; + QString http_proxy = QString(http_proxy_env); + http_proxy.remove(QRegExp("^http://")); + + if (http_proxy.contains(QChar('@'))) { + QStringList http_proxy_list = http_proxy.split(QChar('@')); + QStringList http_proxy_user_pass = http_proxy_list[0].split(QChar(':')); + if (http_proxy_user_pass.size() > 0) { + proxy_user = http_proxy_user_pass[0]; + } + if (http_proxy_user_pass.size() == 2) { + proxy_pass = http_proxy_user_pass[1]; + } + if (http_proxy_list.size() > 1) { + http_proxy = http_proxy_list[1]; + } + } + + QStringList http_proxy_list = http_proxy.split(QChar(':')); + if (http_proxy_list.size() > 0) { + proxy_host = http_proxy_list[0]; + } + if (http_proxy_list.size() > 1) { + proxy_port = http_proxy_list[1]; + } + + qDebug() << "proxy_host: " << proxy_host; + qDebug() << "proxy_port: " << proxy_port; + qDebug() << "proxy_user: " << proxy_user; + qDebug() << "proxy_pass: " << proxy_pass; + + if (!proxy_host.isEmpty()) { + QNetworkProxy proxy; + proxy.setType(QNetworkProxy::HttpProxy); + proxy.setHostName(proxy_host); + if (!proxy_port.isEmpty()) { + proxy.setPort(proxy_port.toUShort()); + } + if (!proxy_user.isEmpty()) { + proxy.setUser(proxy_user); + } + if (!proxy_pass.isEmpty()) { + proxy.setPassword(proxy_pass); + } + QNetworkProxy::setApplicationProxy(proxy); + } + } + } + static QNetworkAccessManager *nam = 0; QNetworkAccessManager* networkAccessManager() { if (!nam) { + networkHttpProxySetting(); nam = new QNetworkAccessManager(); // A simple disk based cache -- 2.39.5