]> code.delx.au - pulseaudio/blob - src/polypcore/authkey-prop.c
Cleaned up the includes after the restructuring. Indicate which headers are
[pulseaudio] / src / polypcore / 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 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 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 Lesser 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 <polypcore/xmalloc.h>
26 #include <polypcore/props.h>
27 #include <polypcore/log.h>
28
29 #include "authkey-prop.h"
30
31 struct authkey_data {
32 int ref;
33 size_t length;
34 };
35
36 int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) {
37 struct authkey_data *a;
38 assert(c && name && data && len > 0);
39
40 if (!(a = pa_property_get(c, name)))
41 return -1;
42
43 assert(a->length == len);
44 memcpy(data, a+1, len);
45 return 0;
46 }
47
48 int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t len) {
49 struct authkey_data *a;
50 assert(c && name);
51
52 if (pa_property_get(c, name))
53 return -1;
54
55 a = pa_xmalloc(sizeof(struct authkey_data) + len);
56 a->ref = 1;
57 a->length = len;
58 memcpy(a+1, data, len);
59
60 pa_property_set(c, name, a);
61
62 return 0;
63 }
64
65 void pa_authkey_prop_ref(pa_core *c, const char *name) {
66 struct authkey_data *a;
67 assert(c && name);
68
69 a = pa_property_get(c, name);
70 assert(a && a->ref >= 1);
71
72 a->ref++;
73 }
74
75 void pa_authkey_prop_unref(pa_core *c, const char *name) {
76 struct authkey_data *a;
77 assert(c && name);
78
79 a = pa_property_get(c, name);
80 assert(a && a->ref >= 1);
81
82 if (!(--a->ref)) {
83 pa_property_remove(c, name);
84 pa_xfree(a);
85 }
86 }
87
88