source: azure_iot_hub/trunk/asp3_dcre/tinet/netapp/wwws.c@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 51.4 KB
Line 
1/*
2 * TINET (TCP/IP Protocol Stack)
3 *
4 * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
5 * Tomakomai National College of Technology, JAPAN
6 *
7 * 上記著作権者
8は,以下の (1)~(4) の条件か,Free Software Foundation
9 * によってå…
10¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
11 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
12 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
13å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
14 * 利用と呼ぶ)することを無償で許諾する.
15 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
16 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
17 * スコード中に含まれていること.
18 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
19 * 用できる形で再é…
20å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
21å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
22 * 者
23マニュアルなど)に,上記の著作権表示,この利用条件および下記
24 * の無保証規定を掲載すること.
25 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
26 * 用できない形で再é…
27å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®æ¡ä»¶ã‚’満たすこと.
28 * (a) 再é…
29å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
30マニュアルなど)に,上記の著
31 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
32 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
33 * 害からも,上記著作権者
34およびTOPPERSプロジェクトをå…
35è²¬ã™ã‚‹ã“と.
36 *
37 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
38お
39 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
40 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
41 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
42 *
43 * @(#) $Id: wwws.c 388 2019-05-22 11:25:18Z coas-nagasima $
44 */
45
46/*
47 * WWW サーバ
48 *
49 * ・送受信タスク同一型
50 * ・ノンブロッキングコール
51 * ・省コピー API
52 * ・IPv4/IPv6
53 */
54
55#include <stdlib.h>
56#include <string.h>
57
58#ifdef TARGET_KERNEL_ASP
59
60#include <kernel.h>
61#include <sil.h>
62#include <t_syslog.h>
63#include "kernel/kernel_impl.h"
64#include "target_config.h"
65#include "target_syssvc.h"
66#include "target_stddef.h"
67#include "kernel_cfg.h"
68#include "tinet_cfg.h"
69
70#endif /* of #ifdef TARGET_KERNEL_ASP */
71
72#ifdef TARGET_KERNEL_JSP
73
74#include <s_services.h>
75#include <t_services.h>
76#include "kernel_id.h"
77#include "tinet_id.h"
78
79#endif /* of #ifdef TARGET_KERNEL_JSP */
80
81#include <tinet_defs.h>
82#include <tinet_config.h>
83
84#include <net/if.h>
85#include <net/if_ppp.h>
86#include <net/if_loop.h>
87#include <net/ethernet.h>
88#include <net/net.h>
89#include <net/net_endian.h>
90#include <net/net_buf.h>
91#include <net/net_count.h>
92
93#include <netinet/in.h>
94#include <netinet/in_itron.h>
95
96#include <netapp/netapp.h>
97#include <netapp/netapp_var.h>
98#include <netapp/wwws.h>
99
100#ifdef USE_WWW_SRV
101
102/*
103 * 送受信 API の選択
104 */
105
106#define EOF (-1)
107
108typedef struct file {
109 ER (*func)(ID cepid, T_WWW_RWBUF *srbuf);
110 char *uri;
111 } T_FILE;
112
113typedef struct status {
114 uint16_t code;
115 uint8_t *reason;
116 } T_STATUS;
117
118/*
119 * 関数
120 */
121
122static ER index_html(ID cepid, T_WWW_RWBUF *srbuf);
123
124#if NET_COUNT_ENABLE
125
126static ER stat_html(ID cepid, T_WWW_RWBUF *srbuf);
127
128#endif /* of #if NET_COUNT_ENABLE */
129
130#ifdef USE_TCP_EXTENTIONS
131
132#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
133
134#if NUM_WWW_SRV_TASKS >= 2 /* 2 を超
135える個数は想定していない。 */
136
137#define WWW4_SRV_TASK WWW_SRV_TASK1
138#define WWW6_SRV_TASK WWW_SRV_TASK2
139
140#else /* of #if NUM_WWW_SRV_TASKS >= 2 */
141
142#define WWW4_SRV_TASK WWW_SRV_TASK1
143#define WWW6_SRV_TASK WWW_SRV_TASK1
144
145#endif /* of #if NUM_WWW_SRV_TASKS >= 2 */
146
147#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
148
149#define WWW4_SRV_TASK WWW_SRV_TASK1
150#define WWW6_SRV_TASK WWW_SRV_TASK1
151
152#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
153
154#endif /* of #ifdef USE_TCP_EXTENTIONS */
155
156
157/*
158 * å…
159¨åŸŸå¤‰æ•°
160 */
161
162/* TCP 送受信ウィンドバッファ */
163
164#ifndef TCP_CFG_SWBUF_CSAVE
165uint8_t www_srv_swbuf[NUM_WWW_SRV_TASKS][WWW_SRV_SWBUF_SIZE];
166#endif
167
168#ifndef TCP_CFG_RWBUF_CSAVE
169uint8_t www_srv_rwbuf[NUM_WWW_SRV_TASKS][WWW_SRV_RWBUF_SIZE];
170#endif
171
172/*
173 * 変数
174 */
175
176SYSTIM srv_start;
177
178static const T_FILE file[] = {
179 { index_html, "/" },
180 { index_html, "/index.html" },
181
182#if NET_COUNT_ENABLE
183
184 { stat_html, "/stat.html" },
185
186#endif /* of #if NET_COUNT_ENABLE */
187 };
188
189#define NUM_FILES (sizeof(file) / sizeof(T_FILE))
190
191static const char *status[] = {
192 "200 OK",
193 "404 Not Found",
194 };
195
196#define NUM_STATUS (sizeof(status) / sizeof(T_STATUS))
197
198#define ST_OK 0
199#define ST_NOT_FOUND 1
200
201/*
202 * 接続相手の情
203報構造体
204 */
205
206#ifdef NUM_WWW4_SRV_TASKS
207#undef NUM_WWW4_SRV_TASKS
208#endif
209#define NUM_WWW4_SRV_TASKS 1
210
211typedef struct t_www_srv_info {
212 ID cepid; /* 通信端点 ID */
213 ID repid; /* 受付口 ID */
214 T_IPEP dst; /* 接続相手アドレス情
215å ± */
216 } T_WWW_SRV_INFO;
217
218#define INDEX_SRV_INFO(id) ((id)-1)
219
220#ifdef USE_TCP_EXTENTIONS
221
222static T_WWW_SRV_INFO www_srv_info[NUM_WWW_SRV_TASKS];
223 /* 2 を超
224える個数は想定していない。 */
225
226#else /* of #ifdef USE_TCP_EXTENTIONS */
227
228static T_WWW_SRV_INFO www_srv_info[] = {
229
230#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
231
232 { WWW4_SRV_CEPID1, WWW4_SRV_REPID },
233
234#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
235
236 { WWW_SRV_CEPID1, WWW_SRV_REPID },
237
238#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
239
240#if NUM_WWW_SRV_TASKS >= 2 /* 2 を超
241える個数は想定していない。 */
242 { WWW_SRV_CEPID2, WWW_SRV_REPID },
243#endif
244
245 };
246
247#endif /* of #ifdef USE_TCP_EXTENTIONS */
248
249#ifdef USE_COPYSAVE_API
250
251/*
252 * get_char -- 一文字å…
253¥åŠ›ã™ã‚‹ã€‚
254 */
255
256static int_t
257get_char (ID cepid, T_WWW_RWBUF *srbuf)
258{
259 int_t len, ch;
260 ER error;
261
262 if (srbuf->unget) {
263 ch = srbuf->unget;
264 srbuf->unget = 0;
265 }
266 else {
267 if (srbuf->rbuf.index >= srbuf->rbuf.len) {
268 if ((error = tcp_rel_buf(cepid, srbuf->rbuf.len)) != E_OK)
269 syslog(LOG_WARNING, "[WWWn:%02u REL] tcp_rel_buf error: %s",
270 cepid, itron_strerror(error));
271 srbuf->rbuf.index = 0;
272 if ((len = tcp_rcv_buf(cepid, (void**)&srbuf->rbuf.buf, TMO_FEVR)) <= 0) {
273 if (len < 0)
274 syslog(LOG_WARNING, "[WWWn:%02u RCV] tcp_rcv_buf error: %s",
275 cepid, itron_strerror(len));
276 srbuf->rbuf.len = 0;
277 return EOF;
278 }
279 else
280 srbuf->rbuf.len = len;
281 }
282 ch = srbuf->rbuf.buf[srbuf->rbuf.index ++];
283 }
284 return ch;
285 }
286
287/*
288 * flush_sbuf -- 送信バッファをフラッシュする。
289 */
290
291static ER
292flush_sbuf (ID cepid, T_WWW_RWBUF *srbuf)
293{
294 ER_UINT error;
295
296 error = tcp_snd_buf(cepid, srbuf->sbuf.index);
297 srbuf->sbuf.index = srbuf->sbuf.len = 0;
298
299 return error;
300 }
301
302/*
303 * put_str -- 文字列を出力する。
304 */
305
306static uint_t
307put_str (ID cepid, T_WWW_RWBUF *srbuf, const char *str)
308{
309 ER error;
310 ER_UINT blen;
311 uint16_t len, off = 0;
312
313 len = strlen(str);
314 while (len > 0) {
315 if (srbuf->sbuf.index >= srbuf->sbuf.len)
316 if ((error = flush_sbuf(cepid, srbuf)) != E_OK) {
317 syslog(LOG_WARNING, "[WWWn:%02u SND] error: %s", cepid, itron_strerror(error));
318 return 0;
319 }
320
321 if (srbuf->sbuf.len == 0) {
322 if ((blen = tcp_get_buf(cepid, (void**)&srbuf->sbuf.buf, TMO_FEVR)) < 0) {
323 syslog(LOG_WARNING, "[WWWn:%02u GET] error: %s", cepid, itron_strerror(srbuf->sbuf.len));
324 return 0;
325 }
326 srbuf->sbuf.len = (uint16_t)blen;
327 }
328
329 if (len > srbuf->sbuf.len - srbuf->sbuf.index)
330 blen = srbuf->sbuf.len - srbuf->sbuf.index;
331 else
332 blen = len;
333 memcpy(&srbuf->sbuf.buf[srbuf->sbuf.index], str + off, blen);
334 srbuf->sbuf.index += (uint16_t)blen;
335 off += (uint16_t)blen;
336 len -= (uint16_t)blen;
337 }
338
339 return off;
340 }
341
342#else /* of #ifdef USE_COPYSAVE_API */
343
344/*
345 * get_char -- 一文字å…
346¥åŠ›ã™ã‚‹ã€‚
347 */
348
349static int_t
350get_char (ID cepid, T_WWW_RWBUF *srbuf)
351{
352 int_t len, ch;
353
354 if (srbuf->unget) {
355 ch = srbuf->unget;
356 srbuf->unget = 0;
357 }
358 else {
359 if (srbuf->rbuf.index >= srbuf->rbuf.len) {
360 if ((len = tcp_rcv_dat(cepid, srbuf->rbuf.buf, sizeof(srbuf->rbuf.buf), TMO_FEVR)) <= 0) {
361 if (len < 0) {
362 syslog(LOG_WARNING, "[WWWn:%02u RCV] error: %s",
363 cepid, itron_strerror(len));
364 }
365 return EOF;
366 }
367 else {
368 srbuf->rbuf.len = len;
369 srbuf->rbuf.index = 0;
370 }
371 }
372 ch = srbuf->rbuf.buf[srbuf->rbuf.index ++];
373 }
374 return ch;
375 }
376
377/*
378 * flush_sbuf -- 送信バッファをフラッシュする。
379 */
380
381static ER
382flush_sbuf (ID cepid, T_WWW_RWBUF *srbuf)
383{
384 ER_UINT len = E_OK;
385 uint16_t off = 0;
386
387 while (off < srbuf->sbuf.index) {
388 if ((len = tcp_snd_dat(cepid, srbuf->sbuf.buf + off, srbuf->sbuf.index - off, TMO_FEVR)) < 0)
389 break;
390 off += len;
391 }
392 srbuf->sbuf.index = 0;
393
394 return len < 0 ? len : E_OK;
395 }
396
397/*
398 * put_str -- 文字列を出力する。
399 */
400
401static uint16_t
402put_str (ID cepid, T_WWW_RWBUF *srbuf, const char *str)
403{
404 ER error;
405 uint16_t blen, len, off = 0;
406
407 len = strlen(str);
408 while (len > 0) {
409 if (srbuf->sbuf.index >= srbuf->sbuf.len)
410 if ((error = flush_sbuf(cepid, srbuf)) != E_OK) {
411 syslog(LOG_WARNING, "[WWWn:%02u SND] error: %s", cepid, itron_strerror(error));
412 return 0;
413 }
414 if (len > srbuf->sbuf.len - srbuf->sbuf.index)
415 blen = srbuf->sbuf.len - srbuf->sbuf.index;
416 else
417 blen = len;
418 memcpy(&srbuf->sbuf.buf[srbuf->sbuf.index], str + off, blen);
419 srbuf->sbuf.index += blen;
420 off += blen;
421 len -= blen;
422 }
423
424 return off;
425 }
426
427#endif /* of #ifdef USE_COPYSAVE_API */
428
429/*
430 * get_line -- 一行å…
431¥åŠ›ã™ã‚‹ã€‚
432 */
433
434static uint16_t
435get_line (ID cepid, T_WWW_LINE *line, T_WWW_RWBUF *srbuf)
436{
437 int_t ch = 0;
438 uint16_t len;
439 char *p, *t;
440
441 p = line->buf;
442 t = line->buf + WWW_LINE_SIZE;
443 while (p < t && (ch = get_char(cepid, srbuf)) != EOF && ch != '\n' && ch != '\r')
444 *p ++ = ch;
445 *p = '\0';
446 len = p - line->buf;
447 if (p >= t) {
448 while ((ch = get_char(cepid, srbuf)) != EOF && ch != '\n' && ch != '\r')
449 len ++;
450 }
451 if (ch == '\r') {
452 len ++;
453 if ((ch = get_char(cepid, srbuf)) != EOF && ch != '\n')
454 srbuf->unget = ch;
455 }
456 if (ch == '\n')
457 len ++;
458 line->len = len;
459 return p - line->buf;
460 }
461
462#if NET_COUNT_ENABLE
463
464#ifdef _int64_
465#define VAL_TYPE uint64_t
466#else
467#define VAL_TYPE uint32_t
468#endif
469
470/*
471 * convert -- 数値変換
472 */
473
474static int_t
475convert (char *buf, VAL_TYPE val, int_t radix, int_t width, bool_t minus, char padchar)
476{
477 static const char radhex[] = "0123456789abcdef";
478
479 char digits[23], *start;
480 int_t ix, pad;
481
482 ix = 0;
483 start = buf;
484 do {
485 digits[ix ++] = radhex[val % radix];
486 val /= radix;
487 } while (val != 0);
488 if (minus)
489 digits[ix ++] = '-';
490 for (pad = ix; pad < width; pad ++)
491 *buf ++ = padchar;
492 while (ix -- > 0)
493 *buf ++ = digits[ix];
494 *buf = '\0';
495 return buf - start;
496 }
497
498#endif /* of #if NET_COUNT_ENABLE */
499
500/*
501 * split_fields -- フィールドに分割する。
502 */
503
504static void
505split_fields (T_WWW_LINE *line, char *delim)
506{
507 char *p, quote;
508 int_t ix = 0;
509
510 line->off[ix ++] = 0;
511 for (p = line->buf; ix < WWW_NUM_FIELDS && *p; p ++) {
512 if (strchr("\"'`", *p) != NULL) {
513 for (quote = *p ++; *p && *p != quote; p ++)
514 ;
515 }
516 else if (strchr(delim, *p) != NULL) {
517 *p = '\0';
518 line->off[ix ++] = (uint8_t)(p - line->buf + 1);
519 }
520 }
521 line->num = ix;
522 }
523
524/*
525 * put_status -- status line を出力する。
526 */
527
528static uint16_t
529put_status (ID cepid, T_WWW_RWBUF *srbuf, int_t index)
530{
531 uint16_t len = 0;
532
533 len += put_str(cepid, srbuf, "HTTP/1.0 ");
534 len += put_str(cepid, srbuf, status[index]);
535 len += put_str(cepid, srbuf, "\r\n");
536 return len;
537 }
538
539/*
540 * put_content_length -- Content-length を出力する。
541 */
542
543static uint16_t
544put_content_length (ID cepid, T_WWW_RWBUF *srbuf, int_t content_len)
545{
546 uint16_t len = 0;
547#if 0
548 char length[TD_DIGITS + 1];
549
550 convert(length, content_len, 10, 0, false, ' ');
551 len += put_str(cepid, srbuf, "Content-length: ");
552 len += put_str(cepid, srbuf, length);
553 len += put_str(cepid, srbuf, "\r\n");
554#endif /* of #if 0 */
555 return len;
556 }
557
558/*
559 * get_method -- GET メソッドの処理
560 */
561
562static ER
563get_method (ID cepid, T_WWW_RWBUF *srbuf, T_WWW_LINE *line)
564{
565 int_t ix;
566
567 for (ix = NUM_FILES; ix -- > 0; ) {
568 if (!strcmp(file[ix].uri, &line->buf[line->off[1]])) {
569 //syslog(LOG_NOTICE, "[WWWn:%02u PTH] '%s'", cepid, &line->buf[line->off[1]]);
570 return (*file[ix].func)(cepid, srbuf);
571 }
572 }
573 put_status(cepid, srbuf, ST_NOT_FOUND);
574 return E_NOEXS;
575 }
576
577/*
578 * parse_request -- リクエストを解析する。
579 */
580
581static ER
582parse_request (ID cepid, T_WWW_RWBUF *srbuf)
583{
584 T_WWW_LINE *method, *line;
585 ER error = E_OK;
586 int_t blen = 0;
587
588 if ((error = tget_mpf(MPF_WWW_LINE, (void*)&method, TMO_FEVR)) != E_OK) {
589 syslog(LOG_CRIT, "[WWWn:%02u MPF] get line error: %s.",
590 cepid, itron_strerror(error));
591 return error;
592 }
593
594 if (get_line(cepid, method, srbuf) == 0) {
595 if ((error = rel_mpf(MPF_WWW_LINE, method)) != E_OK)
596 syslog(LOG_WARNING, "[WWWn:%02u MPF] release line buffer error: %s.",
597 cepid, itron_strerror(error));
598 return error;
599 }
600
601 if ((error = tget_mpf(MPF_WWW_LINE, (void*)&line, TMO_FEVR)) != E_OK) {
602 syslog(LOG_CRIT, "[WWWn:%02u MPF] get line buffer error: %s.",
603 cepid, itron_strerror(error));
604 if ((error = rel_mpf(MPF_WWW_LINE, method)) != E_OK)
605 syslog(LOG_WARNING, "[WWWn:%02u MPF] release line buffer error: %s.",
606 cepid, itron_strerror(error));
607 return error;
608 }
609
610 while (get_line(cepid, line, srbuf) > 0) { /* ヘッダをスキップする。*/
611 split_fields(line, ": ");
612 if (strcmp("Content-Length", &line->buf[line->off[0]]) == 0)
613 blen = atoi(&line->buf[line->off[1]]);
614 }
615 while (blen > 0 && get_line(cepid, line, srbuf) > 0) {
616 /* エンティティ・ボディをスキップする。*/
617 blen -= line->len;
618 }
619
620 if ((error = rel_mpf(MPF_WWW_LINE, line)) != E_OK)
621 syslog(LOG_WARNING, "[WWWn:%02u MPF] release line buffer error: %s.",
622 cepid, itron_strerror(error));
623
624 split_fields(method, ": ");
625 if (!strcmp(&method->buf[method->off[0]], "GET"))
626 error = get_method(cepid, srbuf, method);
627
628 flush_sbuf(cepid, srbuf);
629
630 if ((error = rel_mpf(MPF_WWW_LINE, method)) != E_OK)
631 syslog(LOG_WARNING, "[WWWn:%02u MPF] release line buffer error: %s.",
632 cepid, itron_strerror(error));
633
634 return error;
635 }
636
637/*
638 * index_html -- /index.html ファイル
639 */
640
641static ER
642index_html (ID cepid, T_WWW_RWBUF *srbuf)
643{
644 static const char response[] =
645 "\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD html 3.2//EN\">\r\n"
646 "<html><head>\r\n"
647
648#ifdef TOPPERS_S810_CLG3_85
649 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\">\r\n"
650#else
651 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-JP\">\r\n"
652#endif
653
654 "<title>TINET TCP/IP Protocol Stack</title>\r\n"
655 "</head><body bgcolor=\"#ffffbb\">\r\n"
656 "<hr>この WWW サーバは<br>"
657
658#ifdef TARGET_KERNEL_ASP
659 "ASP Kernel for " TARGET_NAME " (" __DATE__ "," __TIME__ ") と<br>\r\n"
660#endif
661
662#ifdef TARGET_KERNEL_JSP
663 "JSP Kernel for " TARGET_NAME " (" __DATE__ "," __TIME__ ") と<br>\r\n"
664#endif
665
666 "TINET TCP/IP プロトコルスタックによりサービスしています。<br><hr>\r\n"
667
668#if NET_COUNT_ENABLE
669
670 "<ul><li type=\"square\"><a href=\"stat.html\">ネットワーク統計情
671å ±</a></ul><hr>\r\n"
672
673#else /* of #if NET_COUNT_ENABLE */
674
675 "<ul><li type=\"square\">ネットワーク統計情
676å ±</ul><hr>\r\n"
677
678#endif /* of #if NET_COUNT_ENABLE */
679
680 "FreeBSD: Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995<br>\r\n"
681 "The Regents of the University of California. All rights reserved.<br><br>\r\n"
682
683#ifdef SUPPORT_PPP
684
685 "pppd: Copyright (c) 1989 Carnegie Mellon University.<br>\r\n"
686 "All rights reserved.<br><br>\r\n"
687 "ppp: Written by Toshiharu OHNO (tony-o@iij.ad.jp)<br>\r\n"
688 "Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.<br><br>\r\n"
689
690#endif /* of #ifdef SUPPORT_PPP */
691
692#ifdef SUPPORT_ETHER
693
694 "if_ed: Copyright (c) 1995, David Greenman<br>\r\n"
695 "All rights reserved.<br><br>\r\n"
696
697#endif /* of #ifdef SUPPORT_ETHER */
698
699#ifdef TARGET_KERNEL_ASP
700 "TOPPERS/ASP Kernel<br>\r\n"
701 "Toyohashi Open Platform for Embedded Real-Time Systems/<br>\r\n"
702 "Advanced Standard Profile Kernel<br>\r\n"
703 "Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory<br>\r\n"
704 "Toyohashi Univ. of Technology, JAPAN<br>\r\n"
705 "Copyright (C) 2004-2008 by Embedded and Real-Time Systems Laboratory<br>\r\n"
706 "Graduate School of Information Science, Nagoya Univ., JAPAN<br><br>\r\n"
707#endif /* of #ifdef TARGET_KERNEL_ASP */
708
709#ifdef TARGET_KERNEL_JSP
710 "TOPPERS/JSP Kernel<br>\r\n"
711 "Toyohashi Open Platform for Embedded Real-Time Systems/<br>\r\n"
712 "Just Standard Profile Kernel<br>\r\n"
713 "Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory<br>\r\n"
714 "Toyohashi Univ. of Technology, JAPAN<br>\r\n"
715 "Copyright (C) 2005 by Embedded and Real-Time Systems Laboratory<br>\r\n"
716 "Graduate School of Information Science, Nagoya Univ., JAPAN<br><br>\r\n"
717#endif /* of #ifdef TARGET_KERNEL_JSP */
718
719 "TINET (TCP/IP Protocol Stack)<br>\r\n"
720 "Copyright (C) 2001-2008 by Dep. of Computer Science and Engineering<br>\r\n"
721 "Tomakomai National College of Technology, JAPAN\r\n"
722 "</body></html>\r\n"
723 ;
724
725 SYSTIM start, finish;
726 uint16_t len = 0;
727
728 get_tim(&start);
729 len += put_status(cepid, srbuf, ST_OK);
730 len += put_content_length(cepid, srbuf, strlen(response) - 2); /* 2 は最初の \r\n */
731 len += put_str(cepid, srbuf, response);
732 get_tim(&finish);
733 syslog(LOG_NOTICE, "[WWWn:%02u SND] send: index.html, len: %4u, time: %lu [us]",
734 cepid, len, (finish - start) * 1000 / SYSTIM_HZ);
735 return E_OK;
736 }
737
738#if NET_COUNT_ENABLE
739
740#define TD_TEMPLATE1 "<tr><td></td><td align=\"right\"></td>\r\n<td align=\"right\"></td>\r\n<td align=\"right\"></td>\r\n<td align=\"right\"></td>\r\n<td align=\"right\"></td>\r\n<td align=\"right\"></td></tr>\r\n"
741#define TD_TEMPLATE2 "<tr><td></td><td align=\"right\"></td><td align=\"right\"></td></tr>\r\n"
742#define TD_TEMPLATE3 "<tr><td></td><td align=\"right\"></td></tr>\r\n"
743#define TD_TEMPLATE4 "<tr><td></td><td align=\"right\"></td><td align=\"right\"></td><td align=\"right\"></td></tr>\r\n"
744
745#define TD_LEN1(i) (sizeof(i) + sizeof(TD_TEMPLATE1) + TD_DIGITS * 6 - 2)
746#define TD_LEN2(i) (sizeof(i) + sizeof(TD_TEMPLATE2) + TD_DIGITS * 2 - 2)
747#define TD_LEN4(i) (sizeof(i) + sizeof(TD_TEMPLATE4) + TD_DIGITS * 3 - 2)
748#define TD_DIGITS 20
749
750static const char time_prefix[] =
751 "経過時間: "
752 ;
753
754static const char time_suffix[] =
755 "<hr>\r\n"
756 ;
757
758static const char table_suffix[] = "</table><br><hr>";
759
760#if defined(SUPPORT_INET4)
761
762static const char table_prefix_ip4[] =
763 "<h2>IPv4</h2><table border>\r\n"
764 "<tr><th>項
765目</th><th>カウント</th></tr>\r\n"
766 ;
767
768#endif /* of #if defined(SUPPORT_INET4) */
769
770#if defined(SUPPORT_INET6)
771
772static const char table_prefix_ip6[] =
773 "<h2>IPv6</h2><table border>\r\n"
774 "<tr><th>項
775目</th><th>カウント</th></tr>\r\n"
776 ;
777
778static const char table_prefix_icmp6[] =
779 "<h2>ICMPv6</h2><table border>\r\n"
780 "<tr><th>項
781目</th><th>カウント</th></tr>\r\n"
782 ;
783
784static const char table_prefix_nd6[] =
785 "<h2>近隣探索</h2><table border>\r\n"
786 "<tr><th>項
787目</th><th>カウント</th></tr>\r\n"
788 ;
789
790#endif /* of #if defined(SUPPORT_INET6) */
791
792static const char table_prefix_tcp[] =
793 "<h2>TCP</h2><table border>\r\n"
794 "<tr><th>項
795目</th><th>カウント</th></tr>\r\n"
796 ;
797
798static const char table_prefix_net_buf[] =
799 "<h2>ネットワークバッファ</h2><table border>\r\n"
800 "<tr><th>サイズ</th>"
801 "<th>用意数</th>"
802 "<th>割当要求数</th>"
803 "<th>割当数</th>"
804 "<th>割当て<br>エラー数</th></tr>\r\n"
805 ;
806
807#ifdef SUPPORT_PPP
808
809static const char table_prefix_ppp[] =
810 "<h2>PPP ネットワークインタフェース</h2><table border>\r\n"
811 "<tr><th>項
812目</th><th>カウント</th></tr>\r\n"
813 ;
814
815static const char *ppp_item[NC_PPP_SIZE] = {
816 "受信オクテット数",
817 "送信オクテット数",
818 "受信フレーム数",
819 "送信フレーム数",
820 "受信エラーフレーム数",
821 "送信エラーフレーム数",
822 "バッファ割り当て失敗数",
823 };
824
825#endif /* of #ifdef SUPPORT_PPP */
826
827#ifdef SUPPORT_ETHER
828
829static const char table_prefix_ether_nic[] =
830 "<h2>イーサネット・ネットワークインタフェース</h2><table border>\r\n"
831 "<tr><th>項
832目</th><th>カウント</th></tr>\r\n"
833 ;
834
835static const char *ether_nic_item[NC_ETHER_NIC_SIZE] = {
836 "リセット数",
837 "送信セマフォ資源返却オーバー数",
838 "送信タイムアウト数",
839 "衝突数",
840 "送信エラーフレーム数",
841 "送信フレーム数",
842 "送信オクテット数",
843 "受信セマフォ資源返却オーバー数",
844 "受信バッファ割り当て失敗数",
845 "受信エラーフレーム数",
846 "受信フレーム数",
847 "受信オクテット数",
848 };
849
850#endif /* of #ifdef SUPPORT_ETHER */
851
852#if defined(SUPPORT_INET4)
853
854static const char *ip4_item[NC_IP4_SIZE] = {
855 "分割送信、フラグメント数",
856 "分割送信数",
857 "送信エラーデータグラム数",
858 "送信データグラム数",
859 "送信オクテット数",
860 "分割受信タイムアウト数",
861 "分割受信バッファ割り当て失敗数",
862 "分割受信破棄数",
863 "分割受信再構成成功数",
864 "分割受信フラグメント数",
865 "分割受信数",
866 "オプションå…
867¥åŠ›æ•°",
868 "プロトコルエラー数",
869 "アドレスエラー数",
870 "バージョンエラー数",
871 "長さエラー数",
872 "チェックサムエラー数",
873 "受信エラーデータグラム数",
874 "受信データグラム数",
875 "受信オクテット数",
876 };
877
878#endif /* of #if defined(SUPPORT_INET4) */
879
880#if defined(SUPPORT_INET6)
881
882static const char *ip6_item[NC_IP6_SIZE] = {
883 "分割送信、フラグメント数",
884 "分割送信数",
885 "送信エラーデータグラム数",
886 "送信データグラム数",
887 "送信オクテット数 ",
888 "分割受信タイムアウト数",
889 "分割受信バッファ割り当て失敗数",
890 "分割受信破棄数",
891 "分割受信再構成成功数",
892 "分割受信フラグメント数",
893 "分割受信数",
894 "プロトコルエラー数 ",
895 "アドレスエラー数 ",
896 "バージョンエラー数 ",
897 "長さエラー数",
898 "受信エラーデータグラム数",
899 "受信データグラム数",
900 "受信オクテット数 ",
901 };
902
903static const char *icmp6_item[NC_ICMP6_SIZE] = {
904 "送信エラー ICMP データ数 ",
905 "送信 ICMP データ数",
906 "送信 ICMP オクテット数",
907 "長さエラー数",
908 "受信エラー ICMP データ数 ",
909 "受信 ICMP データ数",
910 "受信 ICMP オクテット数",
911 };
912
913static const char *nd6_item[NC_ND6_SIZE] = {
914 "重複アドレス検出送信数",
915 "近隣要請送信数",
916 "近隣要請受信数",
917 "近隣通知送信数",
918 "近隣通知受信数",
919 "ルータ要請出力数",
920 "ルータ通知受信数",
921 };
922
923#endif /* of #if defined(SUPPORT_INET6) */
924
925static const char *tcp_item[NC_TCP_SIZE] = {
926 "能動オープン数",
927 "受動オープン数",
928 "RTT 更新数",
929 "送信 RST 数",
930 "送信 ACK 数",
931 "送信緊急セグメント数",
932 "送信データセグメント数",
933 "再送セグメント数",
934 "送信セグメント数",
935 "送信制御セグメント数",
936 "送信データオクテット数",
937 "受信キュー解放数",
938 "受信多重数",
939 "受信破棄数",
940 "受信 RST 数",
941 "受信多重 ACK 数",
942 "受信 ACK 数",
943 "受信チェックサム不正数",
944 "受信ヘッダ不正数",
945 "受信緊急セグメント数",
946 "受信データセグメント数",
947 "受信セグメント数",
948 "受信データオクテット数",
949 "受信オクテット数",
950 };
951
952/*
953 * put_count_item1 -- カウンタの内
954容を出力する。グループ 1
955 */
956
957static uint16_t
958put_count_item1 (ID cepid, T_WWW_RWBUF *srbuf, const char *item, T_NET_COUNT *counter)
959{
960 char buf[TD_DIGITS + 1];
961 uint16_t len = 0;
962
963 len += put_str(cepid, srbuf, "<tr><td>");
964 len += put_str(cepid, srbuf, item);
965 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
966
967 convert(buf, counter->in_octets, 10, TD_DIGITS, false, ' ');
968 len += put_str(cepid, srbuf, buf);
969 len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
970
971 convert(buf, counter->out_octets, 10, TD_DIGITS, false, ' ');
972 len += put_str(cepid, srbuf, buf);
973 len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
974
975 convert(buf, counter->in_packets, 10, TD_DIGITS, false, ' ');
976 len += put_str(cepid, srbuf, buf);
977 len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
978
979 convert(buf, counter->out_packets, 10, TD_DIGITS, false, ' ');
980 len += put_str(cepid, srbuf, buf);
981 len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
982
983 convert(buf, counter->in_err_packets, 10, TD_DIGITS, false, ' ');
984 len += put_str(cepid, srbuf, buf);
985 len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
986
987 convert(buf, counter->out_err_packets, 10, TD_DIGITS, false, ' ');
988 len += put_str(cepid, srbuf, buf);
989 len += put_str(cepid, srbuf, "</td></tr>\r\n");
990
991 return len;
992 }
993
994#ifdef SUPPORT_PPP
995
996/*
997 * put_count_item2 -- カウンタの内
998容を出力する。グループ 2
999 */
1000
1001static uint16_t
1002put_count_item2 (ID cepid, T_WWW_RWBUF *srbuf, const char *item, uint32_t octets, uint32_t packets)
1003{
1004 char buf[TD_DIGITS + 1];
1005 uint16_t len = 0;
1006
1007 len += put_str(cepid, srbuf, "<tr><td>");
1008 len += put_str(cepid, srbuf, item);
1009 len += put_str(cepid, srbuf, "</td><td>");
1010
1011 convert(buf, octets, 10, TD_DIGITS, false, ' ');
1012 len += put_str(cepid, srbuf, buf);
1013 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1014
1015 convert(buf, packets, 10, TD_DIGITS, false, ' ');
1016 len += put_str(cepid, srbuf, buf);
1017 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1018
1019 return len;
1020 }
1021
1022/*
1023 * td_len_ppp -- put_count_ppp で出力する文字数。
1024 */
1025
1026static uint16_t
1027td_len_ppp (void)
1028{
1029 int_t ix;
1030 uint16_t len = 0;
1031
1032 for (ix = NC_PPP_SIZE; ix -- > 0; )
1033 len += strlen(ppp_item[ix]);
1034 return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_PPP_SIZE;
1035 }
1036
1037/*
1038 * put_count_ppp -- カウンタ (PPP) の内
1039容を出力する。
1040 */
1041
1042static uint16_t
1043put_count_ppp (ID cepid, T_WWW_RWBUF *srbuf)
1044{
1045
1046 char buf[TD_DIGITS + 1];
1047 uint16_t len = 0;
1048
1049 len += put_str(cepid, srbuf, table_prefix_ppp);
1050
1051 len += put_str(cepid, srbuf, "<tr><td>");
1052 len += put_str(cepid, srbuf, ppp_item[0]);
1053 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1054 convert(buf, net_count_ppp.in_octets, 10, TD_DIGITS, false, ' ');
1055 len += put_str(cepid, srbuf, buf);
1056 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1057
1058 len += put_str(cepid, srbuf, "<tr><td>");
1059 len += put_str(cepid, srbuf, ppp_item[1]);
1060 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1061 convert(buf, net_count_ppp.out_octets, 10, TD_DIGITS, false, ' ');
1062 len += put_str(cepid, srbuf, buf);
1063 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1064
1065 len += put_str(cepid, srbuf, "<tr><td>");
1066 len += put_str(cepid, srbuf, ppp_item[2]);
1067 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1068 convert(buf, net_count_ppp.in_packets, 10, TD_DIGITS, false, ' ');
1069 len += put_str(cepid, srbuf, buf);
1070 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1071
1072 len += put_str(cepid, srbuf, "<tr><td>");
1073 len += put_str(cepid, srbuf, ppp_item[3]);
1074 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1075 convert(buf, net_count_ppp.out_packets, 10, TD_DIGITS, false, ' ');
1076 len += put_str(cepid, srbuf, buf);
1077 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1078
1079 len += put_str(cepid, srbuf, "<tr><td>");
1080 len += put_str(cepid, srbuf, ppp_item[4]);
1081 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1082 convert(buf, net_count_ppp.in_err_packets, 10, TD_DIGITS, false, ' ');
1083 len += put_str(cepid, srbuf, buf);
1084 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1085
1086 len += put_str(cepid, srbuf, "<tr><td>");
1087 len += put_str(cepid, srbuf, ppp_item[5]);
1088 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1089 convert(buf, net_count_ppp.out_err_packets, 10, TD_DIGITS, false, ' ');
1090 len += put_str(cepid, srbuf, buf);
1091 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1092
1093 len += put_str(cepid, srbuf, "<tr><td>");
1094 len += put_str(cepid, srbuf, ppp_item[6]);
1095 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1096 convert(buf, net_count_ppp_no_bufs, 10, TD_DIGITS, false, ' ');
1097 len += put_str(cepid, srbuf, buf);
1098 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1099
1100 len += put_str(cepid, srbuf, table_suffix);
1101
1102 return len;
1103 }
1104
1105#endif /* of #ifdef SUPPORT_PPP */
1106
1107#if defined(SUPPORT_INET4)
1108
1109/*
1110 * td_len_ip4 -- put_count_ip4 で出力する文字数。
1111 */
1112
1113static uint16_t
1114td_len_ip4 (void)
1115{
1116 int_t ix;
1117 uint16_t len = 0;
1118
1119 for (ix = NC_IP4_SIZE; ix -- > 0; )
1120 len += strlen(ip4_item[ix]);
1121 return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_IP4_SIZE;
1122 }
1123
1124/*
1125 * put_count_ip4 -- カウンタ (IP4) の内
1126容を出力する。
1127 */
1128
1129static uint16_t
1130put_count_ip4 (ID cepid, T_WWW_RWBUF *srbuf)
1131{
1132 char buf[TD_DIGITS + 1];
1133 uint16_t len = 0;
1134 int_t ix;
1135
1136 len += put_str(cepid, srbuf, table_prefix_ip4);
1137 for (ix = NC_IP4_SIZE; ix -- > 0; ) {
1138 len += put_str(cepid, srbuf, "<tr><td>");
1139 len += put_str(cepid, srbuf, ip4_item[ix]);
1140 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1141 convert(buf, net_count_ip4[ix], 10, TD_DIGITS, false, ' ');
1142 len += put_str(cepid, srbuf, buf);
1143 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1144 }
1145 len += put_str(cepid, srbuf, table_suffix);
1146
1147 return len;
1148 }
1149
1150#endif /* of #if defined(SUPPORT_INET4) */
1151
1152#if defined(SUPPORT_INET6)
1153
1154/*
1155 * td_len_nd6 -- put_count_nd6 で出力する文字数。
1156 */
1157
1158static uint16_t
1159td_len_nd6 (void)
1160{
1161 int_t ix;
1162 uint16_t len = 0;
1163
1164 for (ix = NC_ND6_SIZE; ix -- > 0; )
1165 len += strlen(nd6_item[ix]);
1166 return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_ND6_SIZE;
1167 }
1168
1169/*
1170 * put_count_nd6 -- カウンタ (ND6) の内
1171容を出力する。
1172 */
1173
1174static uint16_t
1175put_count_nd6 (ID cepid, T_WWW_RWBUF *srbuf)
1176{
1177 char buf[TD_DIGITS + 1];
1178 uint16_t len = 0;
1179 int_t ix;
1180
1181 len += put_str(cepid, srbuf, table_prefix_nd6);
1182 for (ix = NC_ND6_SIZE; ix -- > 0; ) {
1183 len += put_str(cepid, srbuf, "<tr><td>");
1184 len += put_str(cepid, srbuf, nd6_item[ix]);
1185 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1186 convert(buf, net_count_nd6[ix], 10, TD_DIGITS, false, ' ');
1187 len += put_str(cepid, srbuf, buf);
1188 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1189 }
1190 len += put_str(cepid, srbuf, table_suffix);
1191
1192 return len;
1193 }
1194
1195/*
1196 * td_len_icmp6 -- put_count_icmp6 で出力する文字数。
1197 */
1198
1199static uint16_t
1200td_len_icmp6 (void)
1201{
1202 int_t ix;
1203 uint16_t len = 0;
1204
1205 for (ix = NC_ICMP6_SIZE; ix -- > 0; )
1206 len += strlen(icmp6_item[ix]);
1207 return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_ICMP6_SIZE;
1208 }
1209
1210/*
1211 * put_count_icmp6 -- カウンタ (ICMP6) の内
1212容を出力する。
1213 */
1214
1215static uint16_t
1216put_count_icmp6 (ID cepid, T_WWW_RWBUF *srbuf)
1217{
1218 char buf[TD_DIGITS + 1];
1219 uint16_t len = 0;
1220 int_t ix;
1221
1222 len += put_str(cepid, srbuf, table_prefix_icmp6);
1223 for (ix = NC_ICMP6_SIZE; ix -- > 0; ) {
1224 len += put_str(cepid, srbuf, "<tr><td>");
1225 len += put_str(cepid, srbuf, icmp6_item[ix]);
1226 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1227 convert(buf, net_count_icmp6[ix], 10, TD_DIGITS, false, ' ');
1228 len += put_str(cepid, srbuf, buf);
1229 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1230 }
1231 len += put_str(cepid, srbuf, table_suffix);
1232
1233 return len;
1234 }
1235
1236/*
1237 * td_len_ip6 -- put_count_ip6 で出力する文字数。
1238 */
1239
1240static uint16_t
1241td_len_ip6 (void)
1242{
1243 int_t ix;
1244 uint16_t len = 0;
1245
1246 for (ix = NC_IP6_SIZE; ix -- > 0; )
1247 len += strlen(ip6_item[ix]);
1248 return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_IP6_SIZE;
1249 }
1250
1251/*
1252 * put_count_ip6 -- カウンタ (IP6) の内
1253容を出力する。
1254 */
1255
1256static uint16_t
1257put_count_ip6 (ID cepid, T_WWW_RWBUF *srbuf)
1258{
1259 char buf[TD_DIGITS + 1];
1260 uint16_t len = 0;
1261 int_t ix;
1262
1263 len += put_str(cepid, srbuf, table_prefix_ip6);
1264 for (ix = NC_IP6_SIZE; ix -- > 0; ) {
1265 len += put_str(cepid, srbuf, "<tr><td>");
1266 len += put_str(cepid, srbuf, ip6_item[ix]);
1267 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1268 convert(buf, net_count_ip6[ix], 10, TD_DIGITS, false, ' ');
1269 len += put_str(cepid, srbuf, buf);
1270 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1271 }
1272 len += put_str(cepid, srbuf, table_suffix);
1273
1274 return len;
1275 }
1276
1277#endif /* of #if defined(SUPPORT_INET6) */
1278
1279/*
1280 * td_len_tcp -- put_count_tcp で出力する文字数。
1281 */
1282
1283static uint16_t
1284td_len_tcp (void)
1285{
1286 int_t ix;
1287 uint16_t len = 0;
1288
1289 for (ix = NC_TCP_SIZE; ix -- > 0; )
1290 len += strlen(tcp_item[ix]);
1291 return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_TCP_SIZE;
1292 }
1293
1294/*
1295 * put_count_tcp -- カウンタ (TCP) の内
1296容を出力する。
1297 */
1298
1299static uint16_t
1300put_count_tcp (ID cepid, T_WWW_RWBUF *srbuf)
1301{
1302 char buf[TD_DIGITS + 1];
1303 uint16_t len = 0;
1304 int_t ix;
1305
1306 len += put_str(cepid, srbuf, table_prefix_tcp);
1307 for (ix = NC_TCP_SIZE; ix -- > 0; ) {
1308 len += put_str(cepid, srbuf, "<tr><td>");
1309 len += put_str(cepid, srbuf, tcp_item[ix]);
1310 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1311 convert(buf, net_count_tcp[ix], 10, TD_DIGITS, false, ' ');
1312 len += put_str(cepid, srbuf, buf);
1313 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1314 }
1315 len += put_str(cepid, srbuf, table_suffix);
1316
1317 return len;
1318 }
1319
1320/*
1321 * put_elapse_time -- 経過時間を出力する。
1322 */
1323
1324static uint16_t
1325put_elapse_time (ID cepid, T_WWW_RWBUF *srbuf)
1326{
1327 SYSTIM now, elapse;
1328 char buf[TD_DIGITS + 1];
1329 uint16_t len = 0;
1330
1331 get_tim(&now);
1332 elapse = now - srv_start;
1333
1334 len += put_str(cepid, srbuf, time_prefix);
1335
1336 convert(buf, elapse / (60 * 60 * SYSTIM_HZ), 10, 4, false, ' ');
1337 len += put_str(cepid, srbuf, buf);
1338 len += put_str(cepid, srbuf, ":");
1339
1340 convert(buf, (elapse / (60 * SYSTIM_HZ)) % 60, 10, 2, false, ' ');
1341 len += put_str(cepid, srbuf, buf);
1342 len += put_str(cepid, srbuf, ":");
1343
1344 convert(buf, (elapse / SYSTIM_HZ) % 60, 10, 2, false, ' ');
1345 len += put_str(cepid, srbuf, buf);
1346
1347 len += put_str(cepid, srbuf, time_suffix);
1348
1349 return len;
1350 }
1351
1352/*
1353 * put_count_net_buf -- カウンタ (TCP) の内
1354容を出力する。
1355 */
1356
1357static uint16_t
1358put_count_net_buf (ID cepid, T_WWW_RWBUF *srbuf)
1359{
1360
1361 const T_NET_BUF_ENTRY *tbl;
1362 char buf[TD_DIGITS + 1];
1363 uint16_t len = 0;
1364 int_t ix;
1365
1366 len += put_str(cepid, srbuf, table_prefix_net_buf);
1367 tbl = nbuf_get_tbl();
1368 for (ix = nbuf_get_tbl_size(); ix -- > 0; ) {
1369 len += put_str(cepid, srbuf, "<tr><td align=\"right\">");
1370 convert(buf, tbl[ix].size, 10, 4, false, ' ');
1371 len += put_str(cepid, srbuf, buf);
1372 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1373 convert(buf, tbl[ix].prepares, 10, TD_DIGITS, false, ' ');
1374 len += put_str(cepid, srbuf, buf);
1375 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1376 convert(buf, tbl[ix].requests, 10, TD_DIGITS, false, ' ');
1377 len += put_str(cepid, srbuf, buf);
1378 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1379 convert(buf, tbl[ix].allocs, 10, TD_DIGITS, false, ' ');
1380 len += put_str(cepid, srbuf, buf);
1381 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1382 convert(buf, tbl[ix].errors, 10, TD_DIGITS, false, ' ');
1383 len += put_str(cepid, srbuf, buf);
1384 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1385 }
1386 len += put_str(cepid, srbuf, table_suffix);
1387
1388 return len;
1389 }
1390
1391#ifdef SUPPORT_ETHER
1392
1393/*
1394 * td_len_ether_nic -- put_count_ether_nic で出力する文字数。
1395 */
1396
1397static uint16_t
1398td_len_ether_nic (void)
1399{
1400 int_t ix;
1401 uint16_t len = 0;
1402
1403 for (ix = NC_ETHER_NIC_SIZE; ix -- > 0; )
1404 len += strlen(ether_nic_item[ix]);
1405 return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_ETHER_NIC_SIZE;
1406 }
1407
1408/*
1409 * put_count_ether_nic -- カウンタ (ETHER_NIC) の内
1410容を出力する。
1411 */
1412
1413static uint16_t
1414put_count_ether_nic (ID cepid, T_WWW_RWBUF *srbuf)
1415{
1416 char buf[TD_DIGITS + 1];
1417 uint16_t len = 0;
1418 int_t ix;
1419
1420 len += put_str(cepid, srbuf, table_prefix_ether_nic);
1421 for (ix = NC_ETHER_NIC_SIZE; ix -- > 0; ) {
1422 len += put_str(cepid, srbuf, "<tr><td>");
1423 len += put_str(cepid, srbuf, ether_nic_item[ix]);
1424 len += put_str(cepid, srbuf, "</td><td align=\"right\">");
1425 convert(buf, net_count_ether_nic[ix], 10, TD_DIGITS, false, ' ');
1426 len += put_str(cepid, srbuf, buf);
1427 len += put_str(cepid, srbuf, "</td></tr>\r\n");
1428 }
1429 len += put_str(cepid, srbuf, table_suffix);
1430
1431 return len;
1432 }
1433
1434#endif /* of #ifdef SUPPORT_ETHER */
1435
1436/*
1437 * stat_html -- /stat.html ファイル
1438 */
1439
1440static ER
1441stat_html (ID cepid, T_WWW_RWBUF *srbuf)
1442{
1443 static const char res_prefix[] =
1444 "\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD html 3.2//EN\">\r\n"
1445 "<html><head>\r\n"
1446
1447#ifdef TOPPERS_S810_CLG3_85
1448 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\">\r\n"
1449#else
1450 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-JP\">\r\n"
1451#endif
1452
1453 "<title>ネットワーク統計情
1454å ±</title>\r\n"
1455 "</head><body bgcolor=\"#ffffbb\">\r\n"
1456 "<hr><h1 align=\"center\">ネットワーク統計情
1457å ±</h1><hr>\r\n"
1458 ;
1459
1460 static const char res_suffix[] =
1461 "</body></html>\r\n"
1462 ;
1463
1464 static const char table_prefix1[] =
1465 "<h2>グループ 1</h2><table border>\r\n"
1466 "<tr><th>項
1467目</th>\r\n"
1468 "<th>受信オクテット数</th>"
1469 "<th>送信オクテット数</th>\r\n"
1470 "<th>受信パケット数</th>"
1471 "<th>送信パケット数</th>\r\n"
1472 "<th>受信エラー<br>パケット数</th>"
1473 "<th>送信エラー<br>パケット数</th></tr>\r\n"
1474 ;
1475
1476#ifdef SUPPORT_PPP
1477
1478 static const char table_prefix2[] =
1479 "<h2>グループ 2</h2><table border>\r\n"
1480 "<tr><th>項
1481目</th>"
1482 "<th>受信オクテット数</th>"
1483 "<th>受信フレーム数</th></tr>\r\n"
1484 ;
1485
1486#endif /* of #ifdef SUPPORT_PPP */
1487
1488 uint16_t content_len, len = 0;
1489 SYSTIM start, finish;
1490
1491 get_tim(&start);
1492 content_len = 0
1493
1494#ifdef SUPPORT_PPP
1495
1496 + TD_LEN1("HDLC")
1497
1498#endif /* of #ifdef SUPPORT_PPP */
1499
1500#ifdef SUPPORT_PPP
1501
1502 + td_len_ppp()
1503 + TD_LEN2("LCP")
1504 + TD_LEN2("IPCP")
1505
1506#endif /* of #ifdef SUPPORT_PPP */
1507
1508#ifdef SUPPORT_ETHER
1509
1510 + TD_LEN1("ARP")
1511 + td_len_ether_nic()
1512
1513#endif /* of #ifdef SUPPORT_ETHER */
1514
1515 + TD_LEN1("ICMP")
1516 + TD_LEN1("UDP")
1517
1518#if defined(SUPPORT_INET4)
1519
1520 + td_len_ip4()
1521
1522#endif /* of #if defined(SUPPORT_INET4) */
1523
1524#if defined(SUPPORT_INET6)
1525
1526 + td_len_ip6()
1527 + td_len_nd6()
1528 + td_len_icmp6()
1529
1530#endif /* of #if defined(SUPPORT_INET6) */
1531
1532 + td_len_tcp()
1533 + TD_LEN4("0123") * nbuf_get_tbl_size();
1534 ;
1535
1536 len += put_status(cepid, srbuf, ST_OK);
1537 len += put_content_length(cepid, srbuf, strlen(res_prefix)
1538 + strlen(res_suffix)
1539 + strlen(time_prefix)
1540 + strlen("1234:12:12")
1541 + strlen(time_suffix)
1542 + strlen(table_prefix1)
1543 + strlen(table_prefix_net_buf)
1544
1545#if defined(SUPPORT_INET4)
1546
1547 + strlen(table_prefix_ip4)
1548
1549#endif /* of #if defined(SUPPORT_INET4) */
1550
1551#if defined(SUPPORT_INET6)
1552
1553 + strlen(table_prefix_ip6)
1554 + strlen(table_prefix_nd6)
1555 + strlen(table_prefix_icmp6)
1556
1557#endif /* of #if defined(SUPPORT_INET6) */
1558 + strlen(table_prefix_tcp)
1559 + strlen(table_suffix) * 3
1560
1561#ifdef SUPPORT_PPP
1562 + strlen(table_prefix2)
1563 + strlen(table_prefix_ppp)
1564 + strlen(table_suffix) * 2
1565
1566#endif /* of #ifdef SUPPORT_PPP */
1567
1568#ifdef SUPPORT_ETHER
1569
1570 + strlen(table_prefix_ether_nic)
1571 + strlen(table_suffix) * 1
1572
1573#endif /* of #ifdef SUPPORT_ETHER */
1574
1575 + content_len
1576 - 2); /* 2 は最初の \r\n */
1577
1578 len += put_str(cepid, srbuf, res_prefix);
1579 len += put_elapse_time(cepid, srbuf);
1580 len += put_str(cepid, srbuf, table_prefix1);
1581
1582#ifdef SUPPORT_PPP
1583
1584 len += put_count_item1(cepid, srbuf, "HDLC", &net_count_hdlc);
1585
1586#endif /* of #ifdef SUPPORT_PPP */
1587
1588#ifdef SUPPORT_ETHER
1589
1590 len += put_count_item1(cepid, srbuf, "Ethernet", &net_count_ether);
1591
1592#if defined(SUPPORT_INET4)
1593
1594 len += put_count_item1(cepid, srbuf, "ARP", &net_count_arp);
1595
1596#endif /* of #if defined(SUPPORT_INET4) */
1597
1598#endif /* of #ifdef SUPPORT_ETHER */
1599
1600#if defined(SUPPORT_INET4)
1601
1602 len += put_count_item1(cepid, srbuf, "ICMP", &net_count_icmp4);
1603
1604#endif /* of #if defined(SUPPORT_INET4) */
1605
1606#ifdef SUPPORT_UDP
1607
1608 len += put_count_item1(cepid, srbuf, "UDP", &net_count_udp);
1609
1610#endif /* of #ifdef SUPPORT_UDP */
1611
1612 len += put_str(cepid, srbuf, table_suffix);
1613
1614#ifdef SUPPORT_PPP
1615
1616 len += put_str(cepid, srbuf, table_prefix2);
1617 len += put_count_item2(cepid, srbuf, "LCP",
1618 net_count_ppp_lcp_in_octets,
1619 net_count_ppp_lcp_in_packets);
1620 len += put_count_item2(cepid, srbuf, "IPCP",
1621 net_count_ppp_ipcp_in_octets,
1622 net_count_ppp_ipcp_in_packets);
1623 len += put_str(cepid, srbuf, table_suffix);
1624
1625 len += put_count_ppp(cepid, srbuf);
1626
1627#endif /* of #ifdef SUPPORT_PPP */
1628
1629#ifdef SUPPORT_ETHER
1630
1631 len += put_count_ether_nic(cepid, srbuf);
1632
1633#endif /* of #ifdef SUPPORT_ETHER */
1634
1635#if defined(SUPPORT_INET4)
1636
1637 len += put_count_ip4(cepid, srbuf);
1638
1639#endif /* of #if defined(SUPPORT_INET4) */
1640
1641#if defined(SUPPORT_INET6)
1642
1643 len += put_count_ip6(cepid, srbuf);
1644 len += put_count_nd6(cepid, srbuf);
1645 len += put_count_icmp6(cepid, srbuf);
1646
1647#endif /* of #if defined(SUPPORT_INET6) */
1648
1649 len += put_count_tcp(cepid, srbuf);
1650
1651 len += put_count_net_buf(cepid, srbuf);
1652
1653 len += put_str(cepid, srbuf, res_suffix);
1654
1655 get_tim(&finish);
1656 syslog(LOG_NOTICE, "[WWWn:%02u SND]send: stat.html, len: %4u, time: %lu [us]",
1657 cepid, len, (finish - start) * 1000 / SYSTIM_HZ);
1658 return E_OK;
1659 }
1660
1661#endif /* of #if NET_COUNT_ENABLE */
1662
1663#ifdef USE_TCP_EXTENTIONS
1664
1665/*
1666 * get_tcp_rep -- TCP 受付口を獲得する。
1667 */
1668
1669#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
1670
1671static ER
1672get_tcp_rep (ID *repid)
1673{
1674 ID tskid;
1675 T_TCP6_CREP crep6;
1676 T_TCP_CREP crep4;
1677
1678 get_tid(&tskid);
1679 if (tskid == WWW4_SRV_TASK) {
1680 crep4.repatr = UINT_C(0);
1681 crep4.myaddr.portno = UINT_C(80);
1682 crep4.myaddr.ipaddr = IPV4_ADDRANY;
1683 return alloc_tcp4_rep(repid, tskid, &crep4);
1684 }
1685 else {
1686 crep6.repatr = UINT_C(0);
1687 crep6.myaddr.portno = UINT_C(80);
1688 memcpy(&crep6.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
1689 return alloc_tcp6_rep(repid, tskid, &crep6);
1690 }
1691 }
1692
1693#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1694
1695static ER
1696get_tcp_rep (ID *repid)
1697{
1698 ID tskid;
1699 T_TCPN_CREP crep;
1700
1701 get_tid(&tskid);
1702
1703 crep.repatr = UINT_C(0);
1704 crep.myaddr.portno = UINT_C(80);
1705
1706#if defined(SUPPORT_INET6)
1707
1708 memcpy(&crep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
1709
1710#else /* #if defined(SUPPORT_INET6) */
1711
1712#if defined(SUPPORT_INET4)
1713 crep.myaddr.ipaddr = IPV4_ADDRANY;
1714#endif
1715
1716#endif /* #if defined(SUPPORT_INET6) */
1717
1718 return ALLOC_TCP_REP(repid, tskid, &crep);
1719 }
1720
1721#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1722
1723/*
1724 * get_tcp_cep -- TCP 通信端点を獲得する。
1725 */
1726
1727static ER
1728get_tcp_cep (ID *cepid)
1729{
1730 ID tskid;
1731 T_TCP_CCEP ccep;
1732
1733 get_tid(&tskid);
1734
1735 ccep.cepatr = UINT_C(0);
1736 ccep.sbufsz = WWW_SRV_SWBUF_SIZE;
1737 ccep.rbufsz = WWW_SRV_RWBUF_SIZE;
1738 ccep.callback = NULL;
1739
1740#ifdef TCP_CFG_SWBUF_CSAVE
1741 ccep.sbuf = NADR;
1742#else
1743 ccep.sbuf = www_srv_swbuf[0];
1744#endif
1745#ifdef TCP_CFG_RWBUF_CSAVE
1746 ccep.rbuf = NADR;
1747#else
1748 ccep.rbuf = www_srv_rwbuf[0];
1749#endif
1750
1751#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
1752
1753 if (tskid == WWW4_SRV_TASK)
1754 return alloc_tcp4_cep(cepid, tskid, &ccep);
1755 else
1756 return alloc_tcp6_cep(cepid, tskid, &ccep);
1757
1758#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1759
1760 return ALLOC_TCP_CEP(cepid, tskid, &ccep);
1761
1762#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1763
1764 }
1765
1766#endif /* of #ifdef USE_TCP_EXTENTIONS */
1767
1768/*
1769 * tcp_passive_open -- 受動オープンを実行する。
1770 *
1771 * USE_TCP_NON_BLOCKING OFF
1772 */
1773
1774#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
1775
1776static ER
1777tcp_passive_open (T_WWW_SRV_INFO *info, char apip)
1778{
1779 ER error = E_OK;
1780 T_IPV4EP dst4;
1781
1782 if (apip == API_PROTO_IPV6) {
1783 /* 受付口は IPv6 */
1784 if ((error = tcp6_acp_cep(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
1785 return error;
1786
1787#ifdef USE_TCP_EXTENTIONS
1788 if ((error = free_tcp6_rep(info->repid, true)) != E_OK)
1789 return error;
1790#endif /* of #ifdef USE_TCP_EXTENTIONS */
1791
1792 }
1793 else {
1794 /* 受付口は IPv4 */
1795 if ((error = tcp_acp_cep(info->cepid, info->repid, &dst4, TMO_FEVR)) != E_OK)
1796 return error;
1797 in6_make_ipv4mapped (&info->dst.ipaddr, dst4.ipaddr);
1798 info->dst.portno = dst4.portno;
1799
1800#ifdef USE_TCP_EXTENTIONS
1801 if ((error = free_tcp4_rep(info->repid, true)) != E_OK)
1802 return error;
1803#endif /* of #ifdef USE_TCP_EXTENTIONS */
1804 }
1805
1806 return error;
1807 }
1808
1809#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1810
1811static ER
1812tcp_passive_open (T_WWW_SRV_INFO *info, char apip)
1813{
1814 ER error = E_OK;
1815
1816 if ((error = TCP_ACP_CEP(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
1817 return error;
1818
1819#ifdef USE_TCP_EXTENTIONS
1820 if ((error = FREE_TCP_REP(info->repid, true)) != E_OK)
1821 return error;
1822#endif /* of #ifdef USE_TCP_EXTENTIONS */
1823
1824 return error;
1825 }
1826
1827#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1828
1829/*
1830 * WWW サーバ
1831 */
1832
1833static ER
1834www_srv (uint_t six, char apip)
1835{
1836 T_WWW_RWBUF *srbuf;
1837 ER error;
1838 SYSTIM now;
1839
1840 if ((error = tcp_passive_open(&www_srv_info[six], apip)) != E_OK)
1841 return error;
1842
1843 syscall(get_tim(&now));
1844
1845#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
1846
1847 if (apip == API_PROTO_IPV6)
1848 syslog(LOG_NOTICE, "[WWW6:%02u ACP] conct: %6lu,from: %s.%u",
1849 www_srv_info[six].cepid, now / SYSTIM_HZ,
1850 ipv62str(NULL, &www_srv_info[six].dst.ipaddr),
1851 www_srv_info[six].dst.portno);
1852 else
1853 syslog(LOG_NOTICE, "[WWW4:%02u ACP] conct: %6lu,from: %s.%u",
1854 www_srv_info[six].cepid, now / SYSTIM_HZ,
1855 ip2str(NULL, &www_srv_info[six].dst.ipaddr.s6_addr32[3]),
1856 www_srv_info[six].dst.portno);
1857
1858#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
1859
1860 syslog(LOG_NOTICE, "[WWWn:%02u ACP] conct: %6lu,from: %s.%u",
1861 www_srv_info[six].cepid, now / SYSTIM_HZ,
1862 IP2STR(NULL, &www_srv_info[six].dst.ipaddr),
1863 www_srv_info[six].dst.portno);
1864
1865#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
1866
1867 if ((error = tget_mpf(MPF_WWW_RWBUF, (void*)&srbuf, TMO_FEVR)) != E_OK) {
1868 syslog(LOG_CRIT, "[WWWn:%02u MPF] get buffer error: %s.",
1869 www_srv_info[six].cepid, itron_strerror(error));
1870 srbuf = NULL;
1871 }
1872 else {
1873 srbuf->rbuf.len = srbuf->rbuf.index = srbuf->sbuf.index = srbuf->unget = 0;
1874
1875#ifdef USE_COPYSAVE_API
1876
1877 srbuf->sbuf.len = 0;
1878
1879#else /* of #ifdef USE_COPYSAVE_API */
1880
1881 srbuf->sbuf.len = sizeof(srbuf->sbuf.buf);
1882
1883#endif /* of #ifdef USE_COPYSAVE_API */
1884
1885 if ((error = parse_request(www_srv_info[six].cepid, srbuf)) != E_OK)
1886 syslog(LOG_WARNING, "[WWWn:%02u RCV] parse request error: %s",
1887 www_srv_info[six].cepid, itron_strerror(error));
1888 }
1889
1890 if ((error = tcp_sht_cep(www_srv_info[six].cepid)) != E_OK)
1891 syslog(LOG_WARNING, "[WWWn:%02u SHD] shutdown error: %s",
1892 www_srv_info[six].cepid, itron_strerror(error));
1893
1894 if (srbuf != NULL) {
1895 while (get_char(www_srv_info[six].cepid, srbuf) != EOF)
1896 ;
1897 if (srbuf != NULL && (error = rel_mpf(MPF_WWW_RWBUF, srbuf)) != E_OK)
1898 syslog(LOG_WARNING, "[WWWn:%02u REL] release buffer error: %s.",
1899 www_srv_info[six].cepid, itron_strerror(error));
1900 }
1901
1902 if ((error = tcp_cls_cep(www_srv_info[six].cepid, TMO_FEVR)) != E_OK)
1903 syslog(LOG_WARNING, "[WWWn:%02u CLS] close error: %s",
1904 www_srv_info[six].cepid, itron_strerror(error));
1905
1906 get_tim(&now);
1907 syslog(LOG_NOTICE, "[WWWn:%02u FIN] finsh: %6lu",
1908 www_srv_info[six].cepid, now / SYSTIM_HZ);
1909
1910 return error;
1911 }
1912
1913#ifdef USE_TCP_EXTENTIONS
1914
1915/*
1916 * WWW サーバタスク
1917 */
1918
1919void
1920www_srv_task(intptr_t exinf)
1921{
1922 ID tskid;
1923 ER error = E_OK;
1924 uint_t six;
1925 char apip;
1926
1927 syscall(get_tid(&tskid));
1928 six = INDEX_SRV_INFO((ID)exinf);
1929
1930#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
1931
1932 if (six >= NUM_WWW4_SRV_TASKS)
1933 apip = API_PROTO_IPV6;
1934 else
1935 apip = API_PROTO_IPV4;
1936
1937#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
1938
1939 apip = API_PROTO_IPVn;
1940
1941#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
1942
1943 syslog(LOG_NOTICE, "[WWW%c:%d] started.", apip, tskid);
1944 while (true) {
1945
1946 syscall(slp_tsk());
1947 if ((error = get_tcp_cep(&www_srv_info[six].cepid)) != E_OK) {
1948 syslog(LOG_NOTICE, "[WWW%c:%02u EXT] create CEP error: %s",
1949 apip, www_srv_info[six].cepid, itron_strerror(error));
1950 continue;
1951 }
1952
1953 while (true) {
1954
1955 if ((error = get_tcp_rep(&www_srv_info[six].repid)) != E_OK) {
1956 syslog(LOG_NOTICE, "[WWW%c:%02u EXT] create REP error: %02u, %s",
1957 apip, www_srv_info[six].cepid, www_srv_info[six].repid, itron_strerror(error));
1958 break;
1959 }
1960 else if ((error = www_srv(six, apip)) != E_OK) {
1961
1962#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
1963
1964 if (tskid == WWW4_SRV_TASK)
1965 error = free_tcp4_rep(www_srv_info[six].repid, error != E_DLT);
1966 else
1967 error = free_tcp6_rep(www_srv_info[six].repid, error != E_DLT);
1968
1969#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1970
1971 error = FREE_TCP_REP(www_srv_info[six].repid, error != E_DLT);
1972
1973#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1974
1975 if (error != E_OK) {
1976 syslog(LOG_NOTICE, "[WWW%c:%02u EXT] delete REP error: %02u, %s",
1977 apip, www_srv_info[six].cepid,
1978 www_srv_info[six].repid, itron_strerror(error));
1979
1980 }
1981 break;
1982 }
1983 }
1984
1985#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
1986
1987 if (tskid == WWW4_SRV_TASK) {
1988 if ((error = free_tcp4_cep(www_srv_info[six].cepid)) != E_OK)
1989 syslog(LOG_NOTICE, "[WWW%c:%02u EXT] delete CEP error: %s",
1990 apip, www_srv_info[six].cepid, itron_strerror(error));
1991 }
1992 else {
1993 if ((error = free_tcp6_cep(www_srv_info[six].cepid)) != E_OK)
1994 syslog(LOG_NOTICE, "[WWW%c:%02u EXT] delete CEP error: %s",
1995 apip, www_srv_info[six].cepid, itron_strerror(error));
1996 }
1997
1998#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
1999
2000 if ((error = FREE_TCP_CEP(www_srv_info[six].cepid)) != E_OK)
2001 syslog(LOG_NOTICE, "[WWW%c:%02u EXT] delete CEP error: %s",
2002 apip, www_srv_info[six].cepid, itron_strerror(error));
2003
2004#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
2005
2006 }
2007 }
2008
2009/*
2010 * wakeup_www_srv -- WWW サーバタスクの休止解除
2011 */
2012
2013ER
2014wakeup_www_srv (char apip)
2015{
2016 ID taskid;
2017
2018 if (apip == API_PROTO_IPV6)
2019 taskid = WWW6_SRV_TASK;
2020 else
2021 taskid = WWW4_SRV_TASK;
2022 syslog(LOG_NOTICE, "[WWW%c(EXT):%d] wake up.", apip, taskid);
2023 return wup_tsk(taskid);
2024 }
2025
2026#else /* of #ifdef USE_TCP_EXTENTIONS */
2027
2028/*
2029 * WWW サーバタスク
2030 */
2031
2032void
2033www_srv_task(intptr_t exinf)
2034{
2035 ID tskid, cepid;
2036 uint_t six;
2037 char apip;
2038
2039 get_tim(&srv_start);
2040 get_tid(&tskid);
2041 six = INDEX_SRV_INFO((ID)exinf);
2042 cepid = www_srv_info[INDEX_SRV_INFO((ID)exinf)].cepid;
2043
2044#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
2045
2046 if (six >= NUM_WWW4_SRV_TASKS)
2047 apip = API_PROTO_IPV6;
2048 else
2049 apip = API_PROTO_IPV4;
2050
2051#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
2052
2053 apip = API_PROTO_IPVn;
2054
2055#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
2056
2057 syslog(LOG_NOTICE, "[WWW%c SRV:%d,%d] started.", apip, tskid, cepid);
2058
2059 while (true) {
2060 while (www_srv(six, apip) == E_OK)
2061 ;
2062 }
2063 }
2064
2065#endif /* of #ifdef USE_TCP_EXTENTIONS */
2066
2067#endif /* of #ifdef USE_WWW_SRV */
Note: See TracBrowser for help on using the repository browser.