]>
Commit | Line | Data |
---|---|---|
b38d9d5a | 1 | /* |
8c40609f | 2 | * Copyright (C) 2013-2014 Andreas Steffen |
b38d9d5a AS |
3 | * HSR Hochschule fuer Technik Rapperswil |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2 of the License, or (at your | |
8 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 | * for more details. | |
14 | */ | |
15 | ||
16 | #include "swid_tag_id.h" | |
17 | ||
18 | typedef struct private_swid_tag_id_t private_swid_tag_id_t; | |
19 | ||
20 | /** | |
21 | * Private data of a swid_tag_id_t object. | |
22 | * | |
23 | */ | |
24 | struct private_swid_tag_id_t { | |
25 | ||
26 | /** | |
27 | * Public swid_tag_id_t interface. | |
28 | */ | |
29 | swid_tag_id_t public; | |
30 | ||
31 | /** | |
32 | * Tag Creator | |
33 | */ | |
34 | chunk_t tag_creator; | |
35 | ||
36 | /** | |
37 | * Unique Software ID | |
38 | */ | |
39 | chunk_t unique_sw_id; | |
40 | ||
41 | /** | |
924ed795 | 42 | * Optional Tag Identifier Instance ID |
b38d9d5a | 43 | */ |
924ed795 | 44 | chunk_t instance_id; |
b38d9d5a | 45 | |
8c40609f AS |
46 | /** |
47 | * Reference count | |
48 | */ | |
49 | refcount_t ref; | |
b38d9d5a AS |
50 | }; |
51 | ||
52 | METHOD(swid_tag_id_t, get_tag_creator, chunk_t, | |
53 | private_swid_tag_id_t *this) | |
54 | { | |
55 | return this->tag_creator; | |
56 | } | |
57 | ||
58 | METHOD(swid_tag_id_t, get_unique_sw_id, chunk_t, | |
924ed795 | 59 | private_swid_tag_id_t *this, chunk_t *instance_id) |
b38d9d5a | 60 | { |
924ed795 | 61 | if (instance_id) |
b38d9d5a | 62 | { |
924ed795 | 63 | *instance_id = this->instance_id; |
b38d9d5a AS |
64 | } |
65 | return this->unique_sw_id; | |
66 | } | |
67 | ||
8c40609f AS |
68 | METHOD(swid_tag_id_t, get_ref, swid_tag_id_t*, |
69 | private_swid_tag_id_t *this) | |
70 | { | |
71 | ref_get(&this->ref); | |
72 | return &this->public; | |
73 | } | |
74 | ||
b38d9d5a AS |
75 | METHOD(swid_tag_id_t, destroy, void, |
76 | private_swid_tag_id_t *this) | |
77 | { | |
8c40609f AS |
78 | if (ref_put(&this->ref)) |
79 | { | |
80 | free(this->tag_creator.ptr); | |
81 | free(this->unique_sw_id.ptr); | |
924ed795 | 82 | free(this->instance_id.ptr); |
8c40609f AS |
83 | free(this); |
84 | } | |
b38d9d5a AS |
85 | } |
86 | ||
87 | /** | |
88 | * See header | |
89 | */ | |
90 | swid_tag_id_t *swid_tag_id_create(chunk_t tag_creator, chunk_t unique_sw_id, | |
924ed795 | 91 | chunk_t instance_id) |
b38d9d5a AS |
92 | { |
93 | private_swid_tag_id_t *this; | |
94 | ||
95 | INIT(this, | |
96 | .public = { | |
97 | .get_tag_creator = _get_tag_creator, | |
98 | .get_unique_sw_id = _get_unique_sw_id, | |
8c40609f | 99 | .get_ref = _get_ref, |
b38d9d5a AS |
100 | .destroy = _destroy, |
101 | }, | |
102 | .tag_creator = chunk_clone(tag_creator), | |
103 | .unique_sw_id = chunk_clone(unique_sw_id), | |
8c40609f | 104 | .ref = 1, |
b38d9d5a AS |
105 | ); |
106 | ||
924ed795 | 107 | if (instance_id.len > 0) |
b38d9d5a | 108 | { |
924ed795 | 109 | this->instance_id = chunk_clone(instance_id); |
b38d9d5a AS |
110 | } |
111 | ||
112 | return &this->public; | |
113 | } | |
114 |