[PATCH/RFC V3 03/13] library: Use named constants for process_auth_form() return value

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


Currently we have 3 valid results, and we're about to add a fourth.

Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
---
 auth.c        |   12 ++++++------
 http.c        |    4 ++--
 main.c        |    4 ++--
 openconnect.h |    5 +++++
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/auth.c b/auth.c
index b6b9698..17f80ef 100644
--- a/auth.c
+++ b/auth.c
@@ -581,9 +581,9 @@ int parse_xml_response(struct openconnect_info *vpninfo, char *response, struct
 
 /* Return value:
  *  < 0, on error
- *  = 0, when form parsed and POST required
- *  = 1, when response was cancelled by user
- *  = 2, when form indicates that login was already successful
+ *  = OC_FORM_RESULT_OK (0), when form parsed and POST required
+ *  = OC_FORM_RESULT_CANCELLED, when response was cancelled by user
+ *  = __OC_FORM_RESULT_LOGGEDIN, when form indicates that login was already successful
  */
 int handle_auth_form(struct openconnect_info *vpninfo, struct oc_auth_form *form,
 		     char *request_body, int req_len, const char **method,
@@ -593,7 +593,7 @@ int handle_auth_form(struct openconnect_info *vpninfo, struct oc_auth_form *form
 	struct vpn_option *opt, *next;
 
 	if (!strcmp(form->auth_id, "success"))
-		return 2;
+		return __OC_FORM_RESULT_LOGGEDIN;
 
 	if (vpninfo->nopasswd) {
 		vpn_progress(vpninfo, PRG_ERR,
@@ -611,7 +611,7 @@ int handle_auth_form(struct openconnect_info *vpninfo, struct oc_auth_form *form
 			free(opt);
 		}
 		vpninfo->cookies = NULL;
-		return 0;
+		return OC_FORM_RESULT_OK;
 	}
 	if (!form->opts) {
 		if (form->message)
@@ -625,7 +625,7 @@ int handle_auth_form(struct openconnect_info *vpninfo, struct oc_auth_form *form
 		ret = vpninfo->process_auth_form(vpninfo->cbdata, form);
 	else {
 		vpn_progress(vpninfo, PRG_ERR, _("No form handler; cannot authenticate.\n"));
-		ret = 1;
+		ret = OC_FORM_RESULT_CANCELLED;
 	}
 	if (ret)
 		return ret;
diff --git a/http.c b/http.c
index 3a5c2c6..fa803c5 100644
--- a/http.c
+++ b/http.c
@@ -1181,9 +1181,9 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo)
 		request_body[0] = 0;
 		result = handle_auth_form(vpninfo, form, request_body, sizeof(request_body),
 					  &method, &request_body_type);
-		if (result < 0 || result == 1)
+		if (result < 0 || result == OC_FORM_RESULT_CANCELLED)
 			goto out;
-		if (result == 2)
+		if (result == __OC_FORM_RESULT_LOGGEDIN)
 			break;
 
 		result = do_https_request(vpninfo, method, request_body_type, request_body,
diff --git a/main.c b/main.c
index e0114d2..16c1824 100644
--- a/main.c
+++ b/main.c
@@ -1247,7 +1247,7 @@ static int process_auth_form(void *_vpninfo,
 		password = NULL;
 	}
 
-	return 0;
+	return OC_FORM_RESULT_OK;
 
  err:
 	for (opt = form->opts; opt; opt = opt->next) {
@@ -1257,7 +1257,7 @@ static int process_auth_form(void *_vpninfo,
 			opt->value = NULL;
 		}
 	}
-	return -EINVAL;
+	return OC_FORM_RESULT_ERR;
 }
 
 static void init_token(struct openconnect_info *vpninfo,
diff --git a/openconnect.h b/openconnect.h
index d48bc25..8f601cb 100644
--- a/openconnect.h
+++ b/openconnect.h
@@ -93,6 +93,11 @@
 #define OC_FORM_OPT_HIDDEN	4
 #define OC_FORM_OPT_TOKEN	5
 
+#define OC_FORM_RESULT_ERR		-1
+#define OC_FORM_RESULT_OK		0
+#define OC_FORM_RESULT_CANCELLED	1
+#define __OC_FORM_RESULT_LOGGEDIN	255	/* internal library use only */
+
 /* char * fields are static (owned by XML parser) and don't need to be
    freed by the form handling code -- except for value, which for TEXT
    and PASSWORD options is allocated by process_form() when
-- 
1.7.9.5




More information about the openconnect-devel mailing list