2 * NyLPC_cHttpClient.h
\r
4 * Created on: 2013/08/24
\r
8 #ifndef NYLPC_CHTTPCLIENT_H_
\r
9 #define NYLPC_CHTTPCLIENT_H_
\r
11 #include "NyLPC_stdlib.h"
\r
12 #include "NyLPC_net.h"
\r
13 #include "NyLPC_http.h"
\r
14 #include "NyLPC_netif.h"
\r
18 #endif /* __cplusplus */
\r
20 typedef struct NyLPC_TcHttpClient NyLPC_TcHttpClient_t;
\r
22 #define NyLPC_cHttpHeaderWriter_CONTENT_LENGTH_UNLIMITED 0xffffffff
\r
23 struct NyLPC_TcHttpClient
\r
25 NyLPC_TUInt8 _state;
\r
26 NyLPC_TUInt8 _padding1;
\r
27 NyLPC_TiTcpSocket_t* _sock;
\r
28 NyLPC_TcHttpStream_t _stream;
\r
30 NyLPC_TcHttpHeaderWriter_t head_writer;
\r
31 NyLPC_TcHttpBodyWriter_t body_writer;
\r
32 NyLPC_TcHttpBasicHeaderParser_t head_parser;
\r
33 NyLPC_TcHttpBodyParser_t body_parser;
\r
38 NyLPC_TBool NyLPC_cHttpClient_initialize(NyLPC_TcHttpClient_t* i_inst,void* i_rx_buf,NyLPC_TUInt16 i_rx_size);
\r
40 void NyLPC_cHttpClient_finalize(NyLPC_TcHttpClient_t* i_inst);
\r
46 void NyLPC_cHttpClient_close(NyLPC_TcHttpClient_t* i_inst);
\r
51 * 関数はステータスをIDLEへ遷移する。
\r
52 * インスタンスのステータスは何でも構わない。
\r
54 * TRUE - ステータスはIDLEへ遷移する。
\r
55 * FALSE - ステータスはCLOSEDへ遷移する。
\r
57 NyLPC_TBool NyLPC_cHttpClient_connect(NyLPC_TcHttpClient_t* i_inst,const struct NyLPC_TIPv4Addr* i_addr,NyLPC_TUInt16 i_port);
\r
63 * ステータスはIDLEである必要がある。
\r
64 * @param i_content_length
\r
65 * 送信bodyのサイズ。最大 0xfffffffe
\r
66 * NyLPC_cHttpHeaderWriter_CONTENT_LENGTH_UNLIMITEDの場合はChunked転送になる。
\r
69 * TRUE - 成功。ステータスはSEND_REQ_BODYになる。write/getStatusを呼び出せる。
\r
70 * FALSE - 失敗。ステータスはCLOSEDになる。
\r
72 NyLPC_TBool NyLPC_cHttpClient_sendMethod(
\r
73 NyLPC_TcHttpClient_t* i_inst,
\r
74 NyLPC_THttpMethodType i_method,
\r
75 const NyLPC_TChar* i_path,
\r
76 NyLPC_TUInt32 i_content_length,
\r
77 const NyLPC_TChar* i_mime_type,
\r
78 const NyLPC_TChar* i_additional_header);
\r
82 * POSTリクエストのデータを送信する。
\r
83 * ステータスはSEND_REQ_BODYである必要がある。
\r
86 * FALSE - 失敗。ステータスはCLOSEDになる。
\r
88 NyLPC_TBool NyLPC_cHttpClient_write(NyLPC_TcHttpClient_t* i_inst,const void* i_buf,NyLPC_TUInt32 i_buf_size);
\r
91 * 書式文字列としてPOSTリクエストのデータを送信する。
\r
92 * ステータスはSEND_REQ_BODYである必要がある。
\r
94 * printfライクなフォーマット文字列
\r
97 * FALSE - 失敗。ステータスはCLOSEDになる。
\r
99 NyLPC_TBool NyLPC_cHttpClient_writeFormat(NyLPC_TcHttpClient_t* i_inst,const NyLPC_TChar* i_fmt,...);
\r
100 NyLPC_TBool NyLPC_cHttpClient_writeFormatV(NyLPC_TcHttpClient_t* i_inst,const NyLPC_TChar* i_fmt,va_list i_args);
\r
104 * ステータスはSEND_REQ_BODYである必要がある。
\r
106 * 0 - 失敗。ステータスはCLOSEDになる。
\r
107 * その他 - ステータスコード。ステータスはRECV_RES_BODYになる。
\r
109 NyLPC_TUInt16 NyLPC_cHttpClient_getStatus(NyLPC_TcHttpClient_t* i_inst);
\r
113 * GET/POSTリクエストで受信したデータを読み出す。
\r
114 * ステータスはRECV_RES_BODYである必要がある。
\r
115 * @param o_read_len
\r
116 * 戻り値TRUEの場合のみ有効。データ終端に達した場合は0になる。
\r
118 * TRUE:正常読み出し。o_read_lenの値で終端判定
\r
119 * FALSE:失敗。コネクションはクローズされる。
\r
121 NyLPC_TBool NyLPC_cHttpClient_read(NyLPC_TcHttpClient_t* i_inst,void* i_buf,NyLPC_TUInt32 i_buf_size,NyLPC_TInt16* o_read_len);
\r
130 #endif /* __cplusplus */
\r
132 #endif /* NYLPC_CHTTPCLIENT_H_ */
\r