From 4e0d5fd52a9825724abe9955f742b6ca53d6a438 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Fri, 3 Nov 2000 20:55:02 +0000 Subject: If show_pass, then base64 the password before writing it to the output 2000-11-03 Jeffrey Stedfast * camel-url.c (camel_url_to_string): If show_pass, then base64 the password before writing it to the output string. (camel_url_new): Assume password has been base64 encoded and decode accordingly. svn path=/trunk/; revision=6374 --- camel/ChangeLog | 7 +++++++ camel/camel-url.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) (limited to 'camel') diff --git a/camel/ChangeLog b/camel/ChangeLog index 026ee4605a..6c83938fe9 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,10 @@ +2000-11-03 Jeffrey Stedfast + + * camel-url.c (camel_url_to_string): If show_pass, then base64 the + password before writing it to the output string. + (camel_url_new): Assume password has been base64 encoded and + decode accordingly. + 2000-11-03 Dan Winship * camel-provider.h: Add an "url_flags" field to CamelProvider. diff --git a/camel/camel-url.c b/camel/camel-url.c index 04c84dc450..f78a4cefc2 100644 --- a/camel/camel-url.c +++ b/camel/camel-url.c @@ -34,6 +34,7 @@ #include #include #include "camel-url.h" +#include "camel-mime-utils.h" #include "camel-exception.h" #include "camel-object.h" @@ -69,7 +70,7 @@ camel_url_new (const char *url_string, CamelException *ex) CamelURL *url; char *semi, *colon, *at, *slash; char *p; - + /* Find protocol: initial substring until ":" */ colon = strchr (url_string, ':'); if (!colon) { @@ -78,7 +79,7 @@ camel_url_new (const char *url_string, CamelException *ex) url_string); return NULL; } - + url = g_new0 (CamelURL, 1); url->protocol = g_strndup (url_string, colon - url_string); g_strdown (url->protocol); @@ -115,8 +116,19 @@ camel_url_new (const char *url_string, CamelException *ex) if (at && (!slash || at < slash)) { colon = strchr (url_string, ':'); if (colon && colon < at) { - url->passwd = g_strndup (colon + 1, at - colon - 1); - camel_url_decode (url->passwd); + /* assume password is base64 encoded */ + int state = 0; int save = 0; + char *passwd; + int len; + + passwd = g_strndup (colon + 1, at - colon - 1); + camel_url_decode (passwd); + + len = strlen (passwd); + url->passwd = g_malloc (len); + len = base64_decode_step (passwd, len, url->passwd, &state, &save); + + url->passwd[len] = '\0'; } else { url->passwd = NULL; colon = at; @@ -183,16 +195,32 @@ camel_url_to_string (CamelURL *url, gboolean show_passwd) if (url->user) user = camel_url_encode (url->user, TRUE, ":;@/"); + if (url->authmech) authmech = camel_url_encode (url->authmech, TRUE, ":@/"); - if (show_passwd && url->passwd) - passwd = camel_url_encode (url->passwd, TRUE, "@/"); + + if (show_passwd && url->passwd) { + int state = 0, save = 0; + int len; + char *pass; + + len = strlen (url->passwd); + pass = g_malloc ((int)(len * 4 / 3) + 4); + len = base64_encode_close (url->passwd, len, FALSE, pass, &state, &save); + pass[len] = '\0'; + + passwd = camel_url_encode (pass, TRUE, "/"); + g_free (pass); + } + if (url->host) host = camel_url_encode (url->host, TRUE, ":/"); + if (url->port) g_snprintf (port, sizeof (port), "%d", url->port); else *port = '\0'; + if (url->path) path = camel_url_encode (url->path, FALSE, NULL); -- cgit v1.2.3