]>
code.delx.au - pulseaudio/blob - src/modules/module-protocol-stub.c
fa21b737e33490e61ee56c518a355e6d32b55ef2
4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
36 #ifdef HAVE_ARPA_INET_H
37 #include <arpa/inet.h>
39 #ifdef HAVE_NETINET_IN_H
40 #include <netinet/in.h>
43 #include "../pulsecore/winsock.h"
45 #include <pulse/xmalloc.h>
47 #include <pulsecore/core-error.h>
48 #include <pulsecore/module.h>
49 #include <pulsecore/socket-server.h>
50 #include <pulsecore/socket-util.h>
51 #include <pulsecore/core-util.h>
52 #include <pulsecore/modargs.h>
53 #include <pulsecore/log.h>
54 #include <pulsecore/native-common.h>
56 #ifdef USE_TCP_SOCKETS
57 #define SOCKET_DESCRIPTION "(TCP sockets)"
58 #define SOCKET_USAGE "port=<TCP port number> loopback=<listen on loopback device only?> listen=<address to listen on>"
60 #define SOCKET_DESCRIPTION "(UNIX sockets)"
61 #define SOCKET_USAGE "socket=<path to UNIX socket>"
64 #if defined(USE_PROTOCOL_SIMPLE)
65 #include <pulsecore/protocol-simple.h>
66 #define protocol_new pa_protocol_simple_new
67 #define protocol_free pa_protocol_simple_free
68 #define TCPWRAP_SERVICE "pulseaudio-simple"
69 #define IPV4_PORT 4711
70 #define UNIX_SOCKET "simple"
71 #define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
72 #if defined(USE_TCP_SOCKETS)
73 #include "module-simple-protocol-tcp-symdef.h"
75 #include "module-simple-protocol-unix-symdef.h"
77 PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION
)
78 PA_MODULE_USAGE("rate=<sample rate> "
79 "format=<sample format> "
80 "channels=<number of channels> "
81 "sink=<sink to connect to> "
82 "source=<source to connect to> "
83 "playback=<enable playback?> "
84 "record=<enable record?> "
86 #elif defined(USE_PROTOCOL_CLI)
87 #include <pulsecore/protocol-cli.h>
88 #define protocol_new pa_protocol_cli_new
89 #define protocol_free pa_protocol_cli_free
90 #define TCPWRAP_SERVICE "pulseaudio-cli"
91 #define IPV4_PORT 4712
92 #define UNIX_SOCKET "cli"
93 #define MODULE_ARGUMENTS
94 #ifdef USE_TCP_SOCKETS
95 #include "module-cli-protocol-tcp-symdef.h"
97 #include "module-cli-protocol-unix-symdef.h"
99 PA_MODULE_DESCRIPTION("Command line interface protocol "SOCKET_DESCRIPTION
)
100 PA_MODULE_USAGE(SOCKET_USAGE
)
101 #elif defined(USE_PROTOCOL_HTTP)
102 #include <pulsecore/protocol-http.h>
103 #define protocol_new pa_protocol_http_new
104 #define protocol_free pa_protocol_http_free
105 #define TCPWRAP_SERVICE "pulseaudio-http"
106 #define IPV4_PORT 4714
107 #define UNIX_SOCKET "http"
108 #define MODULE_ARGUMENTS
109 #ifdef USE_TCP_SOCKETS
110 #include "module-http-protocol-tcp-symdef.h"
112 #include "module-http-protocol-unix-symdef.h"
114 PA_MODULE_DESCRIPTION("HTTP "SOCKET_DESCRIPTION
)
115 PA_MODULE_USAGE(SOCKET_USAGE
)
116 #elif defined(USE_PROTOCOL_NATIVE)
117 #include <pulsecore/protocol-native.h>
118 #define protocol_new pa_protocol_native_new
119 #define protocol_free pa_protocol_native_free
120 #define TCPWRAP_SERVICE "pulseaudio-native"
121 #define IPV4_PORT PA_NATIVE_DEFAULT_PORT
122 #define UNIX_SOCKET PA_NATIVE_DEFAULT_UNIX_SOCKET
123 #define MODULE_ARGUMENTS_COMMON "cookie", "auth-anonymous",
124 #ifdef USE_TCP_SOCKETS
125 #include "module-native-protocol-tcp-symdef.h"
127 #include "module-native-protocol-unix-symdef.h"
130 #if defined(SCM_CREDENTIALS) && !defined(USE_TCP_SOCKETS)
131 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group",
132 #define AUTH_USAGE "auth-group=<local group to allow access>"
134 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
138 PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION
)
139 PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> "
140 "cookie=<path to cookie file> "
143 #elif defined(USE_PROTOCOL_ESOUND)
144 #include <pulsecore/protocol-esound.h>
145 #include <pulsecore/esound.h>
146 #define protocol_new pa_protocol_esound_new
147 #define protocol_free pa_protocol_esound_free
148 #define TCPWRAP_SERVICE "esound"
149 #define IPV4_PORT ESD_DEFAULT_PORT
150 #define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
151 #define MODULE_ARGUMENTS "sink", "source", "auth-anonymous", "cookie",
152 #ifdef USE_TCP_SOCKETS
153 #include "module-esound-protocol-tcp-symdef.h"
155 #include "module-esound-protocol-unix-symdef.h"
157 PA_MODULE_DESCRIPTION("ESOUND protocol "SOCKET_DESCRIPTION
)
158 PA_MODULE_USAGE("sink=<sink to connect to> "
159 "source=<source to connect to> "
160 "auth-anonymous=<don't verify cookies?> "
161 "cookie=<path to cookie file> "
164 #error "Broken build system"
167 PA_MODULE_AUTHOR("Lennart Poettering")
168 PA_MODULE_VERSION(PACKAGE_VERSION
)
170 static const char* const valid_modargs
[] = {
172 #if defined(USE_TCP_SOCKETS)
183 #if defined(USE_TCP_SOCKETS)
192 int pa__init(pa_core
*c
, pa_module
*m
) {
193 pa_modargs
*ma
= NULL
;
196 struct userdata
*u
= NULL
;
198 #if defined(USE_TCP_SOCKETS)
199 pa_socket_server
*s_ipv4
= NULL
, *s_ipv6
= NULL
;
201 uint32_t port
= IPV4_PORT
;
202 const char *listen_on
;
211 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
212 pa_log(__FILE__
": Failed to parse module arguments");
216 u
= pa_xnew0(struct userdata
, 1);
218 #if defined(USE_TCP_SOCKETS)
219 if (pa_modargs_get_value_boolean(ma
, "loopback", &loopback
) < 0) {
220 pa_log(__FILE__
": loopback= expects a boolean argument.");
224 if (pa_modargs_get_value_u32(ma
, "port", &port
) < 0 || port
< 1 || port
> 0xFFFF) {
225 pa_log(__FILE__
": port= expects a numerical argument between 1 and 65535.");
229 listen_on
= pa_modargs_get_value(ma
, "listen", NULL
);
232 s_ipv6
= pa_socket_server_new_ipv6_string(c
->mainloop
, listen_on
, port
, TCPWRAP_SERVICE
);
233 s_ipv4
= pa_socket_server_new_ipv4_string(c
->mainloop
, listen_on
, port
, TCPWRAP_SERVICE
);
234 } else if (loopback
) {
235 s_ipv6
= pa_socket_server_new_ipv6_loopback(c
->mainloop
, port
, TCPWRAP_SERVICE
);
236 s_ipv4
= pa_socket_server_new_ipv4_loopback(c
->mainloop
, port
, TCPWRAP_SERVICE
);
238 s_ipv6
= pa_socket_server_new_ipv6_any(c
->mainloop
, port
, TCPWRAP_SERVICE
);
239 s_ipv4
= pa_socket_server_new_ipv4_any(c
->mainloop
, port
, TCPWRAP_SERVICE
);
242 if (!s_ipv4
&& !s_ipv6
)
246 if (!(u
->protocol_ipv4
= protocol_new(c
, s_ipv4
, m
, ma
)))
247 pa_socket_server_unref(s_ipv4
);
250 if (!(u
->protocol_ipv6
= protocol_new(c
, s_ipv6
, m
, ma
)))
251 pa_socket_server_unref(s_ipv6
);
253 if (!u
->protocol_ipv4
&& !u
->protocol_ipv6
)
258 pa_runtime_path(pa_modargs_get_value(ma
, "socket", UNIX_SOCKET
), tmp
, sizeof(tmp
));
259 u
->socket_path
= pa_xstrdup(tmp
);
261 #if defined(USE_PROTOCOL_ESOUND)
263 /* This socket doesn't reside in our own runtime dir but in
264 * /tmp/.esd/, hence we have to create the dir first */
266 if (pa_make_secure_parent_dir(u
->socket_path
, c
->is_system_instance
? 0755 : 0700, getuid(), getgid()) < 0) {
267 pa_log(__FILE__
": Failed to create socket directory: %s\n", pa_cstrerror(errno
));
272 if ((r
= pa_unix_socket_remove_stale(tmp
)) < 0) {
273 pa_log(__FILE__
": Failed to remove stale UNIX socket '%s': %s", tmp
, pa_cstrerror(errno
));
278 pa_log(__FILE__
": Removed stale UNIX socket '%s'.", tmp
);
280 if (!(s
= pa_socket_server_new_unix(c
->mainloop
, tmp
)))
283 if (!(u
->protocol_unix
= protocol_new(c
, s
, m
, ma
)))
300 #if defined(USE_TCP_SOCKETS)
301 if (u
->protocol_ipv4
)
302 protocol_free(u
->protocol_ipv4
);
303 if (u
->protocol_ipv6
)
304 protocol_free(u
->protocol_ipv6
);
306 if (u
->protocol_unix
)
307 protocol_free(u
->protocol_unix
);
310 pa_xfree(u
->socket_path
);
315 #if defined(USE_TCP_SOCKETS)
317 pa_socket_server_unref(s_ipv4
);
319 pa_socket_server_unref(s_ipv6
);
322 pa_socket_server_unref(s
);
329 void pa__done(pa_core
*c
, pa_module
*m
) {
337 #if defined(USE_TCP_SOCKETS)
338 if (u
->protocol_ipv4
)
339 protocol_free(u
->protocol_ipv4
);
340 if (u
->protocol_ipv6
)
341 protocol_free(u
->protocol_ipv6
);
343 if (u
->protocol_unix
)
344 protocol_free(u
->protocol_unix
);
346 #if defined(USE_PROTOCOL_ESOUND)
347 if (u
->socket_path
) {
348 char *p
= pa_parent_dir(u
->socket_path
);
355 pa_xfree(u
->socket_path
);