Skip to content

Commit

Permalink
define openconnect_set_option_value() to set the value in oc_form_opt
Browse files Browse the repository at this point in the history
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
Nikos Mavrogiannopoulos authored and David Woodhouse committed Oct 9, 2014
1 parent 1915437 commit 19fbe2e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
22 changes: 22 additions & 0 deletions auth.c
Expand Up @@ -42,6 +42,28 @@ static int can_gen_tokencode(struct openconnect_info *vpninfo,
struct oc_auth_form *form, struct oc_form_opt *opt);
static int do_gen_tokencode(struct openconnect_info *vpninfo, struct oc_auth_form *form);

int openconnect_set_option_value(struct oc_form_opt *opt, const char *value)
{
if (opt->type == OC_FORM_OPT_SELECT) {
struct oc_form_opt_select *sopt = (void *)opt;
int i;

for (i=0; i<sopt->nr_choices; i++) {
if (value == sopt->choices[i]->name) {
opt->value = sopt->choices[i]->name;
return 0;
}
}
return -EINVAL;
}

opt->value = strdup(value);
if (!opt->value)
return -ENOMEM;

return 0;
}

static int append_opt(struct oc_text_buf *body, char *opt, char *name)
{
if (buf_error(body))
Expand Down
1 change: 1 addition & 0 deletions libopenconnect.map.in
@@ -1,5 +1,6 @@
OPENCONNECT_4.0 {
global:
openconnect_set_option_value;
openconnect_clear_cookie;
openconnect_get_cert_sha1;
openconnect_get_cookie;
Expand Down
12 changes: 8 additions & 4 deletions openconnect.h
Expand Up @@ -34,6 +34,7 @@
/*
* API version 4.0:
* - Change string handling to never transfer ownership of allocations.
* - Add openconnect_set_option_value()
*
* API version 3.4:
* - Add openconnect_set_token_callbacks()
Expand Down Expand Up @@ -144,19 +145,22 @@
#define OC_FORM_OPT_NUMERIC 0x0002

/* 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
interacting with the user and must be freed. */
freed by the form handling code except for value, which for TEXT
and PASSWORD options is allocated by openconnect_set_option_value()
when process_form() interacts with the user and must be freed. */
struct oc_form_opt {
struct oc_form_opt *next;
int type;
char *name;
char *label;
char *value;
char *value; /* Use openconnect_set_option_value() to set this */
unsigned int flags;
void *reserved;
};

/* To set the value to a form use the following function */
int openconnect_set_option_value(struct oc_form_opt *opt, const char *value);

/* All fields are static, owned by the XML parser */
struct oc_choice {
char *name;
Expand Down

0 comments on commit 19fbe2e

Please sign in to comment.