[PATCH] Proxy Authorization

4 views
Skip to first unread message

David Geary

unread,
Jul 1, 2009, 10:34:36 AM7/1/09
to msn-pecan
---
io/pecan_http_server.c | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/io/pecan_http_server.c b/io/pecan_http_server.c
index bf085ef..11ca93c 100644
--- a/io/pecan_http_server.c
+++ b/io/pecan_http_server.c
@@ -753,6 +753,23 @@ foo_write (PecanNode *conn,
gchar *auth = NULL;
gchar *session_id;

+ /*get proxy auth info and set up proxy auth header*/
+ PurpleProxyInfo *gpi = NULL;
+ char *tmp = NULL;
+ gpi = purple_proxy_get_setup(msn_session_get_user_data(conn-
>session));
+ if (gpi == NULL)
+ {
+ auth = g_strdup_printf("");
+ }
+ else
+ {
+ auth = g_strdup_printf("%s:%s",purple_proxy_info_get_username
(gpi),purple_proxy_info_get_password(gpi));
+ tmp = purple_base64_encode((const guchar *)auth, strlen(auth));
+ g_free(auth);
+ auth = g_strdup_printf("Proxy-Authorization: Basic %s\r\n", tmp);
+ g_free(tmp);
+ }
+
session_id = prev->foo_data;

if (session_id)
--
1.6.0.4

Felipe Contreras

unread,
Jul 1, 2009, 10:42:27 AM7/1/09
to David Geary, msn-pecan
On Wed, Jul 1, 2009 at 5:34 PM, David Geary<bianca...@gmail.com> wrote:
>
> ---
>  io/pecan_http_server.c |   17 +++++++++++++++++
>  1 files changed, 17 insertions(+), 0 deletions(-)
>
> diff --git a/io/pecan_http_server.c b/io/pecan_http_server.c
> index bf085ef..11ca93c 100644
> --- a/io/pecan_http_server.c
> +++ b/io/pecan_http_server.c
> @@ -753,6 +753,23 @@ foo_write (PecanNode *conn,
>         gchar *auth = NULL;
>         gchar *session_id;
>
> +       /*get proxy auth info and set up proxy auth header*/
> +       PurpleProxyInfo *gpi = NULL;
> +       char *tmp = NULL;
> +       gpi = purple_proxy_get_setup(msn_session_get_user_data(conn-
>>session));
> +       if (gpi == NULL)
> +       {
> +               auth = g_strdup_printf("");

What's wrong with leaving auth NULL?

> +       }
> +       else
> +       {
> +               auth = g_strdup_printf("%s:%s",purple_proxy_info_get_username
> (gpi),purple_proxy_info_get_password(gpi));

What happens if purple_proxy_info_get_password returns NULL. I fear
the same about purple_proxy_info_get_username, but I guess there is no
point in purple_proxy_get_setup returning something if there's no
user, right?

Otherwise looks good :)

Can you update the patch with these comments?

--
Felipe Contreras

Frasten

unread,
Jul 1, 2009, 10:42:35 AM7/1/09
to msn-pecan
> +               g_free(auth);
Shouldn't auth be freed after the if/else construct?

--
Frasten

Felipe Contreras

unread,
Jul 1, 2009, 10:46:52 AM7/1/09
to Frasten, msn-pecan
On Wed, Jul 1, 2009 at 5:42 PM, Frasten<fra...@gmail.com> wrote:
>
>> +               g_free(auth);
> Shouldn't auth be freed after the if/else construct?

Good point. But not there, it should be freed after it's used here:

header = g_strdup_printf ("POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n"

Then it's not needed any more.

--
Felipe Contreras

David Geary

unread,
Jul 1, 2009, 10:48:07 AM7/1/09
to msn-pecan
On Jul 2, 12:42 am, Frasten <fras...@gmail.com> wrote:
> > +               g_free(auth);
>
> Shouldn't auth be freed after the if/else construct?

auth only gets freed here because it is to be reused on the next line

> --
> Frasten

David Geary

unread,
Jul 1, 2009, 11:48:42 AM7/1/09
to msn-pecan
---
io/pecan_http_server.c | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/io/pecan_http_server.c b/io/pecan_http_server.c
index bf085ef..2fe5b7f 100644
--- a/io/pecan_http_server.c
+++ b/io/pecan_http_server.c
@@ -753,6 +753,25 @@ foo_write (PecanNode *conn,
gchar *auth = NULL;
gchar *session_id;

+ /*get proxy auth info and set up proxy auth header*/
+ PurpleProxyInfo *gpi = NULL;
+ char *tmp = NULL;
+ const char *username = NULL, *password = NULL;
+ gpi = purple_proxy_get_setup(msn_session_get_user_data(conn-
>session));
+ if (gpi != NULL)
+ {
+ username = purple_proxy_info_get_username(gpi);
+ password = purple_proxy_info_get_password(gpi);
+ if (username || password)
+ {
+ auth = g_strdup_printf("%s:%s", username ? username : "",
password ? password : "");
+ tmp = purple_base64_encode((const guchar *)auth, strlen(auth));
+ g_free(auth);
+ auth = g_strdup_printf("Proxy-Authorization: Basic %s\r\n", tmp);
+ g_free(tmp);
+ }
+ }
+
session_id = prev->foo_data;

if (session_id)
@@ -786,6 +805,10 @@ foo_write (PecanNode *conn,
count);

g_free (params);
+ if (auth)
+ {
+ g_free(auth);
+ }

#ifdef PECAN_DEBUG_HTTP
pecan_debug ("header=[%s]", header);
--
1.6.0.4


On Jul 2, 12:42 am, Felipe Contreras <felipe.contre...@gmail.com>
wrote:
> On Wed, Jul 1, 2009 at 5:34 PM, David Geary<bianca.ura...@gmail.com> wrote:
>
> > ---
> >  io/pecan_http_server.c |   17 +++++++++++++++++
> >  1 files changed, 17 insertions(+), 0 deletions(-)
>
> > diff --git a/io/pecan_http_server.c b/io/pecan_http_server.c
> > index bf085ef..11ca93c 100644
> > --- a/io/pecan_http_server.c
> > +++ b/io/pecan_http_server.c
> > @@ -753,6 +753,23 @@ foo_write (PecanNode *conn,
> >         gchar *auth = NULL;
> >         gchar *session_id;
>
> > +       /*get proxy auth info and set up proxy auth header*/
> > +       PurpleProxyInfo *gpi = NULL;
> > +       char *tmp = NULL;
> > +       gpi = purple_proxy_get_setup(msn_session_get_user_data(conn-
> >>session));
> > +       if (gpi == NULL)
> > +       {
> > +               auth = g_strdup_printf("");
>
> What's wrong with leaving auth NULL?

Nothing

> > +       }
> > +       else
> > +       {
> > +               auth = g_strdup_printf("%s:%s",purple_proxy_info_get_username
> > (gpi),purple_proxy_info_get_password(gpi));
>
> What happens if purple_proxy_info_get_password returns NULL. I fear
> the same about purple_proxy_info_get_username, but I guess there is no
> point in purple_proxy_get_setup returning something if there's no
> user, right?

Worth putting a check in

> Otherwise looks good :)
>
> Can you update the patch with these comments?

See above

Any further comments?

>
> --
> Felipe Contreras

Felipe Contreras

unread,
Jul 1, 2009, 6:01:49 PM7/1/09
to David Geary, msn-pecan
On Wed, Jul 1, 2009 at 6:48 PM, David Geary<bianca...@gmail.com> wrote:
>
> ---
>  io/pecan_http_server.c |   23 +++++++++++++++++++++++
>  1 files changed, 23 insertions(+), 0 deletions(-)
>
> diff --git a/io/pecan_http_server.c b/io/pecan_http_server.c
> index bf085ef..2fe5b7f 100644
> --- a/io/pecan_http_server.c
> +++ b/io/pecan_http_server.c
> @@ -753,6 +753,25 @@ foo_write (PecanNode *conn,
>         gchar *auth = NULL;
>         gchar *session_id;
>
> +       /*get proxy auth info and set up proxy auth header*/

Codestyle:
/* get proxy auth info and set up proxy auth header */

> +       PurpleProxyInfo *gpi = NULL;

Codestyle; declarations go in the beginning of the block. I'll send a
proposal separately.

> +       char *tmp = NULL;
> +       const char *username = NULL, *password = NULL;
> +       gpi = purple_proxy_get_setup(msn_session_get_user_data(conn-
>>session));
> +       if (gpi != NULL)

Codestyle:
+ if (gpi)

> +       {
> +               username = purple_proxy_info_get_username(gpi);
> +               password = purple_proxy_info_get_password(gpi);
> +               if (username || password)
> +               {
> +                       auth = g_strdup_printf("%s:%s", username ? username : "",
> password ? password : "");
> +                       tmp = purple_base64_encode((const guchar *)auth, strlen(auth));
> +                       g_free(auth);
> +                       auth = g_strdup_printf("Proxy-Authorization: Basic %s\r\n", tmp);
> +                       g_free(tmp);
> +               }
> +       }
> +
>         session_id = prev->foo_data;
>
>         if (session_id)
> @@ -786,6 +805,10 @@ foo_write (PecanNode *conn,
>                                   count);
>
>         g_free (params);
> +       if (auth)
> +       {
> +               g_free(auth);
> +       }

g_free can receive NULL, no need for the check.

>  #ifdef PECAN_DEBUG_HTTP
>         pecan_debug ("header=[%s]", header);
> --
> 1.6.0.4

--
Felipe Contreras

Felipe Contreras

unread,
Jul 1, 2009, 6:17:09 PM7/1/09
to msn-...@googlegroups.com, David Geary
From: David Geary <bianca...@gmail.com>

---
io/pecan_http_server.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/io/pecan_http_server.c b/io/pecan_http_server.c
index dd98984..4cc7157 100644
--- a/io/pecan_http_server.c
+++ b/io/pecan_http_server.c
@@ -727,6 +727,27 @@ foo_write (PecanNode *conn,


gchar *auth = NULL;
gchar *session_id;

+ /* get proxy auth info and set up proxy auth header */
+ {
+ PurpleProxyInfo *gpi;


+ gpi = purple_proxy_get_setup(msn_session_get_user_data(conn->session));

+ if (gpi)
+ {
+ const char *username, *password;


+ username = purple_proxy_info_get_username(gpi);
+ password = purple_proxy_info_get_password(gpi);
+ if (username || password)
+ {

+ char *tmp;


+ auth = g_strdup_printf("%s:%s", username ? username : "", password ? password : "");
+ tmp = purple_base64_encode((const guchar *)auth, strlen(auth));
+ g_free(auth);
+ auth = g_strdup_printf("Proxy-Authorization: Basic %s\r\n", tmp);
+ g_free(tmp);
+ }
+ }
+ }
+
session_id = prev->foo_data;

if (session_id)

@@ -760,6 +781,7 @@ foo_write (PecanNode *conn,
count);

g_free (params);
+ g_free (auth);



#ifdef PECAN_DEBUG_HTTP
pecan_debug ("header=[%s]", header);
--

1.6.3.3

Felipe Contreras

unread,
Jul 5, 2009, 5:43:05 AM7/5/09
to msn-...@googlegroups.com, David Geary
On Thu, Jul 2, 2009 at 1:17 AM, Felipe
Contreras<felipe.c...@gmail.com> wrote:
> From: David Geary <bianca...@gmail.com>

Since there was no comments I guess it was ok. Pushed, thanks :)

--
Felipe Contreras

Reply all
Reply to author
Forward
0 new messages