]> code.delx.au - pulseaudio/blobdiff - src/modules/module-protocol-stub.c
modules: Fix resource leak in oss
[pulseaudio] / src / modules / module-protocol-stub.c
index aefd4020fe1500294d7708f777afa9754f9cc62d..3218a01e155eaf338a2e316c2c8dfe6e48e2c79a 100644 (file)
@@ -6,7 +6,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 #include <config.h>
 #endif
 
 #include <config.h>
 #endif
 
-#include <string.h>
 #include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
-#include <limits.h>
 
 
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
 
 #include <pulse/xmalloc.h>
 
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
 
 #include <pulse/xmalloc.h>
 
-#include <pulsecore/winsock.h>
 #include <pulsecore/core-error.h>
 #include <pulsecore/module.h>
 #include <pulsecore/core-error.h>
 #include <pulsecore/module.h>
+#include <pulsecore/socket.h>
 #include <pulsecore/socket-server.h>
 #include <pulsecore/socket-util.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/socket-server.h>
 #include <pulsecore/socket-util.h>
 #include <pulsecore/core-util.h>
@@ -52,6 +44,7 @@
 #include <pulsecore/log.h>
 #include <pulsecore/native-common.h>
 #include <pulsecore/creds.h>
 #include <pulsecore/log.h>
 #include <pulsecore/native-common.h>
 #include <pulsecore/creds.h>
+#include <pulsecore/arpa-inet.h>
 
 #ifdef USE_TCP_SOCKETS
 #define SOCKET_DESCRIPTION "(TCP sockets)"
 
 #ifdef USE_TCP_SOCKETS
 #define SOCKET_DESCRIPTION "(TCP sockets)"
   PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION);
   PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> "
                   "auth-cookie=<path to cookie file> "
   PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION);
   PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> "
                   "auth-cookie=<path to cookie file> "
-                  "auth-cookie-enabled=<enable cookie authentification? "
+                  "auth-cookie-enabled=<enable cookie authentication?> "
                   AUTH_USAGE
                   SOCKET_USAGE);
 #elif defined(USE_PROTOCOL_ESOUND)
                   AUTH_USAGE
                   SOCKET_USAGE);
 #elif defined(USE_PROTOCOL_ESOUND)
                   "source=<source to connect to> "
                   "auth-anonymous=<don't verify cookies?> "
                   "auth-cookie=<path to cookie file> "
                   "source=<source to connect to> "
                   "auth-anonymous=<don't verify cookies?> "
                   "auth-cookie=<path to cookie file> "
-                  "auth-cookie-enabled=<enable cookie authentification? "
+                  "auth-cookie-enabled=<enable cookie authentication?> "
                   AUTH_USAGE
                   SOCKET_USAGE);
 #else
 #  error "Broken build system"
 #endif
 
                   AUTH_USAGE
                   SOCKET_USAGE);
 #else
 #  error "Broken build system"
 #endif
 
-PA_MODULE_LOAD_ONCE(FALSE);
+PA_MODULE_LOAD_ONCE(false);
 PA_MODULE_AUTHOR("Lennart Poettering");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 
 PA_MODULE_AUTHOR("Lennart Poettering");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 
@@ -211,7 +204,9 @@ struct userdata {
 
 #if defined(USE_TCP_SOCKETS)
     pa_socket_server *socket_server_ipv4;
 
 #if defined(USE_TCP_SOCKETS)
     pa_socket_server *socket_server_ipv4;
+#  ifdef HAVE_IPV6
     pa_socket_server *socket_server_ipv6;
     pa_socket_server *socket_server_ipv6;
+#  endif
 #else
     pa_socket_server *socket_server_unix;
     char *socket_path;
 #else
     pa_socket_server *socket_server_unix;
     char *socket_path;
@@ -244,12 +239,13 @@ int pa__init(pa_module*m) {
 
 #if defined(USE_TCP_SOCKETS)
     uint32_t port = IPV4_PORT;
 
 #if defined(USE_TCP_SOCKETS)
     uint32_t port = IPV4_PORT;
+    bool port_fallback = true;
     const char *listen_on;
 #else
     int r;
 #endif
 
     const char *listen_on;
 #else
     int r;
 #endif
 
-#if defined(USE_PROTOCOL_NATIVE)
+#if defined(USE_PROTOCOL_NATIVE) || defined(USE_PROTOCOL_HTTP)
     char t[256];
 #endif
 
     char t[256];
 #endif
 
@@ -291,6 +287,10 @@ int pa__init(pa_module*m) {
 #endif
 
 #if defined(USE_TCP_SOCKETS)
 #endif
 
 #if defined(USE_TCP_SOCKETS)
+
+    if (pa_in_system_mode() || pa_modargs_get_value(ma, "port", NULL))
+        port_fallback = false;
+
     if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) {
         pa_log("port= expects a numerical argument between 1 and 65535.");
         goto fail;
     if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) {
         pa_log("port= expects a numerical argument between 1 and 65535.");
         goto fail;
@@ -299,20 +299,30 @@ int pa__init(pa_module*m) {
     listen_on = pa_modargs_get_value(ma, "listen", NULL);
 
     if (listen_on) {
     listen_on = pa_modargs_get_value(ma, "listen", NULL);
 
     if (listen_on) {
-        u->socket_server_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, (uint16_t) port, TCPWRAP_SERVICE);
-        u->socket_server_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, (uint16_t) port, TCPWRAP_SERVICE);
+#  ifdef HAVE_IPV6
+        u->socket_server_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, (uint16_t) port, port_fallback, TCPWRAP_SERVICE);
+#  endif
+        u->socket_server_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, (uint16_t) port, port_fallback, TCPWRAP_SERVICE);
     } else {
     } else {
-        u->socket_server_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, (uint16_t) port, TCPWRAP_SERVICE);
-        u->socket_server_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, (uint16_t) port, TCPWRAP_SERVICE);
+#  ifdef HAVE_IPV6
+        u->socket_server_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, (uint16_t) port, port_fallback, TCPWRAP_SERVICE);
+#  endif
+        u->socket_server_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, (uint16_t) port, port_fallback, TCPWRAP_SERVICE);
     }
 
     }
 
+#  ifdef HAVE_IPV6
     if (!u->socket_server_ipv4 && !u->socket_server_ipv6)
     if (!u->socket_server_ipv4 && !u->socket_server_ipv6)
+#  else
+    if (!u->socket_server_ipv4)
+#  endif
         goto fail;
 
     if (u->socket_server_ipv4)
         pa_socket_server_set_callback(u->socket_server_ipv4, socket_server_on_connection_cb, u);
         goto fail;
 
     if (u->socket_server_ipv4)
         pa_socket_server_set_callback(u->socket_server_ipv4, socket_server_on_connection_cb, u);
+#  ifdef HAVE_IPV6
     if (u->socket_server_ipv6)
         pa_socket_server_set_callback(u->socket_server_ipv6, socket_server_on_connection_cb, u);
     if (u->socket_server_ipv6)
         pa_socket_server_set_callback(u->socket_server_ipv6, socket_server_on_connection_cb, u);
+#  endif
 
 #else
 
 
 #else
 
@@ -327,7 +337,7 @@ int pa__init(pa_module*m) {
     /* This socket doesn't reside in our own runtime dir but in
      * /tmp/.esd/, hence we have to create the dir first */
 
     /* This socket doesn't reside in our own runtime dir but in
      * /tmp/.esd/, hence we have to create the dir first */
 
-    if (pa_make_secure_parent_dir(u->socket_path, pa_in_system_mode() ? 0755U : 0700U, (uid_t)-1, (gid_t)-1) < 0) {
+    if (pa_make_secure_parent_dir(u->socket_path, pa_in_system_mode() ? 0755U : 0700U, (uid_t)-1, (gid_t)-1, false) < 0) {
         pa_log("Failed to create socket directory '%s': %s\n", u->socket_path, pa_cstrerror(errno));
         goto fail;
     }
         pa_log("Failed to create socket directory '%s': %s\n", u->socket_path, pa_cstrerror(errno));
         goto fail;
     }
@@ -358,9 +368,11 @@ int pa__init(pa_module*m) {
         if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
             pa_native_protocol_add_server_string(u->native_protocol, t);
 
         if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
             pa_native_protocol_add_server_string(u->native_protocol, t);
 
+#    ifdef HAVE_IPV6
     if (u->socket_server_ipv6)
         if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
             pa_native_protocol_add_server_string(u->native_protocol, t);
     if (u->socket_server_ipv6)
         if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
             pa_native_protocol_add_server_string(u->native_protocol, t);
+#    endif
 #  else
     if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
         pa_native_protocol_add_server_string(u->native_protocol, t);
 #  else
     if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
         pa_native_protocol_add_server_string(u->native_protocol, t);
@@ -368,6 +380,24 @@ int pa__init(pa_module*m) {
 #  endif
 #endif
 
 #  endif
 #endif
 
+#if defined(USE_PROTOCOL_HTTP)
+#if defined(USE_TCP_SOCKETS)
+    if (u->socket_server_ipv4)
+        if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
+            pa_http_protocol_add_server_string(u->http_protocol, t);
+
+#ifdef HAVE_IPV6
+    if (u->socket_server_ipv6)
+        if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
+            pa_http_protocol_add_server_string(u->http_protocol, t);
+#endif /* HAVE_IPV6 */
+#else /* USE_TCP_SOCKETS */
+    if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
+        pa_http_protocol_add_server_string(u->http_protocol, t);
+
+#endif /* USE_TCP_SOCKETS */
+#endif /* USE_PROTOCOL_HTTP */
+
     if (ma)
         pa_modargs_free(ma);
 
     if (ma)
         pa_modargs_free(ma);
 
@@ -405,6 +435,24 @@ void pa__done(pa_module*m) {
     }
 #elif defined(USE_PROTOCOL_HTTP)
     if (u->http_protocol) {
     }
 #elif defined(USE_PROTOCOL_HTTP)
     if (u->http_protocol) {
+        char t[256];
+
+#if defined(USE_TCP_SOCKETS)
+        if (u->socket_server_ipv4)
+            if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
+                pa_http_protocol_remove_server_string(u->http_protocol, t);
+
+#ifdef HAVE_IPV6
+        if (u->socket_server_ipv6)
+            if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
+                pa_http_protocol_remove_server_string(u->http_protocol, t);
+#endif /* HAVE_IPV6 */
+#else /* USE_TCP_SOCKETS */
+        if (u->socket_server_unix)
+            if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
+                pa_http_protocol_remove_server_string(u->http_protocol, t);
+#endif /* USE_PROTOCOL_HTTP */
+
         pa_http_protocol_disconnect(u->http_protocol, u->module);
         pa_http_protocol_unref(u->http_protocol);
     }
         pa_http_protocol_disconnect(u->http_protocol, u->module);
         pa_http_protocol_unref(u->http_protocol);
     }
@@ -418,9 +466,11 @@ void pa__done(pa_module*m) {
             if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
                 pa_native_protocol_remove_server_string(u->native_protocol, t);
 
             if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
                 pa_native_protocol_remove_server_string(u->native_protocol, t);
 
+#    ifdef HAVE_IPV6
         if (u->socket_server_ipv6)
             if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
                 pa_native_protocol_remove_server_string(u->native_protocol, t);
         if (u->socket_server_ipv6)
             if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
                 pa_native_protocol_remove_server_string(u->native_protocol, t);
+#    endif
 #  else
         if (u->socket_server_unix)
             if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
 #  else
         if (u->socket_server_unix)
             if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
@@ -444,8 +494,10 @@ void pa__done(pa_module*m) {
 #if defined(USE_TCP_SOCKETS)
     if (u->socket_server_ipv4)
         pa_socket_server_unref(u->socket_server_ipv4);
 #if defined(USE_TCP_SOCKETS)
     if (u->socket_server_ipv4)
         pa_socket_server_unref(u->socket_server_ipv4);
+#  ifdef HAVE_IPV6
     if (u->socket_server_ipv6)
         pa_socket_server_unref(u->socket_server_ipv6);
     if (u->socket_server_ipv6)
         pa_socket_server_unref(u->socket_server_ipv6);
+#  endif
 #else
     if (u->socket_server_unix)
         pa_socket_server_unref(u->socket_server_unix);
 #else
     if (u->socket_server_unix)
         pa_socket_server_unref(u->socket_server_unix);