/src/S2OPC/src/ClientServer/services/b2c/constants_bs.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Licensed to Systerel under one or more contributor license |
3 | | * agreements. See the NOTICE file distributed with this work |
4 | | * for additional information regarding copyright ownership. |
5 | | * Systerel licenses this file to you under the Apache |
6 | | * License, Version 2.0 (the "License"); you may not use this |
7 | | * file except in compliance with the License. You may obtain |
8 | | * a copy of the License at |
9 | | * |
10 | | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | * |
12 | | * Unless required by applicable law or agreed to in writing, |
13 | | * software distributed under the License is distributed on an |
14 | | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | | * KIND, either express or implied. See the License for the |
16 | | * specific language governing permissions and limitations |
17 | | * under the License. |
18 | | */ |
19 | | |
20 | | /** \file |
21 | | * |
22 | | * Implements the base machine for the constants |
23 | | */ |
24 | | |
25 | | #include "constants_bs.h" |
26 | | #include "b2c.h" |
27 | | #include "sopc_assert.h" |
28 | | #include "sopc_builtintypes.h" |
29 | | #include "sopc_date_time.h" |
30 | | #include "sopc_logger.h" |
31 | | #include "sopc_macros.h" |
32 | | #include "sopc_mem_alloc.h" |
33 | | #include "sopc_toolkit_config_internal.h" |
34 | | #include "sopc_types.h" |
35 | | |
36 | | static SOPC_NodeId ByteString_Type = SOPC_NS0_NUMERIC_NODEID(OpcUaId_ByteString); |
37 | | static SOPC_NodeId Byte_Type = SOPC_NS0_NUMERIC_NODEID(OpcUaId_Byte); |
38 | | static SOPC_NodeId Null_Type = SOPC_NS0_NUMERIC_NODEID(0); |
39 | | static SOPC_NodeId HasComponent_Type = SOPC_NS0_NUMERIC_NODEID(OpcUaId_HasComponent); |
40 | | static SOPC_NodeId HasProperty_Type = SOPC_NS0_NUMERIC_NODEID(OpcUaId_HasProperty); |
41 | | static SOPC_NodeId HierarchicalReferences_Type = SOPC_NS0_NUMERIC_NODEID(OpcUaId_HierarchicalReferences); |
42 | | static SOPC_NodeId Server_NodeId = SOPC_NS0_NUMERIC_NODEID(OpcUaId_Server); |
43 | | static SOPC_NodeId BaseEventType_NodeId = SOPC_NS0_NUMERIC_NODEID(OpcUaId_BaseEventType); |
44 | | static SOPC_NodeId Server_ServerCapabilities_RoleSet_NodeId = |
45 | | SOPC_NS0_NUMERIC_NODEID(OpcUaId_Server_ServerCapabilities_RoleSet); |
46 | | static SOPC_NodeId RoleType_NodeId = SOPC_NS0_NUMERIC_NODEID(OpcUaId_RoleType); |
47 | | static SOPC_NodeId Server_NamespaceArray_NodeId = SOPC_NS0_NUMERIC_NODEID(OpcUaId_Server_NamespaceArray); |
48 | | static SOPC_NodeId Server_Namespaces_NodeId = SOPC_NS0_NUMERIC_NODEID(OpcUaId_Server_Namespaces); |
49 | | static SOPC_NodeId NamespaceMetadataType_NodeId = SOPC_NS0_NUMERIC_NODEID(OpcUaId_NamespaceMetadataType); |
50 | | static SOPC_NodeId RolePermissionType_NodeId = SOPC_NS0_NUMERIC_NODEID(OpcUaId_RolePermissionType); |
51 | | |
52 | | const constants_bs__t_NodeId_i constants_bs__c_ByteString_Type_NodeId = &ByteString_Type; |
53 | | const constants_bs__t_NodeId_i constants_bs__c_Byte_Type_NodeId = &Byte_Type; |
54 | | const constants_bs__t_NodeId_i constants_bs__c_Null_Type_NodeId = &Null_Type; |
55 | | const constants_bs__t_NodeId_i constants_bs__c_HasComponentType_NodeId = &HasComponent_Type; |
56 | | const constants_bs__t_NodeId_i constants_bs__c_HasPropertyType_NodeId = &HasProperty_Type; |
57 | | const constants_bs__t_NodeId_i constants_bs__c_HierarchicalReferences_Type_NodeId = &HierarchicalReferences_Type; |
58 | | const constants_bs__t_NodeId_i constants_bs__c_Server_NodeId = &Server_NodeId; |
59 | | const constants_bs__t_NodeId_i constants_bs__c_BaseEventType_NodeId = &BaseEventType_NodeId; |
60 | | const constants_bs__t_NodeId_i constants_bs__c_Server_ServerCapabilities_RoleSet_NodeId = |
61 | | &Server_ServerCapabilities_RoleSet_NodeId; |
62 | | const constants_bs__t_NodeId_i constants_bs__c_RoleType_NodeId = &RoleType_NodeId; |
63 | | const constants_bs__t_NodeId_i constants_bs__c_NamespaceMetadataType_NodeId = &NamespaceMetadataType_NodeId; |
64 | | const constants_bs__t_NodeId_i constants_bs__c_Server_NamespaceArray_NodeId = &Server_NamespaceArray_NodeId; |
65 | | const constants_bs__t_NodeId_i constants_bs__c_Server_Namespaces_NodeId = &Server_Namespaces_NodeId; |
66 | | const constants_bs__t_NodeId_i constants_bs__c_RolePermissionType_NodeId = &RolePermissionType_NodeId; |
67 | | |
68 | | #define SOPC_NS0_QUALIFIED_NAME(name) \ |
69 | | { \ |
70 | | OPCUA_NAMESPACE_INDEX, { sizeof(name) - 1, true, (SOPC_Byte*) name } \ |
71 | | } |
72 | | SOPC_GCC_DIAGNOSTIC_IGNORE_CAST_CONST // Build pikeos: "name" instances are const and cannot cast into (SOPC_Byte*) |
73 | | // which is not const |
74 | | static SOPC_QualifiedName Identities_QualifiedName = SOPC_NS0_QUALIFIED_NAME("Identities"); |
75 | | static SOPC_QualifiedName DefaultRolePermissions_QualifiedName = SOPC_NS0_QUALIFIED_NAME("DefaultRolePermissions"); |
76 | | static SOPC_QualifiedName NamespaceUri_QualifiedName = SOPC_NS0_QUALIFIED_NAME("NamespaceUri"); |
77 | | SOPC_GCC_DIAGNOSTIC_RESTORE |
78 | | const constants_bs__t_QualifiedName_i constants_bs__c_Identities_QualifiedName = &Identities_QualifiedName; |
79 | | const constants_bs__t_QualifiedName_i constants_bs__c_DefaultRolePermissions_QualifiedName = |
80 | | &DefaultRolePermissions_QualifiedName; |
81 | | const constants_bs__t_QualifiedName_i constants_bs__c_NamespaceUri_QualifiedName = &NamespaceUri_QualifiedName; |
82 | | |
83 | | static char* EmptyLocaleIds[] = {NULL}; |
84 | | constants_bs__t_LocaleIds_i constants_bs__c_LocaleIds_empty = EmptyLocaleIds; |
85 | | |
86 | | void constants_bs__INITIALISATION(void) |
87 | 0 | { /*Translated from B but an intialisation is not needed from this module.*/ |
88 | 0 | } |
89 | | |
90 | | /*-------------------- |
91 | | OPERATIONS Clause |
92 | | --------------------*/ |
93 | | |
94 | | void constants_bs__getall_conv_ExpandedNodeId_NodeId(const constants_bs__t_ExpandedNodeId_i constants_bs__p_expnid, |
95 | | t_bool* const constants_bs__p_local_server, |
96 | | constants_bs__t_NodeId_i* const constants_bs__p_nid) |
97 | 0 | { |
98 | 0 | *constants_bs__p_nid = constants_bs__c_ExpandedNodeId_indet; |
99 | 0 | *constants_bs__p_local_server = false; |
100 | 0 | if (constants_bs__p_expnid->ServerIndex == 0) |
101 | 0 | { |
102 | | // TODO: namespaceUri.Length > 0 does not really mean it is an external node but we do not manage it: |
103 | | // if server index indicates it is local node (index == 0) and URI is defined the URI |
104 | | // can be either valid in local server or invalid (another degraded case). |
105 | 0 | if (constants_bs__p_expnid->NamespaceUri.Length <= 0) |
106 | 0 | { |
107 | 0 | *constants_bs__p_local_server = true; |
108 | | /* Reminder: This is a borrow */ |
109 | 0 | *constants_bs__p_nid = &constants_bs__p_expnid->NodeId; |
110 | 0 | } |
111 | 0 | else |
112 | 0 | { |
113 | | // Should be a local namespace URI but we do not manage it |
114 | 0 | SOPC_Logger_TraceWarning( |
115 | 0 | SOPC_LOG_MODULE_CLIENTSERVER, |
116 | 0 | "Conversion of Namespace URI %s from ExpandedNodeId not managed => considered as external server node.", |
117 | 0 | SOPC_String_GetRawCString(&constants_bs__p_expnid->NamespaceUri)); |
118 | 0 | } |
119 | 0 | } |
120 | 0 | } |
121 | | |
122 | | void constants_bs__is_ClientNodeManagementActive(t_bool* const constants_bs__bres) |
123 | 0 | { |
124 | 0 | *constants_bs__bres = S2OPC_NODE_MANAGEMENT; |
125 | 0 | } |
126 | | |
127 | | void constants_bs__is_EventNotifier_SubscribeToEvents(const constants_bs__t_Byte constants_bs__p_eventNotifierByte, |
128 | | t_bool* const constants_bs__bres) |
129 | 0 | { |
130 | 0 | *constants_bs__bres = (0 != (OpcUa_EventNotifierType_SubscribeToEvents & constants_bs__p_eventNotifierByte)); |
131 | 0 | } |
132 | | |
133 | | void constants_bs__is_t_access_level_currentRead(const constants_bs__t_access_level constants_bs__p_access_lvl, |
134 | | t_bool* const constants_bs__bres) |
135 | 0 | { |
136 | 0 | *constants_bs__bres = (constants_bs__p_access_lvl & SOPC_AccessLevelMask_CurrentRead) != 0; |
137 | 0 | } |
138 | | |
139 | | void constants_bs__is_t_access_level_currentWrite(const constants_bs__t_access_level constants_bs__p_access_lvl, |
140 | | t_bool* const constants_bs__bres) |
141 | 0 | { |
142 | 0 | *constants_bs__bres = (constants_bs__p_access_lvl & SOPC_AccessLevelMask_CurrentWrite) != 0; |
143 | 0 | } |
144 | | |
145 | | void constants_bs__is_t_access_level_statusWrite(const constants_bs__t_access_level constants_bs__p_access_lvl, |
146 | | t_bool* const constants_bs__bres) |
147 | 0 | { |
148 | 0 | *constants_bs__bres = (constants_bs__p_access_lvl & SOPC_AccessLevelMask_StatusWrite) != 0; |
149 | 0 | } |
150 | | |
151 | | void constants_bs__is_t_access_level_timestampWrite(const constants_bs__t_access_level constants_bs__p_access_lvl, |
152 | | t_bool* const constants_bs__bres) |
153 | 0 | { |
154 | 0 | *constants_bs__bres = (constants_bs__p_access_lvl & SOPC_AccessLevelMask_TimestampWrite) != 0; |
155 | 0 | } |
156 | | |
157 | | void constants_bs__get_card_t_channel(t_entier4* const constants_bs__p_card_channel) |
158 | 0 | { |
159 | 0 | *constants_bs__p_card_channel = constants_bs__t_channel_i_max; |
160 | 0 | } |
161 | | |
162 | | void constants_bs__get_card_t_channel_config_idx(t_entier4* const constants_bs__p_card_channel_config) |
163 | 0 | { |
164 | 0 | *constants_bs__p_card_channel_config = constants_bs__t_channel_config_idx_i_max; |
165 | 0 | } |
166 | | |
167 | | void constants_bs__get_card_t_session(t_entier4* const constants_bs__p_card_session) |
168 | 0 | { |
169 | 0 | *constants_bs__p_card_session = constants_bs__t_session_i_max; |
170 | 0 | } |
171 | | |
172 | | void constants_bs__get_card_t_subscription(t_entier4* const constants_bs__p_card_subscription) |
173 | 0 | { |
174 | 0 | *constants_bs__p_card_subscription = constants_bs__t_subscription_i_max; |
175 | 0 | } |
176 | | |
177 | | void constants_bs__get_cast_t_channel(const t_entier4 constants_bs__p_ind, |
178 | | constants_bs__t_channel_i* const constants_bs__p_channel) |
179 | 0 | { |
180 | 0 | *constants_bs__p_channel = (uint32_t) constants_bs__p_ind; |
181 | 0 | } |
182 | | |
183 | | void constants_bs__get_cast_t_NamespaceIdx(const t_entier4 constants_bs__p_ind, |
184 | | constants_bs__t_NamespaceIdx* const constants_bs__p_nsIndex) |
185 | 0 | { |
186 | 0 | *constants_bs__p_nsIndex = (uint16_t) constants_bs__p_ind; |
187 | 0 | } |
188 | | |
189 | | void constants_bs__get_cast_t_channel_config_idx(const t_entier4 constants_bs__p_ind, |
190 | | constants_bs__t_channel_config_idx_i* const constants_bs__p_config) |
191 | 0 | { |
192 | 0 | *constants_bs__p_config = (SOPC_SecureChannelConfigIdx) constants_bs__p_ind; |
193 | 0 | } |
194 | | |
195 | | void constants_bs__get_cast_t_session(const t_entier4 constants_bs__p_ind, |
196 | | constants_bs__t_session_i* const constants_bs__p_session) |
197 | 0 | { |
198 | 0 | *constants_bs__p_session = (uint32_t) constants_bs__p_ind; |
199 | 0 | } |
200 | | |
201 | | void constants_bs__get_cast_t_subscription(const t_entier4 constants_bs__p_ind, |
202 | | constants_bs__t_subscription_i* const constants_bs__p_subscription) |
203 | 0 | { |
204 | 0 | *constants_bs__p_subscription = (uint32_t) constants_bs__p_ind; |
205 | 0 | } |
206 | | |
207 | | void constants_bs__is_t_channel(const constants_bs__t_channel_i constants_bs__p_channel, |
208 | | t_bool* const constants_bs__p_res) |
209 | 0 | { |
210 | 0 | *constants_bs__p_res = (constants_bs__p_channel > 0 && constants_bs__p_channel <= constants_bs__t_channel_i_max); |
211 | 0 | } |
212 | | |
213 | | void constants_bs__is_t_channel_config_idx(const constants_bs__t_channel_config_idx_i constants_bs__p_config_idx, |
214 | | t_bool* const constants_bs__p_res) |
215 | 0 | { |
216 | 0 | *constants_bs__p_res = |
217 | 0 | (constants_bs__p_config_idx > 0 && constants_bs__p_config_idx <= constants_bs__t_channel_config_idx_i_max); |
218 | 0 | } |
219 | | |
220 | | void constants_bs__is_t_endpoint_config_idx( |
221 | | const constants_bs__t_endpoint_config_idx_i constants_bs__p_endpoint_config_idx, |
222 | | t_bool* const constants_bs__p_res) |
223 | 0 | { |
224 | 0 | *constants_bs__p_res = (constants_bs__p_endpoint_config_idx > 0 && |
225 | 0 | constants_bs__p_endpoint_config_idx <= constants_bs__t_endpoint_config_idx_i_max); |
226 | 0 | } |
227 | | |
228 | | void constants_bs__get_cast_t_BrowsePath(const t_entier4 constants_bs__p_ind, |
229 | | constants_bs__t_BrowsePath_i* const constants_bs__p_browsePath) |
230 | 0 | { |
231 | 0 | *constants_bs__p_browsePath = (uint32_t) constants_bs__p_ind; |
232 | 0 | } |
233 | | |
234 | | void constants_bs__get_cast_t_CallMethod(const t_entier4 constants_bs__p_ind, |
235 | | constants_bs__t_CallMethod_i* const constants_bs__p_callMethod) |
236 | 0 | { |
237 | 0 | *constants_bs__p_callMethod = constants_bs__p_ind; |
238 | 0 | } |
239 | | |
240 | | void constants_bs__is_QualifiedNames_Empty(const constants_bs__t_QualifiedName_i constants_bs__name, |
241 | | t_bool* const constants_bs__p_bool) |
242 | 0 | { |
243 | 0 | if (NULL == constants_bs__name) |
244 | 0 | { |
245 | 0 | *constants_bs__p_bool = true; |
246 | 0 | } |
247 | 0 | else |
248 | 0 | { |
249 | 0 | *constants_bs__p_bool = (0 >= constants_bs__name->Name.Length); |
250 | 0 | } |
251 | 0 | } |
252 | | |
253 | | void constants_bs__is_QualifiedNames_Equal(const constants_bs__t_QualifiedName_i constants_bs__name1, |
254 | | const constants_bs__t_QualifiedName_i constants_bs__name2, |
255 | | t_bool* const constants_bs__p_bool) |
256 | 0 | { |
257 | 0 | if (NULL == constants_bs__name1 || NULL == constants_bs__name2) |
258 | 0 | { |
259 | 0 | *constants_bs__p_bool = (constants_bs__name1 == constants_bs__name2); |
260 | 0 | } |
261 | 0 | else |
262 | 0 | { |
263 | 0 | int32_t comparison = 0; |
264 | 0 | const SOPC_ReturnStatus retVal = |
265 | 0 | SOPC_QualifiedName_Compare(constants_bs__name1, constants_bs__name2, &comparison); |
266 | 0 | *constants_bs__p_bool = (SOPC_STATUS_OK == retVal && 0 == comparison); |
267 | 0 | } |
268 | 0 | } |
269 | | |
270 | | void constants_bs__is_Timestamps_Null(const constants_bs__t_Timestamp constants_bs__p_ts, |
271 | | t_bool* const constants_bs__bres) |
272 | 0 | { |
273 | 0 | *constants_bs__bres = (constants_bs__c_Timestamp_null.timestamp == constants_bs__p_ts.timestamp && |
274 | 0 | constants_bs__c_Timestamp_null.picoSeconds == constants_bs__p_ts.picoSeconds); |
275 | 0 | } |
276 | | |
277 | | void constants_bs__free_ExpandedNodeId(const constants_bs__t_ExpandedNodeId_i constants_bs__p_in) |
278 | 0 | { |
279 | 0 | if (NULL != constants_bs__p_in) |
280 | 0 | { |
281 | 0 | SOPC_GCC_DIAGNOSTIC_IGNORE_CAST_CONST |
282 | 0 | SOPC_ExpandedNodeId_Clear(constants_bs__p_in); |
283 | 0 | SOPC_Free(constants_bs__p_in); |
284 | 0 | SOPC_GCC_DIAGNOSTIC_RESTORE |
285 | 0 | } |
286 | 0 | } |
287 | | |
288 | | void constants_bs__free_roles(const constants_bs__t_sessionRoles_i constants_bs__p_in) |
289 | 0 | { |
290 | | // Delete the references to the nodeIds in the LinkedList, and delete the LinkedList |
291 | 0 | SOPC_SLinkedList_Delete(constants_bs__p_in); |
292 | 0 | } |
293 | | |
294 | | void constants_bs__free_LocaleIds(const constants_bs__t_LocaleIds_i constants_bs__p_in) |
295 | 0 | { |
296 | 0 | SOPC_ASSERT(constants_bs__c_LocaleIds_indet != constants_bs__p_in); |
297 | 0 | uint32_t idx = 0; |
298 | 0 | SOPC_GCC_DIAGNOSTIC_IGNORE_CAST_CONST |
299 | 0 | char* cstring = constants_bs__p_in[idx]; |
300 | 0 | while (NULL != cstring) |
301 | 0 | { |
302 | 0 | SOPC_Free(cstring); |
303 | 0 | idx++; |
304 | 0 | cstring = constants_bs__p_in[idx]; |
305 | 0 | } |
306 | 0 | SOPC_GCC_DIAGNOSTIC_RESTORE |
307 | 0 | SOPC_Free(constants_bs__p_in); |
308 | 0 | } |
309 | | |
310 | | void constants_bs__get_CurrentTimestamp(constants_bs__t_Timestamp* const constants_bs__p_currentTs) |
311 | 0 | { |
312 | 0 | constants_bs__p_currentTs->picoSeconds = 0; |
313 | 0 | constants_bs__p_currentTs->timestamp = SOPC_Time_GetCurrentTimeUTC(); |
314 | 0 | } |
315 | | |
316 | | void constants_bs__get_SupportedLocales(const constants_bs__t_endpoint_config_idx_i constants_bs__p_in, |
317 | | constants_bs__t_LocaleIds_i* const constants_bs__p_localeIds) |
318 | 0 | { |
319 | 0 | *constants_bs__p_localeIds = constants_bs__c_LocaleIds_empty; |
320 | 0 | SOPC_Endpoint_Config* ep = SOPC_ToolkitServer_GetEndpointConfig(constants_bs__p_in); |
321 | 0 | if (NULL != ep && ep->serverConfigPtr->localeIds != NULL) |
322 | 0 | { |
323 | 0 | *constants_bs__p_localeIds = ep->serverConfigPtr->localeIds; |
324 | 0 | } |
325 | 0 | } |
326 | | |
327 | | void constants_bs__get_copy_ExpandedNodeId(const constants_bs__t_ExpandedNodeId_i constants_bs__p_in, |
328 | | t_bool* const constants_bs__p_alloc, |
329 | | constants_bs__t_ExpandedNodeId_i* const constants_bs__p_out) |
330 | 0 | { |
331 | 0 | *constants_bs__p_alloc = false; |
332 | 0 | *constants_bs__p_out = SOPC_Calloc(1, sizeof(**constants_bs__p_out)); |
333 | 0 | if (NULL != *constants_bs__p_out) |
334 | 0 | { |
335 | 0 | SOPC_ExpandedNodeId_Initialize(*constants_bs__p_out); |
336 | 0 | SOPC_ReturnStatus status = SOPC_ExpandedNodeId_Copy(*constants_bs__p_out, constants_bs__p_in); |
337 | 0 | if (SOPC_STATUS_OK == status) |
338 | 0 | { |
339 | 0 | *constants_bs__p_alloc = true; |
340 | 0 | } |
341 | 0 | else |
342 | 0 | { |
343 | 0 | SOPC_Free(*constants_bs__p_out); |
344 | 0 | } |
345 | 0 | } |
346 | 0 | } |
347 | | |
348 | | void constants_bs__get_NodeId_NamespaceIndex(const constants_bs__t_NodeId_i constants_bs__p_nodeId, |
349 | | constants_bs__t_NamespaceIdx* const constants_bs__p_idx) |
350 | 0 | { |
351 | 0 | SOPC_ASSERT(NULL != constants_bs__p_nodeId); |
352 | 0 | *constants_bs__p_idx = constants_bs__p_nodeId->Namespace; |
353 | 0 | } |