1 | /*
|
---|
2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
3 | *
|
---|
4 | * Copyright (C) 2017 Cores Co., Ltd. Japan
|
---|
5 | *
|
---|
6 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
7 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
8 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
9 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
10 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
11 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
12 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
13 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
14 | gip
|
---|
15 | * Ò}j
|
---|
16 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
17 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
18 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
19 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
20 | * ÆD
|
---|
21 | * (a) Äzzɺ¤hL
|
---|
22 | gipÒ}j
|
---|
23 | AÈÇjÉCãLÌ
|
---|
24 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
25 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
26 | * ñ·é±ÆD
|
---|
27 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
28 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
29 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
30 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
31 | * ÆÓ·é±ÆD
|
---|
32 | *
|
---|
33 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
34 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
35 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
36 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
37 | * ÌÓCðíÈ¢D
|
---|
38 | *
|
---|
39 | * @(#) $Id: httpd.h 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
40 | */
|
---|
41 |
|
---|
42 | #ifndef __HTTPD_H__
|
---|
43 | #define __HTTPD_H__
|
---|
44 |
|
---|
45 | #include "httpd-fs.h"
|
---|
46 | #include "http_parser.h"
|
---|
47 | #include "websocket.h"
|
---|
48 |
|
---|
49 | #define MAX_ELEMENT_SIZE 256
|
---|
50 |
|
---|
51 | struct message {
|
---|
52 | enum http_method method;
|
---|
53 | unsigned short http_major;
|
---|
54 | unsigned short http_minor;
|
---|
55 | char filename[64];
|
---|
56 | char request_url[MAX_ELEMENT_SIZE];
|
---|
57 | char response_status[64];
|
---|
58 | int num_headers;
|
---|
59 | char host[MAX_ELEMENT_SIZE];
|
---|
60 | char referer[MAX_ELEMENT_SIZE];
|
---|
61 | char upgrade[32];
|
---|
62 | char connection[32];
|
---|
63 | char sec_websocket_key[64];
|
---|
64 | char origin[MAX_ELEMENT_SIZE];
|
---|
65 | char sec_websocket_protocol[64];
|
---|
66 | char sec_websocket_version[4];
|
---|
67 | char response_key[86];
|
---|
68 | size_t body_size;
|
---|
69 | int should_keep_alive;
|
---|
70 | int headers_complete_cb_called;
|
---|
71 | int message_begin_cb_called;
|
---|
72 | int message_complete_cb_called;
|
---|
73 | int body_is_final;
|
---|
74 | };
|
---|
75 |
|
---|
76 | #ifndef _MSC_VER
|
---|
77 | size_t strnlen(const char *s, size_t maxlen);
|
---|
78 | #endif
|
---|
79 | size_t strlncat(char *dst, size_t len, const char *src, size_t n);
|
---|
80 | extern http_parser_settings websvr_settings;
|
---|
81 |
|
---|
82 | typedef enum httpd_state_t {
|
---|
83 | STATE_DISCONNECTED, /* Øf */
|
---|
84 | STATE_CONNECTED, /* Ú± */
|
---|
85 | STATE_WEBSOCKET, /* WebSocketÊM */
|
---|
86 | STATE_CLOSING, /* Øf */
|
---|
87 | STATE_RESET, /* mrubyN®Ì½ßÌZbg */
|
---|
88 | } httpd_state_t;
|
---|
89 |
|
---|
90 | typedef enum httpd_in_state_t {
|
---|
91 | IN_STATE_START,
|
---|
92 | IN_STATE_REQUEST,
|
---|
93 | IN_STATE_UPLOAD,
|
---|
94 | IN_STATE_UPLOAD_WAIT,
|
---|
95 | IN_STATE_RESPONSE,
|
---|
96 | IN_STATE_WEBSOCKET,
|
---|
97 | IN_STATE_END,
|
---|
98 | } httpd_in_state_t;
|
---|
99 |
|
---|
100 | typedef enum httpd_out_state_t {
|
---|
101 | OUT_STATE_WAIT_REQUEST,
|
---|
102 | OUT_STATE_OPEN_GET_FILE,
|
---|
103 | OUT_STATE_WAIT_POST_BODY,
|
---|
104 | OUT_STATE_BODY_RECEIVED,
|
---|
105 | OUT_STATE_SEND_HEADER,
|
---|
106 | OUT_STATE_SEND_FILE,
|
---|
107 | OUT_STATE_SEND_DATA,
|
---|
108 | OUT_STATE_SEND_END,
|
---|
109 | } httpd_out_state_t;
|
---|
110 |
|
---|
111 | struct httpd_state {
|
---|
112 | ID tskid;
|
---|
113 | ID cepid;
|
---|
114 | uint8_t dst[20];
|
---|
115 | char temp[16];
|
---|
116 | char addr[sizeof("0123:4567:89ab:cdef:0123:4567:89ab:cdef")];
|
---|
117 | httpd_state_t state;
|
---|
118 | int reset;
|
---|
119 | struct {
|
---|
120 | httpd_in_state_t state;
|
---|
121 | bool_t wait;
|
---|
122 | char *data;
|
---|
123 | SYSTIM timer;
|
---|
124 | } in;
|
---|
125 | struct {
|
---|
126 | httpd_out_state_t state;
|
---|
127 | bool_t wait;
|
---|
128 | const char *statushdr;
|
---|
129 | } out;
|
---|
130 | struct {
|
---|
131 | int parse_pos;
|
---|
132 | int parse_len;
|
---|
133 | struct http_parser parser;
|
---|
134 | struct http_parser_url handle;
|
---|
135 | struct message message;
|
---|
136 | };
|
---|
137 | union {
|
---|
138 | struct {
|
---|
139 | char *filename;
|
---|
140 | char *query;
|
---|
141 | struct httpd_fs_file file;
|
---|
142 | };
|
---|
143 | struct {
|
---|
144 | char *_dummy_filename;
|
---|
145 | const char *response_body;
|
---|
146 | int response_pos;
|
---|
147 | int response_len;
|
---|
148 | };
|
---|
149 | struct {
|
---|
150 | struct websocket websocket;
|
---|
151 | int close_req;
|
---|
152 | };
|
---|
153 | };
|
---|
154 | };
|
---|
155 | #define get_context(p) (struct httpd_state *)((intptr_t)p - (intptr_t)&((struct httpd_state *)0)->parser)
|
---|
156 |
|
---|
157 | #endif /* __HTTPD_H__ */
|
---|