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