static widget_handler_status_T push_add_button(struct dialog_data *dlg_data, struct widget_data *button) { struct listbox_data *box = get_dlg_listbox_data(dlg_data); struct terminal *term = dlg_data->win->term; struct cookie *new_cookie; struct cookie_server *server; if (!box->sel || !box->sel->udata) return EVENT_PROCESSED; if (box->sel->type == BI_FOLDER) { assert(box->sel->depth == 0); server = (struct cookie_server *)box->sel->udata; } else { struct cookie *cookie = (struct cookie *)box->sel->udata; server = cookie->server; } object_lock(server); /* ref consumed by init_cookie */ new_cookie = init_cookie(stracpy((const unsigned char *)"") /* name */, stracpy((const unsigned char *)"") /* value */, stracpy((const unsigned char *)"/") /* path */, stracpy(server->host) /* domain */, server); if (!new_cookie) return EVENT_PROCESSED; accept_cookie(new_cookie); build_edit_dialog(term, new_cookie); return EVENT_PROCESSED; }
/* Called by ok_dialog for the "OK" button in the "Add Server" dialog. * The data parameter points to the buffer used by the server name * widget. */ static void add_server_do(void *data) { unsigned char *value = (unsigned char *)data; struct cookie *dummy_cookie; if (!value) return; dummy_cookie = init_cookie(stracpy((const unsigned char *)"empty") /* name */, stracpy((const unsigned char *)"1") /* value */, stracpy((const unsigned char *)"/") /* path */, stracpy(value) /* domain */, get_cookie_server(value, strlen((const char *)value))); if (!dummy_cookie) return; accept_cookie(dummy_cookie); }
/* sezere 1 cookie z retezce str, na zacatku nesmi byt zadne whitechars * na konci muze byt strednik nebo 0 * cookie musi byt ve tvaru nazev=hodnota, kolem rovnase nesmi byt zadne mezery * (respektive mezery se budou pocitat do nazvu a do hodnoty) */ int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str) { int noval = 0; struct cookie *cookie; struct c_server *cs; unsigned char *p, *q, *s, *server, *date; d_opt = &dd_opt; int accept_cookies = dds.allow_cookies; if (accept_cookies == ACCEPT_NONE) { return 0; } for (p = str; *p != ';' && *p; p++) { /*if (WHITECHAR(*p)) return 0;*/ } for (q = str; *q != '='; q++) if (!*q || q >= p) { noval = 1; break; } if (str == q || q + 1 == p) return 0; cookie = mem_alloc(sizeof(struct cookie)); server = get_host_name(url); cookie->name = memacpy(str, q - str); cookie->value = !noval ? memacpy(q + 1, p - q - 1) : NULL; cookie->server = stracpy(server); date = parse_header_param(str, cast_uchar "expires", 0); if (date) { cookie->expires = parse_http_date(date); /* kdo tohle napsal a proc ?? */ /*if (! cookie->expires) cookie->expires++;*/ /* no harm and we can use zero then */ mem_free(date); } else cookie->expires = 0; if (!(cookie->path = parse_header_param(str, cast_uchar "path", 0))) { /*unsigned char *w;*/ cookie->path = stracpy(cast_uchar "/"); /* add_to_strn(&cookie->path, document); for (w = cookie->path; *w; w++) if (end_of_dir(cookie->path, *w)) { *w = 0; break; } for (w = cookie->path + strlen(cast_const_char cookie->path) - 1; w >= cookie->path; w--) if (*w == '/') { w[1] = 0; break; } */ } else { if (cookie->path[0] != '/') { add_to_strn(&cookie->path, cast_uchar "x"); memmove(cookie->path + 1, cookie->path, strlen(cast_const_char cookie->path) - 1); cookie->path[0] = '/'; } } if (!(cookie->domain = parse_header_param(str, cast_uchar "domain", 0))) cookie->domain = stracpy(server); if (cookie->domain[0] == '.') memmove(cookie->domain, cookie->domain + 1, strlen(cast_const_char cookie->domain)); if ((s = parse_header_param(str, cast_uchar "secure", 0))) { cookie->secure = 1; mem_free(s); } else cookie->secure = 0; if (check_domain_security(server, cookie->domain)) { mem_free(cookie->domain); cookie->domain = stracpy(server); } foreach (cs, c_servers) if (!strcasecmp(cast_const_char cs->server, cast_const_char server)) { if (cs->accpt) goto ok; else { free_cookie(cookie); mem_free(cookie); mem_free(server); return 0; } } if (accept_cookies != ACCEPT_ALL) { free_cookie(cookie); mem_free(cookie); mem_free(server); return 1; } ok: accept_cookie(cookie); mem_free(server); return 0; }
static void accept_cookie_in_msg_box(void *cookie_) { accept_cookie((struct cookie *) cookie_); }