]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/auth-cookie.c
bluez5-util: Free the adapter_path in device_free().
[pulseaudio] / src / pulsecore / auth-cookie.c
index 2f45eca07631cc7798123a71d689bd149099d143..a3d9ca4784d6c1bed93bf5543c13cf120be61c3e 100644 (file)
@@ -26,7 +26,6 @@
 #include <sys/types.h>
 
 #include <pulse/xmalloc.h>
-#include <pulse/util.h>
 
 #include <pulsecore/refcnt.h>
 #include <pulsecore/macro.h>
@@ -43,7 +42,7 @@ struct pa_auth_cookie {
     size_t size;
 };
 
-pa_auth_cookie* pa_auth_cookie_get(pa_core *core, const char *cn, size_t size) {
+pa_auth_cookie* pa_auth_cookie_get(pa_core *core, const char *cn, bool create, size_t size) {
     pa_auth_cookie *c;
     char *t;
 
@@ -70,7 +69,7 @@ pa_auth_cookie* pa_auth_cookie_get(pa_core *core, const char *cn, size_t size) {
 
     pa_assert_se(pa_shared_set(core, t, c) >= 0);
 
-    if (pa_authkey_load_auto(cn, (uint8_t*) c + PA_ALIGN(sizeof(pa_auth_cookie)), size) < 0) {
+    if (pa_authkey_load_auto(cn, create, (uint8_t*) c + PA_ALIGN(sizeof(pa_auth_cookie)), size) < 0) {
         pa_auth_cookie_unref(c);
         return NULL;
     }
@@ -78,6 +77,39 @@ pa_auth_cookie* pa_auth_cookie_get(pa_core *core, const char *cn, size_t size) {
     return c;
 }
 
+pa_auth_cookie *pa_auth_cookie_create(pa_core *core, const void *data, size_t size) {
+    pa_auth_cookie *c;
+    char *t;
+
+    pa_assert(core);
+    pa_assert(data);
+    pa_assert(size > 0);
+
+    t = pa_xstrdup("auth-cookie");
+
+    if ((c = pa_shared_get(core, t))) {
+
+        pa_xfree(t);
+
+        if (c->size != size)
+            return NULL;
+
+        return pa_auth_cookie_ref(c);
+    }
+
+    c = pa_xmalloc(PA_ALIGN(sizeof(pa_auth_cookie)) + size);
+    PA_REFCNT_INIT(c);
+    c->core = core;
+    c->name = t;
+    c->size = size;
+
+    pa_assert_se(pa_shared_set(core, t, c) >= 0);
+
+    memcpy((uint8_t *) c + PA_ALIGN(sizeof(pa_auth_cookie)), data, size);
+
+    return c;
+}
+
 pa_auth_cookie* pa_auth_cookie_ref(pa_auth_cookie *c) {
     pa_assert(c);
     pa_assert(PA_REFCNT_VALUE(c) >= 1);