Re: [Tails-dev] minitube (Youtube client)

Delete this message

Reply to this message
Author: Alessandro Grassi
Date:  
To: tails-dev
Subject: Re: [Tails-dev] minitube (Youtube client)
Hi,

2012/12/6, Alessandro Grassi <alessandro.g89@???>:
> I want to try adding it myself. It should be a matter of parsing
> SOCKS5_SERVER environment variable and passing address, port etc. to
> the appropriate class. HTTP proxy is implemented this way, related
> code is in src/global.h

That was easy. Here's the patch, please test!

Greetings

Alessandro
--- minitube/src/global.h    2012-09-27 10:17:03.000000000 +0000
+++ global.h    2012-12-07 12:45:16.000000000 +0000
@@ -123,12 +123,77 @@
         }
     }


+    void networkSocks5ProxySetting() {
+        char *socks5_server_env;
+        socks5_server_env = std::getenv("socks5_server");
+        if (!socks5_server_env) {
+            socks5_server_env = std::getenv("SOCKS5_SERVER");
+        }
+
+        if (socks5_server_env) {
+            QString proxy_host = "";
+            QString proxy_port = "";
+            QString proxy_user = "";
+            QString proxy_pass = "";
+            QString socks5_server = QString(socks5_server_env);
+            socks5_server.remove(QRegExp("/$"));
+
+            // parse username and password
+            if (socks5_server.contains(QChar('@'))) {
+                QStringList socks5_server_list = socks5_server.split(QChar('@'));
+                QStringList socks5_server_user_pass = socks5_server_list[0].split(QChar(':'));
+                if (socks5_server_user_pass.size() > 0) {
+                    proxy_user = QUrl::fromPercentEncoding(socks5_server_user_pass[0].toUtf8());
+                }
+                if (socks5_server_user_pass.size() == 2) {
+                    proxy_pass = QUrl::fromPercentEncoding(socks5_server_user_pass[1].toUtf8());
+                }
+                if (socks5_server_list.size() > 1) {
+                    socks5_server = socks5_server_list[1];
+                }
+            }
+
+            // parse hostname and port
+            QStringList socks5_server_list = socks5_server.split(QChar(':'));
+            if (socks5_server_list.size() > 0) {
+                proxy_host = socks5_server_list[0];
+            }
+            if (socks5_server_list.size() > 1) {
+                proxy_port = socks5_server_list[1];
+            }
+
+            // set proxy setting
+            if (!proxy_host.isEmpty()) {
+                QNetworkProxy proxy;
+                proxy.setType(QNetworkProxy::Socks5Proxy);
+                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);
+                }
+
+                qDebug() << "Using SOCKS5 proxy:" << socks5_server_env;
+                QNetworkProxy::setApplicationProxy(proxy);
+            }
+        }
+    }
+
     static QNetworkAccessManager *nam = 0;


     QNetworkAccessManager* networkAccessManager() {
         if (!nam) {
-            networkHttpProxySetting();
-            maybeSetSystemProxy();
+            if( std::getenv("socks5_server") || std::getenv("SOCKS5_SERVER") ) {
+                networkSocks5ProxySetting();
+            } else if ( std::getenv("http_proxy") || std::getenv("HTTP_PROXY") ) {
+                networkHttpProxySetting();
+            } else {
+                maybeSetSystemProxy();
+            }
             nam = new QNetworkAccessManager();
         }
         return nam;