Essays.club - TCC, Modelos de monografias, Trabalhos de universidades, Ensaios, Bibliografias
Pesquisar

Documento DOM com um objeto de Site (listagem de código C++)

Por:   •  23/2/2018  •  1.555 Palavras (7 Páginas)  •  407 Visualizações

Página 1 de 7

...

Listagem de código: SiteImpl.h

C++

#include using namespace std; typedef struct _ZONEMAP { wstring _url; DWORD _zoneIndex; BOOL _fullCompare; _ZONEMAP(wstring url, DWORD zoneIndex, BOOL fullCompare) : _url(url), _zoneIndex(zoneIndex), _fullCompare(fullCompare) { } } ZONEMAP; typedef struct _ACTIONMAP { DWORD _zoneIndex; DWORD _action; BYTE _policy; _ACTIONMAP(DWORD zoneIndex, DWORD action, BYTE policy) : _zoneIndex(zoneIndex), _action(action), _policy(policy) { } } ACTIONMAP; class CSiteImpl : public IServiceProvider, public IInternetSecurityManager, IOleClientSite { private: ULONG _ulRefs; wstring _secureBaseURL; // IInternetSecurityManager ZONEMAP* _pZoneMap; int _nZoneMapCount; ACTIONMAP* _pActionMap; int _nActionMapCount; public: CSiteImpl(LPCWSTR secureBaseURL); virtual ~CSiteImpl(); HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv); ULONG STDMETHODCALLTYPE AddRef(); ULONG STDMETHODCALLTYPE Release(); // IServiceProvider HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void** ppv); // IDispatch HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT *pctinfo) { return E_NOTIMPL; } HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo,LCID lcid, ITypeInfo** ppTInfo) { return E_NOTIMPL; } HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,DISPID *rgDispId) { return E_NOTIMPL; } HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) { return E_NOTIMPL; } // IOleClientSite virtual HRESULT STDMETHODCALLTYPE SaveObject() { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE GetMoniker(DWORD dwAssign,DWORD dwWhichMoniker, IMoniker** ppmk); virtual HRESULT STDMETHODCALLTYPE GetContainer(IOleContainer**) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE ShowObject() { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE OnShowWindow(BOOL) { return E_NOTIMPL; } virtual HRESULT STDMETHODCALLTYPE RequestNewObjectLayout(){ return E_NOTIMPL; } // IInternetSecurityManager public: void SetZoneMap(ZONEMAP* pZoneMap, int count) { _pZoneMap = pZoneMap; _nZoneMapCount = count; } void SetActionMap(ACTIONMAP* pActionMap, int count) { _pActionMap = pActionMap; _nActionMapCount = count; } HRESULT STDMETHODCALLTYPE SetSecuritySite( IInternetSecurityMgrSite* pSite) { return INET_E_DEFAULT_ACTION; } HRESULT STDMETHODCALLTYPE GetSecuritySite( IInternetSecurityMgrSite** ppSite) { return INET_E_DEFAULT_ACTION; } virtual HRESULT STDMETHODCALLTYPE MapUrlToZone( LPCWSTR pwszUrl, DWORD *pdwZone, DWORD dwFlags); virtual HRESULT STDMETHODCALLTYPE GetSecurityId( LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved) { return INET_E_DEFAULT_ACTION; } virtual HRESULT STDMETHODCALLTYPE ProcessUrlAction( LPCWSTR pwszUrl, DWORD dwAction, BYTE* pPolicy, DWORD cbPolicy, BYTE* pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved); virtual HRESULT STDMETHODCALLTYPE QueryCustomPolicy( LPCWSTR pwszUrl, REFGUID guidKey, BYTE** ppPolicy, DWORD* pcbPolicy, BYTE* pContext, DWORD cbContext, DWORD dwReserved) { return INET_E_DEFAULT_ACTION; } virtual HRESULT STDMETHODCALLTYPE SetZoneMapping( DWORD dwZone, LPCWSTR lpszPattern, DWORD dwFlags) { return INET_E_DEFAULT_ACTION; } virtual HRESULT STDMETHODCALLTYPE GetZoneMappings( DWORD dwZone, IEnumString** ppenumString, DWORD dwFlags) { return INET_E_DEFAULT_ACTION; } };

Listagem de código: SiteImpl.cpp

C++

#include "stdafx.h" #include #include "SiteImpl.h" #pragma comment( lib, "urlmon.lib") ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CSiteImpl::CSiteImpl(LPCWSTR secureBaseURL) { _ulRefs = 0; _secureBaseURL = secureBaseURL; _pZoneMap = NULL; _pActionMap = NULL; _nZoneMapCount = 0; _nActionMapCount = 0; } CSiteImpl::~CSiteImpl() { } HRESULT CSiteImpl::QueryInterface(REFIID riid, void** ppv) { HRESULT hr = S_OK; if (riid == IID_IUnknown || riid == IID_IServiceProvider) { *ppv = static_cast(this); } else if (riid == IID_IOleClientSite) { *ppv = static_cast(this); } else if (riid == IID_IInternetSecurityManager) { *ppv = static_cast(this); } else { *ppv = NULL; return E_NOINTERFACE; } AddRef(); return S_OK; } ULONG CSiteImpl::AddRef() { return ++_ulRefs; } ULONG CSiteImpl::Release() { ULONG ul = --_ulRefs; if (0 == ul) delete this; return ul; } HRESULT CSiteImpl::QueryService(REFGUID guidService, REFIID riid, void ** ppv) { return QueryInterface(riid, ppv); } // Either URLMON or MSXML can trigger this method. // The implementation should be caller agnostic. // This method is used to determine the zone of the URL. // Further, MSXML will use this method to determine the zone of a referenced document. // It can then determine whether the referring document // is attempting to load a document that is in a different zone. HRESULT CSiteImpl::MapUrlToZone(LPCWSTR pwszUrl, DWORD *pdwZone, DWORD dwFlags) { // Check if URL is in our map. for (int i=0; i_fullCompare && p->_url == pwszUrl) || (!p->_fullCompare && tempurl.find(p->_url) == 0)) { *pdwZone = p->_zoneIndex; return S_OK; } } return INET_E_DEFAULT_ACTION; } // Determines the policy for a specified security action. // URLMON triggers a call to this method whenever it encounters a security action // and needs to enlist a security manager to make a security-related decision // for that action. HRESULT CSiteImpl::ProcessUrlAction( LPCWSTR pwszUrl, DWORD dwAction, BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved) { DWORD dwZone; HRESULT hr = MapUrlToZone(pwszUrl, &dwZone, 0); // The goal is that MapUrlToZone returns a Zone that // either the custom security manager recognizes, or // the default Internet Security Manager recognizes. // (One of which should always be the case.) // Thus we ALWAYS enter the ACTIONMAP for the custom security manager // whenever a ProcessUrlAction is called. if (hr == INET_E_DEFAULT_ACTION) { // The custom MapUrlToZone gets the zone // from the default security manager. IInternetSecurityManagerPtr pDefSecMgr = NULL; hr = ::CoCreateInstance(CLSID_InternetSecurityManager, NULL, CLSCTX_INPROC, IID_IInternetSecurityManager, (LPVOID*)&pDefSecMgr); if (hr == S_OK) hr = pDefSecMgr->MapUrlToZone(pwszUrl, &dwZone, 0); } if (hr == S_OK) { for (int i=0; i_zoneIndex == dwZone && p->_action == dwAction) { *((DWORD*)pPolicy) = p->_policy; if (p->_policy == URLPOLICY_ALLOW) { return S_OK; } else { return S_FALSE; } } } } return INET_E_DEFAULT_ACTION; } // Returns the Secure Base URL to MSXML. HRESULT

...

Baixar como  txt (12.7 Kb)   pdf (57.5 Kb)   docx (14.4 Kb)  
Continuar por mais 6 páginas »
Disponível apenas no Essays.club