OSDN Git Service

git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@198 47198e57-cb75-475f-84c4-a814cd...
[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_uipService.h"\r
12 #include "NyLPC_cHttpRequestPrefixParser.h"\r
13 \r
14 \r
15 \r
16 /** 受信バッファのサイズ*/\r
17 #define NyLPC_NyLPC_TcHttpdConnection_SIZE_OF_RX_BUF 512\r
18 \r
19 \r
20 typedef NyLPC_TUInt8 NyLPC_TcHttpdConnection_Status;\r
21 \r
22 /** リクエストプレフィクスを読み出した状態*/\r
23 #define NyLPC_cHttpdConnection_ReqStatus_LISTEN                 0\r
24 /** ACCEPT待ち*/\r
25 #define NyLPC_cHttpdConnection_ReqStatus_ACCEPT                 1\r
26 /** コネクションは接続済*/\r
27 #define NyLPC_cHttpdConnection_ReqStatus_PREFETCH               2\r
28 /** リクエストパース待ち*/\r
29 #define NyLPC_cHttpdConnection_ReqStatus_REQPARSE               3\r
30 /** リクエストパース済*/\r
31 #define NyLPC_cHttpdConnection_ReqStatus_END                    4\r
32 \r
33 \r
34 /** レスポンスヘッダ送付済*/\r
35 #define NyLPC_cHttpdConnection_ResStatus_HEAD   1\r
36 /** レスポンスヘッダ送付済*/\r
37 #define NyLPC_cHttpdConnection_ResStatus_BODY   2\r
38 /** レスポンスBODY送付済*/\r
39 #define NyLPC_cHttpdConnection_ResStatus_CLOSED 3\r
40 /** エラーが発生した。*/\r
41 #define NyLPC_cHttpdConnection_ResStatus_ERROR  4\r
42 \r
43 \r
44 typedef struct NyLPC_TcHttpd NyLPC_TcHttpd_t;\r
45 /**\r
46  * Httpdのハンドラが引き渡す、HTTPDコネクションクラス。\r
47  *\r
48  */\r
49 typedef struct NyLPC_TcHttpdConnection NyLPC_TcHttpdConnection_t;\r
50 struct NyLPC_TcHttpdConnection\r
51 {\r
52         NyLPC_TUInt8 _req_status;//リクエストステータス\r
53         NyLPC_TUInt8 _res_status;//レスポンスステータス\r
54         NyLPC_TUInt8 _connection_message_mode;//COnnection:closeをヘッダに書き込むかのフラグ\r
55         NyLPC_TcHttpd_t* _parent_httpd; //NyLPC_cHttpd\r
56         NyLPC_TcTcpSocket_t _socket;\r
57         NyLPC_TUInt8 _rxbuf[NyLPC_NyLPC_TcHttpdConnection_SIZE_OF_RX_BUF];\r
58         NyLPC_TcHttpStream_t _in_stream;\r
59         NyLPC_TcHttpRequestPrefixParser_t _pparser;\r
60         union{\r
61                 NyLPC_TcHttpBodyWriter_t _body_writer;\r
62                 NyLPC_TcHttpHeaderWriter_t _head_writer;\r
63         };\r
64 };\r
65 \r
66 /**\r
67  * @param i_parent_httpd\r
68  *\r
69  */\r
70 void NyLPC_cHttpdConnection_initialize(NyLPC_TcHttpdConnection_t* i_inst,NyLPC_TcHttpd_t* i_parent_httpd);\r
71 void NyLPC_cHttpdConnection_finalize(NyLPC_TcHttpdConnection_t* i_inst);\r
72 \r
73 \r
74 \r
75 /**\r
76  * レスポンスヘッダを送信します。\r
77  * BodyはChunkedエンコーディングで送信します。\r
78  */\r
79 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
80 /**\r
81  * レスポンスヘッダを送信します。\r
82  * BodyはContentLengthを伴って送信します。Body送信時にサイズチェックは行いません。\r
83  * @i_content_length\r
84  * 最大で0x0fffffffを指定できます。\r
85  */\r
86 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
87 /**\r
88  * レスポンスBodyを送信します。\r
89  * 関数を実行後、_res_statusはBODYかERRORに遷移します。\r
90  */\r
91 NyLPC_TBool NyLPC_cHttpdConnection_sendResponseBody(NyLPC_TcHttpdConnection_t* i_inst,const void* i_data,NyLPC_TUInt32 i_size);\r
92 \r
93 /**\r
94  * レスポンスBodyを書式出力して送信します。\r
95  * 関数を実行後、_res_statusはBODYかERRORに遷移します。\r
96  */\r
97 NyLPC_TBool NyLPC_cHttpdConnection_sendResponseBodyF(NyLPC_TcHttpdConnection_t* i_inst,const char* i_fmt,...);\r
98 \r
99 \r
100 \r
101 /**\r
102  * コネクションのStreamを返します。\r
103  */\r
104 #define NyLPC_cHttpdConnection_refStream(i_inst) (&(i_inst->_in_stream))\r
105 \r
106 #define NyLPC_cHttpdConnection_getMethod(i_inst) (i_inst->_pparser.method)\r
107 #define NyLPC_cHttpdConnection_getReqStatus(i_inst) (i_inst->_req_status)\r
108 \r
109 \r
110 #endif /* NYLPC_CHTTPDCONNECTION_H_ */\r