Index: EcnlProtoTool/trunk/ntshell/webserver/httpd.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/webserver/httpd.c	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/webserver/httpd.c	(revision 331)
@@ -43,6 +43,9 @@
 #include "syssvc/syslog.h"
 #include "http-strings.h"
+#include <tinet_defs.h>
+#include <tinet_config.h>
 #include "netinet/in.h"
 #include "netinet/in_var.h"
+#include "netinet/in_itron.h"
 #include "httpd.h"
 #include "httpd-fs.h"
@@ -50,5 +53,6 @@
 #include "base64.h"
 #include "sha1.h"
-#include "ntstdio.h"
+#include "util/ntstdio.h"
+#include "core/ntlibc.h"
 
 #define TRUE 1
@@ -82,4 +86,5 @@
 
 #ifndef _MSC_VER
+#define strnlen httpd_strnlen
 /* strnlen() is a POSIX.2008 addition. Can't rely on it being available so
  * define it ourselves.
@@ -99,5 +104,5 @@
 void strcpy_s(char *dst, int size, const char *src)
 {
-	int slen = strlen(src);
+	int slen = ntlibc_strlen(src);
 	if (slen >= size)
 		slen = size - 1;
@@ -108,6 +113,6 @@
 void strcat_s(char *dst, int size, const char *src)
 {
-	int dlen = strlen(dst);
-	int slen = strlen(src);
+	int dlen = ntlibc_strlen(dst);
+	int slen = ntlibc_strlen(src);
 	if (dlen + slen >= size)
 		slen = size - 1 - dlen;
@@ -223,26 +228,26 @@
 	struct message *m = &s->message;
 
-	if (strncmp("Referer", buf, len) == 0) {
+	if (ntlibc_strncmp("Referer", buf, len) == 0) {
 		m->num_headers = 1;
 	}
-	else if (strncmp("Host", buf, len) == 0) {
+	else if (ntlibc_strncmp("Host", buf, len) == 0) {
 		m->num_headers = 2;
 	}
-	else if (strncmp("Upgrade", buf, len) == 0) {
+	else if (ntlibc_strncmp("Upgrade", buf, len) == 0) {
 		m->num_headers = 3;
 	}
-	else if (strncmp("Connection", buf, len) == 0) {
+	else if (ntlibc_strncmp("Connection", buf, len) == 0) {
 		m->num_headers = 4;
 	}
-	else if (strncmp("Sec-WebSocket-Key", buf, len) == 0) {
+	else if (ntlibc_strncmp("Sec-WebSocket-Key", buf, len) == 0) {
 		m->num_headers = 5;
 	}
-	else if (strncmp("Origin", buf, len) == 0) {
+	else if (ntlibc_strncmp("Origin", buf, len) == 0) {
 		m->num_headers = 6;
 	}
-	else if (strncmp("Sec-WebSocket-Protocol", buf, len) == 0) {
+	else if (ntlibc_strncmp("Sec-WebSocket-Protocol", buf, len) == 0) {
 		m->num_headers = 7;
 	}
-	else if (strncmp("Sec-WebSocket-Version", buf, len) == 0) {
+	else if (ntlibc_strncmp("Sec-WebSocket-Version", buf, len) == 0) {
 		m->num_headers = 8;
 	}
@@ -329,5 +334,5 @@
 			s->in.state = IN_STATE_UPLOAD;
 		}
-		else if (strcmp(s->filename, uploding->filename) == 0) {
+		else if (ntlibc_strcmp(s->filename, uploding->filename) == 0) {
 			ntstdio_printf(&ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
 			goto error;
@@ -559,5 +564,5 @@
 	char *ptr;
 
-	len = strlen(statushdr);
+	len = ntlibc_strlen(statushdr);
 	tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR);
 
@@ -574,9 +579,9 @@
 			tcp_snd_dat(s->cepid, "/~", len, TMO_FEVR);
 		}
-		len = strlen(s->filename);
+		len = ntlibc_strlen(s->filename);
 		tcp_snd_dat(s->cepid, s->filename, len, TMO_FEVR);
 		if (s->query != NULL) {
 			tcp_snd_dat(s->cepid, "?", 1, TMO_FEVR);
-			len = strlen(s->query);
+			len = ntlibc_strlen(s->query);
 			tcp_snd_dat(s->cepid, s->query, len, TMO_FEVR);
 		}
@@ -590,58 +595,58 @@
 		tcp_snd_dat(s->cepid, (void *)http_content_type_binary, len, TMO_FEVR);
 	}
-	else if (strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 ||
-		strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) {
+	else if (ntlibc_strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 ||
+		ntlibc_strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) {
 		len = sizeof(http_content_type_html) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_html, len, TMO_FEVR);
 	}
-	else if (strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) {
+	else if (ntlibc_strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) {
 		len = sizeof(http_content_type_css) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_css, len, TMO_FEVR);
 	}
-	else if (strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) {
+	else if (ntlibc_strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) {
 		len = sizeof(http_content_type_js) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_js, len, TMO_FEVR);
 	}
-	else if (strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) {
+	else if (ntlibc_strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) {
 		len = sizeof(http_content_type_json) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_json, len, TMO_FEVR);
 	}
-	else if (strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) {
+	else if (ntlibc_strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) {
 		len = sizeof(http_content_type_png) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_png, len, TMO_FEVR);
 	}
-	else if (strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) {
+	else if (ntlibc_strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) {
 		len = sizeof(http_content_type_gif) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_gif, len, TMO_FEVR);
 	}
-	else if (strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) {
+	else if (ntlibc_strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) {
 		len = sizeof(http_content_type_jpg) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_jpg, len, TMO_FEVR);
 	}
-	else if (strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) {
+	else if (ntlibc_strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) {
 		len = sizeof(http_content_type_svg) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_svg, len, TMO_FEVR);
 	}
-	else if (strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) {
+	else if (ntlibc_strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) {
 		len = sizeof(http_content_type_text) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_text, len, TMO_FEVR);
 	}
-	else if (strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) {
+	else if (ntlibc_strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) {
 		len = sizeof(http_content_type_eot) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_eot, len, TMO_FEVR);
 	}
-	else if (strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) {
+	else if (ntlibc_strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) {
 		len = sizeof(http_content_type_ttf) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_ttf, len, TMO_FEVR);
 	}
-	else if (strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) {
+	else if (ntlibc_strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) {
 		len = sizeof(http_content_type_woff) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_woff, len, TMO_FEVR);
 	}
-	else if (strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) {
+	else if (ntlibc_strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) {
 		len = sizeof(http_content_type_woff2) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_woff2, len, TMO_FEVR);
 	}
-	else if (strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) {
+	else if (ntlibc_strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) {
 		len = sizeof(http_content_type_ico) - 1;
 		tcp_snd_dat(s->cepid, (void *)http_content_type_ico, len, TMO_FEVR);
@@ -656,5 +661,5 @@
 		tcp_snd_dat(s->cepid, (void *)http_content_length, len, TMO_FEVR);
 		ntstdio_snprintf(s->temp, sizeof(s->temp), "%d\r\n", s->file.len);
-		tcp_snd_dat(s->cepid, (void *)s->temp, strlen(s->temp), TMO_FEVR);
+		tcp_snd_dat(s->cepid, (void *)s->temp, ntlibc_strlen(s->temp), TMO_FEVR);
 	}
 
@@ -732,10 +737,10 @@
 	int len;
 
-	len = strlen(statushdr);
+	len = ntlibc_strlen(statushdr);
 	tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR);
 
 	len = sizeof(http_upgrade) - 1;
 	tcp_snd_dat(s->cepid, (void *)http_upgrade, len, TMO_FEVR);
-	len = strlen(s->message.upgrade);
+	len = ntlibc_strlen(s->message.upgrade);
 	tcp_snd_dat(s->cepid, s->message.upgrade, len, TMO_FEVR);
 	len = sizeof(http_crnl) - 1;
@@ -744,5 +749,5 @@
 	len = sizeof(http_connection) - 1;
 	tcp_snd_dat(s->cepid, (void *)http_connection, len, TMO_FEVR);
-	len = strlen(s->message.connection);
+	len = ntlibc_strlen(s->message.connection);
 	tcp_snd_dat(s->cepid, s->message.connection, len, TMO_FEVR);
 	len = sizeof(http_crnl) - 1;
@@ -751,5 +756,5 @@
 	len = sizeof(http_sec_websocket_accept) - 1;
 	tcp_snd_dat(s->cepid, (void *)http_sec_websocket_accept, len, TMO_FEVR);
-	len = strlen(s->message.response_key);
+	len = ntlibc_strlen(s->message.response_key);
 	tcp_snd_dat(s->cepid, s->message.response_key, len, TMO_FEVR);
 	len = sizeof(http_crnl) - 1;
@@ -758,5 +763,5 @@
 	len = sizeof(http_sec_websocket_protocol) - 1;
 	tcp_snd_dat(s->cepid, (void *)http_sec_websocket_protocol, len, TMO_FEVR);
-	len = strlen(s->message.sec_websocket_protocol);
+	len = ntlibc_strlen(s->message.sec_websocket_protocol);
 	tcp_snd_dat(s->cepid, s->message.sec_websocket_protocol, len, TMO_FEVR);
 	len = sizeof(http_crnl) - 1;
