Index: EcnlProtoTool/trunk/ntshell/webserver/httpd.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/webserver/httpd.c	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/webserver/httpd.c	(revision 436)
@@ -1,6 +1,6 @@
 /*
- *  TOPPERS ECHONET Lite Communication Middleware
+ *  TOPPERS PROJECT Home Network Working Group Software
  *
- *  Copyright (C) 2017 Cores Co., Ltd. Japan
+ *  Copyright (C) 2017-2019 Cores Co., Ltd. Japan
  *
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
@@ -62,7 +62,5 @@
 SYSTIM httpd_time;
 struct httpd_state *uploding;
-extern char command[256];
-
-extern int execute_command(int wait);
+static char command[256];
 
 /*  TCP 送受信ウィンドバッファ  */
@@ -367,5 +365,5 @@
 
 	if (s->message.body_is_final) {
-		syslog(LOG_ERROR, "\n\n *** Error http_body_is_final() should return 1 "
+		ntstdio_printf(&ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n"
 			"on last on_body callback call "
 			"but it doesn't! ***\n\n");
@@ -405,5 +403,5 @@
 	struct httpd_state *s = get_context(p);
 	if (s->message.should_keep_alive != http_should_keep_alive(p)) {
-		syslog(LOG_ERROR, "\n\n *** Error http_should_keep_alive() should have same "
+		ntstdio_printf(&ntstdio, "\n\n *** Error http_should_keep_alive() should have same \n"
 			"value in both on_message_complete and on_headers_complete "
 			"but it doesn't! ***\n\n");
@@ -414,5 +412,5 @@
 		http_body_is_final(p) &&
 		!s->message.body_is_final) {
-		syslog(LOG_ERROR, "\n\n *** Error http_body_is_final() should return 1 "
+		ntstdio_printf(&ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n"
 			"on last on_body callback call "
 			"but it doesn't! ***\n\n");
@@ -486,5 +484,5 @@
 		slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
 		if (slen < 0) {
-			syslog(LOG_ERROR, "send_file#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+			ntstdio_printf(&ntstdio, "send_file#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 			s->state = STATE_CLOSING;
 			break;
@@ -499,5 +497,5 @@
 		len = httpd_fs_read(&s->file, buf, len);
 		if (len <= 0) {
-			syslog(LOG_ERROR, "send_file#httpd_fs_read(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, len);
+			ntstdio_printf(&ntstdio, "send_file#httpd_fs_read(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, len);
 			break;
 		}
@@ -507,5 +505,5 @@
 
 		if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) {
-			syslog(LOG_ERROR, "send_file#tcp_snd_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+			ntstdio_printf(&ntstdio, "send_file#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 			s->state = STATE_CLOSING;
 			break;
@@ -529,5 +527,5 @@
 		slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
 		if (slen < 0) {
-			syslog(LOG_ERROR, "send_data#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+			ntstdio_printf(&ntstdio, "send_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 			s->state = STATE_CLOSING;
 			break;
@@ -546,5 +544,5 @@
 
 		if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) {
-			syslog(LOG_ERROR, "send_data#tcp_snd_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+			ntstdio_printf(&ntstdio, "send_data#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 			s->state = STATE_CLOSING;
 			break;
@@ -660,6 +658,6 @@
 		len = sizeof(http_content_length) - 1;
 		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, ntlibc_strlen(s->temp), TMO_FEVR);
+		len = ntstdio_snprintf(s->temp, sizeof(s->temp), "%d\r\n", s->file.len);
+		tcp_snd_dat(s->cepid, (void *)s->temp, len, TMO_FEVR);
 	}
 
@@ -706,20 +704,26 @@
 		break;
 	case OUT_STATE_WAIT_POST_BODY:
+		//ntstdio_printf(&ntstdio, "wait post body\n");
 		s->out.wait = true;
 		break;
 	case OUT_STATE_BODY_RECEIVED:
+		//ntstdio_printf(&ntstdio, "body received\n");
 		s->out.statushdr = http_header_200;
 		s->out.state = OUT_STATE_SEND_HEADER;
 		break;
 	case OUT_STATE_SEND_HEADER:
+		//ntstdio_printf(&ntstdio, "send header\n");
 		send_headers(s, s->out.statushdr);
 		break;
 	case OUT_STATE_SEND_FILE:
+		//ntstdio_printf(&ntstdio, "send file %d\n", s->file.len);
 		send_file(s);
 		break;
 	case OUT_STATE_SEND_DATA:
+		//ntstdio_printf(&ntstdio, "send data %d\n", s->response_len);
 		send_data(s);
 		break;
 	case OUT_STATE_SEND_END:
+		//ntstdio_printf(&ntstdio, "send end\n");
 		s->out.wait = true;
 		if (s->message.should_keep_alive && s->reset == 0) {
@@ -779,5 +783,5 @@
 	slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
 	if (slen < 0) {
-		syslog(LOG_ERROR, "send_ws_data#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+		ntstdio_printf(&ntstdio, "send_ws_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 		return;
 	}
@@ -843,5 +847,5 @@
 				//}
 			}
-			syslog(LOG_ERROR, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);
+			ntstdio_printf(&ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);
 			uploding = NULL;
 			s->state = STATE_CLOSING;
@@ -851,5 +855,5 @@
 		tcp_rel_buf(s->cepid, done);
 		if (s->parser.http_errno != HPE_OK) {
-			syslog(LOG_ERROR, "http_parser error %s.%d => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno);
+			ntstdio_printf(&ntstdio, "http_parser error %s.%d => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno);
 			uploding = NULL;
 			s->state = STATE_CLOSING;
@@ -876,5 +880,5 @@
 					break;
 				}
-				syslog(LOG_ERROR, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);
+				ntstdio_printf(&ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);
 				s->state = STATE_CLOSING;
 				break;
@@ -932,5 +936,5 @@
 		ret2 = get_tim(&httpd_time);
 		if (ret2 != E_OK) {
-			syslog(LOG_ERROR, "get_tim");
+			ntstdio_printf(&ntstdio, "get_tim\n");
 			return;
 		}
@@ -939,7 +943,7 @@
 		case STATE_DISCONNECTED:
 			memset(&s->dst, 0, sizeof(s->dst));
-			if ((ret = TCP_ACP_CEP(s->cepid, TCP_REPID, (T_IPV4EP *)s->dst, TMO_FEVR)) != E_OK) {
-				syslog(LOG_ERROR, "tcp_acp_cep(%d) => %d", s->cepid, ret);
-				tslp_tsk(100);	// TODO
+			if ((ret = tcp_acp_cep(s->cepid, TCP_REPID, (T_IPV4EP *)s->dst, TMO_FEVR)) != E_OK) {
+				ntstdio_printf(&ntstdio, "tcp_acp_cep(%d) => %d\n", s->cepid, ret);
+				tslp_tsk(100 * 1000);	// TODO
 				s->state = STATE_CLOSING;
 				break;
@@ -974,5 +978,5 @@
 			break;
 		case STATE_RESET:
-			execute_command(0);
+			cmd_execute(command, NULL);
 			s->state = STATE_DISCONNECTED;
 			break;
@@ -980,6 +984,6 @@
 
 		if (s->in.wait && s->out.wait) {
-			tslp_tsk(100);
-		}
-	}
-}
+			tslp_tsk(100 * 1000);
+		}
+	}
+}
