39 #define MAX_COOKIES 32 40 #define MAX_STORE_SIZE 8192 43 #define SECONDS_IN_DAY (24 * HOUR) 68 static U32BIT cookie_count = 0;
69 static U32BIT cookiejar_size = 0;
115 data_handle.
len = data_len;
117 if (data_len > 11 && memcmp(data_handle.
data,
"Set-Cookie:", 11) == 0)
119 offset = strlen(
"Set-Cookie:");
133 while (new_cookie && offset < data_len)
137 offset = SkipWhitespace(data, offset, data_len);
139 pos = FindChrInStr(data_handle, offset,
"=");
142 name.
len = pos - offset;
146 if (data_handle.
data[offset] ==
'\"')
152 pos = FindChrInStr(data_handle, offset,
";");
155 pos = FindChrInStr(data_handle, offset,
"\r\n");
165 value.
len = pos - offset;
175 value.
len = data_handle.
len - offset;
176 offset = data_handle.
len;
184 else if (StrCmpChr(name,
"domain") ==
MHEG5TRUE)
188 else if (StrCmpChr(name,
"expires") ==
MHEG5TRUE)
192 else if (StrCmpChr(name,
"max-age") ==
MHEG5TRUE)
196 else if (StrCmpChr(name,
"Version") ==
MHEG5TRUE)
211 GetDomainFromUrl(url, &new_cookie->
domain);
220 offset += new_cookie->
name.
len;
228 PushCookie(new_cookie);
245 U8BIT *cookie_header = NULL;
251 S32BIT current_time, current_date;
260 if (!memcmp(url,
"http://", 7))
265 else if (!memcmp(url,
"https://", 8))
277 location.
len = strlen((
char *)url) - offset;
278 location.
data = url + offset;
295 cookie_header = AddHeader(cookie_header, cursor);
307 return cookie_header;
330 success = ParseIdentity(new_cookie);
338 PushCookie(new_cookie);
372 S32BIT current_time, current_date;
409 DeleteCookie(cookiejar);
425 while (offset < data_len)
427 if (handle[offset] !=
' ' && handle[offset] !=
'\t' && handle[offset] !=
'\r' && handle[offset] !=
'\n')
459 cookiejar_size -= cookie->
value.
len;
472 assert(cookie == cookiejar);
473 cookiejar = cookie->
next;
481 if (cookie == oldest_cookie)
502 domain_pos = FindChrInStr(cookie->
identity, 0,
",");
503 if (domain_pos != -1)
505 path_pos = FindChrInStr(cookie->
identity, domain_pos,
"/");
511 cookie->
domain.
len = path_pos - domain_pos - 1;
512 offset = domain_pos + 1;
534 if (cookiejar == NULL)
536 cookiejar = new_cookie;
538 new_cookie->
next = NULL;
539 oldest_cookie = new_cookie;
544 new_cookie->
next = cookiejar;
546 cookiejar = new_cookie;
551 cookiejar_size += new_cookie->
value.
len;
555 DeleteCookie(oldest_cookie);
560 DeleteCookie(oldest_cookie);
576 register int rc = -1, i, j = 0;
578 if (offset >= 0 && offset < source.
len && search && source.
data)
580 len = strlen(search);
581 for (i = offset; i != source.
len; i++)
583 if ((source.
data[i] | 0x20) == (search[j] | 0x20))
611 if (cmp_str.
len != strlen(cmp_chrs))
616 if (!memcmp(cmp_chrs, cmp_str.
data, cmp_str.
len))
628 U8BIT *header_string;
635 memcpy(header,
"Cookie: $Version=\"0\"; \0", 23);
638 len = strlen((
char *)header);
645 memcpy(header_string, header, strlen((
char *)header));
646 offset = strlen((
char *)header);
653 memcpy(header_string + offset,
"=", 1);
659 memcpy(header_string + offset,
"; $Path=", 8);
665 memcpy(header_string + offset,
"; \0", 3);
668 return header_string;
671 static S32BIT ParseMonthString(
U8BIT *input_string)
674 switch (input_string[0])
677 if (!memcmp(input_string,
"Jan", 3))
681 if (!month_index && !memcmp(input_string,
"Jun", 3))
685 if (!month_index && !memcmp(input_string,
"Jul", 3))
691 if (!memcmp(input_string,
"Feb", 3))
697 if (!memcmp(input_string,
"Mar", 3))
701 if (!month_index && !memcmp(input_string,
"May", 3))
707 if (!memcmp(input_string,
"Apr", 3))
711 if (!month_index && !memcmp(input_string,
"Aug", 3))
717 if (!memcmp(input_string,
"Sep", 3))
723 if (!memcmp(input_string,
"Oct", 3))
729 if (!memcmp(input_string,
"Nov", 3))
735 if (!memcmp(input_string,
"Dec", 3))
748 time = (input_string[0] -
'0') *
HOUR * 10;
749 time += (input_string[1] -
'0') *
HOUR;
750 time += (input_string[3] -
'0') *
MINUTE * 10;
751 time += (input_string[4] -
'0') *
MINUTE;
752 time += (input_string[6] -
'0') * 10;
753 time += (input_string[7] -
'0');
762 if (date_string.
len == 29)
764 day = (date_string.
data[5] -
'0') * 10;
765 day += date_string.
data[6] -
'0';
766 month = ParseMonthString(date_string.
data + 8);
767 year = (date_string.
data[12] -
'0') * 1000;
768 year += (date_string.
data[13] -
'0') * 100;
769 year += (date_string.
data[14] -
'0') * 10;
770 year += date_string.
data[15] -
'0';
772 *time = ParseTimeString(date_string.
data + 17);
781 S32BIT current_date, current_time;
795 full_len = strlen(full_url);
797 if (full_len > 7 && full_url[7] !=
'/')
801 else if (full_len > 8 && full_url[8] !=
'/')
809 for (end = offset; end != full_len; end++)
811 if (full_url[end] ==
'/')
822 if (domain_string->
data == NULL)
826 domain_string->
len = end;
827 memcpy(domain_string->
data,(
U8BIT *)full_url + offset,end);
842 enum {
NAME, DOMAIN, PATH } state =
NAME;
847 if (stored->
len == requested->
len)
851 for (i = 0; equal && i <
len; i++)
853 if ((state == DOMAIN) && (stored->
data[i] ==
'/'))
861 if (toupper(stored->
data[i]) != toupper(requested->
data[i]))
868 if (stored->
data[i] != requested->
data[i])
874 if ((state ==
NAME) && (stored->
data[i] ==
','))
unsigned char * STR_DataAlloc(unsigned int size)
struct cookiestore_s * previous
void MHEG5getDate(S32BIT *day, S32BIT *sec)
Modified Julian Date - see Davic 9.2.12.1.
U8BIT * MHEG5CookieGenerateHeader(U8BIT *url)
Generate a "Cookie" header for the required http request, containing all valid cookies.
MHEG5Int MHEG5strToInt(MHEG5String string)
Convert a MHEG5String to a MHEG5Integer.
void MHEG5CookieClearStore(void)
Delete all cookies from the temporary store.
void MHEG5CookieParse(void *data, U32BIT data_len, char *url)
Parse a Set-cookie header and add the new cookie to the store. If the header is not a set-cookie...
MHEG5String MHEG5stringCopy(MHEG5String source)
<Function description>="">
void MHEG5stringDestruct(MHEG5String *item)
Destruct a MHEG5String.
MHEG5Bool MHEG5CookieRetrieve(MHEG5cookie_t *cookie)
Retrieve a specific cookie from the store, referenced by the identity string.
struct cookiestore_s cookiestore_t
MHEG5Bool MHEG5CookieAdd(MHEG5cookie_t *cookie)
Directly add a cookie to the store.
System Wide Global Technical Data Type Definitions.
struct cookiestore_s * next
Functions relating to HTTP Cookie Store.
U32BIT JulianDate(S32BIT day, S32BIT month, S32BIT year)
The function JulianDate() calculates the julian day number for the specified day, month and year...
void MHEG5CookieAckHeader(U8BIT *header)
This function should be called once the header string returned by MHEG5CookieGenerateHeader has been ...