* along with this program. If not, see <http://www.gnu.org/licenses/>.\r
*\r
* For further information please contact.\r
- * http://nyatla.jp/\r
- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ * http://nyatla.jp/\r
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
*\r
*********************************************************************************/\r
#include "NyLPC_cHttpStream.h"\r
char _wbuf[1024];\r
const char* _rbuf;\r
int _rbuf_len;\r
-void NyLPC_cTcpSocket_initialized(void* inst,const char* rb,int l)\r
+void NyLPC_iTcpSocket_initialized(void* inst,const char* rb,int l)\r
{\r
- _rbuf=rb;\r
- _rbuf_len=l;\r
+ _rbuf=rb;\r
+ _rbuf_len=l;\r
\r
}\r
-void* NyLPC_cTcpSocket_allocSendBuf(void* inst,NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_len,NyLPC_TUInt32 i_to)\r
+void* NyLPC_iIpTcpSocket_allocSendBuf(void* inst,NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_len,NyLPC_TUInt32 i_to)\r
{\r
- *o_len=30;\r
- return _wbuf;\r
+ *o_len=30;\r
+ return _wbuf;\r
}\r
-NyLPC_TBool NyLPC_cTcpSocket_psend(void* inst,void* i_buf,NyLPC_TUInt16 i_len,NyLPC_TUInt32 i_to)\r
+NyLPC_TBool NyLPC_iTcpSocket_psend(void* inst,void* i_buf,NyLPC_TUInt16 i_len,NyLPC_TUInt32 i_to)\r
{\r
- printf("%.*s",i_len,i_buf);\r
- return NyLPC_TBool_TRUE;\r
+ printf("%.*s",i_len,i_buf);\r
+ return NyLPC_TBool_TRUE;\r
}\r
-NyLPC_TInt32 NyLPC_cTcpSocket_precv(void* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_wait_msec)\r
+NyLPC_TInt32 NyLPC_iTcpSocket_precv(void* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_wait_msec)\r
{\r
- int l=(_rbuf_len>100)?100:_rbuf_len;\r
- *o_buf_ptr=_rbuf;\r
- return l;\r
+ int l=(_rbuf_len>100)?100:_rbuf_len;\r
+ *o_buf_ptr=_rbuf;\r
+ return l;\r
}\r
-void NyLPC_cTcpSocket_pseek(void* i_inst,NyLPC_TUInt16 i_seek)\r
+void NyLPC_iTcpSocket_pseek(void* i_inst,NyLPC_TUInt16 i_seek)\r
{\r
- _rbuf+=i_seek;\r
- _rbuf_len-=i_seek;\r
+ _rbuf+=i_seek;\r
+ _rbuf_len-=i_seek;\r
}\r
\r
-void* NyLPC_cTcpSocket_releaseSendBuf(NyLPC_TcTcpSocket_t* i_inst,void* i_buf_ptr)\r
+void* NyLPC_iTcpSocket_releaseSendBuf(NyLPC_TiTcpSocket_t* i_inst,void* i_buf_ptr)\r
{\r
- return NULL;\r
+ return NULL;\r
}\r
#endif\r
\r
//関数テーブル\r
const static struct NyLPC_TiHttpPtrStream_TInterface _interface=\r
{\r
- pread_func,\r
- write_func,\r
- pseek_func,\r
- flush_func,\r
- setReadEncoding_func,\r
- setWriteEncoding_func\r
+ pread_func,\r
+ write_func,\r
+ pseek_func,\r
+ flush_func,\r
+ setReadEncoding_func,\r
+ setWriteEncoding_func\r
};\r
\r
/**\r
*/\r
static void put_chunked_header(NyLPC_TUInt16 i_val,NyLPC_TUInt8* o_buf)\r
{\r
- const static char* D="0123456789ABCDEF";\r
- *(o_buf+0)=D[((i_val&0x0f00)>>8)];\r
- *(o_buf+1)=D[((i_val&0x00f0)>>4)];\r
- *(o_buf+2)=D[ (i_val&0x000f)];\r
- *(o_buf+3)='\r';\r
- *(o_buf+4)='\n';\r
+ const static char* D="0123456789ABCDEF";\r
+ *(o_buf+0)=D[((i_val&0x0f00)>>8)];\r
+ *(o_buf+1)=D[((i_val&0x00f0)>>4)];\r
+ *(o_buf+2)=D[ (i_val&0x000f)];\r
+ *(o_buf+3)='\r';\r
+ *(o_buf+4)='\n';\r
}\r
/**\r
* 接続済のソケットをストリームに抽象化します。\r
*/\r
-NyLPC_TBool NyLPC_cHttpStream_initialize(NyLPC_TcHttpStream_t* i_inst,NyLPC_TcTcpSocket_t* i_ref_sock)\r
-{\r
- i_inst->super.absfunc=&_interface;\r
- i_inst->_ref_sock=i_ref_sock;\r
- i_inst->we_type=NyLPC_TiHttpPtrStream_ET_NONE;\r
- i_inst->re_type=NyLPC_TiHttpPtrStream_ET_NONE;\r
- i_inst->txb=NULL;\r
- return NyLPC_TBool_TRUE;\r
+NyLPC_TBool NyLPC_cHttpStream_initialize(NyLPC_TcHttpStream_t* i_inst,NyLPC_TiTcpSocket_t* i_ref_sock)\r
+{\r
+ i_inst->super.absfunc=&_interface;\r
+ i_inst->_ref_sock=i_ref_sock;\r
+ i_inst->we_type=NyLPC_TiHttpPtrStream_ET_NONE;\r
+ i_inst->re_type=NyLPC_TiHttpPtrStream_ET_NONE;\r
+ i_inst->txb=NULL;\r
+ return NyLPC_TBool_TRUE;\r
}\r
\r
void NyLPC_cHttpStream_finalize(NyLPC_TcHttpStream_t* i_inst)\r
{\r
- if(i_inst->txb!=NULL){\r
- NyLPC_cTcpSocket_releaseSendBuf(i_inst->_ref_sock,i_inst->txb);\r
- }\r
+ if(i_inst->txb!=NULL){\r
+ NyLPC_iTcpSocket_releaseSendBuf(i_inst->_ref_sock,i_inst->txb);\r
+ }\r
}\r
\r
//\r
-// インタフェイス\r
+// インタフェイス\r
//\r
\r
static NyLPC_TInt32 pread_func(void* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_timeout)\r
{\r
- NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
- return NyLPC_cTcpSocket_precv(inst->_ref_sock,o_buf_ptr,i_timeout);\r
+ NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
+ return NyLPC_iTcpSocket_precv(inst->_ref_sock,o_buf_ptr,i_timeout);\r
}\r
\r
static NyLPC_TBool write_func(void* i_inst,const void* i_data,NyLPC_TInt32 i_length)\r
{\r
- NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
- NyLPC_TUInt16 s,free_size;\r
- NyLPC_TUInt32 l;\r
- const char* src=(const char*)i_data;\r
- l=((i_length<0)?strlen(src):i_length);\r
- while(l>0){\r
- //送信バッファがNULLなら、割り当て。\r
- if(inst->txb==NULL){\r
- inst->txb=(NyLPC_TUInt8*)NyLPC_cTcpSocket_allocSendBuf(inst->_ref_sock,HTTP_TX_BUF_HINT,&s,NyLPC_TiHttpPtrStream_DEFAULT_HTTP_TIMEOUT);\r
- if(inst->txb==NULL){\r
- return NyLPC_TBool_FALSE;\r
- }\r
- //chunked encodingなら、先頭5バイト+末尾2バイトを予約する. 000\r
- if(inst->we_type==NyLPC_TiHttpPtrStream_ET_CHUNKED){\r
- inst->tx_len=5;\r
- inst->txb_size=s-7;\r
- }else{\r
- inst->tx_len=0;\r
- inst->txb_size=s;\r
- }\r
- }\r
- //書き込み可能サイズの計算\r
- free_size=inst->txb_size-inst->tx_len;\r
- if((NyLPC_TInt32)free_size>l){\r
- //書き込み可能サイズがi_length未満なら、バッファに貯めるだけ。\r
- memcpy(inst->txb+inst->tx_len,src,l);\r
- inst->tx_len+=(NyLPC_TUInt16)l;\r
- break;\r
- }\r
- //バッファフルになるなら、送信する。\r
- memcpy(inst->txb+inst->tx_len,src,free_size);\r
- inst->tx_len+=free_size;\r
- //書き込み\r
- if(!flush_func(i_inst)){\r
- //書込みエラー・・・\r
- return NyLPC_TBool_FALSE;\r
- }\r
- //読み出し位置の調整\r
- l-=free_size;\r
- src+=free_size;\r
- };\r
- return NyLPC_TBool_TRUE;\r
+ NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
+ NyLPC_TUInt16 s,free_size;\r
+ NyLPC_TUInt32 l;\r
+ const char* src=(const char*)i_data;\r
+ l=((i_length<0)?strlen(src):i_length);\r
+ while(l>0){\r
+ //送信バッファがNULLなら、割り当て。\r
+ if(inst->txb==NULL){\r
+ inst->txb=(NyLPC_TUInt8*)NyLPC_iTcpSocket_allocSendBuf(inst->_ref_sock,HTTP_TX_BUF_HINT,&s,NyLPC_TiHttpPtrStream_DEFAULT_HTTP_TIMEOUT);\r
+ if(inst->txb==NULL){\r
+ return NyLPC_TBool_FALSE;\r
+ }\r
+ //chunked encodingなら、先頭5バイト+末尾2バイトを予約する. 000\r
+ if(inst->we_type==NyLPC_TiHttpPtrStream_ET_CHUNKED){\r
+ inst->tx_len=5;\r
+ inst->txb_size=s-7;\r
+ }else{\r
+ inst->tx_len=0;\r
+ inst->txb_size=s;\r
+ }\r
+ }\r
+ //書き込み可能サイズの計算\r
+ free_size=inst->txb_size-inst->tx_len;\r
+ if((NyLPC_TInt32)free_size>l){\r
+ //書き込み可能サイズがi_length未満なら、バッファに貯めるだけ。\r
+ memcpy(inst->txb+inst->tx_len,src,l);\r
+ inst->tx_len+=(NyLPC_TUInt16)l;\r
+ break;\r
+ }\r
+ //バッファフルになるなら、送信する。\r
+ memcpy(inst->txb+inst->tx_len,src,free_size);\r
+ inst->tx_len+=free_size;\r
+ //書き込み\r
+ if(!flush_func(i_inst)){\r
+ //書込みエラー・・・\r
+ return NyLPC_TBool_FALSE;\r
+ }\r
+ //読み出し位置の調整\r
+ l-=free_size;\r
+ src+=free_size;\r
+ };\r
+ return NyLPC_TBool_TRUE;\r
}\r
\r
\r
static void pseek_func(void* i_inst,NyLPC_TUInt16 i_seek)\r
{\r
- NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
+ NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
\r
- NyLPC_cTcpSocket_pseek(inst->_ref_sock,i_seek);\r
+ NyLPC_iTcpSocket_pseek(inst->_ref_sock,i_seek);\r
}\r
\r
/**\r
*/\r
static NyLPC_TBool flush_func(void* i_inst)\r
{\r
- NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
- if(inst->txb==NULL){\r
- return NyLPC_TBool_TRUE;\r
- }\r
- //chunkedの場合は、header/footerをセットする。\r
- if(inst->we_type==NyLPC_TiHttpPtrStream_ET_CHUNKED){\r
- //5バイト分のヘッダを記述。\r
- put_chunked_header(inst->tx_len-5,inst->txb);\r
- *(inst->txb+inst->tx_len)=0x0d;\r
- *(inst->txb+inst->tx_len+1)=0x0a;\r
- inst->tx_len+=2;\r
- }\r
- //送信する。\r
- if(!NyLPC_cTcpSocket_psend(inst->_ref_sock,inst->txb,inst->tx_len,NyLPC_TiHttpPtrStream_DEFAULT_HTTP_TIMEOUT)){\r
- //失敗。\r
- NyLPC_cTcpSocket_releaseSendBuf(inst->_ref_sock,inst->txb);\r
- inst->txb=NULL;\r
- return NyLPC_TBool_FALSE;\r
- }\r
- //キャッシュを開放\r
- inst->txb=NULL;\r
- return NyLPC_TBool_TRUE;\r
+ NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
+ if(inst->txb==NULL){\r
+ return NyLPC_TBool_TRUE;\r
+ }\r
+ //chunkedの場合は、header/footerをセットする。\r
+ if(inst->we_type==NyLPC_TiHttpPtrStream_ET_CHUNKED){\r
+ //5バイト分のヘッダを記述。\r
+ put_chunked_header(inst->tx_len-5,inst->txb);\r
+ *(inst->txb+inst->tx_len)=0x0d;\r
+ *(inst->txb+inst->tx_len+1)=0x0a;\r
+ inst->tx_len+=2;\r
+ }\r
+ //送信する。\r
+ if(!NyLPC_iTcpSocket_psend(inst->_ref_sock,inst->txb,inst->tx_len,NyLPC_TiHttpPtrStream_DEFAULT_HTTP_TIMEOUT)){\r
+ //失敗。\r
+ NyLPC_iTcpSocket_releaseSendBuf(inst->_ref_sock,inst->txb);\r
+ inst->txb=NULL;\r
+ return NyLPC_TBool_FALSE;\r
+ }\r
+ //キャッシュを開放\r
+ inst->txb=NULL;\r
+ return NyLPC_TBool_TRUE;\r
}\r
static void setReadEncoding_func(void* i_inst,NyLPC_TiHttpPtrStream_ET i_et)\r
{\r
- //未実装。(この関数は不要?)\r
- NyLPC_Abort();\r
- return;\r
+ //未実装。(この関数は不要?)\r
+ NyLPC_Abort();\r
+ return;\r
}\r
static void setWriteEncoding_func(void* i_inst,NyLPC_TiHttpPtrStream_ET i_et)\r
{\r
- NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
- if(inst->we_type==i_et)\r
- {\r
- return;\r
- }\r
- //バッファがあるならフラッシュしてしまう。\r
- if(inst->txb!=NULL){\r
- if(!flush_func(i_inst)){\r
- return;\r
- }\r
- }\r
- //モードの切り替え。\r
- inst->we_type=i_et;\r
+ NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
+ if(inst->we_type==i_et)\r
+ {\r
+ return;\r
+ }\r
+ //バッファがあるならフラッシュしてしまう。\r
+ if(inst->txb!=NULL){\r
+ if(!flush_func(i_inst)){\r
+ return;\r
+ }\r
+ }\r
+ //モードの切り替え。\r
+ inst->we_type=i_et;\r
}\r