~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/net.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <time.h>
30
30
 
31
31
#include "common.h"
32
 
#include "conf.h"
33
32
#include "debug.h"
34
 
#include "ui/liferea_htmlview.h"
35
 
#include "ui/liferea_shell.h"
36
33
 
37
34
#define HOMEPAGE        "http://liferea.sf.net/"
38
35
 
39
 
static SoupSession *session;
40
 
static SoupSession *session_no_proxy;
41
 
static SoupSession *session_no_cookies;
42
 
static SoupSession *session_no_cookies_no_proxy;
 
36
static SoupSession *session = NULL;
43
37
 
44
38
static gchar    *proxyname = NULL;
45
39
static gchar    *proxyusername = NULL;
46
40
static gchar    *proxypassword = NULL;
47
41
static int      proxyport = 0;
48
42
 
49
 
static gboolean online = FALSE;
50
 
 
51
43
static void
52
44
network_process_callback (SoupSession *session, SoupMessage *msg, gpointer user_data)
53
45
{
65
57
        }
66
58
 
67
59
        debug1 (DEBUG_NET, "download status code: %d", msg->status_code);
68
 
        debug1 (DEBUG_NET, "source after download: >>>%s<<<\n", job->result->source);
 
60
        debug1 (DEBUG_NET, "source after download: >>>%s<<<", job->result->source);
69
61
 
70
62
        job->result->data = g_memdup (msg->response_body->data, msg->response_body->length+1);
71
63
        job->result->size = (size_t)msg->response_body->length;
118
110
{
119
111
        SoupMessage     *msg;
120
112
        SoupDate        *date;
121
 
        gboolean        no_proxy = FALSE;
122
 
        gboolean        no_cookies = FALSE;
123
 
        
 
113
 
124
114
        g_assert (NULL != job->request);
125
115
        debug1 (DEBUG_NET, "downloading %s", job->request->source);
126
116
 
161
151
            job->request->options->username &&
162
152
            job->request->options->password) {
163
153
                SoupURI *uri = soup_message_get_uri (msg);
164
 
 
 
154
                
165
155
                soup_uri_set_user (uri, job->request->options->username);
166
156
                soup_uri_set_password (uri, job->request->options->password);
167
157
        }
175
165
        if (job->request->updateState && job->request->updateState->cookies) {
176
166
                soup_message_headers_append (msg->request_headers, "Cookie",
177
167
                                             job->request->updateState->cookies);
178
 
                                                
179
 
                /* This might be confusing: But what we mean by setting this flag
180
 
                   is that we do want to ignore the cookie file in ~/.liferea_1.x
181
 
                   and pass a single cookie in the headers instead. */                  
182
 
                no_cookies = TRUE;
 
168
                soup_message_disable_feature (msg, SOUP_TYPE_COOKIE_JAR);
183
169
        }
184
170
 
185
171
        /* TODO: Right now we send the msg, and if it requires authentication and
190
176
         * msg to a callback in case of 401 (see soup_message_add_status_code_handler())
191
177
         * displaying the dialog ourselves, and requeing the msg if we get credentials */
192
178
 
193
 
        /* We queue the message in one session or the other depending on the global
194
 
         * proxy settings and whether the feed properties has the "dont use a proxy" 
195
 
         * checkbox enabled */
 
179
        /* If the feed has "dont use a proxy" selected, disable the proxy for the msg */
196
180
        if ((job->request->options && job->request->options->dontUseProxy) ||
197
 
            (NULL == network_get_proxy_host ()))
198
 
                no_proxy = TRUE;
 
181
            (network_get_proxy_host () == NULL))
 
182
                soup_message_disable_feature (msg, SOUP_TYPE_PROXY_URI_RESOLVER);
199
183
 
200
 
        if (no_proxy && no_cookies) {
201
 
                soup_session_queue_message (session_no_cookies_no_proxy, msg, network_process_callback, job);
202
 
        } else if (no_proxy) {
203
 
                soup_session_queue_message (session_no_proxy, msg, network_process_callback, job);
204
 
        } else if (no_cookies) {
205
 
                soup_session_queue_message (session_no_cookies, msg, network_process_callback, job);
206
 
        } else {
207
 
                soup_session_queue_message (session, msg, network_process_callback, job);
208
 
        }
 
184
        soup_session_queue_message (session, msg, network_process_callback, job);
209
185
}
210
186
 
211
187
static void
223
199
        // FIXME: Handle HTTP 401 too
224
200
}
225
201
 
226
 
 
227
202
void
228
203
network_init (void)
229
204
{
250
225
        /* Initialize libsoup */
251
226
        proxy = network_get_proxy_uri ();
252
227
        session = soup_session_async_new_with_options (SOUP_SESSION_USER_AGENT, useragent,
253
 
                                                       SOUP_SESSION_TIMEOUT, 120,
 
228
                                                       SOUP_SESSION_TIMEOUT, 120,
254
229
                                                       SOUP_SESSION_IDLE_TIMEOUT, 30,
255
230
                                                       SOUP_SESSION_PROXY_URI, proxy,
256
231
                                                       SOUP_SESSION_ADD_FEATURE, cookies,
 
232
                                                       SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
257
233
                                                       NULL);
258
234
        if (proxy)
259
235
                soup_uri_free (proxy);
260
236
                
261
237
        g_signal_connect (session, "authenticate", G_CALLBACK (network_authenticate), NULL);
262
238
 
263
 
        /* This session is for those cases where we are told not to use the proxy */
264
 
        session_no_proxy = soup_session_async_new_with_options (SOUP_SESSION_USER_AGENT, useragent,
265
 
                                                                SOUP_SESSION_TIMEOUT, 120,
266
 
                                                                SOUP_SESSION_IDLE_TIMEOUT, 30,
267
 
                                                                SOUP_SESSION_ADD_FEATURE, cookies,
268
 
                                                                NULL);
269
 
 
270
 
        /* This session is for those cases where we need to add specific cookies, e.g. Google Reader.
271
 
         * Once GNOME #574571 is fixed, we will be able to use the normal session */
272
 
        session_no_cookies = soup_session_async_new_with_options (SOUP_SESSION_USER_AGENT, useragent,
273
 
                                                                  SOUP_SESSION_TIMEOUT, 120,
274
 
                                                                  SOUP_SESSION_IDLE_TIMEOUT, 30,
275
 
                                                                  SOUP_SESSION_PROXY_URI, proxy,
276
 
                                                                  NULL);
277
 
 
278
 
        /* And this one is for cases where we need to use our own cookies, and bypass the proxy, e.g.
279
 
         * Google Reader subscription where the "ignore proxy" preference is set */
280
 
        session_no_cookies_no_proxy = soup_session_async_new_with_options (SOUP_SESSION_USER_AGENT, useragent,
281
 
                                                                           SOUP_SESSION_TIMEOUT, 120,
282
 
                                                                           SOUP_SESSION_IDLE_TIMEOUT, 30,
283
 
                                                                           NULL);
284
 
 
285
239
        /* Soup debugging */
286
240
        if (debug_level & DEBUG_NET) {
287
241
                logger = soup_logger_new (SOUP_LOGGER_LOG_HEADERS, -1);
323
277
        return proxypassword;
324
278
}
325
279
 
 
280
extern void network_monitor_proxy_changed (void);
 
281
 
326
282
void
327
283
network_set_proxy (gchar *host, guint port, gchar *user, gchar *password)
328
284
{
340
296
        if (session) {
341
297
                SoupURI *newproxy = network_get_proxy_uri ();
342
298
                
343
 
                g_object_set (session,
344
 
                              SOUP_SESSION_PROXY_URI, newproxy,
345
 
                              NULL);
346
 
                g_object_set (session_no_cookies,
 
299
                g_object_set (G_OBJECT (session),
347
300
                              SOUP_SESSION_PROXY_URI, newproxy,
348
301
                              NULL);
349
302
 
352
305
        }
353
306
 
354
307
        debug4 (DEBUG_NET, "proxy set to http://%s:%s@%s:%d", user, password, host, port);
355
 
 
356
 
        liferea_htmlview_update_proxy ();
 
308
        
 
309
        network_monitor_proxy_changed ();
357
310
}
358
311
 
359
312
const char *
406
359
        return tmp;
407
360
}
408
361
 
409
 
void
410
 
network_set_online (gboolean mode)
411
 
{
412
 
        if (online != mode) {
413
 
                online = mode;
414
 
                debug1 (DEBUG_NET, "Changing online mode to %s", mode?"online":"offline");
415
 
                liferea_shell_online_status_changed (mode);
416
 
        }
417
 
}
418
 
 
419
 
gboolean
420
 
network_is_online (void)
421
 
{
422
 
        return online;
423
 
}