📄 devparsing.cpp
字号:
// UDN
if(pwszUDNElement == m_strFullElementName)
{
m_strUDN.trim(L"\n\r\t ");
m_pszOrigUDN = StrDupW(m_strUDN);
m_pRoot->SAXWriter()->characters(m_pszUDN, wcslen(m_pszUDN));
}
// presentationURL
if(pwszPresentationURLElement == m_strFullElementName)
{
m_strPresentationURL.trim(L"\n\r\t ");
if(!m_strPresentationURL.empty())
{
FileToURL(m_strPresentationURL, &m_strPresentationURL);
// add device description URL as query string
m_strPresentationURL += L"?";
m_strPresentationURL += c_szURLPrefix;
m_strPresentationURL += m_pRoot->DescFileName() + celems(c_szLocalWebRootDir) - 1;
}
m_pRoot->SAXWriter()->characters(m_strPresentationURL, m_strPresentationURL.size());
}
// Icon element
if(pwszIconURLElement == m_strFullElementName)
{
// trim white spaces
m_strIconURL.trim(L"\n\r\t ");
FileToURL(m_strIconURL, &m_strIconURL);
m_pRoot->SAXWriter()->characters(m_strIconURL, m_strIconURL.size());
}
//
// service properties
//
static const int nServiceLength = sizeof(pwszServiceElement)/sizeof(*pwszServiceElement) - 1;
if(0 == wcsncmp(pwszServiceElement, m_strFullElementName, nServiceLength))
{
// SCPDURL
if(0 == wcscmp(pwszSCPDURLElement, static_cast<LPCWSTR>(m_strFullElementName) + nServiceLength))
{
m_strServiceDescriptionURL.trim(L"\n\r\t ");
(*m_ppNextService)->m_pszSCPDPath = StrDupW(m_strServiceDescriptionURL);
// fix service description URL
FileToURL(m_strServiceDescriptionURL, &m_strServiceDescriptionURL);
m_pRoot->SAXWriter()->characters(m_strServiceDescriptionURL, m_strServiceDescriptionURL.size());
}
// controlURL
if(0 == wcscmp(pwszControlURLElement, static_cast<LPCWSTR>(m_strFullElementName) + nServiceLength))
{
// set control URL
m_strServiceControlURL.reserve(100);
m_strServiceControlURL = L"/upnpisapi?";
// don't write controlURL at this point because we might not have serviceID yet
bSkipWriting = true;
}
// eventSubURL
if(0 == wcscmp(pwszEventSubURL, static_cast<LPCWSTR>(m_strFullElementName) + nServiceLength))
{
// set eventing URL
m_strServiceEventSubURL.reserve(100);
m_strServiceEventSubURL = L"/upnpisapi?";
// don't write eventSubURL at this point because we might not have serviceID yet
bSkipWriting = true;
}
}
// Service element
if(pwszServiceElement == m_strFullElementName)
{
// trim white spaces
m_strServiceType.trim(L"\n\r\t ");
m_strServiceId.trim(L"\n\r\t ");
// build service URI
ce::wstring strURI;
strURI.reserve(100);
strURI = UDN();
strURI += L"+";
strURI += m_strServiceId;
// build controlURL
m_strServiceControlURL += strURI;
// write controlURL element
m_pRoot->SAXWriter()->startElement(pwchNamespaceUri, cchNamespaceUri, L"controlURL", 10, L"controlURL", 10, NULL);
m_pRoot->SAXWriter()->characters(m_strServiceControlURL, m_strServiceControlURL.size());
m_pRoot->SAXWriter()->endElement(pwchNamespaceUri, cchNamespaceUri, L"controlURL", 10, L"controlURL", 10);
// build controlURL
m_strServiceEventSubURL += strURI;
// write eventSubURL element
m_pRoot->SAXWriter()->startElement(pwchNamespaceUri, cchNamespaceUri, L"eventSubURL", 11, L"eventSubURL", 11, NULL);
m_pRoot->SAXWriter()->characters(m_strServiceEventSubURL, m_strServiceEventSubURL.size());
m_pRoot->SAXWriter()->endElement(pwchNamespaceUri, cchNamespaceUri, L"eventSubURL", 11, L"eventSubURL", 11);
// copy data from strings using during parsing
(*m_ppNextService)->m_pszServiceId = StrDupW(m_strServiceId);
(*m_ppNextService)->m_pszServiceType = StrDupW(m_strServiceType);
(*m_ppNextService)->m_pszaUri = StrDupWtoA(strURI);
// add service to collection
m_ppNextService = &(*m_ppNextService)->m_pNextService;
}
if(!bSkipWriting)
m_pRoot->SAXWriter()->endElement(pwchNamespaceUri, cchNamespaceUri, pwchLocalName, cchLocalName, pwchQName, cchQName);
}
return SAXContentHandler::endElement(pwchNamespaceUri, cchNamespaceUri, pwchLocalName, cchLocalName, pwchQName, cchQName);
}
// characters
HRESULT STDMETHODCALLTYPE HostedDevice::characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
if(m_pTempDevice)
// parsing section for nested device
m_pTempDevice->characters(pwchChars, cchChars);
else
{
bool bSkipWriting = false;
//
// device properties
//
// deviceType
if(L"<urn:schemas-upnp-org:device-1-0><deviceType>" == m_strFullElementName)
m_strDeviceType.append(pwchChars, cchChars);
// UDN
if(pwszUDNElement == m_strFullElementName)
{
m_strUDN.append(pwchChars, cchChars);
bSkipWriting = true;
}
// presentationURL
if(pwszPresentationURLElement == m_strFullElementName)
{
m_strPresentationURL.append(pwchChars, cchChars);
bSkipWriting = true;
}
//
// icon properties
//
if(0 == wcscmp(pwszIconURLElement, m_strFullElementName))
{
m_strIconURL.append(pwchChars, cchChars);
bSkipWriting = true;
}
//
// service properties
//
static const int nServiceLength = sizeof(pwszServiceElement)/sizeof(*pwszServiceElement) - 1;
if(0 == wcsncmp(pwszServiceElement, m_strFullElementName, nServiceLength))
{
// serviceType
if(0 == wcscmp(L"<urn:schemas-upnp-org:device-1-0><serviceType>", static_cast<LPCWSTR>(m_strFullElementName) + nServiceLength))
m_strServiceType.append(pwchChars, cchChars);
// serviceId
if(0 == wcscmp(L"<urn:schemas-upnp-org:device-1-0><serviceId>", static_cast<LPCWSTR>(m_strFullElementName) + nServiceLength))
m_strServiceId.append(pwchChars, cchChars);
// SCPDURL
if(0 == wcscmp(pwszSCPDURLElement, static_cast<LPCWSTR>(m_strFullElementName) + nServiceLength))
{
m_strServiceDescriptionURL.append(pwchChars, cchChars);
bSkipWriting = true;
}
// controlURL
if(0 == wcscmp(pwszControlURLElement, static_cast<LPCWSTR>(m_strFullElementName) + nServiceLength))
// ignore controlURL from xml, it will be generated
bSkipWriting = true;
// eventSubURL
if(0 == wcscmp(pwszEventSubURL, static_cast<LPCWSTR>(m_strFullElementName) + nServiceLength))
// ignore controlURL from xml, it will be generated
bSkipWriting = true;
}
if(!bSkipWriting)
m_pRoot->SAXWriter()->characters(pwchChars, cchChars);
}
return S_OK;
}
// endDocument
HRESULT STDMETHODCALLTYPE HostedDevice::endDocument(void)
{
// we finished parsing XML so now we can trim white spaces from string members
m_strDeviceType.trim(L"\n\r\t ");
// copy data from strings using during parsing
m_pszDeviceType = StrDupW(m_strDeviceType);
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -