Use redirect handling for form action and csd
authorDavid Woodhouse <David.Woodhouse@intel.com>
Tue, 21 Jul 2009 08:20:14 +0000 (09:20 +0100)
committerAdam Piątyszek <ediap@users.sourceforge.net>
Tue, 4 Aug 2009 12:05:50 +0000 (14:05 +0200)
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
auth.c
http.c

diff --git a/auth.c b/auth.c
index 442ab7d..6a163f1 100644 (file)
--- a/auth.c
+++ b/auth.c
@@ -348,8 +348,7 @@ int parse_xml_response(struct openconnect_info *vpninfo, char *response,
                                ret = -EINVAL;
                                goto out;
                        }
-                       free(vpninfo->urlpath);
-                       vpninfo->urlpath = strdup(form->action+1);
+                       vpninfo->redirect_url = strdup(form->action);
 
                        ret = parse_form(vpninfo, form, xml_node, request_body, req_len);
                        if (ret < 0)
@@ -372,9 +371,7 @@ int parse_xml_response(struct openconnect_info *vpninfo, char *response,
        }
        if (vpninfo->csd_token && vpninfo->csd_ticket && vpninfo->csd_starturl && vpninfo->csd_waiturl) {
                /* First, redirect to the stuburl -- we'll need to fetch and run that */
-               free(vpninfo->urlpath);
-               vpninfo->urlpath = strdup(vpninfo->csd_stuburl +
-                                         (vpninfo->csd_stuburl[0] == '/' ? 1 : 0));
+               vpninfo->redirect_url = vpninfo->csd_stuburl;
                ret = 0;
                goto out;
        }
diff --git a/http.c b/http.c
index 915b1f8..59db98f 100644 (file)
--- a/http.c
+++ b/http.c
@@ -398,6 +398,7 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo)
        }
 
        if (result != 200 && vpninfo->redirect_url) {
+       redirect:
                if (!strncmp(vpninfo->redirect_url, "https://", 8)) {
                        /* New host. Tear down the existing connection and make a new one */
                        char *host = vpninfo->redirect_url + 8;
@@ -461,7 +462,7 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo)
        result = parse_xml_response(vpninfo, buf, request_body, sizeof(request_body),
                                    &method, &request_body_type);
        if (!result)
-               goto retry;
+               goto redirect;
 
        if (result != 2)
                return result;