818e7226d9d1884cd4d3aadf0634813ec1432602
[strongswan.git] / src / libpts / pts / components / pts_comp_func_name.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen
3 *
4 * HSR Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "pts/components/pts_comp_func_name.h"
18
19 #include <debug.h>
20
21 #define PTS_QUALIFIER_UNKNOWN 0x00
22 #define PTS_QUALIFIER_WILDCARD 0x3F
23
24 typedef struct private_pts_comp_func_name_t private_pts_comp_func_name_t;
25
26 /**
27 * Private data of a pts_comp_func_name_t object.
28 *
29 */
30 struct private_pts_comp_func_name_t {
31
32 /**
33 * Public pts_comp_func_name_t interface.
34 */
35 pts_comp_func_name_t public;
36
37 /**
38 * PTS Component Functional Name Vendor ID
39 */
40 u_int32_t vendor_id;
41
42 /**
43 * PTS Component Functional Name
44 */
45 u_int32_t name;
46
47 /**
48 * PTS Component Functional Name Qualifier
49 */
50 u_int8_t qualifier;
51
52 };
53
54 METHOD(pts_comp_func_name_t, get_vendor_id, u_int32_t,
55 private_pts_comp_func_name_t *this)
56 {
57 return this->vendor_id;
58 }
59
60 METHOD(pts_comp_func_name_t, get_name, u_int32_t,
61 private_pts_comp_func_name_t *this)
62 {
63 return this->name;
64 }
65
66 METHOD(pts_comp_func_name_t, get_qualifier, u_int8_t,
67 private_pts_comp_func_name_t *this)
68 {
69 return this->qualifier;
70 }
71
72 static bool equals(private_pts_comp_func_name_t *this,
73 private_pts_comp_func_name_t *other)
74 {
75 if (this->vendor_id != other->vendor_id ||
76 this->name != other->name)
77 {
78 return FALSE;
79 }
80 if (this->qualifier == PTS_QUALIFIER_UNKNOWN ||
81 other->qualifier == PTS_QUALIFIER_UNKNOWN)
82 {
83 return TRUE;
84 }
85 /* TODO handle qualifier wildcards */
86
87 return this->qualifier == other->qualifier;
88 }
89
90 METHOD(pts_comp_func_name_t, clone_, pts_comp_func_name_t*,
91 private_pts_comp_func_name_t *this)
92 {
93 private_pts_comp_func_name_t *clone;
94
95 clone = malloc_thing(private_pts_comp_func_name_t);
96 memcpy(clone, this, sizeof(private_pts_comp_func_name_t));
97
98 return &clone->public;
99 }
100
101 METHOD(pts_comp_func_name_t, destroy, void,
102 private_pts_comp_func_name_t *this)
103 {
104 free(this);
105 }
106
107 /**
108 * See header
109 */
110 pts_comp_func_name_t* pts_comp_func_name_create(u_int32_t vendor_id,
111 u_int32_t name,
112 u_int8_t qualifier)
113 {
114 private_pts_comp_func_name_t *this;
115
116 INIT(this,
117 .public = {
118 .get_vendor_id = _get_vendor_id,
119 .get_name = _get_name,
120 .get_qualifier = _get_qualifier,
121 .equals = (bool(*)(pts_comp_func_name_t*,pts_comp_func_name_t*))equals,
122 .clone = _clone_,
123 .destroy = _destroy,
124 },
125 .vendor_id = vendor_id,
126 .name = name,
127 .qualifier = qualifier,
128 );
129
130 return &this->public;
131 }
132