2004-07-16 19:56:36 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
This file is part of polypaudio.
|
|
|
|
|
|
|
|
|
|
polypaudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published
|
|
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
polypaudio 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 General Public License
|
|
|
|
|
along with polypaudio; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-07-06 00:08:44 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
2004-06-29 16:48:37 +00:00
|
|
|
#include <stdio.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <arpa/inet.h>
|
2004-06-29 16:48:37 +00:00
|
|
|
#include <unistd.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
|
#include "socket-server.h"
|
2004-07-11 01:09:46 +00:00
|
|
|
#include "socket-util.h"
|
2004-06-29 16:48:37 +00:00
|
|
|
#include "util.h"
|
2004-07-11 22:20:08 +00:00
|
|
|
#include "modargs.h"
|
2004-06-19 18:51:30 +00:00
|
|
|
|
|
|
|
|
#ifdef USE_PROTOCOL_SIMPLE
|
|
|
|
|
#include "protocol-simple.h"
|
2004-07-11 22:20:08 +00:00
|
|
|
#define protocol_new pa_protocol_simple_new
|
2004-07-03 23:35:12 +00:00
|
|
|
#define protocol_free pa_protocol_simple_free
|
2004-06-20 01:12:13 +00:00
|
|
|
#define IPV4_PORT 4711
|
2004-06-29 16:48:37 +00:00
|
|
|
#define UNIX_SOCKET "/tmp/polypaudio/simple"
|
2004-07-11 22:20:08 +00:00
|
|
|
#define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
|
2004-06-19 18:51:30 +00:00
|
|
|
#else
|
|
|
|
|
#ifdef USE_PROTOCOL_CLI
|
|
|
|
|
#include "protocol-cli.h"
|
2004-07-03 23:35:12 +00:00
|
|
|
#define protocol_new pa_protocol_cli_new
|
|
|
|
|
#define protocol_free pa_protocol_cli_free
|
2004-06-20 01:12:13 +00:00
|
|
|
#define IPV4_PORT 4712
|
2004-06-29 16:48:37 +00:00
|
|
|
#define UNIX_SOCKET "/tmp/polypaudio/cli"
|
2004-07-11 22:20:08 +00:00
|
|
|
#define MODULE_ARGUMENTS
|
2004-06-19 18:51:30 +00:00
|
|
|
#else
|
2004-06-20 01:12:13 +00:00
|
|
|
#ifdef USE_PROTOCOL_NATIVE
|
|
|
|
|
#include "protocol-native.h"
|
2004-07-03 23:35:12 +00:00
|
|
|
#define protocol_new pa_protocol_native_new
|
|
|
|
|
#define protocol_free pa_protocol_native_free
|
2004-06-20 01:12:13 +00:00
|
|
|
#define IPV4_PORT 4713
|
2004-06-29 16:48:37 +00:00
|
|
|
#define UNIX_SOCKET "/tmp/polypaudio/native"
|
2004-07-11 22:20:08 +00:00
|
|
|
#define MODULE_ARGUMENTS "public", "cookie",
|
2004-06-20 01:12:13 +00:00
|
|
|
#else
|
2004-06-29 16:48:37 +00:00
|
|
|
#ifdef USE_PROTOCOL_ESOUND
|
|
|
|
|
#include "protocol-esound.h"
|
2004-07-16 18:58:23 +00:00
|
|
|
#include "esound.h"
|
2004-07-03 23:35:12 +00:00
|
|
|
#define protocol_new pa_protocol_esound_new
|
|
|
|
|
#define protocol_free pa_protocol_esound_free
|
2004-06-29 16:48:37 +00:00
|
|
|
#define IPV4_PORT ESD_DEFAULT_PORT
|
|
|
|
|
#define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
|
2004-07-11 22:20:08 +00:00
|
|
|
#define MODULE_ARGUMENTS "sink", "source", "public", "cookie",
|
2004-06-29 16:48:37 +00:00
|
|
|
#else
|
|
|
|
|
#error "Broken build system"
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2004-06-19 18:51:30 +00:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-11 22:20:08 +00:00
|
|
|
static const char* const valid_modargs[] = {
|
|
|
|
|
MODULE_ARGUMENTS
|
|
|
|
|
#ifdef USE_TCP_SOCKETS
|
|
|
|
|
"port",
|
|
|
|
|
"loopback",
|
|
|
|
|
#else
|
|
|
|
|
"socket",
|
|
|
|
|
#endif
|
|
|
|
|
NULL
|
|
|
|
|
};
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-16 17:56:35 +00:00
|
|
|
static struct pa_socket_server *create_socket_server(struct pa_core *c, struct pa_modargs *ma) {
|
2004-07-11 22:20:08 +00:00
|
|
|
struct pa_socket_server *s;
|
2004-06-19 18:41:24 +00:00
|
|
|
#ifdef USE_TCP_SOCKETS
|
2004-07-17 14:06:13 +00:00
|
|
|
uint32_t loopback = 1, port = IPV4_PORT;
|
2004-07-11 22:20:08 +00:00
|
|
|
|
|
|
|
|
if (pa_modargs_get_value_u32(ma, "loopback", &loopback) < 0) {
|
|
|
|
|
fprintf(stderr, "loopback= expects a numerical argument.\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pa_modargs_get_value_u32(ma, "port", &port) < 0) {
|
|
|
|
|
fprintf(stderr, "port= expects a numerical argument.\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(s = pa_socket_server_new_ipv4(c->mainloop, loopback ? INADDR_LOOPBACK : INADDR_ANY, port)))
|
|
|
|
|
return NULL;
|
2004-06-19 18:41:24 +00:00
|
|
|
#else
|
2004-07-11 22:20:08 +00:00
|
|
|
int r;
|
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
|
|
p = pa_modargs_get_value(ma, "socket", UNIX_SOCKET);
|
|
|
|
|
assert(p);
|
|
|
|
|
|
|
|
|
|
if (pa_unix_socket_make_secure_dir(p) < 0) {
|
2004-06-29 16:48:37 +00:00
|
|
|
fprintf(stderr, "Failed to create secure socket directory.\n");
|
2004-07-11 22:20:08 +00:00
|
|
|
return NULL;
|
2004-06-29 16:48:37 +00:00
|
|
|
}
|
2004-07-06 00:08:44 +00:00
|
|
|
|
2004-07-11 22:20:08 +00:00
|
|
|
if ((r = pa_unix_socket_remove_stale(p)) < 0) {
|
|
|
|
|
fprintf(stderr, "Failed to remove stale UNIX socket '%s': %s\n", p, strerror(errno));
|
|
|
|
|
return NULL;
|
2004-07-06 00:08:44 +00:00
|
|
|
}
|
2004-06-29 16:48:37 +00:00
|
|
|
|
2004-07-11 22:20:08 +00:00
|
|
|
if (r)
|
|
|
|
|
fprintf(stderr, "Removed stale UNIX socket '%s'.", p);
|
|
|
|
|
|
|
|
|
|
if (!(s = pa_socket_server_new_unix(c->mainloop, p)))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa_module_init(struct pa_core *c, struct pa_module*m) {
|
|
|
|
|
struct pa_socket_server *s;
|
2004-07-15 17:33:56 +00:00
|
|
|
struct pa_modargs *ma = NULL;
|
|
|
|
|
int ret = -1;
|
2004-07-11 22:20:08 +00:00
|
|
|
assert(c && m);
|
|
|
|
|
|
|
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
|
|
|
|
fprintf(stderr, "Failed to parse module arguments\n");
|
2004-07-15 17:33:56 +00:00
|
|
|
goto finish;
|
2004-06-29 16:48:37 +00:00
|
|
|
}
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-11 22:20:08 +00:00
|
|
|
if (!(s = create_socket_server(c, ma)))
|
2004-07-15 17:33:56 +00:00
|
|
|
goto finish;
|
2004-07-06 00:08:44 +00:00
|
|
|
|
2004-07-11 22:20:08 +00:00
|
|
|
if (!(m->userdata = protocol_new(c, s, m, ma))) {
|
2004-08-15 00:02:26 +00:00
|
|
|
pa_socket_server_unref(s);
|
2004-07-15 17:33:56 +00:00
|
|
|
goto finish;
|
2004-07-06 00:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-15 17:33:56 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
|
|
|
|
|
|
|
|
|
return ret;
|
2004-06-08 23:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-07 00:22:46 +00:00
|
|
|
void pa_module_done(struct pa_core *c, struct pa_module*m) {
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(c && m);
|
|
|
|
|
|
2004-06-19 19:27:47 +00:00
|
|
|
protocol_free(m->userdata);
|
2004-06-08 23:54:24 +00:00
|
|
|
}
|