aboutsummaryrefslogtreecommitdiff
path: root/net/gerbera/files/patch-git-01-3e2f026f2281aa511f1a9106cf48a1f5344ae06b
blob: 8f3c4e84831fcd8c69dca898e64041117a708f0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
From 3e2f026f2281aa511f1a9106cf48a1f5344ae06b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karl=20Strau=C3=9Fberger?= <k_straussberger@netzland.net>
Date: Tue, 9 Jan 2024 13:12:10 +0100
Subject: [PATCH] Build Support for NPUPNP

---
 .github/workflows/ci.yml            | 23 ++++++++
 CMakeLists.txt                      | 43 ++++++++++++---
 ChangeLog.md                        |  5 ++
 README.md                           |  2 +-
 cmake/FindNPUPNP.cmake              | 54 +++++++++++++++++++
 cmake/FindUPNP.cmake                |  6 +--
 scripts/debian/build-deb.sh         | 33 ++++++++++--
 scripts/install-googletest.sh       |  4 +-
 scripts/install-npupnp.sh           | 83 +++++++++++++++++++++++++++++
 scripts/versions.sh                 |  4 +-
 src/iohandler/process_io_handler.cc |  1 +
 src/server.cc                       |  2 +
 src/server.h                        |  2 +
 13 files changed, 244 insertions(+), 18 deletions(-)
 create mode 100644 cmake/FindNPUPNP.cmake
 create mode 100755 scripts/install-npupnp.sh

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1c301ecd9..5299b7bee 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -385,14 +385,45 @@ target_compile_options(libgerbera PUBLIC ${LFS_COMPILE_OPTIONS})
 target_link_libraries(libgerbera PUBLIC ${LFS_LIBRARIES})
 
 if (WITH_NPUPNP)
-    find_package(PkgConfig QUIET)
-    pkg_check_modules(NPUPNP QUIET libnpupnp>=4.2.1)
-    if (NOT NPUPNP_FOUND)
-        find_package(NPUPNP REQUIRED)
+    set(REQ_NPUPNP_VERSION 4.2.1)
+
+    find_package(NPUPNP ${REQ_NPUPNP_VERSION} QUIET)
+
+    if (NOT TARGET NPUPNP::NPUPNP)
+        find_package(npupnp ${REQ_NPUPNP_VERSION} QUIET)
+        if(TARGET npupnp::npupnp)
+            add_library(NPUPNP::NPUPNP ALIAS npupnp::npupnp)
+        endif()
     endif()
-    target_include_directories(libgerbera PUBLIC ${NPUPNP_INCLUDE_DIRS})
+    if(NOT TARGET NPUPNP::NPUPNP)
+        message(FATAL_ERROR "Gerbera failed to find libnpupnp! at least version ${REQ_UPNP_VERSION} is needed.")
+    endif()
+    # Conan autogenerated targets dont set a version, but to set name_VERSION var
+    get_target_property(_UPNP_VERSION NPUPNP::NPUPNP VERSION)
+    if (NOT _UPNP_VERSION)
+        set(_UPNP_VERSION ${npupnp_VERSION})
+    endif()
+    get_target_property(_UPNP_LIB NPUPNP::NPUPNP LOCATION)
+
+    # Check and warn for libnpupnp features
+    include(CheckCXXSymbolExists)
+    get_target_property(UPNP_INCLUDE_DIR NPUPNP::NPUPNP INTERFACE_INCLUDE_DIRECTORIES)
+    check_cxx_symbol_exists(UPNP_ENABLE_IPV6 "${UPNP_INCLUDE_DIR}/upnpconfig.h" UPNP_HAS_IPV6)
+    if (NOT UPNP_HAS_IPV6)
+        message(FATAL_ERROR "Gerbera requires libnpupnp with IPv6 support.")
+    endif()
+
+    check_cxx_symbol_exists(UPNP_HAVE_TOOLS "${UPNP_INCLUDE_DIR}/upnpconfig.h" UPNP_HAS_TOOLS)
+    if (NOT UPNP_HAS_TOOLS)
+        message(WARNING [=[
+    !! It is strongly recommended to build libupnp with --enable-tools !!
+        ]=])
+    endif()
+
+    message(STATUS "Found libnpupnp: ${_UPNP_LIB} (found version ${_UPNP_VERSION})")
+
     target_compile_definitions(libgerbera PUBLIC USING_NPUPNP)
-    target_link_libraries(libgerbera PUBLIC ${NPUPNP_LIBRARIES})
+    target_link_libraries(libgerbera PUBLIC NPUPNP::NPUPNP)
 else()
     set(REQ_UPNP_VERSION 1.14.6)
     # LibUPnP official target since 1.16 (Lib version 18)
new file mode 100644
index 000000000..b83168295
--- /dev/null
+++ cmake/FindNPUPNP.cmake
@@ -0,0 +1,54 @@
+# - Try to find LibNPUPnP (npupnp) 4.1.2
+# Once done this will define
+#  NPUPNP_FOUND - System has LibNPUPnP
+#  UPNP_INCLUDE_DIRS - The LibNPUPnP include directories
+#  NPUPNP_LIBRARIES - The libraries needed to use LibNPUPnP
+#  NPUPNP_VERSION_STRING - The version of LibNPUPnP found
+#  NPUPNP_HAS_IPV6 - If LibNPUPnP was built with IPv6 support
+#  NPUPNP_HAS_REUSEADDR - If LibNPUPnP was built with SO_REUSEADDR support
+find_package(PkgConfig QUIET)
+pkg_search_module (PC_NPUPNP libnpupnp QUIET)
+
+find_path(UPNP_INCLUDE_DIR upnp.h
+    HINTS ${PC_NPUPNP_INCLUDEDIR} ${PC_UPNP_INCLUDE_DIRS}
+    PATH_SUFFIXES npupnp)
+
+#if (STATIC_LIBUPNP)
+#    set(OLD_SUFFIX ${CMAKE_FIND_LIBRARY_SUFFIXES})
+#    set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
+#endif()
+
+find_library(NPUPNP_LIBRARY
+    NAMES libnpupnp npupnp
+    HINTS ${PC_NPUPNP_LIBDIR} ${PC_NPUPNP_LIBRARY_DIRS})
+
+# Restore
+#if (STATIC_LIBUPNP)
+#    set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIX})
+#endif()
+
+if(EXISTS ${UPNP_INCLUDE_DIR}/upnpconfig.h)
+    file (STRINGS ${UPNP_INCLUDE_DIR}/upnpconfig.h upnp_ver_str REGEX "^#define[ \t]+NPUPNP_VERSION_STRING[ \t]+\".+\"")
+    string(REGEX REPLACE "^#define[ \t]+NPUPNP_VERSION_STRING[ \t]+\"([^\"]+)\".*" "\\1" NPUPNP_VERSION "${upnp_ver_str}")
+endif()
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(NPUPNP
+    REQUIRED_VARS NPUPNP_LIBRARY UPNP_INCLUDE_DIR
+    VERSION_VAR NPUPNP_VERSION)
+
+if (NPUPNP_FOUND)
+    if(NOT TARGET NPUPNP::NPUPNP)
+        add_library(NPUPNP::NPUPNP SHARED IMPORTED)
+        set_target_properties(NPUPNP::NPUPNP PROPERTIES
+                IMPORTED_LOCATION ${NPUPNP_LIBRARY}
+                INTERFACE_INCLUDE_DIRECTORIES ${UPNP_INCLUDE_DIR}
+                VERSION ${NPUPNP_VERSION}
+        )
+    endif()
+endif ()
+
+MARK_AS_ADVANCED(
+    UPNP_INCLUDE_DIR
+    NPUPNP_LIBRARY
+)
diff --git a/cmake/FindUPNP.cmake b/cmake/FindUPNP.cmake
index 587e1c5ef..246328806 100644
--- cmake/FindUPNP.cmake
+++ cmake/FindUPNP.cmake
@@ -3,9 +3,9 @@
 #  UPNP_FOUND - System has LibUPnP
 #  UPNP_INCLUDE_DIRS - The LibUPnP include directories
 #  UPNP_LIBRARIES - The libraries needed to use LibUPnP
-#  UPNP_VERSION_STRING - The version of LinUPnP found
-#  UPNP_HAS_IPV6 - If LinUPnP was built with IPv6 support
-#  UPNP_HAS_REUSEADDR - If LinUPnP was built with SO_REUSEADDR support
+#  UPNP_VERSION_STRING - The version of LibUPnP found
+#  UPNP_HAS_IPV6 - If LibUPnP was built with IPv6 support
+#  UPNP_HAS_REUSEADDR - If LibUPnP was built with SO_REUSEADDR support
 find_package(PkgConfig QUIET)
 pkg_search_module (PC_UPNP QUIET libupnp)
 
diff --git a/scripts/versions.sh b/scripts/versions.sh
index c859e701b..86612f3e3 100755
--- scripts/versions.sh
+++ scripts/versions.sh
@@ -30,6 +30,7 @@ if [[ "${GERBERA_ENV-head}" == "minimum" ]]; then
     MATROSKA="1.5.2"
     PUGIXML="1.10"
     PUPNP="1.14.6"
+    NPUPNP="4.2.1"
     SPDLOG="1.8.1"
     WAVPACK="5.1.0"
     TAGLIB="1.12"
@@ -46,6 +47,7 @@ elif [[ "${GERBERA_ENV-head}" == "default" ]]; then
     MATROSKA="1.5.2"
     PUGIXML="1.10"
     PUPNP="1.14.17"
+    NPUPNP="5.1.2"
     SPDLOG="1.11.0"
     WAVPACK="5.4.0"
     TAGLIB="1.12"
@@ -63,8 +65,8 @@ else
     PUGIXML="1.14"
     PUPNP="1.14.18"
     SPDLOG="1.12.0"
+    NPUPNP="6.1.0"
     WAVPACK="5.6.0"
     TAGLIB="1.13.1"
 
 fi
-
diff --git a/src/iohandler/process_io_handler.cc b/src/iohandler/process_io_handler.cc
index de174eab2..3ff9e8099 100644
--- src/iohandler/process_io_handler.cc
+++ src/iohandler/process_io_handler.cc
@@ -39,6 +39,7 @@
 
 #include <fcntl.h>
 #include <sys/select.h>
+#include <unistd.h>
 
 #include "content/content_manager.h"
 
diff --git a/src/server.cc b/src/server.cc
index c8a0c2c75..bfd5d6477 100644
--- src/server.cc
+++ src/server.cc
@@ -231,8 +231,10 @@ void Server::run()
         throw UpnpException(ret, fmt::format("run: UpnpSendAdvertisement {} failed", aliveAdvertisementInterval));
     }
 
+#if !defined(USING_NPUPNP)
     if (config->getBoolOption(CFG_UPNP_LITERAL_HOST_REDIRECTION))
         UpnpSetAllowLiteralHostRedirection(1);
+#endif
 
     UpnpSetHostValidateCallback(
         [](auto host, auto cookie) -> int {
diff --git a/src/server.h b/src/server.h
index a91466b65..5826a1a77 100644
--- src/server.h
+++ src/server.h
@@ -34,6 +34,8 @@
 #ifndef __SERVER_H__
 #define __SERVER_H__
 
+#include <netinet/in.h>
+
 #include "request_handler.h"
 
 // forward declaration