• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂654 (tree)
時間2015-03-13 01:16:58
作者ornse01

Log Message

add port number handling to bbsmnparser_item_t.

Change Summary

差異

--- bchanl/trunk/src/test_bbsmenuparser.c (revision 653)
+++ bchanl/trunk/src/test_bbsmenuparser.c (revision 654)
@@ -1,7 +1,7 @@
11 /*
22 * test_bbsmenuparser.c
33 *
4- * Copyright (c) 2009-2012 project bchan
4+ * Copyright (c) 2009-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -395,6 +395,96 @@
395395 return UNITTEST_RESULT_FAIL;
396396 }
397397
398+typedef struct {
399+ UB *url;
400+ W url_len;
401+ UB *expected_host;
402+ W expected_host_len;
403+ UH expected_port;
404+ UB *expected_board;
405+ W expected_board_len;
406+} test_bbsmnparser_item_url_t;
407+
408+LOCAL UNITTEST_RESULT test_bbsmnparser_item_url_common(test_bbsmnparser_item_url_t *data)
409+{
410+ bbsmncache_t *cache;
411+ bbsmnparser_t *parser;
412+ bbsmnparser_item_t *item;
413+ UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
414+ UB *host, *board;
415+ W host_len, board_len;
416+ UH port;
417+
418+ cache = bbsmncache_new();
419+ if (cache == NULL) {
420+ return UNITTEST_RESULT_FAIL;
421+ }
422+ parser = bbsmnparser_new(cache);
423+ if (parser == NULL) {
424+ bbsmncache_delete(cache);
425+ return UNITTEST_RESULT_FAIL;
426+ }
427+
428+ item = bbsmnparser_newboarditem(parser, NULL, 0, data->url, data->url_len);
429+ if (item == NULL) {
430+ ret = UNITTEST_RESULT_FAIL;
431+ }
432+ bbsmnparser_item_gethostboard(item, &host, &host_len, &port, &board, &board_len);
433+ if (host_len != data->expected_host_len) {
434+ printf("host length fail: expected = %d, result = %d\n", data->expected_host_len, host_len);
435+ ret = UNITTEST_RESULT_FAIL;
436+ } else if (strncmp(host, data->expected_host, host_len) != 0) {
437+ printf("host fail\n");
438+ ret = UNITTEST_RESULT_FAIL;
439+ }
440+ if (port != data->expected_port) {
441+ printf("port fail: expected = %d, result = %d\n", data->expected_port, port);
442+ ret = UNITTEST_RESULT_FAIL;
443+ }
444+ if (board_len != data->expected_board_len) {
445+ printf("board length fail: expected = %d, result = %d\n", data->expected_board_len, board_len);
446+ ret = UNITTEST_RESULT_FAIL;
447+ } else if (strncmp(board, data->expected_board, board_len) != 0) {
448+ printf("board fail\n");
449+ ret = UNITTEST_RESULT_FAIL;
450+ }
451+
452+ bbsmnparser_delete(parser);
453+ bbsmncache_delete(cache);
454+
455+ return ret;
456+}
457+
458+LOCAL UNITTEST_RESULT test_bbsmnparser_item_url_1(test_bbsmnparser_item_url_t *data)
459+{
460+ UB url[] = "http://aaa.bbb.ccc/test/";
461+ W url_len = strlen(url);
462+ UB host[] = "aaa.bbb.ccc";
463+ W host_len = strlen(host);
464+ UH port = 80;
465+ UB board[] = "test";
466+ W board_len = strlen(board);
467+ test_bbsmnparser_item_url_t testdata = {
468+ url, url_len, host, host_len, port, board, board_len
469+ };
470+ return test_bbsmnparser_item_url_common(&testdata);
471+}
472+
473+LOCAL UNITTEST_RESULT test_bbsmnparser_item_url_2(test_bbsmnparser_item_url_t *data)
474+{
475+ UB url[] = "http://aaa.bbb.ccc:65000/test/";
476+ W url_len = strlen(url);
477+ UB host[] = "aaa.bbb.ccc";
478+ W host_len = strlen(host);
479+ UH port = 65000;
480+ UB board[] = "test";
481+ W board_len = strlen(board);
482+ test_bbsmnparser_item_url_t testdata = {
483+ url, url_len, host, host_len, port, board, board_len
484+ };
485+ return test_bbsmnparser_item_url_common(&testdata);
486+}
487+
398488 EXPORT VOID test_bbsmnparser_main(unittest_driver_t *driver)
399489 {
400490 UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_1);
@@ -412,4 +502,6 @@
412502 UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_13);
413503 UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_14);
414504 UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_15);
505+ UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_item_url_1);
506+ UNITTEST_DRIVER_REGIST(driver, test_bbsmnparser_item_url_2);
415507 }
--- bchanl/trunk/src/bbsmenuparser.c (revision 653)
+++ bchanl/trunk/src/bbsmenuparser.c (revision 654)
@@ -1,7 +1,7 @@
11 /*
22 * bbsmenuparser.c
33 *
4- * Copyright (c) 2009-2012 project bchan
4+ * Copyright (c) 2009-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -262,11 +262,12 @@
262262 return 0; /* TODO */
263263 }
264264
265-EXPORT VOID bbsmnparser_item_gethostboard(bbsmnparser_item_t *item, UB **host, W *host_len, UB **board, W *board_len)
265+EXPORT VOID bbsmnparser_item_gethostboard(bbsmnparser_item_t *item, UB **host, W *host_len, UH *port, UB **board, W *board_len)
266266 {
267267 W i = 0;
268- UB *host0 = NULL, *board0 = NULL;
269- W host_len0 = 0, board_len0 = 0;
268+ UB *host0 = NULL, *port0 = NULL, *board0 = NULL;
269+ W host_len0 = 0, port_len0 = 0, board_len0 = 0;
270+ Bool port_exist = False;
270271
271272 host0 = item->url + 7;
272273 for (i=7; i < item->url_len; i++) {
@@ -273,10 +274,30 @@
273274 if (item->url[i] == '/') {
274275 break;
275276 }
277+ if (item->url[i] == ':') {
278+ port_exist = True;
279+ break;
280+ }
276281 host_len0++;
277282 }
283+ i++;
278284
279- i++;
285+ port0 = item->url + i;
286+ if (port_exist != False) {
287+ for (; i < item->url_len; i++) {
288+ if (item->url[i] == '/') {
289+ break;
290+ }
291+ port_len0++;
292+ }
293+ i++;
294+ }
295+ if (port_len0 > 0) {
296+ *port = atoi(port0);
297+ } else {
298+ *port = 80;
299+ }
300+
280301 board0 = item->url + i;
281302 for (; i < item->url_len; i++) {
282303 if (item->url[i] == '/') {
--- bchanl/trunk/src/bbsmenuparser.h (revision 653)
+++ bchanl/trunk/src/bbsmenuparser.h (revision 654)
@@ -1,7 +1,7 @@
11 /*
22 * bbsmenuparser.h
33 *
4- * Copyright (c) 2009-2012 project bchan
4+ * Copyright (c) 2009-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -43,7 +43,7 @@
4343
4444 IMPORT VOID bbsmnparser_item_delete(bbsmnparser_item_t *item);
4545 IMPORT Bool bbsmnparser_item_checkboradurl(bbsmnparser_item_t *item);
46-IMPORT VOID bbsmnparser_item_gethostboard(bbsmnparser_item_t *item, UB **host, W *host_len, UB **board, W *board_len);
46+IMPORT VOID bbsmnparser_item_gethostboard(bbsmnparser_item_t *item, UB **host, W *host_len, UH *port, UB **board, W *board_len);
4747
4848 IMPORT bbsmnparser_t* bbsmnparser_new(bbsmncache_t *cache);
4949 IMPORT VOID bbsmnparser_delete(bbsmnparser_t *parser);
--- bchanl/trunk/src/main.c (revision 653)
+++ bchanl/trunk/src/main.c (revision 654)
@@ -1,7 +1,7 @@
11 /*
22 * main.c
33 *
4- * Copyright (c) 2009-2014 project bchan
4+ * Copyright (c) 2009-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -614,6 +614,7 @@
614614 W fnd;
615615 UB *host, *board;
616616 W host_len, board_len;
617+ UH port;
617618 TC *title;
618619 W title_len;
619620
@@ -625,7 +626,7 @@
625626 if (item->category != NULL) {
626627 return;
627628 }
628- bbsmnparser_item_gethostboard(item, &host, &host_len, &board, &board_len);
629+ bbsmnparser_item_gethostboard(item, &host, &host_len, &port, &board, &board_len);
629630 subject = bchanl_subjecthash_search(bchanl->subjecthash, host, host_len, board, board_len);
630631 if (subject == NULL) {
631632 DP(("not found by subject hash"));
@@ -734,8 +735,9 @@
734735 W err;
735736 UB *host, *board;
736737 W host_len, board_len;
738+ UH port;
737739
738- bbsmnparser_item_gethostboard(item, &host, &host_len, &board, &board_len);
740+ bbsmnparser_item_gethostboard(item, &host, &host_len, &port, &board, &board_len);
739741 err = bchanl_subjecthash_append(bchanl->subjecthash, host, host_len, board, board_len, item->title, item->title_len);
740742 return err;
741743 }
Show on old repository browser