]> git.pld-linux.org Git - packages/links2.git/blob - links2-cookies-save.patch
- rebuild with libevent 2.1.9
[packages/links2.git] / links2-cookies-save.patch
1 --- links-2.12/cookies.c.orig   2016-01-09 16:48:22.619433626 +0100
2 +++ links-2.12/cookies.c        2016-01-09 16:52:06.066090917 +0100
3 @@ -250,15 +250,99 @@
4  void free_cookies(void)
5  {
6         struct cookie *c;
7 +       unsigned char *cookfile;
8 +       FILE *fp;
9 +
10         free_list(c_domains);
11 -       /* !!! FIXME: save cookies */
12 -       foreach (c, all_cookies) free_cookie(c);
13 +
14 +       cookfile = stracpy(links_home);
15 +       if (! cookfile) return;
16 +       add_to_strn(&cookfile, "cookies");
17 +
18 +       fp = fopen(cookfile, "w");
19 +       mem_free(cookfile);
20 +       if (fp == NULL) return;
21 +
22 +       foreach (c, all_cookies) {
23 +               if (c->expires && ! cookie_expired(c))
24 +                       fprintf(fp, "%s %s %s %s %s %d %d\n", c->name, c->value,
25 +                           c->server?c->server:(unsigned char *)"", c->path?c->path:(unsigned char *)"",
26 +                           c->domain?c->domain:(unsigned char *)"", (int)c->expires, c->secure);
27 +
28 +               free_cookie(c);
29 +       }
30 +
31 +       fclose(fp);
32 +
33         free_list(all_cookies);
34  }
35  
36  void init_cookies(void)
37  {
38 -       /* !!! FIXME: read cookies */
39 +       unsigned char in_buffer[MAX_STR_LEN];
40 +       unsigned char *cookfile, *p, *q;
41 +       FILE *fp;
42 +
43 +       /* must be called after init_home */
44 +       if (! links_home) return;
45 +
46 +       cookfile = stracpy(links_home);
47 +       if (! cookfile) return;
48 +       add_to_strn(&cookfile, "cookies");
49 +
50 +       fp = fopen(cookfile, "r");
51 +       mem_free(cookfile);
52 +       if (fp == NULL) return;
53 +
54 +       while (fgets(in_buffer, MAX_STR_LEN, fp)) {
55 +               struct cookie *cookie;
56 +
57 +               if (!(cookie = mem_alloc(sizeof(struct cookie)))) return;
58 +               memset(cookie, 0, sizeof(struct cookie));
59 +
60 +               q = in_buffer; p = strchr(in_buffer, ' ');
61 +               if (p == NULL) goto inv;
62 +               *p++ = '\0';
63 +               cookie->name = stracpy(q);
64 +
65 +               q = p; p = strchr(p, ' ');
66 +               if (p == NULL) goto inv;
67 +               *p++ = '\0';
68 +               cookie->value = stracpy(q);
69 +
70 +               q = p; p = strchr(p, ' ');
71 +               if (p == NULL) goto inv;
72 +               *p++ = '\0';
73 +               cookie->server = stracpy(q);
74 +
75 +               q = p; p = strchr(p, ' ');
76 +               if (p == NULL) goto inv;
77 +               *p++ = '\0';
78 +               cookie->path = stracpy(q);
79 +
80 +               q = p; p = strchr(p, ' ');
81 +               if (p == NULL) goto inv;
82 +               *p++ = '\0';
83 +               cookie->domain = stracpy(q);
84 +
85 +               q = p; p = strchr(p, ' ');
86 +               if (p == NULL) goto inv;
87 +               *p++ = '\0';
88 +               cookie->expires = atoi(q);
89 +
90 +               cookie->secure = atoi(p);
91 +
92 +               /*cookie->id = cookie_id++;*/
93 +
94 +               accept_cookie(cookie);
95 +
96 +               continue;
97 +
98 +inv:
99 +               free_cookie(cookie);
100 +               free(cookie);
101 +       }
102 +       fclose(fp);
103  }
104  
105  void cleanup_cookies(void)
This page took 0.0842 seconds and 3 git commands to generate.