]>
code.delx.au - pulseaudio/blob - src/modules/module-protocol-stub.c
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>
55 #include <pulsecore/creds.h>
57 #ifdef USE_TCP_SOCKETS
58 #define SOCKET_DESCRIPTION "(TCP sockets)"
59 #define SOCKET_USAGE "port=<TCP port number> listen=<address to listen on>"
61 #define SOCKET_DESCRIPTION "(UNIX sockets)"
62 #define SOCKET_USAGE "socket=<path to UNIX socket>"
65 #if defined(USE_PROTOCOL_SIMPLE)
66 #include <pulsecore/protocol-simple.h>
67 #define protocol_new pa_protocol_simple_new
68 #define protocol_free pa_protocol_simple_free
69 #define TCPWRAP_SERVICE "pulseaudio-simple"
70 #define IPV4_PORT 4711
71 #define UNIX_SOCKET "simple"
72 #define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
73 #if defined(USE_TCP_SOCKETS)
74 #include "module-simple-protocol-tcp-symdef.h"
76 #include "module-simple-protocol-unix-symdef.h"
78 PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION
)
79 PA_MODULE_USAGE("rate=<sample rate> "
80 "format=<sample format> "
81 "channels=<number of channels> "
82 "sink=<sink to connect to> "
83 "source=<source to connect to> "
84 "playback=<enable playback?> "
85 "record=<enable record?> "
87 #elif defined(USE_PROTOCOL_CLI)
88 #include <pulsecore/protocol-cli.h>
89 #define protocol_new pa_protocol_cli_new
90 #define protocol_free pa_protocol_cli_free
91 #define TCPWRAP_SERVICE "pulseaudio-cli"
92 #define IPV4_PORT 4712
93 #define UNIX_SOCKET "cli"
94 #define MODULE_ARGUMENTS
95 #ifdef USE_TCP_SOCKETS
96 #include "module-cli-protocol-tcp-symdef.h"
98 #include "module-cli-protocol-unix-symdef.h"
100 PA_MODULE_DESCRIPTION("Command line interface protocol "SOCKET_DESCRIPTION
)
101 PA_MODULE_USAGE(SOCKET_USAGE
)
102 #elif defined(USE_PROTOCOL_HTTP)
103 #include <pulsecore/protocol-http.h>
104 #define protocol_new pa_protocol_http_new
105 #define protocol_free pa_protocol_http_free
106 #define TCPWRAP_SERVICE "pulseaudio-http"
107 #define IPV4_PORT 4714
108 #define UNIX_SOCKET "http"
109 #define MODULE_ARGUMENTS
110 #ifdef USE_TCP_SOCKETS
111 #include "module-http-protocol-tcp-symdef.h"
113 #include "module-http-protocol-unix-symdef.h"
115 PA_MODULE_DESCRIPTION("HTTP "SOCKET_DESCRIPTION
)
116 PA_MODULE_USAGE(SOCKET_USAGE
)
117 #elif defined(USE_PROTOCOL_NATIVE)
118 #include <pulsecore/protocol-native.h>
119 #define protocol_new pa_protocol_native_new
120 #define protocol_free pa_protocol_native_free
121 #define TCPWRAP_SERVICE "pulseaudio-native"
122 #define IPV4_PORT PA_NATIVE_DEFAULT_PORT
123 #define UNIX_SOCKET PA_NATIVE_DEFAULT_UNIX_SOCKET
124 #define MODULE_ARGUMENTS_COMMON "cookie", "auth-anonymous",
125 #ifdef USE_TCP_SOCKETS
126 #include "module-native-protocol-tcp-symdef.h"
128 #include "module-native-protocol-unix-symdef.h"
131 #if defined(HAVE_CREDS) && !defined(USE_TCP_SOCKETS)
132 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group", "auth-group-enable="
133 #define AUTH_USAGE "auth-group=<system group to allow access> auth-group-enable=<enable auth by UNIX group?> "
135 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
139 PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION
)
140 PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> "
141 "cookie=<path to cookie file> "
144 #elif defined(USE_PROTOCOL_ESOUND)
145 #include <pulsecore/protocol-esound.h>
146 #include <pulsecore/esound.h>
147 #define protocol_new pa_protocol_esound_new
148 #define protocol_free pa_protocol_esound_free
149 #define TCPWRAP_SERVICE "esound"
150 #define IPV4_PORT ESD_DEFAULT_PORT
151 #define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
152 #define MODULE_ARGUMENTS "sink", "source", "auth-anonymous", "cookie",
153 #ifdef USE_TCP_SOCKETS
154 #include "module-esound-protocol-tcp-symdef.h"
156 #include "module-esound-protocol-unix-symdef.h"
158 PA_MODULE_DESCRIPTION("ESOUND protocol "SOCKET_DESCRIPTION
)
159 PA_MODULE_USAGE("sink=<sink to connect to> "
160 "source=<source to connect to> "
161 "auth-anonymous=<don't verify cookies?> "
162 "cookie=<path to cookie file> "
165 #error "Broken build system"
168 PA_MODULE_AUTHOR("Lennart Poettering")
169 PA_MODULE_VERSION(PACKAGE_VERSION
)
171 static const char* const valid_modargs
[] = {
173 #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
;
200 uint32_t port
= IPV4_PORT
;
201 const char *listen_on
;
210 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
211 pa_log(__FILE__
": Failed to parse module arguments");
215 u
= pa_xnew0(struct userdata
, 1);
217 #if defined(USE_TCP_SOCKETS)
218 if (pa_modargs_get_value_u32(ma
, "port", &port
) < 0 || port
< 1 || port
> 0xFFFF) {
219 pa_log(__FILE__
": port= expects a numerical argument between 1 and 65535.");
223 listen_on
= pa_modargs_get_value(ma
, "listen", NULL
);
226 s_ipv6
= pa_socket_server_new_ipv6_string(c
->mainloop
, listen_on
, port
, TCPWRAP_SERVICE
);
227 s_ipv4
= pa_socket_server_new_ipv4_string(c
->mainloop
, listen_on
, port
, TCPWRAP_SERVICE
);
229 s_ipv6
= pa_socket_server_new_ipv6_any(c
->mainloop
, port
, TCPWRAP_SERVICE
);
230 s_ipv4
= pa_socket_server_new_ipv4_any(c
->mainloop
, port
, TCPWRAP_SERVICE
);
233 if (!s_ipv4
&& !s_ipv6
)
237 if (!(u
->protocol_ipv4
= protocol_new(c
, s_ipv4
, m
, ma
)))
238 pa_socket_server_unref(s_ipv4
);
241 if (!(u
->protocol_ipv6
= protocol_new(c
, s_ipv6
, m
, ma
)))
242 pa_socket_server_unref(s_ipv6
);
244 if (!u
->protocol_ipv4
&& !u
->protocol_ipv6
)
249 pa_runtime_path(pa_modargs_get_value(ma
, "socket", UNIX_SOCKET
), tmp
, sizeof(tmp
));
250 u
->socket_path
= pa_xstrdup(tmp
);
252 #if defined(USE_PROTOCOL_ESOUND)
254 /* This socket doesn't reside in our own runtime dir but in
255 * /tmp/.esd/, hence we have to create the dir first */
257 if (pa_make_secure_parent_dir(u
->socket_path
, c
->is_system_instance
? 0755 : 0700, (uid_t
)-1, (gid_t
)-1) < 0) {
258 pa_log(__FILE__
": Failed to create socket directory: %s\n", pa_cstrerror(errno
));
263 if ((r
= pa_unix_socket_remove_stale(tmp
)) < 0) {
264 pa_log(__FILE__
": Failed to remove stale UNIX socket '%s': %s", tmp
, pa_cstrerror(errno
));
269 pa_log(__FILE__
": Removed stale UNIX socket '%s'.", tmp
);
271 if (!(s
= pa_socket_server_new_unix(c
->mainloop
, tmp
)))
274 if (!(u
->protocol_unix
= protocol_new(c
, s
, m
, ma
)))
291 #if defined(USE_TCP_SOCKETS)
292 if (u
->protocol_ipv4
)
293 protocol_free(u
->protocol_ipv4
);
294 if (u
->protocol_ipv6
)
295 protocol_free(u
->protocol_ipv6
);
297 if (u
->protocol_unix
)
298 protocol_free(u
->protocol_unix
);
301 pa_xfree(u
->socket_path
);
306 #if defined(USE_TCP_SOCKETS)
308 pa_socket_server_unref(s_ipv4
);
310 pa_socket_server_unref(s_ipv6
);
313 pa_socket_server_unref(s
);
320 void pa__done(pa_core
*c
, pa_module
*m
) {
328 #if defined(USE_TCP_SOCKETS)
329 if (u
->protocol_ipv4
)
330 protocol_free(u
->protocol_ipv4
);
331 if (u
->protocol_ipv6
)
332 protocol_free(u
->protocol_ipv6
);
334 if (u
->protocol_unix
)
335 protocol_free(u
->protocol_unix
);
337 #if defined(USE_PROTOCOL_ESOUND)
338 if (u
->socket_path
) {
339 char *p
= pa_parent_dir(u
->socket_path
);
346 pa_xfree(u
->socket_path
);