From 01f7abfc6385884251cc57fa615a065f82d274df Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 26 Jan 2014 13:53:03 +0100 Subject: upnp: move library initialization to Init.cxx Allow calling UpnpGlobalInit() multiple times. --- src/lib/upnp/upnpplib.cxx | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'src/lib/upnp/upnpplib.cxx') diff --git a/src/lib/upnp/upnpplib.cxx b/src/lib/upnp/upnpplib.cxx index 452c033d5..d36fc3593 100644 --- a/src/lib/upnp/upnpplib.cxx +++ b/src/lib/upnp/upnpplib.cxx @@ -21,33 +21,24 @@ #include "upnpplib.hxx" #include "Callback.hxx" #include "Domain.hxx" +#include "Init.hxx" #include "Log.hxx" -#include #include LibUPnP::LibUPnP() { - auto code = UpnpInit(0, 0); - if (code != UPNP_E_SUCCESS) { - init_error.Format(upnp_domain, code, - "UpnpInit() failed: %s", - UpnpGetErrorMessage(code)); + if (!UpnpGlobalInit(init_error)) return; - } - - UpnpSetMaxContentLength(2000*1024); - code = UpnpRegisterClient(o_callback, nullptr, &m_clh); + auto code = UpnpRegisterClient(o_callback, nullptr, &m_clh); if (code != UPNP_E_SUCCESS) { + UpnpGlobalFinish(); init_error.Format(upnp_domain, code, "UpnpRegisterClient() failed: %s", UpnpGetErrorMessage(code)); return; } - - // Servers sometimes make error (e.g.: minidlna returns bad utf-8) - ixmlRelaxParser(1); } int @@ -65,8 +56,5 @@ LibUPnP::o_callback(Upnp_EventType et, void* evp, void* cookie) LibUPnP::~LibUPnP() { - int error = UpnpFinish(); - if (error != UPNP_E_SUCCESS) - FormatError(upnp_domain, "UpnpFinish() failed: %s", - UpnpGetErrorMessage(error)); + UpnpGlobalFinish(); } -- cgit v1.2.3