Mercurial > pidgin.yaz
comparison src/html.c @ 1840:00aef397a1fe
[gaim-migrate @ 1850]
reworked some of the proxy stuff so that it's non-blocking now. next thing to do is to get IRC, MSN, Napster, and Jabber to use the new proxy_connect code. After that, Oscar and Yahoo (maybe Zephyr too? not likely)
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 12 May 2001 01:38:04 +0000 |
parents | b5783215b245 |
children | 4dbd8533d209 |
comparison
equal
deleted
inserted
replaced
1839:109cacf1ff97 | 1840:00aef397a1fe |
---|---|
98 | 98 |
99 sscanf(port, "%d", &test.port); | 99 sscanf(port, "%d", &test.port); |
100 return test; | 100 return test; |
101 } | 101 } |
102 | 102 |
103 char *grab_url(struct aim_user *user, char *url) | 103 struct grab_url_data { |
104 { | 104 void (*callback)(gpointer, char *); |
105 gpointer data; | |
105 struct g_url website; | 106 struct g_url website; |
107 char *url; | |
108 }; | |
109 | |
110 static void grab_url_callback(gpointer dat, gint sock, GdkInputCondition cond) | |
111 { | |
112 struct grab_url_data *gunk = dat; | |
106 char *webdata = NULL; | 113 char *webdata = NULL; |
107 int sock; | |
108 int len; | 114 int len; |
109 int read_rv; | 115 int read_rv; |
110 int datalen = 0; | 116 int datalen = 0; |
111 char buf[256]; | 117 char buf[256]; |
112 char data; | 118 char data; |
113 int startsaving = 0; | 119 int startsaving = 0; |
114 GtkWidget *pw = NULL, *pbar = NULL, *label; | 120 GtkWidget *pw = NULL, *pbar = NULL, *label; |
115 | 121 |
116 website = parse_url(url); | 122 if (sock == -1) { |
117 | 123 gunk->callback(gunk->data, NULL); |
118 if (user) { | 124 g_free(gunk->url); |
119 if ((sock = proxy_connect(website.address, website.port, user->proto_opt[2], | 125 g_free(gunk); |
120 atoi(user->proto_opt[3]), atoi(user->proto_opt[4]))) < 0) | 126 return; |
121 return g_strdup(_("g003: Error opening connection.\n")); | 127 } |
122 } else { | 128 |
123 if ((sock = proxy_connect(website.address, website.port, NULL, 0, -1)) < 0) | 129 g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", gunk->website.page); |
124 return g_strdup(_("g003: Error opening connection.\n")); | |
125 } | |
126 | |
127 g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", website.page); | |
128 debug_printf("Request: %s\n", buf); | 130 debug_printf("Request: %s\n", buf); |
129 write(sock, buf, strlen(buf)); | 131 write(sock, buf, strlen(buf)); |
130 fcntl(sock, F_SETFL, O_NONBLOCK); | 132 fcntl(sock, F_SETFL, O_NONBLOCK); |
131 | 133 |
132 webdata = NULL; | 134 webdata = NULL; |
151 char *cs = strstr(webdata, "Content-Length"); | 153 char *cs = strstr(webdata, "Content-Length"); |
152 if (cs) { | 154 if (cs) { |
153 char tmpbuf[1024]; | 155 char tmpbuf[1024]; |
154 sscanf(cs, "Content-Length: %d", &datalen); | 156 sscanf(cs, "Content-Length: %d", &datalen); |
155 | 157 |
156 g_snprintf(tmpbuf, 1024, _("Getting %d bytes from %s"), datalen, url); | 158 g_snprintf(tmpbuf, 1024, _("Getting %d bytes from %s"), |
159 datalen, gunk->url); | |
157 pw = gtk_dialog_new(); | 160 pw = gtk_dialog_new(); |
158 | 161 |
159 label = gtk_label_new(tmpbuf); | 162 label = gtk_label_new(tmpbuf); |
160 gtk_widget_show(label); | 163 gtk_widget_show(label); |
161 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->vbox), | 164 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->vbox), |
202 | 205 |
203 if (pw) | 206 if (pw) |
204 gtk_widget_destroy(pw); | 207 gtk_widget_destroy(pw); |
205 | 208 |
206 close(sock); | 209 close(sock); |
207 return webdata; | 210 gunk->callback(gunk->data, webdata); |
208 } | 211 g_free(gunk->url); |
212 g_free(gunk); | |
213 } | |
214 | |
215 void grab_url(struct aim_user *user, char *url, void (*callback)(gpointer, char *), gpointer data) | |
216 { | |
217 int sock; | |
218 struct grab_url_data *gunk = g_new0(struct grab_url_data, 1); | |
219 | |
220 gunk->callback = callback; | |
221 gunk->data = data; | |
222 gunk->url = g_strdup(url); | |
223 gunk->website = parse_url(url); | |
224 | |
225 if (user) { | |
226 if ((sock = proxy_connect(gunk->website.address, gunk->website.port, | |
227 user->proto_opt[2], atoi(user->proto_opt[3]), | |
228 atoi(user->proto_opt[4]), | |
229 grab_url_callback, gunk)) < 0) { | |
230 g_free(gunk->url); | |
231 g_free(gunk); | |
232 callback(data, g_strdup(_("g003: Error opening connection.\n"))); | |
233 } | |
234 } else { | |
235 if ((sock = proxy_connect(gunk->website.address, gunk->website.port, NULL, 0, -1, | |
236 grab_url_callback, gunk)) < 0) { | |
237 g_free(gunk->url); | |
238 g_free(gunk); | |
239 callback(data, g_strdup(_("g003: Error opening connection.\n"))); | |
240 } | |
241 } | |
242 } |