Replaced Tag File Path by Instance ID field
[strongswan.git] / src / libpts / swid / swid_tag.c
1 /*
2 * Copyright (C) 2013-2014 Andreas Steffen
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.h"
17
18 typedef struct private_swid_tag_t private_swid_tag_t;
19
20 /**
21 * Private data of a swid_tag_t object.
22 *
23 */
24 struct private_swid_tag_t {
25
26 /**
27 * Public swid_tag_t interface.
28 */
29 swid_tag_t public;
30
31 /**
32 * UTF-8 XML encoding of SWID tag
33 */
34 chunk_t encoding;
35
36 /**
37 * Optional Tag Identifier Instance ID
38 */
39 chunk_t instance_id;
40
41 /**
42 * Reference count
43 */
44 refcount_t ref;
45 };
46
47 METHOD(swid_tag_t, get_encoding, chunk_t,
48 private_swid_tag_t *this)
49 {
50 return this->encoding;
51 }
52
53 METHOD(swid_tag_t, get_instance_id, chunk_t,
54 private_swid_tag_t *this)
55 {
56 return this->instance_id;
57 }
58
59 METHOD(swid_tag_t, get_ref, swid_tag_t*,
60 private_swid_tag_t *this)
61 {
62 ref_get(&this->ref);
63 return &this->public;
64 }
65
66 METHOD(swid_tag_t, destroy, void,
67 private_swid_tag_t *this)
68 {
69 if (ref_put(&this->ref))
70 {
71 free(this->encoding.ptr);
72 free(this->instance_id.ptr);
73 free(this);
74 }
75 }
76
77 /**
78 * See header
79 */
80 swid_tag_t *swid_tag_create(chunk_t encoding, chunk_t instance_id)
81 {
82 private_swid_tag_t *this;
83
84 INIT(this,
85 .public = {
86 .get_encoding = _get_encoding,
87 .get_instance_id = _get_instance_id,
88 .get_ref = _get_ref,
89 .destroy = _destroy,
90 },
91 .encoding = chunk_clone(encoding),
92 .ref = 1,
93 );
94
95 if (instance_id.len > 0)
96 {
97 this->instance_id = chunk_clone(instance_id);
98 }
99
100 return &this->public;
101 }
102