Merge lp:~rodrigo-moya/ubuntu/maverick/tomboy/1_2_with_proxy_support into lp:~ubuntu-desktop/tomboy/ubuntu

Proposed by Rodrigo Moya on 2010-06-22
Status: Merged
Merged at revision: 45
Proposed branch: lp:~rodrigo-moya/ubuntu/maverick/tomboy/1_2_with_proxy_support
Merge into: lp:~ubuntu-desktop/tomboy/ubuntu
Diff against target: 246 lines (+223/-0)
3 files modified
debian/changelog (+7/-0)
debian/patches/05_libproxy_support.patch (+215/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~rodrigo-moya/ubuntu/maverick/tomboy/1_2_with_proxy_support
Reviewer Review Type Date Requested Status
Ubuntu branches 2010-06-22 Pending
Review via email: mp+28162@code.launchpad.net

Description of the Change

Added patch to add proxy support

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2010-05-21 18:29:07 +0000
3+++ debian/changelog 2010-06-22 11:32:29 +0000
4@@ -1,3 +1,10 @@
5+tomboy (1.2.1-1ubuntu4) maverick; urgency=low
6+
7+ * debian/patches/05_libproxy_support.patch
8+ - Add path to support proxies for notes syncing
9+
10+ -- Rodrigo Moya <rodrigo.moya@canonical.com> Fri, 18 Jun 2010 17:32:18 +0200
11+
12 tomboy (1.2.1-1ubuntu3) maverick; urgency=low
13
14 * debian/control
15
16=== added file 'debian/patches/05_libproxy_support.patch'
17--- debian/patches/05_libproxy_support.patch 1970-01-01 00:00:00 +0000
18+++ debian/patches/05_libproxy_support.patch 2010-06-22 11:32:29 +0000
19@@ -0,0 +1,215 @@
20+diff --git a/Tomboy/Addins/WebSyncService/Api/AnonymousConnection.cs b/Tomboy/Addins/WebSyncService/Api/AnonymousConnection.cs
21+index 11a349d..7c377e2 100644
22+--- a/Tomboy/Addins/WebSyncService/Api/AnonymousConnection.cs
23++++ b/Tomboy/Addins/WebSyncService/Api/AnonymousConnection.cs
24+@@ -70,7 +70,7 @@ namespace Tomboy.WebSync.Api
25+ ServicePointManager.CertificatePolicy = new CertificateManager ();
26+
27+ try {
28+- webRequest = System.Net.WebRequest.Create (uri) as HttpWebRequest;
29++ webRequest = ProxiedWebRequest.Create (uri);
30+
31+ webRequest.Method = method;
32+ webRequest.ServicePoint.Expect100Continue = false;
33+diff --git a/Tomboy/Addins/WebSyncService/Api/OAuth.cs b/Tomboy/Addins/WebSyncService/Api/OAuth.cs
34+index 5a039f4..e2fed66 100644
35+--- a/Tomboy/Addins/WebSyncService/Api/OAuth.cs
36++++ b/Tomboy/Addins/WebSyncService/Api/OAuth.cs
37+@@ -234,7 +234,7 @@ namespace Tomboy.WebSync.Api
38+ ServicePointManager.CertificatePolicy = new CertificateManager ();
39+
40+ // TODO: Set UserAgent, Timeout, KeepAlive, Proxy?
41+- HttpWebRequest webRequest = System.Net.WebRequest.Create (url) as HttpWebRequest;
42++ HttpWebRequest webRequest = ProxiedWebRequest.Create (url);
43+ webRequest.Method = method.ToString ();
44+ webRequest.ServicePoint.Expect100Continue = false;
45+
46+diff --git a/Tomboy/Addins/WebSyncService/Api/ProxiedWebRequest.cs b/Tomboy/Addins/WebSyncService/Api/ProxiedWebRequest.cs
47+new file mode 100644
48+index 0000000..e39d26d
49+--- /dev/null
50++++ b/Tomboy/Addins/WebSyncService/Api/ProxiedWebRequest.cs
51+@@ -0,0 +1,82 @@
52++
53++using System;
54++using System.Net;
55++using LibProxy;
56++
57++namespace Tomboy.WebSync
58++{
59++ public static class ProxiedWebRequest
60++ {
61++ private const string useProxyAuthentication =
62++ "/system/http_proxy/use_authentication";
63++ private const string proxyAuthenticationUser =
64++ "/system/http_proxy/authentication_user";
65++ private const string proxyAuthenticationPassword =
66++ "/system/http_proxy/authentication_password";
67++
68++ public static bool useLibProxy = true;
69++ public static HttpWebRequest Create (string uri)
70++ {
71++ HttpWebRequest webRequest = WebRequest.Create (uri) as HttpWebRequest;
72++ if (useLibProxy) {
73++ try {
74++ ApplyProxy(webRequest, uri);
75++ } catch (System.DllNotFoundException e) {
76++ Console.WriteLine("WARNING: libproxy not installed");
77++ useLibProxy = false;
78++ }
79++ }
80++
81++ return webRequest;
82++ }
83++
84++ private static void ApplyProxy(HttpWebRequest webRequest, string uri)
85++ {
86++ ProxyFactory pf = new LibProxy.ProxyFactory();
87++ string[] proxies = pf.GetProxies(uri);
88++
89++ foreach (string proxy in proxies) {
90++ Uri proxyUri=new Uri(proxy);
91++ string scheme = proxyUri.Scheme;
92++ if (scheme == "direct") {
93++ break;
94++ } else if (scheme == "http" || scheme == "https") {
95++ WebProxy webProxy = new WebProxy();
96++
97++ if (UseAuthentication()) {
98++ ICredentials credentials =
99++ new NetworkCredential(GetAuthUser(), GetAuthPass());
100++ webProxy.Credentials = credentials;
101++ }
102++
103++ webProxy.Address = proxyUri;
104++ webRequest.Proxy = webProxy;
105++ break;
106++ }
107++ }
108++ }
109++
110++ // this settings are taken from GConf/xml until libproxy supports
111++ // returning the user/password to use for the proxy
112++ // TODO: fix when libproxy release 0.5 is out
113++ public static bool UseAuthentication ()
114++ {
115++ object useProxyAuth = Preferences.Get (useProxyAuthentication);
116++
117++ if (useProxyAuth == null) {
118++ return false;
119++ }
120++ return (bool) useProxyAuth;
121++ }
122++
123++ public static string GetAuthUser ()
124++ {
125++ return Preferences.Get (proxyAuthenticationUser) as string;
126++ }
127++
128++ public static string GetAuthPass ()
129++ {
130++ return Preferences.Get (proxyAuthenticationPassword) as string;
131++ }
132++ }
133++}
134+diff --git a/Tomboy/Addins/WebSyncService/LibProxy/LibProxy.cs b/Tomboy/Addins/WebSyncService/LibProxy/LibProxy.cs
135+new file mode 100644
136+index 0000000..1a46ef7
137+--- /dev/null
138++++ b/Tomboy/Addins/WebSyncService/LibProxy/LibProxy.cs
139+@@ -0,0 +1,83 @@
140++/***************************************************
141++ * This code comes from the libproxy C library
142++ **************************************************/
143++
144++/*******************************************************************************
145++ * libproxy - A library for proxy configuration
146++ * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
147++ *
148++ * This library is free software; you can redistribute it and/or
149++ * modify it under the terms of the GNU Lesser General Public
150++ * License as published by the Free Software Foundation; either
151++ * version 2.1 of the License, or (at your option) any later version.
152++ *
153++ * This library is distributed in the hope that it will be useful,
154++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
155++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
156++ * Lesser General Public License for more details.
157++ *
158++ * You should have received a copy of the GNU Lesser General Public
159++ * License along with this library; if not, write to the Free Software
160++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
161++ ******************************************************************************/
162++
163++namespace LibProxy {
164++ using System;
165++ using System.Runtime.InteropServices;
166++
167++ public class ProxyFactory {
168++ private HandleRef self;
169++
170++ [DllImport ("proxy")]
171++ private static extern
172++ IntPtr px_proxy_factory_new();
173++
174++ [DllImport ("proxy")]
175++ private static extern
176++ IntPtr px_proxy_factory_get_proxies(HandleRef self, string url);
177++
178++ [DllImport ("proxy")]
179++ private static extern
180++ void px_proxy_factory_free(HandleRef self);
181++
182++ public ProxyFactory()
183++ {
184++ this.self = new HandleRef(this, px_proxy_factory_new());
185++ }
186++
187++ public string[] GetProxies(string url)
188++ {
189++ int count = 0;
190++
191++ // Get the results
192++ // TODO: If we call both this function and px_proxy_factory_free()
193++ // this crashes, figure out why...
194++ IntPtr array = px_proxy_factory_get_proxies(this.self, url);
195++
196++ // Count the number of returned strings
197++ while (Marshal.ReadIntPtr(array, count * IntPtr.Size) != IntPtr.Zero) count++;
198++
199++ // Allocate a correctly sized array
200++ string[] proxies = new string[count];
201++
202++ // Fill the response array
203++ for (int i=0 ; i < count ; i++)
204++ {
205++ IntPtr p = Marshal.ReadIntPtr(array, i * IntPtr.Size);
206++ proxies[i] = Marshal.PtrToStringAnsi(p);
207++ Marshal.FreeCoTaskMem(p); // Free the string
208++ }
209++
210++ // Free the array itself
211++ Marshal.FreeCoTaskMem(array);
212++
213++ return proxies;
214++ }
215++
216++ ~ProxyFactory()
217++ {
218++ // TODO: See note above...
219++ px_proxy_factory_free(this.self);
220++ }
221++ }
222++}
223+diff --git a/Tomboy/Addins/WebSyncService/Makefile.am b/Tomboy/Addins/WebSyncService/Makefile.am
224+index e722830..75387ad 100644
225+--- a/Tomboy/Addins/WebSyncService/Makefile.am
226++++ b/Tomboy/Addins/WebSyncService/Makefile.am
227+@@ -32,6 +32,7 @@ CSFILES = \
228+ $(srcdir)/Api/Tests/*.cs \
229+ $(srcdir)/Hyena.Json/*.cs \
230+ $(srcdir)/Hyena.Json/Tests/*.cs \
231++ $(srcdir)/LibProxy/*.cs \
232+ $(srcdir)/OAuth/*.cs \
233+ $(srcdir)/OAuth/Mono.Rocks/*.cs
234+ RESOURCES = \
235
236=== modified file 'debian/patches/series'
237--- debian/patches/series 2010-05-21 16:01:47 +0000
238+++ debian/patches/series 2010-06-22 11:32:29 +0000
239@@ -1,6 +1,7 @@
240 01_dllmaps.patch
241 03_u1_as_default_sync.patch
242 04_app_indicator.patch
243+05_libproxy_support.patch
244 10_disable_unit_tests
245 11_lpi.patch
246 20_remove_pcfile_requires

Subscribers

People subscribed via source and target branches

to all changes: