comparison src/html.c @ 6516:7c14b35bc984

[gaim-migrate @ 7033] reversed the last yahoo info patch and applied this one instead, which includes msn info support. ChipX86: if this messes you up, tell me and i'll switch it back. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 20 Aug 2003 02:45:31 +0000
parents 64d952098596
children 67c4e9d39242
comparison
equal deleted inserted replaced
6515:785a272be6ce 6516:7c14b35bc984
79 int f; 79 int f;
80 char* turl; 80 char* turl;
81 /* hyphen at end includes it in control set */ 81 /* hyphen at end includes it in control set */
82 char addr_ctrl[] = "A-Za-z0-9.-"; 82 char addr_ctrl[] = "A-Za-z0-9.-";
83 char port_ctrl[] = "0-9"; 83 char port_ctrl[] = "0-9";
84 char page_ctrl[] = "A-Za-z0-9.~_/&%%?=+^-"; 84 char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-";
85 85
86 if((turl=strstr(url, "http://")) || (turl=strstr(url, "HTTP://"))) 86 if((turl=strstr(url, "http://")) || (turl=strstr(url, "HTTP://")))
87 url=turl+=7; 87 url=turl+=7;
88 88
89 snprintf(scan_info, sizeof(scan_info), 89 snprintf(scan_info, sizeof(scan_info),
109 void (* callback)(gpointer, char *, unsigned long); 109 void (* callback)(gpointer, char *, unsigned long);
110 gpointer data; 110 gpointer data;
111 struct g_url *website; 111 struct g_url *website;
112 char *url; 112 char *url;
113 gboolean full; 113 gboolean full;
114 char *user_agent;
115 int http11;
114 116
115 int inpa; 117 int inpa;
116 118
117 gboolean sentreq; 119 gboolean sentreq;
118 gboolean newline; 120 gboolean newline;
165 167
166 gaim_debug(GAIM_DEBUG_INFO, "grab_url", 168 gaim_debug(GAIM_DEBUG_INFO, "grab_url",
167 "Redirecting to %s\n", new_url); 169 "Redirecting to %s\n", new_url);
168 170
169 /* Try again, with this new location. */ 171 /* Try again, with this new location. */
170 grab_url(new_url, full, gunk->callback, gunk->data); 172 grab_url(new_url, full, gunk->callback, gunk->data, gunk->user_agent, gunk->http11);
171 173
172 /* Free up. */ 174 /* Free up. */
173 g_free(new_url); 175 g_free(new_url);
174 g_free(gunk->webdata); 176 g_free(gunk->webdata);
175 g_free(gunk->website); 177 g_free(gunk->website);
176 g_free(gunk->url); 178 g_free(gunk->url);
179 g_free(gunk->user_agent);
177 g_free(gunk); 180 g_free(gunk);
178 181
179 return TRUE; 182 return TRUE;
180 } 183 }
181 184
199 202
200 if (sock == -1) { 203 if (sock == -1) {
201 gunk->callback(gunk->data, NULL, 0); 204 gunk->callback(gunk->data, NULL, 0);
202 g_free(gunk->website); 205 g_free(gunk->website);
203 g_free(gunk->url); 206 g_free(gunk->url);
207 g_free(gunk->user_agent);
204 g_free(gunk); 208 g_free(gunk);
205 return; 209 return;
206 } 210 }
207 211
208 if (!gunk->sentreq) { 212 if (!gunk->sentreq) {
209 char buf[256]; 213 char buf[1024];
210 214
211 g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", gunk->full ? "" : "/", 215 if(gunk->user_agent) {
212 gunk->full ? gunk->url : gunk->website->page); 216 if(gunk->http11)
213 217 g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.1\r\nUser-Agent: \"%s\"\r\nHost: %s\r\n\r\n", gunk->full ? "" : "/",
218 gunk->full ? gunk->url : gunk->website->page, gunk->user_agent, gunk->website->address);
219 else
220 g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\nUser-Agent: \"%s\"\r\n\r\n", gunk->full ? "" : "/",
221 gunk->full ? gunk->url : gunk->website->page, gunk->user_agent);
222 }
223 else {
224 if(gunk->http11)
225 g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.1\r\nHost: %s\r\n\r\n", gunk->full ? "" : "/",
226 gunk->full ? gunk->url : gunk->website->page, gunk->website->address);
227 else
228 g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", gunk->full ? "" : "/",
229 gunk->full ? gunk->url : gunk->website->page);
230
231 }
214 gaim_debug(GAIM_DEBUG_MISC, "grab_url_callback", 232 gaim_debug(GAIM_DEBUG_MISC, "grab_url_callback",
215 "Request: %s\n", buf); 233 "Request: %s\n", buf);
216 234
217 write(sock, buf, strlen(buf)); 235 write(sock, buf, strlen(buf));
218 fcntl(sock, F_SETFL, O_NONBLOCK); 236 fcntl(sock, F_SETFL, O_NONBLOCK);
286 gunk->callback(gunk->data, gunk->webdata, gunk->len); 304 gunk->callback(gunk->data, gunk->webdata, gunk->len);
287 if (gunk->webdata) 305 if (gunk->webdata)
288 g_free(gunk->webdata); 306 g_free(gunk->webdata);
289 g_free(gunk->website); 307 g_free(gunk->website);
290 g_free(gunk->url); 308 g_free(gunk->url);
309 g_free(gunk->user_agent);
291 g_free(gunk); 310 g_free(gunk);
292 } else { 311 } else {
293 gaim_input_remove(gunk->inpa); 312 gaim_input_remove(gunk->inpa);
294 close(sock); 313 close(sock);
295 gunk->callback(gunk->data, NULL, 0); 314 gunk->callback(gunk->data, NULL, 0);
296 if (gunk->webdata) 315 if (gunk->webdata)
297 g_free(gunk->webdata); 316 g_free(gunk->webdata);
298 g_free(gunk->website); 317 g_free(gunk->website);
299 g_free(gunk->url); 318 g_free(gunk->url);
319 g_free(gunk->user_agent);
300 g_free(gunk); 320 g_free(gunk);
301 } 321 }
302 } 322 }
303 323
304 void grab_url(char *url, gboolean full, void callback(gpointer, char *, unsigned long), gpointer data) 324 void grab_url(char *url, gboolean full, void callback(gpointer, char *, unsigned long),
325 gpointer data, char *user_agent, int http11)
305 { 326 {
306 int sock; 327 int sock;
307 struct grab_url_data *gunk = g_new0(struct grab_url_data, 1); 328 struct grab_url_data *gunk = g_new0(struct grab_url_data, 1);
308 329
309 gunk->callback = callback; 330 gunk->callback = callback;
310 gunk->data = data; 331 gunk->data = data;
311 gunk->url = g_strdup(url); 332 gunk->url = g_strdup(url);
333 gunk->user_agent = (user_agent) ? g_strdup(user_agent) : NULL;
334 gunk->http11 = http11;
312 gunk->website = parse_url(url); 335 gunk->website = parse_url(url);
313 gunk->full = full; 336 gunk->full = full;
314 337
315 if ((sock = gaim_proxy_connect(NULL, gunk->website->address, 338 if ((sock = gaim_proxy_connect(NULL, gunk->website->address,
316 gunk->website->port, grab_url_callback, 339 gunk->website->port, grab_url_callback,
317 gunk)) < 0) { 340 gunk)) < 0) {
318 g_free(gunk->website); 341 g_free(gunk->website);
319 g_free(gunk->url); 342 g_free(gunk->url);
343 g_free(gunk->user_agent);
320 g_free(gunk); 344 g_free(gunk);
321 callback(data, g_strdup(_("g003: Error opening connection.\n")), 0); 345 callback(data, g_strdup(_("g003: Error opening connection.\n")), 0);
322 } 346 }
323 } 347 }
324 348