helper.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #pragma once
  2. #include "../../Src/SocketInterface.h"
  3. #define USER_INFO_MSG (WM_USER + 100)
  4. #define MAX_LOG_RECORD_LENGTH 1000
  5. #define EVT_ON_SEND _T("OnSend")
  6. #define EVT_ON_RECEIVE _T("OnReceive")
  7. #define EVT_ON_CLOSE _T("OnClose")
  8. #define EVT_ON_ERROR _T("OnError")
  9. #define EVT_ON_PREPARE_CONNECT _T("OnPrepareConnect")
  10. #define EVT_ON_PREPARE_LISTEN _T("OnPrepareListen")
  11. #define EVT_ON_ACCEPT _T("OnAccept")
  12. #define EVT_ON_CONNECT _T("OnConnect")
  13. #define EVT_ON_HAND_SHAKE _T("OnHandShake")
  14. #define EVT_ON_SHUTDOWN _T("OnShutdown")
  15. #define EVT_ON_END_TEST _T("END TEST")
  16. #define EVT_ON_MESSAGE_BEGIN _T("OnMessageBegin")
  17. #define EVT_ON_REQUEST_LINE _T("OnRequestLine")
  18. #define EVT_ON_STATUS_LINE _T("OnStatusLine")
  19. #define EVT_ON_HEADER _T("OnHeader")
  20. #define EVT_ON_HEADERS_COMPLETE _T("OnHeadersComplete")
  21. #define EVT_ON_BODY _T("OnBody")
  22. #define EVT_ON_CHUNK_HEADER _T("OnChunkHeader")
  23. #define EVT_ON_CHUNK_COMPLETE _T("OnChunkComplete")
  24. #define EVT_ON_MESSAGE_COMPLETE _T("OnMessageComplete")
  25. #define EVT_ON_UPGRADE _T("OnUpgrade")
  26. #define EVT_ON_PARSE_ERROR _T("OnParseError")
  27. enum EnAppState
  28. {
  29. ST_STARTING, ST_STARTED, ST_CONNECTING, ST_CONNECTED, ST_STOPPING, ST_STOPPED
  30. };
  31. struct info_msg
  32. {
  33. LPCTSTR name;
  34. CONNID connID;
  35. LPCTSTR evt;
  36. int contentLength;
  37. LPCTSTR content;
  38. static info_msg* Construct(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength = 0, LPCTSTR lpszContent = nullptr, LPCTSTR lpszName = nullptr);
  39. static void Destruct(info_msg* pMsg);
  40. private:
  41. info_msg(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength = 0, LPCTSTR lpszContent = nullptr, LPCTSTR lpszName = nullptr);
  42. ~info_msg();
  43. };
  44. struct TPkgHeader
  45. {
  46. DWORD seq;
  47. int body_len;
  48. };
  49. struct TPkgBody
  50. {
  51. char name[30];
  52. short age;
  53. char desc[1];
  54. };
  55. struct TPkgInfo
  56. {
  57. bool is_header;
  58. int length;
  59. TPkgInfo(bool header = true, int len = sizeof(TPkgHeader)) : is_header(header), length(len) {}
  60. void Reset() {is_header = true, length = sizeof(TPkgHeader);}
  61. ~TPkgInfo() {}
  62. };
  63. CBufferPtr* GeneratePkgBuffer(DWORD seq, LPCTSTR lpszName, short age, LPCTSTR lpszDesc);
  64. CBufferPtr* GeneratePkgBuffer(const TPkgHeader& header, const TPkgBody& body);
  65. void SetMainWnd(CWnd* pWnd);
  66. void SetInfoList(CListBox* pInfoList);
  67. void LogServerStart(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName = nullptr);
  68. void LogServerStartFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
  69. void LogServerStop(LPCTSTR lpszName = nullptr);
  70. void LogServerStopFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
  71. void LogClientStart(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName = nullptr);
  72. void LogClientStarting(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName = nullptr);
  73. void LogClientStartFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
  74. void LogClientStopping(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  75. void LogClientStopFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
  76. void LogSend(CONNID dwConnID, LPCTSTR lpszContent, LPCTSTR lpszName = nullptr);
  77. void LogClientSendFail(int iSequence, int iSocketIndex, DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
  78. void LogSendFail(CONNID dwConnID, DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
  79. void LogDisconnect(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  80. void LogDisconnectFail(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  81. void LogRelease(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  82. void LogReleaseFail(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  83. void LogDetect(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  84. void LogDetectFail(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  85. void LogOnConnect(CONNID dwConnID, const CString& strAddress, USHORT usPort);
  86. void LogOnConnect2(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  87. void LogOnHandShake2(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  88. void PostOnSend(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName = nullptr);
  89. void PostOnReceive(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName = nullptr);
  90. void PostOnReceiveCast(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, const BYTE* pData, int iLength, LPCTSTR lpszName = nullptr);
  91. void PostOnClose(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  92. void PostOnError(CONNID dwConnID, int enOperation, int iErrorCode, LPCTSTR lpszName = nullptr);
  93. void PostOnAccept(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, BOOL bPass, LPCTSTR lpszName = nullptr);
  94. void PostOnAccept2(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  95. void PostOnHandShake(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  96. void PostOnPrepareListen(LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName = nullptr);
  97. void PostOnPrepareConnect(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  98. void PostOnConnect(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName = nullptr);
  99. void PostOnConnect2(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName = nullptr);
  100. void PostOnConnect3(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  101. void PostOnShutdown(LPCTSTR lpszName = nullptr);
  102. void PostServerStatics(const LONGLONG& llTotalSent, const LONGLONG& llTotalReceived, LPCTSTR lpszName = nullptr);
  103. void PostTimeConsuming(DWORD dwTickCount, LPCTSTR lpszName = nullptr);
  104. void PostOnMessageBegin(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  105. void PostOnRequestLine(CONNID dwConnID, LPCSTR lpszMethod, USHORT usUrlFieldSet, LPCSTR lpszUrl, LPCTSTR lpszName = nullptr);
  106. void PostOnStatusLine(CONNID dwConnID, USHORT usStatusCode, LPCSTR lpszDesc, LPCTSTR lpszName = nullptr);
  107. void PostOnHeader(CONNID dwConnID, LPCSTR lpszHeaderName, LPCSTR lpszHeaderValue, LPCTSTR lpszName = nullptr);
  108. void PostOnHeadersComplete(CONNID dwConnID, LPCSTR lpszSummary, LPCTSTR lpszName = nullptr);
  109. void PostOnBody(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName = nullptr);
  110. void PostOnChunkHeader(CONNID dwConnID, int iLength, LPCTSTR lpszName = nullptr);
  111. void PostOnChunkComplete(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  112. void PostOnMessageComplete(CONNID dwConnID, LPCTSTR lpszName = nullptr);
  113. void PostOnUpgrade(CONNID dwConnID, EnHttpUpgradeType enUpgradeType, LPCTSTR lpszName = nullptr);
  114. void PostOnParseError(CONNID dwConnID, int iErrorCode, LPCSTR lpszErrorDesc, LPCTSTR lpszName = nullptr);
  115. void PostInfoMsg(info_msg* msg);
  116. void LogInfoMsg(info_msg* pInfoMsg);
  117. void LogMsg(const CString& msg);
  118. #ifdef _SSL_SUPPORT
  119. extern int g_c_iVerifyMode;
  120. extern BOOL g_c_bNeedClientVerification;
  121. extern LPCTSTR g_c_lpszCAPemCertFileOrPath;
  122. extern LPCTSTR g_c_lpszPemCertFile;
  123. extern LPCTSTR g_c_lpszPemKeyFile;
  124. extern LPCTSTR g_c_lpszKeyPasswod;
  125. extern int g_s_iVerifyMode;
  126. extern BOOL g_s_bNeedClientVerification;
  127. extern LPCTSTR g_s_lpszCAPemCertFileOrPath;
  128. extern LPCTSTR g_s_lpszPemCertFile;
  129. extern LPCTSTR g_s_lpszPemKeyFile;
  130. extern LPCTSTR g_s_lpszKeyPasswod;
  131. #endif