]> code.delx.au - pulseaudio/blob - src/pulsecore/authkey-prop.c
merge 'lennart' branch back into trunk.
[pulseaudio] / src / pulsecore / authkey-prop.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 Copyright 2004-2006 Lennart Poettering
7
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
12
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 USA.
22 ***/
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <string.h>
29
30 #include <pulse/xmalloc.h>
31
32 #include <pulsecore/props.h>
33 #include <pulsecore/macro.h>
34 #include <pulsecore/log.h>
35 #include <pulsecore/refcnt.h>
36
37 #include "authkey-prop.h"
38
39 struct authkey_data {
40 PA_REFCNT_DECLARE;
41 size_t length;
42 };
43
44 int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) {
45 struct authkey_data *a;
46
47 pa_assert(c);
48 pa_assert(name);
49 pa_assert(data);
50 pa_assert(len > 0);
51
52 if (!(a = pa_property_get(c, name)))
53 return -1;
54
55 pa_assert(a->length == len);
56 memcpy(data, (uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), len);
57
58 return 0;
59 }
60
61 int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t len) {
62 struct authkey_data *a;
63
64 pa_assert(c);
65 pa_assert(name);
66
67 if (pa_property_get(c, name))
68 return -1;
69
70 a = pa_xmalloc(PA_ALIGN(sizeof(struct authkey_data)) + len);
71 PA_REFCNT_INIT(a);
72 a->length = len;
73 memcpy((uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), data, len);
74
75 pa_property_set(c, name, a);
76
77 return 0;
78 }
79
80 void pa_authkey_prop_ref(pa_core *c, const char *name) {
81 struct authkey_data *a;
82
83 pa_assert(c);
84 pa_assert(name);
85
86 a = pa_property_get(c, name);
87 pa_assert(a);
88 pa_assert(PA_REFCNT_VALUE(a) >= 1);
89 PA_REFCNT_INC(a);
90 }
91
92 void pa_authkey_prop_unref(pa_core *c, const char *name) {
93 struct authkey_data *a;
94
95 pa_assert(c);
96 pa_assert(name);
97
98 a = pa_property_get(c, name);
99 pa_assert(a);
100 pa_assert(PA_REFCNT_VALUE(a) >= 1);
101
102 if (PA_REFCNT_DEC(a) <= 0) {
103 pa_property_remove(c, name);
104 pa_xfree(a);
105 }
106 }
107
108