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-06-29 16:48:37 +00:00
|
|
|
#include "util.h"
|
2004-06-19 18:51:30 +00:00
|
|
|
|
|
|
|
|
#ifdef USE_PROTOCOL_SIMPLE
|
|
|
|
|
#include "protocol-simple.h"
|
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_DIR "/tmp/polypaudio"
|
|
|
|
|
#define UNIX_SOCKET "/tmp/polypaudio/simple"
|
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_DIR "/tmp/polypaudio"
|
|
|
|
|
#define UNIX_SOCKET "/tmp/polypaudio/cli"
|
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_DIR "/tmp/polypaudio"
|
|
|
|
|
#define UNIX_SOCKET "/tmp/polypaudio/native"
|
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"
|
|
|
|
|
#include "esound-spec.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_DIR ESD_UNIX_SOCKET_DIR
|
|
|
|
|
#define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
|
|
|
|
|
#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-03 23:35:12 +00:00
|
|
|
int module_init(struct pa_core *c, struct pa_module*m) {
|
|
|
|
|
struct pa_socket_server *s;
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(c && m);
|
|
|
|
|
|
2004-06-19 18:41:24 +00:00
|
|
|
#ifdef USE_TCP_SOCKETS
|
2004-07-03 23:35:12 +00:00
|
|
|
if (!(s = pa_socket_server_new_ipv4(c->mainloop, INADDR_LOOPBACK, IPV4_PORT)))
|
2004-06-08 23:54:24 +00:00
|
|
|
return -1;
|
2004-06-19 18:41:24 +00:00
|
|
|
#else
|
2004-07-03 23:35:12 +00:00
|
|
|
if (pa_make_secure_dir(UNIX_SOCKET_DIR) < 0) {
|
2004-06-29 16:48:37 +00:00
|
|
|
fprintf(stderr, "Failed to create secure socket directory.\n");
|
2004-06-19 18:41:24 +00:00
|
|
|
return -1;
|
2004-06-29 16:48:37 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
if (!(s = pa_socket_server_new_unix(c->mainloop, UNIX_SOCKET))) {
|
2004-06-29 16:48:37 +00:00
|
|
|
rmdir(UNIX_SOCKET_DIR);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2004-06-19 18:41:24 +00:00
|
|
|
#endif
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-06-19 18:51:30 +00:00
|
|
|
#ifdef USE_PROTOCOL_SIMPLE
|
2004-07-03 23:35:12 +00:00
|
|
|
m->userdata = pa_protocol_simple_new(c, s, PA_PROTOCOL_SIMPLE_PLAYBACK);
|
2004-06-19 18:51:30 +00:00
|
|
|
#else
|
|
|
|
|
m->userdata = protocol_new(c, s);
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(m->userdata);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
void 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-29 16:48:37 +00:00
|
|
|
|
|
|
|
|
#ifndef USE_TCP_SOCKETS
|
|
|
|
|
rmdir(UNIX_SOCKET_DIR);
|
|
|
|
|
#endif
|
2004-06-08 23:54:24 +00:00
|
|
|
}
|