Attempt form handling
authorDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 1 Oct 2008 12:17:20 +0000 (13:17 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 1 Oct 2008 12:17:20 +0000 (13:17 +0100)
http.c

diff --git a/http.c b/http.c
index c53932c..ebd63b9 100644 (file)
--- a/http.c
+++ b/http.c
@@ -242,10 +242,19 @@ int process_http_response(struct anyconnect_info *vpninfo, int *result,
                close(vpninfo->ssl_fd);
                vpninfo->ssl_fd = -1;
        }
-
+       body[done] = 0;
        return done;
 }
 
+int parse_form(struct anyconnect_info *vpninfo, xmlNode *xml_node, char *body)
+{
+       char *username = "lalala";
+
+       sprintf(body, "group_list=Layer3_ACE&username=%s&password=%s",
+               username, vpninfo->tpmpass);
+       return -EINVAL;
+}
+
 int obtain_cookie(struct anyconnect_info *vpninfo)
 {
        struct vpn_option *opt, *next;
@@ -358,6 +367,37 @@ int obtain_cookie(struct anyconnect_info *vpninfo)
                return -EINVAL;
        }
 
+
+       for (xml_node = xml_node->children; xml_node; xml_node = xml_node->next) {
+               if (xml_node->type != XML_ELEMENT_NODE)
+                       continue;
+
+               if (!strcmp((char *)xml_node->name, "message"))
+                       printf("%s\n", xmlNodeGetContent(xml_node));
+               else if (!strcmp((char *)xml_node->name, "error")) {
+                       printf("%s\n", xmlNodeGetContent(xml_node));
+                       return -EINVAL;
+               } else if (!strcmp((char *)xml_node->name, "form")) {
+                       char *form_method, *form_action;
+                       form_method = (char *)xmlGetProp(xml_node, (unsigned char *)"method");
+                       form_action = (char *)xmlGetProp(xml_node, (unsigned char *)"action");
+                       if (strcasecmp(form_method, "POST")) {
+                               fprintf(stderr, "Cannot handle form method '%s'\n",
+                                       form_method);
+                               return -EINVAL;
+                       }
+                       method = "POST";
+                       free(vpninfo->urlpath);
+                       vpninfo->urlpath = strdup(form_action);
+                       if (verbose)
+                               printf("WILL POST: %s %s\n", form_method, form_action);
+                       request_body_type = "application/x-www-form-urlencoded";
+                       
+                       if (parse_form(vpninfo, xml_node, request_body))
+                               return -EINVAL;
+                       goto retry;
+               }
+       }
        xmlFreeDoc(xml_doc);
 
        for (opt = vpninfo->cookies; opt; opt = opt->next) {