基本信息
源码名称:支持ASP的WEB服务器源代码,采用MFC编写(web服务器)
源码大小:0.12M
文件格式:.rar
开发语言:C/C++
更新时间:2015-03-30
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
#include "stdafx.h" #include "server.h" #include "ServerObject.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif IMPLEMENT_DYNCREATE(CServerObject, CCmdTarget) CServerObject::CServerObject() { EnableAutomation(); } CServerObject::~CServerObject() { } void CServerObject::OnFinalRelease() { // When the last reference for an automation object is released // OnFinalRelease is called. The base class will automatically // deletes the object. Add additional cleanup required for your // object before calling the base class. CCmdTarget::OnFinalRelease(); } BEGIN_MESSAGE_MAP(CServerObject, CCmdTarget) //{{AFX_MSG_MAP(CServerObject) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP() BEGIN_DISPATCH_MAP(CServerObject, CCmdTarget) //{{AFX_DISPATCH_MAP(CServerObject) DISP_FUNCTION(CServerObject, "URLEncode", URLEncode, VT_BSTR, VTS_BSTR) DISP_FUNCTION(CServerObject, "CreateObject", CreateObjectEx, VT_DISPATCH, VTS_BSTR) DISP_FUNCTION(CServerObject, "MapPath", MapPath, VT_BSTR, VTS_BSTR) DISP_FUNCTION(CServerObject, "HTMLEncode", HTMLEncode, VT_BSTR, VTS_BSTR) //}}AFX_DISPATCH_MAP END_DISPATCH_MAP() // Note: we add support for IID_IServerObject to support typesafe binding // from VBA. This IID must match the GUID that is attached to the // dispinterface in the .ODL file. // {7631CBBC-4CD8-4400-90A0-013E1AF29454} static const IID IID_IServerObject = { 0x7631cbbc, 0x4cd8, 0x4400, { 0x90, 0xa0, 0x1, 0x3e, 0x1a, 0xf2, 0x94, 0x54 } }; BEGIN_INTERFACE_MAP(CServerObject, CCmdTarget) INTERFACE_PART(CServerObject, IID_IServerObject, Dispatch) END_INTERFACE_MAP() /********************************************************************/ /* */ /* Function name : SetCurrentDirectory */ /* Description : Set current directory */ /* */ /********************************************************************/ void CServerObject::SetCurrentDirectory(LPCTSTR lpszDirectory) { m_strCurrentDirectory = lpszDirectory; m_strCurrentDirectory.TrimRight('\\'); } /********************************************************************/ /* */ /* Function name : SetRootDirectory */ /* Description : Set root directory */ /* */ /********************************************************************/ void CServerObject::SetRootDirectory(LPCTSTR lpszDirectory) { m_strRootDirectory = lpszDirectory; m_strRootDirectory.TrimRight('\\'); } /********************************************************************/ /* */ /* Function name : URLEncode */ /* Description : Convert unsafe characters to %xx sequences */ /* */ /********************************************************************/ BSTR CServerObject::URLEncode(LPCTSTR lpszURL) { CString strResult = ""; CString strHex; char ch; while((ch = *lpszURL ) != '\0') { // check if it's an unsafe character if (AfxIsUnsafeUrlChar(ch)) { if (ch == ' ') strResult = ' '; else { // output the percent, followed by the hex value of the character strResult = '%'; strHex.Format("%02X", ch); strResult = strHex; } } else // safe character { strResult = ch; } } return strResult.AllocSysString(); } /********************************************************************/ /* */ /* Function name : CreateObjectEx */ /* Description : Create an instance of a server object. */ /* */ /********************************************************************/ LPDISPATCH CServerObject::CreateObjectEx(LPCTSTR lpszProgID) { IDispatchPtr pServerObject; // create instance of specified object using smart pointer HRESULT hResult = pServerObject.CreateInstance(lpszProgID); if (FAILED(hResult)) { return NULL; } pServerObject->AddRef(); return pServerObject; } /********************************************************************/ /* */ /* Function name : MapPath */ /* Description : Maps the specified relative or virtual path to */ /* the corresponding physical directory. */ /* */ /********************************************************************/ BSTR CServerObject::MapPath(LPCTSTR lpszLogicalPath) { CString strPhysicalPath; CString strLogicalPath = lpszLogicalPath; CString strOffset; // make unix style strLogicalPath.Replace("\\","/"); while(strLogicalPath.Replace("//","/")); if (strLogicalPath.Left(1) == '/') { // absolute path strOffset = m_strRootDirectory; } else { // relative path strOffset = m_strCurrentDirectory; } if (strOffset.Right(1) != '\\') strOffset = "\\"; strLogicalPath.TrimLeft('/'); strPhysicalPath = strOffset strLogicalPath; // make Windows style strPhysicalPath.Replace("/", "\\"); CStringList partList; CString strSub; int nCount=0; // split path in parts while(AfxExtractSubString(strSub, strPhysicalPath, nCount , '\\')) { if (!strSub.IsEmpty()) partList.AddTail(strSub); } strPhysicalPath.Empty(); // fix dots while(!partList.IsEmpty()) { CString strPart = partList.GetHead(); partList.RemoveHead(); if (strPart == "..") { // go back one level int nPos = strPhysicalPath.ReverseFind('\\'); if (nPos != -1) { strPhysicalPath = strPhysicalPath.Left(nPos); } } else { if (!strPhysicalPath.IsEmpty()) { strPhysicalPath = "\\"; } strPhysicalPath = strPart; } } return strPhysicalPath.AllocSysString(); } /********************************************************************/ /* */ /* Function name : HTMLEncode */ /* Description : Apply HTML encoding to the specified string. */ /* */ /********************************************************************/ BSTR CServerObject::HTMLEncode(LPCTSTR lpszIn) { CString strEncoded; int nLength = lstrlen(lpszIn); while (nLength--) { switch (*lpszIn) { case '<': strEncoded = "<"; break; case '>': strEncoded = ">"; break; case '&': strEncoded = "&"; break; case '\'': strEncoded = "'"; break; case '\"': strEncoded = """; break; default: // just copy the character strEncoded = *lpszIn; break; } lpszIn ; } return strEncoded.AllocSysString(); }