⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soapisap.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//+----------------------------------------------------------------------------
//
//
// File:    soapisap.cpp
//
// Contents:
//
//  ISAPI Extension that listens to SOAP packages and routes them to the
//  appropriate SOAP driver.
//
//
//
//-----------------------------------------------------------------------------

#define INIT_ISAPI_GLOBALS
#define MYINIT_GUID                 // Includes GUID instances

#ifdef UNDER_CE
#include "WinCEUtils.h"
#endif 
#include "isapihdr.h"

#ifndef UNDER_CE
#include "iiscnfg.h"
#include "iadmw.h"
#else
#define SOAP_ISAPI_DBG                    DEBUGZONE(0)
#define SOAP_PROCESS_ATTACH               DEBUGZONE(1)
#define SOAP_PROCESS_REQUEST              DEBUGZONE(2)
#endif 


typedef HRESULT (STDAPICALLTYPE * PGETCLASSOBJ)(REFCLSID, REFIID, LPVOID);

BOOL DllProcessAttach(HINSTANCE hInstDLL);
BOOL DllProcessDetach();
void InitRegInfo();
void SetRegInfo();
void RemoveRegInfo();

#ifndef UNDER_CE
HRESULT GetMetadataExtensions(IMSAdminBase *pAdminBase,
                                    METADATA_HANDLE *phMD,
                                    METADATA_RECORD *pmdRec,
                                    WCHAR ** tempbuf);
#endif 

HRESULT RemoveSoapExt(WCHAR * pwstr, DWORD *pwch);

BOOL IsIISVersion4(WCHAR * pwstr, DWORD wch);

extern "C" BOOL __cdecl DbgDllMain(HANDLE hinst, DWORD dwReason, LPVOID lpReason);

#ifdef UNDER_CE
HANDLE g_hTerminateThread;
HANDLE g_hTerminateEvent;
DWORD TerminateISAPIThread(LPVOID param);
#endif 

#ifndef UNDER_CE
#ifdef _CRTDBG_MAP_ALLOC
	HANDLE	hfile;
#endif
#endif


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: DllMain
//
//  parameters:
//
//
//  description:
//          @func DLL Entry point where Instance and Thread attach/detach notifications
//          takes place.  Some current activity is OLE is being initialized and the
//          IMalloc Interface pointer is obtained.
//
//          @rdesc Boolean Flag
//              @flag TRUE  | Successful initialization
//              @flag FALSE | Failure to intialize
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL WINAPI DllMain
    (
    HANDLE   hInstDLL,       //@parm IN | Application Instance Handle         
    DWORD       fdwReason,      //@parm IN | Indicated Process or Thread activity
    LPVOID      lpvReserved     //@parm IN | Reserved...                         
    )
{
    BOOL        fRetVal = TRUE;        // assume successful.

    switch( fdwReason )
    {
        case DLL_PROCESS_ATTACH:  
#ifndef UNDER_CE // cant call coinit from process attach!  moving to GetExtensionVersion()
            if (FAILED(CoInitializeEx(NULL,COINIT_MULTITHREADED)))
                {
                    DEBUGMSG(SOAP_ISAPI_DBG,(L"[SOAPISAPI] DLL_PROCESS_ATTACH -- cant CoInitialize\n"));
                    return FALSE;
                }
            fRetVal = DllProcessAttach((HINSTANCE)hInstDLL);
            CoUninitialize(); 
#else
            g_hInstance = (HINSTANCE)hInstDLL;
#endif 
            break;
        case DLL_PROCESS_DETACH:            
            fRetVal = DllProcessDetach();
            
            DEBUGMSG(SOAP_ISAPI_DBG,(L"[SOAPISAPI] DLL_PROCESS_DETACH -- isapi is gone\n"));                  
            break;
    }
    return fRetVal;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: DllProcessAttach(HINSTANCE hInstDLL)
//
//  parameters:
//
//
//  description:
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL DllProcessAttach(HINSTANCE hInstDLL)
{
#ifdef UNDER_CE
    DEBUGMSG(SOAP_PROCESS_ATTACH, (L"[SOAPISAPI] DllProcessAttach"));
#endif 
    BOOL    fRetVal = TRUE;
#ifndef UNDER_CE
    HRESULT hr = S_OK;    
    char    szModuleName[MAX_RES_STRING_SIZE + 1];
    char *  psz;
    char *  pszlocale;
    char *  pszcurpath;
    DWORD   cch;
    OSVERSIONINFOA osver;
    LCID    lcid;
#endif 

	SET_TRACE_LEVEL(3);

    InitializeCriticalSection(&g_cs);

    InitSoaputil();
#ifdef UNDER_CE
    DEBUGMSG(SOAP_PROCESS_ATTACH, (L"[SOAPISAPI] Finishised SoapUtil init"));
    g_hTerminateThread = NULL;
#endif 

#ifndef UNDER_CE //this is already set from dllmain
    g_hInstance = hInstDLL;
#endif 

    // Disable the DLL_THREAD_ATTACH and DLL_THREAD_DETACH
    // notifications for this DLL
    DisableThreadLibraryCalls(hInstDLL);

#ifndef UNDER_CE
    GetSystemInfo(&g_si);
#endif 

    // Initialize the registry values
#ifndef UNDER_CE
    g_cThreads = (2 * g_si.dwNumberOfProcessors)+ 1;
#else
    g_cThreads = 2 + 1;
#endif 
    g_cObjCachePerThread = 5;       // default value
    g_cbMaxPost = 100 * 1024;       // 100 Kb is the default max

    // Get the number of threads from the registry, if any.
    InitRegInfo();

#ifndef UNDER_CE
    osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);

    GetVersionExA(&osver);

    g_fIsWin9x = !!(osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
	TRACEL((1, "Running under Win9x: %s\n", g_fIsWin9x ? "true" : "false"));


    //
    // Load Localization DLL
    //
    cch = GetModuleFileNameA(hInstDLL, szModuleName, MAX_RES_STRING_SIZE);
    if (cch == 0)
    {
        hr = GetLastError();
        fRetVal = FALSE;
        goto Cleanup;
    }
    // Find the path of the file
    psz = &(szModuleName[cch - 1]);
    while ((psz >= szModuleName) && (*psz != '\\') && (*psz != '/'))
        psz--;
    psz++;
    pszcurpath = psz;
    strncpy(psz, "Resources\\", (MAX_RES_STRING_SIZE - (psz - szModuleName)));
    lcid = GetSystemDefaultLCID();
    pszlocale = szModuleName + strlen(szModuleName);
    ltoa (lcid, pszlocale, 10);
    psz = szModuleName + strlen(szModuleName);
    *psz = (char)'\\';
    psz++;
    strncpy(psz, "MSSOAPR.DLL", (MAX_RES_STRING_SIZE - (psz - szModuleName)))
;

    g_hInstance_language = LoadLibraryExA(szModuleName, NULL,
            LOAD_WITH_ALTERED_SEARCH_PATH);

    if( !g_hInstance_language )
    {
        // If not found, try the local default 1033 (US English)
        strncpy(pszlocale, "1033\\MSSOAPR.DLL", (MAX_RES_STRING_SIZE - (pszlocale - szModuleName)));
        g_hInstance_language = LoadLibraryExA(szModuleName, NULL,
            LOAD_WITH_ALTERED_SEARCH_PATH);
        if( !g_hInstance_language )
        {
            // Finally look for it in the current directory
            strncpy(pszcurpath, "MSSOAPR.DLL", (MAX_RES_STRING_SIZE - (pszcurpath - szModuleName)));
            g_hInstance_language = LoadLibraryExA(szModuleName, NULL,
                LOAD_WITH_ALTERED_SEARCH_PATH);

            if( !g_hInstance_language )
            {
#ifdef DEBUG
                // For DEBUG version only, check the path ..\..\..\mssoapr\objd\i386\mssoapr.dll
                // This hack is convenient for development debugging.
                // Go up three directories
                psz = pszcurpath - 2;
                for ( int i = 0 ; i < 3 ; i++)
                {
                    while ((psz >= szModuleName) && (*psz != '\\') && (*psz != '/'))
                        psz--;
                    psz--;
                }
                psz++;
                psz++;
                strncpy(psz, "mssoapres\\objd\\i386\\MSSOAPR.DLL",
                        (MAX_RES_STRING_SIZE - (psz - szModuleName)));
                g_hInstance_language = LoadLibraryExA(szModuleName, NULL,
                    LOAD_WITH_ALTERED_SEARCH_PATH);
                if (g_hInstance_language)
                {
                    fRetVal = TRUE;
                }
                else
                {
#endif
                    fRetVal = FALSE;
                    goto Cleanup;
#ifdef DEBUG
                }
#endif
            }
        }
    }

Cleanup:



#ifdef _CRTDBG_MAP_ALLOC

	hfile = CreateFile(_T("soapisapimemdump.log"), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL, 0);
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF |  _CRTDBG_DELAY_FREE_MEM_DF);
	_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_WARN, hfile);
#endif


#endif //UNDER_CE
    if (g_cThreads < 1)
        g_cThreads = 1;
    else if (g_cThreads > 32)
        g_cThreads = 32;

    if (!fRetVal)
    {
        DeleteCriticalSection(&g_cs);

#ifndef UNDER_CE
        if (g_hInstance_language)
            FreeLibrary(g_hInstance_language);
#endif 
    }

    return fRetVal;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: SafeFreeLibrary(HINSTANCE h)
//
//  parameters:
//
//
//  description:
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void SafeFreeLibrary(HINSTANCE h)
{
    __try
    {
        FreeLibrary(h);
    }
    __except(EXCEPTION_EXECUTE_HANDLER)
    {
        TRACEL((1, "DllMain: Exception fired during DllProcessDetach()\n"));
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: SafeRelease(IUnknown * ptr, size_t sz)
//
//  parameters:
//
//
//  description:
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void SafeRelease(IUnknown * ptr, size_t sz)
{
    if(ptr && !IsBadWritePtr(ptr, sz))
    {
        __try
        {
            ptr->Release();
        }
        __except(EXCEPTION_EXECUTE_HANDLER)
        {
            TRACEL((1, "DllMain: Exception fired during Interface release \n"));
        }
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: DllProcessDetach()
//
//  parameters:
//
//
//  description:
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL DllProcessDetach()
{

    globalDeleteErrorList();
    DeleteCriticalSection(&g_cs);

#ifndef UNDER_CE
    // Don't free the Localized Resource Strings on Win95
    if (!g_fIsWin9x)
        SafeFreeLibrary(g_hInstance_language);
    else
        CloseHandle(g_hInstance_language);
#endif 

#ifndef UNDER_CE
#ifdef _CRTDBG_MAP_ALLOC
	ASSERT(_CrtCheckMemory());
	ASSERT(!_CrtDumpMemoryLeaks());
	CloseHandle(hfile);
#endif
#endif
	TRACEL((1, "Nr of objects still around=%d\n", g_cObjects));

    return TRUE;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: DllCanUnloadNow
//
//  parameters:
//
//  description:
//          @func Indicates whether the DLL is no longer in use and
//          can be unloaded.
//
//          @rdesc HResult indicating status of routine
//              @flag S_OK | DLL can be unloaded now.
//              @flag S_FALSE | DLL cannot be unloaded now.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
STDAPI DllCanUnloadNow(void)
{
   	static HRESULT s_result[] = { S_OK, S_FALSE };
	return s_result[g_cLock || g_cObjects];

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: GetExtensionVersion( HSE_VERSION_INFO *pVer)
//
//  parameters:
//
//          Arguments:   pVer - poins to extension version info structure
//          Returns:     TRUE (always)
//
//  description:
//          This is required ISAPI Extension DLL entry point.
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL WINAPI GetExtensionVersion (HSE_VERSION_INFO *pVer)
{
    BOOL                        fRetVal = TRUE;
    
#ifdef UNDER_CE  //moved from DLLMain (cant call coinit from dllmain)
        if (FAILED(CoInitializeEx(NULL,COINIT_MULTITHREADED)))
            {
                DEBUGMSG(SOAP_ISAPI_DBG,(L"[SOAPISAPI] DLL_PROCESS_ATTACH -- cant CoInitialize\n"));
                return FALSE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -