/*
* bbsmenuparser.c
*
- * Copyright (c) 2009-2012 project bchan
+ * Copyright (c) 2009-2015 project bchan
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
return 0; /* TODO */
}
-EXPORT VOID bbsmnparser_item_gethostboard(bbsmnparser_item_t *item, UB **host, W *host_len, UB **board, W *board_len)
+EXPORT VOID bbsmnparser_item_gethostboard(bbsmnparser_item_t *item, UB **host, W *host_len, UH *port, UB **board, W *board_len)
{
W i = 0;
- UB *host0 = NULL, *board0 = NULL;
- W host_len0 = 0, board_len0 = 0;
+ UB *host0 = NULL, *port0 = NULL, *board0 = NULL;
+ W host_len0 = 0, port_len0 = 0, board_len0 = 0;
+ Bool port_exist = False;
host0 = item->url + 7;
for (i=7; i < item->url_len; i++) {
if (item->url[i] == '/') {
break;
}
+ if (item->url[i] == ':') {
+ port_exist = True;
+ break;
+ }
host_len0++;
}
-
i++;
+
+ port0 = item->url + i;
+ if (port_exist != False) {
+ for (; i < item->url_len; i++) {
+ if (item->url[i] == '/') {
+ break;
+ }
+ port_len0++;
+ }
+ i++;
+ }
+ if (port_len0 > 0) {
+ *port = atoi(port0);
+ } else {
+ *port = 80;
+ }
+
board0 = item->url + i;
for (; i < item->url_len; i++) {
if (item->url[i] == '/') {
/*
* bbsmenuparser.h
*
- * Copyright (c) 2009-2012 project bchan
+ * Copyright (c) 2009-2015 project bchan
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
IMPORT VOID bbsmnparser_item_delete(bbsmnparser_item_t *item);
IMPORT Bool bbsmnparser_item_checkboradurl(bbsmnparser_item_t *item);
-IMPORT VOID bbsmnparser_item_gethostboard(bbsmnparser_item_t *item, UB **host, W *host_len, UB **board, W *board_len);
+IMPORT VOID bbsmnparser_item_gethostboard(bbsmnparser_item_t *item, UB **host, W *host_len, UH *port, UB **board, W *board_len);
IMPORT bbsmnparser_t* bbsmnparser_new(bbsmncache_t *cache);
IMPORT VOID bbsmnparser_delete(bbsmnparser_t *parser);
/*
* main.c
*
- * Copyright (c) 2009-2014 project bchan
+ * Copyright (c) 2009-2015 project bchan
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
W fnd;
UB *host, *board;
W host_len, board_len;
+ UH port;
TC *title;
W title_len;
if (item->category != NULL) {
return;
}
- bbsmnparser_item_gethostboard(item, &host, &host_len, &board, &board_len);
+ bbsmnparser_item_gethostboard(item, &host, &host_len, &port, &board, &board_len);
subject = bchanl_subjecthash_search(bchanl->subjecthash, host, host_len, board, board_len);
if (subject == NULL) {
DP(("not found by subject hash"));
W err;
UB *host, *board;
W host_len, board_len;
+ UH port;
- bbsmnparser_item_gethostboard(item, &host, &host_len, &board, &board_len);
+ bbsmnparser_item_gethostboard(item, &host, &host_len, &port, &board, &board_len);
err = bchanl_subjecthash_append(bchanl->subjecthash, host, host_len, board, board_len, item->title, item->title_len);
return err;
}
/*
* test_bbsmenuparser.c
*
- * Copyright (c) 2009-2012 project bchan
+ * Copyright (c) 2009-2015 project bchan
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
return UNITTEST_RESULT_FAIL;
}
+typedef struct {
+ UB *url;
+ W url_len;
+ UB *expected_host;
+ W expected_host_len;
+ UH expected_port;
+ UB *expected_board;
+ W expected_board_len;
+} test_bbsmnparser_item_url_t;
+
+LOCAL UNITTEST_RESULT test_bbsmnparser_item_url_common(test_bbsmnparser_item_url_t *data)
+{
+ bbsmncache_t *cache;
+ bbsmnparser_t *parser;
+ bbsmnparser_item_t *item;
+ UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
+ UB *host, *board;
+ W host_len, board_len;
+ UH port;
+
+ cache = bbsmncache_new();
+ if (cache == NULL) {
+ return UNITTEST_RESULT_FAIL;
+ }
+ parser = bbsmnparser_new(cache);
+ if (parser == NULL) {
+ bbsmncache_delete(cache);
+ return UNITTEST_RESULT_FAIL;
+ }
+
+ item = bbsmnparser_newboarditem(parser, NULL, 0, data->url, data->url_len);
+ if (item == NULL) {
+ ret = UNITTEST_RESULT_FAIL;
+ }
+ bbsmnparser_item_gethostboard(item, &host, &host_len, &port, &board, &board_len);
+ if (host_len != data->expected_host_len) {
+ printf("host length fail: expected = %d, result = %d\n", data->expected_host_len, host_len);
+ ret = UNITTEST_RESULT_FAIL;
+ } else if (strncmp(host, data->expected_host, host_len) != 0) {
+ printf("host fail\n");
+ ret = UNITTEST_RESULT_FAIL;
+ }
+ if (port != data->expected_port) {
+ printf("port fail: expected = %d, result = %d\n", data->expected_port, port);
+ ret = UNITTEST_RESULT_FAIL;
+ }
+ if (board_len != data->expected_board_len) {
+ printf("board length fail: expected = %d, result = %d\n", data->expected_board_len, board_len);
+ ret = UNITTEST_RESULT_FAIL;
+ } else if (strncmp(board, data->expected_board, board_len) != 0) {
+ printf("board fail\n");
+ ret = UNITTEST_RESULT_FAIL;
+ }
+
+ bbsmnparser_delete(parser);
+ bbsmncache_delete(cache);
+
+ return ret;
+}
+
+LOCAL UNITTEST_RESULT test_bbsmnparser_item_url_1(test_bbsmnparser_item_url_t *data)
+{
+ UB url[] = "http://aaa.bbb.ccc/test/";
+ W url_len = strlen(url);
+ UB host[] = "aaa.bbb.ccc";
+ W host_len = strlen(host);
+ UH port = 80;
+ UB board[] = "test";
+ W board_len = strlen(board);
+ test_bbsmnparser_item_url_t testdata = {
+ url, url_len, host, host_len, port, board, board_len
+ };
+ return test_bbsmnparser_item_url_common(&testdata);
+}
+
+LOCAL UNITTEST_RESULT test_bbsmnparser_item_url_2(test_bbsmnparser_item_url_t *data)
+{
+ UB url[] = "http://aaa.bbb.ccc:65000/test/";
+ W url_len = strlen(url);
+ UB host[] = "aaa.bbb.ccc";
+ W host_len = strlen(host);
+ UH port = 65000;
+ UB board[] = "test";
+ W board_len = strlen(board);
+ test_bbsmnparser_item_url_t testdata = {
+ url, url_len, host, host_len, port, board, board_len
+ };
+ return test_bbsmnparser_item_url_common(&testdata);
+}
+
EXPORT VOID test_bbsmnparser_main(unittest_driver_t *driver)
{
UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_1);
UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_13);
UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_14);
UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_15);
+ UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_item_url_1);
+ UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_item_url_2);
}