]> code.delx.au - pulseaudio/blob - src/pulsecore/authkey-prop.c
more modernizations, s/assert/pa_assert/g
[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 int ref;
42 size_t length;
43 };
44
45 int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) {
46 struct authkey_data *a;
47
48 pa_assert(c);
49 pa_assert(name);
50 pa_assert(data);
51 pa_assert(len > 0);
52
53 if (!(a = pa_property_get(c, name)))
54 return -1;
55
56 pa_assert(a->length == len);
57 memcpy(data, (uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), len);
58
59 return 0;
60 }
61
62 int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t len) {
63 struct authkey_data *a;
64
65 pa_assert(c);
66 pa_assert(name);
67
68 if (pa_property_get(c, name))
69 return -1;
70
71 a = pa_xmalloc(PA_ALIGN(sizeof(struct authkey_data)) + len);
72 PA_REFCNT_INIT(a);
73 a->length = len;
74 memcpy((uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), data, len);
75
76 pa_property_set(c, name, a);
77
78 return 0;
79 }
80
81 void pa_authkey_prop_ref(pa_core *c, const char *name) {
82 struct authkey_data *a;
83
84 pa_assert(c);
85 pa_assert(name);
86
87 a = pa_property_get(c, name);
88 pa_assert(a);
89 pa_assert(PA_REFCNT_VALUE(a) >= 1);
90 PA_REFCNT_INC(a);
91 }
92
93 void pa_authkey_prop_unref(pa_core *c, const char *name) {
94 struct authkey_data *a;
95
96 pa_assert(c);
97 pa_assert(name);
98
99 a = pa_property_get(c, name);
100 pa_assert(a);
101 pa_assert(PA_REFCNT_VALUE(a) >= 1);
102
103 if (PA_REFCNT_DEC(a) <= 0) {
104 pa_property_remove(c, name);
105 pa_xfree(a);
106 }
107 }
108
109