]> code.delx.au - pulseaudio/blob - polyp/authkey-prop.c
132279556db02d91a5bb207ce6147ef5fb195051
[pulseaudio] / polyp / authkey-prop.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU 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 polypaudio 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 General Public License
17 along with polypaudio; 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 "xmalloc.h"
26 #include "authkey-prop.h"
27 #include "props.h"
28 #include "log.h"
29
30 struct authkey_data {
31 int ref;
32 size_t length;
33 };
34
35 int pa_authkey_prop_get(struct pa_core *c, const char *name, void *data, size_t len) {
36 struct authkey_data *a;
37 assert(c && name && data && len > 0);
38
39 if (!(a = pa_property_get(c, name)))
40 return -1;
41
42 assert(a->length == len);
43 memcpy(data, a+1, len);
44 return 0;
45 }
46
47 int pa_authkey_prop_put(struct pa_core *c, const char *name, const void *data, size_t len) {
48 struct authkey_data *a;
49 assert(c && name);
50
51 if (pa_property_get(c, name))
52 return -1;
53
54 a = pa_xmalloc(sizeof(struct authkey_data) + len);
55 a->ref = 1;
56 a->length = len;
57 memcpy(a+1, data, len);
58
59 pa_property_set(c, name, a);
60
61 return 0;
62 }
63
64 void pa_authkey_prop_ref(struct pa_core *c, const char *name) {
65 struct authkey_data *a;
66 assert(c && name);
67
68 a = pa_property_get(c, name);
69 assert(a && a->ref >= 1);
70
71 a->ref++;
72 }
73
74 void pa_authkey_prop_unref(struct pa_core *c, const char *name) {
75 struct authkey_data *a;
76 assert(c && name);
77
78 a = pa_property_get(c, name);
79 assert(a && a->ref >= 1);
80
81 if (!(--a->ref)) {
82 pa_property_remove(c, name);
83 pa_xfree(a);
84 }
85 }
86
87