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

« back to all changes in this revision

Viewing changes to src/favicon.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:
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2, or (at your option)
9
 
 * any later version.
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
10
10
 *
11
11
 * This program is distributed in the hope that it will be useful,
12
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35
35
#include "favicon.h"
36
36
#include "feed.h"
37
37
#include "html.h"
 
38
#include "metadata.h"
38
39
 
39
40
typedef struct faviconDownloadCtxt {
40
41
        gchar                   *id;            /**< favicon cache id */
252
253
        return slashes;
253
254
}
254
255
 
255
 
void favicon_download(const gchar *id, const gchar *html_url, const gchar *source_url, const updateOptionsPtr options, faviconUpdatedCb callback, gpointer user_data) {
 
256
void
 
257
favicon_download (subscriptionPtr subscription,
 
258
                  const gchar *html_url,
 
259
                  const gchar *source_url,
 
260
                  const updateOptionsPtr options,
 
261
                  faviconUpdatedCb callback,
 
262
                  gpointer user_data)
 
263
{
 
264
        const gchar             *id;
256
265
        faviconDownloadCtxtPtr  ctxt;
257
266
        gchar                   *tmp, *tmp2;
258
 
        
 
267
 
259
268
        debug_enter("favicon_download");
260
 
        
 
269
 
 
270
        id = subscription->node->id;
 
271
 
261
272
        ctxt = favicon_download_ctxt_new ();
262
273
        ctxt->id = g_strdup (id);
263
274
        ctxt->options = update_options_copy (options);
264
275
        ctxt->callback = callback;
265
276
        ctxt->user_data = user_data;
266
 
        
 
277
 
267
278
        /*
268
279
         * This code tries to download from a series of URLs. If there are no
269
280
         * favicons, this will make five downloads, three of which will be 404
270
281
         * errors. Hopefully this will not cause any webservers pain because
271
282
         * this code should be run only once a month per feed.
272
283
         *
273
 
         * 1. --> downloading HTML of the feed url and looking for a favicon reference
274
 
         * 2. --> downloading HTML of root of webserver and looking for a favicon reference
275
 
         * 3. --> downloading favicon from the root HTML
276
 
         * 4. --> downloading favicon from directory of RSS feed
277
 
         * 5. --> downloading favicon from root of webserver of the RSS feed
 
284
         * 1. --> downloading favicon from the feed (e.g. <icon> tag in atom feeds)
 
285
         * 2. --> downloading HTML of the feed url and looking for a favicon reference
 
286
         * 3. --> downloading HTML of root of webserver and looking for a favicon reference
 
287
         * 4. --> downloading favicon from the root HTML
 
288
         * 5. --> downloading favicon from directory of RSS feed
 
289
         * 6. --> downloading favicon from root of webserver of the RSS feed
278
290
         */
279
 
          
 
291
 
280
292
        /* In the following These URLs will be prepared here and passed as a list to 
281
293
           the download function that will then process in order
282
294
           until success or the end of the list is reached... */
283
295
        debug1(DEBUG_UPDATE, "preparing download URLs for favicon %s...", ctxt->id);
284
 
        
 
296
 
285
297
        /* case 1. */
 
298
        if (metadata_list_get (subscription->metadata, "icon")) {
 
299
                tmp = g_strstrip (g_strdup (metadata_list_get (subscription->metadata, "icon")));
 
300
                ctxt->urls = g_slist_append (ctxt->urls, tmp);
 
301
                debug1 (DEBUG_UPDATE, "(1) adding favicon search URL: %s", tmp);
 
302
        }
 
303
 
 
304
        /* case 2. */
286
305
        if(html_url) {
287
 
                tmp = g_strstrip (g_strdup(html_url));
 
306
                tmp = g_strstrip (g_strdup (html_url));
288
307
                ctxt->urls = g_slist_append(ctxt->urls, tmp);
289
 
                debug1(DEBUG_UPDATE, "(1) adding favicon search URL: %s", tmp);
 
308
                debug1(DEBUG_UPDATE, "(2) adding favicon search URL: %s", tmp);
290
309
        }
291
310
 
292
 
        /* case 2. */
293
 
        g_assert(source_url);   
 
311
        /* case 3. */
 
312
        g_assert(source_url);
294
313
        if(*source_url != '|') {
295
 
                tmp = tmp2 = g_strstrip (g_strdup(source_url));
 
314
                tmp = tmp2 = g_strstrip (g_strdup (source_url));
296
315
                tmp = strrchr(tmp, '/');
297
316
                if(tmp) {
298
317
                        *tmp = 0;
299
318
                        ctxt->urls = g_slist_append(ctxt->urls, tmp2);
300
 
                        debug1(DEBUG_UPDATE, "(2) adding favicon search URL: %s", tmp2);
 
319
                        debug1(DEBUG_UPDATE, "(3) adding favicon search URL: %s", tmp2);
301
320
                }
302
321
        }
303
 
        
304
 
        /* case 3. */
 
322
 
 
323
        /* case 4. */
305
324
        if(html_url) {
306
325
                if(2 < count_slashes(html_url)) {
307
326
                        tmp = tmp2 = g_strstrip (g_strdup (html_url));
313
332
                                        tmp = tmp2;
314
333
                                        tmp2 = g_strdup_printf("%s/favicon.ico", tmp);
315
334
                                        ctxt->urls = g_slist_append(ctxt->urls, tmp2);
316
 
                                        debug1(DEBUG_UPDATE, "(3) adding favicon source URL: %s", tmp2);
 
335
                                        debug1(DEBUG_UPDATE, "(4) adding favicon source URL: %s", tmp2);
317
336
                                }
318
337
                        }
319
338
                        g_free(tmp);
320
339
                }
321
340
        }
322
 
        
 
341
 
323
342
        if(*source_url != '|' && 2 < count_slashes(source_url)) {
324
 
                /* case 4 */
 
343
                /* case 5 */
325
344
                tmp = tmp2 = g_strstrip (g_strdup (source_url));
326
345
                tmp = strrchr(tmp, '/');
327
346
                if(tmp) {
329
348
                        tmp = tmp2;
330
349
                        tmp2 = g_strdup_printf("%s/favicon.ico", tmp);
331
350
                        ctxt->urls = g_slist_append(ctxt->urls, tmp2);
332
 
                        debug1(DEBUG_UPDATE, "(4) adding favicon source URL: %s", tmp2);
 
351
                        debug1(DEBUG_UPDATE, "(5) adding favicon source URL: %s", tmp2);
333
352
                }
334
353
                g_free(tmp);
335
 
        
336
 
                /* case 5 */
 
354
 
 
355
                /* case 6 */
337
356
                tmp = tmp2 = g_strstrip (g_strdup (source_url));
338
357
                tmp = strstr(tmp, "://");
339
358
                if(tmp) {
343
362
                                tmp = tmp2;
344
363
                                tmp2 = g_strdup_printf("%s/favicon.ico", tmp);
345
364
                                ctxt->urls = g_slist_append(ctxt->urls, tmp2);
346
 
                                debug1(DEBUG_UPDATE, "(5) adding favicon source URL: %s", tmp2);
 
365
                                debug1(DEBUG_UPDATE, "(6) adding favicon source URL: %s", tmp2);
347
366
                        }
348
367
                }
349
368
                g_free(tmp);
350
369
        }
351
 
                        
 
370
 
352
371
        favicon_download_run(ctxt);
353
 
        
 
372
 
354
373
        debug_exit("favicon_download");
355
374
}