Commit 60515d89 authored by Eden Abitbol's avatar Eden Abitbol

upnp: support libupnp and libnatnatpmp simultaneously

Update libupnp to version 1.8.4.

For windows, the IPV6 preprocessor must be undefined. Or else
libupnp won't initialize. Added visual studio 2017 support
via one patch for windows that also combines previous windows
patches.

UPnPController: Class that the jami classes use to control the
opening and closing of ports. Every  service has it's own upnp
controller. The controller does it's actions by using the upnp
context class. Also refactored the functions used to add
mappings. Instead of using two different functions with
different types of parameters, we now use one function with
parameters that have default values. The logic stays the same
but the function call is more clear.

UPnPContext: Class that holds a (linked) list of discovered IGDs
and their corresponding protocols (which discovered them).
Whenever the controller wants to add or remove a mapping, the
context picks a valid IGD in it's list and uses the correct
protocol to complete the required action. This class also has
the ability to swap protocols for an IGD that was discovered
by more then one protocol.

UPnPProtocol: Virtual base class that defines the functions
needed by the context to use the corresponding protocol.

PUPnP: UPnPProtocol derived class that represents a upnp client
that uses the portable upnp library (libupnp). Every time the
client discovers a new IGD it uses a callback to add it to the
context's main IGD linked list. It also has an internal list of
IGDs that it discovered. Added features to this class include:
	- IGD event subscription.
	- Use UpnpInit2 function instead of deprecated UpnpInit
	  function. It's also supposed to support IPv6.

NatPmp: UPnPProtocol derived class that represents a upnp client
that uses the NAT-PMP library (libnatpmp). Unlike libupnp,
libnatpmp only supports discovering one IGD. Also uses callbacks
to add the IGD it finds to the context's main IGD class.

Also inclided debug warning prints whenever a controller opens
and closes the ports. That way we can keep track of whenever
the application opens and closes ports on the internet
gateway device.

Gitlab: #96

Change-Id: I199271edac2c6d93dc60c24e2e2aefe36de7950c
parent 3e2c8637
This diff is collapsed.
......@@ -62,6 +62,12 @@
<Filter Include="Source Files\media\video\winvideo">
<UniqueIdentifier>{96b01e7f-7e05-480c-85a3-fa35ef5f8b87}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\upnp\protocol">
<UniqueIdentifier>{13d62143-0c05-410a-bc32-8748a87deaa9}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\upnp\protocol\pupnp">
<UniqueIdentifier>{a75d6869-9eb3-4cdd-8006-08b5ee5e6050}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\hooks\urlhook.cpp">
......@@ -175,15 +181,6 @@
<ClCompile Include="..\src\jamidht\sips_transport_ice.cpp">
<Filter>Source Files\jamidht</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\upnp_context.cpp">
<Filter>Source Files\upnp</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\upnp_control.cpp">
<Filter>Source Files\upnp</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\upnp_igd.cpp">
<Filter>Source Files\upnp</Filter>
</ClCompile>
<ClCompile Include="..\src\sip\sdes_negotiator.cpp">
<Filter>Source Files\sip</Filter>
</ClCompile>
......@@ -328,9 +325,6 @@
<ClCompile Include="..\src\string_utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\thread_pool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\threadloop.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -409,6 +403,24 @@
<ClCompile Include="..\src\media\video\accel.cpp">
<Filter>Source Files\media\video</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\upnp_context.cpp">
<Filter>Source Files\upnp</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\upnp_control.cpp">
<Filter>Source Files\upnp</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\protocol\igd.cpp">
<Filter>Source Files\upnp\protocol</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\protocol\mapping.cpp">
<Filter>Source Files\upnp\protocol</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\protocol\pupnp\pupnp.cpp">
<Filter>Source Files\upnp\protocol\pupnp</Filter>
</ClCompile>
<ClCompile Include="..\src\upnp\protocol\pupnp\upnp_igd.cpp">
<Filter>Source Files\upnp\protocol\pupnp</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\account.h">
......@@ -507,9 +519,6 @@
<ClInclude Include="..\src\string_utils.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\thread_pool.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\threadloop.h">
<Filter>Source Files</Filter>
</ClInclude>
......@@ -606,9 +615,6 @@
<ClInclude Include="..\src\jamidht\p2p.h">
<Filter>Source Files\jamidht</Filter>
</ClInclude>
<ClInclude Include="..\src\jamidht\jamiaccount.h">
<Filter>Source Files\jamidht</Filter>
</ClInclude>
<ClInclude Include="..\src\jamidht\ringcontact.h">
<Filter>Source Files\jamidht</Filter>
</ClInclude>
......@@ -792,15 +798,6 @@
<ClInclude Include="..\src\sip\sipvoiplink.h">
<Filter>Source Files\sip</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\upnp_context.h">
<Filter>Source Files\upnp</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\upnp_control.h">
<Filter>Source Files\upnp</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\upnp_igd.h">
<Filter>Source Files\upnp</Filter>
</ClInclude>
<ClInclude Include="..\src\media\media_filter.h">
<Filter>Source Files\media</Filter>
</ClInclude>
......@@ -843,10 +840,37 @@
<ClInclude Include="..\src\media\video\accel.h">
<Filter>Source Files\media\video</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\upnp_context.h">
<Filter>Source Files\upnp</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\upnp_control.h">
<Filter>Source Files\upnp</Filter>
</ClInclude>
<ClInclude Include="..\src\jamidht\jamiaccount.h">
<Filter>Source Files\jamidht</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\protocol\global_mapping.h">
<Filter>Source Files\upnp\protocol</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\protocol\igd.h">
<Filter>Source Files\upnp\protocol</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\protocol\mapping.h">
<Filter>Source Files\upnp\protocol</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\protocol\upnp_protocol.h">
<Filter>Source Files\upnp\protocol</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\protocol\pupnp\pupnp.h">
<Filter>Source Files\upnp\protocol\pupnp</Filter>
</ClInclude>
<ClInclude Include="..\src\upnp\protocol\pupnp\upnp_igd.h">
<Filter>Source Files\upnp\protocol\pupnp</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\src\jamidht\eth\libdevcore\Makefile.am">
<Filter>Source Files\jamidht\eth\libdevcore</Filter>
</None>
</ItemGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -566,6 +566,7 @@ AS_IF([test "x$with_upnp" = "xyes"],
[AC_MSG_WARN([Missing libupnp development files])
AC_DEFINE([HAVE_LIBUPNP], 0, [Define if you have libupnp])])
])
AM_CONDITIONAL([BUILD_PUPNP], test "x$with_upnp" = "xyes")
# LIBNATPMP
dnl check for libnatpmp
......@@ -580,6 +581,7 @@ AS_IF([test "x$with_natpmp" != xno],
],[])
AC_DEFINE_UNQUOTED([HAVE_LIBNATPMP], `if test "x$with_natpmp" != xno; then echo 1; else echo 0; fi`, [Define if you have libnatpmp])
AM_CONDITIONAL([BUILD_NATPMP], test "x$with_natpmp" = "xyes")
AC_DEFINE_UNQUOTED([HAVE_SHM], `if test -z "${HAVE_LINUX_TRUE}" && test -z "${HAVE_ANDROID_FALSE}" ; then echo 1; else echo 0; fi`,
[Define if you have shared memory support])
......@@ -632,6 +634,9 @@ AC_CONFIG_FILES([Makefile \
src/media/video/winvideo/Makefile \
src/security/Makefile \
src/upnp/Makefile \
src/upnp/protocol/Makefile \
src/upnp/protocol/natpmp/Makefile \
src/upnp/protocol/pupnp/Makefile \
ringtones/Makefile \
test/Makefile\
test/sip/Makefile
......
......@@ -68,9 +68,8 @@ msgpack=build\msgpack-c\vs2017\msgpackc-static.vcxproj, ^
opendht=build\opendht\MSVC\opendht.vcxproj, ^
pjproject=pjproject, ^
pthreads=build\pthreads\MSVC\pthreads.vcxproj, ^
xml=build\libupnp\build\vs2017\ixml.vcxproj, ^
threadutil=build\libupnp\build\vs2017\threadutil.vcxproj, ^
upnp=build\libupnp\build\vs2017\libupnp.vcxproj, ^
xml=build\pupnp\build\vs2017\ixml.vcxproj, ^
upnp=build\pupnp\build\vs2017\libupnp.vcxproj, ^
secp256k1=build\secp256k1\MSVC\secp256k1.vcxproj, ^
portaudio=build\portaudio\msvc\portaudio.vcxproj, ^
yaml-cpp=build\yaml-cpp\msvc\yaml-cpp.vcxproj, ^
......@@ -95,9 +94,8 @@ msgpack=build\msgpack-c\vs2017\msgpackc-static.vcxproj, ^
opendht=build\opendht\MSVC\opendht.vcxproj, ^
pjproject=pjproject, ^
pthreads=build\pthreads\MSVC\pthreads.vcxproj, ^
xml=build\libupnp\build\vs2017\ixml.vcxproj, ^
threadutil=build\libupnp\build\vs2017\threadutil.vcxproj, ^
upnp=build\libupnp\build\vs2017\libupnp.vcxproj, ^
xml=build\pupnp\build\vs2017\ixml.vcxproj, ^
upnp=build\pupnp\build\vs2017\libupnp.vcxproj, ^
secp256k1=build\secp256k1\MSVC\secp256k1.vcxproj, ^
portaudio=build\portaudio\msvc\portaudio.vcxproj, ^
yaml-cpp=build\yaml-cpp\msvc\yaml-cpp.vcxproj
......
0c44356cd466c72baa9a15a45bc601d3d88a5c1efea79495e07581d93edfeaf3d6e47a301a51e3fa54a776945e0d6b65a67998c480e918a535eeb80d18b05fa9 pupnp-release-1.6.25.tar.gz
6d96dc0dcf187a425f3b60f4e750102331bd0a5bd452007e345eeacb63e9287ac213574c8071294809283ff8d8795433706ed2a14bae3d451605bf7a75e5a5bb pupnp-release-1.8.4.tar.gz
set BUILD=%SRC%..\build
set UPNP_VERSION=1.6.25
set UPNP_VERSION=1.8.4
set UPNP_URL=https://github.com/mrjimenez/pupnp/archive/release-%UPNP_VERSION%.tar.gz
mkdir %BUILD%
......@@ -13,11 +13,10 @@ if %USE_CACHE%==1 (
7z -y x release-%UPNP_VERSION%.tar.gz && 7z -y x release-%UPNP_VERSION%.tar -o%BUILD%
del release-%UPNP_VERSION%.tar && del release-%UPNP_VERSION%.tar.gz && del %BUILD%\pax_global_header
rename %BUILD%\pupnp-release-%UPNP_VERSION% libupnp
rename %BUILD%\pupnp-release-%UPNP_VERSION% pupnp
cd %BUILD%\libupnp
cd %BUILD%\pupnp
%APPLY_CMD% %SRC%\upnp\libupnp-windows.patch
%APPLY_CMD% %SRC%\upnp\libupnp-vs2017.patch
cd %SRC%
\ No newline at end of file
cd %SRC%
......@@ -15,7 +15,7 @@ index af310ca..1ae422f 100644
@@ -68,6 +68,13 @@
/*! . */
#define APPLICATION_LISTENING_PORT 49152
+/* IPV6_V6ONLY is missing from MinGW, hack taken from
+ * http://svn.apache.org/repos/asf/apr/apr/trunk/network_io/win32/sockopt.c
+ */
......@@ -33,7 +33,7 @@ index 231c2c5..6a9c27f 100644
@@ -69,6 +69,13 @@
#endif /* UPNP_ENABLE_IPV6 */
#endif /* INCLUDE_CLIENT_APIS */
+/* IPV6_V6ONLY is missing from MinGW, hack taken from
+ * http://svn.apache.org/repos/asf/apr/apr/trunk/network_io/win32/sockopt.c
+ */
......@@ -42,8 +42,8 @@ index 231c2c5..6a9c27f 100644
+#endif
+
void RequestHandler();
enum Listener {
--
--
1.7.9.7
This diff is collapsed.
From 1e14f51854a54e0aea7186b7408f2f74621ab4df Mon Sep 17 00:00:00 2001
From: fner <fner@yetanotherthinkpad>
Date: Thu, 24 May 2018 11:20:33 -0400
Subject: [PATCH] b
---
configure.ac | 1 +
libupnp.pc.in | 2 +-
upnp/inc/UpnpInet.h | 5 -----
upnp/src/inc/upnputil.h | 2 +-
4 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
index bcf2395..335a516 100644
--- a/configure.ac
+++ b/configure.ac
@@ -559,6 +559,7 @@ fi
RT_BOOL_ARG_ENABLE([samples], [yes], [compilation of upnp/sample/ code])
+AC_DEFINE([_WIN32_WINNT], 0x0501, [Define to '0x0500' for Windows 2000 APIs.])
#
# doc installation
# autoconf >= 2.60 already defines ${docdir}, but we will not use its
diff --git a/libupnp.pc.in b/libupnp.pc.in
index c649c24..f46f774 100644
--- a/libupnp.pc.in
+++ b/libupnp.pc.in
@@ -6,6 +6,6 @@ includedir=@includedir@
Name: libupnp
Description: Linux SDK for UPnP Devices
Version: @VERSION@
-Libs: @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ -L${libdir} -lupnp -lthreadutil -lixml
+Libs: @PTHREAD_CFLAGS@ -L${libdir} -lupnp -lthreadutil -lixml -liphlpapi @PTHREAD_LIBS@
Cflags: -I${includedir}/upnp
diff --git a/upnp/inc/UpnpInet.h b/upnp/inc/UpnpInet.h
index ad00a7d..14f87f7 100644
--- a/upnp/inc/UpnpInet.h
+++ b/upnp/inc/UpnpInet.h
@@ -15,11 +15,6 @@
#ifdef WIN32
#include <stdarg.h>
- #ifndef UPNP_USE_MSVCPP
- /* Removed: not required (and cause compilation issues) */
- #include <winbase.h>
- #include <windef.h>
- #endif
#include <winsock2.h>
#include <iphlpapi.h>
#include <ws2tcpip.h>
diff --git a/upnp/src/inc/upnputil.h b/upnp/src/inc/upnputil.h
index 76292f8..ed922e1 100644
--- a/upnp/src/inc/upnputil.h
+++ b/upnp/src/inc/upnputil.h
@@ -130,7 +130,7 @@ void linecopylen(
#define strncasecmp strnicmp
#define sleep(a) Sleep((a)*1000)
#define usleep(a) Sleep((a)/1000)
- #define strerror_r(a,b,c) (strerror_s((b),(c),(a)))
+ #define strerror_r(a,b,c) strncpy( b, strerror(a), c)
#else
#define max(a, b) (((a)>(b))? (a):(b))
#define min(a, b) (((a)<(b))? (a):(b))
--
2.14.3
--- libupnp/threadutil/inc/ThreadPool.h 2011-01-20 07:46:57.000000000 +0100
+++ libupnp.new/threadutil/inc/ThreadPool.h 2011-09-23 01:36:12.000000000 +0200
@@ -45,6 +45,7 @@
#include <errno.h>
#ifdef WIN32
+ #ifndef _TIMEZONE_DEFINED
#include <time.h>
struct timezone
{
@@ -52,6 +53,7 @@
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
+ #endif
#else /* WIN32 */
#include <sys/param.h>
#include <sys/time.h> /* for gettimeofday() */
--- libupnp-1.6.16/upnp/inc/upnp.h.orig 2012-03-22 00:15:38.000000000 +0100
+++ libupnp-1.6.16/upnp/inc/upnp.h 2012-03-28 18:58:55.043642000 +0200
@@ -61,6 +61,20 @@
/* Other systems ??? */
#endif
+# if defined( __MINGW32__ )
+# if !defined( _OFF_T_ )
+ typedef long long _off_t;
+ typedef _off_t off_t;
+# define _OFF_T_
+# else
+# ifdef off_t
+# undef off_t
+# endif
+# define off_t long long
+# endif
+# endif
+
+
#define LINE_SIZE (size_t)180
#define NAME_SIZE (size_t)256
#define MNFT_NAME_SIZE 64
This diff is collapsed.
--- upnp/upnp/src/api/upnpapi.c.orig 2013-04-08 00:23:46.000000000 +0200
+++ upnp/upnp/src/api/upnpapi.c 2013-04-08 00:25:49.000000000 +0200
@@ -358,13 +358,13 @@
From 39f8e5f5379607166cf6e54d270590e1fd13c12f Mon Sep 17 00:00:00 2001
From: Eden Abitbol <eden.abitbol@savoirfairelinux.com>
Date: Mon, 3 Jun 2019 15:55:40 -0400
Subject: [PATCH] web server patch
---
upnp/src/api/upnpapi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/upnp/src/api/upnpapi.c b/upnp/src/api/upnpapi.c
index 9ddc7fb..d286092 100644
--- a/upnp/src/api/upnpapi.c
+++ b/upnp/src/api/upnpapi.c
@@ -383,13 +383,13 @@ static int UpnpInitPreamble(void)
return retVal;
}
+#ifdef INTERNAL_WEB_SERVER
#ifdef INCLUDE_DEVICE_APIS
#if EXCLUDE_SOAP == 0
SetSoapCallback(soap_device_callback);
#endif
#endif /* INCLUDE_DEVICE_APIS */
-#ifdef INTERNAL_WEB_SERVER
#if EXCLUDE_GENA == 0
SetGenaCallback(genaCallback);
#endif
--
2.17.1
# UPNP
UPNP_VERSION := 1.6.25
UPNP_VERSION := 1.8.4
UPNP_URL := https://github.com/mrjimenez/pupnp/archive/release-$(UPNP_VERSION).tar.gz
PKGS += upnp
ifeq ($(call need_pkg,"libupnp >= 1.6.25"),)
ifeq ($(call need_pkg,"libupnp >= 1.8.2"),)
PKGS_FOUND += upnp
endif
......@@ -14,27 +14,21 @@ $(TARBALLS)/pupnp-release-$(UPNP_VERSION).tar.gz:
upnp: pupnp-release-$(UPNP_VERSION).tar.gz .sum-upnp
$(UNPACK)
ifdef HAVE_WIN32
$(APPLY) $(SRC)/upnp/libupnp-win32.patch
$(APPLY) $(SRC)/upnp/libupnp-win64.patch
$(APPLY) $(SRC)/upnp/threadpool.patch
endif
ifdef HAVE_WIN64
$(APPLY) $(SRC)/upnp/win_inet_pton.patch
ifeq ($(OS),Windows_NT)
$(APPLY) $(SRC)/upnp/libupnp-windows.patch
endif
$(APPLY) $(SRC)/upnp/libupnp-ipv6.patch
$(APPLY) $(SRC)/upnp/miniserver.patch
$(APPLY) $(SRC)/upnp/uuid_upnp.patch
$(UPDATE_AUTOCONFIG) && cd $(UNPACK_DIR) && mv config.guess config.sub
$(MOVE)
.upnp: upnp
ifdef HAVE_WIN32
$(RECONF)
cd $< && $(HOSTVARS) CFLAGS="-DUPNP_STATIC_LIB" ./configure --disable-samples --without-documentation --disable-blocking_tcp_connections $(HOSTCONF)
cd $< && $(HOSTVARS) CFLAGS="-DUPNP_STATIC_LIB" ./configure --disable-largefile --disable-samples --without-documentation --disable-blocking_tcp_connections $(HOSTCONF)
else
$(RECONF)
cd $< && $(HOSTVARS) CFLAGS="$(CFLAGS) -DUPNP_STATIC_LIB" ./configure --disable-samples --without-documentation --disable-blocking_tcp_connections $(HOSTCONF)
cd $< && $(HOSTVARS) CFLAGS="$(CFLAGS) -DUPNP_STATIC_LIB" ./configure --disable-largefile --disable-samples --without-documentation --disable-blocking_tcp_connections $(HOSTCONF)
endif
cd $< && $(MAKE) install
touch $@
--- a/threadutil/src/ThreadPool.c 2012-04-03 09:01:15.000000000 -0400
+++ b/threadutil/src/ThreadPool.c 2015-05-07 14:37:13.168494069 -0400
@@ -264,7 +264,7 @@
setpriority(PRIO_PROCESS, 0, 0);
retVal = 0;
#elif defined(WIN32)
From 1da6fe09a3387d31c111e5d26c98653e39bf1d46 Mon Sep 17 00:00:00 2001
From: Eden Abitbol <eden.abitbol@savoirfairelinux.com>
Date: Mon, 3 Jun 2019 17:48:04 -0400
Subject: [PATCH] threadpool patch
---
upnp/src/threadutil/ThreadPool.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/upnp/src/threadutil/ThreadPool.c b/upnp/src/threadutil/ThreadPool.c
index 2441d38..6de4d3d 100644
--- a/upnp/src/threadutil/ThreadPool.c
+++ b/upnp/src/threadutil/ThreadPool.c
@@ -264,7 +264,7 @@ static int SetPolicyType(
setpriority(PRIO_PROCESS, 0, 0);
retVal = 0;
#elif defined(_WIN32)
- retVal = sched_setscheduler(0, in);
+ retVal = 0;
+ retVal = 0
#elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0
struct sched_param current;
int sched_result;
@@ -416,7 +416,7 @@
struct sched_param current;
int sched_result;
@@ -416,7 +416,7 @@ static void SetSeed(void)
gettimeofday(&t, NULL);
#if defined(WIN32)
gettimeofday(&t, NULL);
#if defined(_WIN32)
- srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id().p);
+ srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
#elif defined(BSD) || defined(__OSX__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
#elif defined(__linux__) || defined(__sun) || defined(__CYGWIN__) || defined(__GLIBC__)
@@ -654,7 +654,7 @@
rc = ithread_detach(temp);
/* ithread_detach will return EINVAL if thread has been
successfully detached by ithread_create */
- if (rc == EINVAL)
+ if (rc == EINVAL || rc == ESRCH)
rc = 0;
tp->pendingWorkerThreadStart = 1;
/* wait until the new worker thread starts */
--
2.17.1
diff --git a/upnp/src/api/upnpapi.c b/upnp/src/api/upnpapi.c
index 8f36822..322c724 100644
--- a/upnp/src/api/upnpapi.c
+++ b/upnp/src/api/upnpapi.c
@@ -341,8 +341,8 @@ static int UpnpInitPreamble(void)
#ifdef UPNP_HAVE_OPTSSDP
/* Create the NLS uuid. */
- uuid_create(&nls_uuid);
- uuid_unpack(&nls_uuid, gUpnpSdkNLSuuid);
+ uuid_upnp_create(&nls_uuid);
+ uuid_upnp_unpack(&nls_uuid, gUpnpSdkNLSuuid);
#endif /* UPNP_HAVE_OPTSSDP */
/* Initializes the handle list. */
diff --git a/upnp/src/gena/gena_ctrlpt.c b/upnp/src/gena/gena_ctrlpt.c
index bca4981..0c428fc 100644
--- a/upnp/src/gena/gena_ctrlpt.c
+++ b/upnp/src/gena/gena_ctrlpt.c
@@ -561,8 +561,8 @@ int genaSubscribe(
}
/* generate client SID */
- uuid_create(&uid );
- uuid_unpack(&uid, temp_sid);
+ uuid_upnp_create(&uid );
+ uuid_upnp_unpack(&uid, temp_sid);
rc = snprintf(temp_sid2, sizeof(temp_sid2), "uuid:%s", temp_sid);
if (rc < 0 || (unsigned int) rc >= sizeof(temp_sid2)) {
return_code = UPNP_E_OUTOF_MEMORY;
diff --git a/upnp/src/gena/gena_device.c b/upnp/src/gena/gena_device.c
index 39edc0b..b1ec3c4 100644
--- a/upnp/src/gena/gena_device.c
+++ b/upnp/src/gena/gena_device.c
@@ -1353,8 +1353,8 @@ void gena_process_subscription_request(
}
/* generate SID */
- uuid_create(&uid);
- uuid_unpack(&uid, temp_sid);
+ uuid_upnp_create(&uid);
+ uuid_upnp_unpack(&uid, temp_sid);
rc = snprintf(sub->sid, sizeof(sub->sid), "uuid:%s", temp_sid);
/* respond OK */
diff --git a/upnp/src/inc/uuid.h b/upnp/src/inc/uuid.h
index 93f5681..17fd463 100644
--- a/upnp/src/inc/uuid.h
+++ b/upnp/src/inc/uuid.h
@@ -41,14 +41,14 @@ typedef struct _uuid_upnp {
/*!
* \brief Generate a UUID.
*/
-int uuid_create(
+int uuid_upnp_create(
/*! . */
uuid_upnp * id);
/*!
* \brief Out will be xxxx-xx-xx-xx-xxxxxx format.
*/
-void uuid_unpack(
+void uuid_upnp_unpack(
/*! . */
uuid_upnp * u,
/*! . */
@@ -57,7 +57,7 @@ void uuid_unpack(
/*!
* \brief Create a UUID using a "name" from a "name space"
*/
-void uuid_create_from_name(
+void uuid_upnp_create_from_name(
/*! Resulting UUID. */
uuid_upnp * uid,
/*! UUID to serve as context, so identical names from different name
@@ -78,7 +78,7 @@ void uuid_create_from_name(
*
* \note Lexical ordering is not temporal ordering!
*/
-int uuid_compare(
+int uuid_upnp_compare(
/*! . */
uuid_upnp * u1,
/*! . */
diff --git a/upnp/src/uuid/uuid.c b/upnp/src/uuid/uuid.c
index 211b61f..ecd5904 100644
--- a/upnp/src/uuid/uuid.c
+++ b/upnp/src/uuid/uuid.c
@@ -50,7 +50,7 @@ static uint16_t true_random(void);
/*!
* \brief Generator of a UUID.
*/
-int uuid_create(uuid_upnp * uid)
+int uuid_upnp_create(uuid_upnp * uid)
{
uuid_time_t timestamp;
uuid_time_t last_time;
@@ -82,7 +82,7 @@ int uuid_create(uuid_upnp * uid)
return 1;
};
-void uuid_unpack(uuid_upnp * u, char *out)
+void uuid_upnp_unpack(uuid_upnp * u, char *out)
{
sprintf(out,
"%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
@@ -221,7 +221,7 @@ static uint16_t true_random(void)
/*!
* \brief Create a UUID using a "name" from a "name space".
*/
-void uuid_create_from_name(
+void uuid_upnp_create_from_name(
/*! resulting UUID. */
uuid_upnp *uid,
/*! UUID to serve as context, so identical names from different name
@@ -280,7 +280,7 @@ void format_uuid_v3(uuid_upnp *uid, unsigned char hash[16])
*
* Note: Lexical ordering is not temporal ordering!
*/
-int uuid_compare(uuid_upnp *u1, uuid_upnp *u2)
+int uuid_upnp_compare(uuid_upnp *u1, uuid_upnp *u2)
{
int i;
......@@ -471,11 +471,11 @@ Account::getUPnPIpAddress() const
* ie: if it is able to make port mappings
*/
bool
Account::getUPnPActive(std::chrono::seconds timeout) const
Account::getUPnPActive() const
{
std::lock_guard<std::mutex> lk(upnp_mtx);
if (upnp_)
return upnp_->hasValidIGD(timeout);
return upnp_->hasValidIGD();
return false;
}
......
......@@ -295,7 +295,7 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
* returns whether or not UPnP is enabled and active
* ie: if it is able to make port mappings
*/
bool getUPnPActive(std::chrono::seconds timeout = {}) const;
bool getUPnPActive() const;
/**
* Get the UPnP IP (external router) address.
......
......@@ -825,15 +825,15 @@ IceTransport::Impl::selectUPnPIceCandidates()
auto portType = candidate.transport == PJ_CAND_UDP
? upnp::PortType::UDP
: upnp::PortType::TCP;
if (upnp_->addAnyMapping(port, portType, true, &port_used)) {
if (upnp_->addMapping(port, portType, true, &port_used)) {
publicIP.setPort(port_used);
addReflectiveCandidate(comp_id, candidate.addr, publicIP, candidate.transport);
} else
JAMI_WARN("[ice:%p] UPnP: Could not create a port mapping for the ICE candide", this);
JAMI_WARN("[ice:%p] Could not create a port mapping for the ICE candide", this);
}
}
} else {
JAMI_WARN("[ice:%p] UPnP: Could not determine public IP for ICE candidates", this);
JAMI_WARN("[ice:%p] Could not determine public IP for ICE candidates", this);
}
}
}
......
......@@ -2024,10 +2024,10 @@ JamiAccount::mapPortUPnP()
uint16_t port_used;
std::lock_guard<std::mutex> lock(upnp_mtx);
upnp_->removeMappings();
added = upnp_->addAnyMapping(dhtPort_, jami::upnp::PortType::UDP, false, &port_used);
added = upnp_->addMapping(dhtPort_, jami::upnp::PortType::UDP, false, &port_used);
if (added) {
if (port_used != dhtPort_)
JAMI_DBG("UPnP could not map port %u for DHT, using %u instead", dhtPort_, port_used);
JAMI_WARN("[Account %s] Could not map port %u for DHT, using %u instead.", getAccountID().c_str(), dhtPort_, port_used);
dhtPortUsed_ = port_used;
}
}
......
......@@ -705,10 +705,10 @@ bool SIPAccount::mapPortUPnP()
* a different port, if succesfull, then we have to use that port for SIP
*/
uint16_t port_used;
bool added = upnp_->addAnyMapping(publishedPort_, localPort_, jami::upnp::PortType::UDP, false, false, &port_used);
bool added = upnp_->addMapping(publishedPort_, jami::upnp::PortType::UDP, false, &port_used, localPort_);
if (added) {
if (port_used != publishedPort_)
JAMI_DBG("UPnP could not map published port %u for SIP, using %u instead", publishedPort_, port_used);
JAMI_WARN("[Account %s] Could not map published port %u for SIP, using %u instead.", getAccountID().c_str(), publishedPort_, port_used);
publishedPortUsed_ = port_used;
}
}
......@@ -740,7 +740,7 @@ void SIPAccount::doRegister()
if (auto acc = w.lock()) {
sip_utils::register_thread();
if (not acc->mapPortUPnP())
JAMI_WARN("UPnP: Could not successfully map SIP port with UPnP, continuing with account registration anyways.");
JAMI_WARN("UPnP: Could not successfully map SIP port with UPnP, continuing with account registration anyways");
acc->doRegister1_();
}
}}.detach();
......
......@@ -1186,17 +1186,17 @@ SIPCall::openPortsUPnP()
*/
JAMI_DBG("[call:%s] opening ports via UPNP for SDP session", getCallId().c_str());
uint16_t audio_port_used;
if (upnp_->addAnyMapping(sdp_->getLocalAudioPort(), upnp::PortType::UDP, true, &audio_port_used)) {
if (upnp_->addMapping(sdp_->getLocalAudioPort(), upnp::PortType::UDP, true, &audio_port_used)) {
uint16_t control_port_used;
if (upnp_->addAnyMapping(sdp_->getLocalAudioControlPort(), upnp::PortType::UDP, true, &control_port_used)) {
if (upnp_->addMapping(sdp_->getLocalAudioControlPort(), upnp::PortType::UDP, true, &control_port_used)) {
sdp_->setLocalPublishedAudioPorts(audio_port_used, control_port_used);
}
}
#ifdef ENABLE_VIDEO
uint16_t video_port_used;
if (upnp_->addAnyMapping(sdp_->getLocalVideoPort(), upnp::PortType::UDP, true, &video_port_used)) {
if (upnp_->addMapping(sdp_->getLocalVideoPort(), upnp::PortType::UDP, true, &video_port_used)) {
uint16_t control_port_used;
if (upnp_->addAnyMapping(sdp_->getLocalVideoControlPort(), upnp::PortType::UDP, true, &control_port_used)) {
if (upnp_->addMapping(sdp_->getLocalVideoControlPort(), upnp::PortType::UDP, true, &control_port_used)) {
sdp_->setLocalPublishedVideoPorts(video_port_used, control_port_used);
}
}
......
......@@ -2,13 +2,16 @@ include $(top_srcdir)/globals.mk
noinst_LTLIBRARIES = libupnpcontrol.la
SUBDIRS = protocol
libupnpcontrol_la_CXXFLAGS = \
@CXXFLAGS@
@CXXFLAGS@
libupnpcontrol_la_SOURCES = \
upnp_control.cpp \
upnp_control.h \
upnp_context.cpp \
upnp_context.h \
upnp_igd.cpp \
upnp_igd.h
upnp_context.h