From: Christian H. <ch...@us...> - 2004-06-07 04:01:09
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6902/src Modified Files: proxy.c util.c util.h Log Message: 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. Index: proxy.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/proxy.c,v retrieving revision 1.99 retrieving revision 1.100 diff -u -d -p -r1.99 -r1.100 --- proxy.c 31 May 2004 00:07:05 -0000 1.99 +++ proxy.c 7 Jun 2004 04:00:57 -0000 1.100 @@ -1446,16 +1446,24 @@ gaim_proxy_connect(GaimAccount *account, if ((tmp = g_getenv("HTTP_PROXY")) != NULL || (tmp = g_getenv("http_proxy")) != NULL || (tmp= g_getenv("HTTPPROXY")) != NULL) { - char *proxyhost,*proxypath; + char *proxyhost,*proxypath,*proxyuser,*proxypasswd; int proxyport; /* http_proxy-format: - * export http_proxy="http://your.proxy.server:port/" + * export http_proxy="http://user:pa...@yo...rver:port/" */ - if(gaim_url_parse(tmp, &proxyhost, &proxyport, &proxypath)) { + if(gaim_url_parse(tmp, &proxyhost, &proxyport, &proxypath, &proxyuser, &proxypasswd)) { gaim_proxy_info_set_host(phb->gpi, proxyhost); g_free(proxyhost); g_free(proxypath); + if (proxyuser != NULL) { + gaim_proxy_info_set_username(phb->gpi, proxyuser); + g_free(proxyuser); + } + if (proxypasswd != NULL) { + gaim_proxy_info_set_password(phb->gpi, proxypasswd); + g_free(proxypasswd); + } /* only for backward compatibility */ if (proxyport == 80 && @@ -1468,6 +1476,7 @@ gaim_proxy_connect(GaimAccount *account, } } + /* XXX: Do we want to skip this step if user/password were part of url? */ if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL || (tmp = g_getenv("http_proxy_user")) != NULL || (tmp = g_getenv("HTTPPROXYUSER")) != NULL) Index: util.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/util.c,v retrieving revision 1.298 retrieving revision 1.299 diff -u -d -p -r1.298 -r1.299 --- util.c 6 Jun 2004 19:06:22 -0000 1.298 +++ util.c 7 Jun 2004 04:00:59 -0000 1.299 @@ -39,6 +39,8 @@ typedef struct struct { + char *user; + char *passwd; char *address; int port; char *page; @@ -2388,18 +2390,21 @@ gaim_str_seconds_to_string(guint sec) */ gboolean gaim_url_parse(const char *url, char **ret_host, int *ret_port, - char **ret_path) + char **ret_path, char **ret_user, char **ret_passwd) { char scan_info[255]; char port_str[6]; int f; + const char *at; const char *turl; - char host[256], path[256]; + char host[256], path[256], user[256], passwd[256]; int port = 0; /* hyphen at end includes it in control set */ static char addr_ctrl[] = "A-Za-z0-9.-"; static char port_ctrl[] = "0-9"; static char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-"; + static char user_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-"; + static char passwd_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-"; g_return_val_if_fail(url != NULL, FALSE); @@ -2410,6 +2415,26 @@ gaim_url_parse(const char *url, char **r url = turl; } + /* parse out authentication information if supplied */ + if (at = strchr(url, '@')) { + g_snprintf(scan_info, sizeof(scan_info), + "%%255[%s]:%%255[%s]^@", user_ctrl, passwd_ctrl); + f = sscanf(url, scan_info, user, passwd); + + if (f ==1 ) { + /* No passwd, possibly just username supplied */ + g_snprintf(scan_info, sizeof(scan_info), + "%%255[%s]^@", user_ctrl); + f = sscanf(url, scan_info, user); + *passwd = '\0'; + } + + url = strdup(at+1); /* move pointer after the @ char */ + } else { + *user = '\0'; + *passwd = '\0'; + } + g_snprintf(scan_info, sizeof(scan_info), "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, page_ctrl); @@ -2432,6 +2457,8 @@ gaim_url_parse(const char *url, char **r if (ret_host != NULL) *ret_host = g_strdup(host); if (ret_port != NULL) *ret_port = port; if (ret_path != NULL) *ret_path = g_strdup(path); + if (ret_user != NULL) *ret_user = g_strdup(user); + if (ret_passwd != NULL) *ret_passwd = g_strdup(passwd); return TRUE; } @@ -2444,6 +2471,8 @@ destroy_fetch_url_data(GaimFetchUrlData if (gfud->user_agent != NULL) g_free(gfud->user_agent); if (gfud->website.address != NULL) g_free(gfud->website.address); if (gfud->website.page != NULL) g_free(gfud->website.page); + if (gfud->website.user != NULL) g_free(gfud->website.user); + if (gfud->website.passwd != NULL) g_free(gfud->website.passwd); g_free(gfud); } @@ -2700,7 +2729,7 @@ gaim_url_fetch(const char *url, gboolean gfud->full = full; gaim_url_parse(url, &gfud->website.address, &gfud->website.port, - &gfud->website.page); + &gfud->website.page, &gfud->website.user, &gfud->website.passwd); if ((sock = gaim_proxy_connect(NULL, gfud->website.address, gfud->website.port, url_fetched_cb, Index: util.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/util.h,v retrieving revision 1.55 retrieving revision 1.56 diff -u -d -p -r1.55 -r1.56 --- util.h 5 Jun 2004 07:33:58 -0000 1.55 +++ util.h 7 Jun 2004 04:00:59 -0000 1.56 @@ -576,7 +576,7 @@ char *gaim_str_seconds_to_string(guint s /*@{*/ /** - * Parses a URL, returning its host, port, and file path. + * Parses a URL, returning its host, port, file path, username and password. * * The returned data must be freed. * @@ -584,9 +584,11 @@ char *gaim_str_seconds_to_string(guint s * @param ret_host The returned host. * @param ret_port The returned port. * @param ret_path The returned path. + * @param ret_user The returned username. + * @param ret_passwd The returned password. */ gboolean gaim_url_parse(const char *url, char **ret_host, int *ret_port, - char **ret_path); + char **ret_path, char **ret_user, char **ret_passwd); /** * Fetches the data from a URL, and passes it to a callback function. |