summaryrefslogtreecommitdiffstats
path: root/polyp/protocol-native.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-11-07 20:48:46 +0000
committerLennart Poettering <lennart@poettering.net>2004-11-07 20:48:46 +0000
commitb55923a8d33a1c4ed2f892a0da36c9c679e7d828 (patch)
treece438dbabea11c10a531afa540ef120948014f5d /polyp/protocol-native.c
parent5844a33f0be1af942ee33feae38b9d46169fd61c (diff)
* Look for M4 in configure.ac
* Share auth cookies in module-tunnel.c, module-x11-publish.c and native-protocol.c * disable TCP_NODELAY * publish auth cookie in module-x11-publish git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@274 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/protocol-native.c')
-rw-r--r--polyp/protocol-native.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/polyp/protocol-native.c b/polyp/protocol-native.c
index 6f3f82be..fade2a2f 100644
--- a/polyp/protocol-native.c
+++ b/polyp/protocol-native.c
@@ -46,6 +46,7 @@
#include "subscribe.h"
#include "log.h"
#include "autoload.h"
+#include "authkey-prop.h"
struct connection;
struct pa_protocol_native;
@@ -106,6 +107,7 @@ struct pa_protocol_native {
struct pa_socket_server *server;
struct pa_idxset *connections;
uint8_t auth_cookie[PA_NATIVE_COOKIE_LENGTH];
+ int auth_cookie_in_property;
};
static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk);
@@ -2008,6 +2010,32 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
/*** module entry points ***/
+static int load_key(struct pa_protocol_native*p, const char*fn) {
+ assert(p);
+
+ p->auth_cookie_in_property = 0;
+
+ if (!fn && pa_authkey_prop_get(p->core, PA_NATIVE_COOKIE_PROPERTY_NAME, p->auth_cookie, sizeof(p->auth_cookie)) >= 0) {
+ pa_log(__FILE__": using already loaded auth cookie.\n");
+ pa_authkey_prop_ref(p->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
+ p->auth_cookie_in_property = 1;
+ return 0;
+ }
+
+ if (!fn)
+ fn = PA_NATIVE_COOKIE_FILE;
+
+ if (pa_authkey_load_from_home(fn, p->auth_cookie, sizeof(p->auth_cookie)) < 0)
+ return -1;
+
+ pa_log(__FILE__": loading cookie from disk.\n");
+
+ if (pa_authkey_prop_put(p->core, PA_NATIVE_COOKIE_PROPERTY_NAME, p->auth_cookie, sizeof(p->auth_cookie)) >= 0)
+ p->auth_cookie_in_property = 1;
+
+ return 0;
+}
+
static struct pa_protocol_native* protocol_new_internal(struct pa_core *c, struct pa_module *m, struct pa_modargs *ma) {
struct pa_protocol_native *p;
int public = 0;
@@ -2019,16 +2047,16 @@ static struct pa_protocol_native* protocol_new_internal(struct pa_core *c, struc
}
p = pa_xmalloc(sizeof(struct pa_protocol_native));
+ p->core = c;
+ p->module = m;
+ p->public = public;
+ p->server = NULL;
- if (pa_authkey_load_from_home(pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), p->auth_cookie, sizeof(p->auth_cookie)) < 0) {
+ if (load_key(p, pa_modargs_get_value(ma, "cookie", NULL)) < 0) {
pa_xfree(p);
return NULL;
}
- p->module = m;
- p->public = public;
- p->server = NULL;
- p->core = c;
p->connections = pa_idxset_new(NULL, NULL);
assert(p->connections);
@@ -2057,7 +2085,10 @@ void pa_protocol_native_free(struct pa_protocol_native *p) {
if (p->server)
pa_socket_server_unref(p->server);
-
+
+ if (p->auth_cookie_in_property)
+ pa_authkey_prop_unref(p->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
+
pa_xfree(p);
}