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