• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂660 (tree)
時間2015-03-15 18:12:49
作者ornse01

Log Message

implement port number handling.

Change Summary

差異

--- bchan/trunk/src/http.c (revision 659)
+++ bchan/trunk/src/http.c (revision 660)
@@ -1,7 +1,7 @@
11 /*
22 * http.c
33 *
4- * Copyright (c) 2009-2011 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
@@ -54,11 +54,12 @@
5454 http_responsecontext_t *context;
5555 };
5656
57-EXPORT W http_connect(http_t *http, UB *host, W host_len)
57+EXPORT W http_connect(http_t *http, UB *host, W host_len, UH port)
5858 {
5959 W sock, err;
6060 B buf[HBUFLEN], *str;
6161 HOSTENT ent;
62+ struct in_addr addr;
6263 struct sockaddr_in *addr_in;
6364
6465 if (http->sockid > 0) {
@@ -72,19 +73,26 @@
7273 strncpy(str, host, host_len);
7374 str[host_len] = '\0';
7475
75- err = so_gethostbyname(str, &ent, buf);
76+ err = inet_aton(str, &addr);
77+ if (err == 0) {
78+ err = so_gethostbyname(str, &ent, buf);
79+ if (err < 0) {
80+ DP_ER("so_gethostbyname error", err);
81+ free(str);
82+ return err;
83+ }
84+ addr.s_addr = *(unsigned int *)(ent.h_addr_list[0]);
85+ }
7686 free(str);
77- if (err < 0) {
78- return err;
79- }
8087
8188 addr_in = (struct sockaddr_in *)&(http->addr);
8289 addr_in->sin_family = AF_INET;
83- addr_in->sin_port = htons( 80 );
84- addr_in->sin_addr.s_addr = *(unsigned int *)(ent.h_addr_list[0]);
90+ addr_in->sin_port = htons(port);
91+ addr_in->sin_addr = addr;
8592
8693 sock = so_socket(AF_INET, SOCK_STREAM, 0);
8794 if (sock < 0) {
95+ DP_ER("so_socket error", sock);
8896 return sock;
8997 }
9098 http->sockid = sock;
@@ -91,6 +99,7 @@
9199
92100 err = so_connect(http->sockid, &(http->addr), sizeof(SOCKADDR));
93101 if (err < 0) {
102+ DP_ER("so_connect error", err);
94103 so_close(http->sockid);
95104 return err;
96105 }
--- bchan/trunk/src/http.h (revision 659)
+++ bchan/trunk/src/http.h (revision 660)
@@ -1,7 +1,7 @@
11 /*
22 * http.h
33 *
4- * Copyright (c) 2009 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
@@ -34,7 +34,7 @@
3434
3535 IMPORT http_t* http_new();
3636 IMPORT VOID http_delete(http_t *http);
37-IMPORT W http_connect(http_t *http, UB *host, W host_len);
37+IMPORT W http_connect(http_t *http, UB *host, W host_len, UH port);
3838 IMPORT W http_send(http_t *http, UB *bin, W len);
3939 IMPORT W http_waitresponseheader(http_t *http);
4040 IMPORT W http_getstatus(http_t *http);
--- bchan/trunk/src/test_cache.c (revision 659)
+++ bchan/trunk/src/test_cache.c (revision 660)
@@ -1,7 +1,7 @@
11 /*
22 * test_cache.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
@@ -49,6 +49,7 @@
4949 LOCAL UB test_cache_testdata_05[] = {"thread"};
5050 LOCAL UB test_cache_testdata_06[] = {"AAAAAAAAA"};
5151 LOCAL UB test_cache_testdata_07[] = {"XXX abcdef\r\nAAAA: valueC\r\nBBBB: valueC\r\n\r\n"};
52+LOCAL UB test_cache_testdata_08[] = {"aaa.bbb.ccc.jp:15000\nthread\nAAAAAAAAA\n"};
5253
5354 LOCAL W test_cache_util_gen_file(LINK *lnk, VID *nvid)
5455 {
@@ -637,6 +638,7 @@
637638 UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
638639 UB *host, *borad, *thread;
639640 W cmp, host_len, borad_len, thread_len;
641+ UH port;
640642
641643 cache = datcache_new(vid);
642644
@@ -651,6 +653,12 @@
651653 result = UNITTEST_RESULT_FAIL;
652654 }
653655
656+ datcache_getport(cache, &port);
657+ if (port != 80) {
658+ printf("datcache_getport: data error\n");
659+ result = UNITTEST_RESULT_FAIL;
660+ }
661+
654662 datcache_getborad(cache, &borad, &borad_len);
655663 if (borad_len != strlen(test_cache_testdata_05)) {
656664 printf("datcache_getboard: length error\n");
@@ -733,6 +741,7 @@
733741 UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
734742 UB *host, *borad, *thread;
735743 W host_len, borad_len, thread_len;
744+ UH port;
736745
737746 cache = datcache_new(vid);
738747
@@ -746,6 +755,12 @@
746755 result = UNITTEST_RESULT_FAIL;
747756 }
748757
758+ datcache_getport(cache, &port);
759+ if (port != 80) {
760+ printf("datcache_getport: data error\n");
761+ result = UNITTEST_RESULT_FAIL;
762+ }
763+
749764 datcache_getborad(cache, &borad, &borad_len);
750765 if (borad_len != 0) {
751766 printf("datcache_getboard: length error\n");
@@ -1396,6 +1411,109 @@
13961411 return result;
13971412 }
13981413
1414+/* test_cache_16 */
1415+
1416+LOCAL UNITTEST_RESULT test_cache_16_testseq(VID vid, LINK *lnk)
1417+{
1418+ datcache_t *cache;
1419+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
1420+ UB *host, *borad, *thread;
1421+ W cmp, host_len, borad_len, thread_len;
1422+ UH port;
1423+
1424+ cache = datcache_new(vid);
1425+
1426+ datcache_gethost(cache, &host, &host_len);
1427+ if (host_len != strlen(test_cache_testdata_04)) {
1428+ printf("datcache_gethost: length error\n");
1429+ result = UNITTEST_RESULT_FAIL;
1430+ }
1431+ cmp = memcmp(host, test_cache_testdata_04, host_len);
1432+ if (cmp != 0) {
1433+ printf("datcache_gethost: data error\n");
1434+ result = UNITTEST_RESULT_FAIL;
1435+ }
1436+
1437+ datcache_getport(cache, &port);
1438+ if (port != 15000) {
1439+ printf("datcache_getport: data error\n");
1440+ result = UNITTEST_RESULT_FAIL;
1441+ }
1442+
1443+ datcache_getborad(cache, &borad, &borad_len);
1444+ if (borad_len != strlen(test_cache_testdata_05)) {
1445+ printf("datcache_getboard: length error\n");
1446+ result = UNITTEST_RESULT_FAIL;
1447+ }
1448+ cmp = memcmp(borad, test_cache_testdata_05, borad_len);
1449+ if (cmp != 0) {
1450+ printf("datcache_getboard: data error\n");
1451+ result = UNITTEST_RESULT_FAIL;
1452+ }
1453+
1454+ datcache_getthread(cache, &thread, &thread_len);
1455+ if (thread_len != strlen(test_cache_testdata_06)) {
1456+ printf("datcache_getthread: length error\n");
1457+ result = UNITTEST_RESULT_FAIL;
1458+ }
1459+ cmp = memcmp(thread, test_cache_testdata_06, thread_len);
1460+ if (cmp != 0) {
1461+ printf("datcache_getthread: data error\n");
1462+ result = UNITTEST_RESULT_FAIL;
1463+ }
1464+
1465+ datcache_delete(cache);
1466+
1467+ return result;
1468+}
1469+
1470+LOCAL UNITTEST_RESULT test_cache_16()
1471+{
1472+ LINK test_lnk;
1473+ W fd, err;
1474+ VID vid;
1475+ UNITTEST_RESULT result;
1476+
1477+ fd = test_cache_util_gen_file(&test_lnk, &vid);
1478+ if (fd < 0) {
1479+ return UNITTEST_RESULT_FAIL;
1480+ }
1481+ err = ins_rec(fd, test_cache_testdata_01, strlen(test_cache_testdata_01), DATCACHE_RECORDTYPE_MAIN, 0, 0);
1482+ if (err < 0) {
1483+ cls_fil(fd);
1484+ del_fil(NULL, &test_lnk, 0);
1485+ return UNITTEST_RESULT_FAIL;
1486+ }
1487+ err = ins_rec(fd, test_cache_testdata_02, strlen(test_cache_testdata_02), DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_HEADER, 0);
1488+ if (err < 0) {
1489+ cls_fil(fd);
1490+ del_fil(NULL, &test_lnk, 0);
1491+ return UNITTEST_RESULT_FAIL;
1492+ }
1493+ err = ins_rec(fd, test_cache_testdata_08, strlen(test_cache_testdata_08), DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_RETRIEVE, 0);
1494+ if (err < 0) {
1495+ cls_fil(fd);
1496+ del_fil(NULL, &test_lnk, 0);
1497+ return UNITTEST_RESULT_FAIL;
1498+ }
1499+ cls_fil(fd);
1500+
1501+ result = test_cache_16_testseq(vid, &test_lnk);
1502+
1503+ err = odel_vob(vid, 0);
1504+ if (err < 0) {
1505+ printf("error odel_vob:%d\n", err >> 16);
1506+ result = UNITTEST_RESULT_FAIL;
1507+ }
1508+ err = del_fil(NULL, &test_lnk, 0);
1509+ if (err < 0) {
1510+ printf("error del_fil:%d\n", err >> 16);
1511+ result = UNITTEST_RESULT_FAIL;
1512+ }
1513+
1514+ return result;
1515+}
1516+
13991517 /* append and write file test */
14001518
14011519 LOCAL W test_cache_writecheck_testseq_appenddata(datcache_t *cache, Bool clear)
@@ -3616,6 +3734,7 @@
36163734 UNITTEST_DRIVER_REGIST(driver, test_cache_13);
36173735 UNITTEST_DRIVER_REGIST(driver, test_cache_14);
36183736 UNITTEST_DRIVER_REGIST(driver, test_cache_15);
3737+ UNITTEST_DRIVER_REGIST(driver, test_cache_16);
36193738 UNITTEST_DRIVER_REGIST(driver, test_cache_residinfo_1);
36203739 UNITTEST_DRIVER_REGIST(driver, test_cache_residinfo_2);
36213740 UNITTEST_DRIVER_REGIST(driver, test_cache_residinfo_3);
--- bchan/trunk/src/retriever.c (revision 659)
+++ bchan/trunk/src/retriever.c (revision 660)
@@ -1,7 +1,7 @@
11 /*
22 * retriever.c
33 *
4- * Copyright (c) 2009-2010 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
@@ -52,6 +52,7 @@
5252 W server_len;
5353 W board_len;
5454 W thread_len;
55+ UH port;
5556 http_t *http;
5657 };
5758
@@ -270,8 +271,9 @@
270271 UB *bin, *lm, *et;
271272 http_responsecontext_t *ctx;
272273
273- err = http_connect(retriever->http, retriever->server, retriever->server_len);
274+ err = http_connect(retriever->http, retriever->server, retriever->server_len, retriever->port);
274275 if (err < 0) {
276+ DP_ER("http_connect error", err);
275277 return err;
276278 }
277279
@@ -513,6 +515,8 @@
513515 retriever->server[len] = '\0';
514516 retriever->server_len = len;
515517
518+ datcache_getport(cache, &retriever->port);
519+
516520 datcache_getborad(cache, &str, &len);
517521 if (str == NULL) {
518522 ret = 0;
--- bchan/trunk/src/cache.c (revision 659)
+++ bchan/trunk/src/cache.c (revision 660)
@@ -1,7 +1,7 @@
11 /*
22 * cache.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
@@ -65,6 +65,7 @@
6565 W retrinfo_len;
6666 UB *host;
6767 W host_len;
68+ UH port;
6869 UB *board;
6970 W board_len;
7071 UB *thread;
@@ -393,6 +394,11 @@
393394 *len = cache->host_len;
394395 }
395396
397+EXPORT VOID datcache_getport(datcache_t *cache, UH *port)
398+{
399+ *port = cache->port;
400+}
401+
396402 EXPORT VOID datcache_getborad(datcache_t *cache, UB **borad, W *len)
397403 {
398404 *borad = cache->board;
@@ -408,11 +414,13 @@
408414 LOCAL VOID datcache_setupretrinfo(datcache_t *cache, UB *retrinfo, W len)
409415 {
410416 W i=0;
417+ Bool has_port = False;
411418
412419 cache->retrinfo = retrinfo;
413420 cache->retrinfo_len = len;
414421 cache->host = NULL;
415422 cache->host_len = 0;
423+ cache->port = 80;
416424 cache->board = NULL;
417425 cache->board_len = 0;
418426 cache->thread = NULL;
@@ -427,9 +435,23 @@
427435 if (cache->retrinfo[i] == '\n') {
428436 break;
429437 }
438+ if (cache->retrinfo[i] == ':') {
439+ has_port = True;
440+ break;
441+ }
430442 cache->host_len++;
431443 }
432444
445+ if (has_port != False) {
446+ i++;
447+ cache->port = atoi(cache->retrinfo + i);
448+ for (; i < len; i++) {
449+ if (cache->retrinfo[i] == '\n') {
450+ break;
451+ }
452+ }
453+ }
454+
433455 i++;
434456 cache->board = cache->retrinfo + i;
435457 for (; i < len; i++) {
--- bchan/trunk/src/submit.c (revision 659)
+++ bchan/trunk/src/submit.c (revision 660)
@@ -1,7 +1,7 @@
11 /*
22 * submit.c
33 *
4- * Copyright (c) 2009-2011 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
@@ -57,11 +57,13 @@
5757 {
5858 UB *host, *r_body = NULL, *bin;
5959 W err, host_len, r_len = 0, len;
60+ UH port;
6061 http_responsecontext_t *context;
6162
6263 datcache_gethost(submit->cache, &host, &host_len);
64+ datcache_getport(submit->cache, &port);
6365
64- err = http_connect(submit->http, host, host_len);
66+ err = http_connect(submit->http, host, host_len, port);
6567 if (err < 0) {
6668 DP_ER("error http_connect", err);
6769 return err;
--- bchan/trunk/src/cache.h (revision 659)
+++ bchan/trunk/src/cache.h (revision 660)
@@ -1,7 +1,7 @@
11 /*
22 * cache.h
33 *
4- * Copyright (c) 2009-2011 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
@@ -54,6 +54,7 @@
5454 IMPORT VOID datcache_getlatestheader(datcache_t *cache, UB **header, W *len);
5555 IMPORT W datcache_updatelatestheader(datcache_t *cache, UB *header, W len);
5656 IMPORT VOID datcache_gethost(datcache_t *cache, UB **header, W *len);
57+IMPORT VOID datcache_getport(datcache_t *cache, UH *port);
5758 IMPORT VOID datcache_getborad(datcache_t *cache, UB **borad, W *len);
5859 IMPORT VOID datcache_getthread(datcache_t *cache, UB **thread, W *len);
5960 IMPORT W datcache_datasize(datcache_t *cache);
Show on old repository browser