#include "setcookieheader.h"
#include "parselib.h"
+#include "httpdateparser.h"
#include <basic.h>
#include <bstdio.h>
EXPORT W setcookieparser_inputchar(setcookieparser_t *parser, UB ch, setcookieparser_result_t **result, W *result_len)
{
- W ret, val;
+ W ret, val, err;
HTTPCOOKIEGENERAL_RESULT_T res;
*result_len = 0;
return SETCOOKIEPARSER_CONTINUE;
}
if (res == HTTPCOOKIEGENERAL_RESULT_VALUE) {
- if (val != SETCOOKIEPARSER_ATTR_SECURE) {
+ if (val == SETCOOKIEPARSER_ATTR_SECURE) {
+ parser->state = SETCOOKIEPARSER_STATE_VALUE_UNSUPPORTED;
+ } else if (val == SETCOOKIEPARSER_ATTR_EXPIRES) {
+ parser->state = SETCOOKIEPARSER_STATE_VALUE_EXPIRES;
+ rfc733dateparser_initialize(&parser->dateparser);
+ err = rfc733dateparser_inputchar(&parser->dateparser, ch, &parser->date);
+ if (err != HTTPDATEPARSER_CONTINUE) {
+ return SETCOOKIEPARSER_ERROR;
+ }
+ } else {
parser->state = SETCOOKIEPARSER_STATE_VALUE_SUPPORTED;
parser->attr = val;
setcookieparser_inputchar_resultVALUE_ch(parser, ch, parser->buffer, parser->attr);
*result = parser->buffer;
*result_len = 1;
- } else {
- parser->state = SETCOOKIEPARSER_STATE_VALUE_UNSUPPORTED;
}
return SETCOOKIEPARSER_CONTINUE;
}
*result = parser->buffer;
*result_len = 1;
break;
+ case SETCOOKIEPARSER_STATE_VALUE_EXPIRES:
+ if (res == HTTPCOOKIEGENERAL_RESULT_AVPAIR_END) {
+ parser->state = SETCOOKIEPARSER_STATE_SEARCH_ATTR;
+ err = rfc733dateparser_endinput(&parser->dateparser, &parser->date);
+ if (err == HTTPDATEPARSER_DETERMINE) {
+ parser->buffer[0].type = SETCOOKIEPARSER_RESULT_TYPE_EXPIRESATTR;
+ set_tod(&parser->date, &(parser->buffer[0].val.expires.time), 0);
+ *result = parser->buffer;
+ *result_len = 1;
+ }
+ rfc733dateparser_finalize(&parser->dateparser);
+ break;
+ }
+ err = rfc733dateparser_inputchar(&parser->dateparser, ch, &parser->date);
+ if (err != HTTPDATEPARSER_CONTINUE) {
+ return SETCOOKIEPARSER_ERROR;
+ }
+ break;
}
return SETCOOKIEPARSER_CONTINUE;
#include <basic.h>
#include "parselib.h"
+#include "httpdateparser.h"
#ifndef __SETCOOKIEHEADER_H__
#define __SETCOOKIEHEADER_H__
SETCOOKIEPARSER_RESULT_TYPE_NAMEATTR,
SETCOOKIEPARSER_RESULT_TYPE_VALUE,
SETCOOKIEPARSER_RESULT_TYPE_SECUREATTR,
+ SETCOOKIEPARSER_RESULT_TYPE_EXPIRESATTR,
};
typedef enum SETCOOKIEPARSER_RESULT_TYPE_T_ SETCOOKIEPARSER_RESULT_TYPE_T;
W len;
SETCOOKIEPARSER_ATTR_T attr;
} value;
+ struct {
+ STIME time;
+ } expires;
} val;
};
typedef struct setcookieparser_result_t_ setcookieparser_result_t;
SETCOOKIEPARSER_STATE_READ_NAMEATTR,
SETCOOKIEPARSER_STATE_SKIP_AVPAIR,
SETCOOKIEPARSER_STATE_VALUE_NAME,
+ SETCOOKIEPARSER_STATE_VALUE_EXPIRES,
SETCOOKIEPARSER_STATE_VALUE_SUPPORTED,
SETCOOKIEPARSER_STATE_VALUE_UNSUPPORTED,
} state;
W attr;
httpcookiegeneral_t lexer;
tokenchecker_t attrchecker;
+ rfc733dateparser_t dateparser;
setcookieparser_result_t buffer[2];
UB buf_str[1];
+ DATE_TIM date;
};
typedef struct setcookieparser_t_ setcookieparser_t;
UB *value_name_exptd;
UB *value_comment_exptd;
UB *value_domain_exptd;
- UB *value_expires_exptd;
UB *value_max_age_exptd;
UB *value_path_exptd;
UB *value_version_exptd;
Bool issecure_exptd;
+ STIME expires_exptd;
W i_a_name;
W i_v_name;
W i_v_comment;
W i_v_domain;
- W i_v_expires;
W i_v_max_age;
W i_v_path;
W i_v_version;
Bool b_secure;
+ STIME t_v_expires;
} test_cookieresult_t;
-LOCAL VOID test_cookieresult_initialize(test_cookieresult_t *result, UB *name, UB *val_name, UB *comment, UB *domain, UB *expires, UB *max_age, UB *path, UB *version, Bool secure)
+LOCAL VOID test_cookieresult_initialize(test_cookieresult_t *result, UB *name, UB *val_name, UB *comment, UB *domain, STIME expires, UB *max_age, UB *path, UB *version, Bool secure)
{
result->attr_name_exptd = name;
result->value_name_exptd = val_name;
result->value_comment_exptd = comment;
result->value_domain_exptd = domain;
- result->value_expires_exptd = expires;
result->value_max_age_exptd = max_age;
result->value_path_exptd = path;
result->value_version_exptd = version;
result->issecure_exptd = secure;
+ result->expires_exptd = expires;
result->i_a_name = 0;
result->i_v_name = 0;
result->i_v_comment = 0;
result->i_v_domain = 0;
- result->i_v_expires = 0;
result->i_v_max_age = 0;
result->i_v_path = 0;
result->i_v_version = 0;
result->b_secure = False;
+ result->t_v_expires = 0;
}
LOCAL VOID test_cookieresult_checkstring(UB *target, W *target_len, UB *rcv, W rcv_len)
test_cookieresult_checkstring(result->value_domain_exptd, &result->i_v_domain, str, len);
}
-LOCAL VOID test_cookieresult_value_expires(test_cookieresult_t *result, UB *str, W len)
-{
- test_cookieresult_checkstring(result->value_expires_exptd, &result->i_v_expires, str, len);
-}
-
LOCAL VOID test_cookieresult_value_max_age(test_cookieresult_t *result, UB *str, W len)
{
test_cookieresult_checkstring(result->value_max_age_exptd, &result->i_v_max_age, str, len);
result->b_secure = True;
}
+LOCAL VOID test_cookieresult_expires(test_cookieresult_t *result, STIME time)
+{
+ result->t_v_expires = time;
+}
+
LOCAL VOID test_cookieresult_inputresult(test_cookieresult_t *result, setcookieparser_result_t *res)
{
if (res->type == SETCOOKIEPARSER_RESULT_TYPE_NAMEATTR) {
case SETCOOKIEPARSER_ATTR_DOMAIN:
test_cookieresult_value_domain(result, res->val.name.str, res->val.name.len);
break;
- case SETCOOKIEPARSER_ATTR_EXPIRES:
- test_cookieresult_value_expires(result, res->val.name.str, res->val.name.len);
- break;
case SETCOOKIEPARSER_ATTR_MAX_AGE:
test_cookieresult_value_max_age(result, res->val.name.str, res->val.name.len);
break;
case SETCOOKIEPARSER_ATTR_NAME:
test_cookieresult_value_name(result, res->val.name.str, res->val.name.len);
break;
+ case SETCOOKIEPARSER_ATTR_EXPIRES:
case SETCOOKIEPARSER_ATTR_SECURE:
default:
printf("invalid attr value\n");
}
} else if (res->type == SETCOOKIEPARSER_RESULT_TYPE_SECUREATTR) {
test_cookieresult_secure(result);
+ } else if (res->type == SETCOOKIEPARSER_RESULT_TYPE_EXPIRESATTR) {
+ test_cookieresult_expires(result, res->val.expires.time);
} else {
printf("invalid value\n");
}
printf("domain is not expected\n");
return False;
}
- if (strlen(result->value_expires_exptd) != result->i_v_expires) {
- printf("expires is not expected\n");
- return False;
- }
if (strlen(result->value_max_age_exptd) != result->i_v_max_age) {
printf("max-age is not expected\n");
return False;
printf("secure is not expected\n");
return False;
}
+ if (result->expires_exptd != result->t_v_expires) {
+ printf("expires is not expected\n");
+ return False;
+ }
return True;
}
setcookieparser_result_t *res;
test_cookieresult_t check;
- test_cookieresult_initialize(&check, "PON", "xAjpuk10.tky.hoge.co.jp", "", "", "Friday, 01-Jan-2016 00:00:00", "", "/", "", False);
+ test_cookieresult_initialize(&check, "PON", "xAjpuk10.tky.hoge.co.jp", "", "", /*"Friday, 01-Jan-2016 00:00:00"*/0x3a4e7700, "", "/", "", False);
err = setcookieparser_initialize(&parser);
if (err < 0) {
setcookieparser_result_t *res;
test_cookieresult_t check;
- test_cookieresult_initialize(&check, "HAP", "0000000", "", ".2ch.net", "Friday, 01-Jan-2016 00:00:00 GMT", "", "/", "", False);
+ test_cookieresult_initialize(&check, "HAP", "0000000", "", ".2ch.net", /*"Friday, 01-Jan-2016 00:00:00 GMT"*/0x3a4e7700, "", "/", "", False);
err = setcookieparser_initialize(&parser);
if (err < 0) {
setcookieparser_result_t *res;
test_cookieresult_t check;
- test_cookieresult_initialize(&check, "num", "123456", "", "", "Sun, 10-Jun-2001 12:00:00 GMT", "", "/HTTP/", "", False);
+ test_cookieresult_initialize(&check, "num", "123456", "", "", /*"Sun, 10-Jun-2001 12:00:00 GMT"*/0x1eec16c0, "", "/HTTP/", "", False);
err = setcookieparser_initialize(&parser);
if (err < 0) {
setcookieparser_result_t *res;
test_cookieresult_t check;
- test_cookieresult_initialize(&check, "param2", "GHIJKL", "", "", "Mon, 31-Dec-2001 23:59:59 GMT", "", "/", "", True);
+ test_cookieresult_initialize(&check, "param2", "GHIJKL", "", "", /*"Mon, 31-Dec-2001 23:59:59 GMT"*/0x1ff9b17f, "", "/", "", True);
err = setcookieparser_initialize(&parser);
if (err < 0) {