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
+ it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
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
+ You should have received a copy of the GNU Lesser 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.
#include "authkey.h"
#include "socket-client.h"
#include "socket-util.h"
-
-PA_MODULE_AUTHOR("Lennart Poettering")
-PA_MODULE_VERSION(PACKAGE_VERSION)
+#include "authkey-prop.h"
#ifdef TUNNEL_SINK
+#include "module-tunnel-sink-symdef.h"
PA_MODULE_DESCRIPTION("Tunnel module for sinks")
-PA_MODULE_USAGE("server=<filename> sink=<remote sink name> cookie=<filename> format=<sample format> channels=<number of channels> rate=<sample rate> sink_name=<name for the local sink>")
+PA_MODULE_USAGE("server=<address> sink=<remote sink name> cookie=<filename> format=<sample format> channels=<number of channels> rate=<sample rate> sink_name=<name for the local sink>")
#else
+#include "module-tunnel-source-symdef.h"
PA_MODULE_DESCRIPTION("Tunnel module for sources")
-PA_MODULE_USAGE("server=<filename> source=<remote source name> cookie=<filename> format=<sample format> channels=<number of channels> rate=<sample rate> source_name=<name for the local source>")
+PA_MODULE_USAGE("server=<address> source=<remote source name> cookie=<filename> format=<sample format> channels=<number of channels> rate=<sample rate> source_name=<name for the local source>")
#endif
+PA_MODULE_AUTHOR("Lennart Poettering")
+PA_MODULE_VERSION(PACKAGE_VERSION)
+
#define DEFAULT_SINK_NAME "tunnel"
#define DEFAULT_SOURCE_NAME "tunnel"
pa_usec_t host_latency;
struct pa_time_event *time_event;
-};
+ int auth_cookie_in_property;
+};
static void close_stuff(struct userdata *u) {
+ assert(u);
+
if (u->pstream) {
pa_pstream_close(u->pstream);
pa_pstream_unref(u->pstream);
m->time_restart(e, &ntv);
}
+static int load_key(struct userdata *u, const char*fn) {
+ assert(u);
+
+ u->auth_cookie_in_property = 0;
+
+ if (!fn && pa_authkey_prop_get(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0) {
+ pa_log(__FILE__": using already loaded auth cookie.\n");
+ pa_authkey_prop_ref(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
+ u->auth_cookie_in_property = 1;
+ return 0;
+ }
+
+ if (!fn)
+ fn = PA_NATIVE_COOKIE_FILE;
+
+ if (pa_authkey_load_from_home(fn, u->auth_cookie, sizeof(u->auth_cookie)) < 0)
+ return -1;
+
+ pa_log(__FILE__": loading cookie from disk.\n");
+
+ if (pa_authkey_prop_put(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0)
+ u->auth_cookie_in_property = 1;
+
+ return 0;
+}
+
int pa__init(struct pa_core *c, struct pa_module*m) {
struct pa_modargs *ma = NULL;
struct userdata *u = NULL;
u->ctag = 1;
u->device_index = u->channel = PA_INVALID_INDEX;
u->host_latency = 0;
-
- if (pa_authkey_load_from_home(pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), u->auth_cookie, sizeof(u->auth_cookie)) < 0) {
- pa_log(__FILE__": failed to load cookie.\n");
+ u->auth_cookie_in_property = 0;
+ u->time_event = NULL;
+
+ if (load_key(u, pa_modargs_get_value(ma, "cookie", NULL)) < 0)
goto fail;
- }
if (!(u->server_name = pa_xstrdup(pa_modargs_get_value(ma, "server", NULL)))) {
pa_log(__FILE__": no server specified.\n");
close_stuff(u);
+ if (u->auth_cookie_in_property)
+ pa_authkey_prop_unref(c, PA_NATIVE_COOKIE_PROPERTY_NAME);
+
#ifdef TUNNEL_SINK
pa_xfree(u->sink_name);
#else