Fix compilation with libupnp-1.8.x

This commit is contained in:
Gioacchino Mazzurco 2019-04-24 23:36:40 +02:00
parent 3c5ac8b6e6
commit 650c5f1fa8
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
14 changed files with 255 additions and 217 deletions

View File

@ -31,8 +31,8 @@ define_default_value SQLITE_SOURCE_SHA256 da9a1484423d524d3ac793af518cdf870c8255
define_default_value SQLCIPHER_SOURCE_VERSION "3.4.2" define_default_value SQLCIPHER_SOURCE_VERSION "3.4.2"
define_default_value SQLCIPHER_SOURCE_SHA256 69897a5167f34e8a84c7069f1b283aba88cdfa8ec183165c4a5da2c816cfaadb define_default_value SQLCIPHER_SOURCE_SHA256 69897a5167f34e8a84c7069f1b283aba88cdfa8ec183165c4a5da2c816cfaadb
define_default_value LIBUPNP_SOURCE_VERSION "1.6.25" define_default_value LIBUPNP_SOURCE_VERSION "1.8.4"
define_default_value LIBUPNP_SOURCE_SHA256 c5a300b86775435c076d58a79cc0d5a977d76027d2a7d721590729b7f369fa43 define_default_value LIBUPNP_SOURCE_SHA256 976c3e4555604cdd8391ed2f359c08c9dead3b6bf131c24ce78e64d6669af2ed
define_default_value INSTALL_QT_ANDROID "false" define_default_value INSTALL_QT_ANDROID "false"
define_default_value QT_VERSION "5.12.0" define_default_value QT_VERSION "5.12.0"
@ -297,19 +297,23 @@ build_sqlcipher()
build_libupnp() build_libupnp()
{ {
B_dir="libupnp-${LIBUPNP_SOURCE_VERSION}" B_dir="pupnp-release-${LIBUPNP_SOURCE_VERSION}"
B_ext=".tar.gz"
B_file="${B_dir}${B_ext}"
rm -rf $B_dir rm -rf $B_dir
verified_download $B_dir.tar.bz2 $LIBUPNP_SOURCE_SHA256 \ verified_download $B_file $LIBUPNP_SOURCE_SHA256 \
https://sourceforge.net/projects/pupnp/files/pupnp/libUPnP%20${LIBUPNP_SOURCE_VERSION}/$B_dir.tar.bz2 https://github.com/mrjimenez/pupnp/archive/release-${LIBUPNP_SOURCE_VERSION}${B_ext}
tar -xf $B_dir.tar.bz2 tar -xf $B_file
cd $B_dir cd $B_dir
./bootstrap
## liupnp must be configured as static library because if not the linker will ## liupnp must be configured as static library because if not the linker will
## look for libthreadutils.so.6 at runtime that cannot be packaged on android ## look for libthreadutils.so.6 at runtime that cannot be packaged on android
## as it supports only libname.so format for libraries, thus resulting in a ## as it supports only libname.so format for libraries, thus resulting in a
## crash at startup. ## crash at startup.
./configure --enable-static --disable-shared --disable-samples \ ./configure --enable-static --disable-shared --disable-samples \
--disable-largefile \
--prefix="${PREFIX}" --host=${ANDROID_NDK_ARCH}-linux --prefix="${PREFIX}" --host=${ANDROID_NDK_ARCH}-linux
make -j${HOST_NUM_CPU} make -j${HOST_NUM_CPU}
make install make install

View File

@ -651,16 +651,14 @@ SOURCES += util/folderiterator.cc \
util/rsurl.cc util/rsurl.cc
equals(RS_UPNP_LIB, miniupnpc) { equals(RS_UPNP_LIB, miniupnpc) {
HEADERS += upnp/upnputil.h upnp/upnphandler_miniupnp.h HEADERS += rs_upnp/upnputil.h rs_upnp/upnphandler_miniupnp.h
SOURCES += upnp/upnputil.c upnp/upnphandler_miniupnp.cc SOURCES += rs_upnp/upnputil.c rs_upnp/upnphandler_miniupnp.cc
} }
equals(RS_UPNP_LIB, "upnp ixml") { ## libupnp-1.8.x
# Not supported yet contains(RS_UPNP_LIB, upnp) {
} HEADERS += rs_upnp/upnp18_retrocompat.h
equals(RS_UPNP_LIB, "upnp ixml threadutil") { ## libupnp-1.6.x HEADERS += rs_upnp/UPnPBase.h rs_upnp/upnphandler_linux.h
HEADERS += upnp/UPnPBase.h upnp/upnphandler_linux.h SOURCES += rs_upnp/UPnPBase.cpp rs_upnp/upnphandler_linux.cc
SOURCES += upnp/UPnPBase.cpp upnp/upnphandler_linux.cc
DEFINES *= RS_USE_LIBUPNP
} }
# new gxs cache system # new gxs cache system

View File

@ -6,6 +6,7 @@
* Copyright (c) 2004-2009 Marcelo Roberto Jimenez ( phoenix@amule.org ) * * Copyright (c) 2004-2009 Marcelo Roberto Jimenez ( phoenix@amule.org ) *
* Copyright (c) 2006-2009 aMule Team ( admin@amule.org / http://www.amule.org)* * Copyright (c) 2006-2009 aMule Team ( admin@amule.org / http://www.amule.org)*
* Copyright (c) 2009-2010 Retroshare Team * * Copyright (c) 2009-2010 Retroshare Team *
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -25,12 +26,14 @@
#define UPNP_C #define UPNP_C
#include "UPnPBase.h" #include "UPnPBase.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sstream> // for std::istringstream #include <sstream> // for std::istringstream
#include <algorithm> // For transform() #include <algorithm> // For transform()
#include "util/rsstring.h" #include "util/rsstring.h"
#include "rs_upnp/upnp18_retrocompat.h"
#ifdef __GNUC__ #ifdef __GNUC__
#if __GNUC__ >= 4 #if __GNUC__ >= 4
@ -115,7 +118,7 @@ std::string CUPnPLib::processUPnPErrorMessage(
const std::string &message, const std::string &message,
int errorCode, int errorCode,
const DOMString errorString, const DOMString errorString,
IXML_Document *doc) const const IXML_Document* doc) const
{ {
/* remove unused parameter warnings */ /* remove unused parameter warnings */
(void) message; (void) message;
@ -159,7 +162,7 @@ std::string CUPnPLib::processUPnPErrorMessage(
void CUPnPLib::ProcessActionResponse( void CUPnPLib::ProcessActionResponse(
IXML_Document *RespDoc, const IXML_Document* RespDoc,
const std::string &actionName) const const std::string &actionName) const
{ {
/* remove unused parameter warnings */ /* remove unused parameter warnings */
@ -196,11 +199,11 @@ void CUPnPLib::ProcessActionResponse(
* \brief Returns the root node of a given document. * \brief Returns the root node of a given document.
*/ */
IXML_Element *CUPnPLib::Element_GetRootElement( IXML_Element *CUPnPLib::Element_GetRootElement(
IXML_Document *doc) const const IXML_Document* doc) const
{ {
IXML_Element *root = REINTERPRET_CAST(IXML_Element *)( IXML_Element* root = REINTERPRET_CAST(IXML_Element *)(
ixmlNode_getFirstChild( ixmlNode_getFirstChild(
REINTERPRET_CAST(IXML_Node *)(doc))); REINTERPRET_CAST(IXML_Node *)(const_cast<IXML_Document*>(doc))));
return root; return root;
} }
@ -748,7 +751,7 @@ bool CUPnPService::Execute(
GetAbsControlURL().c_str(), GetAbsControlURL().c_str(),
GetServiceType().c_str(), GetServiceType().c_str(),
NULL, ActionDoc, NULL, ActionDoc,
static_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback), reinterpret_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback),
NULL); NULL);
return true; return true;
} }
@ -948,7 +951,7 @@ m_WanService(NULL)
#endif #endif
ret = UpnpRegisterClient( ret = UpnpRegisterClient(
static_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback), reinterpret_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback),
&m_UPnPClientHandle, &m_UPnPClientHandle,
&m_UPnPClientHandle); &m_UPnPClientHandle);
if (ret != UPNP_E_SUCCESS) { if (ret != UPNP_E_SUCCESS) {
@ -1295,61 +1298,31 @@ bool CUPnPControlPoint::PrivateGetExternalIpAdress()
// This function is static // This function is static
int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /*Cookie*/) int CUPnPControlPoint::Callback(
Upnp_EventType EventType, const void* Event, void * /*Cookie*/ )
{ {
if(!Event) return 0;
std::string msg; std::string msg;
std::string msg2; std::string msg2;
// Somehow, this is unreliable. UPNP_DISCOVERY_ADVERTISEMENT_ALIVE events
// happen with a wrong cookie and... boom!
// CUPnPControlPoint *upnpCP = static_cast<CUPnPControlPoint *>(Cookie);
CUPnPControlPoint *upnpCP = CUPnPControlPoint::s_CtrlPoint ;
if (upnpCP == NULL) CUPnPControlPoint* upnpCP = CUPnPControlPoint::s_CtrlPoint;
return 0; if (!upnpCP) return 0;
switch (EventType)
{
case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: /*fallthrough*/
case UPNP_DISCOVERY_SEARCH_RESULT:
{
const UpnpDiscovery* d_event = static_cast<const UpnpDiscovery*>(Event);
//fprintf(stderr, "Callback: %d, Cookie: %p\n", EventType, Cookie);
switch (EventType) {
case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
#ifdef UPNP_DEBUG
std::cerr << "CUPnPControlPoint::Callback() UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: ";
#endif
goto upnpDiscovery;
case UPNP_DISCOVERY_SEARCH_RESULT: {
#ifdef UPNP_DEBUG
std::cerr << "UPNP_DISCOVERY_SEARCH_RESULT: ";
#endif
// UPnP Discovery
upnpDiscovery:
struct Upnp_Discovery *d_event = (struct Upnp_Discovery *)Event;
IXML_Document *doc = NULL;
int ret;
if (d_event->ErrCode != UPNP_E_SUCCESS) {
#ifdef UPNP_DEBUG
std::cerr << upnpCP->m_upnpLib.GetUPnPErrorMessage(d_event->ErrCode) << "." << std::endl;
#endif
}
#ifdef UPNP_DEBUG
std::cerr << "CUPnPControlPoint::Callback() URetrieving device description from " <<
d_event->Location << "." << std::endl;
#endif
// Get the XML tree device description in doc // Get the XML tree device description in doc
ret = UpnpDownloadXmlDoc(d_event->Location, &doc); IXML_Document* doc = nullptr;
if (ret != UPNP_E_SUCCESS) { UpnpDownloadXmlDoc(UpnpDiscovery_get_Location_cstr(d_event), &doc);
#ifdef UPNP_DEBUG if (!doc) break;
std::cerr << "CUPnPControlPoint::Callback() UError retrieving device description from " <<
d_event->Location << ": " << IXML_Element* root = upnpCP->m_upnpLib.Element_GetRootElement(doc);
upnpCP->m_upnpLib.GetUPnPErrorMessage(ret) << ".";
#endif
} else {
#ifdef UPNP_DEBUG
std::cerr << "CUPnPControlPoint::Callback() URetrieving device description from " <<
d_event->Location << "." << std::endl;
#endif
}
if (doc) {
// Get the root node
IXML_Element *root =
upnpCP->m_upnpLib.Element_GetRootElement(doc);
// Extract the URLBase // Extract the URLBase
const std::string urlBase = upnpCP->m_upnpLib. const std::string urlBase = upnpCP->m_upnpLib.
Element_GetChildValueByTag(root, "URLBase"); Element_GetChildValueByTag(root, "URLBase");
@ -1359,8 +1332,10 @@ upnpDiscovery:
// Extract the deviceType // Extract the deviceType
std::string devType(upnpCP->m_upnpLib. std::string devType(upnpCP->m_upnpLib.
Element_GetChildValueByTag(rootDevice, "deviceType")); Element_GetChildValueByTag(rootDevice, "deviceType"));
// Only add device if it is an InternetGatewayDevice // Only add device if it is an InternetGatewayDevice
if (stdStringIsEqualCI(devType, upnpCP->m_upnpLib.UPNP_DEVICE_IGW)) { if (stdStringIsEqualCI(devType, upnpCP->m_upnpLib.UPNP_DEVICE_IGW))
{
// This condition can be used to auto-detect // This condition can be used to auto-detect
// the UPnP device we are interested in. // the UPnP device we are interested in.
// Obs.: Don't block the entry here on this // Obs.: Don't block the entry here on this
@ -1371,109 +1346,84 @@ upnpDiscovery:
// Log it if not UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, // Log it if not UPNP_DISCOVERY_ADVERTISEMENT_ALIVE,
// we don't want to spam our logs. // we don't want to spam our logs.
//if (EventType != UPNP_DISCOVERY_ADVERTISEMENT_ALIVE) { //if (EventType != UPNP_DISCOVERY_ADVERTISEMENT_ALIVE) {
#ifdef UPNP_DEBUG
std::cerr << "Internet Gateway Device Detected." << std::endl;
#endif
//}
#ifdef UPNP_DEBUG
std::cerr << "CUPnPControlPoint::Callback() UGetting root device desc." << std::endl;
#endif
// Add the root device to our list // Add the root device to our list
upnpCP->AddRootDevice(rootDevice, urlBase, upnpCP->AddRootDevice(
d_event->Location, d_event->Expires); rootDevice, urlBase,
#ifdef UPNP_DEBUG UpnpDiscovery_get_Location_cstr(d_event),
std::cerr << "CUPnPControlPoint::Callback() UFinishing getting root device desc." << std::endl; UpnpDiscovery_get_Expires(d_event) );
#endif
} }
// Free the XML doc tree // Free the XML doc tree
ixmlDocument_free(doc); ixmlDocument_free(doc);
}
break; break;
} }
case UPNP_DISCOVERY_SEARCH_TIMEOUT: { case UPNP_DISCOVERY_SEARCH_TIMEOUT:
//fprintf(stderr, "Callback: UPNP_DISCOVERY_SEARCH_TIMEOUT\n"); {
// Search timeout
#ifdef UPNP_DEBUG
std::cerr << "CUPnPControlPoint::Callback() UUPNP_DISCOVERY_SEARCH_TIMEOUT : unlocking mutex." << std::endl;
#endif
// Unlock the search timeout mutex // Unlock the search timeout mutex
upnpCP->m_WaitForSearchTimeoutMutex.unlock(); upnpCP->m_WaitForSearchTimeoutMutex.unlock();
break; break;
} }
case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: { case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: // UPnP Device Removed
//fprintf(stderr, "Callback: UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE\n"); {
// UPnP Device Removed const UpnpDiscovery* dab_event = static_cast<const UpnpDiscovery*>(Event);
struct Upnp_Discovery *dab_event = (struct Upnp_Discovery *)Event; if(!dab_event) break;
if (dab_event->ErrCode != UPNP_E_SUCCESS) {
#ifdef UPNP_DEBUG std::string devType = UpnpDiscovery_get_DeviceType_cstr(dab_event);
std::cerr << "CUPnPControlPoint::Callback() Uerror(UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE): " <<
upnpCP->m_upnpLib.GetUPnPErrorMessage(dab_event->ErrCode) <<
"." << std::endl;
#endif
}
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
std::transform(devType.begin(), devType.end(), devType.begin(), tolower); std::transform(devType.begin(), devType.end(), devType.begin(), tolower);
if (stdStringIsEqualCI(devType, upnpCP->m_upnpLib.UPNP_DEVICE_IGW)) { if (stdStringIsEqualCI(devType, upnpCP->m_upnpLib.UPNP_DEVICE_IGW))
upnpCP->RemoveRootDevice(dab_event->DeviceId); upnpCP->RemoveRootDevice(
} UpnpDiscovery_get_DeviceID_cstr(dab_event) );
break; break;
} }
case UPNP_EVENT_RECEIVED: { case UPNP_EVENT_RECEIVED:
#ifdef UPNP_DEBUG {
fprintf(stderr, "Callback: UPNP_EVENT_RECEIVED\n");
#endif
// Event reveived // Event reveived
struct Upnp_Event *e_event = (struct Upnp_Event *)Event; const UpnpEvent* e_event = static_cast<const UpnpEvent*>(Event);
const std::string Sid = e_event->Sid;
const std::string Sid = UpnpEvent_get_SID_cstr(e_event);
// Parses the event // Parses the event
upnpCP->OnEventReceived(Sid, e_event->EventKey, e_event->ChangedVariables); upnpCP->OnEventReceived( Sid,
UpnpEvent_get_EventKey(e_event),
UpnpEvent_get_ChangedVariables(e_event) );
break; break;
} }
case UPNP_EVENT_SUBSCRIBE_COMPLETE: case UPNP_EVENT_SUBSCRIBE_COMPLETE:
//fprintf(stderr, "Callback: UPNP_EVENT_SUBSCRIBE_COMPLETE\n");
msg += "error(UPNP_EVENT_SUBSCRIBE_COMPLETE): "; msg += "error(UPNP_EVENT_SUBSCRIBE_COMPLETE): ";
goto upnpEventRenewalComplete; goto upnpEventRenewalComplete;
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
//fprintf(stderr, "Callback: UPNP_EVENT_UNSUBSCRIBE_COMPLETE\n");
msg += "error(UPNP_EVENT_UNSUBSCRIBE_COMPLETE): "; msg += "error(UPNP_EVENT_UNSUBSCRIBE_COMPLETE): ";
goto upnpEventRenewalComplete; goto upnpEventRenewalComplete;
case UPNP_EVENT_RENEWAL_COMPLETE: { case UPNP_EVENT_RENEWAL_COMPLETE:
//fprintf(stderr, "Callback: UPNP_EVENT_RENEWAL_COMPLETE\n"); {
msg += "error(UPNP_EVENT_RENEWAL_COMPLETE): "; msg += "error(UPNP_EVENT_RENEWAL_COMPLETE): ";
upnpEventRenewalComplete: upnpEventRenewalComplete:
struct Upnp_Event_Subscribe *es_event = const UpnpEventSubscribe* es_event =
(struct Upnp_Event_Subscribe *)Event; static_cast<const UpnpEventSubscribe*>(Event);
if (es_event->ErrCode != UPNP_E_SUCCESS) {
if (UpnpEventSubscribe_get_ErrCode(es_event) != UPNP_E_SUCCESS)
{
msg += "Error in Event Subscribe Callback"; msg += "Error in Event Subscribe Callback";
upnpCP->m_upnpLib.processUPnPErrorMessage( upnpCP->m_upnpLib.processUPnPErrorMessage(
msg, es_event->ErrCode, NULL, NULL); msg, UpnpEventSubscribe_get_ErrCode(es_event),
} else { nullptr, nullptr );
#if 0
TvCtrlPointHandleSubscribeUpdate(
es_event->PublisherUrl,
es_event->Sid,
es_event->TimeOut );
#endif
} }
break; break;
} }
case UPNP_EVENT_AUTORENEWAL_FAILED: case UPNP_EVENT_AUTORENEWAL_FAILED:
//fprintf(stderr, "Callback: UPNP_EVENT_AUTORENEWAL_FAILED\n");
msg += "CUPnPControlPoint::Callback() error(UPNP_EVENT_AUTORENEWAL_FAILED): "; msg += "CUPnPControlPoint::Callback() error(UPNP_EVENT_AUTORENEWAL_FAILED): ";
msg2 += "UPNP_EVENT_AUTORENEWAL_FAILED: "; msg2 += "UPNP_EVENT_AUTORENEWAL_FAILED: ";
goto upnpEventSubscriptionExpired; goto upnpEventSubscriptionExpired;
case UPNP_EVENT_SUBSCRIPTION_EXPIRED: { case UPNP_EVENT_SUBSCRIPTION_EXPIRED: {
//fprintf(stderr, "Callback: UPNP_EVENT_SUBSCRIPTION_EXPIRED\n");
msg += "CUPnPControlPoint::Callback() error(UPNP_EVENT_SUBSCRIPTION_EXPIRED): "; msg += "CUPnPControlPoint::Callback() error(UPNP_EVENT_SUBSCRIPTION_EXPIRED): ";
msg2 += "UPNP_EVENT_SUBSCRIPTION_EXPIRED: "; msg2 += "UPNP_EVENT_SUBSCRIPTION_EXPIRED: ";
upnpEventSubscriptionExpired: upnpEventSubscriptionExpired:
struct Upnp_Event_Subscribe *es_event = const UpnpEventSubscribe* es_event =
(struct Upnp_Event_Subscribe *)Event; static_cast<const UpnpEventSubscribe*>(Event);
Upnp_SID newSID; Upnp_SID newSID;
int TimeOut = 1801; int TimeOut = 1801;
int ret = UpnpSubscribe( int ret = UpnpSubscribe(
@ -1481,20 +1431,25 @@ upnpEventSubscriptionExpired:
#ifdef PATCHED_LIBUPNP #ifdef PATCHED_LIBUPNP
UpnpString_get_String(es_event->PublisherUrl), UpnpString_get_String(es_event->PublisherUrl),
#else #else
es_event->PublisherUrl, UpnpEventSubscribe_get_PublisherUrl_cstr(es_event),
#endif #endif
&TimeOut, &TimeOut,
newSID); newSID);
if (ret != UPNP_E_SUCCESS) { if (ret != UPNP_E_SUCCESS)
{
msg += "Error Subscribing to EventURL"; msg += "Error Subscribing to EventURL";
upnpCP->m_upnpLib.processUPnPErrorMessage( upnpCP->m_upnpLib.processUPnPErrorMessage(
msg, es_event->ErrCode, NULL, NULL); msg, UpnpEventSubscribe_get_ErrCode(es_event),
} else { nullptr, nullptr );
}
else
{
ServiceMap::iterator it = ServiceMap::iterator it =
#ifdef PATCHED_LIBUPNP #ifdef PATCHED_LIBUPNP
upnpCP->m_ServiceMap.find(UpnpString_get_String(es_event->PublisherUrl)); upnpCP->m_ServiceMap.find(UpnpString_get_String(es_event->PublisherUrl));
#else #else
upnpCP->m_ServiceMap.find(es_event->PublisherUrl); upnpCP->m_ServiceMap.find(
UpnpEventSubscribe_get_PublisherUrl_cstr(es_event) );
#endif #endif
if (it != upnpCP->m_ServiceMap.end()) { if (it != upnpCP->m_ServiceMap.end()) {
CUPnPService &service = *(it->second); CUPnPService &service = *(it->second);
@ -1504,7 +1459,7 @@ upnpEventSubscriptionExpired:
#ifdef PATCHED_LIBUPNP #ifdef PATCHED_LIBUPNP
UpnpString_get_String(es_event->PublisherUrl) << UpnpString_get_String(es_event->PublisherUrl) <<
#else #else
es_event->PublisherUrl << UpnpEventSubscribe_get_PublisherUrl_cstr(es_event) <<
#endif #endif
"' with SID == '" << "' with SID == '" <<
newSID << "'." << std::endl; newSID << "'." << std::endl;
@ -1512,7 +1467,9 @@ upnpEventSubscriptionExpired:
// service is the same. But here we only have one // service is the same. But here we only have one
// service, so... // service, so...
upnpCP->RefreshPortMappings(); upnpCP->RefreshPortMappings();
} else { }
else
{
#ifdef UPNP_DEBUG #ifdef UPNP_DEBUG
std::cerr << "CUPnPControlPoint::Callback() Error: did not find service " << std::cerr << "CUPnPControlPoint::Callback() Error: did not find service " <<
newSID << " in the service map." << std::endl; newSID << " in the service map." << std::endl;
@ -1521,41 +1478,49 @@ upnpEventSubscriptionExpired:
} }
break; break;
} }
case UPNP_CONTROL_ACTION_COMPLETE: { case UPNP_CONTROL_ACTION_COMPLETE:
//fprintf(stderr, "Callback: UPNP_CONTROL_ACTION_COMPLETE\n"); {
// This is here if we choose to do this asynchronously // This is here if we choose to do this asynchronously
struct Upnp_Action_Complete *a_event = const UpnpActionComplete* a_event =
(struct Upnp_Action_Complete *)Event; static_cast<const UpnpActionComplete*>(Event);
if (a_event->ErrCode != UPNP_E_SUCCESS) { if(UpnpActionComplete_get_ErrCode(a_event) != UPNP_E_SUCCESS)
{
upnpCP->m_upnpLib.processUPnPErrorMessage( upnpCP->m_upnpLib.processUPnPErrorMessage(
"UpnpSendActionAsync", "UpnpSendActionAsync",
a_event->ErrCode, NULL, UpnpActionComplete_get_ErrCode(a_event), nullptr,
a_event->ActionResult); UpnpActionComplete_get_ActionResult(a_event) );
} else { }
else
{
// Check the response document // Check the response document
upnpCP->m_upnpLib.ProcessActionResponse( upnpCP->m_upnpLib.ProcessActionResponse(
a_event->ActionResult, UpnpActionComplete_get_ActionResult(a_event),
"<UpnpSendActionAsync>"); "<UpnpSendActionAsync>" );
} }
/* No need for any processing here, just print out results. /* No need for any processing here, just print out results.
* Service state table updates are handled by events. * Service state table updates are handled by events.
*/ */
break; break;
} }
case UPNP_CONTROL_GET_VAR_COMPLETE: { case UPNP_CONTROL_GET_VAR_COMPLETE:
#ifdef UPNP_DEBUG {
fprintf(stderr, "CUPnPControlPoint::Callback() Callback: UPNP_CONTROL_GET_VAR_COMPLETE\n");
#endif
msg += "CUPnPControlPoint::Callback() error(UPNP_CONTROL_GET_VAR_COMPLETE): "; msg += "CUPnPControlPoint::Callback() error(UPNP_CONTROL_GET_VAR_COMPLETE): ";
struct Upnp_State_Var_Complete *sv_event = const UpnpStateVarComplete* sv_event =
(struct Upnp_State_Var_Complete *)Event; static_cast<const UpnpStateVarComplete*>(Event);
if (sv_event->ErrCode != UPNP_E_SUCCESS) { if (UpnpStateVarComplete_get_ErrCode(sv_event) != UPNP_E_SUCCESS)
{
msg += "m_UpnpGetServiceVarStatusAsync"; msg += "m_UpnpGetServiceVarStatusAsync";
upnpCP->m_upnpLib.processUPnPErrorMessage( upnpCP->m_upnpLib.processUPnPErrorMessage(
msg, sv_event->ErrCode, NULL, NULL); msg, UpnpStateVarComplete_get_ErrCode(sv_event),
} else { nullptr, nullptr );
}
else
{
//add the variable to the wanservice property map //add the variable to the wanservice property map
(upnpCP->m_WanService->propertyMap)[std::string(sv_event->StateVarName)] = std::string(sv_event->CurrentVal); (upnpCP->m_WanService->propertyMap)[
std::string(
UpnpStateVarComplete_get_StateVarName_cstr(sv_event) ) ]
= std::string(UpnpStateVarComplete_get_CurrentVal_cstr(sv_event));
} }
break; break;
} }
@ -1603,7 +1568,7 @@ eventSubscriptionRequest:
void CUPnPControlPoint::OnEventReceived( void CUPnPControlPoint::OnEventReceived(
const std::string &Sid, const std::string &Sid,
int EventKey, int EventKey,
IXML_Document *ChangedVariablesDoc) const IXML_Document* ChangedVariablesDoc)
{ {
/* remove unused parameter warnings */ /* remove unused parameter warnings */
(void) EventKey; (void) EventKey;

View File

@ -113,20 +113,18 @@ public:
// Convenience function to avoid repetitive processing of error // Convenience function to avoid repetitive processing of error
// messages // messages
std::string processUPnPErrorMessage( std::string processUPnPErrorMessage(const std::string &messsage,
const std::string &messsage,
int code, int code,
const DOMString errorString, const DOMString errorString,
IXML_Document *doc) const; const IXML_Document* doc) const;
// Processing response to actions // Processing response to actions
void ProcessActionResponse( void ProcessActionResponse(
IXML_Document *RespDoc, const IXML_Document* RespDoc,
const std::string &actionName) const; const std::string& actionName ) const;
// IXML_Element // IXML_Element
IXML_Element *Element_GetRootElement( IXML_Element* Element_GetRootElement(const IXML_Document* doc) const;
IXML_Document *doc) const;
IXML_Element *Element_GetFirstChild( IXML_Element *Element_GetFirstChild(
IXML_Element *parent) const; IXML_Element *parent) const;
IXML_Element *Element_GetNextSibling( IXML_Element *Element_GetNextSibling(
@ -597,13 +595,10 @@ public:
// Callback function // Callback function
static int Callback( static int Callback(
Upnp_EventType EventType, Upnp_EventType EventType, const void* Event, void* Cookie );
void* Event, void OnEventReceived(const std::string &Sid,
void* Cookie);
void OnEventReceived(
const std::string &Sid,
int EventKey, int EventKey,
IXML_Document *ChangedVariables); const IXML_Document* ChangedVariables);
private: private:
void AddRootDevice( void AddRootDevice(

View File

@ -0,0 +1,82 @@
/*******************************************************************************
* libupnp-1.8.x -> libupnp-1.6.x retrocompatibility header *
* *
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#pragma once
#include "upnp/upnp.h"
#if UPNP_VERSION < 10800
using UpnpDiscovery = Upnp_Discovery;
using UpnpEvent = Upnp_Event;
using UpnpEventSubscribe = Upnp_Event_Subscribe;
using UpnpActionComplete = Upnp_Action_Complete;
using UpnpStateVarComplete = Upnp_State_Var_Complete;
#endif // UPNP_VERSION < 10800
#if UPNP_VERSION < 10624
static inline int UpnpDiscovery_get_Expires(const Upnp_Discovery* disc) noexcept
{ return disc->Expires; }
static inline const char* UpnpDiscovery_get_DeviceID_cstr(
const Upnp_Discovery* disc ) noexcept
{ return disc->DeviceId; }
static inline const char* UpnpDiscovery_get_DeviceType_cstr(
const Upnp_Discovery* disc ) noexcept
{ return disc->DeviceType; }
static inline const char* UpnpDiscovery_get_Location_cstr(
const Upnp_Discovery* disc ) noexcept
{ return disc->Location; }
static inline const char* UpnpEvent_get_SID_cstr(const UpnpEvent* ev) noexcept
{ return ev->Sid; }
static inline int UpnpEvent_get_EventKey(const UpnpEvent* ev) noexcept
{ return ev->EventKey; }
static inline const IXML_Document* UpnpEvent_get_ChangedVariables(
const UpnpEvent* ev) noexcept { return ev->ChangedVariables; }
static inline int UpnpEventSubscribe_get_ErrCode(const UpnpEventSubscribe* evs)
noexcept { return evs->ErrCode; }
static inline const char* UpnpEventSubscribe_get_PublisherUrl_cstr(
const UpnpEventSubscribe* evs ) noexcept { return evs->PublisherUrl; }
static inline int UpnpActionComplete_get_ErrCode(const UpnpActionComplete* evc)
noexcept { return evc->ErrCode; }
static inline const IXML_Document* UpnpActionComplete_get_ActionResult(
const UpnpActionComplete* evc ) noexcept { return evc->ActionResult; }
static inline int UpnpStateVarComplete_get_ErrCode(
const UpnpStateVarComplete* esvc) noexcept { return esvc->ErrCode; }
static inline const char* UpnpStateVarComplete_get_StateVarName_cstr(
const UpnpStateVarComplete* esvc) noexcept { return esvc->StateVarName; }
static inline const char* UpnpStateVarComplete_get_CurrentVal_cstr(
const UpnpStateVarComplete* esvc) noexcept { return esvc->CurrentVal; }
#endif // UPNP_VERSION < 10624

View File

@ -28,7 +28,7 @@ extern "C" {
#endif #endif
/* This stuff is actually C */ /* This stuff is actually C */
#include "upnp/upnphandler_linux.h" #include "rs_upnp/upnphandler_linux.h"
#include "util/rsnet.h" #include "util/rsnet.h"

View File

@ -31,7 +31,7 @@
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include <upnp/upnp.h> #include <upnp/upnp.h>
#include "upnp/UPnPBase.h" #include "rs_upnp/UPnPBase.h"
#define RS_UPNP_S_UNINITIALISED 0 #define RS_UPNP_S_UNINITIALISED 0
#define RS_UPNP_S_UNAVAILABLE 1 #define RS_UPNP_S_UNAVAILABLE 1

View File

@ -734,9 +734,9 @@ RsGRouter *rsGRouter = NULL ;
#include "util/rsrandom.h" #include "util/rsrandom.h"
#ifdef RS_USE_LIBUPNP #ifdef RS_USE_LIBUPNP
# include "upnp/upnphandler_linux.h" # include "rs_upnp/upnphandler_linux.h"
#else // def RS_USE_LIBUPNP #else // def RS_USE_LIBUPNP
# include "upnp/upnphandler_miniupnp.h" # include "rs_upnp/upnphandler_miniupnp.h"
#endif // def RS_USE_LIBUPNP #endif // def RS_USE_LIBUPNP
#include "services/autoproxy/p3i2pbob.h" #include "services/autoproxy/p3i2pbob.h"

View File

@ -723,10 +723,6 @@ isEmpty(RS_UPNP_LIB) {
!isEmpty(attemptPath):RS_UPNP_LIB += $${mLib} !isEmpty(attemptPath):RS_UPNP_LIB += $${mLib}
} }
## Workaround as libupnp-1.8.x is not supported yet
equals(RS_UPNP_LIB, "upnp ixml"):RS_UPNP_LIB=
## END Workaround as libupnp-1.8.x is not supported yet
isEmpty(RS_UPNP_LIB) { isEmpty(RS_UPNP_LIB) {
__TEMP_UPNP_LIBS=$$findFileInPath(libminiupnpc.a, QMAKE_LIBDIR) __TEMP_UPNP_LIBS=$$findFileInPath(libminiupnpc.a, QMAKE_LIBDIR)
!isEmpty(__TEMP_UPNP_LIBS):RS_UPNP_LIB=miniupnpc !isEmpty(__TEMP_UPNP_LIBS):RS_UPNP_LIB=miniupnpc
@ -743,9 +739,7 @@ isEmpty(RS_UPNP_LIB) {
equals(RS_UPNP_LIB, none):RS_UPNP_LIB= equals(RS_UPNP_LIB, none):RS_UPNP_LIB=
equals(RS_UPNP_LIB, miniupnpc):DEFINES*=RS_USE_LIBMINIUPNPC equals(RS_UPNP_LIB, miniupnpc):DEFINES*=RS_USE_LIBMINIUPNPC
equals(RS_UPNP_LIB, "upnp ixml"):DEFINES*=RS_USE_LIBUPNP_1_8_X contains(RS_UPNP_LIB, upnp):DEFINES*=RS_USE_LIBUPNP
## libupnp-1.6.x
equals(RS_UPNP_LIB, "upnp ixml threadutil"):DEFINES*=RS_USE_LIBUPNP
## Retrocompatibility assignations, get rid of this ASAP ## Retrocompatibility assignations, get rid of this ASAP