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

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

ntstdio_snprintfの動作が間違っていたのを修正。
Webサーバーを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 5.7 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 512
60#define TCP_RWBUF_SIZE 512
61
62/*
63 * 関数のプロトタイプ宣言
64 */
65#ifndef TOPPERS_MACRO_ONLY
66
67 /* TCP 送受信ウィンドバッファ */
68
69extern uint8_t tcp_swbuf1[];
70extern uint8_t tcp_rwbuf1[];
71extern uint8_t tcp_swbuf2[];
72extern uint8_t tcp_rwbuf2[];
73
74/* HTTPサーバータスク */
75extern void httpd_task(intptr_t exinf);
76
77#define MAX_ELEMENT_SIZE 256
78
79struct message {
80 enum http_method method;
81 unsigned short http_major;
82 unsigned short http_minor;
83 char filename[64];
84 char request_url[MAX_ELEMENT_SIZE];
85 char response_status[64];
86 int num_headers;
87 char host[MAX_ELEMENT_SIZE];
88 char referer[MAX_ELEMENT_SIZE];
89 char upgrade[32];
90 char connection[32];
91 char sec_websocket_key[64];
92 char origin[MAX_ELEMENT_SIZE];
93 char sec_websocket_protocol[64];
94 char sec_websocket_version[4];
95 char response_key[86];
96 size_t body_size;
97 int should_keep_alive;
98 int headers_complete_cb_called;
99 int message_begin_cb_called;
100 int message_complete_cb_called;
101 int body_is_final;
102};
103
104#ifndef _MSC_VER
105size_t strnlen(const char *s, size_t maxlen);
106#endif
107size_t strlncat(char *dst, size_t len, const char *src, size_t n);
108extern http_parser_settings websvr_settings;
109
110typedef enum httpd_state_t {
111 STATE_DISCONNECTED, /* 切断中 */
112 STATE_CONNECTED, /* 接続中 */
113 STATE_WEBSOCKET, /* WebSocket通信中 */
114 STATE_CLOSING, /* 切断処理中 */
115 STATE_RESET, /* mruby起動のためのリセット */
116} httpd_state_t;
117
118typedef enum httpd_in_state_t {
119 IN_STATE_START,
120 IN_STATE_REQUEST,
121 IN_STATE_UPLOAD,
122 IN_STATE_UPLOAD_WAIT,
123 IN_STATE_RESPONSE,
124 IN_STATE_WEBSOCKET,
125 IN_STATE_END,
126} httpd_in_state_t;
127
128typedef enum httpd_out_state_t {
129 OUT_STATE_WAIT_REQUEST,
130 OUT_STATE_OPEN_GET_FILE,
131 OUT_STATE_WAIT_POST_BODY,
132 OUT_STATE_BODY_RECEIVED,
133 OUT_STATE_SEND_HEADER,
134 OUT_STATE_SEND_FILE,
135 OUT_STATE_SEND_DATA,
136 OUT_STATE_SEND_END,
137} httpd_out_state_t;
138
139struct httpd_state {
140 ID tskid;
141 ID cepid;
142 uint8_t dst[20];
143 char temp[16];
144 char addr[sizeof("0123:4567:89ab:cdef:0123:4567:89ab:cdef")];
145 httpd_state_t state;
146 int reset;
147 struct {
148 httpd_in_state_t state;
149 bool_t wait;
150 char *data;
151 SYSTIM timer;
152 } in;
153 struct {
154 httpd_out_state_t state;
155 bool_t wait;
156 const char *statushdr;
157 } out;
158 struct {
159 int parse_pos;
160 int parse_len;
161 struct http_parser parser;
162 struct http_parser_url handle;
163 struct message message;
164 };
165 union {
166 struct {
167 char *filename;
168 char *query;
169 struct httpd_fs_file file;
170 };
171 struct {
172 char *_dummy_filename;
173 const char *response_body;
174 int response_pos;
175 int response_len;
176 };
177 struct {
178 struct websocket websocket;
179 int close_req;
180 };
181 };
182};
183#define get_context(p) (struct httpd_state *)((intptr_t)p - (intptr_t)&((struct httpd_state *)0)->parser)
184
185/*
186 * ノンブロッキングコールのコールバック関数
187 */
188extern ER callback_nblk_tcp(ID cepid, FN fncd, void *p_parblk);
189
190#endif /* TOPPERS_MACRO_ONLY */
191
192#endif /* __HTTPD_H__ */
Note: See TracBrowser for help on using the repository browser.