Thread.h
上传用户:st5609838
上传日期:2013-03-29
资源大小:66k
文件大小:3k
源码类别:

搜索引擎

开发平台:

Visual C++

  1. // InetThread.h : header file
  2. //
  3. /******************************************************************
  4. Pre-emptive Multithreading Web Spider
  5. ************************************************************/
  6. #if !defined _Thread_H
  7. #define _Thread_H
  8. #include <afxtempl.h>
  9. class CEntry : public CObject
  10. {
  11. public:
  12. CString m_URL;
  13. CString m_URLPage;
  14. CString m_StatusString;
  15. CString m_LastModified;
  16. CString m_ContentType;
  17. CString m_ContentLength;
  18. DWORD m_Status;
  19.  
  20. };
  21. class CriticalSectionLock
  22. {
  23. public:
  24.     CriticalSectionLock()
  25. {
  26. InitializeCriticalSection(&m_CritSect);
  27. EnterCriticalSection(&m_CritSect);
  28. }
  29.     ~CriticalSectionLock()
  30. {
  31. LeaveCriticalSection(&m_CritSect);
  32. DeleteCriticalSection(&m_CritSect);
  33. }
  34. private:
  35.     CRITICAL_SECTION m_CritSect; 
  36. };
  37. extern  UINT g_nEntries;
  38. extern CArray<CEntry*, CEntry*> g_entry;
  39. int LookUpEntry(LPCTSTR pszURL);
  40. int AddEntry(URLStatus * lpEntry);
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CSpiderThread thread
  43. class CMyInternetSession : public CInternetSession
  44. {
  45. public:
  46. CMyInternetSession(LPCTSTR pstrAgent = NULL, DWORD dwContext = 1, DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG, LPCTSTR pstrProxyName = NULL, LPCTSTR pstrProxyBypass = NULL, DWORD dwFlags = 0 ) 
  47. : CInternetSession(pstrAgent, dwContext, dwAccessType,
  48. pstrProxyName, pstrProxyBypass, dwFlags) 
  49. {  m_pMainWnd = NULL; };
  50. // Attributes
  51. public:
  52. HWND m_pMainWnd;  // pointer to parent window
  53. CString m_strHttpSite;  // current URL 
  54. // Operations
  55. public:
  56. virtual void OnStatusCallback(DWORD dwContext, DWORD dwInternetStatus,
  57. LPVOID lpvStatusInfomration, DWORD dwStatusInformationLen);
  58. };
  59. class CSpiderThread : public CWinThread
  60. {
  61. public:
  62. CSpiderThread(AFX_THREADPROC pfnThreadProc,ThreadParams *pThreadParams);     
  63. virtual ~CSpiderThread();
  64. static UINT ThreadFunc(LPVOID lparam);
  65. BOOL ThreadRun(ThreadParams *pThreadParams);
  66. BOOL m_bDone;
  67. void KillThread();
  68. // Implementation
  69. public:
  70. // Generated message map functions
  71. //{{AFX_MSG(CSpiderThread)
  72. // NOTE - the ClassWizard will add and remove member functions here.
  73. //}}AFX_MSG
  74. DECLARE_MESSAGE_MAP()
  75. private:
  76. CMyInternetSession* m_pSession;
  77. CHttpConnection* m_pServer;
  78. CHttpFile* m_pFile;
  79. CString m_strCurrentServer;
  80. BOOL CleanUp();
  81. BOOL InitServer();
  82. BOOL PrintLine(ThreadParams *pThreadParams,LPCSTR line);
  83. BOOL PrintFile(ThreadParams *pThreadParams,
  84. LPCSTR line);
  85. BOOL PrintStatus(ThreadParams *pThreadParams,
  86. LPCSTR line);
  87. BOOL GetStatus(ThreadParams *pThreadParams,UINT ntype,LPCSTR line);
  88. BOOL GetNewFile(ThreadParams *pThreadParams,UINT ntype,LPCSTR line);
  89. int GetServerList(LPCTSTR pszURL,CStringList& list,CString& lpSub);
  90. DWORD NewConnection(LPCTSTR ServerName,LPCTSTR strObject);
  91. BOOL ParseURL(ThreadParams *pThreadParams);
  92. DWORD GetHttpStatus(LPCTSTR lpServerName,LPCTSTR strObject);
  93. BOOL GetServerHeader(LPCTSTR ServerName,LPCTSTR strObject, ThreadParams *pThreadParams);
  94. BOOL GetHttpFile(LPCTSTR ServerName,LPCTSTR strObject,ThreadParams *pThreadParams,BOOL ViewFile =TRUE);
  95. BOOL CheckURL(LPCTSTR ServerName,LPCTSTR strObject, ThreadParams *pThreadParams);
  96. BOOL CheckAllURLs(LPCTSTR ServerName,ThreadParams *pThreadParams);
  97. };
  98. #endif
  99. /////////////////////////////////////////////////////////////////////////////