Add npupnp support

libnpupnp is a C++ modification of libupnp.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Jean-Francois Dockes
2020-08-23 14:22:21 +02:00
committed by Rosen Penev
parent a7ba10423d
commit e960626804
9 changed files with 166 additions and 13 deletions

View File

@@ -38,6 +38,7 @@ CountNameValuePairs([[maybe_unused]] const char *name, [[maybe_unused]] const ch
return 1 + CountNameValuePairs(args...);
}
#ifdef USING_PUPNP
/**
* A wrapper for UpnpMakeAction() that counts the number of name/value
* pairs and adds the nullptr sentinel.
@@ -52,5 +53,6 @@ MakeActionHelper(const char *action_name, const char *service_type,
args...,
nullptr, nullptr);
}
#endif
#endif

View File

@@ -17,13 +17,21 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "ContentDirectoryService.hxx"
#include "UniqueIxml.hxx"
#include "Device.hxx"
#include "ixmlwrap.hxx"
#include "util/UriRelative.hxx"
#include "util/RuntimeError.hxx"
#include "UniqueIxml.hxx"
#ifdef USING_PUPNP
# include "ixmlwrap.hxx"
#endif
#include "Action.hxx"
#include "util/IterableSplitString.hxx"
#include "util/RuntimeError.hxx"
#include "util/UriRelative.hxx"
#include "util/UriUtil.hxx"
#include <algorithm>
#include <upnptools.h>
@@ -50,6 +58,7 @@ ContentDirectoryService::~ContentDirectoryService() noexcept = default;
std::forward_list<std::string>
ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl) const
{
#ifdef USING_PUPNP
UniqueIxmlDocument request(UpnpMakeAction("GetSearchCapabilities", m_serviceType.c_str(),
0,
nullptr, nullptr));
@@ -68,6 +77,23 @@ ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl) const
const char *s = ixmlwrap::getFirstElementValue(response.get(),
"SearchCaps");
#else
std::vector<std::pair<std::string, std::string>> responseData;
int errcode;
std::string errdesc;
auto code = UpnpSendAction(hdl, "", m_actionURL, m_serviceType,
"GetSearchCapabilities", {}, responseData, &errcode,
errdesc);
if (code != UPNP_E_SUCCESS)
throw FormatRuntimeError("UpnpSendAction() failed: %s",
UpnpGetErrorMessage(code));
const char *s{nullptr};
for (auto &entry : responseData) {
if (entry.first == "SearchCaps") {
s = entry.second.c_str();
}
}
#endif
if (s == nullptr || *s == 0)
return {};

View File

@@ -23,7 +23,9 @@
#include "util/RuntimeError.hxx"
#include <upnptools.h>
#include <ixml.h>
#ifdef USING_PUPNP
# include <ixml.h>
#endif
#include <cassert>
@@ -44,8 +46,10 @@ DoInit()
UpnpSetMaxContentLength(2000*1024);
#ifdef USING_PUPNP
// Servers sometimes make error (e.g.: minidlna returns bad utf-8)
ixmlRelaxParser(1);
#endif
}
void

View File

@@ -20,9 +20,10 @@
#ifndef MPD_UPNP_UNIQUE_XML_HXX
#define MPD_UPNP_UNIQUE_XML_HXX
#include <ixml.h>
#ifdef USING_PUPNP
# include <ixml.h>
#include <memory>
# include <memory>
struct UpnpIxmlDeleter {
void operator()(IXML_Document *doc) noexcept {
@@ -37,4 +38,5 @@ struct UpnpIxmlDeleter {
typedef std::unique_ptr<IXML_Document, UpnpIxmlDeleter> UniqueIxmlDocument;
typedef std::unique_ptr<IXML_NodeList, UpnpIxmlDeleter> UniqueIxmlNodeList;
#endif /* USING_PUPNP */
#endif

View File

@@ -15,8 +15,11 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "ixmlwrap.hxx"
#include "UniqueIxml.hxx"
#include "config.h"
#ifdef USING_PUPNP
# include "ixmlwrap.hxx"
# include "UniqueIxml.hxx"
namespace ixmlwrap {
@@ -39,3 +42,4 @@ getFirstElementValue(IXML_Document *doc, const char *name) noexcept
}
} // namespace ixmlwrap
#endif

View File

@@ -17,7 +17,8 @@
#ifndef _IXMLWRAP_H_INCLUDED_
#define _IXMLWRAP_H_INCLUDED_
#include <ixml.h>
#ifdef USING_PUPNP
# include <ixml.h>
namespace ixmlwrap {
/**
@@ -30,4 +31,5 @@ namespace ixmlwrap {
}
#endif /* USING_PUPNP */
#endif /* _IXMLWRAP_H_INCLUDED_ */

View File

@@ -1,4 +1,22 @@
upnp_dep = dependency('libupnp', version: '>= 1.8', required: get_option('upnp'))
upnp_option = get_option('upnp')
if upnp_option == 'auto'
upnp_dep = dependency('libupnp', version: '>= 1.8', required: false)
conf.set('USING_PUPNP', upnp_dep.found())
if not upnp_dep.found()
upnp_dep = dependency('libnpupnp', version: '>= 1.8', required: false)
endif
elif upnp_option == 'pupnp'
upnp_dep = dependency('libupnp', version: '>= 1.8', required: true)
conf.set('USING_PUPNP', true)
elif upnp_option == 'npupnp'
upnp_dep = dependency('libnpupnp', required: true)
conf.set('USING_PUPNP', false)
elif upnp_option == 'disabled'
upnp_dep = dependency('', required: false)
subdir_done()
endif
conf.set('ENABLE_UPNP', upnp_dep.found())
if not upnp_dep.found()
subdir_done()