📄 symbian 2nd支持cmnet和cmwap的断点续传的rsocket实现.htm
字号:
<DIV> // search and jump over the http or https
prefix<BR> uri_ptr.Set(uri.Ptr(), uri.Length()) ;
<BR> find_pos = uri.Find(KHttpPrefix) ;
<BR> if(find_pos != KErrNotFound)
{<BR> tmp_buf.Copy(KHttpPrefix) ;
<BR>
uri_ptr.Set(uri.Ptr()+tmp_buf.Length(), uri.Length() -
tmp_buf.Length()) ; <BR> } else {
<BR> find_pos = uri.Find(KHttpsPrefix)
; <BR> if(find_pos != KErrNotFound)
{<BR> tmp_buf.Copy(KHttpsPrefix)
; <BR> uri_ptr.Set(uri.Ptr()+tmp_buf.Length(),
uri.Length() - tmp_buf.Length()) ;
<BR> } <BR> }</DIV>
<DIV> // get web address <BR> find_pos =
uri_ptr.Find(KHttpClip) ; <BR> if(find_pos !=
KErrNotFound) {<BR>
web_addr.Copy(uri_ptr.Mid(0, find_pos)) ; <BR> }</DIV>
<DIV> // get web file name<BR>
m_web_fname.Copy(uri_ptr.Ptr() + find_pos, uri_ptr.Length() -
find_pos) ; </DIV>
<DIV> return ETrue ; <BR>}</DIV>
<DIV><BR>TBool CM5HttpDown::GetRespField(const TDesC8& recv_buf,
TDesC8& field_name, TDesC8& end_flag, TDes8& res)
<BR>{<BR> TPtrC8 ptr_hdr ;
<BR> TInt find_pos ; <BR> if(recv_buf.Length()
<= 0) return EFalse ;</DIV>
<DIV> find_pos = recv_buf.Find(field_name) ;
<BR> if(find_pos != KErrNotFound) {<BR>
ptr_hdr.Set(recv_buf.Ptr() + find_pos + field_name.Length(),
<BR>
recv_buf.Length() - find_pos - field_name.Length()) ;
<BR> find_pos = ptr_hdr.Find(end_flag)
;<BR> if(find_pos != KErrNotFound)
{<BR>
res.Copy(ptr_hdr.Ptr(), find_pos) ; <BR>
}<BR> return ETrue ; <BR> }<BR>
return EFalse ; <BR>}</DIV>
<DIV> </DIV>
<DIV>TBool CM5HttpDown::ParseWebFileInfo(const TDesC8& recv_buf,
TInt& file_length, TInt&
jump_len)<BR>{<BR> TBuf8<30> tmp_field ;
<BR> TBuf8<30> tmp_end ; <BR> TBuf8<30>
tmp_str ; <BR> int find_pos
; </DIV>
<DIV> file_length = 0 ; <BR> jump_len = 0 ; </DIV>
<DIV> // get web file length <BR> if(m_down_type ==
HTTP_DOWN_CMWAP)
{<BR> tmp_field.Append(KHttpCMWapHdrFileLen) ;
<BR> } else
{<BR> tmp_field.Append(KHttpCMNetHdrFileLen) ;
<BR> } <BR> tmp_end.Append(KHttpHdrDiv)
;<BR> if(!GetRespField(recv_buf, tmp_field, tmp_end, tmp_str))
<BR> return EFalse ; </DIV>
<DIV> file_length = Str2Int(tmp_str) ; </DIV>
<DIV> </DIV>
<DIV> // set the jump length <BR> find_pos =
recv_buf.Find(KHttpHdrEnd) ;<BR> if(find_pos != KErrNotFound)
{<BR> tmp_str.Copy(KHttpHdrEnd) ;
<BR> jump_len = find_pos + tmp_str.Length() ;
<BR> }<BR> return ETrue ; <BR>}</DIV>
<DIV> </DIV>
<DIV>TBool CM5HttpDown::InitSock(TDesC8& server_name, TInt
server_port) <BR>{<BR> TBuf<50> svr_name ;
<BR> svr_name.Copy(server_name) ;
<BR> m_sock_eng->SetServerName(svr_name) ;
<BR> m_sock_eng->SetPort(server_port) ;
<BR> m_sock_eng->ConnectL() ; <BR> return
ETrue ; <BR>}</DIV>
<DIV>TBool CM5HttpDown::CloseSock()<BR>{<BR> if(m_running
&& m_sock_eng->IsActive()) {<BR>
m_sock_eng->Disconnect() ; <BR> }<BR>
return true ; <BR>}</DIV>
<DIV> </DIV>
<DIV>TInt CM5HttpDown::Str2Int(const TDesC8 & s)
<BR>{<BR> TInt value = 0 ; <BR> TLex8 lex(s) ;
<BR> lex.Val(value) ; <BR> return value ; <BR>}</DIV>
<DIV> </DIV>
<DIV>TBool CM5HttpDown::HttpConnPorxy(TDesC8& uri, TInt
down_type)<BR>{<BR> m_running = true ; <BR> m_down_type =
down_type ; <BR> ParseUri(uri, m_web_addr, m_web_fname,
m_web_port) ; <BR> if(m_down_type == HTTP_DOWN_CMWAP)
{<BR> TBuf8<20> proxy_svr ;
<BR> proxy_svr.Copy(KCMCCWapProxy) ;
<BR> if(!InitSock(proxy_svr, 80)) return EFalse
; <BR> } else {<BR>
if(!InitSock(m_web_addr, m_web_port)) return EFalse ;
<BR> }<BR> return ETrue ; <BR>}</DIV>
<DIV> </DIV>
<DIV>TBool CM5HttpDown::HttpDown(TDesC8& uri, TInt
recv_bytes)<BR>{<BR> TBuf8<20> tmp_str ; <BR>
m_recv_bytes = recv_bytes ; <BR> m_send_buf.SetLength(0)
; <BR> if(m_recv_bytes == 0)
{<BR>
m_send_buf.Append(KHttpCommonGet1) ;
<BR> if(m_down_type ==
HTTP_DOWN_CMWAP)<BR>
m_send_buf.Append(uri)
; <BR> else <BR> m_send_buf.Append(m_web_fname)
; <BR> </DIV>
<DIV>
m_send_buf.Append(KHttpCommonGet2) ;
<BR> m_send_buf.Append(m_web_addr) ;
<BR>
m_send_buf.Append(KHttpCommonGet3) ;
<BR> tmp_str.Format(_L8("%d"),
m_web_port) ; <BR>
m_send_buf.Append(tmp_str) ; <BR>
m_send_buf.Append(KHttpCommonGet4) ;<BR> } else
{<BR>
m_send_buf.Append(KHttpResumeGet1) ; <BR>
if(m_down_type ==
HTTP_DOWN_CMWAP)<BR>
m_send_buf.Append(uri) ; <BR>
else<BR>
m_send_buf.Append(m_web_fname) ; <BR>
</DIV>
<DIV> m_send_buf.Append(KHttpResumeGet2) ;
<BR> m_send_buf.Append(m_web_addr) ;
<BR> m_send_buf.Append(KHttpResumeGet3) ;
<BR> tmp_str.Format(_L8("%d"), m_web_port) ;
<BR> m_send_buf.Append(tmp_str) ;
<BR> m_send_buf.Append(KHttpResumeGet4) ;
<BR> tmp_str.Format(_L8("%d"), m_recv_bytes)
;<BR> m_send_buf.Append(tmp_str) ;
<BR> m_send_buf.Append(KHttpResumeGet5) ;
<BR> }</DIV>
<DIV> // send the request<BR>
return SendReq(m_send_buf) ; <BR>}</DIV>
<DIV> </DIV>
<DIV>TBool CM5HttpDown::HttpStopDown()<BR>{<BR>
return CloseSock() ; <BR>}</DIV>
<DIV><BR>大概就是这个样子了,一些使用方面的注意事项请参阅以前的帖子吧。这个chinaunix似乎把代码排版都给弄乱了,我也没办法了,凑合者用吧。欢迎各位朋友多多提意见和建议,谢谢。</DIV>
<DIV>代码和sis文件包下载:</DIV>
<DIV>
<TABLE style="BORDER-COLLAPSE: collapse" borderColor=#dddddd
cellSpacing=0 cellPadding=0 width=360 align=center border=1>
<TBODY>
<TR height=60>
<TD align=middle width=60><IMG alt=""
src="symbian 2nd支持cmnet和cmwap的断点续传的RSocket实现.files/rar.gif"
border=0></TD>
<TD>
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=0
cellPadding=0 width="100%" border=0>
<TBODY>
<TR height=20>
<TD align=middle width=40>文件:</TD>
<TD>NetTest.rar</TD></TR>
<TR height=20>
<TD align=middle width=40>大小:</TD>
<TD>64KB</TD></TR>
<TR height=20>
<TD align=middle width=40>下载:</TD>
<TD><A
href="http://blogimg.chinaunix.net/blog/upfile2/080108162635.rar">下载</A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV>
<DIV> </DIV>
<DIV> </DIV></DIV></TD></TR></TBODY></TABLE>
<P style="MARGIN: 5px; LINE-HEIGHT: 150%"></P></TD></TR>
<TR>
<TD align=middle height=25><FONT color=#295200>发表于: 2008-01-08,修改于:
2008-01-08 16:27,已浏览610次,有评论0条</FONT> <A id=star title=推荐这篇文章
onclick="NewWindows(this.href);return false;"
href="http://www.cublog.cn/u2/star.php?blogid=26691&artid=459698">推荐</A>
<A id=complaint title=投诉这篇文章 onclick="NewWindows(this.href);return false;"
href="http://www.cublog.cn/u2/complaint.php?blogid=26691&artid=459698">投诉</A>
</TD></TR>
<TR>
<TD align=middle height=9><IMG height=13 alt=""
src="symbian 2nd支持cmnet和cmwap的断点续传的RSocket实现.files/line1.gif" width=702
border=0></TD></TR>
<TR>
<TD>
<TABLE style="COLOR: #02368d; BORDER-COLLAPSE: collapse" cellSpacing=0
cellPadding=0 width="95%" align=center border=0>
<TBODY></TBODY></TABLE><BR>
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0
width="95%" align=center border=0>
<TBODY>
<TR height=25>
<TD width=25><IMG height=16 alt=""
src="symbian 2nd支持cmnet和cmwap的断点续传的RSocket实现.files/dot.gif" width=16
border=0></TD>
<TD width=80><B>给我留言</B> </TD>
<TD id=pagelist width=405></TD></TR>
<TR>
<TD bgColor=#90baed colSpan=3 height=2></TD></TR>
<TR>
<TD colSpan=3 height=2></TD></TR></TBODY></TABLE>
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0
width=500 align=center border=0>
<TBODY>
<TR>
<TD height=25><IFRAME name=comment
src="symbian 2nd支持cmnet和cmwap的断点续传的RSocket实现.files/comment.htm"
frameBorder=0 width=640
height=160></IFRAME></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=760
align=center bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD bgColor=#ffffff height=3></TD></TR>
<TR>
<TD bgColor=#dddddd height=1></TD></TR>
<TR>
<TD bgColor=#ffffff height=3></TD></TR>
<TR>
<TD align=middle>版权所有 ChinaUnix.net 页面生成时间:0.00791</TD></TR></TBODY></TABLE>
<CENTER></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -