⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httprequest.h

📁 mysee网络直播源代码Mysee Lite是Mysee独立研发的网络视频流媒体播放系统。在应有了P2P技术和一系列先进流媒体技术之后
💻 H
字号:
/*
 *  Openmysee
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
// HttpDownload.h: interface for the HttpDownload class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_HTTPDOWNLOAD_H__D397CA06_A1C5_4301_A6AE_9CE551094F4C__INCLUDED_)
#define AFX_HTTPDOWNLOAD_H__D397CA06_A1C5_4301_A6AE_9CE551094F4C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <WinInet.h>		

/*******************
Create() :类初始化
OpenRequest(CString url) : 打开一个http URL,并将网页内容全部下载(阻塞的)
ReadString: 读取一行,参考CStdioFile同名函数的行为(不牵涉网络操作)
StopRequest: 中断OpenRequest的动作
*******************/

#define USER_BUSY					32775	//程序忙
#define USER_STOP					32776	//使用者中断
#define ERROR_HTML					32774	//代码页错误
#define ERROR_STOP					32777	//错误,工作终结	
#define SUCCEED_CONTINUE			0	//正常,通行		

#define EVENT_SERIES				2
#define DOWNLOAD_THREADS			5

class HttpRequest  
{
public:
	HttpRequest();
	virtual ~HttpRequest();
	
	BOOL Create(UINT = 60000, UINT = 60000, BOOL wide = FALSE);
	void SetFileMode(HANDLE h, DWORD m = UINT_MAX, DWORD n = UINT_MAX)
		{h_File = h; m_dwOffset = m; m_dwOffsetEnd = n;}
	void EndFileMode(){h_File = NULL; m_dwOffset = m_dwOffsetEnd = UINT_MAX;}
	BOOL OpenRequest(LPCWSTR, BOOL cache = FALSE, LPCWSTR send = NULL);
	BOOL OpenRequest(LPCSTR, BOOL cache = FALSE, LPCSTR send = NULL);
	BOOL OpenRequestEx(LPCTSTR, BOOL cache, const void *send, DWORD sendsize);
	void SetStopRequest();
	void ResumeStopRequest();
	BOOL ReadString(LPWSTR);
	BOOL ReadString(LPSTR);
	int  ReadStringEx();
	DWORD GetError(){return errorcode;}
	UINT  getBufLen(){return buflength;}
	void  TransBuf(BYTE* dest){memcpy(dest, recvBuf, buflength);}

	static void  SetProxy(int b){b_useproxy = b;}
	static void  SetProxyName(LPCWSTR s);
	static void	 SetProxyName(LPCSTR s);

    //增强了inet库的效能
    static BOOL  GetCookieEx(
        LPCTSTR lpszUrlName,
        LPCTSTR lpszCookieDataName,
        LPTSTR lpszCookieData,
        LPDWORD lpdwSize);

protected:

	BOOL	fWide;

	static	 void CALLBACK AsyncInternetCallback(		//internet callback func.
		    HINTERNET hInternet,
			DWORD dwContext,
			DWORD dwInternetStatus,
			LPVOID lpvStatusInformation,
			DWORD dwStatusInformationLength);
	static  DWORD WINAPI InitialCallback(LPVOID);

	UINT WaitingEvent(DWORD = INFINITE);
	void HDResetEvent();
	void InternetCloseHandleAsync(HINTERNET);
	BOOL ParseURL(LPCTSTR src, LPTSTR stN, LPTSTR flN, DWORD* port);
	BOOL WriteBuffer(const BYTE*, const DWORD);

	void MakeHeadMsg(BOOL post, LPTSTR);
	void InitWrite(DWORD);

//	HINTERNET	HSO;

	//连接超时
	UINT	Connect_timeout;
	UINT	Request_timeout;

	//回调函数用代码
//	CRITICAL_SECTION m_hSync;
//	BOOL	b_userStop;
	HANDLE m_hEvent[EVENT_SERIES];	//内部交互的事件
	HINTERNET m_hInternet;
	//错误代码
	DWORD errorcode;

	BYTE* recvBuf;
	DWORD  buflength;
	UINT  readstrpos;

	HANDLE h_File;
	DWORD  m_dwOffset;
	DWORD  m_dwOffsetEnd;

	//proxy
	static int  b_useproxy;
	static TCHAR m_proxystr[256];
};

#endif // !defined(AFX_HTTPDOWNLOAD_H__D397CA06_A1C5_4301_A6AE_9CE551094F4C__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -