summaryrefslogtreecommitdiffstats
path: root/src/modules/module-protocol-stub.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/module-protocol-stub.c')
-rw-r--r--src/modules/module-protocol-stub.c156
1 files changed, 80 insertions, 76 deletions
diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c
index df58958a..0c9529c3 100644
--- a/src/modules/module-protocol-stub.c
+++ b/src/modules/module-protocol-stub.c
@@ -1,18 +1,19 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
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,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -26,7 +27,6 @@
#include <string.h>
#include <errno.h>
#include <stdio.h>
-#include <assert.h>
#include <unistd.h>
#include <limits.h>
@@ -40,10 +40,9 @@
#include <netinet/in.h>
#endif
-#include "../pulsecore/winsock.h"
-
#include <pulse/xmalloc.h>
+#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
#include <pulsecore/module.h>
#include <pulsecore/socket-server.h>
@@ -75,7 +74,7 @@
#else
#include "module-simple-protocol-unix-symdef.h"
#endif
- PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION)
+PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION);
PA_MODULE_USAGE("rate=<sample rate> "
"format=<sample format> "
"channels=<number of channels> "
@@ -83,22 +82,22 @@
"source=<source to connect to> "
"playback=<enable playback?> "
"record=<enable record?> "
- SOCKET_USAGE)
+ SOCKET_USAGE);
#elif defined(USE_PROTOCOL_CLI)
- #include <pulsecore/protocol-cli.h>
+ #include <pulsecore/protocol-cli.h>
#define protocol_new pa_protocol_cli_new
#define protocol_free pa_protocol_cli_free
#define TCPWRAP_SERVICE "pulseaudio-cli"
#define IPV4_PORT 4712
#define UNIX_SOCKET "cli"
- #define MODULE_ARGUMENTS
+ #define MODULE_ARGUMENTS
#ifdef USE_TCP_SOCKETS
#include "module-cli-protocol-tcp-symdef.h"
#else
#include "module-cli-protocol-unix-symdef.h"
#endif
- PA_MODULE_DESCRIPTION("Command line interface protocol "SOCKET_DESCRIPTION)
- PA_MODULE_USAGE(SOCKET_USAGE)
+ PA_MODULE_DESCRIPTION("Command line interface protocol "SOCKET_DESCRIPTION);
+ PA_MODULE_USAGE(SOCKET_USAGE);
#elif defined(USE_PROTOCOL_HTTP)
#include <pulsecore/protocol-http.h>
#define protocol_new pa_protocol_http_new
@@ -106,14 +105,14 @@
#define TCPWRAP_SERVICE "pulseaudio-http"
#define IPV4_PORT 4714
#define UNIX_SOCKET "http"
- #define MODULE_ARGUMENTS
+ #define MODULE_ARGUMENTS
#ifdef USE_TCP_SOCKETS
#include "module-http-protocol-tcp-symdef.h"
#else
#include "module-http-protocol-unix-symdef.h"
#endif
- PA_MODULE_DESCRIPTION("HTTP "SOCKET_DESCRIPTION)
- PA_MODULE_USAGE(SOCKET_USAGE)
+ PA_MODULE_DESCRIPTION("HTTP "SOCKET_DESCRIPTION);
+ PA_MODULE_USAGE(SOCKET_USAGE);
#elif defined(USE_PROTOCOL_NATIVE)
#include <pulsecore/protocol-native.h>
#define protocol_new pa_protocol_native_new
@@ -129,21 +128,21 @@
#endif
#if defined(HAVE_CREDS) && !defined(USE_TCP_SOCKETS)
- #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group", "auth-group-enable",
+ #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group", "auth-group-enable",
#define AUTH_USAGE "auth-group=<system group to allow access> auth-group-enable=<enable auth by UNIX group?> "
#elif defined(USE_TCP_SOCKETS)
- #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl",
+ #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl",
#define AUTH_USAGE "auth-ip-acl=<IP address ACL to allow access> "
#else
#define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
#define AUTH_USAGE
#endif
-
- PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION)
+
+ PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION);
PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> "
"cookie=<path to cookie file> "
AUTH_USAGE
- SOCKET_USAGE)
+ SOCKET_USAGE);
#elif defined(USE_PROTOCOL_ESOUND)
#include <pulsecore/protocol-esound.h>
#include <pulsecore/esound.h>
@@ -151,7 +150,6 @@
#define protocol_free pa_protocol_esound_free
#define TCPWRAP_SERVICE "esound"
#define IPV4_PORT ESD_DEFAULT_PORT
- #define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
#define MODULE_ARGUMENTS_COMMON "sink", "source", "auth-anonymous", "cookie",
#ifdef USE_TCP_SOCKETS
#include "module-esound-protocol-tcp-symdef.h"
@@ -160,26 +158,27 @@
#endif
#if defined(USE_TCP_SOCKETS)
- #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl",
+ #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl",
#define AUTH_USAGE "auth-ip-acl=<IP address ACL to allow access> "
#else
#define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
#define AUTH_USAGE
#endif
- PA_MODULE_DESCRIPTION("ESOUND protocol "SOCKET_DESCRIPTION)
+ PA_MODULE_DESCRIPTION("ESOUND protocol "SOCKET_DESCRIPTION);
PA_MODULE_USAGE("sink=<sink to connect to> "
"source=<source to connect to> "
"auth-anonymous=<don't verify cookies?> "
"cookie=<path to cookie file> "
AUTH_USAGE
- SOCKET_USAGE)
+ SOCKET_USAGE);
#else
- #error "Broken build system"
+ #error "Broken build system"
#endif
-PA_MODULE_AUTHOR("Lennart Poettering")
-PA_MODULE_VERSION(PACKAGE_VERSION)
+PA_MODULE_LOAD_ONCE(FALSE);
+PA_MODULE_AUTHOR("Lennart Poettering");
+PA_MODULE_VERSION(PACKAGE_VERSION);
static const char* const valid_modargs[] = {
MODULE_ARGUMENTS
@@ -202,10 +201,9 @@ struct userdata {
#endif
};
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
int ret = -1;
-
struct userdata *u = NULL;
#if defined(USE_TCP_SOCKETS)
@@ -215,10 +213,9 @@ int pa__init(pa_core *c, pa_module*m) {
#else
pa_socket_server *s;
int r;
- char tmp[PATH_MAX];
#endif
- assert(c && m);
+ pa_assert(m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
pa_log("Failed to parse module arguments");
@@ -236,57 +233,68 @@ int pa__init(pa_core *c, pa_module*m) {
listen_on = pa_modargs_get_value(ma, "listen", NULL);
if (listen_on) {
- s_ipv6 = pa_socket_server_new_ipv6_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE);
- s_ipv4 = pa_socket_server_new_ipv4_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE);
+ s_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE);
+ s_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE);
} else {
- s_ipv6 = pa_socket_server_new_ipv6_any(c->mainloop, port, TCPWRAP_SERVICE);
- s_ipv4 = pa_socket_server_new_ipv4_any(c->mainloop, port, TCPWRAP_SERVICE);
+ s_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, port, TCPWRAP_SERVICE);
+ s_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, port, TCPWRAP_SERVICE);
}
if (!s_ipv4 && !s_ipv6)
goto fail;
if (s_ipv4)
- if (!(u->protocol_ipv4 = protocol_new(c, s_ipv4, m, ma)))
- pa_socket_server_unref(s_ipv4);
-
+ u->protocol_ipv4 = protocol_new(m->core, s_ipv4, m, ma);
if (s_ipv6)
- if (!(u->protocol_ipv6 = protocol_new(c, s_ipv6, m, ma)))
- pa_socket_server_unref(s_ipv6);
+ u->protocol_ipv6 = protocol_new(m->core, s_ipv6, m, ma);
if (!u->protocol_ipv4 && !u->protocol_ipv6)
goto fail;
-#else
+ if (s_ipv6)
+ pa_socket_server_unref(s_ipv6);
+ if (s_ipv6)
+ pa_socket_server_unref(s_ipv4);
- pa_runtime_path(pa_modargs_get_value(ma, "socket", UNIX_SOCKET), tmp, sizeof(tmp));
- u->socket_path = pa_xstrdup(tmp);
+#else
#if defined(USE_PROTOCOL_ESOUND)
+#if defined(USE_PER_USER_ESOUND_SOCKET)
+ u->socket_path = pa_sprintf_malloc("/tmp/.esd-%lu/socket", (unsigned long) getuid());
+#else
+ u->socket_path = pa_xstrdup("/tmp/.esd/socket");
+#endif
+
/* 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, c->is_system_instance ? 0755 : 0700, (uid_t)-1, (gid_t)-1) < 0) {
- pa_log("Failed to create socket directory: %s\n", pa_cstrerror(errno));
+
+ if (pa_make_secure_parent_dir(u->socket_path, pa_in_system_mode() ? 0755 : 0700, (uid_t)-1, (gid_t)-1) < 0) {
+ pa_log("Failed to create socket directory '%s': %s\n", u->socket_path, pa_cstrerror(errno));
goto fail;
}
-#endif
-
- if ((r = pa_unix_socket_remove_stale(tmp)) < 0) {
- pa_log("Failed to remove stale UNIX socket '%s': %s", tmp, pa_cstrerror(errno));
+
+#else
+ if (!(u->socket_path = pa_runtime_path(pa_modargs_get_value(ma, "socket", UNIX_SOCKET)))) {
+ pa_log("Failed to generate socket path.");
goto fail;
}
-
- if (r)
- pa_log("Removed stale UNIX socket '%s'.", tmp);
-
- if (!(s = pa_socket_server_new_unix(c->mainloop, tmp)))
+#endif
+
+ if ((r = pa_unix_socket_remove_stale(u->socket_path)) < 0) {
+ pa_log("Failed to remove stale UNIX socket '%s': %s", u->socket_path, pa_cstrerror(errno));
goto fail;
+ } else if (r > 0)
+ pa_log_info("Removed stale UNIX socket '%s'.", u->socket_path);
- if (!(u->protocol_unix = protocol_new(c, s, m, ma)))
+ if (!(s = pa_socket_server_new_unix(m->core->mainloop, u->socket_path)))
goto fail;
+ if (!(u->protocol_unix = protocol_new(m->core, s, m, ma)))
+ goto fail;
+
+ pa_socket_server_unref(s);
+
#endif
m->userdata = u;
@@ -309,32 +317,29 @@ fail:
#else
if (u->protocol_unix)
protocol_free(u->protocol_unix);
-
- if (u->socket_path)
- pa_xfree(u->socket_path);
+ pa_xfree(u->socket_path);
#endif
pa_xfree(u);
- } else {
+ }
+
#if defined(USE_TCP_SOCKETS)
- if (s_ipv4)
- pa_socket_server_unref(s_ipv4);
- if (s_ipv6)
- pa_socket_server_unref(s_ipv6);
+ if (s_ipv4)
+ pa_socket_server_unref(s_ipv4);
+ if (s_ipv6)
+ pa_socket_server_unref(s_ipv6);
#else
- if (s)
- pa_socket_server_unref(s);
+ if (s)
+ pa_socket_server_unref(s);
#endif
- }
goto finish;
}
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
struct userdata *u;
-
- assert(c);
- assert(m);
+
+ pa_assert(m);
u = m->userdata;
@@ -347,15 +352,14 @@ void pa__done(pa_core *c, pa_module*m) {
if (u->protocol_unix)
protocol_free(u->protocol_unix);
-#if defined(USE_PROTOCOL_ESOUND)
+#if defined(USE_PROTOCOL_ESOUND) && !defined(USE_PER_USER_ESOUND_SOCKET)
if (u->socket_path) {
char *p = pa_parent_dir(u->socket_path);
rmdir(p);
pa_xfree(p);
}
#endif
-
-
+
pa_xfree(u->socket_path);
#endif