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

Proposed by Alberto Mardegan
Status: Merged
Approved by: David King
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) Approve
jenkins (community) continuous-integration Needs Fixing
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.
Revision history for this message
David King (amigadave) wrote :

242 + -lproxy

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

review: Needs Fixing
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
lp:~mardy/signon-ui/proxy updated
62. By Alberto Mardegan

Use pkg-config

Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
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.

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

Subscribers

People subscribed via source and target branches

to all changes: