OSDN Git Service

update libMiMic
[mimic/MiMicSDK.git] / lib / src / net / httpd / NyLPC_cHttpdConnection.h
1 /*\r
2  * NyLPC_cHttpdConnection.h\r
3  *\r
4  *  Created on: 2013/02/07\r
5  *      Author: nyatla\r
6  */\r
7 \r
8 #ifndef NYLPC_CHTTPDCONNECTION_H_\r
9 #define NYLPC_CHTTPDCONNECTION_H_\r
10 #include "NyLPC_stdlib.h"\r
11 #include "NyLPC_cHttpRequestPrefixParser.h"\r
12 \r
13 #ifdef __cplusplus\r
14 extern "C" {\r
15 #endif /* __cplusplus */\r
16 \r
17 #ifndef DEFINE_NyLPC_TcHttpd_t\r
18     typedef struct NyLPC_TcHttpd NyLPC_TcHttpd_t;\r
19     #define DEFINE_NyLPC_TcHttpd_t\r
20 #endif\r
21 \r
22 \r
23 typedef NyLPC_TUInt8 NyLPC_TcHttpdConnection_Status;\r
24 \r
25 /** リクエストプレフィクスを読み出した状態*/\r
26 #define NyLPC_cHttpdConnection_ReqStatus_LISTEN         0\r
27 /** ACCEPT待ち*/\r
28 #define NyLPC_cHttpdConnection_ReqStatus_ACCEPT         1\r
29 /** コネクションは接続済*/\r
30 #define NyLPC_cHttpdConnection_ReqStatus_PREFETCH       2\r
31 /** リクエストパース待ち*/\r
32 #define NyLPC_cHttpdConnection_ReqStatus_REQPARSE       3\r
33 /** リクエストパース済*/\r
34 #define NyLPC_cHttpdConnection_ReqStatus_END            4\r
35 #define NyLPC_cHttpdConnection_ReqStatus_BODYPARSE      5\r
36 \r
37 \r
38 \r
39 \r
40 /** レスポンスヘッダ送付済*/\r
41 #define NyLPC_cHttpdConnection_ResStatus_HEAD   1\r
42 /** レスポンスヘッダ送付済*/\r
43 #define NyLPC_cHttpdConnection_ResStatus_BODY   2\r
44 /** レスポンスBODY送付済*/\r
45 #define NyLPC_cHttpdConnection_ResStatus_CLOSED 3\r
46 /** エラーが発生した。*/\r
47 #define NyLPC_cHttpdConnection_ResStatus_ERROR  4\r
48 \r
49 \r
50 \r
51 /**\r
52  * Httpdのハンドラが引き渡す、HTTPDコネクションクラス。\r
53  *\r
54  */\r
55 #ifndef DEFINE_NyLPC_TcHttpdConnection_t\r
56     typedef struct NyLPC_TcHttpdConnection NyLPC_TcHttpdConnection_t;\r
57     #define DEFINE_NyLPC_TcHttpdConnection_t\r
58 #endif\r
59 struct NyLPC_TcHttpdConnection\r
60 {\r
61     NyLPC_TUInt8 _req_status;//リクエストステータス\r
62     NyLPC_TUInt8 _res_status;//レスポンスステータス\r
63     NyLPC_TUInt8 _connection_message_mode;//COnnection:closeをヘッダに書き込むかのフラグ\r
64     NyLPC_TcHttpd_t* _parent_httpd; //NyLPC_cHttpd\r
65     NyLPC_TiTcpSocket_t* _socket;\r
66     NyLPC_TcHttpStream_t _in_stream;\r
67     NyLPC_TcHttpRequestPrefixParser_t _pparser;\r
68     union{\r
69         NyLPC_TcHttpBodyWriter_t _body_writer;\r
70         NyLPC_TcHttpHeaderWriter_t _head_writer;\r
71     };\r
72 };\r
73 \r
74 /**\r
75  * @param i_parent_httpd\r
76  *\r
77  */\r
78 NyLPC_TBool NyLPC_cHttpdConnection_initialize(NyLPC_TcHttpdConnection_t* i_inst,NyLPC_TcHttpd_t* i_parent_httpd);\r
79 void NyLPC_cHttpdConnection_finalize(NyLPC_TcHttpdConnection_t* i_inst);\r
80 \r
81 /**\r
82  * 100 Continueをストリームに送信する。\r
83  * HTTP/1.1でPOSTメッセージを受け付けた場合にコールすること。\r
84  * この関数はステータスがNyLPC_cHttpdConnection_ResStatus_HEADの時だけ実行できる。\r
85  */\r
86 NyLPC_TBool NyLPC_cHttpdConnection_send100Continue(NyLPC_TcHttpdConnection_t* i_inst);\r
87 \r
88 \r
89 /**\r
90  * レスポンスヘッダを送信します。\r
91  * BodyはChunkedエンコーディングで送信します。\r
92  * @param i_additional_header\r
93  * メッセージフィールドに追加する文字列です。\r
94  * \r\nで終端下文字列を指定して下さい。\r
95  */\r
96 NyLPC_TBool NyLPC_cHttpdConnection_sendResponseHeader(NyLPC_TcHttpdConnection_t* i_inst,NyLPC_TUInt16 i_response_code,const NyLPC_TChar* i_content_type,const NyLPC_TChar* i_additional_header);\r
97 /**\r
98  * レスポンスヘッダを送信します。\r
99  * BodyはContentLengthを伴って送信します。Body送信時にサイズチェックは行いません。\r
100  * @param i_content_length\r
101  * 最大で0x0fffffffを指定できます。\r
102  * @param i_additional_header\r
103  * メッセージフィールドに追加する文字列です。\r
104  * \r\nで終端下文字列を指定して下さい。\r
105  */\r
106 NyLPC_TBool NyLPC_cHttpdConnection_sendResponseHeader2(NyLPC_TcHttpdConnection_t* i_inst,NyLPC_TUInt16 i_response_code,const NyLPC_TChar* i_content_type,NyLPC_TUInt32 i_content_length,const NyLPC_TChar* i_additional_header);\r
107 /**\r
108  * レスポンスBodyを送信します。\r
109  * 関数を実行後、_res_statusはBODYかERRORに遷移します。\r
110  */\r
111 NyLPC_TBool NyLPC_cHttpdConnection_sendResponseBody(NyLPC_TcHttpdConnection_t* i_inst,const void* i_data,NyLPC_TUInt32 i_size);\r
112 \r
113 /**\r
114  * レスポンスBodyを書式出力して送信します。\r
115  * 関数を実行後、_res_statusはBODYかERRORに遷移します。\r
116  */\r
117 NyLPC_TBool NyLPC_cHttpdConnection_sendResponseBodyF(NyLPC_TcHttpdConnection_t* i_inst,const char* i_fmt,...);\r
118 \r
119 \r
120 /**\r
121  * Httpd全体で唯一のロックを取得する。\r
122  */\r
123 void NyLPC_cHttpdConnection_lock(NyLPC_TcHttpdConnection_t* i_inst);\r
124 \r
125 /**\r
126  * Httpd全体で唯一のロックを開放する。\r
127  */\r
128 void NyLPC_cHttpdConnection_unlock(NyLPC_TcHttpdConnection_t* i_inst);\r
129 \r
130 \r
131 /**\r
132  * コネクションのStreamを返します。\r
133  */\r
134 #define NyLPC_cHttpdConnection_refStream(i_inst) (&(i_inst->_in_stream.super))\r
135 \r
136 #define NyLPC_cHttpdConnection_getMethod(i_inst) ((i_inst)->_pparser.method)\r
137 #define NyLPC_cHttpdConnection_getReqStatus(i_inst) ((i_inst)->_req_status)\r
138 \r
139 #ifdef __cplusplus\r
140 }\r
141 #endif /* __cplusplus */\r
142 \r
143 #endif /* NYLPC_CHTTPDCONNECTION_H_ */\r