[PATCH/RFC V3 08/13] auth: Provide information on which auth choice is currently selected

Kevin Cernekee cernekee at gmail.com
Sun Dec 15 01:42:59 EST 2013


In XML POST mode, the gateway keeps track of which authgroup is selected.
Provide this information to the UI so that the interface can be rendered
correctly.

Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
---
 auth.c                 |   21 +++++++++++++++++++++
 openconnect-internal.h |    1 +
 openconnect.h          |    2 ++
 3 files changed, 24 insertions(+)

diff --git a/auth.c b/auth.c
index e9dfb2f..2b08403 100644
--- a/auth.c
+++ b/auth.c
@@ -112,6 +112,17 @@ static int append_form_opts(struct openconnect_info *vpninfo,
 	return 0;
 }
 
+static int prop_equals(xmlNode *xml_node, const char *name, const char *value)
+{
+	char *tmp = (char *)xmlGetProp(xml_node, (unsigned char *)name);
+	int ret = 0;
+
+	if (tmp && !strcasecmp(tmp, value))
+		ret = 1;
+	free(tmp);
+	return ret;
+}
+
 /*
  * Maybe we should offer this choice to the user. So far we've only
  * ever seen it offer bogus choices though -- between certificate and
@@ -123,6 +134,7 @@ static int parse_auth_choice(struct openconnect_info *vpninfo, struct __oc_auth_
 			     xmlNode *xml_node)
 {
 	struct __oc_form_opt_select *opt;
+	int selection = 0;
 
 	opt = calloc(1, sizeof(*opt));
 	if (!opt)
@@ -167,6 +179,15 @@ static int parse_auth_choice(struct openconnect_info *vpninfo, struct __oc_auth_
 		choice->u.auth_type = (char *)xmlGetProp(xml_node, (unsigned char *)"auth-type");
 		choice->u.override_name = (char *)xmlGetProp(xml_node, (unsigned char *)"override-name");
 		choice->u.override_label = (char *)xmlGetProp(xml_node, (unsigned char *)"override-label");
+
+		if (prop_equals(xml_node, "selected", "true"))
+			selection = opt->nr_choices - 1;
+	}
+
+	if (!strcmp(opt->form.u.name, "group_list")) {
+		form->u.authgroup_field = opt->form.u.name;
+		form->u.authgroup_selection = selection;
+		form->authgroup_opt = opt;
 	}
 
 	/* We link the choice _first_ so it's at the top of what we present
diff --git a/openconnect-internal.h b/openconnect-internal.h
index c980ef8..1f52d5d 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -141,6 +141,7 @@ struct __oc_form_opt_select {
 struct __oc_auth_form {
 	struct oc_auth_form u;
 	struct __oc_form_opt *opts;
+	struct __oc_form_opt_select *authgroup_opt;
 };
 
 #define RECONNECT_INTERVAL_MIN	10
diff --git a/openconnect.h b/openconnect.h
index 8f601cb..18d31ae 100644
--- a/openconnect.h
+++ b/openconnect.h
@@ -134,6 +134,8 @@ struct oc_auth_form {
 	char *method;
 	char *action;
 	struct oc_form_opt *opts;
+	char *authgroup_field;
+	int authgroup_selection;
 };
 
 /****************************************************************************/
-- 
1.7.9.5




More information about the openconnect-devel mailing list