M5HttpDown.h
资源名称:nettest.rar [点击查看]
上传用户:pmma55
上传日期:2020-12-28
资源大小:17k
文件大小:2k
源码类别:
手机WAP编程
开发平台:
Visual C++
- #ifndef _M5_HTTP_DOWN_H_
- #include <process.h>
- #include <wininet.h>
- #include <winsock2.h>
- #include <stdio.h>
- #define HTTP_DEBUG_MODE 1
- #define HTTP_WEB_PORT 80
- #define HTTP_TEMP_BUF_LEN 120
- #define HTTP_SEND_BUF_LEN 256
- #define HTTP_RECV_BUF_LEN 4096
- #define HTTP_HDR_OK "200 OK"
- #define HTTP_HDR_FILE_LEN "Content-Length: "
- #define HTTP_HDR_DIV "rn"
- #define HTTP_HDR_END "rnrn"
- #define HTTP_PREFIX "http://"
- #define HTTPS_PREFIX "https://"
- #define HTTP_COMMON_GET "GET /%s HTTP/1.1rn
- User-Agent: Opera 8.0rn
- Host: %s:%drnAccept: */
- *rnConnection: Keep-Alivernrn"
- #define HTTP_RESUME_GET "GET /%s HTTP/1.1rn
- User-Agent: Opera 8.0rn
- Host: %s:%drnAccept: */
- *rnRANGE: bytes=%d-rn
- Connection: Keep-Alivernrn"
- typedef void (*RECV_CALLBACK)(char * recv_buf, int recv_len, void * data) ;
- class CM5HttpDown {
- protected:
- // socket data
- SOCKET m_sock ;
- bool m_running ;
- bool m_is_first_resp ;
- char * m_web_addr ;
- char * m_web_fname ;
- int m_web_port ;
- char * m_recv_buf ;
- int m_total_bytes ;
- int m_recv_bytes;
- // custom defined receive handler
- RECV_CALLBACK m_custom_callback ;
- void * m_custom_data ;
- public:
- // common receive thread func
- static void recv_thread(void * data) ;
- void recv_thread_handler() ;
- protected:
- bool parse_uri(char * uri,
- char * web_addr, char * web_fname, int * web_port) ;
- bool parse_webfile_info(char * recv_buf,
- int * total_length, int * jump_len) ;
- bool get_resp_field(char * recv_buf,
- char * field_name, char * end_flag, char * res) ;
- bool init_sock(char * server_name, int server_port) ;
- bool send_req(char * req_str, int req_len) ;
- bool close_sock() ;
- public:
- CM5HttpDown() ;
- ~CM5HttpDown() ;
- bool is_running() {return m_running ; }
- int http_total_size() { return m_total_bytes ; }
- int http_recv_size() { return m_recv_bytes ; }
- bool http_down(char * uri,
- RECV_CALLBACK custom_func, void * custom_data,
- int recv_bytes = 0) ;
- bool http_stop() ;
- } ;
- #endif