return 0; /* same length */
}
+/*
+ * match example
+ * astr: XXXXYYYYZZZZ
+ * suffix: YYYZZZZ
+ *
+ */
+EXPORT Bool ascstr_suffixcmp(ascstr_t *astr, ascstr_t *suffix)
+{
+ if (astr->len < suffix->len) {
+ return False;
+ }
+ if (strncmp(astr->str + astr->len - suffix->len, suffix->str, suffix->len) != 0) {
+ return False;
+ }
+
+ return True;
+}
+
EXPORT W ascstr_initialize(ascstr_t *astr)
{
astr->str = malloc(sizeof(UB));
return False;
}
-LOCAL Bool cookiedb_writeiterator_domaincheck(ascstr_t *send_host, ascstr_t *origin_host)
+LOCAL Bool cookiedb_writeiterator_checksendcondition_domaincheck(cookiedb_writeiterator_t *iter, httpcookie_t *cookie)
{
- if (origin_host->len < send_host->len) {
- return False;
- }
- if (strncmp(origin_host->str + origin_host->len - send_host->len, send_host->str, send_host->len) != 0) {
- return False;
+ Bool ok;
+ W count;
+
+ if (cookie->domain.len != 0) {
+ ok = ascstr_suffixcmp(&iter->host, &cookie->domain);
+ if (ok == False) {
+ return False;
+ }
+ count = count_priod(&cookie->domain);
+ ok = check_specified_TLD(&cookie->domain);
+ if (ok == True) {
+ if (count < 2) {
+ return False;
+ }
+ } else {
+ if (count < 3) {
+ return False;
+ }
+ }
+ } else {
+ ok = ascstr_suffixcmp(&iter->host, &cookie->origin_host);
+ if (ok == False) {
+ return False;
+ }
}
return True;
LOCAL Bool cookiedb_writeiterator_checksendcondition(cookiedb_writeiterator_t *iter, httpcookie_t *cookie)
{
Bool ok;
- W count;
if (cookie->secure == True) {
if (iter->secure != True) {
return False;
}
}
- if (cookie->domain.len != 0) {
- ok = cookiedb_writeiterator_domaincheck(&iter->host, &cookie->domain);
- if (ok == False) {
- return False;
- }
- count = count_priod(&cookie->domain);
- ok = check_specified_TLD(&cookie->domain);
- if (ok == True) {
- if (count < 2) {
- return False;
- }
- } else {
- if (count < 3) {
- return False;
- }
- }
- } else {
- ok = cookiedb_writeiterator_domaincheck(&iter->host, &cookie->origin_host);
- if (ok == False) {
- return False;
- }
+ ok = cookiedb_writeiterator_checksendcondition_domaincheck(iter, cookie);
+ if (ok == False) {
+ return False;
}
if (cookie->path.len != 0) {
ok = cookiedb_writeitereator_pathcheck(&iter->path, &cookie->path);
LOCAL Bool cookiedb_checkinsertioncondition(cookiedb_t *db, httpcookie_t *cookie, STIME current)
{
- /* TODO: domain chack */
+ W count;
+ Bool ok;
+
+ /* domain check */
+ if (cookie->domain.len != 0) {
+ if (cookie->domain.str[0] != '.') { /* is not error and add period? */
+ return False;
+ }
+ /* same as cookiedb_writeiterator_checksendcondition */
+ count = count_priod(&cookie->domain);
+ ok = check_specified_TLD(&cookie->domain);
+ if (ok == True) {
+ if (count < 2) {
+ return False;
+ }
+ } else {
+ if (count < 3) {
+ return False;
+ }
+ }
+ /* domain and request host check */
+ if (cookie->domain.len == (cookie->origin_host.len + 1)) {
+ /* for
+ * domain = .xxx.yyy.zzz
+ * origin = xxx.yyy.zzz
+ */
+ if (strncmp(cookie->domain.str + 1, cookie->origin_host.str, cookie->origin_host.len) != 0) {
+ return False;
+ }
+ } else {
+ ok = ascstr_suffixcmp(&cookie->origin_host, &cookie->domain);
+ if (ok == False) {
+ return False;
+ }
+ }
+ }
+
+ /* expire check */
if (cookie->expires == 0) {
return True;
}
if (cookie->expires < current) {
return True;
}
+
return False;
}
-LOCAL VOID cookiedb_inserteachdb(cookiedb_t *db, httpcookie_t *cookie, STIME current)
+LOCAL VOID cookiedb_insertwithcheck(cookiedb_t *db, httpcookie_t *cookie, STIME current)
{
Bool save;
save = cookiedb_checkinsertioncondition(db, cookie, current);
break;
}
httpcookie_QueRemove(cookie);
- cookiedb_inserteachdb(db, cookie, context->current);
+ cookiedb_insertwithcheck(db, cookie, context->current);
}
if (context->reading != NULL) {
ok = httpcookie_isvalueset(context->reading);
if (ok == True) {
httpcookie_QueRemove(context->reading);
- cookiedb_inserteachdb(db, context->reading, context->current);
+ cookiedb_insertwithcheck(db, context->reading, context->current);
} else {
httpcookie_delete(context->reading);
}
return TEST_RESULT_PASS;
}
+/* check origin host condition. */
+
LOCAL UB test_cookiedb_host1[] = ".2ch.net";
LOCAL UB test_cookiedb_name1[] = "NAME01";
LOCAL UB test_cookiedb_value1[] = "VALUE01";
{
"PON", /* name */
"xxxxx.yyyyy.zzzz.ad.jp", /* value */
- },
- {
- "HAP", /* name */
- "XYZABCD", /* value */
}
};
- return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "2ch.net", "/", False, 0x1eec16c0, expected, 2);
+ return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "2ch.net", "/", False, 0x1eec16c0, expected, 1);
}
LOCAL TEST_RESULT test_cookiedb_4()
{
"HAP", /* name */
"XYZABCD", /* value */
+ },
+ {
+ "PON", /* name */
+ "xxxxx.yyyyy.zzzz.ad.jp", /* value */
}
};
- return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "www.2ch.net", "/", False, 0x1eec16c0, expected, 1);
+ return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "www.2ch.net", "/", False, 0x1eec16c0, expected, 2);
}
+/* check path condition */
+
LOCAL TEST_RESULT test_cookiedb_5()
{
testcookie_input_t data[] = {
}
};
- return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "2ch.net", "/", False, 0x1eec16c0, expected, 1);
+ return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "www.2ch.net", "/", False, 0x1eec16c0, expected, 1);
}
LOCAL TEST_RESULT test_cookiedb_6()
}
};
- return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "2ch.net", "/", False, 0x1eec16c0, expected, 1);
+ return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "www.2ch.net", "/", False, 0x1eec16c0, expected, 1);
}
LOCAL TEST_RESULT test_cookiedb_7()
}
};
- return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "2ch.net", "/", False, 0x1eec16c0, expected, 1);
+ return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "www.2ch.net", "/", False, 0x1eec16c0, expected, 1);
}
LOCAL TEST_RESULT test_cookiedb_8()
}
};
- return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "2ch.net", "/", False, 0x1eec16c0, expected, 1);
+ return test_cookiedb_testingseparateinput(data, 2, 0x1eec16c0, "www.2ch.net", "/", False, 0x1eec16c0, expected, 1);
}
+/* check cookie order by path */
+
LOCAL TEST_RESULT test_cookiedb_9()
{
testcookie_input_t data[] = {
return test_cookiedb_testingseparateinput_order(data, 2, 0x1eec16c0, "2ch.net", "/", False, 0x1eec16c0, expected, 2);
}
+/* check domain condition. */
+
+LOCAL TEST_RESULT test_cookiedb_13()
+{
+ testcookie_input_t data[] = {
+ {
+ "www.2ch.net", /* origin_host */
+ "/", /* origin_path */
+ "AAA", /* name */
+ "BBB", /* value */
+ ".xxx.www.2ch.net", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ {
+ "www.2ch.net", /* origin_host */
+ "/", /* origin_path */
+ "CCC", /* name */
+ "DDD", /* value */
+ ".www.2ch.net", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ {
+ "www.2ch.net", /* origin_host */
+ "/", /* origin_path */
+ "EEE", /* name */
+ "FFF", /* value */
+ ".2ch.net", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ };
+ testcookie_expected_t expected[] = {
+ {
+ "CCC", /* name */
+ "DDD", /* value */
+ },
+ {
+ "EEE", /* name */
+ "FFF", /* value */
+ }
+ };
+
+ return test_cookiedb_testingseparateinput(data, 3, 0x1eec16c0, "xxx.www.2ch.net", "/", False, 0x1eec16c0, expected, 2);
+}
+
+LOCAL TEST_RESULT test_cookiedb_14()
+{
+ testcookie_input_t data[] = {
+ {
+ "www.xxx.xx.jp", /* origin_host */
+ "/", /* origin_path */
+ "AAA", /* name */
+ "BBB", /* value */
+ ".xxx.www.xxx.xx.jp", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ {
+ "www.xxx.xx.jp", /* origin_host */
+ "/", /* origin_path */
+ "CCC", /* name */
+ "DDD", /* value */
+ ".www.xxx.xx.jp", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ {
+ "www.xxx.xx.jp", /* origin_host */
+ "/", /* origin_path */
+ "EEE", /* name */
+ "FFF", /* value */
+ ".xxx.xx.jp", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ };
+ testcookie_expected_t expected[] = {
+ {
+ "CCC", /* name */
+ "DDD", /* value */
+ },
+ {
+ "EEE", /* name */
+ "FFF", /* value */
+ }
+ };
+
+ return test_cookiedb_testingseparateinput(data, 3, 0x1eec16c0, "xxx.www.xxx.xx.jp", "/", False, 0x1eec16c0, expected, 2);
+}
+
+LOCAL TEST_RESULT test_cookiedb_15()
+{
+ testcookie_input_t data[] = {
+ {
+ "www.2ch.net", /* origin_host */
+ "/", /* origin_path */
+ "AAA", /* name */
+ "BBB", /* value */
+ ".xxx.www.2ch.net", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ {
+ "www.2ch.net", /* origin_host */
+ "/", /* origin_path */
+ "CCC", /* name */
+ "DDD", /* value */
+ ".www.2ch.net", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ {
+ "www.2ch.net", /* origin_host */
+ "/", /* origin_path */
+ "EEE", /* name */
+ "FFF", /* value */
+ ".2ch.net", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ };
+ testcookie_expected_t expected[] = {
+ {
+ "EEE", /* name */
+ "FFF", /* value */
+ }
+ };
+
+ return test_cookiedb_testingseparateinput(data, 3, 0x1eec16c0, "xxx.yyy.2ch.net", "/", False, 0x1eec16c0, expected, 1);
+}
+
+LOCAL TEST_RESULT test_cookiedb_16()
+{
+ testcookie_input_t data[] = {
+ {
+ "www.xxx.xx.jp", /* origin_host */
+ "/", /* origin_path */
+ "AAA", /* name */
+ "BBB", /* value */
+ ".xxx.www.xxx.xx.jp", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ {
+ "www.xxx.xx.jp", /* origin_host */
+ "/", /* origin_path */
+ "CCC", /* name */
+ "DDD", /* value */
+ ".www.xxx.xx.jp", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ {
+ "www.xxx.xx.jp", /* origin_host */
+ "/", /* origin_path */
+ "EEE", /* name */
+ "FFF", /* value */
+ ".xxx.xx.jp", /* domain */
+ NULL, /* path */
+ False, /* secure */
+ 0 /* expires */
+ },
+ };
+ testcookie_expected_t expected[] = {
+ {
+ "EEE", /* name */
+ "FFF", /* value */
+ }
+ };
+
+ return test_cookiedb_testingseparateinput(data, 3, 0x1eec16c0, "yyy.zzz.xxx.xx.jp", "/", False, 0x1eec16c0, expected, 1);
+}
+
LOCAL VOID test_cookiedb_printresult(TEST_RESULT (*proc)(), B *test_name)
{
TEST_RESULT result;
test_cookiedb_printresult(test_cookiedb_10, "test_cookiedb_10");
test_cookiedb_printresult(test_cookiedb_11, "test_cookiedb_11");
test_cookiedb_printresult(test_cookiedb_12, "test_cookiedb_12");
+ test_cookiedb_printresult(test_cookiedb_13, "test_cookiedb_13");
+ test_cookiedb_printresult(test_cookiedb_14, "test_cookiedb_14");
+ test_cookiedb_printresult(test_cookiedb_15, "test_cookiedb_15");
+ test_cookiedb_printresult(test_cookiedb_16, "test_cookiedb_16");
}