2004-07-16 19:56:36 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2004-07-16 19:56:36 +00:00
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
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.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
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-06-19 19:27:47 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/cli.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-06-19 19:27:47 +00:00
|
|
|
#include "protocol-cli.h"
|
2004-11-18 00:28:26 +00:00
|
|
|
|
|
|
|
|
/* Don't allow more than this many concurrent connections */
|
2005-09-16 00:08:53 +00:00
|
|
|
#define MAX_CONNECTIONS 25
|
2004-06-19 19:27:47 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
struct pa_protocol_cli {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_module *module;
|
|
|
|
|
pa_core *core;
|
|
|
|
|
pa_socket_server*server;
|
|
|
|
|
pa_idxset *connections;
|
2004-06-19 19:27:47 +00:00
|
|
|
};
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static void cli_eof_cb(pa_cli*c, void*userdata) {
|
|
|
|
|
pa_protocol_cli *p = userdata;
|
2004-06-23 23:17:30 +00:00
|
|
|
assert(p);
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_remove_by_data(p->connections, c, NULL);
|
|
|
|
|
pa_cli_free(c);
|
2004-06-19 19:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) {
|
|
|
|
|
pa_protocol_cli *p = userdata;
|
|
|
|
|
pa_cli *c;
|
2004-06-19 19:27:47 +00:00
|
|
|
assert(s && io && p);
|
2004-06-23 23:17:30 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
|
2004-11-18 00:28:26 +00:00
|
|
|
pa_iochannel_free(io);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-07-10 20:56:38 +00:00
|
|
|
c = pa_cli_new(p->core, io, p->module);
|
2004-06-19 19:27:47 +00:00
|
|
|
assert(c);
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_cli_set_eof_callback(c, cli_eof_cb, p);
|
2004-06-19 19:27:47 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_put(p->connections, c, NULL);
|
2004-06-19 19:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_protocol_cli* pa_protocol_cli_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) {
|
|
|
|
|
pa_protocol_cli* p;
|
2004-06-19 19:27:47 +00:00
|
|
|
assert(core && server);
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
p = pa_xmalloc(sizeof(pa_protocol_cli));
|
2004-07-10 20:56:38 +00:00
|
|
|
p->module = m;
|
2004-06-19 19:27:47 +00:00
|
|
|
p->core = core;
|
|
|
|
|
p->server = server;
|
2004-07-03 23:35:12 +00:00
|
|
|
p->connections = pa_idxset_new(NULL, NULL);
|
2004-06-19 19:27:47 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_socket_server_set_callback(p->server, on_connection, p);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-06-19 19:27:47 +00:00
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static void free_connection(void *p, PA_GCC_UNUSED void *userdata) {
|
2004-06-19 19:27:47 +00:00
|
|
|
assert(p);
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_cli_free(p);
|
2004-06-19 19:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_protocol_cli_free(pa_protocol_cli *p) {
|
2004-06-19 19:27:47 +00:00
|
|
|
assert(p);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_free(p->connections, free_connection, NULL);
|
2004-08-15 00:02:26 +00:00
|
|
|
pa_socket_server_unref(p->server);
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(p);
|
2004-06-19 19:27:47 +00:00
|
|
|
}
|