annotate src/html.c @ 4757:c4ebe1a8484b

[gaim-migrate @ 5074] this fixes a bunch of little things, as well as a few big things, plugs a few leaks, and makes the new buddy icon cache stuff much cooler. enjoy! committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 14 Mar 2003 01:14:24 +0000
parents d19872836812
children e23a7e166680
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 278
diff changeset
22 #ifdef HAVE_CONFIG_H
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2060
diff changeset
23 #include <config.h>
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 278
diff changeset
24 #endif
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25 #include <string.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 #include <stdio.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #include <stdlib.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3100
diff changeset
28
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3100
diff changeset
29 #ifndef _WIN32
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #include <sys/time.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31 #include <unistd.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32 #include <sys/socket.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 #include <netdb.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 #include <netinet/in.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3100
diff changeset
35 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3100
diff changeset
36
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3100
diff changeset
37 #include <sys/types.h>
278
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
38 #include <fcntl.h>
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
39 #include <errno.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3100
diff changeset
40 #include "gaim.h"
1092
a930439f29b1 [gaim-migrate @ 1102]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1088
diff changeset
41 #include "proxy.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
43 #ifdef _WIN32
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
44 #include "win32dep.h"
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
45 #endif
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
46
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4335
diff changeset
47 gchar *strip_html(const gchar *text)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48 {
1883
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
49 int i, j, k;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 int visible = 1;
1883
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
51 gchar *text2 = g_strdup(text);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
52
4757
c4ebe1a8484b [gaim-migrate @ 5074]
Nathan Walp <nwalp@pidgin.im>
parents: 4634
diff changeset
53 if(!text)
c4ebe1a8484b [gaim-migrate @ 5074]
Nathan Walp <nwalp@pidgin.im>
parents: 4634
diff changeset
54 return NULL;
4503
fdc4ac6d1db1 [gaim-migrate @ 4778]
Nathan Walp <nwalp@pidgin.im>
parents: 4473
diff changeset
55
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
56 for (i = 0, j = 0; text2[i]; i++) {
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
57 if (text2[i] == '<') {
1883
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
58 k = i + 1;
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
59 while (text2[k]) {
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
60 if (text2[k] == '<') {
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
61 visible = 1;
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
62 break;
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
63 }
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
64 if (text2[k] == '>') {
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
65 visible = 0;
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
66 break;
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
67 }
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
68 k++;
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
69 }
060161a5d5f8 [gaim-migrate @ 1893]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
70 } else if (text2[i] == '>' && !visible) {
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71 visible = 1;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 continue;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 }
4473
7b0f6537da75 [gaim-migrate @ 4748]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
74 if (text2[i] == '&' && strncasecmp(text2+i,"&quot;",6) == 0) {
7b0f6537da75 [gaim-migrate @ 4748]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
75 text2[j++] = '\"';
7b0f6537da75 [gaim-migrate @ 4748]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
76 i = i+5;
7b0f6537da75 [gaim-migrate @ 4748]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
77 continue;
7b0f6537da75 [gaim-migrate @ 4748]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
78 }
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
79 if (visible) {
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
80 text2[j++] = text2[i];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
81 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
82 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83 text2[j] = '\0';
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84 return text2;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
86
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3100
diff changeset
87 struct g_url *parse_url(char *url)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
88 {
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
89 struct g_url *test = g_new0(struct g_url, 1);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 char scan_info[255];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 char port[5];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92 int f;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94 if (strstr(url, "http://"))
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
95 g_snprintf(scan_info, sizeof(scan_info),
2060
2fe660574083 [gaim-migrate @ 2070]
Rob Flynn <gaim@robflynn.com>
parents: 1883
diff changeset
96 "http://%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?=+]");
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97 else
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
98 g_snprintf(scan_info, sizeof(scan_info),
2060
2fe660574083 [gaim-migrate @ 2070]
Rob Flynn <gaim@robflynn.com>
parents: 1883
diff changeset
99 "%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?=+^]");
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
100 f = sscanf(url, scan_info, test->address, port, test->page);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101 if (f == 1) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102 if (strstr(url, "http://"))
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
103 g_snprintf(scan_info, sizeof(scan_info),
2060
2fe660574083 [gaim-migrate @ 2070]
Rob Flynn <gaim@robflynn.com>
parents: 1883
diff changeset
104 "http://%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?=+^]");
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105 else
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
106 g_snprintf(scan_info, sizeof(scan_info),
2060
2fe660574083 [gaim-migrate @ 2070]
Rob Flynn <gaim@robflynn.com>
parents: 1883
diff changeset
107 "%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?=+^]");
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
108 f = sscanf(url, scan_info, test->address, test->page);
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
109 g_snprintf(port, sizeof(test->port), "80");
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
110 port[2] = 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
111 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
112 if (f == 1) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 if (strstr(url, "http://"))
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114 g_snprintf(scan_info, sizeof(scan_info), "http://%%[A-Za-z0-9.]");
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
115 else
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
116 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]");
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
117 f = sscanf(url, scan_info, test->address);
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
118 g_snprintf(test->page, sizeof(test->page), "%c", '\0');
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
120
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
121 sscanf(port, "%d", &test->port);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
122 return test;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
123 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
124
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
125 struct grab_url_data {
4322
a789969fc198 [gaim-migrate @ 4577]
Rob Flynn <gaim@robflynn.com>
parents: 3717
diff changeset
126 void (* callback)(gpointer, char *, unsigned long);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
127 gpointer data;
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
128 struct g_url *website;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
129 char *url;
2584
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
130 gboolean full;
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
131
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
132 int inpa;
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
133
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
134 gboolean sentreq;
2584
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
135 gboolean newline;
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
136 gboolean startsaving;
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
137 char *webdata;
4322
a789969fc198 [gaim-migrate @ 4577]
Rob Flynn <gaim@robflynn.com>
parents: 3717
diff changeset
138 unsigned long len;
4331
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
139 unsigned long data_len;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
140 };
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
141
4331
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
142 static gboolean
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
143 parse_redirect(const char *data, size_t data_len, gint sock,
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
144 struct grab_url_data *gunk)
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
145 {
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
146 gchar *s;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
147
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
148 if ((s = g_strstr_len(data, data_len, "Location: ")) != NULL) {
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
149 gchar *new_url, *end;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
150 int len;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
151
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
152 s += strlen("Location: ");
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
153 end = strchr(s, '\r');
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
154
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
155 /* Just in case :) */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
156 if (end == NULL)
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
157 end = strchr(s, '\n');
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
158
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
159 len = end - s;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
160
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
161 new_url = g_malloc(len + 1);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
162 strncpy(new_url, s, len);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
163 new_url[len] = '\0';
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
164
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
165 /* Close the existing stuff. */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
166 gaim_input_remove(gunk->inpa);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
167 close(sock);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
168
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
169 /* Try again, with this new location. */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
170 grab_url(new_url, gunk->full, gunk->callback,
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
171 gunk->data);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
172
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
173 /* Free up. */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
174 g_free(new_url);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
175 g_free(gunk->webdata);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
176 g_free(gunk->website);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
177 g_free(gunk->url);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
178 g_free(gunk);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
179
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
180 return TRUE;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
181 }
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
182
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
183 return FALSE;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
184 }
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
185
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
186 static size_t
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
187 parse_content_len(const char *data, size_t data_len)
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
188 {
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
189 size_t content_len = 0;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
190
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
191 sscanf(data, "Content-Length: %d", &content_len);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
192
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
193 return content_len;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
194 }
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
195
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
196 static void grab_url_callback(gpointer dat, gint sock, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
197 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
198 struct grab_url_data *gunk = dat;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
199 char data;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
201 if (sock == -1) {
4322
a789969fc198 [gaim-migrate @ 4577]
Rob Flynn <gaim@robflynn.com>
parents: 3717
diff changeset
202 gunk->callback(gunk->data, NULL, 0);
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
203 g_free(gunk->website);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
204 g_free(gunk->url);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
205 g_free(gunk);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
206 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 691
diff changeset
207 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
208
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
209 if (!gunk->sentreq) {
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
210 char buf[256];
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
211
2584
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
212 g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", gunk->full ? "" : "/",
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
213 gunk->full ? gunk->url : gunk->website->page);
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
214 debug_printf("Request: %s\n", buf);
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
215
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
216 write(sock, buf, strlen(buf));
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
217 fcntl(sock, F_SETFL, O_NONBLOCK);
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
218 gunk->sentreq = TRUE;
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
219 gunk->inpa = gaim_input_add(sock, GAIM_INPUT_READ, grab_url_callback, dat);
4331
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
220 gunk->data_len = 4096;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
221 gunk->webdata = g_malloc(gunk->data_len);
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
222 return;
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
223 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
224
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
225 if (read(sock, &data, 1) > 0 || errno == EWOULDBLOCK) {
278
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
226 if (errno == EWOULDBLOCK) {
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
227 errno = 0;
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
228 return;
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
229 }
4331
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
230
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
231 gunk->len++;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
232
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
233 if (gunk->len == gunk->data_len + 1) {
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
234 gunk->data_len += (gunk->data_len) / 2;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
235
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
236 gunk->webdata = g_realloc(gunk->webdata, gunk->data_len);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
237 }
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
238
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
239 gunk->webdata[gunk->len - 1] = data;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
240
2584
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
241 if (!gunk->startsaving) {
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
242 if (data == '\r')
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
243 return;
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
244 if (data == '\n') {
4331
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
245 if (gunk->newline) {
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
246 size_t content_len;
2584
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
247 gunk->startsaving = TRUE;
4331
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
248
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
249 /* See if we can find a redirect. */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
250 if (parse_redirect(gunk->webdata, gunk->len, sock, gunk))
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
251 return;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
252
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
253 /* No redirect. See if we can find a content length. */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
254 content_len = parse_content_len(gunk->webdata, gunk->len);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
255
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
256 if (content_len == 0) {
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
257 /* We'll stick with an initial 8192 */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
258 content_len = 8192;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
259 }
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
260
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
261 /* Out with the old... */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
262 gunk->len = 0;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
263 g_free(gunk->webdata);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
264 gunk->webdata = NULL;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
265
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
266 /* In with the new. */
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
267 gunk->data_len = content_len;
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
268 gunk->webdata = g_malloc(gunk->data_len);
bbd7b12986a8 [gaim-migrate @ 4595]
Christian Hammond <chipx86@chipx86.com>
parents: 4322
diff changeset
269 }
2584
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
270 else
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
271 gunk->newline = TRUE;
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
272 return;
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
273 }
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
274 gunk->newline = FALSE;
278
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
275 }
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
276 } else if (errno != ETIMEDOUT) {
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
277 gunk->webdata = g_realloc(gunk->webdata, gunk->len + 1);
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
278 gunk->webdata[gunk->len] = 0;
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
279
3100
dd78d89c910b [gaim-migrate @ 3114]
Sean Egan <seanegan@gmail.com>
parents: 2662
diff changeset
280 debug_printf(_("Received: '%s'\n"), gunk->webdata);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
281
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
282 gaim_input_remove(gunk->inpa);
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
283 close(sock);
4322
a789969fc198 [gaim-migrate @ 4577]
Rob Flynn <gaim@robflynn.com>
parents: 3717
diff changeset
284 gunk->callback(gunk->data, gunk->webdata, gunk->len);
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
285 if (gunk->webdata)
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
286 g_free(gunk->webdata);
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
287 g_free(gunk->website);
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
288 g_free(gunk->url);
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
289 g_free(gunk);
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
290 } else {
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
291 gaim_input_remove(gunk->inpa);
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
292 close(sock);
4322
a789969fc198 [gaim-migrate @ 4577]
Rob Flynn <gaim@robflynn.com>
parents: 3717
diff changeset
293 gunk->callback(gunk->data, NULL, 0);
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
294 if (gunk->webdata)
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
295 g_free(gunk->webdata);
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
296 g_free(gunk->website);
2369
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
297 g_free(gunk->url);
117e9f0950b6 [gaim-migrate @ 2382]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
298 g_free(gunk);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
299 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
300 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
301
4322
a789969fc198 [gaim-migrate @ 4577]
Rob Flynn <gaim@robflynn.com>
parents: 3717
diff changeset
302 void grab_url(char *url, gboolean full, void callback(gpointer, char *, unsigned long), gpointer data)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
303 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
304 int sock;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
305 struct grab_url_data *gunk = g_new0(struct grab_url_data, 1);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
306
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
307 gunk->callback = callback;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
308 gunk->data = data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
309 gunk->url = g_strdup(url);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
310 gunk->website = parse_url(url);
2584
34812d648f72 [gaim-migrate @ 2597]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
311 gunk->full = full;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
312
4634
d19872836812 [gaim-migrate @ 4941]
Nathan Walp <nwalp@pidgin.im>
parents: 4503
diff changeset
313 if ((sock = proxy_connect(NULL, gunk->website->address, gunk->website->port,
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2369
diff changeset
314 grab_url_callback, gunk)) < 0) {
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2417
diff changeset
315 g_free(gunk->website);
1881
a02584b98823 [gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
316 g_free(gunk->url);
a02584b98823 [gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
317 g_free(gunk);
4322
a789969fc198 [gaim-migrate @ 4577]
Rob Flynn <gaim@robflynn.com>
parents: 3717
diff changeset
318 callback(data, g_strdup(_("g003: Error opening connection.\n")), 0);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
319 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
320 }