Commit MetaInfo

修订版375fa3071a1c429a0ccff0620e160e685a91fc5a (tree)
时间2014-01-04 22:34:54
作者Akira <akohta001@gmai...>
CommiterAkira

Log Message

Experimental: support ipv6.

更改概述

差异

--- a/Makefile
+++ b/Makefile
@@ -4,9 +4,10 @@
44 # You may need to install then.
55
66 #Option for development
7-CFLAGS = -g -Wall -DDEBUG ${DEFS} ${CDEF} -DNT_CLOUD
7+#CFLAGS = -g -Wall -DDEBUG ${DEFS} ${CDEF} -DNT_CLOUD
8+#CFLAGS = -g -Wall -DDEBUG ${DEFS} ${CDEF} -DNT_CLOUD -DNT_NET_IPV6
89 #Option for release
9-#CFLAGS = -Wall ${DEFS} ${CDEF} -DNT_CLOUD
10+CFLAGS = -Wall ${DEFS} ${CDEF} -DNT_CLOUD -DNT_NET_IPV6
1011
1112 CDEF = -D_REENTRANT -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=700 -D_ISOC99_SOURCE
1213
--- a/Makefile.in
+++ b/Makefile.in
@@ -5,8 +5,9 @@
55
66 #Option for development
77 #CFLAGS = -g -Wall -DDEBUG ${DEFS} ${CDEF} -DNT_CLOUD
8+#CFLAGS = -g -Wall -DDEBUG ${DEFS} ${CDEF} -DNT_CLOUD -DNT_NET_IPV6
89 #Option for release
9-CFLAGS = -Wall ${DEFS} ${CDEF} -DNT_CLOUD
10+CFLAGS = -Wall ${DEFS} ${CDEF} -DNT_CLOUD -DNT_NET_IPV6
1011
1112 CDEF = -D_REENTRANT -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=700 -D_ISOC99_SOURCE
1213
--- a/config.h
+++ b/config.h
@@ -141,7 +141,7 @@
141141 #define PACKAGE_NAME "ntch"
142142
143143 /* Define to the full name and version of this package. */
144-#define PACKAGE_STRING "ntch 1.0.2.3"
144+#define PACKAGE_STRING "ntch 1.0.2.4"
145145
146146 /* Define to the one symbol short name of this package. */
147147 #define PACKAGE_TARNAME "ntch"
@@ -150,7 +150,7 @@
150150 #define PACKAGE_URL "https://sourceforge.jp/projects/ntch/"
151151
152152 /* Define to the version of this package. */
153-#define PACKAGE_VERSION "1.0.2.3"
153+#define PACKAGE_VERSION "1.0.2.4"
154154
155155 /* Define to 1 if you have the ANSI C header files. */
156156 #define STDC_HEADERS 1
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
11 #! /bin/sh
22 # Guess values for system-dependent variables and create Makefiles.
3-# Generated by GNU Autoconf 2.69 for ntch 1.0.2.3.
3+# Generated by GNU Autoconf 2.69 for ntch 1.0.2.4.
44 #
55 # Report bugs to <akohta001@gmail.com>.
66 #
@@ -580,8 +580,8 @@ MAKEFLAGS=
580580 # Identity of this package.
581581 PACKAGE_NAME='ntch'
582582 PACKAGE_TARNAME='ntch'
583-PACKAGE_VERSION='1.0.2.3'
584-PACKAGE_STRING='ntch 1.0.2.3'
583+PACKAGE_VERSION='1.0.2.4'
584+PACKAGE_STRING='ntch 1.0.2.4'
585585 PACKAGE_BUGREPORT='akohta001@gmail.com'
586586 PACKAGE_URL='https://sourceforge.jp/projects/ntch/'
587587
@@ -1230,7 +1230,7 @@ if test "$ac_init_help" = "long"; then
12301230 # Omit some internal or obsolete options to make the list less imposing.
12311231 # This message is too long to be a string in the A/UX 3.1 sh.
12321232 cat <<_ACEOF
1233-\`configure' configures ntch 1.0.2.3 to adapt to many kinds of systems.
1233+\`configure' configures ntch 1.0.2.4 to adapt to many kinds of systems.
12341234
12351235 Usage: $0 [OPTION]... [VAR=VALUE]...
12361236
@@ -1291,7 +1291,7 @@ fi
12911291
12921292 if test -n "$ac_init_help"; then
12931293 case $ac_init_help in
1294- short | recursive ) echo "Configuration of ntch 1.0.2.3:";;
1294+ short | recursive ) echo "Configuration of ntch 1.0.2.4:";;
12951295 esac
12961296 cat <<\_ACEOF
12971297
@@ -1372,7 +1372,7 @@ fi
13721372 test -n "$ac_init_help" && exit $ac_status
13731373 if $ac_init_version; then
13741374 cat <<\_ACEOF
1375-ntch configure 1.0.2.3
1375+ntch configure 1.0.2.4
13761376 generated by GNU Autoconf 2.69
13771377
13781378 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1795,7 +1795,7 @@ cat >config.log <<_ACEOF
17951795 This file contains any messages produced by compilers while
17961796 running configure, to aid debugging if configure makes a mistake.
17971797
1798-It was created by ntch $as_me 1.0.2.3, which was
1798+It was created by ntch $as_me 1.0.2.4, which was
17991799 generated by GNU Autoconf 2.69. Invocation command line was
18001800
18011801 $ $0 $@
@@ -4797,7 +4797,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
47974797 # report actual input values of CONFIG_FILES etc. instead of their
47984798 # values after options handling.
47994799 ac_log="
4800-This file was extended by ntch $as_me 1.0.2.3, which was
4800+This file was extended by ntch $as_me 1.0.2.4, which was
48014801 generated by GNU Autoconf 2.69. Invocation command line was
48024802
48034803 CONFIG_FILES = $CONFIG_FILES
@@ -4864,7 +4864,7 @@ _ACEOF
48644864 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
48654865 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
48664866 ac_cs_version="\\
4867-ntch config.status 1.0.2.3
4867+ntch config.status 1.0.2.4
48684868 configured by $0, generated by GNU Autoconf 2.69,
48694869 with options \\"\$ac_cs_config\\"
48704870
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
22 # Process this file with autoconf to produce a configure script.
33
44 AC_PREREQ([2.69])
5-AC_INIT([ntch], [1.0.2.3], [akohta001@gmail.com],[ntch],[https://sourceforge.jp/projects/ntch/])
5+AC_INIT([ntch], [1.0.2.4], [akohta001@gmail.com],[ntch],[https://sourceforge.jp/projects/ntch/])
66 AC_CONFIG_SRCDIR([src/main.c])
77 AC_CONFIG_HEADERS([config.h])
88
--- a/help.txt
+++ b/help.txt
@@ -1,5 +1,5 @@
11
2- ntch version 1.0.2.3
2+ ntch version 1.0.2.4
33
44 This file is part of ntch.
55
--- a/nce/nc_update_readcnt_db.php
+++ b/nce/nc_update_readcnt_db.php
@@ -53,8 +53,8 @@ QUERY2;
5353
5454 $query3 = <<< QUERY3
5555 update $table_name
56- set res_number="{$res_number}"
57- where record_type=1 and
56+ set res_number="{$res_number}" , record_type=1
57+ where (record_type=1 or record_type=4) and
5858 board_name="{$board_name}" and
5959 dat_name='{$dat_name}'
6060 QUERY3;
--- a/src/inc/config.h
+++ b/src/inc/config.h
@@ -141,7 +141,7 @@
141141 #define PACKAGE_NAME "ntch"
142142
143143 /* Define to the full name and version of this package. */
144-#define PACKAGE_STRING "ntch 1.0.2.3"
144+#define PACKAGE_STRING "ntch 1.0.2.4"
145145
146146 /* Define to the one symbol short name of this package. */
147147 #define PACKAGE_TARNAME "ntch"
@@ -150,7 +150,7 @@
150150 #define PACKAGE_URL "https://sourceforge.jp/projects/ntch/"
151151
152152 /* Define to the version of this package. */
153-#define PACKAGE_VERSION "1.0.2.3"
153+#define PACKAGE_VERSION "1.0.2.4"
154154
155155 /* Define to 1 if you have the ANSI C header files. */
156156 #define STDC_HEADERS 1
--- a/src/inc/net/nt_http.h
+++ b/src/inc/net/nt_http.h
@@ -84,6 +84,7 @@ extern BOOL nt_parse_server_name_and_board_name(const wchar_t *url,
8484 wchar_t *buf, size_t buf_size, wchar_t **server_name,
8585 wchar_t **board_name);
8686 extern wchar_t* nt_rid_sufix(const wchar_t *file_name);
87+extern BOOL nt_is_ipv6_addr(const char *addr, char **endp);
8788 extern BOOL url_encode(const char *src, char *out_buf, size_t out_buf_len);
8889 extern BOOL url_decode(const char *src, char *out_buf, size_t out_buf_len);
8990 #endif /* _NT_HTTP_H_ */
--- a/src/inc/net/nt_socket.h
+++ b/src/inc/net/nt_socket.h
@@ -22,7 +22,15 @@
2222
2323 typedef struct tag_nt_socket_t *nt_socket_tp;
2424 typedef struct tag_nt_socket_t{
25+#ifdef NT_NET_IPV6
26+ union{
27+ struct sockaddr_in _sockaddr_in;
28+ struct sockaddr_in6 _sockaddr_in6;
29+ };
30+ int addr_family;
31+#else
2532 struct sockaddr_in _sockaddr_in;
33+#endif
2634 nt_mutex_handle h_mutex;
2735 } nt_socket_t;
2836
--- a/src/net/nt_http.c
+++ b/src/net/nt_http.c
@@ -559,13 +559,38 @@ static nt_http_header_tp nt_http_init_header(const char *url)
559559 host[len] = '\0';
560560 }
561561
562+#ifdef NT_NET_IPV6
563+ if(nt_is_ipv6_addr(host, &cptr)){
564+ if(!ssl){
565+ *cptr = '\0';
566+ cptr++;
567+ memmove(host, host+1, cptr - host);
568+ }else{
569+ cptr++;
570+ }
571+ if(*cptr == ':'){
572+ port = atoi(cptr+1);
573+ port = (port == 0) ? -1 : port;
574+ *cptr = '\0';
575+ }
576+ port = atoi(cptr);
577+ port = (port == 0) ? -1 : port;
578+ }else{
579+ cptr = strchr(host, ':');
580+ if(cptr != NULL && strlen(cptr+1) > 0){
581+ port = atoi(cptr+1);
582+ port = (port == 0) ? -1 : port;
583+ *cptr = '\0';
584+ }
585+ }
586+#else
562587 cptr = strrchr(host, ':');
563588 if(cptr != NULL && strlen(cptr) > 0){
564589 port = atoi(cptr);
565590 port = (port == 0) ? -1 : port;
566591 *cptr = '\0';
567592 }
568-
593+#endif
569594 headerp = calloc(1, sizeof(nt_http_header_t));
570595 if(headerp == NULL){
571596 free(host);
--- a/src/net/nt_http_utils.c
+++ b/src/net/nt_http_utils.c
@@ -184,3 +184,24 @@ BOOL nt_parse_server_name_and_board_name(const wchar_t *url,
184184 *board_name = cptr2;
185185 return TRUE;
186186 }
187+
188+BOOL nt_is_ipv6_addr(const char *addr, char **endp)
189+{
190+ int len;
191+ char *cptr;
192+ if(!addr)
193+ return FALSE;
194+ len = strlen(addr);
195+ if(len == 0)
196+ return FALSE;
197+ if(addr[0] != '[')
198+ return FALSE;
199+
200+ cptr = strchr(addr+1, ']');
201+ if(!cptr)
202+ return FALSE;
203+
204+ *endp = cptr;
205+ return TRUE;
206+}
207+
--- a/src/net/nt_socket.c
+++ b/src/net/nt_socket.c
@@ -24,6 +24,7 @@
2424 #include <arpa/inet.h>
2525 #include <netdb.h>
2626 #include <unistd.h>
27+#include <assert.h>
2728
2829 #include "utils/nt_std_t.h"
2930 #include "net/nt_socket.h"
@@ -35,7 +36,15 @@ void nt_socket_free(nt_socket_tp socketp)
3536
3637 nt_socket_tp nt_socket_init(int port, char *addr)
3738 {
39+#ifdef NT_NET_IPV6
40+ struct addrinfo addr_limit;
41+ struct addrinfo *addr_out, *addr_list;
42+ struct sockaddr_in *s_addr;
43+ struct sockaddr_in6 *s_addr6;
44+
45+#else
3846 struct hostent *hostinfo;
47+#endif
3948
4049 nt_socket_tp ptr = malloc(sizeof(nt_socket_t));
4150 if(ptr == NULL)
@@ -51,8 +60,44 @@ nt_socket_tp nt_socket_init(int port, char *addr)
5160 return NULL;
5261 }
5362
54- ptr->_sockaddr_in.sin_family = AF_INET;
5563 ptr->_sockaddr_in.sin_port = htons(port);
64+
65+#ifdef NT_NET_IPV6
66+ memset(&addr_limit, 0, sizeof(addr_limit));
67+ addr_limit.ai_family = AF_UNSPEC;
68+ addr_limit.ai_socktype = SOCK_STREAM;
69+ addr_limit.ai_protocol = IPPROTO_TCP;
70+ if(0 != getaddrinfo(addr, NULL, &addr_limit, &addr_out)){
71+ free(ptr);
72+ return NULL;
73+ }
74+
75+ for(addr_list = addr_out; addr_list != NULL;
76+ addr_list = addr_list->ai_next){
77+ if(!addr_list->ai_addr)
78+ continue;
79+ switch(addr_list->ai_family){
80+ case AF_INET:
81+ assert(addr_list->ai_addrlen == sizeof(struct sockaddr_in));
82+ ptr->addr_family = AF_INET;
83+ s_addr = (struct sockaddr_in*)addr_list->ai_addr;
84+ ptr->_sockaddr_in.sin_family = AF_INET;
85+ memcpy(&ptr->_sockaddr_in.sin_addr.s_addr,
86+ &s_addr->sin_addr.s_addr, sizeof(struct in_addr));
87+ return ptr;
88+ case AF_INET6:
89+ assert(addr_list->ai_addrlen == sizeof(struct sockaddr_in6));
90+ ptr->addr_family = AF_INET6;
91+ s_addr6 = (struct sockaddr_in6*)addr_list->ai_addr;
92+ ptr->_sockaddr_in6.sin6_family = AF_INET6;
93+ memcpy(&ptr->_sockaddr_in6.sin6_addr.s6_addr,
94+ s_addr6->sin6_addr.s6_addr, sizeof(struct in6_addr));
95+ return ptr;
96+ }
97+ }
98+ freeaddrinfo(addr_out);
99+#else
100+ ptr->_sockaddr_in.sin_family = AF_INET;
56101 ptr->_sockaddr_in.sin_addr.s_addr = inet_addr(addr);
57102 if(ptr->_sockaddr_in.sin_addr.s_addr == 0xffffffff){
58103 hostinfo = gethostbyname(addr);
@@ -65,6 +110,7 @@ nt_socket_tp nt_socket_init(int port, char *addr)
65110 memcpy(&ptr->_sockaddr_in.sin_addr.s_addr,
66111 hostinfo->h_addr_list[0], 4);
67112 }
113+#endif
68114 return ptr;
69115 }
70116
@@ -74,11 +120,28 @@ int nt_socket_connect(nt_socket_tp socketp, char* data, int data_len)
74120 int len;
75121 int result;
76122
123+#ifdef NT_NET_IPV6
124+ switch(socketp->addr_family){
125+ case AF_INET:
126+ len = sizeof(socketp->_sockaddr_in);
127+ break;
128+ case AF_INET6:
129+ len = sizeof(socketp->_sockaddr_in6);
130+ break;
131+ default:
132+ assert(0);
133+ }
134+ sockfd = socket(socketp->addr_family, SOCK_STREAM, 0);
135+ if(sockfd == -1)
136+ return -1;
137+
138+#else
77139 sockfd = socket(AF_INET, SOCK_STREAM, 0);
78140 if(sockfd == -1)
79141 return -1;
80- len = sizeof(socketp->_sockaddr_in);
81142
143+ len = sizeof(socketp->_sockaddr_in);
144+#endif
82145 nt_mutex_lock(socketp->h_mutex);
83146 result = connect(sockfd,
84147 (struct sockaddr *)&(socketp->_sockaddr_in), len);
--- a/src/usr/usr_db_t.c
+++ b/src/usr/usr_db_t.c
@@ -477,6 +477,7 @@ char* nt_usr_db_board_last_query(nt_usr_db_handle db_handle,
477477 rc = sqlite3_step(stmt);
478478 if(rc != SQLITE_DONE){
479479 free(result);
480+ result = NULL;
480481 goto ERROR_TRAP;
481482 }
482483 ERROR_TRAP:
--- a/src/utils/crypt.c
+++ b/src/utils/crypt.c
@@ -155,19 +155,19 @@ static nt_crypt_handle nt_crypt_alloc(const char *rfc2898_salt,
155155
156156 cryptp = malloc(sizeof(nt_crypt_t));
157157 if(!cryptp)
158- return FALSE;
158+ return NULL;
159159
160160 if(!validate_rfc2898param(
161161 rfc2898_salt, rfc2898_iteration, error_msg)){
162162 free(cryptp);
163- return FALSE;
163+ return NULL;
164164 }
165165 if(!PKCS5_PBKDF2_HMAC_SHA1(aes256pass, strlen(aes256pass),
166166 (const unsigned char*)rfc2898_salt, strlen(rfc2898_salt),
167167 rfc2898_iteration, 32+16, result)){
168168 *error_msg = "PKCS5_PBKDF2_HMAC_SHA1 呼び出しに失敗しました";
169169 free(cryptp);
170- return FALSE;
170+ return NULL;
171171 }
172172
173173 memcpy(cryptp->key, result, 32);
Show on old repository browser