source: EcnlProtoTool/trunk/ntshell/webserver/httpd.h@ 441

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

NTShellタスクを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 5.9 KB
Line 
1/*
2 * TOPPERS PROJECT Home Network Working Group Software
3 *
4 * Copyright (C) 2017-2019 Cores Co., Ltd. Japan
5 *
6 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
7 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
8 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
9 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
10 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
11 * スコード中に含まれていること.
12 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
13 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
14 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
15 * の無保証規定を掲載すること.
16 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
17 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
18 * と.
19 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
20 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
21 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
22 * 報告すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
26 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
27 * 免責すること.
28 *
29 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
30 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
31 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
32 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
33 * の責任を負わない.
34 *
35 * @(#) $Id$
36 */
37
38#ifndef __HTTPD_H__
39#define __HTTPD_H__
40
41/*
42 * ターゲット依存の定義
43 */
44#include <kernel.h>
45#include "httpd-fs.h"
46#include "http_parser.h"
47#include "websocket.h"
48
49/*
50 * 各タスクの優先度の定義
51 */
52
53#define HTTPD_PRIORITY 5 /* HTTPサーバータスクの優先度 */
54
55#define HTTPD_STACK_SIZE 1024 /* HTTPサーバータスクのスタック領域のサイズ */
56
57 /* TCP 送受信ウィンドバッファサイズ */
58
59#define TCP_SWBUF_SIZE 1024
60#define TCP_RWBUF_SIZE 1024
61
62/*
63 * 関数のプロトタイプ宣言
64 */
65#ifndef TOPPERS_MACRO_ONLY
66
67 /* TCP 送受信ウィンドバッファ */
68#ifdef SUPPORT_INET6
69extern uint8_t tcp6_swbuf1[];
70extern uint8_t tcp6_rwbuf1[];
71extern uint8_t tcp6_swbuf2[];
72extern uint8_t tcp6_rwbuf2[];
73#endif
74
75#ifdef SUPPORT_INET4
76extern uint8_t tcp_swbuf1[];
77extern uint8_t tcp_rwbuf1[];
78extern uint8_t tcp_swbuf2[];
79extern uint8_t tcp_rwbuf2[];
80#endif
81
82/* HTTPサーバータスク */
83extern void httpd_task(intptr_t exinf);
84
85#define MAX_ELEMENT_SIZE 256
86
87struct message {
88 enum http_method method;
89 unsigned short http_major;
90 unsigned short http_minor;
91 char filename[64];
92 char request_url[MAX_ELEMENT_SIZE];
93 char response_status[64];
94 int num_headers;
95 char host[MAX_ELEMENT_SIZE];
96 char referer[MAX_ELEMENT_SIZE];
97 char upgrade[32];
98 char connection[32];
99 char sec_websocket_key[64];
100 char origin[MAX_ELEMENT_SIZE];
101 char sec_websocket_protocol[64];
102 char sec_websocket_version[4];
103 char response_key[86];
104 size_t body_size;
105 int should_keep_alive;
106 int headers_complete_cb_called;
107 int message_begin_cb_called;
108 int message_complete_cb_called;
109 int body_is_final;
110};
111
112#ifndef _MSC_VER
113size_t strnlen(const char *s, size_t maxlen);
114#endif
115size_t strlncat(char *dst, size_t len, const char *src, size_t n);
116extern http_parser_settings websvr_settings;
117
118typedef enum httpd_state_t {
119 STATE_DISCONNECTED, /* 切断中 */
120 STATE_CONNECTED, /* 接続中 */
121 STATE_WEBSOCKET, /* WebSocket通信中 */
122 STATE_CLOSING, /* 切断処理中 */
123 STATE_RESET, /* mruby起動のためのリセット */
124} httpd_state_t;
125
126typedef enum httpd_in_state_t {
127 IN_STATE_START,
128 IN_STATE_REQUEST,
129 IN_STATE_UPLOAD,
130 IN_STATE_UPLOAD_WAIT,
131 IN_STATE_RESPONSE,
132 IN_STATE_WEBSOCKET,
133 IN_STATE_END,
134} httpd_in_state_t;
135
136typedef enum httpd_out_state_t {
137 OUT_STATE_WAIT_REQUEST,
138 OUT_STATE_OPEN_GET_FILE,
139 OUT_STATE_WAIT_POST_BODY,
140 OUT_STATE_BODY_RECEIVED,
141 OUT_STATE_SEND_HEADER,
142 OUT_STATE_SEND_FILE,
143 OUT_STATE_SEND_DATA,
144 OUT_STATE_SEND_END,
145} httpd_out_state_t;
146
147struct httpd_state {
148 ID tskid;
149 ID cepid;
150 uint8_t dst[20];
151 char temp[16];
152 char addr[sizeof("0123:4567:89ab:cdef:0123:4567:89ab:cdef")];
153 httpd_state_t state;
154 int reset;
155 struct {
156 httpd_in_state_t state;
157 bool_t wait;
158 char *data;
159 SYSTIM timer;
160 } in;
161 struct {
162 httpd_out_state_t state;
163 bool_t wait;
164 const char *statushdr;
165 } out;
166 struct {
167 int parse_pos;
168 int parse_len;
169 struct http_parser parser;
170 struct http_parser_url handle;
171 struct message message;
172 };
173 union {
174 struct {
175 char *filename;
176 char *query;
177 struct httpd_fs_file file;
178 };
179 struct {
180 char *_dummy_filename;
181 const char *response_body;
182 int response_pos;
183 int response_len;
184 };
185 struct {
186 struct websocket websocket;
187 int close_req;
188 };
189 };
190};
191#define get_context(p) (struct httpd_state *)((intptr_t)p - (intptr_t)&((struct httpd_state *)0)->parser)
192
193/*
194 * ノンブロッキングコールのコールバック関数
195 */
196extern ER callback_nblk_tcp(ID cepid, FN fncd, void *p_parblk);
197
198#endif /* TOPPERS_MACRO_ONLY */
199
200#endif /* __HTTPD_H__ */
Note: See TracBrowser for help on using the repository browser.