* provided by their caller.
*/
+int http_add_cookie(struct openconnect_info *vpninfo, const char *option, const char *value)
+{
+ struct vpn_option *new, **this;
+
+ if (*value) {
+ new = malloc(sizeof(*new));
+ if (!new) {
+ vpninfo->progress(vpninfo, PRG_ERR, "No memory for allocating cookies\n");
+ return -ENOMEM;
+ }
+ new->next = NULL;
+ new->option = strdup(option);
+ new->value = strdup(value);
+ } else {
+ /* Kill cookie; don't replace it */
+ new = NULL;
+ }
+ for (this = &vpninfo->cookies; *this; this = &(*this)->next) {
+ if (!strcmp(option, (*this)->option)) {
+ /* Replace existing cookie */
+ if (new)
+ new->next = (*this)->next;
+ else
+ new = (*this)->next;
+
+ free((*this)->option);
+ free((*this)->value);
+ free(*this);
+ *this = new;
+ break;
+ }
+ }
+ if (new && !*this) {
+ *this = new;
+ new->next = NULL;
+ }
+ return 0;
+}
+
static int process_http_response(struct openconnect_info *vpninfo, int *result,
int (*header_cb)(struct openconnect_info *, char *, char *),
char *body, int buf_len)
}
}
if (!strcmp(buf, "Set-Cookie")) {
- struct vpn_option *new, **this;
char *semicolon = strchr(colon, ';');
char *equals = strchr(colon, '=');
+ int ret;
if (semicolon)
*semicolon = 0;
}
*(equals++) = 0;
- if (*equals) {
- new = malloc(sizeof(*new));
- if (!new) {
- vpninfo->progress(vpninfo, PRG_ERR, "No memory for allocating cookies\n");
- return -ENOMEM;
- }
- new->next = NULL;
- new->option = strdup(colon);
- new->value = strdup(equals);
- } else {
- /* Kill cookie; don't replace it */
- new = NULL;
- }
- for (this = &vpninfo->cookies; *this; this = &(*this)->next) {
- if (!strcmp(colon, (*this)->option)) {
- /* Replace existing cookie */
- if (new)
- new->next = (*this)->next;
- else
- new = (*this)->next;
-
- free((*this)->option);
- free((*this)->value);
- free(*this);
- *this = new;
- break;
- }
- }
- if (new && !*this) {
- *this = new;
- new->next = NULL;
- }
+ ret = http_add_cookie(vpninfo, colon, equals);
+ if (ret)
+ return ret;
}
if (!strcmp(buf, "Transfer-Encoding")) {
if (!strcmp(colon, "chunked"))
vpninfo->csd_waiturl = NULL;
vpninfo->csd_scriptname = strdup(fname);
- /* AB: add cookie "sdesktop=__TOKEN__" */
- {
- struct vpn_option *new, **this;
- new = malloc(sizeof(*new));
- if (!new) {
- vpninfo->progress(vpninfo, PRG_ERR, "No memory for allocating cookies\n");
- return -ENOMEM;
- }
- new->next = NULL;
- new->option = strdup("sdesktop");
- new->value = strdup(vpninfo->csd_token);
-
- for (this = &vpninfo->cookies; *this; this = &(*this)->next) {
- if (!strcmp(new->option, (*this)->option)) {
- /* Replace existing cookie */
- if (new)
- new->next = (*this)->next;
- else
- new = (*this)->next;
-
- free((*this)->option);
- free((*this)->value);
- free(*this);
- *this = new;
- break;
- }
- }
- if (new && !*this) {
- *this = new;
- new->next = NULL;
- }
- }
+ http_add_cookie(vpninfo, "sdesktop", vpninfo->csd_token);
+
return 0;
}