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

📄 dcomlib.cpp

📁 dcom机制在vxworks上的实现源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    char * hint = 0;    if (pServerInfo->pwszName)	{	hint = new char [comWideStrLen (pServerInfo->pwszName) + 1];	comWideToAscii (hint,		        pServerInfo->pwszName,			comWideStrLen (pServerInfo->pwszName) + 1);	}    HRESULT hr =  comInstanceCreate (rclsid,                                     pUnkOuter,                                     dwClsCtx,                                     hint,                                     nInterfaces,                                     pResults);    if (hint)	delete []hint;    return hr;    }/**************************************************************************** CoGetStandardMarshal - Returns an instance of the standard marshaler.** Returns an instance of the system standard marshaler. This object * encapsulates the mechanism for marshaling any interface pointer into a * stream, and is used (in this context) simply to marshal the given * interface, after that it will be destroyed.** RETURNS: S_OK.*/HRESULT CoGetStandardMarshal    (    REFIID		riid,		/* interface IID */    IUnknown*		pUnk,		/* interface-ptr to be marshaled */    DWORD		dwDestContext,  /* destination context */    void*		pvDestContext,  /* reserved for future use */    DWORD		mshlflags,      /* reason for marshaling */    IMarshal**		ppMshl		/* output ptr */    )    {    TRACE_CALL;        *ppMshl = new VxStdMarshaler ();    (*ppMshl)->AddRef ();    return S_OK;    }/**************************************************************************** CoMarshalInterface - marshal an interface pointer into a stream** This function differs from its Win32 counterpart in that only* standard marshaling is supported. The interface to be marshaled is* 'not' queried for 'IMarshal' and no attempt will be made to use* custom marshaling even if the object supports it.** RETURNS: an HRESULT value*/HRESULT CoMarshalInterface    (    IStream*		pStm,		/* stream to marshal into */    REFIID		riid,		/* interface IID */    IUnknown*		pUnk,		/* interface-ptr to be marshaled */    DWORD		dwDestContext,  /* destination context */    void*		pvDestContext,  /* reserved for future use */    DWORD		mshlflags       /* reason for marshaling */    )    {    TRACE_CALL;    // We are now going to make an entry in the object exporter's    // object table for the new object's marshaling packet. If at some    // point this function fails, we need to remove this entry...    ObjectExporter* pExp = SCM::objectExporter ();    return pExp->objectMarshal (CLSID_NULL,				pStm,				riid,				pUnk,				dwDestContext,				pvDestContext,				mshlflags,				0);    }/**************************************************************************** CoUnmarshalInterface - Un-marshal an interface pointer from a stream** This function differs from its Win32 counterpart in that only* standard marshaling is supported. If the OBJREF being Un-marshaled* indicates <custom marshaling> or <handler marshaling> then this call* will fail.** RETURNS: an HRESULT value*/HRESULT CoUnmarshalInterface    (    IStream*		pStm,		/* pointer to stream */    REFIID		riid,		/* IID of the interface */    void**		ppv		/* output variable to receive ptr */    )    {    TRACE_CALL;        // Record current location in stream before use...    ULARGE_INTEGER currPos;    HRESULT hr = pStm->Seek (0, STREAM_SEEK_CUR, &currPos);    if (FAILED (hr))	return hr;    // Read signature and flags from stream, to see if its a STDOBJREF.    // The STDOBJREF is known to be encoded in little-endian format as    // the rules of DCOM say so!    ULONG signature;    ULONG flags;    hr = pStm->Read (&signature, sizeof (signature), 0);    ndr_make_right (signature, VXDCOM_DREP_LITTLE_ENDIAN);    if (FAILED (hr))	return hr;    hr = pStm->Read (&flags, sizeof (flags), 0);    ndr_make_right (flags, VXDCOM_DREP_LITTLE_ENDIAN);    if (FAILED (hr))	return hr;    // Validate OBJREF format...    if (signature != OBJREF_SIGNATURE)        return RPC_E_INVALID_OBJREF;    if (flags != OBJREF_STANDARD)        return E_NOTIMPL;    // Now rewind the stream, ready for proper Un-marshaling...    pStm->Seek (currPos, STREAM_SEEK_SET, 0);    // Create std-proxy-object to perform Un-marshaling...    IMarshal* pMshl = new VxStdProxy ();    if (! pMshl)	return E_OUTOFMEMORY;    pMshl->AddRef ();    // Call UnmarshalInterface() to create connection    hr = pMshl->UnmarshalInterface (pStm, riid, ppv);    if (FAILED (hr))	return hr;    pMshl->Release ();    return hr;    }/**************************************************************************** CoGetPSClsid - returns the proxy/stub CLSID for a given interface ID** This function is meaningless in VxDCOM as CLSIDs are not used to* identify proxy/stub code as they are on Win32. Thus, this function* always return S_OK and outputs CLSID_NULL.** RETURNS: S_OK*/HRESULT CoGetPSClsid    (    REFIID              riid,           /* interface ID */    LPCLSID             pClsid          /* resulting P/S CLSID */    )    {    TRACE_CALL;    *pClsid = CLSID_NULL;    return S_OK;    }/**************************************************************************** CoGetMarshalSizeMax - Returns the upper bound on the number of bytes needed to marshal the interface.** Discover max size of marshaling packet required for given interface. As * we don't support custom or handler marshaling, its simply the size of the * std-mshl packet.** RETURNS: S_OK on success or CO_E_NOTINITIALIZED.*/HRESULT CoGetMarshalSizeMax    (    ULONG*              pulSize,        /* ptr to the upper-bound value */    REFIID              riid,           /* IID of interface */    IUnknown*           pUnk,           /* interface-ptr to be marshaled */    DWORD               dwDestContext,  /* destination process */    LPVOID              pvDestContext,  /* reserved for future use */    DWORD               mshlflags       /* reason for marshaling */    )    {    TRACE_CALL;    // Get std-marshaler, use its value...    IMarshal* pMshl;    HRESULT hr = CoGetStandardMarshal (riid,				       pUnk,				       dwDestContext,				       pvDestContext,				       mshlflags,				       &pMshl);    if (SUCCEEDED (hr))	{	// Now find out marshal-size requirements of interface...	hr = pMshl->GetMarshalSizeMax (riid,				       pUnk,				       dwDestContext,				       pvDestContext, 				       mshlflags,				       pulSize);	}    return hr;    }/** vxdcom_ps_autoreg -- used by proxy/stub modules to register their* p/s classes with the system. Every server module that wants to be* remoted must register a p/s entry via this function. It provides 2* VTABLEs, one for proxies and one for stubs, and they are then* managed by the system's own p/s factory object.*/vxdcom_ps_autoreg::vxdcom_ps_autoreg    (    REFIID			iid,		// IID of interface    const void*			pvProxyVtbl,	// proxy's VTBL ptr    const VXDCOM_STUB_DISPTBL*	pStubDispTbl	// stub dispatch table    )    {    // Register vtbl pointers with system P/S class factory...    VxPSFactory* pPSFactory = VxPSFactory::theInstance ();    pPSFactory->Register (iid, pvProxyVtbl, pStubDispTbl);    }/**************************************************************************** vxdcomUserAdd - adds a user to the NTLMSSP user table** This function adds a user/password combination to the VxDCOM NTLM* security tables. The password must be given in clear text, but only* the <password hash> is stored. This means that VxDCOM can use the* authentication setting RPC_CN_AUTHN_LEVEL_CONNECT to allow or* disallow incoming requests from specific users. If the* authentication level is set to this value, then only requests from* users with valid entries in the VxDCOM security tables will be* honored. Other users will be rejected with an 'access denied' error* when trying to activate servers on a VxDCOM target.** RETURNS: void*/void vxdcomUserAdd    (    const char*		userName,	/* user name */    const char*		passwd		/* user's password in plain text */    )    {    NTLMSSP::userAdd (userName, passwd);    }/**************************************************************************** CoInitializeSecurity - establish security for the whole application ** This function differs from its Win32 counterpart in that it only* supports the de-activation of security settings. This is because* VxDCOM does not support the full NTLM security subsystem, and so* this API is provided for source-compatibility only. However, to* prevent applications which rely on specific Win32 security behavior* from misbehaving under VxDCOM, this API will fail any attempts to* establish non-NULL security settings.** RETURNS: S_OK if requested to disable security settings,* E_INVALIDARG otherwise.*/HRESULT CoInitializeSecurity    (    void*		psd,		/* security descriptor - MBZ */    long		cAuths,		/* must be -1 */    void*		asAuths,	/* array of services - MBZ */    void*		pReserved1,	/* reserved - MBZ */    DWORD		dwAuthnLevel,	/* default authentication level */    DWORD		dwImpLevel,	/* default impersonation level */    void*		pAuthList,	/* per-service info - MBZ */    DWORD		dwCapabilities,	/* capabilities - must be EOAC_NONE */    void*		pReserved3	/* reserved - MBZ */    )    {    if (psd || asAuths || pReserved1 || pAuthList || pReserved3 ||	(cAuths != -1) ||	(dwCapabilities != EOAC_NONE))	return E_INVALIDARG;    g_defaultAuthnLevel = dwAuthnLevel;    return S_OK;    }/**************************************************************************** CoDisconnectObject - disconnects all remote connections to an object** This function forcibly disconnects all remote connections to the* given object. It should only ever be called in the same address* space (i.e. the same VxWorks instance) as the object being* disconnected. It is not for use by a remote client, for example.** When this function is called, all references on the object instance* identified by 'pUnk' that are held by the VxDCOM object exporter,* are released. The result is that the exporter's tables no longer* hold references to that object, and so any subsequent attempts to* call methods on any of its interfaces will result in* RPC_E_INVALID_IPID errors. This approach means that there is no* chance of object references (to disconnected objects) remaining in* the server's export tables, and hence less likelyhood of leaks* occurring at the VxDCOM server.** RETURNS: S_OK if all connections successfully severed.*/HRESULT CoDisconnectObject    (    IUnknown*           pUnk,           /* object to be disconnected */    DWORD               dwReserved      /* reserved for future use */    )    {    // Does the object support IMarshal? If so, let it handle the    // disconnection itself...    IMarshal* pMshl=0;    HRESULT hr = pUnk->QueryInterface (IID_IMarshal,                                       (void**) &pMshl);    if (FAILED (hr))        {        // It doesn't have IMarshal, so use the standard marshaler. We        // must find the OID of the object in the exporter's tables...        ObjectExporter* pExp = SCM::objectExporter ();        ObjectTableEntry* pOTE = pExp->objectFindByIUnknown (pUnk);        if (pOTE)            {            pMshl = new VxStdMarshaler (pOTE->oid);            pMshl->AddRef ();            hr = S_OK;            }        else            hr = RPC_E_INVALID_OBJECT;        }    // Perform the disconnect, if everything went well...    if (SUCCEEDED (hr) && pMshl)        {        // Use marshaler to disconnect...        hr = pMshl->DisconnectObject (dwReserved);        // Release the marshaler...        pMshl->Release ();        }    // Return the result of the DisconnectObject() method...    return hr;    }

⌨️ 快捷键说明

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