/*
Module : W3MFCClient.cpp
Purpose: Implementation for the CW3MFCClient class
Created: PJN / 22-04-1999
History PJN / 19-02-2006 1. Replaced all calls to ZeroMemory and CopyMemory with memset and memcpy
PJN / 27-06-2006 1. Combined the functionality of the _W3MFC_DATA class into the main CW3MFCClient class.
PJN / 19-11-2007 1. CHttpClient class has been renamed to CW3MFCClient
PJN / 18-02-2008 1. Fixed a memory leak in CW3MFCClient::_TransmitFile
PJN / 31-05-2008 1. Code now compiles cleanly using Code Analysis (/analyze)
PJN / 23-05-2009 1. Reworked all token parsing code to use CString::Tokenize
PJN / 07-09-2009 1. Fixed a debug mode ASSERT when calling TRACE in CW3MFCClient::PostLog
Copyright (c) 1999 - 2009 by PJ Naughter (Web: www.naughter.com, Email: pjna@naughter.com)
All rights reserved.
Copyright / Usage Details:
You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise)
when your product is released in binary form. You are allowed to modify the source code in any way you want
except you cannot modify the copyright details at the top of each module. If you want to distribute source
code with your application, then you are only allowed to distribute versions released by the author. This is
to maintain a single distribution point for the source code.
*/
//////////////// Includes /////////////////////////////////////////////////////
#include "stdafx.h"
#include "W3MFC.h"
#include "W3MFCResponseHeader.h"
#include "W3MFCClient.h"
#ifndef __ATLENC_H__
#pragma message("To avoid this message, please put atlenc.h in your pre compiled header (usually stdafx.h)")
#include <atlenc.h>
#endif
//////////////// Macros / Defines /////////////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//////////////// Implementation ///////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CW3MFCClient, CThreadPoolClient)
CW3MFCClient::CW3MFCClient() : m_lpfnTransmitFile(NULL),
m_lpfnTransmitPackets(NULL),
m_pServer(NULL),
m_hMSWsock(NULL),
#ifdef W3MFC_SSL_SUPPORT
m_pSSLContext(NULL),
#endif
#ifndef W3MFC_NO_ISAPI_SUPPORT
m_dwDataSentViaWriteClient(0),
m_nHttpStatusCodeSent(0),
#endif
m_bResponseKeepAlive(FALSE)
{
//Only use the TransmitFile and TransmitPacket API's if we are running on Win2K or later
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
BOOL bNT = (GetVersionEx(&osvi) && osvi.dwPlatformId == VER_PLATFORM_WIN32_NT);
if (bNT && (osvi.dwMajorVersion >= 5))
{
m_hMSWsock = LoadLibrary(_T("MSWSOCK.DLL"));
if (m_hMSWsock)
{
m_lpfnTransmitFile = reinterpret_cast<LPFN_TRANSMITFILE>(GetProcAddress(m_hMSWsock, "TransmitFile"));
m_lpfnTransmitPackets = reinterpret_cast<LPFN_TRANSMITPACKETS>(GetProcAddress(m_hMSWsock, "TransmitPackets"));
}
}
}
CW3MFCClient::~CW3MFCClient()
{
if (m_hMSWsock)
{
FreeLibrary(m_hMSWsock);
m_hMSWsock = NULL;
}
}
#ifndef W3MFC_NO_ISAPI_SUPPORT
BOOL CW3MFCClient::_TransmitFile(CW3MFCSocket& socket, CW3MFCResponseHeader& responseHdr, HSE_TF_INFO* pInfo)
{
//Assume the worst
BOOL bSuccess = FALSE;
if (pInfo->pfnHseIO)
{
SetLastError(ERROR_INVALID_PARAMETER); //we do not support ascynchronous notifications
return FALSE;
}
if (pInfo->Offset)
{
SetLastError(ERROR_INVALID_PARAMETER); //we do not support partials sends thro TransmitFile because that requires overlapped IO
return FALSE;
}
if (pInfo->dwFlags & HSE_IO_SEND_HEADERS)
{
if (m_lpfnTransmitPackets && m_lpfnTransmitFile)
{
TRANSMIT_PACKETS_ELEMENT tpe[2];
tpe[0].pBuffer = static_cast<void*>(const_cast<LPSTR>(pInfo->pszStatusCode));
tpe[0].dwElFlags = TP_ELEMENT_MEMORY;
tpe[0].cLength = static_cast<ULONG>(strlen(pInfo->pszStatusCode));
CStringA sHeader(responseHdr.GetData());
tpe[1].cLength = sHeader.GetLength();
tpe[1].pBuffer = sHeader.GetBuffer();
tpe[1].dwElFlags = TP_ELEMENT_MEMORY;
//Call the TransmitPackets function
bSuccess = m_lpfnTransmitPackets(socket, tpe, 2, 0, NULL, TF_USE_KERNEL_APC);
sHeader.ReleaseBuffer();
//And the TransmitFile function
if (bSuccess)
bSuccess = m_lpfnTransmitFile(socket, pInfo->hFile, pInfo->BytesToWrite, 0, NULL, NULL, TF_USE_KERNEL_APC);
}
else
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
}
else
{
if (m_lpfnTransmitFile)
{
TRANSMIT_FILE_BUFFERS tfb;
tfb.Head = pInfo->pHead;
tfb.HeadLength = pInfo->HeadLength;
tfb.Tail = pInfo->pTail;
tfb.TailLength = pInfo->TailLength;
//Call the TransmitFile function
bSuccess = m_lpfnTransmitFile(socket, pInfo->hFile, pInfo->BytesToWrite, 0, NULL, &tfb, TF_USE_KERNEL_APC);
}
else
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
}
return bSuccess;
}
#endif
BOOL CW3MFCClient::_TransmitFile(CW3MFCSocket& socket, CW3MFCResponseHeader& responseHdr, HANDLE hFile, DWORD dwSize)
{
//Validate our parameter
ASSERT(m_lpfnTransmitFile);
//Setup the TFB ready for the call to the "TransmitFile" function
TRANSMIT_FILE_BUFFERS tfb;
CStringA sData(responseHdr.GetData());
tfb.HeadLength = sData.GetLength();
tfb.Head = sData.GetBuffer();
tfb.Tail = NULL;
tfb.TailLength = 0;
//Call the TransmitFile function
BOOL bSuccess = m_lpfnTransmitFile(socket, hFile, dwSize, 0, NULL, &tfb, TF_USE_KERNEL_APC);
sData.ReleaseBuffer();
return bSuccess;
}
BOOL CW3MFCClient::_TransmitBuffer(CW3MFCSocket& socket, CW3MFCResponseHeader& responseHdr, BYTE* byData, DWORD dwSize)
{
//Validate our parameters
ASSERT(m_lpfnTransmitPackets);
//Setup the TFB ready for the call to the "TransmitPackets" function
TRANSMIT_PACKETS_ELEMENT tpe[2];
CStringA sData(responseHdr.GetData());
tpe[0].pBuffer = sData.GetBuffer();
tpe[0].dwElFlags = TP_ELEMENT_MEMORY;
tpe[1].pBuffer = reinterpret_cast<void*>(byData);
tpe[1].cLength = dwSize;
tpe[0].dwElFlags = TP_ELEMENT_MEMORY;
//Call the TransmitPackets function
BOOL bSuccess = m_lpfnTransmitPackets(socket, tpe, 2, 0, NULL, TF_USE_KERNEL_APC);
sData.ReleaseBuffer();
return bSuccess;
}
BOOL CW3MFCClient::AllowThisConnection()
{
return TRUE;
}
#ifdef W3MFC_SSL_SUPPORT
BOOL CW3MFCClient::InitializeSSLConnection()
{
SSL* pSSL = SSL_new(m_pSSLContext->operator SSL_CTX*());
if (pSSL == NULL)
{
//Report the error
CString sError;
sError.Format(_T("CW3MFCClient::InitializeSSLConnection, Failed to create create SSL connection object"));
AFXASSUME(m_pServer);
m_pServer->OnError(sError);
m_pServer->LogSSLErrors();
return FALSE;
}
else
m_SSL.Attach(pSSL);
//Associate the raw socket with the SSL connection object
if (SSL_set_fd(m_SSL, m_Socket) != 1)
{
//Report the error
CString sError;
sError.Format(_T("CW3MFCClient::InitializeSSLConnection, Failed to create create SSL connection object"));
AFXASSUME(m_pServer);
m_pServer->OnError(sError);
m_pServer->LogSSLErrors();
return FALSE;
}
return TRUE;
}
BOOL CW3MFCClient::DoSSLNegotiation()
{
//Validate our parameters
AFXASSUME(m_pServer);
CW3MFCServerSettings* pSettings = m_pServer->GetSettings();
AFXASSUME(pSettings);
BOOL bNegotiationComplete = FALSE;
while (!bNegotiationComplete)
{
int nSSLAccept = SSL_acce
没有合适的资源?快使用搜索试试~ 我知道了~
W3MFC web服务器源码
共85个文件
h:26个
cpp:24个
htm:8个
需积分: 9 37 下载量 129 浏览量
2010-01-23
01:22:26
上传
评论 3
收藏 892KB ZIP 举报
温馨提示
开发webserver 的一个很有参考价值代码,基于HTTP协议和VC MFC开发WEB服务器的源码
资源推荐
资源详情
资源评论
收起资源包目录
w3mfc.zip (85个子文件)
W3MFCISAPI.h 4KB
W3MFCISAPIManager.h 2KB
W3MFCDirectory.cpp 17KB
main.cpp 18KB
ReleaseS
root
w3mfc.gif 1KB
w3mfc.htm 65KB
index.html 547B
naughter.css 917B
W3MFC.exe 156KB
ssleay32.dll 196KB
w3mfc.ini 1KB
SSLw3mfc.ini 1KB
libeay32.dll 994KB
w3mfc.pem 2KB
scripts
TestISAPI.dll 39KB
TestCGI.exe 108KB
SocMFC.h 6KB
StdAfx.cpp 23B
resource.h 855B
OpenSSLMfc.cpp 8KB
DirectedThreadPoolQueue.cpp 13KB
W3MFCRequest.cpp 5KB
W3MFCClient.h 6KB
W3MFCSocket.cpp 22KB
W3MFC.vcproj 45KB
DirectedThreadPoolQueue.h 4KB
W3MFCResponseHeader.h 2KB
W3MFC.sln 11KB
W3MFC.rc 4KB
W3MFCMimeManager.h 2KB
StdAfx.h 912B
W3MFCCGI.cpp 28KB
IOCPThreadPoolQueue.h 2KB
SSLServer
StdAfx.cpp 21B
resource.h 456B
SSLServer.cpp 3KB
SSLServer.rc 1KB
StdAfx.h 895B
Release
SSLServer.exe 30KB
w3mfc.pem 2KB
SSLServer.vcproj 7KB
SSLServer.h 39B
W3MFCResponseHeader.cpp 8KB
TestISAPI
TestISAPI.vcproj 6KB
StdAfx.cpp 27B
TestISAPI.rc2 401B
TestISAPI.def 165B
TestISAPI.h 802B
StdAfx.h 1KB
Resource.h 318B
TestISAPI.rc 4KB
TestISAPI.cpp 8KB
SocMFC.cpp 39KB
SSLClient
StdAfx.cpp 21B
SSLClient.h 39B
SSLClient.vcproj 7KB
SSLClient.cpp 3KB
StdAfx.h 895B
Resource.h 407B
Release
SSLClient.exe 29KB
SSLClient.rc 1KB
W3MFCRequest.h 6KB
W3MFCCGI.h 2KB
W3MFCClient.cpp 68KB
IOCPThreadPoolQueue.cpp 4KB
W3MFC.cpp 57KB
ThrdPool.h 12KB
res
404.htm 365B
401.htm 288B
500.htm 287B
302.htm 191B
mainfrm.ico 3KB
501.htm 226B
400.htm 312B
deleted_ok.htm 149B
W3MFCDirectory.h 4KB
ThrdPool.cpp 28KB
W3MFCMimeManager.cpp 6KB
W3MFC.h 11KB
W3MFCSocket.h 3KB
W3MFCISAPIManager.cpp 5KB
W3MFCISAPI.cpp 40KB
TestCGI
TestCGI.cpp 689B
TestCGI.vcproj 4KB
OpenSSLMfc.h 5KB
共 85 条
- 1
资源评论
牛魔皇
- 粉丝: 9
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 王姿.html
- 51单片机学习(1)-软件keil下载
- 历届(第1-21届)希望杯数学竞赛初一试题及答案(最新整理).doc全国数学邀请赛(264页资料)
- 水滴.psd
- TokenPocket_V2.1.2_release.apk
- Apache-druid-kafka-rce.yaml
- 基于C#的ASP.NET数据库原理及应用技术课程指导平台的开发
- 基于ROS的智能车轨迹跟踪算法的仿真与设计源码运用PID跟踪算法.zip.zip
- Bug Bounty Tip - i春秋Self-XSS变废为宝的奇思妙想
- 1991-2015年全国初中化学竞赛复赛试题汇编(212页)(24年竞赛复赛真题).docx天原杯
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功