|
|
@ -32,9 +32,6 @@ |
|
|
|
#include <QMutexLocker> |
|
|
|
#include <QMutexLocker> |
|
|
|
#include <QString> |
|
|
|
#include <QString> |
|
|
|
|
|
|
|
|
|
|
|
#include <dlfcn.h> // For dlopen(), dlsym(), dlclose() |
|
|
|
|
|
|
|
#include <algorithm> // For transform() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUC__ |
|
|
|
#ifdef __GNUC__ |
|
|
|
#if __GNUC__ >= 4 |
|
|
|
#if __GNUC__ >= 4 |
|
|
@ -65,36 +62,6 @@ m_key() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CDynamicLibHandle::CDynamicLibHandle(const char *libname) |
|
|
|
|
|
|
|
: |
|
|
|
|
|
|
|
m_libname(libname), |
|
|
|
|
|
|
|
m_LibraryHandle(dlopen(libname, RTLD_LAZY)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::ostringstream msg; |
|
|
|
|
|
|
|
if (!m_LibraryHandle) { |
|
|
|
|
|
|
|
qDebug("error(CDynamicLibHandle): Unable to dlopen the lib. Check PATH and LD_LIBRARY_PATH."); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qDebug("Successfully opened the lib."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CDynamicLibHandle::~CDynamicLibHandle() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::ostringstream msg; |
|
|
|
|
|
|
|
int err_code = dlclose(m_LibraryHandle); |
|
|
|
|
|
|
|
if (err_code) { |
|
|
|
|
|
|
|
msg << "error(CDynamicLibHandle): Error closing " << |
|
|
|
|
|
|
|
m_libname << ": " << dlerror() << |
|
|
|
|
|
|
|
"."; |
|
|
|
|
|
|
|
fprintf(stderr, "%s\n", msg.str().c_str()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
msg << "Successfully closed " << m_libname << "."; |
|
|
|
|
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::string &CUPnPLib::UPNP_ROOT_DEVICE = |
|
|
|
const std::string &CUPnPLib::UPNP_ROOT_DEVICE = |
|
|
|
"upnp:rootdevice"; |
|
|
|
"upnp:rootdevice"; |
|
|
|
|
|
|
|
|
|
|
@ -116,134 +83,12 @@ const std::string &CUPnPLib::UPNP_SERVICE_WAN_IP_CONNECTION = |
|
|
|
const std::string &CUPnPLib::UPNP_SERVICE_WAN_PPP_CONNECTION = |
|
|
|
const std::string &CUPnPLib::UPNP_SERVICE_WAN_PPP_CONNECTION = |
|
|
|
"urn:schemas-upnp-org:service:WANPPPConnection:1"; |
|
|
|
"urn:schemas-upnp-org:service:WANPPPConnection:1"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CUPnPLib::CUPnPLib(CUPnPControlPoint &ctrlPoint) : m_ctrlPoint(ctrlPoint) {} |
|
|
|
const char *CUPnPLib::s_LibIXMLSymbols[] = |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
/* 0*/ "ixmlNode_getFirstChild", |
|
|
|
|
|
|
|
/* 1*/ "ixmlNode_getNextSibling", |
|
|
|
|
|
|
|
/* 2*/ "ixmlNode_getNodeName", |
|
|
|
|
|
|
|
/* 3*/ "ixmlNode_getNodeValue", |
|
|
|
|
|
|
|
/* 4*/ "ixmlNode_getAttributes", |
|
|
|
|
|
|
|
/* 5*/ "ixmlDocument_free", |
|
|
|
|
|
|
|
/* 6*/ "ixmlNamedNodeMap_getNamedItem", |
|
|
|
|
|
|
|
/* 7*/ "ixmlNamedNodeMap_free", |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *CUPnPLib::s_LibUPnPSymbols[] = |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
/* 0*/ "UpnpInit", |
|
|
|
|
|
|
|
/* 1*/ "UpnpFinish", |
|
|
|
|
|
|
|
/* 2*/ "UpnpGetServerPort", |
|
|
|
|
|
|
|
/* 3*/ "UpnpGetServerIpAddress", |
|
|
|
|
|
|
|
/* 4*/ "UpnpRegisterClient", |
|
|
|
|
|
|
|
/* 5*/ "UpnpUnRegisterClient", |
|
|
|
|
|
|
|
/* 6*/ "UpnpSearchAsync", |
|
|
|
|
|
|
|
/* 7*/ "UpnpGetServiceVarStatus", |
|
|
|
|
|
|
|
/* 8*/ "UpnpSendAction", |
|
|
|
|
|
|
|
/* 9*/ "UpnpSendActionAsync", |
|
|
|
|
|
|
|
/*10*/ "UpnpSubscribe", |
|
|
|
|
|
|
|
/*11*/ "UpnpUnSubscribe", |
|
|
|
|
|
|
|
/*12*/ "UpnpDownloadXmlDoc", |
|
|
|
|
|
|
|
/*13*/ "UpnpResolveURL", |
|
|
|
|
|
|
|
/*14*/ "UpnpMakeAction", |
|
|
|
|
|
|
|
/*15*/ "UpnpAddToAction", |
|
|
|
|
|
|
|
/*16*/ "UpnpGetErrorMessage", |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CUPnPLib::CUPnPLib(CUPnPControlPoint &ctrlPoint) |
|
|
|
|
|
|
|
: |
|
|
|
|
|
|
|
m_ctrlPoint(ctrlPoint), |
|
|
|
|
|
|
|
m_LibIXMLHandle("libixml.so.0"), |
|
|
|
|
|
|
|
m_LibUPnPHandle("libupnp.so.0") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// IXML
|
|
|
|
|
|
|
|
m_ixmlNode_getFirstChild = |
|
|
|
|
|
|
|
REINTERPRET_CAST(IXML_Node *(*)(IXML_Node *)) |
|
|
|
|
|
|
|
(dlsym(m_LibIXMLHandle.Get(), s_LibIXMLSymbols[0])); |
|
|
|
|
|
|
|
m_ixmlNode_getNextSibling = |
|
|
|
|
|
|
|
REINTERPRET_CAST(IXML_Node *(*)(IXML_Node *)) |
|
|
|
|
|
|
|
(dlsym(m_LibIXMLHandle.Get(), s_LibIXMLSymbols[1])); |
|
|
|
|
|
|
|
m_ixmlNode_getNodeName = |
|
|
|
|
|
|
|
REINTERPRET_CAST(const DOMString (*)(IXML_Node *)) |
|
|
|
|
|
|
|
(dlsym(m_LibIXMLHandle.Get(), s_LibIXMLSymbols[2])); |
|
|
|
|
|
|
|
m_ixmlNode_getNodeValue = |
|
|
|
|
|
|
|
REINTERPRET_CAST(const DOMString (*)(IXML_Node *)) |
|
|
|
|
|
|
|
(dlsym(m_LibIXMLHandle.Get(), s_LibIXMLSymbols[3])); |
|
|
|
|
|
|
|
m_ixmlNode_getAttributes = |
|
|
|
|
|
|
|
REINTERPRET_CAST(IXML_NamedNodeMap *(*)(IXML_Node *)) |
|
|
|
|
|
|
|
(dlsym(m_LibIXMLHandle.Get(), s_LibIXMLSymbols[4])); |
|
|
|
|
|
|
|
m_ixmlDocument_free = |
|
|
|
|
|
|
|
REINTERPRET_CAST(void (*)(IXML_Document *)) |
|
|
|
|
|
|
|
(dlsym(m_LibIXMLHandle.Get(), s_LibIXMLSymbols[5])); |
|
|
|
|
|
|
|
m_ixmlNamedNodeMap_getNamedItem = |
|
|
|
|
|
|
|
REINTERPRET_CAST(IXML_Node *(*)(IXML_NamedNodeMap *, const DOMString)) |
|
|
|
|
|
|
|
(dlsym(m_LibIXMLHandle.Get(), s_LibIXMLSymbols[6])); |
|
|
|
|
|
|
|
m_ixmlNamedNodeMap_free = |
|
|
|
|
|
|
|
REINTERPRET_CAST(void (*)(IXML_NamedNodeMap *)) |
|
|
|
|
|
|
|
(dlsym(m_LibIXMLHandle.Get(), s_LibIXMLSymbols[7])); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// UPnP
|
|
|
|
|
|
|
|
m_UpnpInit = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(const char *, int)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[0])); |
|
|
|
|
|
|
|
m_UpnpFinish = |
|
|
|
|
|
|
|
REINTERPRET_CAST(void (*)()) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[1])); |
|
|
|
|
|
|
|
m_UpnpGetServerPort = |
|
|
|
|
|
|
|
REINTERPRET_CAST(unsigned short (*)()) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[2])); |
|
|
|
|
|
|
|
m_UpnpGetServerIpAddress = |
|
|
|
|
|
|
|
REINTERPRET_CAST(char * (*)()) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[3])); |
|
|
|
|
|
|
|
m_UpnpRegisterClient = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(Upnp_FunPtr, const void *, UpnpClient_Handle *)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[4])); |
|
|
|
|
|
|
|
m_UpnpUnRegisterClient = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(UpnpClient_Handle)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[5])); |
|
|
|
|
|
|
|
m_UpnpSearchAsync = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(UpnpClient_Handle, int, const char *, const void *)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[6])); |
|
|
|
|
|
|
|
m_UpnpGetServiceVarStatus = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(UpnpClient_Handle, const char *, const char *, DOMString *)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[7])); |
|
|
|
|
|
|
|
m_UpnpSendAction = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(UpnpClient_Handle, const char *, const char *, const char *, |
|
|
|
|
|
|
|
IXML_Document *, IXML_Document **)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[8])); |
|
|
|
|
|
|
|
m_UpnpSendActionAsync = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(UpnpClient_Handle, const char *, const char *, const char *, |
|
|
|
|
|
|
|
IXML_Document *, Upnp_FunPtr, const void *)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[9])); |
|
|
|
|
|
|
|
m_UpnpSubscribe = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(UpnpClient_Handle, const char *, int *, Upnp_SID)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[10])); |
|
|
|
|
|
|
|
m_UpnpUnSubscribe = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(UpnpClient_Handle, Upnp_SID)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[11])); |
|
|
|
|
|
|
|
m_UpnpDownloadXmlDoc = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(const char *, IXML_Document **)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[12])); |
|
|
|
|
|
|
|
m_UpnpResolveURL = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(const char *, const char *, char *)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[13])); |
|
|
|
|
|
|
|
m_UpnpMakeAction = |
|
|
|
|
|
|
|
REINTERPRET_CAST(IXML_Document *(*)(const char *, const char *, int, const char *, ...)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[14])); |
|
|
|
|
|
|
|
m_UpnpAddToAction = |
|
|
|
|
|
|
|
REINTERPRET_CAST(int (*)(IXML_Document **, const char *, const char *, const char *, const char *)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[15])); |
|
|
|
|
|
|
|
m_UpnpGetErrorMessage = |
|
|
|
|
|
|
|
REINTERPRET_CAST(const char *(*)(int)) |
|
|
|
|
|
|
|
(dlsym(m_LibUPnPHandle.Get(), s_LibUPnPSymbols[16])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string CUPnPLib::GetUPnPErrorMessage(int code) const |
|
|
|
std::string CUPnPLib::GetUPnPErrorMessage(int code) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return m_UpnpGetErrorMessage(code); |
|
|
|
return UpnpGetErrorMessage(code); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -319,7 +164,7 @@ IXML_Element *CUPnPLib::Element_GetRootElement( |
|
|
|
IXML_Document *doc) const |
|
|
|
IXML_Document *doc) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
IXML_Element *root = REINTERPRET_CAST(IXML_Element *)( |
|
|
|
IXML_Element *root = REINTERPRET_CAST(IXML_Element *)( |
|
|
|
m_ixmlNode_getFirstChild( |
|
|
|
ixmlNode_getFirstChild( |
|
|
|
REINTERPRET_CAST(IXML_Node *)(doc))); |
|
|
|
REINTERPRET_CAST(IXML_Node *)(doc))); |
|
|
|
|
|
|
|
|
|
|
|
return root; |
|
|
|
return root; |
|
|
@ -333,7 +178,7 @@ IXML_Element *CUPnPLib::Element_GetFirstChild( |
|
|
|
IXML_Element *parent) const |
|
|
|
IXML_Element *parent) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(parent); |
|
|
|
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(parent); |
|
|
|
IXML_Node *child = m_ixmlNode_getFirstChild(node); |
|
|
|
IXML_Node *child = ixmlNode_getFirstChild(node); |
|
|
|
|
|
|
|
|
|
|
|
return REINTERPRET_CAST(IXML_Element *)(child); |
|
|
|
return REINTERPRET_CAST(IXML_Element *)(child); |
|
|
|
} |
|
|
|
} |
|
|
@ -346,7 +191,7 @@ IXML_Element *CUPnPLib::Element_GetNextSibling( |
|
|
|
IXML_Element *child) const |
|
|
|
IXML_Element *child) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(child); |
|
|
|
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(child); |
|
|
|
IXML_Node *sibling = m_ixmlNode_getNextSibling(node); |
|
|
|
IXML_Node *sibling = ixmlNode_getNextSibling(node); |
|
|
|
|
|
|
|
|
|
|
|
return REINTERPRET_CAST(IXML_Element *)(sibling); |
|
|
|
return REINTERPRET_CAST(IXML_Element *)(sibling); |
|
|
|
} |
|
|
|
} |
|
|
@ -359,7 +204,7 @@ const DOMString CUPnPLib::Element_GetTag( |
|
|
|
IXML_Element *element) const |
|
|
|
IXML_Element *element) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(element); |
|
|
|
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(element); |
|
|
|
const DOMString tag = m_ixmlNode_getNodeName(node); |
|
|
|
const DOMString tag = ixmlNode_getNodeName(node); |
|
|
|
|
|
|
|
|
|
|
|
return tag; |
|
|
|
return tag; |
|
|
|
} |
|
|
|
} |
|
|
@ -374,9 +219,9 @@ const std::string CUPnPLib::Element_GetTextValue( |
|
|
|
if (!element) { |
|
|
|
if (!element) { |
|
|
|
return stdEmptyString; |
|
|
|
return stdEmptyString; |
|
|
|
} |
|
|
|
} |
|
|
|
IXML_Node *text = m_ixmlNode_getFirstChild( |
|
|
|
IXML_Node *text = ixmlNode_getFirstChild( |
|
|
|
REINTERPRET_CAST(IXML_Node *)(element)); |
|
|
|
REINTERPRET_CAST(IXML_Node *)(element)); |
|
|
|
const DOMString s = m_ixmlNode_getNodeValue(text); |
|
|
|
const DOMString s = ixmlNode_getNodeValue(text); |
|
|
|
std::string ret; |
|
|
|
std::string ret; |
|
|
|
if (s) { |
|
|
|
if (s) { |
|
|
|
ret = s; |
|
|
|
ret = s; |
|
|
@ -413,11 +258,11 @@ IXML_Element *CUPnPLib::Element_GetFirstChildByTag( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(element); |
|
|
|
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(element); |
|
|
|
IXML_Node *child = m_ixmlNode_getFirstChild(node); |
|
|
|
IXML_Node *child = ixmlNode_getFirstChild(node); |
|
|
|
const DOMString childTag = m_ixmlNode_getNodeName(child); |
|
|
|
const DOMString childTag = ixmlNode_getNodeName(child); |
|
|
|
while(child && childTag && strcmp(tag, childTag)) { |
|
|
|
while(child && childTag && strcmp(tag, childTag)) { |
|
|
|
child = m_ixmlNode_getNextSibling(child); |
|
|
|
child = ixmlNode_getNextSibling(child); |
|
|
|
childTag = m_ixmlNode_getNodeName(child); |
|
|
|
childTag = ixmlNode_getNodeName(child); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return REINTERPRET_CAST(IXML_Element *)(child); |
|
|
|
return REINTERPRET_CAST(IXML_Element *)(child); |
|
|
@ -438,8 +283,8 @@ IXML_Element *CUPnPLib::Element_GetNextSiblingByTag( |
|
|
|
IXML_Node *child = REINTERPRET_CAST(IXML_Node *)(element); |
|
|
|
IXML_Node *child = REINTERPRET_CAST(IXML_Node *)(element); |
|
|
|
const DOMString childTag = NULL; |
|
|
|
const DOMString childTag = NULL; |
|
|
|
do { |
|
|
|
do { |
|
|
|
child = m_ixmlNode_getNextSibling(child); |
|
|
|
child = ixmlNode_getNextSibling(child); |
|
|
|
childTag = m_ixmlNode_getNodeName(child); |
|
|
|
childTag = ixmlNode_getNodeName(child); |
|
|
|
} while(child && childTag && strcmp(tag, childTag)); |
|
|
|
} while(child && childTag && strcmp(tag, childTag)); |
|
|
|
|
|
|
|
|
|
|
|
return REINTERPRET_CAST(IXML_Element *)(child); |
|
|
|
return REINTERPRET_CAST(IXML_Element *)(child); |
|
|
@ -449,15 +294,15 @@ IXML_Element *CUPnPLib::Element_GetNextSiblingByTag( |
|
|
|
const std::string CUPnPLib::Element_GetAttributeByTag( |
|
|
|
const std::string CUPnPLib::Element_GetAttributeByTag( |
|
|
|
IXML_Element *element, const DOMString tag) const |
|
|
|
IXML_Element *element, const DOMString tag) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
IXML_NamedNodeMap *NamedNodeMap = m_ixmlNode_getAttributes( |
|
|
|
IXML_NamedNodeMap *NamedNodeMap = ixmlNode_getAttributes( |
|
|
|
REINTERPRET_CAST(IXML_Node *)(element)); |
|
|
|
REINTERPRET_CAST(IXML_Node *)(element)); |
|
|
|
IXML_Node *attribute = m_ixmlNamedNodeMap_getNamedItem(NamedNodeMap, tag); |
|
|
|
IXML_Node *attribute = m_ixmlNamedNodeMap_getNamedItem(NamedNodeMap, tag); |
|
|
|
const DOMString s = m_ixmlNode_getNodeValue(attribute); |
|
|
|
const DOMString s = ixmlNode_getNodeValue(attribute); |
|
|
|
std::string ret; |
|
|
|
std::string ret; |
|
|
|
if (s) { |
|
|
|
if (s) { |
|
|
|
ret = s; |
|
|
|
ret = s; |
|
|
|
} |
|
|
|
} |
|
|
|
m_ixmlNamedNodeMap_free(NamedNodeMap); |
|
|
|
ixmlNamedNodeMap_free(NamedNodeMap); |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
@ -603,9 +448,9 @@ m_SCPD(NULL) |
|
|
|
int errcode; |
|
|
|
int errcode; |
|
|
|
|
|
|
|
|
|
|
|
char *scpdURL = new char[URLBase.length() + m_SCPDURL.length() + 1]; |
|
|
|
char *scpdURL = new char[URLBase.length() + m_SCPDURL.length() + 1]; |
|
|
|
errcode = upnpLib.m_UpnpResolveURL( |
|
|
|
errcode = UpnpResolveURL( |
|
|
|
URLBase.c_str(), |
|
|
|
(char*)URLBase.c_str(), |
|
|
|
m_SCPDURL.c_str(), |
|
|
|
(char*)m_SCPDURL.c_str(), |
|
|
|
scpdURL); |
|
|
|
scpdURL); |
|
|
|
if( errcode != UPNP_E_SUCCESS ) { |
|
|
|
if( errcode != UPNP_E_SUCCESS ) { |
|
|
|
msg << "Error generating scpdURL from " << |
|
|
|
msg << "Error generating scpdURL from " << |
|
|
@ -618,9 +463,9 @@ m_SCPD(NULL) |
|
|
|
|
|
|
|
|
|
|
|
char *controlURL = new char[ |
|
|
|
char *controlURL = new char[ |
|
|
|
URLBase.length() + m_controlURL.length() + 1]; |
|
|
|
URLBase.length() + m_controlURL.length() + 1]; |
|
|
|
errcode = upnpLib.m_UpnpResolveURL( |
|
|
|
errcode = UpnpResolveURL( |
|
|
|
URLBase.c_str(), |
|
|
|
(char*)URLBase.c_str(), |
|
|
|
m_controlURL.c_str(), |
|
|
|
(char*)m_controlURL.c_str(), |
|
|
|
controlURL); |
|
|
|
controlURL); |
|
|
|
if( errcode != UPNP_E_SUCCESS ) { |
|
|
|
if( errcode != UPNP_E_SUCCESS ) { |
|
|
|
msg << "Error generating controlURL from " << |
|
|
|
msg << "Error generating controlURL from " << |
|
|
@ -633,9 +478,9 @@ m_SCPD(NULL) |
|
|
|
|
|
|
|
|
|
|
|
char *eventURL = new char[ |
|
|
|
char *eventURL = new char[ |
|
|
|
URLBase.length() + m_eventSubURL.length() + 1]; |
|
|
|
URLBase.length() + m_eventSubURL.length() + 1]; |
|
|
|
errcode = upnpLib.m_UpnpResolveURL( |
|
|
|
errcode = UpnpResolveURL( |
|
|
|
URLBase.c_str(), |
|
|
|
(char*)URLBase.c_str(), |
|
|
|
m_eventSubURL.c_str(), |
|
|
|
(char*)m_eventSubURL.c_str(), |
|
|
|
eventURL); |
|
|
|
eventURL); |
|
|
|
if( errcode != UPNP_E_SUCCESS ) { |
|
|
|
if( errcode != UPNP_E_SUCCESS ) { |
|
|
|
msg << "Error generating eventURL from " << |
|
|
|
msg << "Error generating eventURL from " << |
|
|
@ -777,12 +622,12 @@ bool CUPnPService::Execute( |
|
|
|
IXML_Document *ActionDoc = NULL; |
|
|
|
IXML_Document *ActionDoc = NULL; |
|
|
|
if (ArgValue.size()) { |
|
|
|
if (ArgValue.size()) { |
|
|
|
for (unsigned int i = 0; i < ArgValue.size(); ++i) { |
|
|
|
for (unsigned int i = 0; i < ArgValue.size(); ++i) { |
|
|
|
int ret = m_upnpLib.m_UpnpAddToAction( |
|
|
|
int ret = UpnpAddToAction( |
|
|
|
&ActionDoc, |
|
|
|
&ActionDoc, |
|
|
|
action.GetName().c_str(), |
|
|
|
(char*)action.GetName().c_str(), |
|
|
|
GetServiceType().c_str(), |
|
|
|
(char*)GetServiceType().c_str(), |
|
|
|
ArgValue[i].GetArgument().c_str(), |
|
|
|
(char*)ArgValue[i].GetArgument().c_str(), |
|
|
|
ArgValue[i].GetValue().c_str()); |
|
|
|
(char*)ArgValue[i].GetValue().c_str()); |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
m_upnpLib.processUPnPErrorMessage( |
|
|
|
m_upnpLib.processUPnPErrorMessage( |
|
|
|
"m_UpnpAddToAction", ret, NULL, NULL); |
|
|
|
"m_UpnpAddToAction", ret, NULL, NULL); |
|
|
@ -790,9 +635,9 @@ bool CUPnPService::Execute( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ActionDoc = m_upnpLib.m_UpnpMakeAction( |
|
|
|
ActionDoc = UpnpMakeAction( |
|
|
|
action.GetName().c_str(), |
|
|
|
(char*)action.GetName().c_str(), |
|
|
|
GetServiceType().c_str(), |
|
|
|
(char*)GetServiceType().c_str(), |
|
|
|
0, NULL); |
|
|
|
0, NULL); |
|
|
|
if (!ActionDoc) { |
|
|
|
if (!ActionDoc) { |
|
|
|
msg << "Error: m_UpnpMakeAction returned NULL."; |
|
|
|
msg << "Error: m_UpnpMakeAction returned NULL."; |
|
|
@ -800,24 +645,13 @@ bool CUPnPService::Execute( |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#if 0 |
|
|
|
|
|
|
|
// Send the action asynchronously
|
|
|
|
|
|
|
|
m_upnpLib.m_UpnpSendActionAsync( |
|
|
|
|
|
|
|
m_UPnPControlPoint.GetUPnPClientHandle(), |
|
|
|
|
|
|
|
GetAbsControlURL().c_str(), |
|
|
|
|
|
|
|
GetServiceType().c_str(), |
|
|
|
|
|
|
|
NULL, ActionDoc, |
|
|
|
|
|
|
|
static_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback), |
|
|
|
|
|
|
|
NULL); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send the action synchronously
|
|
|
|
// Send the action synchronously
|
|
|
|
IXML_Document *RespDoc = NULL; |
|
|
|
IXML_Document *RespDoc = NULL; |
|
|
|
int ret = m_upnpLib.m_UpnpSendAction( |
|
|
|
int ret = UpnpSendAction( |
|
|
|
m_UPnPControlPoint.GetUPnPClientHandle(), |
|
|
|
m_UPnPControlPoint.GetUPnPClientHandle(), |
|
|
|
GetAbsControlURL().c_str(), |
|
|
|
(char*)GetAbsControlURL().c_str(), |
|
|
|
GetServiceType().c_str(), |
|
|
|
(char*)GetServiceType().c_str(), |
|
|
|
NULL, ActionDoc, &RespDoc); |
|
|
|
NULL, ActionDoc, &RespDoc); |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
m_upnpLib.processUPnPErrorMessage( |
|
|
|
m_upnpLib.processUPnPErrorMessage( |
|
|
@ -826,14 +660,14 @@ bool CUPnPService::Execute( |
|
|
|
m_upnpLib.m_ixmlDocument_free(RespDoc); |
|
|
|
m_upnpLib.m_ixmlDocument_free(RespDoc); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
m_upnpLib.m_ixmlDocument_free(ActionDoc); |
|
|
|
ixmlDocument_free(ActionDoc); |
|
|
|
|
|
|
|
|
|
|
|
// Check the response document
|
|
|
|
// Check the response document
|
|
|
|
m_upnpLib.ProcessActionResponse( |
|
|
|
m_upnpLib.ProcessActionResponse( |
|
|
|
RespDoc, action.GetName()); |
|
|
|
RespDoc, action.GetName()); |
|
|
|
|
|
|
|
|
|
|
|
// Free the response document
|
|
|
|
// Free the response document
|
|
|
|
m_upnpLib.m_ixmlDocument_free(RespDoc); |
|
|
|
ixmlDocument_free(RespDoc); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -844,10 +678,10 @@ const std::string CUPnPService::GetStateVariable( |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::ostringstream msg; |
|
|
|
std::ostringstream msg; |
|
|
|
DOMString StVarVal; |
|
|
|
DOMString StVarVal; |
|
|
|
int ret = m_upnpLib.m_UpnpGetServiceVarStatus( |
|
|
|
int ret = UpnpGetServiceVarStatus( |
|
|
|
m_UPnPControlPoint.GetUPnPClientHandle(), |
|
|
|
m_UPnPControlPoint.GetUPnPClientHandle(), |
|
|
|
GetAbsControlURL().c_str(), |
|
|
|
(char*)GetAbsControlURL().c_str(), |
|
|
|
stateVariableName.c_str(), |
|
|
|
(char*)stateVariableName.c_str(), |
|
|
|
&StVarVal); |
|
|
|
&StVarVal); |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
msg << "GetStateVariable(\"" << |
|
|
|
msg << "GetStateVariable(\"" << |
|
|
@ -893,9 +727,9 @@ m_presentationURL (upnpLib.Element_GetChildValueByTag(device, "presentationURL" |
|
|
|
int presURLlen = strlen(URLBase.c_str()) + |
|
|
|
int presURLlen = strlen(URLBase.c_str()) + |
|
|
|
strlen(m_presentationURL.c_str()) + 2; |
|
|
|
strlen(m_presentationURL.c_str()) + 2; |
|
|
|
char presURL[presURLlen]; |
|
|
|
char presURL[presURLlen]; |
|
|
|
int errcode = upnpLib.m_UpnpResolveURL( |
|
|
|
int errcode = UpnpResolveURL( |
|
|
|
URLBase.c_str(), |
|
|
|
(char*)URLBase.c_str(), |
|
|
|
m_presentationURL.c_str(), |
|
|
|
(char*)m_presentationURL.c_str(), |
|
|
|
presURL); |
|
|
|
presURL); |
|
|
|
if (errcode != UPNP_E_SUCCESS) { |
|
|
|
if (errcode != UPNP_E_SUCCESS) { |
|
|
|
msg << "Error generating presentationURL from " << |
|
|
|
msg << "Error generating presentationURL from " << |
|
|
@ -973,18 +807,18 @@ m_UPnPPort(udpPort) |
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
char *ipAddress = NULL; |
|
|
|
char *ipAddress = NULL; |
|
|
|
unsigned short port = 0; |
|
|
|
unsigned short port = 0; |
|
|
|
ret = m_upnpLib.m_UpnpInit(ipAddress, udpPort); |
|
|
|
ret = UpnpInit(ipAddress, udpPort); |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
msg << "error(UpnpInit): Error code "; |
|
|
|
msg << "error(UpnpInit): Error code "; |
|
|
|
goto error; |
|
|
|
goto error; |
|
|
|
} |
|
|
|
} |
|
|
|
port = m_upnpLib.m_UpnpGetServerPort(); |
|
|
|
port = UpnpGetServerPort(); |
|
|
|
ipAddress = m_upnpLib.m_UpnpGetServerIpAddress(); |
|
|
|
ipAddress = UpnpGetServerIpAddress(); |
|
|
|
msg << "bound to " << ipAddress << ":" << |
|
|
|
msg << "bound to " << ipAddress << ":" << |
|
|
|
port << "."; |
|
|
|
port << "."; |
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
msg.str(""); |
|
|
|
msg.str(""); |
|
|
|
ret = m_upnpLib.m_UpnpRegisterClient( |
|
|
|
ret = UpnpRegisterClient( |
|
|
|
static_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback), |
|
|
|
static_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback), |
|
|
|
&m_UPnPClientHandle, |
|
|
|
&m_UPnPClientHandle, |
|
|
|
&m_UPnPClientHandle); |
|
|
|
&m_UPnPClientHandle); |
|
|
@ -1002,10 +836,10 @@ m_UPnPPort(udpPort) |
|
|
|
// We should not search twice, because this will produce two
|
|
|
|
// We should not search twice, because this will produce two
|
|
|
|
// UPNP_DISCOVERY_SEARCH_TIMEOUT events, and we might end with problems
|
|
|
|
// UPNP_DISCOVERY_SEARCH_TIMEOUT events, and we might end with problems
|
|
|
|
// on the mutex.
|
|
|
|
// on the mutex.
|
|
|
|
ret = m_upnpLib.m_UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_ROOT_DEVICE.c_str(), NULL); |
|
|
|
ret = UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_ROOT_DEVICE.c_str(), NULL); |
|
|
|
//ret = m_upnpLib.m_UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_IGW.c_str(), this);
|
|
|
|
//ret = UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_IGW.c_str(), this);
|
|
|
|
//ret = m_upnpLib.m_UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_LAN.c_str(), this);
|
|
|
|
//ret = UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_LAN.c_str(), this);
|
|
|
|
//ret = m_upnpLib.m_UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_WAN_CONNECTION.c_str(), this);
|
|
|
|
//ret = UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_WAN_CONNECTION.c_str(), this);
|
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
msg << "error(UpnpSearchAsync): Error sending search request: "; |
|
|
|
msg << "error(UpnpSearchAsync): Error sending search request: "; |
|
|
|
goto error; |
|
|
|
goto error; |
|
|
@ -1027,7 +861,7 @@ m_UPnPPort(udpPort) |
|
|
|
|
|
|
|
|
|
|
|
// Error processing
|
|
|
|
// Error processing
|
|
|
|
error: |
|
|
|
error: |
|
|
|
m_upnpLib.m_UpnpFinish(); |
|
|
|
UpnpFinish(); |
|
|
|
msg << ret << ": " << m_upnpLib.GetUPnPErrorMessage(ret) << "."; |
|
|
|
msg << ret << ": " << m_upnpLib.GetUPnPErrorMessage(ret) << "."; |
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
} |
|
|
|
} |
|
|
@ -1042,8 +876,8 @@ CUPnPControlPoint::~CUPnPControlPoint() |
|
|
|
} |
|
|
|
} |
|
|
|
// Remove all first
|
|
|
|
// Remove all first
|
|
|
|
// RemoveAll();
|
|
|
|
// RemoveAll();
|
|
|
|
m_upnpLib.m_UpnpUnRegisterClient(m_UPnPClientHandle); |
|
|
|
UpnpUnRegisterClient(m_UPnPClientHandle); |
|
|
|
m_upnpLib.m_UpnpFinish(); |
|
|
|
UpnpFinish(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1148,7 +982,7 @@ bool CUPnPControlPoint::PrivateAddPortMapping( |
|
|
|
CUPnPPortMapping &upnpPortMapping) |
|
|
|
CUPnPPortMapping &upnpPortMapping) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Get an IP address. The UPnP server one must do.
|
|
|
|
// Get an IP address. The UPnP server one must do.
|
|
|
|
std::string ipAddress(m_upnpLib.m_UpnpGetServerIpAddress()); |
|
|
|
std::string ipAddress(UpnpGetServerIpAddress()); |
|
|
|
|
|
|
|
|
|
|
|
// Start building the action
|
|
|
|
// Start building the action
|
|
|
|
std::string actionName("AddPortMapping"); |
|
|
|
std::string actionName("AddPortMapping"); |
|
|
@ -1301,7 +1135,7 @@ upnpDiscovery: |
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
// Get the XML tree device description in doc
|
|
|
|
// Get the XML tree device description in doc
|
|
|
|
ret = upnpCP->m_upnpLib.m_UpnpDownloadXmlDoc(d_event->Location, &doc); |
|
|
|
ret = UpnpDownloadXmlDoc(d_event->Location, &doc); |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
if (ret != UPNP_E_SUCCESS) { |
|
|
|
msg << "Error retrieving device description from " << |
|
|
|
msg << "Error retrieving device description from " << |
|
|
|
d_event->Location << ": " << |
|
|
|
d_event->Location << ": " << |
|
|
@ -1369,7 +1203,6 @@ upnpDiscovery: |
|
|
|
} |
|
|
|
} |
|
|
|
std::string devType = dab_event->DeviceType; |
|
|
|
std::string devType = dab_event->DeviceType; |
|
|
|
// Check for an InternetGatewayDevice and removes it from the list
|
|
|
|
// Check for an InternetGatewayDevice and removes it from the list
|
|
|
|
transform(devType.begin(), devType.end(), devType.begin(), tolower); |
|
|
|
|
|
|
|
if (QString(devType.c_str()).toUpper() == QString(upnpCP->m_upnpLib.UPNP_DEVICE_IGW.c_str()).toUpper()) { |
|
|
|
if (QString(devType.c_str()).toUpper() == QString(upnpCP->m_upnpLib.UPNP_DEVICE_IGW.c_str()).toUpper()) { |
|
|
|
upnpCP->RemoveRootDevice(dab_event->DeviceId); |
|
|
|
upnpCP->RemoveRootDevice(dab_event->DeviceId); |
|
|
|
} |
|
|
|
} |
|
|
@ -1419,7 +1252,7 @@ upnpEventSubscriptionExpired: |
|
|
|
(struct Upnp_Event_Subscribe *)Event; |
|
|
|
(struct Upnp_Event_Subscribe *)Event; |
|
|
|
Upnp_SID newSID; |
|
|
|
Upnp_SID newSID; |
|
|
|
int TimeOut = 1801; |
|
|
|
int TimeOut = 1801; |
|
|
|
int ret = upnpCP->m_upnpLib.m_UpnpSubscribe( |
|
|
|
int ret = UpnpSubscribe( |
|
|
|
upnpCP->m_UPnPClientHandle, |
|
|
|
upnpCP->m_UPnPClientHandle, |
|
|
|
es_event->PublisherUrl, |
|
|
|
es_event->PublisherUrl, |
|
|
|
&TimeOut, |
|
|
|
&TimeOut, |
|
|
@ -1605,7 +1438,7 @@ void CUPnPControlPoint::RemoveRootDevice(const char *udn) |
|
|
|
void CUPnPControlPoint::Subscribe(CUPnPService &service) |
|
|
|
void CUPnPControlPoint::Subscribe(CUPnPService &service) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::ostringstream msg; |
|
|
|
std::ostringstream msg; |
|
|
|
int errcode = m_upnpLib.m_UpnpSubscribe(m_UPnPClientHandle, |
|
|
|
int errcode = UpnpSubscribe(m_UPnPClientHandle, |
|
|
|
service.GetAbsEventSubURL().c_str(), |
|
|
|
service.GetAbsEventSubURL().c_str(), |
|
|
|
service.GetTimeoutAddr(), |
|
|
|
service.GetTimeoutAddr(), |
|
|
|
service.GetSID()); |
|
|
|
service.GetSID()); |
|
|
@ -1617,7 +1450,7 @@ void CUPnPControlPoint::Subscribe(CUPnPService &service) |
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
qDebug("UPnP: %s", msg.str().c_str()); |
|
|
|
|
|
|
|
|
|
|
|
IXML_Document *scpdDoc = NULL; |
|
|
|
IXML_Document *scpdDoc = NULL; |
|
|
|
errcode = m_upnpLib.m_UpnpDownloadXmlDoc( |
|
|
|
errcode = UpnpDownloadXmlDoc( |
|
|
|
service.GetAbsSCPDURL().c_str(), &scpdDoc); |
|
|
|
service.GetAbsSCPDURL().c_str(), &scpdDoc); |
|
|
|
if (errcode == UPNP_E_SUCCESS) { |
|
|
|
if (errcode == UPNP_E_SUCCESS) { |
|
|
|
// Get the root node
|
|
|
|
// Get the root node
|
|
|
@ -1652,7 +1485,7 @@ void CUPnPControlPoint::Unsubscribe(CUPnPService &service) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ServiceMap::iterator it = m_ServiceMap.find(service.GetAbsEventSubURL()); |
|
|
|
ServiceMap::iterator it = m_ServiceMap.find(service.GetAbsEventSubURL()); |
|
|
|
m_ServiceMap.erase(it); |
|
|
|
m_ServiceMap.erase(it); |
|
|
|
m_upnpLib.m_UpnpUnSubscribe(m_UPnPClientHandle, service.GetSID()); |
|
|
|
UpnpUnSubscribe(m_UPnPClientHandle, service.GetSID()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|