📄 upnpsvc.h
字号:
//
// 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.
//
#include <list.h>
#include <UpnpInvokeRequest.hpp>
#define VALIDSSDPH(handle) (handle != INVALID_HANDLE_VALUE)
#define DEFAULT_PUBLISH_INTERVAL 1800 // default recommended by UPnP spec
#define MINIMUM_PUBLISH_INTERVAL 150 // this is the minimum allowed
#define HDT_NO_CALLBACKS 1 // flag to Shutdown()
#include "sax.h"
#include "trace.h"
#include "SAXWriter.h"
class HostedDeviceTree;
class HostedDevice;
class ControlRequest;
class HostedService
{
private:
PWSTR m_pszServiceId;
PWSTR m_pszServiceType;
PWSTR m_pszSCPDPath;
PSTR m_pszaUri;
BOOL m_fEventing;
HANDLE m_hSSDPSvc;
HostedDevice *m_pDevice;
HostedService *m_pNextService;
friend class HostedDevice;
public:
HostedService(HostedDevice *pOwnerDevice)
: m_pNextService(NULL),
m_pDevice(pOwnerDevice),
m_pszServiceId(NULL),
m_pszServiceType(NULL),
m_pszSCPDPath(NULL),
m_pszaUri(NULL),
m_fEventing(FALSE),
m_hSSDPSvc(INVALID_HANDLE_VALUE)
{
}
~HostedService();
HostedService * NextService(void)
{
return m_pNextService;
}
void LinkService(class HostedService *pNext)
{
m_pNextService = pNext;
}
PCWSTR ServiceId()
{
return m_pszServiceId;
}
PCWSTR SCPDPath()
{
return m_pszSCPDPath;
}
BOOL SubmitPropertyEvent(DWORD dwFlags, DWORD nArgs, UPNPPARAM *rgArgs);
BOOL SsdpRegister(DWORD dwLifeTime, PCWSTR pszDescURL, PCWSTR pszUDN);
BOOL SsdpUnregister(void);
};
class HostedDevice : ce::SAXContentHandler
{
private:
PWSTR m_pszUDN;
PWSTR m_pszOrigUDN;
PWSTR m_pszDeviceType;
HANDLE m_hSSDPUDN;
HANDLE m_hSSDPDevType;
HostedDevice *m_pTempDevice;
HostedDevice *m_pNextDev;
HostedDevice *m_pFirstChildDev;
HostedDevice **m_ppNextChildDev;
HostedDeviceTree *m_pRoot;
HostedService *m_pFirstService;
HostedService **m_ppNextService;
// private methods
// used during parsing
ce::wstring m_strServiceType;
ce::wstring m_strServiceId;
ce::wstring m_strServiceDescriptionURL;
ce::wstring m_strServiceControlURL;
ce::wstring m_strServiceEventSubURL;
ce::wstring m_strIconURL;
ce::wstring m_strDeviceType;
ce::wstring m_strUDN;
ce::wstring m_strPresentationURL;
friend class HostedDeviceTree;
public:
// public methods
HostedDevice( HostedDeviceTree *pRoot)
: m_pszUDN(NULL),
m_pszOrigUDN(NULL),
m_pszDeviceType(NULL),
m_hSSDPUDN(INVALID_HANDLE_VALUE),
m_hSSDPDevType(INVALID_HANDLE_VALUE),
m_pTempDevice(NULL),
m_pNextDev(NULL),
m_pFirstChildDev(NULL),
m_pRoot(pRoot),
m_pFirstService(NULL),
m_ppNextChildDev(&m_pFirstChildDev),
m_ppNextService(&m_pFirstService)
{}
~HostedDevice();
PCWSTR UDN() { return m_pszUDN;}
BOOL SetUDN(PCWSTR pszUDN);
HostedDeviceTree *Root() {return m_pRoot;}
HostedDevice *FindDevice(PCWSTR pszUDN);
HostedDevice *FindByOrigUDN(PCWSTR pszTemplateUDN);
HostedService *FindService(PCWSTR pszUDN, PCWSTR pszServiceId);
BOOL CreateUDN();
BOOL FileToURL(LPCWSTR pwszFile, ce::wstring* pstrURL);
BOOL SsdpRegister(DWORD dwLifeTime, PCWSTR pszDescURL );
BOOL SsdpUnregister(void);
// ISAXContentHandler
private:
virtual HRESULT STDMETHODCALLTYPE startDocument(void);
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE endDocument(void);
};
// used only in Initialize2
struct HDTInitInfo {
class HostedDeviceTree *pHDT;
UPNPDEVICEINFO devInfo;
HANDLE hOwner;
HANDLE hOwnerProc;
BOOL fRet;
};
typedef enum
{
DevTreeInvalid = 0,
DevTreeInitialized,
DevTreePublished,
DevTreeRunning
} DevTreeState;
class HostedDeviceTree : ce::SAXContentHandler
{
private:
// data
DevTreeState m_state;
DWORD m_dwLifeTime;
LONG m_cRef;
PWSTR m_pszURLBase;
PWSTR m_pszDescURL;
PWSTR m_pszDescFileName;
PWSTR m_pszName;
PWSTR m_pszUDN;
ce::wstring m_strSpecVersionMajor;
ce::wstring m_strSpecVersionMinor;
int m_nUDNSuffix;
HANDLE m_hOwner; // opaque handle identifying owner of the device tree
HANDLE m_hOwnerProc; // process into which to do callbacks
PUPNPCALLBACK m_pfCallback; // callback address in target process
PVOID m_pvCallbackContext; // opaque callback context
ControlRequest *m_pCurControlReq; // currently outstanding control action
HostedDevice *m_pRootDevice;
HostedDevice *m_pTempDevice;
HANDLE m_hSSDPRoot;
CRITICAL_SECTION m_cs;
HANDLE m_hShutdownEvent; // don't free
HANDLE m_hInitEvent; // don't free
ce::SAXWriter m_SAXWriter;
// private methods
void Lock()
{
EnterCriticalSection(&m_cs);
}
void Unlock()
{
LeaveCriticalSection(&m_cs);
}
public:
// public data
LIST_ENTRY m_link;
// public methods
HostedDeviceTree() :
m_state(DevTreeInvalid),
m_dwLifeTime(DEFAULT_PUBLISH_INTERVAL),
m_cRef(0),
m_pszDescURL(NULL),
m_pszURLBase(NULL),
m_pRootDevice(NULL),
m_pTempDevice(NULL),
m_hSSDPRoot(INVALID_HANDLE_VALUE),
m_hShutdownEvent(NULL),
m_hInitEvent(NULL),
m_pszName(NULL),
m_pfCallback(NULL),
m_pszDescFileName(NULL),
m_pszUDN(NULL),
m_nUDNSuffix(0),
m_pvCallbackContext(NULL),
m_pCurControlReq(NULL),
m_hOwnerProc(NULL),
m_hOwner(NULL),
m_SAXWriter(CP_UTF8)
{
InitializeListHead(&m_link);
InitializeCriticalSection(&m_cs);
}
~HostedDeviceTree();
BOOL Parse(LPCWSTR pwszDeviceDescription);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -