comparison src/util.c @ 9227:9171e528d7e5

[gaim-migrate @ 10023] Patch by Don Seiler (aka rizzo) to add two additional parameters to gaim_url_parse(), which are used for storing the username and password from the URL, if they exist. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 07 Jun 2004 04:01:00 +0000
parents 316b1afb5974
children b83905afbb55
comparison
equal deleted inserted replaced
9226:7a00289f2ef1 9227:9171e528d7e5
37 void (*callback)(void *, const char *, size_t); 37 void (*callback)(void *, const char *, size_t);
38 void *user_data; 38 void *user_data;
39 39
40 struct 40 struct
41 { 41 {
42 char *user;
43 char *passwd;
42 char *address; 44 char *address;
43 int port; 45 int port;
44 char *page; 46 char *page;
45 47
46 } website; 48 } website;
2386 * Would be nice when dissecting an environmental variable 2388 * Would be nice when dissecting an environmental variable
2387 * that specifies proxy information. 2389 * that specifies proxy information.
2388 */ 2390 */
2389 gboolean 2391 gboolean
2390 gaim_url_parse(const char *url, char **ret_host, int *ret_port, 2392 gaim_url_parse(const char *url, char **ret_host, int *ret_port,
2391 char **ret_path) 2393 char **ret_path, char **ret_user, char **ret_passwd)
2392 { 2394 {
2393 char scan_info[255]; 2395 char scan_info[255];
2394 char port_str[6]; 2396 char port_str[6];
2395 int f; 2397 int f;
2398 const char *at;
2396 const char *turl; 2399 const char *turl;
2397 char host[256], path[256]; 2400 char host[256], path[256], user[256], passwd[256];
2398 int port = 0; 2401 int port = 0;
2399 /* hyphen at end includes it in control set */ 2402 /* hyphen at end includes it in control set */
2400 static char addr_ctrl[] = "A-Za-z0-9.-"; 2403 static char addr_ctrl[] = "A-Za-z0-9.-";
2401 static char port_ctrl[] = "0-9"; 2404 static char port_ctrl[] = "0-9";
2402 static char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-"; 2405 static char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-";
2406 static char user_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
2407 static char passwd_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
2403 2408
2404 g_return_val_if_fail(url != NULL, FALSE); 2409 g_return_val_if_fail(url != NULL, FALSE);
2405 2410
2406 if ((turl = strstr(url, "http://")) != NULL || 2411 if ((turl = strstr(url, "http://")) != NULL ||
2407 (turl = strstr(url, "HTTP://")) != NULL) 2412 (turl = strstr(url, "HTTP://")) != NULL)
2408 { 2413 {
2409 turl += 7; 2414 turl += 7;
2410 url = turl; 2415 url = turl;
2416 }
2417
2418 /* parse out authentication information if supplied */
2419 if (at = strchr(url, '@')) {
2420 g_snprintf(scan_info, sizeof(scan_info),
2421 "%%255[%s]:%%255[%s]^@", user_ctrl, passwd_ctrl);
2422 f = sscanf(url, scan_info, user, passwd);
2423
2424 if (f ==1 ) {
2425 /* No passwd, possibly just username supplied */
2426 g_snprintf(scan_info, sizeof(scan_info),
2427 "%%255[%s]^@", user_ctrl);
2428 f = sscanf(url, scan_info, user);
2429 *passwd = '\0';
2430 }
2431
2432 url = strdup(at+1); /* move pointer after the @ char */
2433 } else {
2434 *user = '\0';
2435 *passwd = '\0';
2411 } 2436 }
2412 2437
2413 g_snprintf(scan_info, sizeof(scan_info), 2438 g_snprintf(scan_info, sizeof(scan_info),
2414 "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, page_ctrl); 2439 "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, page_ctrl);
2415 2440
2430 sscanf(port_str, "%d", &port); 2455 sscanf(port_str, "%d", &port);
2431 2456
2432 if (ret_host != NULL) *ret_host = g_strdup(host); 2457 if (ret_host != NULL) *ret_host = g_strdup(host);
2433 if (ret_port != NULL) *ret_port = port; 2458 if (ret_port != NULL) *ret_port = port;
2434 if (ret_path != NULL) *ret_path = g_strdup(path); 2459 if (ret_path != NULL) *ret_path = g_strdup(path);
2460 if (ret_user != NULL) *ret_user = g_strdup(user);
2461 if (ret_passwd != NULL) *ret_passwd = g_strdup(passwd);
2435 2462
2436 return TRUE; 2463 return TRUE;
2437 } 2464 }
2438 2465
2439 static void 2466 static void
2442 if (gfud->webdata != NULL) g_free(gfud->webdata); 2469 if (gfud->webdata != NULL) g_free(gfud->webdata);
2443 if (gfud->url != NULL) g_free(gfud->url); 2470 if (gfud->url != NULL) g_free(gfud->url);
2444 if (gfud->user_agent != NULL) g_free(gfud->user_agent); 2471 if (gfud->user_agent != NULL) g_free(gfud->user_agent);
2445 if (gfud->website.address != NULL) g_free(gfud->website.address); 2472 if (gfud->website.address != NULL) g_free(gfud->website.address);
2446 if (gfud->website.page != NULL) g_free(gfud->website.page); 2473 if (gfud->website.page != NULL) g_free(gfud->website.page);
2474 if (gfud->website.user != NULL) g_free(gfud->website.user);
2475 if (gfud->website.passwd != NULL) g_free(gfud->website.passwd);
2447 2476
2448 g_free(gfud); 2477 g_free(gfud);
2449 } 2478 }
2450 2479
2451 static gboolean 2480 static gboolean
2698 gfud->user_agent = (user_agent != NULL ? g_strdup(user_agent) : NULL); 2727 gfud->user_agent = (user_agent != NULL ? g_strdup(user_agent) : NULL);
2699 gfud->http11 = http11; 2728 gfud->http11 = http11;
2700 gfud->full = full; 2729 gfud->full = full;
2701 2730
2702 gaim_url_parse(url, &gfud->website.address, &gfud->website.port, 2731 gaim_url_parse(url, &gfud->website.address, &gfud->website.port,
2703 &gfud->website.page); 2732 &gfud->website.page, &gfud->website.user, &gfud->website.passwd);
2704 2733
2705 if ((sock = gaim_proxy_connect(NULL, gfud->website.address, 2734 if ((sock = gaim_proxy_connect(NULL, gfud->website.address,
2706 gfud->website.port, url_fetched_cb, 2735 gfud->website.port, url_fetched_cb,
2707 gfud)) < 0) 2736 gfud)) < 0)
2708 { 2737 {