annotate src/html.c @ 1843:4dbd8533d209

[gaim-migrate @ 1853] http can be authenticated committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 12 May 2001 08:09:54 +0000
parents 00aef397a1fe
children a02584b98823
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
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 278
diff changeset
23 #include "../config.h"
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>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #include <sys/time.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 #include <unistd.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #include <gtk/gtk.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31 #include <gdk/gdkprivate.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32 #include <gdk/gdkx.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 #include "gaim.h"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 #include <sys/types.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35 #include <sys/socket.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #include <netdb.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 #include <netinet/in.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>
1092
a930439f29b1 [gaim-migrate @ 1102]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1088
diff changeset
40 #include "proxy.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
42 gchar *strip_html(gchar *text)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 int i, j;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45 int visible = 1;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46 gchar *text2 = g_malloc(strlen(text) + 1);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
47
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48 strcpy(text2, text);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
49 for (i = 0, j = 0; text2[i]; i++) {
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
50 if (text2[i] == '<') {
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51 visible = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52 continue;
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
53 } else if (text2[i] == '>') {
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54 visible = 1;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55 continue;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
56 }
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
57 if (visible) {
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
58 text2[j++] = text2[i];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
59 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61 text2[j] = '\0';
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
62 return text2;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
63 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
64
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
65 struct g_url parse_url(char *url)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
66 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
67 struct g_url test;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
68 char scan_info[255];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
69 char port[5];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
70 int f;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 if (strstr(url, "http://"))
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
73 g_snprintf(scan_info, sizeof(scan_info),
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
74 "http://%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?]");
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75 else
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
76 g_snprintf(scan_info, sizeof(scan_info),
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
77 "%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?]");
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78 f = sscanf(url, scan_info, test.address, port, test.page);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 if (f == 1) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
80 if (strstr(url, "http://"))
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
81 g_snprintf(scan_info, sizeof(scan_info),
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
82 "http://%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?]");
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83 else
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
84 g_snprintf(scan_info, sizeof(scan_info),
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
85 "%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?]");
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
86 f = sscanf(url, scan_info, test.address, test.page);
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
87 g_snprintf(port, sizeof(test.port), "80");
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
88 port[2] = 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 if (f == 1) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 if (strstr(url, "http://"))
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92 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
93 else
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
94 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]");
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95 f = sscanf(url, scan_info, test.address);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96 g_snprintf(test.page, sizeof(test.page), "%c", '\0');
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
98
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99 sscanf(port, "%d", &test.port);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 return test;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
103 struct grab_url_data {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
104 void (*callback)(gpointer, char *);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
105 gpointer data;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 struct g_url website;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
107 char *url;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
108 };
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
109
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
110 static void grab_url_callback(gpointer dat, gint sock, GdkInputCondition cond)
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
111 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
112 struct grab_url_data *gunk = dat;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 char *webdata = NULL;
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
114 int len;
268
f8a29745247c [gaim-migrate @ 278]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 253
diff changeset
115 int read_rv;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116 int datalen = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
117 char buf[256];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
118 char data;
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
119 int startsaving = 0;
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
120 GtkWidget *pw = NULL, *pbar = NULL, *label;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
121
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
122 if (sock == -1) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
123 gunk->callback(gunk->data, NULL);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
124 g_free(gunk->url);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
125 g_free(gunk);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
126 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 691
diff changeset
127 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
128
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
129 g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", gunk->website.page);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
130 debug_printf("Request: %s\n", buf);
268
f8a29745247c [gaim-migrate @ 278]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 253
diff changeset
131 write(sock, buf, strlen(buf));
278
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
132 fcntl(sock, F_SETFL, O_NONBLOCK);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
133
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
134 webdata = NULL;
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
135 len = 0;
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
136
268
f8a29745247c [gaim-migrate @ 278]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 253
diff changeset
137 /*
f8a29745247c [gaim-migrate @ 278]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 253
diff changeset
138 * avoid fgetc(), it causes problems on solaris
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
139 while ((data = fgetc(sockfile)) != EOF) {
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
140 */
268
f8a29745247c [gaim-migrate @ 278]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 253
diff changeset
141 /* read_rv will be 0 on EOF and < 0 on error, so this should be fine */
278
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
142 while ((read_rv = read(sock, &data, 1)) > 0 || errno == EWOULDBLOCK) {
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
143 if (errno == EWOULDBLOCK) {
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
144 errno = 0;
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
145 continue;
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
146 }
29e1669b006b [gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 268
diff changeset
147
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
148 if (!data)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
149 continue;
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
150
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
151 if (!startsaving && data == '<') {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
152 #ifdef HAVE_STRSTR
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
153 char *cs = strstr(webdata, "Content-Length");
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
154 if (cs) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
155 char tmpbuf[1024];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
156 sscanf(cs, "Content-Length: %d", &datalen);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
158 g_snprintf(tmpbuf, 1024, _("Getting %d bytes from %s"),
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
159 datalen, gunk->url);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
160 pw = gtk_dialog_new();
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162 label = gtk_label_new(tmpbuf);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
163 gtk_widget_show(label);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->vbox),
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 label, FALSE, FALSE, 5);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
166
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
167 pbar = gtk_progress_bar_new();
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
168 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->action_area),
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
169 pbar, FALSE, FALSE, 5);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
170 gtk_widget_show(pbar);
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
171
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
172 gtk_window_set_title(GTK_WINDOW(pw), _("Getting Data"));
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
173
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
174 gtk_widget_realize(pw);
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
175 aol_icon(pw->window);
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
176
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
177 gtk_widget_show(pw);
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
178 } else
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179 datalen = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
180 #else
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
181 datalen = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
182 #endif
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
183 g_free(webdata);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
184 webdata = NULL;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
185 len = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
186 startsaving = 1;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
187 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
188
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
189 len++;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
190 webdata = g_realloc(webdata, len);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
191 webdata[len - 1] = data;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
192
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
193 if (pbar)
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
194 gtk_progress_bar_update(GTK_PROGRESS_BAR(pbar), ((100 * len) / datalen) / 100.0);
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
195
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
196 while (gtk_events_pending())
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
197 gtk_main_iteration();
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
198 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
199
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
200 webdata = g_realloc(webdata, len + 1);
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
201 webdata[len] = 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
202
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
203
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
204 debug_printf(_("Receieved: '%s'\n"), webdata);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
205
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
206 if (pw)
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1092
diff changeset
207 gtk_widget_destroy(pw);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
208
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
209 close(sock);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
210 gunk->callback(gunk->data, webdata);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
211 g_free(gunk->url);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
212 g_free(gunk);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
213 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
214
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
215 void grab_url(struct aim_user *user, char *url, void (*callback)(gpointer, char *), gpointer data)
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
216 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
217 int sock;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
218 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
219
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
220 gunk->callback = callback;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
221 gunk->data = data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
222 gunk->url = g_strdup(url);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
223 gunk->website = parse_url(url);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
224
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
225 if (user) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
226 if ((sock = proxy_connect(gunk->website.address, gunk->website.port,
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
227 user->proto_opt[2], atoi(user->proto_opt[3]),
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
228 atoi(user->proto_opt[4]),
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
229 user->proto_opt[5], user->proto_opt[6],
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
230 grab_url_callback, gunk)) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
231 g_free(gunk->url);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
232 g_free(gunk);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
233 callback(data, g_strdup(_("g003: Error opening connection.\n")));
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
234 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
235 } else {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
236 if ((sock = proxy_connect(gunk->website.address, gunk->website.port, NULL, 0, -1,
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
237 NULL, NULL, grab_url_callback, gunk)) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
238 g_free(gunk->url);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
239 g_free(gunk);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
240 callback(data, g_strdup(_("g003: Error opening connection.\n")));
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
241 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
242 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
243 }