]>
code.delx.au - pulseaudio/blob - src/modules/module-protocol-stub.c
2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 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 <pulse/xmalloc.h>
45 #include <pulsecore/winsock.h>
46 #include <pulsecore/core-error.h>
47 #include <pulsecore/module.h>
48 #include <pulsecore/socket-server.h>
49 #include <pulsecore/socket-util.h>
50 #include <pulsecore/core-util.h>
51 #include <pulsecore/modargs.h>
52 #include <pulsecore/log.h>
53 #include <pulsecore/native-common.h>
54 #include <pulsecore/creds.h>
56 #ifdef USE_TCP_SOCKETS
57 #define SOCKET_DESCRIPTION "(TCP sockets)"
58 #define SOCKET_USAGE "port=<TCP port number> 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(HAVE_CREDS) && !defined(USE_TCP_SOCKETS)
131 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group", "auth-group-enable",
132 #define AUTH_USAGE "auth-group=<system group to allow access> auth-group-enable=<enable auth by UNIX group?> "
133 #elif defined(USE_TCP_SOCKETS)
134 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl",
135 #define AUTH_USAGE "auth-ip-acl=<IP address ACL to allow access> "
137 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
141 PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION
);
142 PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> "
143 "cookie=<path to cookie file> "
146 #elif defined(USE_PROTOCOL_ESOUND)
147 #include <pulsecore/protocol-esound.h>
148 #include <pulsecore/esound.h>
149 #define protocol_new pa_protocol_esound_new
150 #define protocol_free pa_protocol_esound_free
151 #define TCPWRAP_SERVICE "esound"
152 #define IPV4_PORT ESD_DEFAULT_PORT
153 #define MODULE_ARGUMENTS_COMMON "sink", "source", "auth-anonymous", "cookie",
154 #ifdef USE_TCP_SOCKETS
155 #include "module-esound-protocol-tcp-symdef.h"
157 #include "module-esound-protocol-unix-symdef.h"
160 #if defined(USE_TCP_SOCKETS)
161 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl",
162 #define AUTH_USAGE "auth-ip-acl=<IP address ACL to allow access> "
164 #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
168 PA_MODULE_DESCRIPTION("ESOUND protocol "SOCKET_DESCRIPTION
);
169 PA_MODULE_USAGE("sink=<sink to connect to> "
170 "source=<source to connect to> "
171 "auth-anonymous=<don't verify cookies?> "
172 "cookie=<path to cookie file> "
176 #error "Broken build system"
179 PA_MODULE_LOAD_ONCE(FALSE
);
180 PA_MODULE_AUTHOR("Lennart Poettering");
181 PA_MODULE_VERSION(PACKAGE_VERSION
);
183 static const char* const valid_modargs
[] = {
185 #if defined(USE_TCP_SOCKETS)
195 #if defined(USE_TCP_SOCKETS)
204 int pa__init(pa_module
*m
) {
205 pa_modargs
*ma
= NULL
;
207 struct userdata
*u
= NULL
;
209 #if defined(USE_TCP_SOCKETS)
210 pa_socket_server
*s_ipv4
= NULL
, *s_ipv6
= NULL
;
211 uint32_t port
= IPV4_PORT
;
212 const char *listen_on
;
220 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
221 pa_log("Failed to parse module arguments");
225 u
= pa_xnew0(struct userdata
, 1);
227 #if defined(USE_TCP_SOCKETS)
228 if (pa_modargs_get_value_u32(ma
, "port", &port
) < 0 || port
< 1 || port
> 0xFFFF) {
229 pa_log("port= expects a numerical argument between 1 and 65535.");
233 listen_on
= pa_modargs_get_value(ma
, "listen", NULL
);
236 s_ipv6
= pa_socket_server_new_ipv6_string(m
->core
->mainloop
, listen_on
, port
, TCPWRAP_SERVICE
);
237 s_ipv4
= pa_socket_server_new_ipv4_string(m
->core
->mainloop
, listen_on
, port
, TCPWRAP_SERVICE
);
239 s_ipv6
= pa_socket_server_new_ipv6_any(m
->core
->mainloop
, port
, TCPWRAP_SERVICE
);
240 s_ipv4
= pa_socket_server_new_ipv4_any(m
->core
->mainloop
, port
, TCPWRAP_SERVICE
);
243 if (!s_ipv4
&& !s_ipv6
)
247 u
->protocol_ipv4
= protocol_new(m
->core
, s_ipv4
, m
, ma
);
249 u
->protocol_ipv6
= protocol_new(m
->core
, s_ipv6
, m
, ma
);
251 if (!u
->protocol_ipv4
&& !u
->protocol_ipv6
)
255 pa_socket_server_unref(s_ipv6
);
257 pa_socket_server_unref(s_ipv4
);
261 #if defined(USE_PROTOCOL_ESOUND)
263 #if defined(USE_PER_USER_ESOUND_SOCKET)
264 u
->socket_path
= pa_sprintf_malloc("/tmp/.esd-%lu/socket", (unsigned long) getuid());
266 u
->socket_path
= pa_xstrdup("/tmp/.esd/socket");
269 /* This socket doesn't reside in our own runtime dir but in
270 * /tmp/.esd/, hence we have to create the dir first */
272 if (pa_make_secure_parent_dir(u
->socket_path
, pa_in_system_mode() ? 0755 : 0700, (uid_t
)-1, (gid_t
)-1) < 0) {
273 pa_log("Failed to create socket directory '%s': %s\n", u
->socket_path
, pa_cstrerror(errno
));
278 if (!(u
->socket_path
= pa_runtime_path(pa_modargs_get_value(ma
, "socket", UNIX_SOCKET
)))) {
279 pa_log("Failed to generate socket path.");
284 if ((r
= pa_unix_socket_remove_stale(u
->socket_path
)) < 0) {
285 pa_log("Failed to remove stale UNIX socket '%s': %s", u
->socket_path
, pa_cstrerror(errno
));
288 pa_log_info("Removed stale UNIX socket '%s'.", u
->socket_path
);
290 if (!(s
= pa_socket_server_new_unix(m
->core
->mainloop
, u
->socket_path
)))
293 if (!(u
->protocol_unix
= protocol_new(m
->core
, s
, m
, ma
)))
296 pa_socket_server_unref(s
);
312 #if defined(USE_TCP_SOCKETS)
313 if (u
->protocol_ipv4
)
314 protocol_free(u
->protocol_ipv4
);
315 if (u
->protocol_ipv6
)
316 protocol_free(u
->protocol_ipv6
);
318 if (u
->protocol_unix
)
319 protocol_free(u
->protocol_unix
);
320 pa_xfree(u
->socket_path
);
326 #if defined(USE_TCP_SOCKETS)
328 pa_socket_server_unref(s_ipv4
);
330 pa_socket_server_unref(s_ipv6
);
333 pa_socket_server_unref(s
);
339 void pa__done(pa_module
*m
) {
346 #if defined(USE_TCP_SOCKETS)
347 if (u
->protocol_ipv4
)
348 protocol_free(u
->protocol_ipv4
);
349 if (u
->protocol_ipv6
)
350 protocol_free(u
->protocol_ipv6
);
352 if (u
->protocol_unix
)
353 protocol_free(u
->protocol_unix
);
355 #if defined(USE_PROTOCOL_ESOUND) && !defined(USE_PER_USER_ESOUND_SOCKET)
356 if (u
->socket_path
) {
357 char *p
= pa_parent_dir(u
->socket_path
);
363 pa_xfree(u
->socket_path
);