[vlc-devel] [PATCH 1/4] httpd: rework httpd_HostCreate arg types

Thomas Guillem thomas at gllm.fr
Mon Jan 11 13:32:16 UTC 2021


---
 src/network/httpd.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/network/httpd.c b/src/network/httpd.c
index 2f7f20c3623..8843c217e55 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -881,14 +881,26 @@ void httpd_StreamDelete(httpd_stream_t *stream)
  * Low level
  *****************************************************************************/
 static void* httpd_HostThread(void *);
-static httpd_host_t *httpd_HostCreate(vlc_object_t *, const char *,
-                                      const char *, vlc_tls_server_t *,
-                                      unsigned);
+static httpd_host_t *httpd_HostCreate(vlc_object_t *, const char *, unsigned,
+                                      vlc_tls_server_t *, unsigned);
+
+static httpd_host_t *httpd_HostVarCreate(vlc_object_t *p_this,
+                                         const char *hostvar,
+                                         const char *portvar,
+                                         vlc_tls_server_t *p_tls,
+                                         unsigned timeout_sec)
+{
+    char *hostname = var_InheritString(p_this, hostvar);
+    unsigned port = var_InheritInteger(p_this, portvar);
+    httpd_host_t *host = httpd_HostCreate(p_this, hostname, port, p_tls, timeout_sec);
+    free(hostname);
+    return host;
+}
 
 /* create a new host */
 httpd_host_t *vlc_http_HostNew(vlc_object_t *p_this)
 {
-    return httpd_HostCreate(p_this, "http-host", "http-port", NULL, 10);
+    return httpd_HostVarCreate(p_this, "http-host", "http-port", NULL, 10);
 }
 
 httpd_host_t *vlc_https_HostNew(vlc_object_t *obj)
@@ -912,13 +924,13 @@ httpd_host_t *vlc_https_HostNew(vlc_object_t *obj)
     free(key);
     free(cert);
 
-    return httpd_HostCreate(obj, "http-host", "https-port", tls, 10);
+    return httpd_HostVarCreate(obj, "http-host", "https-port", tls, 10);
 }
 
 httpd_host_t *vlc_rtsp_HostNew(vlc_object_t *p_this)
 {
     unsigned timeout = var_InheritInteger(p_this, "rtsp-timeout");
-    return httpd_HostCreate(p_this, "rtsp-host", "rtsp-port", NULL, timeout);
+    return httpd_HostVarCreate(p_this, "rtsp-host", "rtsp-port", NULL, timeout);
 }
 
 static struct httpd
@@ -928,13 +940,11 @@ static struct httpd
 } httpd = { VLC_STATIC_MUTEX, VLC_LIST_INITIALIZER(&httpd.hosts) };
 
 static httpd_host_t *httpd_HostCreate(vlc_object_t *p_this,
-                                       const char *hostvar,
-                                       const char *portvar,
-                                       vlc_tls_server_t *p_tls,
-                                       unsigned timeout_sec)
+                                      const char *hostname, unsigned port,
+                                      vlc_tls_server_t *p_tls,
+                                      unsigned timeout_sec)
 {
     httpd_host_t *host;
-    unsigned port = var_InheritInteger(p_this, portvar);
 
     /* to be sure to avoid multiple creation */
     vlc_mutex_lock(&httpd.mutex);
@@ -963,10 +973,7 @@ static httpd_host_t *httpd_HostCreate(vlc_object_t *p_this,
     vlc_mutex_init(&host->lock);
     atomic_init(&host->ref, 1);
 
-    char *hostname = var_InheritString(p_this, hostvar);
-
     host->fds = net_ListenTCP(p_this, hostname, port);
-    free(hostname);
 
     if (!host->fds) {
         msg_Err(p_this, "cannot create socket(s) for HTTP host");
-- 
2.29.2



More information about the vlc-devel mailing list