Commit e3349caa authored by David Woodhouse's avatar David Woodhouse

Add 'replace' argument to http_add_cookie()

For Juniper support we're going to want an option to add cookies only if
they don't already exist.
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 7c601276
......@@ -1277,7 +1277,7 @@ out:
vpninfo->csd_waiturl = NULL;
vpninfo->csd_scriptname = strdup(fname);
http_add_cookie(vpninfo, "sdesktop", vpninfo->csd_token);
http_add_cookie(vpninfo, "sdesktop", vpninfo->csd_token, 1);
return 0;
#endif /* !_WIN32 */
}
......
......@@ -280,8 +280,8 @@ int buf_free(struct oc_text_buf *buf)
* provided by their caller.
*/
int http_add_cookie(struct openconnect_info *vpninfo,
const char *option, const char *value)
int http_add_cookie(struct openconnect_info *vpninfo, const char *option,
const char *value, int replace)
{
struct oc_vpn_option *new, **this;
......@@ -307,6 +307,12 @@ int http_add_cookie(struct openconnect_info *vpninfo,
}
for (this = &vpninfo->cookies; *this; this = &(*this)->next) {
if (!strcmp(option, (*this)->option)) {
if (!replace) {
free(new->value);
free(new->option);
free(new);
return 0;
}
/* Replace existing cookie */
if (new)
new->next = (*this)->next;
......@@ -417,7 +423,7 @@ int process_http_response(struct openconnect_info *vpninfo, int connect,
vpn_progress(vpninfo, PRG_ERR,
_("SSL certificate authentication failed\n"));
ret = http_add_cookie(vpninfo, colon, equals);
ret = http_add_cookie(vpninfo, colon, equals, 1);
if (ret)
return ret;
} else {
......
......@@ -806,8 +806,8 @@ int internal_parse_url(const char *url, char **res_proto, char **res_host,
int do_https_request(struct openconnect_info *vpninfo, const char *method,
const char *request_body_type, struct oc_text_buf *request_body,
char **form_buf, int fetch_redirect);
int http_add_cookie(struct openconnect_info *vpninfo,
const char *option, const char *value);
int http_add_cookie(struct openconnect_info *vpninfo, const char *option,
const char *value, int replace);
int process_http_response(struct openconnect_info *vpninfo, int connect,
int (*header_cb)(struct openconnect_info *, char *, char *),
struct oc_text_buf *body);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment