Merge lp:~mardy/signon-ui/proxy into lp:signon-ui

Proposed by Alberto Mardegan on 2012-09-17
Status: Merged
Approved by: David King on 2012-09-17
Approved revision: 62
Merged at revision: 61
Proposed branch: lp:~mardy/signon-ui/proxy
Merge into: lp:signon-ui
Diff against target: 252 lines (+207/-0)
4 files modified
src/main.cpp (+7/-0)
src/my-network-proxy-factory.cpp (+165/-0)
src/my-network-proxy-factory.h (+33/-0)
src/src.pro (+2/-0)
To merge this branch: bzr merge lp:~mardy/signon-ui/proxy
Reviewer Review Type Date Requested Status
David King (community) 2012-09-17 Approve on 2012-09-17
jenkins (community) continuous-integration Needs Fixing on 2012-09-17
Review via email: mp+124618@code.launchpad.net

Description of the change

Use libproxy to detect proxy settings

This is needed as a workaround for
https://bugreports.qt-project.org/browse/QTBUG-26295

To post a comment you must log in.
David King (amigadave) wrote :

242 + -lproxy

Use the pkg-config file (libproxy-1.0) please.

review: Needs Fixing
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
lp:~mardy/signon-ui/proxy updated on 2012-09-17
62. By Alberto Mardegan on 2012-09-17

Use pkg-config

jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
Alberto Mardegan (mardy) wrote :

Updated to use pkg-config.
The Jenkins failure is due to the new dependency on libproxy; I'll update the packaging branch once this MR is approved.

David King (amigadave) wrote :

Looks good. The CI failure is only because of a missing libproxy-dev build dependency in the packaging.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main.cpp'
2--- src/main.cpp 2012-07-26 10:38:55 +0000
3+++ src/main.cpp 2012-09-17 09:03:20 +0000
4@@ -21,6 +21,7 @@
5 #include "debug.h"
6 #include "i18n.h"
7 #include "indicator-service.h"
8+#include "my-network-proxy-factory.h"
9 #include "service.h"
10
11 #include <QApplication>
12@@ -58,6 +59,12 @@
13
14 initTr(I18N_DOMAIN, NULL);
15
16+ /* Use a libproxy-based proxy factory; this code will no longer be
17+ * needed when https://bugreports.qt-project.org/browse/QTBUG-26295
18+ * is fixed. */
19+ MyNetworkProxyFactory proxyFactory;
20+ QNetworkProxyFactory::setApplicationProxyFactory(&proxyFactory);
21+
22 Service *service = new Service();
23 if (daemonTimeout > 0)
24 service->setTimeout(daemonTimeout);
25
26=== added file 'src/my-network-proxy-factory.cpp'
27--- src/my-network-proxy-factory.cpp 1970-01-01 00:00:00 +0000
28+++ src/my-network-proxy-factory.cpp 2012-09-17 09:03:20 +0000
29@@ -0,0 +1,165 @@
30+/*
31+ * Copied from
32+ * https://codereview.qt-project.org/cat/29453%2C6%2Csrc/network/kernel/qnetworkproxy_libproxy.cpp%5E0
33+ *
34+ * With minor modifications by
35+ * Alberto Mardegan <alberto.mardegan@canonical.com>
36+ */
37+
38+/****************************************************************************
39+**
40+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
41+** Contact: http://www.qt-project.org/
42+**
43+** This file is part of the QtNetwork module of the Qt Toolkit.
44+**
45+** $QT_BEGIN_LICENSE:LGPL$
46+** GNU Lesser General Public License Usage
47+** This file may be used under the terms of the GNU Lesser General Public
48+** License version 2.1 as published by the Free Software Foundation and
49+** appearing in the file LICENSE.LGPL included in the packaging of this
50+** file. Please review the following information to ensure the GNU Lesser
51+** General Public License version 2.1 requirements will be met:
52+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
53+**
54+** In addition, as a special exception, Nokia gives you certain additional
55+** rights. These rights are described in the Nokia Qt LGPL Exception
56+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
57+**
58+** GNU General Public License Usage
59+** Alternatively, this file may be used under the terms of the GNU General
60+** Public License version 3.0 as published by the Free Software Foundation
61+** and appearing in the file LICENSE.GPL included in the packaging of this
62+** file. Please review the following information to ensure the GNU General
63+** Public License version 3.0 requirements will be met:
64+** http://www.gnu.org/copyleft/gpl.html.
65+**
66+** Other Usage
67+** Alternatively, this file may be used in accordance with the terms and
68+** conditions contained in a signed written agreement between you and Nokia.
69+**
70+**
71+**
72+**
73+**
74+**
75+** $QT_END_LICENSE$
76+**
77+****************************************************************************/
78+
79+#include "my-network-proxy-factory.h"
80+
81+#include <QNetworkProxy>
82+
83+#include <QtCore/QByteArray>
84+#include <QtCore/QUrl>
85+
86+#include <proxy.h>
87+
88+class QLibProxyWrapper
89+{
90+public:
91+ QLibProxyWrapper()
92+ : factory(px_proxy_factory_new())
93+ {
94+ }
95+
96+ ~QLibProxyWrapper()
97+ {
98+ px_proxy_factory_free(factory);
99+ }
100+
101+ QList<QUrl> getProxies(const QUrl &url);
102+
103+private:
104+ pxProxyFactory *factory;
105+};
106+
107+Q_GLOBAL_STATIC(QLibProxyWrapper, libProxyWrapper);
108+
109+/*
110+ Gets the list of proxies from libproxy, converted to QUrl list.
111+ Thread safe, according to libproxy documentation.
112+*/
113+QList<QUrl> QLibProxyWrapper::getProxies(const QUrl &url)
114+{
115+ QList<QUrl> ret;
116+
117+ if (factory) {
118+ char **proxies = px_proxy_factory_get_proxies(factory, url.toEncoded());
119+ if (proxies) {
120+ for (int i = 0; proxies[i]; i++) {
121+ ret.append(QUrl::fromEncoded(proxies[i]));
122+ free(proxies[i]);
123+ }
124+ free(proxies);
125+ }
126+ }
127+
128+ return ret;
129+}
130+
131+QList<QNetworkProxy> MyNetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query)
132+{
133+ QList<QNetworkProxy> proxyList;
134+
135+ QUrl queryUrl;
136+ QNetworkProxy::Capabilities requiredCapabilities(0);
137+ switch (query.queryType()) {
138+ //URL requests are directly supported by libproxy
139+ case QNetworkProxyQuery::UrlRequest:
140+ queryUrl = query.url();
141+ break;
142+ // fake URLs to get libproxy to tell us the SOCKS proxy
143+ case QNetworkProxyQuery::TcpSocket:
144+ queryUrl.setScheme(QLatin1String("tcp"));
145+ queryUrl.setHost(query.peerHostName());
146+ queryUrl.setPort(query.peerPort());
147+ requiredCapabilities |= QNetworkProxy::TunnelingCapability;
148+ break;
149+ case QNetworkProxyQuery::UdpSocket:
150+ queryUrl.setScheme(QLatin1String("udp"));
151+ queryUrl.setHost(query.peerHostName());
152+ queryUrl.setPort(query.peerPort());
153+ requiredCapabilities |= QNetworkProxy::UdpTunnelingCapability;
154+ break;
155+ default:
156+ proxyList.append(QNetworkProxy(QNetworkProxy::NoProxy));
157+ return proxyList;
158+ }
159+
160+ QList<QUrl> rawProxies = libProxyWrapper()->getProxies(query.url());
161+
162+ bool haveDirectConnection = false;
163+ foreach (const QUrl& url, rawProxies) {
164+ QNetworkProxy::ProxyType type;
165+ if (url.scheme() == QLatin1String("http")) {
166+ type = QNetworkProxy::HttpProxy;
167+ } else if (url.scheme() == QLatin1String("socks")
168+ || url.scheme() == QLatin1String("socks5")) {
169+ type = QNetworkProxy::Socks5Proxy;
170+ } else if (url.scheme() == QLatin1String("ftp")) {
171+ type = QNetworkProxy::FtpCachingProxy;
172+ } else if (url.scheme() == QLatin1String("direct")) {
173+ type = QNetworkProxy::NoProxy;
174+ haveDirectConnection = true;
175+ } else {
176+ continue; //unsupported proxy type e.g. socks4
177+ }
178+
179+ QNetworkProxy proxy(type,
180+ url.host(),
181+ url.port(),
182+ url.userName(),
183+ url.password());
184+
185+ if ((proxy.capabilities() & requiredCapabilities) == requiredCapabilities)
186+ proxyList.append(proxy);
187+ }
188+
189+ // fallback is direct connection
190+ if (proxyList.isEmpty() || !haveDirectConnection)
191+ proxyList.append(QNetworkProxy(QNetworkProxy::NoProxy));
192+
193+ return proxyList;
194+}
195
196=== added file 'src/my-network-proxy-factory.h'
197--- src/my-network-proxy-factory.h 1970-01-01 00:00:00 +0000
198+++ src/my-network-proxy-factory.h 2012-09-17 09:03:20 +0000
199@@ -0,0 +1,33 @@
200+/*
201+ * This file is part of signon-ui
202+ *
203+ * Copyright (C) 2012 Canonical Ltd.
204+ *
205+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
206+ *
207+ * This program is free software: you can redistribute it and/or modify it
208+ * under the terms of the GNU General Public License version 3, as published
209+ * by the Free Software Foundation.
210+ *
211+ * This program is distributed in the hope that it will be useful, but
212+ * WITHOUT ANY WARRANTY; without even the implied warranties of
213+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
214+ * PURPOSE. See the GNU General Public License for more details.
215+ *
216+ * You should have received a copy of the GNU General Public License along
217+ * with this program. If not, see <http://www.gnu.org/licenses/>.
218+ */
219+
220+#ifndef SIGNON_UI_MY_NETWORK_PROXY_FACTORY_H
221+#define SIGNON_UI_MY_NETWORK_PROXY_FACTORY_H
222+
223+#include <QNetworkProxyFactory>
224+
225+class MyNetworkProxyFactory: public QNetworkProxyFactory
226+{
227+public:
228+ // reimplemented virtual methods
229+ QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery());
230+};
231+
232+#endif // SIGNON_UI_MY_NETWORK_PROXY_FACTORY_H
233
234=== modified file 'src/src.pro'
235--- src/src.pro 2012-09-14 07:14:43 +0000
236+++ src/src.pro 2012-09-17 09:03:20 +0000
237@@ -21,6 +21,7 @@
238 PKGCONFIG += \
239 accounts-qt \
240 signon-plugins-common \
241+ libproxy-1.0 \
242 libsignon-qt
243
244 HEADERS = \
245@@ -48,6 +49,7 @@
246 i18n.cpp \
247 indicator-service.cpp \
248 main.cpp \
249+ my-network-proxy-factory.cpp \
250 network-access-manager.cpp \
251 request.cpp \
252 service.cpp \

Subscribers

People subscribed via source and target branches

to all changes: