~ubuntu-branches/ubuntu/quantal/elinks/quantal

« back to all changes in this revision

Viewing changes to src/cookies/cookies.c

  • Committer: Bazaar Package Importer
  • Author(s): Siegfried-Angel Gevatter Pujals (RainCT)
  • Date: 2008-02-01 16:29:06 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080201162906-xdourui5tyjva0al
Tags: 0.11.3-5ubuntu1
 
* Merge from Debian unstable (LP: #187936); remaining changes:
  - Add X-Ubuntu-Gettext-Domain to .desktop files.
  - debian/control: Maintainer field update.
* Improve the text in the .desktop file and add some translations.
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "intl/gettext/libintl.h"
30
30
#include "main/module.h"
31
31
#include "main/object.h"
 
32
#include "main/select.h"
32
33
#include "protocol/date.h"
33
34
#include "protocol/header.h"
34
35
#include "protocol/protocol.h"
62
63
 
63
64
static INIT_LIST_HEAD(cookie_servers);
64
65
 
 
66
/* Only @set_cookies_dirty may make this nonzero.  */
65
67
static int cookies_dirty = 0;
66
68
 
67
69
enum cookies_option {
200
202
        mem_free(c);
201
203
}
202
204
 
 
205
/* The cookie @c can be either in @cookies or in @cookie_queries.
 
206
 * Because changes in @cookie_queries should not affect the cookie
 
207
 * file, this function does not set @cookies_dirty.  Instead, the
 
208
 * caller must do that if appropriate.  */
203
209
void
204
210
delete_cookie(struct cookie *c)
205
211
{
460
466
                                continue;
461
467
 
462
468
                        delete_cookie(c);
 
469
                        /* @set_cookies_dirty will be called below.  */
463
470
                }
464
471
        }
465
472
 
466
473
        add_to_list(cookies, cookie);
467
 
        cookies_dirty = 1;
 
474
        set_cookies_dirty();
468
475
 
469
476
        /* XXX: This crunches CPU too. --pasky */
470
477
        foreach (cd, c_domains)
478
485
 
479
486
        memcpy(cd->domain, cookie->domain, domain_len + 1);
480
487
        add_to_list(c_domains, cd);
481
 
 
482
 
        if (get_cookies_save() && get_cookies_resave())
483
 
                save_cookies();
484
488
}
485
489
 
486
490
#if 0
507
511
end:
508
512
        del_from_list(c);
509
513
        done_cookie(c);
510
 
 
511
 
        if (get_cookies_save() && get_cookies_resave())
512
 
                save_cookies();
513
514
}
514
515
 
515
516
 
535
536
        if (!c) return;
536
537
 
537
538
        delete_cookie(c);
 
539
        set_cookies_dirty(); /* @find_cookie_id doesn't use @cookie_queries */
538
540
}
539
541
 
540
542
 
637
639
#endif
638
640
                        delete_cookie(c);
639
641
 
640
 
                        cookies_dirty = 1;
 
642
                        set_cookies_dirty();
641
643
                        continue;
642
644
                }
643
645
 
658
660
 
659
661
        mem_free(path);
660
662
 
661
 
        if (cookies_dirty && get_cookies_save() && get_cookies_resave())
662
 
                save_cookies();
663
 
 
664
663
        if (!header.length) {
665
664
                done_string(&header);
666
665
                return NULL;
730
729
                /* Skip expired cookies if any. */
731
730
                expires = str_to_time_t(members[EXPIRES].pos);
732
731
                if (!expires || expires <= now) {
733
 
                        cookies_dirty = 1;
 
732
                        set_cookies_dirty();
734
733
                        continue;
735
734
                }
736
735
 
761
760
        fclose(fp);
762
761
}
763
762
 
 
763
static void
 
764
resave_cookies_bottom_half(void *always_null)
 
765
{
 
766
        if (get_cookies_save() && get_cookies_resave())
 
767
                save_cookies(); /* checks cookies_dirty */
 
768
}
 
769
 
 
770
/* Note that the cookies have been modified, and register a bottom
 
771
 * half for saving them if appropriate.  We use a bottom half so that
 
772
 * if something makes multiple changes and calls this for each change,
 
773
 * the cookies get saved only once at the end.  */
 
774
void
 
775
set_cookies_dirty(void)
 
776
{
 
777
        /* Do not check @cookies_dirty here.  If the previous attempt
 
778
         * to save cookies failed, @cookies_dirty can still be nonzero
 
779
         * even though @resave_cookies_bottom_half is no longer in the
 
780
         * queue.  */
 
781
        cookies_dirty = 1;
 
782
        /* If @resave_cookies_bottom_half is already in the queue,
 
783
         * @register_bottom_half does nothing.  */
 
784
        register_bottom_half(resave_cookies_bottom_half, NULL);
 
785
}
 
786
 
764
787
void
765
788
save_cookies(void) {
766
789
        struct cookie *c;
801
824
                load_cookies();
802
825
}
803
826
 
 
827
/* Like @delete_cookie, this function does not set @cookies_dirty.
 
828
 * The caller must do that if appropriate.  */
804
829
static void
805
830
free_cookies_list(struct list_head *list)
806
831
{
821
846
 
822
847
        free_cookies_list(&cookies);
823
848
        free_cookies_list(&cookie_queries);
 
849
        /* If @save_cookies failed above, @cookies_dirty can still be
 
850
         * nonzero.  Now if @resave_cookies_bottom_half were in the
 
851
         * queue, it could save the empty @cookies list to the file.
 
852
         * Prevent that.  */
 
853
        cookies_dirty = 0;
824
854
}
825
855
 
826
856
struct module cookies_module = struct_module(