Add copyright notices to all relevant files. (based on svn log)
[profile/ivi/pulseaudio.git] / 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 #include <assert.h>
25 #include <string.h>
26
27 #include <pulse/xmalloc.h>
28
29 #include <pulsecore/props.h>
30 #include <pulsecore/log.h>
31
32 #include "authkey-prop.h"
33
34 struct authkey_data {
35     int ref;
36     size_t length;
37 };
38
39 int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) {
40     struct authkey_data *a;
41     assert(c && name && data && len > 0);
42
43     if (!(a = pa_property_get(c, name)))
44         return -1;
45
46     assert(a->length == len);
47     memcpy(data, a+1, len);
48     return 0;
49 }
50
51 int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t len) {
52     struct authkey_data *a;
53     assert(c && name);
54
55     if (pa_property_get(c, name))
56         return -1;
57
58     a = pa_xmalloc(sizeof(struct authkey_data) + len);
59     a->ref = 1;
60     a->length = len;
61     memcpy(a+1, data, len);
62
63     pa_property_set(c, name, a);
64
65     return 0;
66 }
67
68 void pa_authkey_prop_ref(pa_core *c, const char *name) {
69     struct authkey_data *a;
70     assert(c && name);
71
72     a = pa_property_get(c, name);
73     assert(a && a->ref >= 1);
74
75     a->ref++;
76 }
77
78 void pa_authkey_prop_unref(pa_core *c, const char *name) {
79     struct authkey_data *a;
80     assert(c && name);
81
82     a = pa_property_get(c, name);
83     assert(a && a->ref >= 1);
84
85     if (!(--a->ref)) {
86         pa_property_remove(c, name);
87         pa_xfree(a);
88     }
89 }
90
91