123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705 |
- #include "stdafx.h"
- #include "helper.h"
- CWnd* g_pMainWnd;
- CListBox* g_pInfoList;
- info_msg* info_msg::Construct(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength, LPCTSTR lpszContent, LPCTSTR lpszName)
- {
- return new info_msg(dwConnID, lpszEvent, iContentLength, lpszContent, lpszName);
- }
- void info_msg::Destruct(info_msg* pMsg)
- {
- delete pMsg;
- }
- info_msg::info_msg(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength, LPCTSTR lpszContent, LPCTSTR lpszName)
- : connID(dwConnID), evt(lpszEvent), contentLength(iContentLength), content(lpszContent), name(nullptr)
- {
- if(lpszName)
- {
- int len = lstrlen(lpszName);
- if(len > 0)
- {
- name = new TCHAR[len + 1];
- memcpy((LPSTR)name, lpszName, (len + 1) * sizeof(TCHAR));
- }
- }
- }
- info_msg::~info_msg()
- {
- if(name)
- delete[] name;
- if(contentLength > 0)
- delete[] content;
- }
- void SetMainWnd(CWnd* pWnd)
- {
- g_pMainWnd = pWnd;
- }
- void SetInfoList(CListBox* pInfoList)
- {
- g_pInfoList = pInfoList;
- }
- inline CString SafeString(LPCTSTR lpszName)
- {
- CString str(lpszName);
- if(lpszName) str.AppendChar(' ');
- return str;
- }
- inline CString SafeString2(LPCTSTR lpszName)
- {
- CString str(lpszName);
- if(lpszName) str.Append(_T(" #"));
- return str;
- }
- void LogServerStart(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sServer Start OK --> (%s : %d)"), SafeString(lpszName), lpszAddress, port);
- LogMsg(msg);
- }
- void LogServerStartFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sServer Start Fail --> %s (%d)"), SafeString(lpszName), lpszDesc, code);
- LogMsg(msg);
- }
- void LogServerStop(LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sServer Stop"), SafeString(lpszName));
- LogMsg(msg);
- }
- void LogServerStopFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sServer Stop Fail --> %s (%d)"), SafeString(lpszName), lpszDesc, code);
- LogMsg(msg);
- }
- void LogClientStart(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sClient Start OK --> (%s : %d)"), SafeString(lpszName), lpszAddress, port);
- LogMsg(msg);
- }
- void LogClientStarting(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sClient Starting ... --> (%s : %d)"), SafeString(lpszName), lpszAddress, port);
- LogMsg(msg);
- }
- void LogClientStartFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sClient Start Fail --> %s (%d)"), SafeString(lpszName), lpszDesc, code);
- LogMsg(msg);
- }
- void LogClientStopping(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sClient Stopping ... --> (%Iu)"), SafeString(lpszName), dwConnID);
- LogMsg(msg);
- }
- void LogClientStopFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sClient Stop Fail --> %s (%d)"), SafeString(lpszName), lpszDesc, code);
- LogMsg(msg);
- }
- void LogClientSendFail(int iSequence, int iSocketIndex, DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %sClient Send Fail [SOCK: %d, SEQ: %d] --> %s (%d)"), SafeString(lpszName), iSocketIndex, iSequence, lpszDesc, code);
- LogMsg(msg);
- }
- void LogSend(CONNID dwConnID, LPCTSTR lpszContent, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %s(%Iu) Send OK --> %s"), SafeString2(lpszName), dwConnID, lpszContent);
- LogMsg(msg);
- }
- void LogSendFail(CONNID dwConnID, DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %s(%Iu) Send Fail --> %s (%d)"), SafeString2(lpszName), dwConnID, lpszDesc, code, lpszName);
- LogMsg(msg);
- }
- void LogDisconnect(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %s(%Iu) Disconnect OK"), SafeString2(lpszName), dwConnID);
- LogMsg(msg);
- }
- void LogDisconnectFail(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %s(%Iu) Disconnect Fail"), SafeString2(lpszName), dwConnID, lpszName);
- LogMsg(msg);
- }
- void LogRelease(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %s(%Iu) Release OK"), SafeString2(lpszName), dwConnID);
- LogMsg(msg);
- }
- void LogReleaseFail(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %s(%Iu) Release Fail"), SafeString2(lpszName), dwConnID);
- LogMsg(msg);
- }
- void LogDetect(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %s(%Iu) Detect Connection OK"), SafeString2(lpszName), dwConnID);
- LogMsg(msg);
- }
- void LogDetectFail(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T("$ %s(%Iu) Detect Connection Fail"), SafeString2(lpszName), dwConnID);
- LogMsg(msg);
- }
- void LogOnConnect(CONNID dwConnID, const CString& strAddress, USHORT usPort, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T("local address: %s:%d"), strAddress, usPort);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CONNECT, content_len, lpszContent, lpszName);
- LogInfoMsg(msg);
- }
- void LogOnConnect2(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T(" > [ %s%Iu, %s ]"), SafeString2(lpszName), dwConnID, EVT_ON_CONNECT);
- LogMsg(msg);
- }
- void LogOnHandShake2(CONNID dwConnID, LPCTSTR lpszName)
- {
- CString msg;
- msg.Format(_T(" > [ %s%Iu, %s ]"), SafeString2(lpszName), dwConnID, EVT_ON_HAND_SHAKE);
- LogMsg(msg);
- }
- void PostOnSend(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[20];
- wsprintf(lpszContent, _T("(%d bytes)"), iLength);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_SEND, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnReceive(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[20];
- wsprintf(lpszContent, _T("(%d bytes)"), iLength);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_RECEIVE, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnReceiveCast(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, const BYTE* pData, int iLength, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T("<%s:%d> (%d bytes)"), lpszAddress, usPort, iLength);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_RECEIVE, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnClose(CONNID dwConnID, LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CLOSE, 0, nullptr, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnError(CONNID dwConnID, int enOperation, int iErrorCode, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T("OP: %d, CODE: %d"), enOperation, iErrorCode);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_ERROR, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnAccept(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, BOOL bPass, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T("%s (%s:%d)"), bPass ? _T("PASS") : _T("REJECT"), lpszAddress, usPort);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_ACCEPT, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnAccept2(CONNID dwConnID, LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_ACCEPT, 0, nullptr, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnHandShake(CONNID dwConnID, LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_HAND_SHAKE, 0, nullptr, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnPrepareListen(LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T("bind address: %s:%d"), lpszAddress, usPort);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(0, EVT_ON_PREPARE_LISTEN, content_len, lpszContent, lpszName);
- LogInfoMsg(msg);
- }
- void PostOnPrepareConnect(CONNID dwConnID, LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_PREPARE_CONNECT, 0, nullptr, lpszName);
- LogInfoMsg(msg);
- }
- void PostOnConnect(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T("local address: %s:%d"), lpszAddress, usPort);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CONNECT, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnConnect2(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T("remote address: %s:%d"), lpszAddress, usPort);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CONNECT, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnConnect3(CONNID dwConnID, LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CONNECT, 0, nullptr, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnShutdown(LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(0, EVT_ON_SHUTDOWN, 0, nullptr, lpszName);
- PostInfoMsg(msg);
- }
- void PostServerStatics(const LONGLONG& llTotalSent, const LONGLONG& llTotalReceived, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T(" *** Summary: send - %I64d, recv - %I64d"), llTotalSent, llTotalReceived);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(0, EVT_ON_END_TEST, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostTimeConsuming(DWORD dwTickCount, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[100];
- wsprintf(lpszContent, _T("Total Time Consuming: %u"), dwTickCount);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(0, EVT_ON_END_TEST, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnMessageBegin(CONNID dwConnID, LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_MESSAGE_BEGIN, 0, nullptr, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnRequestLine(CONNID dwConnID, LPCSTR lpszMethod, USHORT usUrlFieldSet, LPCSTR lpszUrl, LPCTSTR lpszName)
- {
- USES_CONVERSION;
- int content_len = (int)(strlen(lpszMethod) + strlen(lpszUrl) + 20);
- LPTSTR lpszContent = new TCHAR[content_len];
- wsprintf(lpszContent, _T("[%s/0x%02X] : %s"), A2T(lpszMethod), usUrlFieldSet, A2T(lpszUrl));
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_REQUEST_LINE, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnStatusLine(CONNID dwConnID, USHORT usStatusCode, LPCSTR lpszDesc, LPCTSTR lpszName)
- {
- USES_CONVERSION;
- int content_len = (int)(strlen(lpszDesc) + 10);
- LPTSTR lpszContent = new TCHAR[content_len];
- wsprintf(lpszContent, _T("(%u) : %s"), usStatusCode, A2T(lpszDesc));
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_STATUS_LINE, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnHeader(CONNID dwConnID, LPCSTR lpszHeaderName, LPCSTR lpszHeaderValue, LPCTSTR lpszName)
- {
- USES_CONVERSION;
- int content_len = (int)(strlen(lpszHeaderName) + strlen(lpszHeaderValue) + 10);
- LPTSTR lpszContent = new TCHAR[content_len];
- wsprintf(lpszContent, _T("%s: %s"), A2T(lpszHeaderName), A2T(lpszHeaderValue));
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_HEADER, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnHeadersComplete(CONNID dwConnID, LPCSTR lpszSummary, LPCTSTR lpszName)
- {
- USES_CONVERSION;
- static LPCTSTR PREFIX = _T("* * * * * * * * * Summary * * * * * * * * *\r\n");
- static int PREFIX_LEN = lstrlen(PREFIX);
- LPCTSTR lpszSummaryT = A2CT(lpszSummary);
- int content_len = lstrlen(lpszSummaryT) + PREFIX_LEN + 1;
- LPTSTR lpszContent = new TCHAR[content_len];
- memcpy(lpszContent, PREFIX, PREFIX_LEN * sizeof(TCHAR));
- memcpy(lpszContent + PREFIX_LEN, lpszSummaryT, (content_len - PREFIX_LEN) * sizeof(TCHAR));
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_HEADERS_COMPLETE, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnBody(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[20];
- wsprintf(lpszContent, _T("(%d bytes)"), iLength);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_BODY, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnChunkHeader(CONNID dwConnID, int iLength, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[20];
- wsprintf(lpszContent, _T("(%d bytes)"), iLength);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CHUNK_HEADER, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnChunkComplete(CONNID dwConnID, LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CHUNK_COMPLETE, 0, nullptr, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnMessageComplete(CONNID dwConnID, LPCTSTR lpszName)
- {
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_MESSAGE_COMPLETE, 0, nullptr, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnUpgrade(CONNID dwConnID, EnHttpUpgradeType enUpgradeType, LPCTSTR lpszName)
- {
- LPTSTR lpszContent = new TCHAR[20];
- wsprintf(lpszContent, _T("(type: %d)"), enUpgradeType);
- int content_len = lstrlen(lpszContent);
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_UPGRADE, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostOnParseError(CONNID dwConnID, int iErrorCode, LPCSTR lpszErrorDesc, LPCTSTR lpszName)
- {
- USES_CONVERSION;
- int content_len = (int)(strlen(lpszErrorDesc) + 10);
- LPTSTR lpszContent = new TCHAR[content_len];
- wsprintf(lpszContent, _T("(%i) : %s"), iErrorCode, A2T(lpszErrorDesc));
- info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_PARSE_ERROR, content_len, lpszContent, lpszName);
- PostInfoMsg(msg);
- }
- void PostInfoMsg(info_msg* msg)
- {
- if( g_pMainWnd == nullptr ||
- g_pMainWnd->GetSafeHwnd() == nullptr ||
- !g_pMainWnd->PostMessage(USER_INFO_MSG, (WPARAM)msg ))
- info_msg::Destruct(msg);
- }
- void LogInfoMsg(info_msg* pInfoMsg)
- {
- CString msg;
- if(pInfoMsg->name)
- {
- if(pInfoMsg->connID > 0)
- {
- if(pInfoMsg->contentLength > 0)
- msg.Format(_T(" > [ %s #%Iu, %s ] -> %s"), pInfoMsg->name, pInfoMsg->connID, pInfoMsg->evt, pInfoMsg->content);
- else
- msg.Format(_T(" > [ %s #%Iu, %s ]"), pInfoMsg->name, pInfoMsg->connID, pInfoMsg->evt);
- }
- else
- {
- if(pInfoMsg->contentLength > 0)
- msg.Format(_T(" > [ %s - %s ] -> %s"), pInfoMsg->name, pInfoMsg->evt, pInfoMsg->content);
- else
- msg.Format(_T(" > [ %s - %s ]"), pInfoMsg->name, pInfoMsg->evt);
- }
- }
- else
- {
- if(pInfoMsg->connID > 0)
- {
- if(pInfoMsg->contentLength > 0)
- msg.Format(_T(" > [ %Iu, %s ] -> %s"), pInfoMsg->connID, pInfoMsg->evt, pInfoMsg->content);
- else
- msg.Format(_T(" > [ %Iu, %s ]"), pInfoMsg->connID, pInfoMsg->evt);
- }
- else
- {
- if(pInfoMsg->contentLength > 0)
- msg.Format(_T(" > [ %s ] -> %s"), pInfoMsg->evt, pInfoMsg->content);
- else
- msg.Format(_T(" > [ %s ]"), pInfoMsg->evt);
- }
- }
- LogMsg(msg);
- info_msg::Destruct(pInfoMsg);
- }
- void LogMsg(const CString& msg)
- {
- if(!g_pInfoList || !g_pInfoList->GetSafeHwnd())
- return;
- g_pInfoList->SetRedraw(FALSE);
- int iCurIndex = g_pInfoList->GetCurSel();
- BOOL bFirst = TRUE;
- int iStart = 0;
- int iAdd = 0;
- while(true)
- {
- CString item = msg.Tokenize(_T("\r\n"), iStart);
- if(iStart == -1)
- break;
- if(bFirst)
- bFirst = FALSE;
- else
- item.Insert(0, _T(" | "));
- g_pInfoList->AddString(item);
- ++iAdd;
- }
- int iCount = g_pInfoList->GetCount();
- BOOL bCurLast = (iCurIndex == LB_ERR || iCurIndex + iAdd == iCount - 1);
- int iDec = 0;
- while(g_pInfoList->GetCount() > MAX_LOG_RECORD_LENGTH)
- {
- g_pInfoList->DeleteString(0);
- ++iDec;
- }
- if(bCurLast)
- {
- iCurIndex = iCount - iDec - 1;
- g_pInfoList->SetCurSel(iCurIndex);
- }
- else if(iCurIndex < iDec)
- {
- iCurIndex = 0;
- g_pInfoList->SetCurSel(iCurIndex);
- }
- else
- iCurIndex = g_pInfoList->GetCurSel();
- g_pInfoList->SetAnchorIndex(iCurIndex);
- g_pInfoList->SetRedraw(TRUE);
- }
- CBufferPtr* GeneratePkgBuffer(DWORD seq, LPCTSTR lpszName, short age, LPCTSTR lpszDesc)
- {
- USES_CONVERSION;
- LPCSTR name = T2A((LPTSTR)lpszName);
- LPCSTR desc = T2A((LPTSTR)lpszDesc);
- int desc_len = (int)strlen(desc) + 1;
- int body_len = offsetof(TPkgBody, desc) + desc_len;
- TPkgBody* pBody = (TPkgBody*)_alloca(body_len);
- memset(pBody, 0, body_len);
- pBody->age = age;
- strcpy(pBody->name, name);
- strcpy(pBody->desc, desc);
- TPkgHeader header;
- header.seq = seq;
- header.body_len = body_len;
- return GeneratePkgBuffer(header, *pBody);
- }
- CBufferPtr* GeneratePkgBuffer(const TPkgHeader& header, const TPkgBody& body)
- {
- int header_len = sizeof(TPkgHeader);
- int body_len = header.body_len;
-
- CBufferPtr* pBuffer = new CBufferPtr(header_len + body_len);
- memcpy(pBuffer->Ptr(), (BYTE*)&header, header_len);
- memcpy(pBuffer->Ptr() + header_len, (BYTE*)&body, body_len);
- return pBuffer;
- }
- #ifdef _SSL_SUPPORT
- #include "../../../Common/Src/FuncHelper.h"
- CString g_c_strCAPemCertFileOrPath;
- CString g_c_strPemCertFile;
- CString g_c_strPemKeyFile;
- CString g_s_strCAPemCertFileOrPath;
- CString g_s_strPemCertFile;
- CString g_s_strPemKeyFile;
- int g_c_iVerifyMode = SSL_VM_PEER;
- LPCTSTR g_c_lpszCAPemCertFileOrPath = _T("ssl-cert\\ca.crt");
- LPCTSTR g_c_lpszPemCertFile = _T("ssl-cert\\client.cer");
- LPCTSTR g_c_lpszPemKeyFile = _T("ssl-cert\\client.key");
- LPCTSTR g_c_lpszKeyPasswod = _T("123456");
- int g_s_iVerifyMode = SSL_VM_PEER | SSL_VM_FAIL_IF_NO_PEER_CERT;
- LPCTSTR g_s_lpszCAPemCertFileOrPath = _T("ssl-cert\\ca.crt");
- LPCTSTR g_s_lpszPemCertFile = _T("ssl-cert\\server.cer");
- LPCTSTR g_s_lpszPemKeyFile = _T("ssl-cert\\server.key");
- LPCTSTR g_s_lpszKeyPasswod = _T("123456");
- BOOL InitSSLParams();
- BOOL g_SSLParams = InitSSLParams();
- BOOL InitSSLParams()
- {
- ::SetCurrentPathToModulePath();
- CString strPath;
- ::GetCurrentDirectory(MAX_PATH, strPath.GetBuffer(MAX_PATH));
- strPath.ReleaseBuffer();
- strPath += PATH_SEPARATOR_CHAR;
- if(g_c_lpszPemCertFile)
- {
- g_c_strPemCertFile = strPath + g_c_lpszPemCertFile;
- g_c_lpszPemCertFile = g_c_strPemCertFile;
- }
- if(g_c_lpszPemKeyFile)
- {
- g_c_strPemKeyFile = strPath + g_c_lpszPemKeyFile;
- g_c_lpszPemKeyFile = g_c_strPemKeyFile;
- }
- if(g_c_lpszCAPemCertFileOrPath)
- {
- g_c_strCAPemCertFileOrPath = strPath + g_c_lpszCAPemCertFileOrPath;
- g_c_lpszCAPemCertFileOrPath = g_c_strCAPemCertFileOrPath;
- }
- if(g_s_lpszPemCertFile)
- {
- g_s_strPemCertFile = strPath + g_s_lpszPemCertFile;
- g_s_lpszPemCertFile = g_s_strPemCertFile;
- }
- if(g_s_lpszPemKeyFile)
- {
- g_s_strPemKeyFile = strPath + g_s_lpszPemKeyFile;
- g_s_lpszPemKeyFile = g_s_strPemKeyFile;
- }
- if(g_s_lpszCAPemCertFileOrPath)
- {
- g_s_strCAPemCertFileOrPath = strPath + g_s_lpszCAPemCertFileOrPath;
- g_s_lpszCAPemCertFileOrPath = g_s_strCAPemCertFileOrPath;
- }
- return TRUE;
- }
- #endif
|