mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
- Started to clean up upnp code
This commit is contained in:
parent
01dd57a5fb
commit
fa2815df49
13
configure
vendored
13
configure
vendored
@ -25,6 +25,7 @@ Dependency options:
|
||||
--disable-libupnp Disable use of libupnp
|
||||
--disable-upnp disable UPnP support
|
||||
--with-libupnp-inc=[path] Path to libupnp include files
|
||||
--with-libupnp-lib=[path] Path to libupnp library files
|
||||
|
||||
EOT
|
||||
}
|
||||
@ -176,6 +177,11 @@ while [ $# -gt 0 ]; do
|
||||
shift
|
||||
;;
|
||||
|
||||
--with-libupnp-lib=*)
|
||||
QC_WITH_LIBUPNP_LIB=$optarg
|
||||
shift
|
||||
;;
|
||||
|
||||
--verbose)
|
||||
QC_DEBUG="Y"
|
||||
shift
|
||||
@ -204,6 +210,7 @@ echo QC_WITH_LIBCURL_LIB=$QC_WITH_LIBCURL_LIB
|
||||
echo QC_DISABLE_libupnp=$QC_DISABLE_libupnp
|
||||
echo QC_DISABLE_UPNP=$QC_DISABLE_UPNP
|
||||
echo QC_WITH_LIBUPNP_INC=$QC_WITH_LIBUPNP_INC
|
||||
echo QC_WITH_LIBUPNP_LIB=$QC_WITH_LIBUPNP_LIB
|
||||
echo
|
||||
fi
|
||||
|
||||
@ -474,6 +481,7 @@ public:
|
||||
name: libupnp
|
||||
arg: disable-upnp, disable UPnP support
|
||||
arg: with-libupnp-inc=[path], Path to libupnp include files
|
||||
arg: with-libupnp-lib=[path], Path to libupnp library files
|
||||
-----END QCMOD-----
|
||||
*/
|
||||
class qc_libupnp : public ConfObj
|
||||
@ -509,7 +517,7 @@ public:
|
||||
conf->addIncludePath(s);
|
||||
}
|
||||
|
||||
/*s = conf->getenv("QC_WITH_LIBUPNP_LIB");
|
||||
s = conf->getenv("QC_WITH_LIBUPNP_LIB");
|
||||
if(!s.isEmpty()) {
|
||||
if(!conf->checkLibrary(s, "upnp")) {
|
||||
qWarning("libupnp library not found!");
|
||||
@ -525,7 +533,7 @@ public:
|
||||
conf->addLib(QString("-L") + s);
|
||||
}
|
||||
|
||||
conf->addLib("-lupnp");*/
|
||||
conf->addLib("-lupnp");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1484,6 +1492,7 @@ export QC_WITH_LIBCURL_LIB
|
||||
export QC_DISABLE_libupnp
|
||||
export QC_DISABLE_UPNP
|
||||
export QC_WITH_LIBUPNP_INC
|
||||
export QC_WITH_LIBUPNP_LIB
|
||||
export QC_DEBUG
|
||||
rm -rf .qconftemp
|
||||
(
|
||||
|
@ -3,6 +3,7 @@
|
||||
name: libupnp
|
||||
arg: disable-upnp, disable UPnP support
|
||||
arg: with-libupnp-inc=[path], Path to libupnp include files
|
||||
arg: with-libupnp-lib=[path], Path to libupnp library files
|
||||
-----END QCMOD-----
|
||||
*/
|
||||
class qc_libupnp : public ConfObj
|
||||
@ -38,7 +39,7 @@ public:
|
||||
conf->addIncludePath(s);
|
||||
}
|
||||
|
||||
/*s = conf->getenv("QC_WITH_LIBUPNP_LIB");
|
||||
s = conf->getenv("QC_WITH_LIBUPNP_LIB");
|
||||
if(!s.isEmpty()) {
|
||||
if(!conf->checkLibrary(s, "upnp")) {
|
||||
qWarning("libupnp library not found!");
|
||||
@ -54,7 +55,7 @@ public:
|
||||
conf->addLib(QString("-L") + s);
|
||||
}
|
||||
|
||||
conf->addLib("-lupnp");*/
|
||||
conf->addLib("-lupnp");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
291
src/UPnP.cpp
291
src/UPnP.cpp
@ -32,9 +32,6 @@
|
||||
#include <QMutexLocker>
|
||||
#include <QString>
|
||||
|
||||
#include <dlfcn.h> // For dlopen(), dlsym(), dlclose()
|
||||
#include <algorithm> // For transform()
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#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 =
|
||||
"upnp:rootdevice";
|
||||
|
||||
@ -116,134 +83,12 @@ const std::string &CUPnPLib::UPNP_SERVICE_WAN_IP_CONNECTION =
|
||||
const std::string &CUPnPLib::UPNP_SERVICE_WAN_PPP_CONNECTION =
|
||||
"urn:schemas-upnp-org:service:WANPPPConnection:1";
|
||||
|
||||
|
||||
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]));
|
||||
}
|
||||
CUPnPLib::CUPnPLib(CUPnPControlPoint &ctrlPoint) : m_ctrlPoint(ctrlPoint) {}
|
||||
|
||||
|
||||
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_Element *root = REINTERPRET_CAST(IXML_Element *)(
|
||||
m_ixmlNode_getFirstChild(
|
||||
ixmlNode_getFirstChild(
|
||||
REINTERPRET_CAST(IXML_Node *)(doc)));
|
||||
|
||||
return root;
|
||||
@ -333,7 +178,7 @@ IXML_Element *CUPnPLib::Element_GetFirstChild(
|
||||
IXML_Element *parent) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
@ -346,7 +191,7 @@ IXML_Element *CUPnPLib::Element_GetNextSibling(
|
||||
IXML_Element *child) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
@ -359,7 +204,7 @@ const DOMString CUPnPLib::Element_GetTag(
|
||||
IXML_Element *element) const
|
||||
{
|
||||
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(element);
|
||||
const DOMString tag = m_ixmlNode_getNodeName(node);
|
||||
const DOMString tag = ixmlNode_getNodeName(node);
|
||||
|
||||
return tag;
|
||||
}
|
||||
@ -374,9 +219,9 @@ const std::string CUPnPLib::Element_GetTextValue(
|
||||
if (!element) {
|
||||
return stdEmptyString;
|
||||
}
|
||||
IXML_Node *text = m_ixmlNode_getFirstChild(
|
||||
IXML_Node *text = ixmlNode_getFirstChild(
|
||||
REINTERPRET_CAST(IXML_Node *)(element));
|
||||
const DOMString s = m_ixmlNode_getNodeValue(text);
|
||||
const DOMString s = ixmlNode_getNodeValue(text);
|
||||
std::string ret;
|
||||
if (s) {
|
||||
ret = s;
|
||||
@ -413,11 +258,11 @@ IXML_Element *CUPnPLib::Element_GetFirstChildByTag(
|
||||
}
|
||||
|
||||
IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(element);
|
||||
IXML_Node *child = m_ixmlNode_getFirstChild(node);
|
||||
const DOMString childTag = m_ixmlNode_getNodeName(child);
|
||||
IXML_Node *child = ixmlNode_getFirstChild(node);
|
||||
const DOMString childTag = ixmlNode_getNodeName(child);
|
||||
while(child && childTag && strcmp(tag, childTag)) {
|
||||
child = m_ixmlNode_getNextSibling(child);
|
||||
childTag = m_ixmlNode_getNodeName(child);
|
||||
child = ixmlNode_getNextSibling(child);
|
||||
childTag = ixmlNode_getNodeName(child);
|
||||
}
|
||||
|
||||
return REINTERPRET_CAST(IXML_Element *)(child);
|
||||
@ -438,8 +283,8 @@ IXML_Element *CUPnPLib::Element_GetNextSiblingByTag(
|
||||
IXML_Node *child = REINTERPRET_CAST(IXML_Node *)(element);
|
||||
const DOMString childTag = NULL;
|
||||
do {
|
||||
child = m_ixmlNode_getNextSibling(child);
|
||||
childTag = m_ixmlNode_getNodeName(child);
|
||||
child = ixmlNode_getNextSibling(child);
|
||||
childTag = ixmlNode_getNodeName(child);
|
||||
} while(child && childTag && strcmp(tag, childTag));
|
||||
|
||||
return REINTERPRET_CAST(IXML_Element *)(child);
|
||||
@ -449,15 +294,15 @@ IXML_Element *CUPnPLib::Element_GetNextSiblingByTag(
|
||||
const std::string CUPnPLib::Element_GetAttributeByTag(
|
||||
IXML_Element *element, const DOMString tag) const
|
||||
{
|
||||
IXML_NamedNodeMap *NamedNodeMap = m_ixmlNode_getAttributes(
|
||||
IXML_NamedNodeMap *NamedNodeMap = ixmlNode_getAttributes(
|
||||
REINTERPRET_CAST(IXML_Node *)(element));
|
||||
IXML_Node *attribute = m_ixmlNamedNodeMap_getNamedItem(NamedNodeMap, tag);
|
||||
const DOMString s = m_ixmlNode_getNodeValue(attribute);
|
||||
const DOMString s = ixmlNode_getNodeValue(attribute);
|
||||
std::string ret;
|
||||
if (s) {
|
||||
ret = s;
|
||||
}
|
||||
m_ixmlNamedNodeMap_free(NamedNodeMap);
|
||||
ixmlNamedNodeMap_free(NamedNodeMap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -603,9 +448,9 @@ m_SCPD(NULL)
|
||||
int errcode;
|
||||
|
||||
char *scpdURL = new char[URLBase.length() + m_SCPDURL.length() + 1];
|
||||
errcode = upnpLib.m_UpnpResolveURL(
|
||||
URLBase.c_str(),
|
||||
m_SCPDURL.c_str(),
|
||||
errcode = UpnpResolveURL(
|
||||
(char*)URLBase.c_str(),
|
||||
(char*)m_SCPDURL.c_str(),
|
||||
scpdURL);
|
||||
if( errcode != UPNP_E_SUCCESS ) {
|
||||
msg << "Error generating scpdURL from " <<
|
||||
@ -618,9 +463,9 @@ m_SCPD(NULL)
|
||||
|
||||
char *controlURL = new char[
|
||||
URLBase.length() + m_controlURL.length() + 1];
|
||||
errcode = upnpLib.m_UpnpResolveURL(
|
||||
URLBase.c_str(),
|
||||
m_controlURL.c_str(),
|
||||
errcode = UpnpResolveURL(
|
||||
(char*)URLBase.c_str(),
|
||||
(char*)m_controlURL.c_str(),
|
||||
controlURL);
|
||||
if( errcode != UPNP_E_SUCCESS ) {
|
||||
msg << "Error generating controlURL from " <<
|
||||
@ -633,9 +478,9 @@ m_SCPD(NULL)
|
||||
|
||||
char *eventURL = new char[
|
||||
URLBase.length() + m_eventSubURL.length() + 1];
|
||||
errcode = upnpLib.m_UpnpResolveURL(
|
||||
URLBase.c_str(),
|
||||
m_eventSubURL.c_str(),
|
||||
errcode = UpnpResolveURL(
|
||||
(char*)URLBase.c_str(),
|
||||
(char*)m_eventSubURL.c_str(),
|
||||
eventURL);
|
||||
if( errcode != UPNP_E_SUCCESS ) {
|
||||
msg << "Error generating eventURL from " <<
|
||||
@ -777,12 +622,12 @@ bool CUPnPService::Execute(
|
||||
IXML_Document *ActionDoc = NULL;
|
||||
if (ArgValue.size()) {
|
||||
for (unsigned int i = 0; i < ArgValue.size(); ++i) {
|
||||
int ret = m_upnpLib.m_UpnpAddToAction(
|
||||
int ret = UpnpAddToAction(
|
||||
&ActionDoc,
|
||||
action.GetName().c_str(),
|
||||
GetServiceType().c_str(),
|
||||
ArgValue[i].GetArgument().c_str(),
|
||||
ArgValue[i].GetValue().c_str());
|
||||
(char*)action.GetName().c_str(),
|
||||
(char*)GetServiceType().c_str(),
|
||||
(char*)ArgValue[i].GetArgument().c_str(),
|
||||
(char*)ArgValue[i].GetValue().c_str());
|
||||
if (ret != UPNP_E_SUCCESS) {
|
||||
m_upnpLib.processUPnPErrorMessage(
|
||||
"m_UpnpAddToAction", ret, NULL, NULL);
|
||||
@ -790,9 +635,9 @@ bool CUPnPService::Execute(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ActionDoc = m_upnpLib.m_UpnpMakeAction(
|
||||
action.GetName().c_str(),
|
||||
GetServiceType().c_str(),
|
||||
ActionDoc = UpnpMakeAction(
|
||||
(char*)action.GetName().c_str(),
|
||||
(char*)GetServiceType().c_str(),
|
||||
0, NULL);
|
||||
if (!ActionDoc) {
|
||||
msg << "Error: m_UpnpMakeAction returned NULL.";
|
||||
@ -800,24 +645,13 @@ bool CUPnPService::Execute(
|
||||
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
|
||||
IXML_Document *RespDoc = NULL;
|
||||
int ret = m_upnpLib.m_UpnpSendAction(
|
||||
int ret = UpnpSendAction(
|
||||
m_UPnPControlPoint.GetUPnPClientHandle(),
|
||||
GetAbsControlURL().c_str(),
|
||||
GetServiceType().c_str(),
|
||||
(char*)GetAbsControlURL().c_str(),
|
||||
(char*)GetServiceType().c_str(),
|
||||
NULL, ActionDoc, &RespDoc);
|
||||
if (ret != UPNP_E_SUCCESS) {
|
||||
m_upnpLib.processUPnPErrorMessage(
|
||||
@ -826,14 +660,14 @@ bool CUPnPService::Execute(
|
||||
m_upnpLib.m_ixmlDocument_free(RespDoc);
|
||||
return false;
|
||||
}
|
||||
m_upnpLib.m_ixmlDocument_free(ActionDoc);
|
||||
ixmlDocument_free(ActionDoc);
|
||||
|
||||
// Check the response document
|
||||
m_upnpLib.ProcessActionResponse(
|
||||
RespDoc, action.GetName());
|
||||
|
||||
// Free the response document
|
||||
m_upnpLib.m_ixmlDocument_free(RespDoc);
|
||||
ixmlDocument_free(RespDoc);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -844,10 +678,10 @@ const std::string CUPnPService::GetStateVariable(
|
||||
{
|
||||
std::ostringstream msg;
|
||||
DOMString StVarVal;
|
||||
int ret = m_upnpLib.m_UpnpGetServiceVarStatus(
|
||||
int ret = UpnpGetServiceVarStatus(
|
||||
m_UPnPControlPoint.GetUPnPClientHandle(),
|
||||
GetAbsControlURL().c_str(),
|
||||
stateVariableName.c_str(),
|
||||
(char*)GetAbsControlURL().c_str(),
|
||||
(char*)stateVariableName.c_str(),
|
||||
&StVarVal);
|
||||
if (ret != UPNP_E_SUCCESS) {
|
||||
msg << "GetStateVariable(\"" <<
|
||||
@ -893,9 +727,9 @@ m_presentationURL (upnpLib.Element_GetChildValueByTag(device, "presentationURL"
|
||||
int presURLlen = strlen(URLBase.c_str()) +
|
||||
strlen(m_presentationURL.c_str()) + 2;
|
||||
char presURL[presURLlen];
|
||||
int errcode = upnpLib.m_UpnpResolveURL(
|
||||
URLBase.c_str(),
|
||||
m_presentationURL.c_str(),
|
||||
int errcode = UpnpResolveURL(
|
||||
(char*)URLBase.c_str(),
|
||||
(char*)m_presentationURL.c_str(),
|
||||
presURL);
|
||||
if (errcode != UPNP_E_SUCCESS) {
|
||||
msg << "Error generating presentationURL from " <<
|
||||
@ -973,18 +807,18 @@ m_UPnPPort(udpPort)
|
||||
int ret;
|
||||
char *ipAddress = NULL;
|
||||
unsigned short port = 0;
|
||||
ret = m_upnpLib.m_UpnpInit(ipAddress, udpPort);
|
||||
ret = UpnpInit(ipAddress, udpPort);
|
||||
if (ret != UPNP_E_SUCCESS) {
|
||||
msg << "error(UpnpInit): Error code ";
|
||||
goto error;
|
||||
}
|
||||
port = m_upnpLib.m_UpnpGetServerPort();
|
||||
ipAddress = m_upnpLib.m_UpnpGetServerIpAddress();
|
||||
port = UpnpGetServerPort();
|
||||
ipAddress = UpnpGetServerIpAddress();
|
||||
msg << "bound to " << ipAddress << ":" <<
|
||||
port << ".";
|
||||
qDebug("UPnP: %s", msg.str().c_str());
|
||||
msg.str("");
|
||||
ret = m_upnpLib.m_UpnpRegisterClient(
|
||||
ret = UpnpRegisterClient(
|
||||
static_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback),
|
||||
&m_UPnPClientHandle,
|
||||
&m_UPnPClientHandle);
|
||||
@ -1002,10 +836,10 @@ m_UPnPPort(udpPort)
|
||||
// We should not search twice, because this will produce two
|
||||
// UPNP_DISCOVERY_SEARCH_TIMEOUT events, and we might end with problems
|
||||
// on the mutex.
|
||||
ret = m_upnpLib.m_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 = m_upnpLib.m_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_ROOT_DEVICE.c_str(), NULL);
|
||||
//ret = UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_IGW.c_str(), this);
|
||||
//ret = UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_LAN.c_str(), this);
|
||||
//ret = UpnpSearchAsync(m_UPnPClientHandle, 3, m_upnpLib.UPNP_DEVICE_WAN_CONNECTION.c_str(), this);
|
||||
if (ret != UPNP_E_SUCCESS) {
|
||||
msg << "error(UpnpSearchAsync): Error sending search request: ";
|
||||
goto error;
|
||||
@ -1027,7 +861,7 @@ m_UPnPPort(udpPort)
|
||||
|
||||
// Error processing
|
||||
error:
|
||||
m_upnpLib.m_UpnpFinish();
|
||||
UpnpFinish();
|
||||
msg << ret << ": " << m_upnpLib.GetUPnPErrorMessage(ret) << ".";
|
||||
qDebug("UPnP: %s", msg.str().c_str());
|
||||
}
|
||||
@ -1042,8 +876,8 @@ CUPnPControlPoint::~CUPnPControlPoint()
|
||||
}
|
||||
// Remove all first
|
||||
// RemoveAll();
|
||||
m_upnpLib.m_UpnpUnRegisterClient(m_UPnPClientHandle);
|
||||
m_upnpLib.m_UpnpFinish();
|
||||
UpnpUnRegisterClient(m_UPnPClientHandle);
|
||||
UpnpFinish();
|
||||
}
|
||||
|
||||
|
||||
@ -1148,7 +982,7 @@ bool CUPnPControlPoint::PrivateAddPortMapping(
|
||||
CUPnPPortMapping &upnpPortMapping)
|
||||
{
|
||||
// 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
|
||||
std::string actionName("AddPortMapping");
|
||||
@ -1301,7 +1135,7 @@ upnpDiscovery:
|
||||
qDebug("UPnP: %s", msg.str().c_str());
|
||||
}
|
||||
// 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) {
|
||||
msg << "Error retrieving device description from " <<
|
||||
d_event->Location << ": " <<
|
||||
@ -1369,7 +1203,6 @@ upnpDiscovery:
|
||||
}
|
||||
std::string devType = dab_event->DeviceType;
|
||||
// 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()) {
|
||||
upnpCP->RemoveRootDevice(dab_event->DeviceId);
|
||||
}
|
||||
@ -1419,7 +1252,7 @@ upnpEventSubscriptionExpired:
|
||||
(struct Upnp_Event_Subscribe *)Event;
|
||||
Upnp_SID newSID;
|
||||
int TimeOut = 1801;
|
||||
int ret = upnpCP->m_upnpLib.m_UpnpSubscribe(
|
||||
int ret = UpnpSubscribe(
|
||||
upnpCP->m_UPnPClientHandle,
|
||||
es_event->PublisherUrl,
|
||||
&TimeOut,
|
||||
@ -1605,7 +1438,7 @@ void CUPnPControlPoint::RemoveRootDevice(const char *udn)
|
||||
void CUPnPControlPoint::Subscribe(CUPnPService &service)
|
||||
{
|
||||
std::ostringstream msg;
|
||||
int errcode = m_upnpLib.m_UpnpSubscribe(m_UPnPClientHandle,
|
||||
int errcode = UpnpSubscribe(m_UPnPClientHandle,
|
||||
service.GetAbsEventSubURL().c_str(),
|
||||
service.GetTimeoutAddr(),
|
||||
service.GetSID());
|
||||
@ -1617,7 +1450,7 @@ void CUPnPControlPoint::Subscribe(CUPnPService &service)
|
||||
qDebug("UPnP: %s", msg.str().c_str());
|
||||
|
||||
IXML_Document *scpdDoc = NULL;
|
||||
errcode = m_upnpLib.m_UpnpDownloadXmlDoc(
|
||||
errcode = UpnpDownloadXmlDoc(
|
||||
service.GetAbsSCPDURL().c_str(), &scpdDoc);
|
||||
if (errcode == UPNP_E_SUCCESS) {
|
||||
// Get the root node
|
||||
@ -1652,7 +1485,7 @@ void CUPnPControlPoint::Unsubscribe(CUPnPService &service)
|
||||
{
|
||||
ServiceMap::iterator it = m_ServiceMap.find(service.GetAbsEventSubURL());
|
||||
m_ServiceMap.erase(it);
|
||||
m_upnpLib.m_UpnpUnSubscribe(m_UPnPClientHandle, service.GetSID());
|
||||
UpnpUnSubscribe(m_UPnPClientHandle, service.GetSID());
|
||||
}
|
||||
|
||||
|
||||
|
65
src/UPnP.h
65
src/UPnP.h
@ -35,6 +35,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include <upnp/upnp.h>
|
||||
#include <upnp/upnptools.h>
|
||||
#include <upnp/ixml.h>
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
@ -84,22 +86,6 @@ public:
|
||||
{ return m_key; }
|
||||
};
|
||||
|
||||
|
||||
class CDynamicLibHandle
|
||||
{
|
||||
private:
|
||||
std::string m_libname;
|
||||
void *const m_LibraryHandle;
|
||||
CDynamicLibHandle(const CDynamicLibHandle &);
|
||||
CDynamicLibHandle &operator=(const CDynamicLibHandle &);
|
||||
|
||||
public:
|
||||
CDynamicLibHandle(const char *libname);
|
||||
~CDynamicLibHandle();
|
||||
void *Get() const { return m_LibraryHandle; }
|
||||
};
|
||||
|
||||
|
||||
class CUPnPControlPoint;
|
||||
|
||||
|
||||
@ -117,15 +103,6 @@ public:
|
||||
static const std::string &UPNP_SERVICE_WAN_PPP_CONNECTION;
|
||||
CUPnPControlPoint &m_ctrlPoint;
|
||||
|
||||
private:
|
||||
// dlopen stuff
|
||||
static const int NUM_LIB_IXML_SYMBOLS = 8;
|
||||
static const char *s_LibIXMLSymbols[NUM_LIB_IXML_SYMBOLS];
|
||||
static const int NUM_LIB_UPNP_SYMBOLS = 17;
|
||||
static const char *s_LibUPnPSymbols[NUM_LIB_UPNP_SYMBOLS];
|
||||
CDynamicLibHandle m_LibIXMLHandle;
|
||||
CDynamicLibHandle m_LibUPnPHandle;
|
||||
|
||||
public:
|
||||
CUPnPLib(CUPnPControlPoint &ctrlPoint);
|
||||
~CUPnPLib() {}
|
||||
@ -181,44 +158,6 @@ public:
|
||||
IXML_Node *(*m_ixmlNamedNodeMap_getNamedItem)(
|
||||
IXML_NamedNodeMap *nnMap, const DOMString name);
|
||||
void (*m_ixmlNamedNodeMap_free)(IXML_NamedNodeMap *nnMap);
|
||||
|
||||
// upnp api
|
||||
// 1 - Initialization and Registration
|
||||
int (*m_UpnpInit)(const char *IPAddress, int Port);
|
||||
void (*m_UpnpFinish)();
|
||||
unsigned short (*m_UpnpGetServerPort)();
|
||||
char *(*m_UpnpGetServerIpAddress)();
|
||||
int (*m_UpnpRegisterClient)(Upnp_FunPtr Callback,
|
||||
const void *Cookie, UpnpClient_Handle *Hnd);
|
||||
int (*m_UpnpUnRegisterClient)(UpnpClient_Handle Hnd);
|
||||
// 2 - Discovery
|
||||
int (*m_UpnpSearchAsync)(UpnpClient_Handle Hnd, int Mx,
|
||||
const char *Target, const void *Cookie);
|
||||
// 3 - Control
|
||||
int (*m_UpnpGetServiceVarStatus)(UpnpClient_Handle Hnd, const char *ActionURL,
|
||||
const char *VarName, DOMString *StVarVal);
|
||||
int (*m_UpnpSendAction)(UpnpClient_Handle Hnd, const char *ActionURL,
|
||||
const char *ServiceType, const char *DevUDN, IXML_Document *Action,
|
||||
IXML_Document **RespNode);
|
||||
int (*m_UpnpSendActionAsync)(UpnpClient_Handle Hnd, const char *ActionURL,
|
||||
const char *ServiceType, const char *DevUDN, IXML_Document *Action,
|
||||
Upnp_FunPtr Callback, const void *Cookie);
|
||||
// 4 - Eventing
|
||||
int (*m_UpnpSubscribe)(UpnpClient_Handle Hnd,
|
||||
const char *PublisherUrl, int *TimeOut, Upnp_SID SubsId);
|
||||
int (*m_UpnpUnSubscribe)(UpnpClient_Handle Hnd, Upnp_SID SubsId);
|
||||
// 5 - HTTP
|
||||
int (*m_UpnpDownloadXmlDoc)(const char *url, IXML_Document **xmlDoc);
|
||||
// 6 - Optional Tools API
|
||||
int (*m_UpnpResolveURL)(const char *BaseURL,
|
||||
const char *RelURL, char *AbsURL);
|
||||
IXML_Document *(*m_UpnpMakeAction)(
|
||||
const char *ActionName, const char *ServType, int NumArg,
|
||||
const char *Arg, ...);
|
||||
int (*m_UpnpAddToAction)(
|
||||
IXML_Document **ActionDoc, const char *ActionName,
|
||||
const char *ServType, const char *ArgName, const char *ArgVal);
|
||||
const char *(*m_UpnpGetErrorMessage)(int ErrorCode);
|
||||
};
|
||||
|
||||
|
||||
|
@ -27,8 +27,7 @@ contains(DEBUG_MODE, 0){
|
||||
|
||||
QMAKE_CXXFLAGS_RELEASE += -fwrapv
|
||||
QMAKE_CXXFLAGS_DEBUG += -fwrapv
|
||||
#LIBS += -lcurl
|
||||
LIBS += -lupnp
|
||||
#LIBS += -lcurl -lupnp
|
||||
#CONFIG += link_pkgconfig
|
||||
#PKGCONFIG += libtorrent
|
||||
QT += network
|
||||
|
Loading…
Reference in New Issue
Block a user