92 p = gw_malloc(
sizeof(
Cookie));
125 info (0,
"No session machine for cookie retrieval");
129 for (pos = 0; pos <
gwlist_len(headers); pos++) {
145 debug(
"wap.wsp.http", 0,
"parse_cookie: Cookie present");
150 debug(
"wap.wsp.http", 0,
"get_cookies: Added (%s)",
157 debug(
"wap.wsp.http", 0,
"get_cookies: End");
168 if (headers == NULL || sm == NULL) {
169 error (0,
"set_cookies: Null argument(s) - no headers, WSPMachine or both");
178 debug(
"wap.wsp.http", 0,
"set_cookies: Cookies in cache");
180 for (pos = 0; pos <
gwlist_len(sm->cookies); pos++) {
203 debug(
"wap.wsp.http", 0,
"set_cookies: No cookies in cache");
223 if (header == NULL) {
224 error(0,
"get_header_value: NULL argument");
256 if (cookiestr == NULL) {
257 error(0,
"parse_cookie: NULL argument");
267 while (isspace((
int)*p)) p++;
269 if (strncasecmp(
"version", p, 7) == 0)
271 else if (strncasecmp(
"path", p, 4) == 0)
273 else if (strncasecmp(
"domain", p, 6) == 0)
277 else if (strncasecmp(
"max-age", p, 7) == 0) {
278 c -> max_age = atol(strrchr (p,
'=') + 1);
279 p = strtok(NULL,
";");
282 else if (strncasecmp(
"expires", p, 7) == 0) {
286 p = strtok(NULL,
";");
289 else if (strncasecmp(
"comment", p, 7) == 0 ) {
290 p = strtok(NULL,
";");
293 else if (strncasecmp(
"secure", p, 6) == 0 ) {
294 p = strtok(NULL,
";");
300 if ((equals = strchr(p,
'=')) != NULL) {
306 error(0,
"parse_cookie: Bad name=value cookie component (%s)", p);
310 p = strtok(NULL,
";");
315 error(0,
"parse_cookie: Duplicate cookie field (%s), discarding", p);
316 p = strtok(NULL,
";");
322 p = strtok(NULL,
";");
366 if (cookies == NULL || cookie == NULL) {
367 error(0,
"have_cookie: Null argument(s) - no Cookie list, Cookie or both");
376 debug (
"wap.wsp.http", 0,
"have_cookie: Comparing name (%s:%s), path (%s:%s), domain (%s:%s)",
383 (value->
name == NULL ||
385 (value->
path == NULL ||
397 debug(
"wap.wsp.http", 0,
"have_cookie: Discarding expired cookie (%s)",
402 debug(
"wap.wsp.http", 0,
"have_cookie: Updating cached cookie (%s)",
425 if (cookies == NULL) {
426 error(0,
"expire_cookies: Null argument(s) - no Cookie list");
435 debug(
"wap.wsp.http", 0,
"expire_cookies: Cookies in cache");
436 for (pos = 0; pos <
gwlist_len(cookies); pos++) {
442 debug(
"wap.wsp.http", 0,
"expire_cookies: Expired cookie (%s)",
450 debug(
"wap.wsp.http", 0,
"expire_cookies: No cookies in cache");
470 debug(
"wap.wsp.http", 0,
"cookie_destroy: Destroyed cookie");
504 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
505 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec", NULL
510 const char **p = &
months[0];
514 if (strcmp(s, *p) == 0)
531 memset(&ti, 0,
sizeof(
struct tm));
534 if (!(
date = strchr(expires,
'='))) {
535 error(0,
"parse_http_date: Bogus expires type=value header (%s)", expires);
539 while (isspace((
int)*
date))
544 if (!(p = strchr (
date,
' '))) {
545 error(0,
"parse_http_date: Bogus date string (%s)",
date);
548 while (isspace((
int)*p))
556 if (isalpha((
int)*p)) {
558 sscanf(p, (strstr(p,
"DST") ?
"%s %d %d:%d:%d %*s %d" :
"%s %d %d:%d:%d %d"),
559 month, &ti.tm_mday, &ti.tm_hour, &ti.tm_min,
560 &ti.tm_sec, &ti.tm_year);
563 }
else if (p[2] ==
'-') {
567 sscanf(p,
"%s %d:%d:%d", buf, &ti.tm_hour, &ti.tm_min, &ti.tm_sec);
569 ti.tm_mday = atoi(buf);
572 strcpy(month, &buf[3]);
573 ti.tm_year = atoi(&buf[7]);
577 if (ti.tm_year < 70) {
579 }
else if (ti.tm_year > 1900) {
584 sscanf(p,
"%d %s %d %d:%d:%d",&ti.tm_mday, month, &ti.tm_year,
585 &ti.tm_hour, &ti.tm_min, &ti.tm_sec);
595 if (ti.tm_mon == -1) {
596 error(0,
"parse_http_date () failed on bad month value (%s)", month);
607 error(0,
"parse_http_date(): mktime() was unable to resolve date/time: %s",
612 debug(
"parse_http_date", 0,
"Parsed date (%s) as: %s",
date, asctime(&ti));
622 error(0,
"parse_http_date () Expiry time (%s) (delta=%ld) is in the past !",
623 asctime(&ti), rv-now);
int get_cookies(List *headers, const WSPMachine *sm)
void error(int err, const char *fmt,...)
void info(int err, const char *fmt,...)
gw_assert(wtls_machine->packet_to_send !=NULL)
static int month_index(const char *s)
void gwlist_append(List *list, void *item)
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
long gwlist_len(List *list)
static const char * months[]
void * gwlist_get(List *list, long pos)
void octstr_append_char(Octstr *ostr, int ch)
void octstr_append_cstr(Octstr *ostr, const char *cstr)
void octstr_strip_blanks(Octstr *text)
#define octstr_get_cstr(ostr)
#define octstr_copy(ostr, from, len)
long octstr_search_char(const Octstr *ostr, int ch, long pos)
static void expire_cookies(List *)
void cookies_destroy(List *cookies)
static int have_cookie(List *, Cookie *)
static Octstr * get_header_value(Octstr *)
time_t gw_mktime(struct tm *tm)
static void cookie_destroy(void *)
void gwlist_delete(List *list, long pos, long count)
#define MAX_HTTP_DATE_LENGTH
static Cookie * parse_cookie(Octstr *)
static Cookie emptyCookie
static int parse_http_date(const char *)
void octstr_destroy(Octstr *ostr)
Cookie * cookie_create(void)
#define octstr_create(cstr)
long octstr_len(const Octstr *ostr)
void debug(const char *place, int err, const char *fmt,...)
void() gwlib_assert_init(void)
int set_cookies(List *headers, WSPMachine *sm)
static void add_cookie_to_cache(const WSPMachine *, Cookie *)
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)