Skip to content

Commit

Permalink
Add 'replace' argument to http_add_cookie()
Browse files Browse the repository at this point in the history
For Juniper support we're going to want an option to add cookies only if
they don't already exist.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jan 26, 2015
1 parent 7c60127 commit e3349ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion auth.c
Expand Up @@ -1277,7 +1277,7 @@ static int run_csd_script(struct openconnect_info *vpninfo, char *buf, int bufle
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 */
}
Expand Down
12 changes: 9 additions & 3 deletions http.c
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions openconnect-internal.h
Expand Up @@ -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);
Expand Down

0 comments on commit e3349ca

Please sign in to comment.