[Spice-devel] [PATCHv3 spice-gtk 04/14] proxy: parse user and pass from uri
Christophe Fergeau
cfergeau at redhat.com
Thu Feb 20 06:32:04 PST 2014
On Mon, Feb 17, 2014 at 10:35:43PM +0100, Marc-André Lureau wrote:
> ---
> gtk/spice-proxy.c | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/gtk/spice-proxy.c b/gtk/spice-proxy.c
> index 7711e83..8613469 100644
> --- a/gtk/spice-proxy.c
> +++ b/gtk/spice-proxy.c
> @@ -19,6 +19,7 @@
> #include <stdlib.h>
> #include <string.h>
>
> +#include "glib-compat.h"
> #include "spice-client.h"
> #include "spice-proxy.h"
>
> @@ -78,6 +79,18 @@ gboolean spice_proxy_parse(SpiceProxy *self, const gchar *proxyuri, GError **err
> spice_proxy_set_protocol(self, "http");
> spice_proxy_set_port(self, 3128);
>
> + /* yes, that parser is bad, we need GUri... */
> + if (strstr(uri, "@")) {
> + gchar *saveptr, *saveptr2;
> + gchar *next = strstr(uri, "@") + 1;
> + gchar *auth = strtok_r(uri, "@", &saveptr);
> + const gchar *user = strtok_r(auth, ":", &saveptr2);
> + const gchar *pass = strtok_r(NULL, ":", &saveptr2);
> + spice_proxy_set_user(self, user);
> + spice_proxy_set_password(self, pass);
> + uri = next;
> + }
> +
> /* max 2 parts, host:port */
> gchar **proxyv = g_strsplit(uri, ":", 2);
> const gchar *proxy_port = NULL;
> @@ -303,7 +316,14 @@ gchar* spice_proxy_to_string(SpiceProxy* self)
> if (p->protocol == NULL || p->hostname == NULL)
> return NULL;
>
> - return g_strdup_printf("%s://%s:%u", p->protocol, p->hostname, p->port);
> + if (p->user || p->password)
> + return g_strdup_printf("%s://%s:%s@%s:%u",
> + p->protocol,
> + p->user, p->password,
> + p->hostname, p->port);
> + else
> + return g_strdup_printf("%s://%s:%u",
> + p->protocol, p->hostname, p->port);
> }
I would have expected this hunk to be in the previous patch (the one
introducing the password/username properties), but I can live with it being
part of this patch.
ACK
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20140220/0ba287b4/attachment.pgp>
More information about the Spice-devel
mailing list