/src/open62541/include/open62541/server.h
Line | Count | Source |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | | * |
5 | | * Copyright 2014-2025 (c) Fraunhofer IOSB (Author: Julius Pfrommer) |
6 | | * Copyright 2015-2016 (c) Sten Grüner |
7 | | * Copyright 2014-2015, 2017 (c) Florian Palm |
8 | | * Copyright 2015-2016 (c) Chris Iatrou |
9 | | * Copyright 2015-2016 (c) Oleksiy Vasylyev |
10 | | * Copyright 2016-2017 (c) Stefan Profanter, fortiss GmbH |
11 | | * Copyright 2017 (c) Henrik Norrman |
12 | | * Copyright 2018 (c) Fabian Arndt, Root-Core |
13 | | * Copyright 2017-2020 (c) HMS Industrial Networks AB (Author: Jonas Green) |
14 | | * Copyright 2020-2022 (c) Christian von Arnim, ISW University of Stuttgart (for VDW and umati) |
15 | | * Copyright 2025 (c) o6 Automation GmbH (Author: Julius Pfrommer) |
16 | | * Copyright 2025-2026 (c) o6 Automation GmbH (Author: Andreas Ebner) |
17 | | */ |
18 | | |
19 | | #ifndef UA_SERVER_H_ |
20 | | #define UA_SERVER_H_ |
21 | | |
22 | | #include <open62541/common.h> |
23 | | #include <open62541/util.h> |
24 | | #include <open62541/types.h> |
25 | | #ifdef UA_ENABLE_DISCOVERY |
26 | | #include <open62541/client.h> |
27 | | #endif |
28 | | |
29 | | #include <open62541/plugin/log.h> |
30 | | #include <open62541/plugin/certificategroup.h> |
31 | | #include <open62541/plugin/eventloop.h> |
32 | | #include <open62541/plugin/accesscontrol.h> |
33 | | #include <open62541/plugin/securitypolicy.h> |
34 | | |
35 | | #ifdef UA_ENABLE_HISTORIZING |
36 | | #include <open62541/plugin/historydatabase.h> |
37 | | #endif |
38 | | |
39 | | #ifdef UA_ENABLE_PUBSUB |
40 | | #include <open62541/server_pubsub.h> |
41 | | #endif |
42 | | |
43 | | /* Forward Declarations */ |
44 | | struct UA_Nodestore; |
45 | | typedef struct UA_Nodestore UA_Nodestore; |
46 | | |
47 | | struct UA_ServerConfig; |
48 | | typedef struct UA_ServerConfig UA_ServerConfig; |
49 | | |
50 | | _UA_BEGIN_DECLS |
51 | | |
52 | | /** |
53 | | * .. _server: |
54 | | * |
55 | | * Server |
56 | | * ====== |
57 | | * An OPC UA server contains an object-oriented information model and makes it |
58 | | * accessible to clients over the network via the OPC UA :ref:`services`. The |
59 | | * information model can be used either used to store "passive data" or as an |
60 | | * "active database" that integrates with data-sources and devices. For the |
61 | | * latter, user-defined callbacks can be attached to VariableNodes and |
62 | | * MethodNodes. |
63 | | * |
64 | | * .. _server-lifecycle: |
65 | | * |
66 | | * Server Lifecycle |
67 | | * ---------------- |
68 | | * This section describes the API for creating, running and deleting a server. |
69 | | * At runtime, the server continuously listens on the network, acceppts incoming |
70 | | * connections and processes received messages. Furthermore, timed (cyclic) |
71 | | * callbacks are executed. */ |
72 | | |
73 | | /* Create a new server with a default configuration that adds plugins for |
74 | | * networking, security, logging and so on. See the "server_config_default.h" |
75 | | * for more detailed options. |
76 | | * |
77 | | * The default configuration can be used as the starting point to adjust the |
78 | | * server configuration to individual needs. UA_Server_new is implemented in the |
79 | | * /plugins folder under the CC0 license. Furthermore the server confiugration |
80 | | * only uses the public server API. |
81 | | * |
82 | | * Returns the configured server or NULL if an error occurs. */ |
83 | | UA_EXPORT UA_Server * |
84 | | UA_Server_new(void); |
85 | | |
86 | | /* Creates a new server. Moves the config into the server with a shallow copy. |
87 | | * The config content is cleared together with the server. */ |
88 | | UA_EXPORT UA_Server * |
89 | | UA_Server_newWithConfig(UA_ServerConfig *config); |
90 | | |
91 | | /* Delete the server and its configuration */ |
92 | | UA_EXPORT UA_StatusCode |
93 | | UA_Server_delete(UA_Server *server); |
94 | | |
95 | | /* Get the configuration. Always succeeds as this simplfy resolves a pointer. |
96 | | * Attention! Do not adjust the configuration while the server is running! */ |
97 | | UA_EXPORT UA_ServerConfig * |
98 | | UA_Server_getConfig(UA_Server *server); |
99 | | |
100 | | /* Get the current server lifecycle state */ |
101 | | UA_EXPORT UA_LifecycleState |
102 | | UA_Server_getLifecycleState(UA_Server *server); |
103 | | |
104 | | /* Runs the server until until "running" is set to false. The logical sequence |
105 | | * is as follows: |
106 | | * |
107 | | * - UA_Server_run_startup |
108 | | * - Loop UA_Server_run_iterate while "running" is true |
109 | | * - UA_Server_run_shutdown */ |
110 | | UA_EXPORT UA_StatusCode |
111 | | UA_Server_run(UA_Server *server, const volatile UA_Boolean *running); |
112 | | |
113 | | /* Runs the server until interrupted. On Unix/Windows this registers an |
114 | | * interrupt for SIGINT (ctrl-c). The method only returns after having received |
115 | | * the interrupt or upon an error condition. The logical sequence is as follows: |
116 | | * |
117 | | * - Register the interrupt |
118 | | * - UA_Server_run_startup |
119 | | * - Loop until interrupt: UA_Server_run_iterate |
120 | | * - UA_Server_run_shutdown |
121 | | * - Deregister the interrupt |
122 | | * |
123 | | * Attention! This method is implemented individually for the different |
124 | | * platforms (POSIX/Win32/etc.). The default implementation is in |
125 | | * /plugins/ua_config_default.c under the CC0 license. Adjust as needed. */ |
126 | | UA_EXPORT UA_StatusCode |
127 | | UA_Server_runUntilInterrupt(UA_Server *server); |
128 | | |
129 | | /* The prologue part of UA_Server_run (no need to use if you call |
130 | | * UA_Server_run or UA_Server_runUntilInterrupt) */ |
131 | | UA_EXPORT UA_StatusCode |
132 | | UA_Server_run_startup(UA_Server *server); |
133 | | |
134 | | /* Executes a single iteration of the server's main loop. |
135 | | * |
136 | | * @param server The server object. |
137 | | * @param waitInternal Should we wait for messages in the networklayer? |
138 | | * Otherwise, the timeouts for the networklayers are set to zero. |
139 | | * The default max wait time is 200ms. |
140 | | * @return Returns how long we can wait until the next scheduled |
141 | | * callback (in ms) */ |
142 | | UA_EXPORT UA_UInt16 |
143 | | UA_Server_run_iterate(UA_Server *server, UA_Boolean waitInternal); |
144 | | |
145 | | /* The epilogue part of UA_Server_run (no need to use if you call |
146 | | * UA_Server_run or UA_Server_runUntilInterrupt) */ |
147 | | UA_EXPORT UA_StatusCode |
148 | | UA_Server_run_shutdown(UA_Server *server); |
149 | | |
150 | | /** |
151 | | * Timed Callbacks |
152 | | * --------------- |
153 | | * Timed callback are executed at their defined timestamp. The callback can also |
154 | | * be registered with a cyclic repetition interval. */ |
155 | | |
156 | | typedef void (*UA_ServerCallback)(UA_Server *server, void *data); |
157 | | |
158 | | /* Add a callback for execution at a specified time. If the indicated time lies |
159 | | * in the past, then the callback is executed at the next iteration of the |
160 | | * server's main loop. |
161 | | * |
162 | | * @param server The server object. |
163 | | * @param callback The callback that shall be added. |
164 | | * @param data Data that is forwarded to the callback. |
165 | | * @param date The timestamp for the execution time. |
166 | | * @param callbackId Set to the identifier of the repeated callback . This can |
167 | | * be used to cancel the callback later on. If the pointer is null, the |
168 | | * identifier is not set. |
169 | | * @return Upon success, ``UA_STATUSCODE_GOOD`` is returned. An error code |
170 | | * otherwise. */ |
171 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
172 | | UA_Server_addTimedCallback(UA_Server *server, UA_ServerCallback callback, |
173 | | void *data, UA_DateTime date, UA_UInt64 *callbackId); |
174 | | |
175 | | /* Add a callback for cyclic repetition to the server. |
176 | | * |
177 | | * @param server The server object. |
178 | | * @param callback The callback that shall be added. |
179 | | * @param data Data that is forwarded to the callback. |
180 | | * @param interval_ms The callback shall be repeatedly executed with the given |
181 | | * interval (in ms). The interval must be positive. The first execution |
182 | | * occurs at now() + interval at the latest. |
183 | | * @param callbackId Set to the identifier of the repeated callback . This can |
184 | | * be used to cancel the callback later on. If the pointer is null, the |
185 | | * identifier is not set. |
186 | | * @return Upon success, ``UA_STATUSCODE_GOOD`` is returned. An error code |
187 | | * otherwise. */ |
188 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
189 | | UA_Server_addRepeatedCallback(UA_Server *server, UA_ServerCallback callback, |
190 | | void *data, UA_Double interval_ms, |
191 | | UA_UInt64 *callbackId); |
192 | | |
193 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
194 | | UA_Server_changeRepeatedCallbackInterval(UA_Server *server, UA_UInt64 callbackId, |
195 | | UA_Double interval_ms); |
196 | | |
197 | | /* Remove a repeated callback. Does nothing if the callback is not found. */ |
198 | | void UA_EXPORT UA_THREADSAFE |
199 | | UA_Server_removeCallback(UA_Server *server, UA_UInt64 callbackId); |
200 | | |
201 | | #define UA_Server_removeRepeatedCallback(server, callbackId) \ |
202 | 0 | UA_Server_removeCallback(server, callbackId) |
203 | | |
204 | | /** |
205 | | * Application Notification |
206 | | * ------------------------ |
207 | | * The server defines callbacks to notify the application on defined triggering |
208 | | * points. These callbacks are executed with the (re-entrant) server-mutex held. |
209 | | * |
210 | | * The different types of callback are disambiguated by their type enum. Besides |
211 | | * the global notification callback (which is always triggered), the server |
212 | | * configuration contains specialized callbacks that trigger only for specific |
213 | | * notifications. This can reduce the burden of high-frequency notifications. |
214 | | * |
215 | | * If a specialized notification callback is set, it always gets called before |
216 | | * the global notification callback for the same triggering point. |
217 | | * |
218 | | * See the section on the :ref:`Application Notification` enum for more |
219 | | * documentation on the notifications and their defined payload. */ |
220 | | |
221 | | typedef void (*UA_ServerNotificationCallback)(UA_Server *server, |
222 | | UA_ApplicationNotificationType type, |
223 | | const UA_KeyValueMap payload); |
224 | | |
225 | | /** |
226 | | * SecureChannel Handling |
227 | | * ---------------------- |
228 | | * The server opens new SecureChannels internally when a server socket is |
229 | | * active. Information about SecureChannels and their state is notified with |
230 | | * UA_APPLICATIONNOTIFICATIONTYPE_SECURECHANNEL. SecureChannels can be manually |
231 | | * closed. This leaves any attached session alive so that it can potentially |
232 | | * reconnect. */ |
233 | | |
234 | | UA_EXPORT UA_StatusCode UA_THREADSAFE |
235 | | UA_Server_closeSecureChannel(UA_Server *server, UA_UInt32 channelId, |
236 | | UA_ShutdownReason reason); |
237 | | |
238 | | /** |
239 | | * .. _server-session-handling: |
240 | | * |
241 | | * Session Handling |
242 | | * ---------------- |
243 | | * Sessions are managed via the OPC UA Session Service Set (CreateSession, |
244 | | * ActivateSession, CloseSession). The identifier of sessions is generated |
245 | | * internally in the server and is always a Guid-NodeId. |
246 | | * |
247 | | * The creation of sessions is passed to the :ref:`access-control`. There, the |
248 | | * authentication information is evaluated and a context-pointer is attached to |
249 | | * the new session. The context pointer (and the session identifier) are then |
250 | | * forwarded to all user-defined callbacks that can be triggere by a session. |
251 | | * |
252 | | * When the operations from the OPC UA Services are invoked locally via the |
253 | | * C-API, this implies that the operations are executed with the access rights |
254 | | * of the "admin-session" that is always present in a server. Any AccessControl |
255 | | * checks are omitted for the admin-session. |
256 | | * |
257 | | * The admin-session has the identifier |
258 | | * ``g=00000001-0000-0000-0000-000000000000``. Its session context pointer needs |
259 | | * to be manually set (NULL by default). */ |
260 | | |
261 | | void UA_EXPORT |
262 | | UA_Server_setAdminSessionContext(UA_Server *server, void *context); |
263 | | |
264 | | /* Manually close a session */ |
265 | | UA_EXPORT UA_StatusCode UA_THREADSAFE |
266 | | UA_Server_closeSession(UA_Server *server, const UA_NodeId *sessionId); |
267 | | |
268 | | /** |
269 | | * Besides the session context pointer from the AccessControl plugin, a session |
270 | | * carries attributes in a key-value map. Always defined (and read-only) session |
271 | | * attributes are: |
272 | | * |
273 | | * - ``0:localeIds`` (``UA_String``): List of preferred languages |
274 | | * - ``0:clientDescription`` (``UA_ApplicationDescription``): Client description |
275 | | * - ``0:sessionName`` (``String``): Client-defined name of the session |
276 | | * - ``0:clientUserId`` (``String``): User identifier used to activate the session |
277 | | * |
278 | | * Additional attributes can be set manually with the API below. */ |
279 | | |
280 | | /* Returns a shallow copy of the attribute (don't _clear or _delete manually). |
281 | | * While the method is thread-safe, the returned value is not protected. Only |
282 | | * use it in a (callback) context where the server is locked for the current |
283 | | * thread. */ |
284 | | UA_EXPORT UA_StatusCode UA_THREADSAFE |
285 | | UA_Server_getSessionAttribute(UA_Server *server, const UA_NodeId *sessionId, |
286 | | const UA_QualifiedName key, UA_Variant *outValue); |
287 | | |
288 | | /* Return a deep copy of the attribute */ |
289 | | UA_EXPORT UA_StatusCode UA_THREADSAFE |
290 | | UA_Server_getSessionAttributeCopy(UA_Server *server, const UA_NodeId *sessionId, |
291 | | const UA_QualifiedName key, UA_Variant *outValue); |
292 | | |
293 | | /* Returns NULL if the attribute is not defined or not a scalar or not of the |
294 | | * right datatype. Otherwise a shallow copy of the scalar value is created at |
295 | | * the target location of the void pointer (don't _clear or _delete manually). |
296 | | * While the method is thread-safe, the returned value is not protected. Only |
297 | | * use it in a (callback) context where the server is locked for the current |
298 | | * thread. */ |
299 | | UA_EXPORT UA_StatusCode UA_THREADSAFE |
300 | | UA_Server_getSessionAttribute_scalar(UA_Server *server, |
301 | | const UA_NodeId *sessionId, |
302 | | const UA_QualifiedName key, |
303 | | const UA_DataType *type, |
304 | | void *outValue); |
305 | | |
306 | | UA_EXPORT UA_StatusCode UA_THREADSAFE |
307 | | UA_Server_setSessionAttribute(UA_Server *server, const UA_NodeId *sessionId, |
308 | | const UA_QualifiedName key, |
309 | | const UA_Variant *value); |
310 | | |
311 | | UA_EXPORT UA_StatusCode UA_THREADSAFE |
312 | | UA_Server_deleteSessionAttribute(UA_Server *server, const UA_NodeId *sessionId, |
313 | | const UA_QualifiedName key); |
314 | | |
315 | | /** |
316 | | * Attribute Service Set |
317 | | * --------------------- |
318 | | * The functions for reading and writing node attributes call the regular read |
319 | | * and write service in the background that are also used over the network. |
320 | | * |
321 | | * The following attributes cannot be read, since the local "admin" user always |
322 | | * has full rights. |
323 | | * |
324 | | * - UserWriteMask |
325 | | * - UserAccessLevel |
326 | | * - UserExecutable */ |
327 | | |
328 | | /* Read an attribute of a node. Returns a deep copy. */ |
329 | | UA_DataValue UA_EXPORT UA_THREADSAFE |
330 | | UA_Server_read(UA_Server *server, const UA_ReadValueId *item, |
331 | | UA_TimestampsToReturn timestamps); |
332 | | |
333 | | /** |
334 | | * The following specialized read methods are a shorthand for the regular read |
335 | | * and set a deep copy of the attribute to the ``out`` pointer (when |
336 | | * successful). */ |
337 | | |
338 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
339 | | UA_Server_readNodeId(UA_Server *server, const UA_NodeId nodeId, |
340 | | UA_NodeId *out); |
341 | | |
342 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
343 | | UA_Server_readNodeClass(UA_Server *server, const UA_NodeId nodeId, |
344 | | UA_NodeClass *out); |
345 | | |
346 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
347 | | UA_Server_readBrowseName(UA_Server *server, const UA_NodeId nodeId, |
348 | | UA_QualifiedName *out); |
349 | | |
350 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
351 | | UA_Server_readDisplayName(UA_Server *server, const UA_NodeId nodeId, |
352 | | UA_LocalizedText *out); |
353 | | |
354 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
355 | | UA_Server_readDescription(UA_Server *server, const UA_NodeId nodeId, |
356 | | UA_LocalizedText *out); |
357 | | |
358 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
359 | | UA_Server_readWriteMask(UA_Server *server, const UA_NodeId nodeId, |
360 | | UA_UInt32 *out); |
361 | | |
362 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
363 | | UA_Server_readIsAbstract(UA_Server *server, const UA_NodeId nodeId, |
364 | | UA_Boolean *out); |
365 | | |
366 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
367 | | UA_Server_readSymmetric(UA_Server *server, const UA_NodeId nodeId, |
368 | | UA_Boolean *out); |
369 | | |
370 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
371 | | UA_Server_readInverseName(UA_Server *server, const UA_NodeId nodeId, |
372 | | UA_LocalizedText *out); |
373 | | |
374 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
375 | | UA_Server_readContainsNoLoops(UA_Server *server, const UA_NodeId nodeId, |
376 | | UA_Boolean *out); |
377 | | |
378 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
379 | | UA_Server_readEventNotifier(UA_Server *server, const UA_NodeId nodeId, |
380 | | UA_Byte *out); |
381 | | |
382 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
383 | | UA_Server_readValue(UA_Server *server, const UA_NodeId nodeId, |
384 | | UA_Variant *out); |
385 | | |
386 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
387 | | UA_Server_readDataType(UA_Server *server, const UA_NodeId nodeId, |
388 | | UA_NodeId *out); |
389 | | |
390 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
391 | | UA_Server_readValueRank(UA_Server *server, const UA_NodeId nodeId, |
392 | | UA_Int32 *out); |
393 | | |
394 | | /* Returns a variant with an uint32 array */ |
395 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
396 | | UA_Server_readArrayDimensions(UA_Server *server, const UA_NodeId nodeId, |
397 | | UA_Variant *out); |
398 | | |
399 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
400 | | UA_Server_readAccessLevel(UA_Server *server, const UA_NodeId nodeId, |
401 | | UA_Byte *out); |
402 | | |
403 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
404 | | UA_Server_readAccessLevelEx(UA_Server *server, const UA_NodeId nodeId, |
405 | | UA_UInt32 *out); |
406 | | |
407 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
408 | | UA_Server_readMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId, |
409 | | UA_Double *out); |
410 | | |
411 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
412 | | UA_Server_readHistorizing(UA_Server *server, const UA_NodeId nodeId, |
413 | | UA_Boolean *out); |
414 | | |
415 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
416 | | UA_Server_readExecutable(UA_Server *server, const UA_NodeId nodeId, |
417 | | UA_Boolean *out); |
418 | | |
419 | | /* Returns a variant with a UA_RolePermissionType array */ |
420 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
421 | | UA_Server_readRolePermissions(UA_Server *server, const UA_NodeId nodeId, |
422 | | UA_Variant *out); |
423 | | |
424 | | /* Returns a variant with a UA_RolePermissionType array */ |
425 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
426 | | UA_Server_readUserRolePermissions(UA_Server *server, const UA_NodeId nodeId, |
427 | | UA_Variant *out); |
428 | | |
429 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
430 | | UA_Server_readAccessRestrictions(UA_Server *server, const UA_NodeId nodeId, |
431 | | UA_AccessRestrictionType *out); |
432 | | |
433 | | /** |
434 | | * The following node attributes cannot be written once a node has been created: |
435 | | * |
436 | | * - NodeClass |
437 | | * - NodeId |
438 | | * - Symmetric |
439 | | * - ContainsNoLoops |
440 | | * |
441 | | * The following attributes cannot be written from C-API, as they are specific |
442 | | * to the session (context set by the access control callback): |
443 | | * |
444 | | * - UserWriteMask |
445 | | * - UserAccessLevel |
446 | | * - UserExecutable |
447 | | */ |
448 | | |
449 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
450 | | UA_Server_write(UA_Server *server, const UA_WriteValue *value); |
451 | | |
452 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
453 | | UA_Server_writeBrowseName(UA_Server *server, const UA_NodeId nodeId, |
454 | | const UA_QualifiedName browseName); |
455 | | |
456 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
457 | | UA_Server_writeDisplayName(UA_Server *server, const UA_NodeId nodeId, |
458 | | const UA_LocalizedText displayName); |
459 | | |
460 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
461 | | UA_Server_writeDescription(UA_Server *server, const UA_NodeId nodeId, |
462 | | const UA_LocalizedText description); |
463 | | |
464 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
465 | | UA_Server_writeWriteMask(UA_Server *server, const UA_NodeId nodeId, |
466 | | const UA_UInt32 writeMask); |
467 | | |
468 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
469 | | UA_Server_writeIsAbstract(UA_Server *server, const UA_NodeId nodeId, |
470 | | const UA_Boolean isAbstract); |
471 | | |
472 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
473 | | UA_Server_writeInverseName(UA_Server *server, const UA_NodeId nodeId, |
474 | | const UA_LocalizedText inverseName); |
475 | | |
476 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
477 | | UA_Server_writeEventNotifier(UA_Server *server, const UA_NodeId nodeId, |
478 | | const UA_Byte eventNotifier); |
479 | | |
480 | | /* The value attribute is a DataValue. Here only a variant is provided. The |
481 | | * StatusCode is set to UA_STATUSCODE_GOOD, sourceTimestamp and serverTimestamp |
482 | | * are set to UA_DateTime_now(). See below for setting the full DataValue. */ |
483 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
484 | | UA_Server_writeValue(UA_Server *server, const UA_NodeId nodeId, |
485 | | const UA_Variant value); |
486 | | |
487 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
488 | | UA_Server_writeDataValue(UA_Server *server, const UA_NodeId nodeId, |
489 | | const UA_DataValue value); |
490 | | |
491 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
492 | | UA_Server_writeDataType(UA_Server *server, const UA_NodeId nodeId, |
493 | | const UA_NodeId dataType); |
494 | | |
495 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
496 | | UA_Server_writeValueRank(UA_Server *server, const UA_NodeId nodeId, |
497 | | const UA_Int32 valueRank); |
498 | | |
499 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
500 | | UA_Server_writeArrayDimensions(UA_Server *server, const UA_NodeId nodeId, |
501 | | const UA_Variant arrayDimensions); |
502 | | |
503 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
504 | | UA_Server_writeAccessLevel(UA_Server *server, const UA_NodeId nodeId, |
505 | | const UA_Byte accessLevel); |
506 | | |
507 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
508 | | UA_Server_writeAccessLevelEx(UA_Server *server, const UA_NodeId nodeId, |
509 | | const UA_UInt32 accessLevelEx); |
510 | | |
511 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
512 | | UA_Server_writeMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId, |
513 | | const UA_Double miniumSamplingInterval); |
514 | | |
515 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
516 | | UA_Server_writeHistorizing(UA_Server *server, const UA_NodeId nodeId, |
517 | | const UA_Boolean historizing); |
518 | | |
519 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
520 | | UA_Server_writeExecutable(UA_Server *server, const UA_NodeId nodeId, |
521 | | const UA_Boolean executable); |
522 | | |
523 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
524 | | UA_Server_writeRolePermissions(UA_Server *server, const UA_NodeId nodeId, |
525 | | const UA_Variant rolePermissions); |
526 | | |
527 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
528 | | UA_Server_writeAccessRestrictions(UA_Server *server, const UA_NodeId nodeId, |
529 | | const UA_AccessRestrictionType accessRestrictions); |
530 | | |
531 | | /** |
532 | | * .. _server-method-call: |
533 | | * |
534 | | * Method Service Set |
535 | | * ------------------ |
536 | | * |
537 | | * The Method Service Set defines the means to invoke methods. A MethodNode is a |
538 | | * component of an ObjectNode or of an ObjectTypeNode. The input and output |
539 | | * arguments of a method are a list of ``UA_Variant``. The type- and |
540 | | * size-requirements of the arguments can be retrieved from the |
541 | | * **InputArguments** and **OutputArguments** variable below the MethodNode. |
542 | | * |
543 | | * For calling a method, both ``methodId`` and ``objectId`` need to be defined |
544 | | * by their NodeId. This is required because the same MethodNode can be |
545 | | * referenced from multiple objects. |
546 | | * |
547 | | * In this server implementation, when an object is instantiated from a an |
548 | | * ObjectType, all (mandatory) methods are automatically added to the new object |
549 | | * instance. This is done by adding an additional reference to the original |
550 | | * MethodNode. It is however possible to add a custom MethodNode directly to the |
551 | | * object instance. It is also possible to remove a (optional) MethodNode that |
552 | | * exists in the ObjectType from an instance. |
553 | | * |
554 | | * The ``methodId`` can point to a MethodNode that exists in the ObjectType but |
555 | | * not in the object instance. It is resolved to the actual MethodNode of the |
556 | | * object instance by taking the *BrowseName* attribute of the |
557 | | * ``methodId``-MethodNode and looking up the member of the ``objectId`` object |
558 | | * with the same BrowseName. |
559 | | * |
560 | | * The resolved MethodNode then is used to |
561 | | * |
562 | | * - Check permissions for the current Session to call the method |
563 | | * - Obtain the ``UA_MethodCallback`` to execute |
564 | | * - Forwarded as ``methodId`` to said callback |
565 | | * |
566 | | * To showcase the resolution of the MethodNode with an example, consider this |
567 | | * information model:: |
568 | | * |
569 | | * ObjectType ObjectType Object |
570 | | * Creature (i=10) <-isSubTypeOf- Insect (i=20) <-hasTypeDef- Ant (i=30) |
571 | | * | | | |
572 | | * hasComponent hasComponent hasComponent |
573 | | * | | | |
574 | | * v v v |
575 | | * Methods Methods Methods |
576 | | * - Walk (i=11) - Walk (i=21) - Walk (i=31) |
577 | | * - Fly (i=12) - Fly (i=22) - Amount (i=33) |
578 | | * - Amount (i=13) - Amount (i=23) |
579 | | * |
580 | | * The following table shows what ``methodId`` - ``objectId`` combinations are |
581 | | * allowed to be used as parameters for the Call service and the resolved |
582 | | * ``methodId``. |
583 | | * |
584 | | * ======== ======== ==================================== ================= |
585 | | * objectId methodId Corresponds to in OO-languages Resolved methodId |
586 | | * ======== ======== ==================================== ================= |
587 | | * i=30 i=31 ``Ant a; a.Walk();`` i=31 |
588 | | * i=30 i=21 ``Ant a; Insect i = a; i.Walk();`` i=31 |
589 | | * i=30 i=11 ``Ant a; Creature c = a; c.Walk();`` i=31 |
590 | | * i=20 i=23 ``Insect::Amount();`` i=23 |
591 | | * i=10 i=13 ``Creature::Amount();`` i=13 |
592 | | * ======== ======== ==================================== ================= |
593 | | * |
594 | | * The next table shows ``methodId`` - ``objectId`` combinations that are not |
595 | | * allowed. Note that an ObjecType cannot execute a methodId from a subtype or |
596 | | * instance. |
597 | | * |
598 | | * ======== ======== ===================================================== |
599 | | * objectId methodId Reason |
600 | | * ======== ======== ===================================================== |
601 | | * i=30 i=22 Object "Ant" does not own a method "Fly" |
602 | | * i=30 i=12 Object "Ant" does not own a method "Fly" |
603 | | * i=10 i=23 The method is not owned by the object type "Creature" |
604 | | * i=20 i=13 The method is not owned by the object type "Insect" |
605 | | * ======== ======== ===================================================== */ |
606 | | |
607 | | #ifdef UA_ENABLE_METHODCALLS |
608 | | UA_CallMethodResult UA_EXPORT UA_THREADSAFE |
609 | | UA_Server_call(UA_Server *server, const UA_CallMethodRequest *request); |
610 | | #endif |
611 | | |
612 | | /** |
613 | | * View Service Set |
614 | | * ---------------- |
615 | | * The View Service Set allows Clients to discover Nodes by browsing the |
616 | | * information model. */ |
617 | | |
618 | | /* Browse the references of a particular node. See the definition of |
619 | | * BrowseDescription structure for details. */ |
620 | | UA_BrowseResult UA_EXPORT UA_THREADSAFE |
621 | | UA_Server_browse(UA_Server *server, UA_UInt32 maxReferences, |
622 | | const UA_BrowseDescription *bd); |
623 | | |
624 | | UA_BrowseResult UA_EXPORT UA_THREADSAFE |
625 | | UA_Server_browseNext(UA_Server *server, UA_Boolean releaseContinuationPoint, |
626 | | const UA_ByteString *continuationPoint); |
627 | | |
628 | | /* Non-standard version of the Browse service that recurses into child nodes. |
629 | | * |
630 | | * Possible loops (that can occur for non-hierarchical references) are handled |
631 | | * internally. Every node is added at most once to the results array. |
632 | | * |
633 | | * Nodes are only added if they match the NodeClassMask in the |
634 | | * BrowseDescription. However, child nodes are still recursed into if the |
635 | | * NodeClass does not match. So it is possible, for example, to get all |
636 | | * VariableNodes below a certain ObjectNode, with additional objects in the |
637 | | * hierarchy below. */ |
638 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
639 | | UA_Server_browseRecursive(UA_Server *server, const UA_BrowseDescription *bd, |
640 | | size_t *resultsSize, UA_ExpandedNodeId **results); |
641 | | |
642 | | /* Translate abrowse path to (potentially several) NodeIds. Each browse path is |
643 | | * constructed of a starting Node and a RelativePath. The specified starting |
644 | | * Node identifies the Node from which the RelativePath is based. The |
645 | | * RelativePath contains a sequence of ReferenceTypes and BrowseNames. */ |
646 | | UA_BrowsePathResult UA_EXPORT UA_THREADSAFE |
647 | | UA_Server_translateBrowsePathToNodeIds(UA_Server *server, |
648 | | const UA_BrowsePath *browsePath); |
649 | | |
650 | | /* A simplified TranslateBrowsePathsToNodeIds based on the |
651 | | * SimpleAttributeOperand type (Part 4, 7.4.4.5). |
652 | | * |
653 | | * This specifies a relative path using a list of BrowseNames instead of the |
654 | | * RelativePath structure. The list of BrowseNames is equivalent to a |
655 | | * RelativePath that specifies forward references which are subtypes of the |
656 | | * HierarchicalReferences ReferenceType. All Nodes followed by the browsePath |
657 | | * shall be of the NodeClass Object or Variable. */ |
658 | | UA_BrowsePathResult UA_EXPORT UA_THREADSAFE |
659 | | UA_Server_browseSimplifiedBrowsePath(UA_Server *server, const UA_NodeId origin, |
660 | | size_t browsePathSize, |
661 | | const UA_QualifiedName *browsePath); |
662 | | |
663 | | /* Returns the target of a "HasTypeDefinition" reference (or inverse |
664 | | * "HasSubtype" reference for type nodes) */ |
665 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
666 | | UA_Server_getNodeType(UA_Server *server, const UA_NodeId nodeId, |
667 | | UA_NodeId *outTypeId); |
668 | | |
669 | | /* Iterate over all nodes referenced by parentNodeId by calling the callback |
670 | | * function for each child node (in ifdef because GCC/CLANG handle include order |
671 | | * differently) */ |
672 | | typedef UA_StatusCode |
673 | | (*UA_ServerNodeIteratorCallback)(UA_NodeId childId, UA_Boolean isInverse, |
674 | | UA_NodeId referenceTypeId, void *handle); |
675 | | |
676 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
677 | | UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId, |
678 | | UA_ServerNodeIteratorCallback callback, |
679 | | void *handle); |
680 | | |
681 | | /** |
682 | | * .. _local-monitoreditems: |
683 | | * |
684 | | * MonitoredItem Service Set |
685 | | * ------------------------- |
686 | | * MonitoredItems are used with the Subscription mechanism of OPC UA to |
687 | | * transported notifications for data changes and events. MonitoredItems can |
688 | | * also be registered locally. Notifications are then forwarded to a |
689 | | * user-defined callback instead of a remote client. |
690 | | * |
691 | | * Local MonitoredItems are delivered asynchronously. That is, the notification |
692 | | * is inserted as a *Delayed Callback* for the EventLoop. The callback is then |
693 | | * triggered when the control flow next returns to the EventLoop. */ |
694 | | |
695 | | #ifdef UA_ENABLE_SUBSCRIPTIONS |
696 | | |
697 | | /* Delete a local MonitoredItem. Used for both DataChange- and |
698 | | * Event-MonitoredItems. */ |
699 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
700 | | UA_Server_deleteMonitoredItem(UA_Server *server, UA_UInt32 monitoredItemId); |
701 | | |
702 | | typedef void (*UA_Server_DataChangeNotificationCallback) |
703 | | (UA_Server *server, UA_UInt32 monitoredItemId, void *monitoredItemContext, |
704 | | const UA_NodeId *nodeId, void *nodeContext, UA_UInt32 attributeId, |
705 | | const UA_DataValue *value); |
706 | | |
707 | | /** |
708 | | * DataChange MonitoredItem use a sampling interval and filter criteria to |
709 | | * notify the userland about value changes. Note that the sampling interval can |
710 | | * also be zero to be notified about changes "right away". For this we hook the |
711 | | * MonitoredItem into the observed Node and check the filter after every call of |
712 | | * the Write-Service. */ |
713 | | |
714 | | /* Create a local MonitoredItem to detect data changes. |
715 | | * |
716 | | * @param server The server executing the MonitoredItem |
717 | | * @param timestampsToReturn Shall timestamps be added to the value for the |
718 | | * callback? |
719 | | * @param item The parameters of the new MonitoredItem. Note that the attribute |
720 | | * of the ReadValueId (the node that is monitored) can not be |
721 | | * ``UA_ATTRIBUTEID_EVENTNOTIFIER``. See below for event notifications. |
722 | | * @param monitoredItemContext A pointer that is forwarded with the callback |
723 | | * @param callback The callback that is executed on detected data changes |
724 | | * @return Returns a description of the created MonitoredItem. The structure |
725 | | * also contains a StatusCode (in case of an error) and the identifier |
726 | | * of the new MonitoredItem. */ |
727 | | UA_MonitoredItemCreateResult UA_EXPORT UA_THREADSAFE |
728 | | UA_Server_createDataChangeMonitoredItem(UA_Server *server, |
729 | | UA_TimestampsToReturn timestampsToReturn, |
730 | | const UA_MonitoredItemCreateRequest item, |
731 | | void *monitoredItemContext, |
732 | | UA_Server_DataChangeNotificationCallback callback); |
733 | | |
734 | | /** |
735 | | * See the section on :ref`events` for how to emit events in the server. |
736 | | * |
737 | | * Event-MonitoredItems emit notifications with a list of "fields" (variants). |
738 | | * The fields are specified as *SimpleAttributeOperands* in the select-clause of |
739 | | * the MonitoredItem's event filter. For the local event callback, instead of |
740 | | * using a list of variants, we use a key-value map for the event fields. They |
741 | | * key names are generated with ``UA_SimpleAttributeOperand_print`` to get a |
742 | | * human-readable representation. |
743 | | * |
744 | | * The received event-fields map could look like this:: |
745 | | * |
746 | | * /Severity => UInt16(1000) |
747 | | * /Message => LocalizedText("en-US", "My Event Message") |
748 | | * /EventType => NodeId(i=50831) |
749 | | * /SourceNode => NodeId(i=2253) |
750 | | * |
751 | | * The order of the keys is identical to the order of SimpleAttributeOperands in |
752 | | * the select-clause. */ |
753 | | |
754 | | #ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS |
755 | | |
756 | | typedef void (*UA_Server_EventNotificationCallback) |
757 | | (UA_Server *server, UA_UInt32 monitoredItemId, void *monitoredItemContext, |
758 | | const UA_KeyValueMap eventFields); |
759 | | |
760 | | /* Create a local MonitoredItem for Events. The API is simplifed compared to a |
761 | | * UA_MonitoredItemCreateRequest. The unavailable options are not relevant for |
762 | | * local MonitoredItems (e.g. the queue size) or not relevant for Event |
763 | | * MonitoredItems (e.g. the sampling interval). |
764 | | * |
765 | | * @param server The server executing the MonitoredItem |
766 | | * @param nodeId The node where events are collected. Note that events "bubble |
767 | | * up" to their parents (via hierarchical references). |
768 | | * @param filter The filter defined which event fields are selected (select |
769 | | * clauses) and which events are considered for this particular |
770 | | * MonitoredItem (where clause). |
771 | | * @param monitoredItemContext A pointer that is forwarded with the callback |
772 | | * @param callback The callback that is executed for each event |
773 | | * @return Returns a description of the created MonitoredItem. The structure |
774 | | * also contains a StatusCode (in case of an error) and the identifier |
775 | | * of the new MonitoredItem. */ |
776 | | UA_MonitoredItemCreateResult UA_EXPORT UA_THREADSAFE |
777 | | UA_Server_createEventMonitoredItem(UA_Server *server, const UA_NodeId nodeId, |
778 | | const UA_EventFilter filter, |
779 | | void *monitoredItemContext, |
780 | | UA_Server_EventNotificationCallback callback); |
781 | | |
782 | | /* Extended version UA_Server_createEventMonitoredItem that allows setting of |
783 | | * uncommon parameters (for local MonitoredItems) like the MonitoringMode and |
784 | | * queue sizes. |
785 | | * |
786 | | * @param server The server executing the MonitoredItem |
787 | | * @param item The description of the MonitoredItem. Must use |
788 | | * UA_ATTRIBUTEID_EVENTNOTIFIER and an EventFilter. |
789 | | * @param monitoredItemContext A pointer that is forwarded with the callback |
790 | | * @param callback The callback that is executed for each event |
791 | | * @return Returns a description of the created MonitoredItem. The structure |
792 | | * also contains a StatusCode (in case of an error) and the identifier |
793 | | * of the new MonitoredItem. */ |
794 | | UA_MonitoredItemCreateResult UA_EXPORT UA_THREADSAFE |
795 | | UA_Server_createEventMonitoredItemEx(UA_Server *server, |
796 | | const UA_MonitoredItemCreateRequest item, |
797 | | void *monitoredItemContext, |
798 | | UA_Server_EventNotificationCallback callback); |
799 | | |
800 | | #endif /* UA_ENABLE_SUBSCRIPTIONS_EVENTS */ |
801 | | |
802 | | #endif /* UA_ENABLE_SUBSCRIPTIONS */ |
803 | | |
804 | | /** |
805 | | * .. _server-node-management: |
806 | | * |
807 | | * Node Management Service Set |
808 | | * --------------------------- |
809 | | * When creating dynamic node instances at runtime, chances are that you will |
810 | | * not care about the specific NodeId of the new node, as long as you can |
811 | | * reference it later. When passing numeric NodeIds with a numeric identifier 0, |
812 | | * the stack evaluates this as "select a random unassigned numeric NodeId in |
813 | | * that namespace". To find out which NodeId was actually assigned to the new |
814 | | * node, you may pass a pointer `outNewNodeId`, which will (after a successful |
815 | | * node insertion) contain the nodeId of the new node. You may also pass a |
816 | | * ``NULL`` pointer if this result is not needed. |
817 | | * |
818 | | * See the Section :ref:`node-lifecycle` on constructors and on attaching |
819 | | * user-defined data to nodes. |
820 | | * |
821 | | * The Section :ref:`default-node-attributes` contains useful starting points |
822 | | * for defining node attributes. Forgetting to set the ValueRank or the |
823 | | * AccessLevel leads to errors that can be hard to track down for new users. The |
824 | | * default attributes have a high likelihood to "do the right thing". |
825 | | * |
826 | | * The methods for node addition and deletion take mostly const arguments that |
827 | | * are not modified. When creating a node, a deep copy of the node identifier, |
828 | | * node attributes, etc. is created. Therefore, it is possible to call for |
829 | | * example ``UA_Server_addVariablenode`` with a value attribute (a |
830 | | * :ref:`variant`) pointing to a memory location on the stack. |
831 | | * |
832 | | * .. _variable-node: |
833 | | * |
834 | | * VariableNode |
835 | | * ~~~~~~~~~~~~ |
836 | | * Variables store values as well as contraints for possible values. There are |
837 | | * three options for storing the value: Internal in the VariableNode data |
838 | | * structure itself, external with a double-pointer (to switch to an updated |
839 | | * value with an atomic pointer-replacing operation) or with a callback |
840 | | * registered by the application. */ |
841 | | |
842 | | typedef enum { |
843 | | UA_VALUESOURCETYPE_INTERNAL = 0, |
844 | | UA_VALUESOURCETYPE_EXTERNAL = 1, |
845 | | UA_VALUESOURCETYPE_CALLBACK = 2 |
846 | | } UA_ValueSourceType; |
847 | | |
848 | | typedef struct { |
849 | | /* Notify the application before the value attribute is read. Ignored if |
850 | | * NULL. It is possible to write into the value attribute during onRead |
851 | | * (using the write service). The node is re-retrieved from the Nodestore |
852 | | * afterwards so that changes are considered in the following read |
853 | | * operation. |
854 | | * |
855 | | * @param handle Points to user-provided data for the callback. |
856 | | * @param nodeid The identifier of the node. |
857 | | * @param data Points to the current node value. |
858 | | * @param range Points to the numeric range the client wants to read from |
859 | | * (or NULL). */ |
860 | | void (*onRead)(UA_Server *server, const UA_NodeId *sessionId, |
861 | | void *sessionContext, const UA_NodeId *nodeid, |
862 | | void *nodeContext, const UA_NumericRange *range, |
863 | | const UA_DataValue *value); |
864 | | |
865 | | /* Notify the application after writing the value attribute. Ignored if |
866 | | * NULL. The node is re-retrieved after writing, so that the new value is |
867 | | * visible in the callback. |
868 | | * |
869 | | * @param server The server executing the callback |
870 | | * @sessionId The identifier of the session |
871 | | * @sessionContext Additional data attached to the session |
872 | | * in the access control layer |
873 | | * @param nodeid The identifier of the node. |
874 | | * @param nodeUserContext Additional data attached to the node by |
875 | | * the user. |
876 | | * @param nodeConstructorContext Additional data attached to the node |
877 | | * by the type constructor(s). |
878 | | * @param range Points to the numeric range the client wants to write to (or |
879 | | * NULL). */ |
880 | | void (*onWrite)(UA_Server *server, const UA_NodeId *sessionId, |
881 | | void *sessionContext, const UA_NodeId *nodeId, |
882 | | void *nodeContext, const UA_NumericRange *range, |
883 | | const UA_DataValue *data); |
884 | | } UA_ValueSourceNotifications; |
885 | | |
886 | | typedef struct { |
887 | | /* Copies the data from the source into the provided value. |
888 | | * |
889 | | * !! ZERO-COPY OPERATIONS POSSIBLE !! |
890 | | * It is not required to return a copy of the actual content data. You can |
891 | | * return a pointer to memory owned by the user. Memory can be reused |
892 | | * between read callbacks of a DataSource, as the result is already encoded |
893 | | * on the network buffer between each read operation. |
894 | | * |
895 | | * To use zero-copy reads, set the value of the `value->value` Variant |
896 | | * without copying, e.g. with `UA_Variant_setScalar`. Then, also set |
897 | | * `value->value.storageType` to `UA_VARIANT_DATA_NODELETE` to prevent the |
898 | | * memory being cleaned up. Don't forget to also set `value->hasValue` to |
899 | | * true to indicate the presence of a value. |
900 | | * |
901 | | * To make an async read, return UA_STATUSCODE_GOODCOMPLETESASYNCHRONOUSLY. |
902 | | * The result can then be set at a later time using |
903 | | * UA_Server_setAsyncReadResult. Note that the server might cancel the async |
904 | | * read by calling serverConfig->asyncOperationCancelCallback. |
905 | | * |
906 | | * @param server The server executing the callback |
907 | | * @param sessionId The identifier of the session |
908 | | * @param sessionContext Additional data attached to the session in the |
909 | | * access control layer |
910 | | * @param nodeId The identifier of the node being read from |
911 | | * @param nodeContext Additional data attached to the node by the user |
912 | | * @param includeSourceTimeStamp If true, then the datasource is expected to |
913 | | * set the source timestamp in the returned value |
914 | | * @param range If not null, then the datasource shall return only a |
915 | | * selection of the (nonscalar) data. Set |
916 | | * UA_STATUSCODE_BADINDEXRANGEINVALID in the value if this does not |
917 | | * apply |
918 | | * @param value The (non-null) DataValue that is returned to the client. The |
919 | | * data source sets the read data, the result status and optionally a |
920 | | * sourcetimestamp. |
921 | | * @return Returns a status code for logging. Error codes intended for the |
922 | | * original caller are set in the value. If an error is returned, |
923 | | * then no releasing of the value is done. */ |
924 | | UA_StatusCode (*read)(UA_Server *server, const UA_NodeId *sessionId, |
925 | | void *sessionContext, const UA_NodeId *nodeId, |
926 | | void *nodeContext, UA_Boolean includeSourceTimeStamp, |
927 | | const UA_NumericRange *range, UA_DataValue *value); |
928 | | |
929 | | /* Write into a data source. This method pointer can be NULL if the |
930 | | * operation is unsupported. |
931 | | * |
932 | | * To make an async write, return UA_STATUSCODE_GOODCOMPLETESASYNCHRONOUSLY. |
933 | | * The result can then be set at a later time using |
934 | | * UA_Server_setAsyncWriteResult. Note that the server might cancel the |
935 | | * async read by calling serverConfig->asyncOperationCancelCallback. |
936 | | * |
937 | | * @param server The server executing the callback |
938 | | * @param sessionId The identifier of the session |
939 | | * @param sessionContext Additional data attached to the session in the |
940 | | * access control layer |
941 | | * @param nodeId The identifier of the node being written to |
942 | | * @param nodeContext Additional data attached to the node by the user |
943 | | * @param range If not NULL, then the datasource shall return only a |
944 | | * selection of the (nonscalar) data. Set |
945 | | * UA_STATUSCODE_BADINDEXRANGEINVALID in the value if this does not |
946 | | * apply |
947 | | * @param value The (non-NULL) DataValue that has been written by the client. |
948 | | * The data source contains the written data, the result status and |
949 | | * optionally a sourcetimestamp |
950 | | * @return Returns a status code for logging. Error codes intended for the |
951 | | * original caller are set in the value. If an error is returned, |
952 | | * then no releasing of the value is done. */ |
953 | | UA_StatusCode (*write)(UA_Server *server, const UA_NodeId *sessionId, |
954 | | void *sessionContext, const UA_NodeId *nodeId, |
955 | | void *nodeContext, const UA_NumericRange *range, |
956 | | const UA_DataValue *value); |
957 | | } UA_CallbackValueSource; |
958 | | |
959 | | /** |
960 | | * By default, when adding a VariableNode, the value from the |
961 | | * ``UA_VariableAttributes`` is used. The methods following afterwards can be |
962 | | * used to override the value source. */ |
963 | | |
964 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
965 | | UA_Server_addVariableNode(UA_Server *server, const UA_NodeId requestedNewNodeId, |
966 | | const UA_NodeId parentNodeId, |
967 | | const UA_NodeId referenceTypeId, |
968 | | const UA_QualifiedName browseName, |
969 | | const UA_NodeId typeDefinition, |
970 | | const UA_VariableAttributes attr, |
971 | | void *nodeContext, UA_NodeId *outNewNodeId); |
972 | | |
973 | | /* Add a VariableNode with a callback value-source */ |
974 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
975 | | UA_Server_addCallbackValueSourceVariableNode(UA_Server *server, |
976 | | const UA_NodeId requestedNewNodeId, |
977 | | const UA_NodeId parentNodeId, |
978 | | const UA_NodeId referenceTypeId, |
979 | | const UA_QualifiedName browseName, |
980 | | const UA_NodeId typeDefinition, |
981 | | const UA_VariableAttributes attr, |
982 | | const UA_CallbackValueSource evs, |
983 | | void *nodeContext, UA_NodeId *outNewNodeId); |
984 | | |
985 | | /* Legacy API */ |
986 | | #define UA_Server_addDataSourceVariableNode(server, requestedNewNodeId, parentNodeId, \ |
987 | | referenceTypeId, browseName, typeDefinition, \ |
988 | | attr, dataSource, nodeContext, outNewNodeId) \ |
989 | | UA_Server_addCallbackValueSourceVariableNode(server, requestedNewNodeId, \ |
990 | | parentNodeId, referenceTypeId, \ |
991 | | browseName, typeDefinition, \ |
992 | | attr, dataSource, nodeContext, \ |
993 | | outNewNodeId) |
994 | | |
995 | | /* Set an internal value source. Both the value argument and the notifications |
996 | | * argument can be NULL. If value is NULL, an existing internal value is kept; |
997 | | * switching from another value source creates an empty internal value. If |
998 | | * notifications is NULL, then all onRead/onWrite notifications are disabled. */ |
999 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1000 | | UA_Server_setVariableNode_internalValueSource(UA_Server *server, |
1001 | | const UA_NodeId nodeId, const UA_DataValue *value, |
1002 | | const UA_ValueSourceNotifications *notifications); |
1003 | | |
1004 | | /* For the external value, no initial copy is made. The node "just" points to |
1005 | | * the provided double-pointer. Otherwise identical to the internal data |
1006 | | * source. */ |
1007 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1008 | | UA_Server_setVariableNode_externalValueSource(UA_Server *server, |
1009 | | const UA_NodeId nodeId, UA_DataValue** value, |
1010 | | const UA_ValueSourceNotifications *notifications); |
1011 | | |
1012 | | /* It is expected that the read callback is implemented. Whenever the value |
1013 | | * attribute is read, the function will be called and asked to fill a |
1014 | | * UA_DataValue structure that contains the value content and additional |
1015 | | * metadata like timestamps. |
1016 | | * |
1017 | | * The write callback can be set to a null-pointer. Then writing into the value |
1018 | | * is disabled. */ |
1019 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1020 | | UA_Server_setVariableNode_callbackValueSource(UA_Server *server, |
1021 | | const UA_NodeId nodeId, const UA_CallbackValueSource evs); |
1022 | | |
1023 | | /* Deprecated API */ |
1024 | | typedef UA_CallbackValueSource UA_DataSource; |
1025 | | #define UA_Server_setVariableNode_dataSource(server, nodeId, dataSource) \ |
1026 | 0 | UA_Server_setVariableNode_callbackValueSource(server, nodeId, dataSource) |
1027 | | |
1028 | | /* Deprecated API */ |
1029 | | typedef UA_ValueSourceNotifications UA_ValueCallback; |
1030 | | #define UA_Server_setVariableNode_valueCallback(server, nodeId, callback) \ |
1031 | | UA_Server_setVariableNode_internalValueSource(server, nodeId, NULL, &callback) |
1032 | | |
1033 | | /* VariableNodes that are "dynamic" (default for user-created variables) receive |
1034 | | * and store a SourceTimestamp. For non-dynamic VariableNodes the current time |
1035 | | * is used for the SourceTimestamp. */ |
1036 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1037 | | UA_Server_setVariableNodeDynamic(UA_Server *server, const UA_NodeId nodeId, |
1038 | | UA_Boolean isDynamic); |
1039 | | |
1040 | | /** |
1041 | | * VariableTypeNode |
1042 | | * ~~~~~~~~~~~~~~~~ */ |
1043 | | |
1044 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1045 | | UA_Server_addVariableTypeNode(UA_Server *server, |
1046 | | const UA_NodeId requestedNewNodeId, |
1047 | | const UA_NodeId parentNodeId, |
1048 | | const UA_NodeId referenceTypeId, |
1049 | | const UA_QualifiedName browseName, |
1050 | | const UA_NodeId typeDefinition, |
1051 | | const UA_VariableTypeAttributes attr, |
1052 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1053 | | |
1054 | | /** |
1055 | | * MethodNode |
1056 | | * ~~~~~~~~~~ |
1057 | | * Please refer to the :ref:`Method Service Set <server-method-call>` to get |
1058 | | * information about which MethodNodes may get executed and would thus require |
1059 | | * callbacks to be registered. */ |
1060 | | |
1061 | | typedef UA_StatusCode |
1062 | | (*UA_MethodCallback)(UA_Server *server, |
1063 | | const UA_NodeId *sessionId, void *sessionContext, |
1064 | | const UA_NodeId *methodId, void *methodContext, |
1065 | | const UA_NodeId *objectId, void *objectContext, |
1066 | | size_t inputSize, const UA_Variant *input, |
1067 | | size_t outputSize, UA_Variant *output); |
1068 | | |
1069 | | #ifdef UA_ENABLE_METHODCALLS |
1070 | | |
1071 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1072 | | UA_Server_addMethodNode(UA_Server *server, const UA_NodeId requestedNewNodeId, |
1073 | | const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId, |
1074 | | const UA_QualifiedName browseName, const UA_MethodAttributes attr, |
1075 | | UA_MethodCallback method, |
1076 | | size_t inputArgumentsSize, const UA_Argument *inputArguments, |
1077 | | size_t outputArgumentsSize, const UA_Argument *outputArguments, |
1078 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1079 | | |
1080 | | /* Extended version, allows the additional definition of fixed NodeIds for the |
1081 | | * InputArgument/OutputArgument child variables */ |
1082 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1083 | | UA_Server_addMethodNodeEx(UA_Server *server, const UA_NodeId requestedNewNodeId, |
1084 | | const UA_NodeId parentNodeId, |
1085 | | const UA_NodeId referenceTypeId, |
1086 | | const UA_QualifiedName browseName, |
1087 | | const UA_MethodAttributes attr, UA_MethodCallback method, |
1088 | | size_t inputArgumentsSize, const UA_Argument *inputArguments, |
1089 | | const UA_NodeId inputArgumentsRequestedNewNodeId, |
1090 | | UA_NodeId *inputArgumentsOutNewNodeId, |
1091 | | size_t outputArgumentsSize, const UA_Argument *outputArguments, |
1092 | | const UA_NodeId outputArgumentsRequestedNewNodeId, |
1093 | | UA_NodeId *outputArgumentsOutNewNodeId, |
1094 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1095 | | |
1096 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1097 | | UA_Server_setMethodNodeCallback(UA_Server *server, |
1098 | | const UA_NodeId methodNodeId, |
1099 | | UA_MethodCallback methodCallback); |
1100 | | |
1101 | | /* Backwards compatibility definition */ |
1102 | | #define UA_Server_setMethodNode_callback(server, methodNodeId, methodCallback) \ |
1103 | | UA_Server_setMethodNodeCallback(server, methodNodeId, methodCallback) |
1104 | | |
1105 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1106 | | UA_Server_getMethodNodeCallback(UA_Server *server, |
1107 | | const UA_NodeId methodNodeId, |
1108 | | UA_MethodCallback *outMethodCallback); |
1109 | | |
1110 | | #endif |
1111 | | |
1112 | | /** |
1113 | | * ObjectNode |
1114 | | * ~~~~~~~~~~ */ |
1115 | | |
1116 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1117 | | UA_Server_addObjectNode(UA_Server *server, const UA_NodeId requestedNewNodeId, |
1118 | | const UA_NodeId parentNodeId, |
1119 | | const UA_NodeId referenceTypeId, |
1120 | | const UA_QualifiedName browseName, |
1121 | | const UA_NodeId typeDefinition, |
1122 | | const UA_ObjectAttributes attr, |
1123 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1124 | | |
1125 | | /** |
1126 | | * ObjectTypeNode |
1127 | | * ~~~~~~~~~~~~~~ */ |
1128 | | |
1129 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1130 | | UA_Server_addObjectTypeNode(UA_Server *server, const UA_NodeId requestedNewNodeId, |
1131 | | const UA_NodeId parentNodeId, |
1132 | | const UA_NodeId referenceTypeId, |
1133 | | const UA_QualifiedName browseName, |
1134 | | const UA_ObjectTypeAttributes attr, |
1135 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1136 | | |
1137 | | /** |
1138 | | * ReferenceTypeNode |
1139 | | * ~~~~~~~~~~~~~~~~~ */ |
1140 | | |
1141 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1142 | | UA_Server_addReferenceTypeNode(UA_Server *server, |
1143 | | const UA_NodeId requestedNewNodeId, |
1144 | | const UA_NodeId parentNodeId, |
1145 | | const UA_NodeId referenceTypeId, |
1146 | | const UA_QualifiedName browseName, |
1147 | | const UA_ReferenceTypeAttributes attr, |
1148 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1149 | | |
1150 | | /** |
1151 | | * DataTypeNode |
1152 | | * ~~~~~~~~~~~~ */ |
1153 | | |
1154 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1155 | | UA_Server_addDataTypeNode(UA_Server *server, |
1156 | | const UA_NodeId requestedNewNodeId, |
1157 | | const UA_NodeId parentNodeId, |
1158 | | const UA_NodeId referenceTypeId, |
1159 | | const UA_QualifiedName browseName, |
1160 | | const UA_DataTypeAttributes attr, |
1161 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1162 | | |
1163 | | /** |
1164 | | * Due to the history of development, the DataTypeAttributes structure used in |
1165 | | * the AddNodes Service does not describe the layout of the DataType. But the |
1166 | | * (newer) structures for describing DataTypes do: |
1167 | | * |
1168 | | * - SimpleTypeDescription |
1169 | | * - EnumDescription |
1170 | | * - StructureDescription |
1171 | | * |
1172 | | * The ``UA_Server_addDataTypeFromDescription`` function translates the |
1173 | | * DataTypeDescription into a UA_DataType structure and adds it to an internal |
1174 | | * array of the server. Then the DataType is automatically decoded in messages |
1175 | | * received by the server. Also the ``DataTypeDefinition`` attribute of the |
1176 | | * corresponding DataTypeNode can then be read via the Read service. |
1177 | | * |
1178 | | * The memory layout of the internally generated ``UA_DataType`` corresponds to |
1179 | | * the matching C-structure including padding. |
1180 | | * |
1181 | | * Note that a DataTypeDescription can be added only once during the lifetime of |
1182 | | * the server. This protects against existing instances of the DataType to |
1183 | | * having their layout changed. */ |
1184 | | |
1185 | | /* Use the DataType description to create an internal UA_DataType entry in the |
1186 | | * server */ |
1187 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1188 | | UA_Server_addDataTypeFromDescription(UA_Server *server, |
1189 | | const UA_ExtensionObject *description); |
1190 | | |
1191 | | /* The same as UA_Server_addDataTypeFromDescription, but with the description |
1192 | | * already converted into a UA_DataType. Makes a copy of the UA_DataType |
1193 | | * internally. */ |
1194 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1195 | | UA_Server_addDataType(UA_Server *server, const UA_NodeId parentNodeId, |
1196 | | const UA_DataType *type); |
1197 | | |
1198 | | /* Get the entry to the linked list of custom datatypes. This includes both the |
1199 | | * datatypes from serverConfig->customDataTypes and the internal custom data |
1200 | | * types from UA_Server_addDataType. |
1201 | | * |
1202 | | * Attention! The output pointer is only valid until the next call to |
1203 | | * UA_Server_addDataType. */ |
1204 | | UA_EXPORT UA_THREADSAFE const UA_DataTypeArray * |
1205 | | UA_Server_getDataTypes(UA_Server *server); |
1206 | | |
1207 | | /** |
1208 | | * ViewNode |
1209 | | * ~~~~~~~~ */ |
1210 | | |
1211 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1212 | | UA_Server_addViewNode(UA_Server *server, const UA_NodeId requestedNewNodeId, |
1213 | | const UA_NodeId parentNodeId, |
1214 | | const UA_NodeId referenceTypeId, |
1215 | | const UA_QualifiedName browseName, |
1216 | | const UA_ViewAttributes attr, |
1217 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1218 | | |
1219 | | /** |
1220 | | * .. _node-lifecycle: |
1221 | | * |
1222 | | * Node Lifecycle: Constructors, Destructors and Node Contexts |
1223 | | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1224 | | * To finalize the instantiation of a node, a (user-defined) constructor |
1225 | | * callback is executed. There can be both a global constructor for all nodes |
1226 | | * and node-type constructor specific to the TypeDefinition of the new node |
1227 | | * (attached to an ObjectTypeNode or VariableTypeNode). |
1228 | | * |
1229 | | * In the hierarchy of ObjectTypes and VariableTypes, only the constructor of |
1230 | | * the (lowest) type defined for the new node is executed. Note that every |
1231 | | * Object and Variable can have only one ``isTypeOf`` reference. But type-nodes |
1232 | | * can technically have several ``hasSubType`` references to implement multiple |
1233 | | * inheritance. Issues of (multiple) inheritance in the constructor need to be |
1234 | | * solved by the user. |
1235 | | * |
1236 | | * When a node is destroyed, the node-type destructor is called before the |
1237 | | * global destructor. So the overall node lifecycle is as follows: |
1238 | | * |
1239 | | * 1. Global Early Constructor (set in the server config) |
1240 | | * 2. Node-Type Early Constructor (for Variables or Objects) |
1241 | | * 3. Recursive instantiation of the node's children |
1242 | | * 4. Global Constructor (set in the server config) |
1243 | | * 5. Node-Type Constructor (for Variables or Objects) |
1244 | | * 6. (Usage-period of the Node) |
1245 | | * 7. Node-Type Destructor |
1246 | | * 8. Global Destructor |
1247 | | * |
1248 | | * The constructor and destructor callbacks can be set to ``NULL`` and are not |
1249 | | * used in that case. If a constructor fails, the global destructor will be |
1250 | | * called before removing the node. The destructors are assumed to never fail. |
1251 | | * |
1252 | | * Every node carries a user-context and a constructor-context pointer. The |
1253 | | * user-context is used to attach custom data to a node. But the (user-defined) |
1254 | | * constructors and destructors may replace the user-context pointer if they |
1255 | | * wish to do so. The initial value for the constructor-context is ``NULL``. |
1256 | | * When the ``AddNodes`` service is used over the network, the user-context |
1257 | | * pointer of the new node is also initially set to ``NULL``. */ |
1258 | | |
1259 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1260 | | UA_Server_getNodeContext(UA_Server *server, UA_NodeId nodeId, void **nodeContext); |
1261 | | |
1262 | | /* Careful! The user has to ensure that the destructor callbacks still work. */ |
1263 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1264 | | UA_Server_setNodeContext(UA_Server *server, UA_NodeId nodeId, void *nodeContext); |
1265 | | |
1266 | | /** |
1267 | | * Global constructor and destructor callbacks used for every node. |
1268 | | * It gets set in the server config. */ |
1269 | | |
1270 | | typedef struct { |
1271 | | /* Can be NULL. May replace the nodeContext */ |
1272 | | UA_StatusCode (*constructor)(UA_Server *server, |
1273 | | const UA_NodeId *sessionId, void *sessionContext, |
1274 | | const UA_NodeId *nodeId, void **nodeContext); |
1275 | | |
1276 | | /* Can be NULL. The context cannot be replaced since the node is destroyed |
1277 | | * immediately afterwards anyway. */ |
1278 | | void (*destructor)(UA_Server *server, |
1279 | | const UA_NodeId *sessionId, void *sessionContext, |
1280 | | const UA_NodeId *nodeId, void *nodeContext); |
1281 | | |
1282 | | /* Can be NULL. Called during recursive node instantiation. While mandatory |
1283 | | * child nodes are automatically created if not already present, optional child |
1284 | | * nodes are not. This callback can be used to define whether an optional child |
1285 | | * node should be created. |
1286 | | * |
1287 | | * @param server The server executing the callback |
1288 | | * @param sessionId The identifier of the session |
1289 | | * @param sessionContext Additional data attached to the session in the |
1290 | | * access control layer |
1291 | | * @param sourceNodeId Source node from the type definition. If the new node |
1292 | | * shall be created, it will be a copy of this node. |
1293 | | * @param targetParentNodeId Parent of the potential new child node |
1294 | | * @param referenceTypeId Identifies the reference type which that the parent |
1295 | | * node has to the new node. |
1296 | | * @return Return UA_TRUE if the child node shall be instantiated, |
1297 | | * UA_FALSE otherwise. */ |
1298 | | UA_Boolean (*createOptionalChild)(UA_Server *server, |
1299 | | const UA_NodeId *sessionId, |
1300 | | void *sessionContext, |
1301 | | const UA_NodeId *sourceNodeId, |
1302 | | const UA_NodeId *targetParentNodeId, |
1303 | | const UA_NodeId *referenceTypeId); |
1304 | | |
1305 | | /* Can be NULL. Called when a node is to be copied during recursive |
1306 | | * node instantiation. Allows definition of the NodeId for the new node. |
1307 | | * If the callback is set to NULL or the resulting NodeId is UA_NODEID_NUMERIC(X,0) |
1308 | | * an unused nodeid in namespace X will be used. E.g. passing UA_NODEID_NULL will |
1309 | | * result in a NodeId in namespace 0. |
1310 | | * |
1311 | | * @param server The server executing the callback |
1312 | | * @param sessionId The identifier of the session |
1313 | | * @param sessionContext Additional data attached to the session in the |
1314 | | * access control layer |
1315 | | * @param sourceNodeId Source node of the copy operation |
1316 | | * @param targetParentNodeId Parent node of the new node |
1317 | | * @param referenceTypeId Identifies the reference type which that the parent |
1318 | | * node has to the new node. */ |
1319 | | UA_StatusCode (*generateChildNodeId)(UA_Server *server, |
1320 | | const UA_NodeId *sessionId, void *sessionContext, |
1321 | | const UA_NodeId *sourceNodeId, |
1322 | | const UA_NodeId *targetParentNodeId, |
1323 | | const UA_NodeId *referenceTypeId, |
1324 | | UA_NodeId *targetNodeId); |
1325 | | |
1326 | | /* Can be NULL. Called after the node has been inserted into the Nodestore |
1327 | | * and its parent and TypeDefinition references have been added, but before |
1328 | | * automatic child instantiation. This allows the callback to add children |
1329 | | * that shall take the place of children declared by the TypeDefinition. |
1330 | | * May replace the nodeContext. */ |
1331 | | UA_StatusCode (*earlyConstructor)(UA_Server *server, |
1332 | | const UA_NodeId *sessionId, |
1333 | | void *sessionContext, |
1334 | | const UA_NodeId *nodeId, |
1335 | | void **nodeContext); |
1336 | | } UA_GlobalNodeLifecycle; |
1337 | | |
1338 | | /** |
1339 | | * The following node-type lifecycle can be set for VariableTypeNodes and |
1340 | | * ObjectTypeNodes. It gets called for instances of this node-type. */ |
1341 | | |
1342 | | typedef struct { |
1343 | | /* Can be NULL. May replace the nodeContext */ |
1344 | | UA_StatusCode (*constructor)(UA_Server *server, |
1345 | | const UA_NodeId *sessionId, void *sessionContext, |
1346 | | const UA_NodeId *typeNodeId, void *typeNodeContext, |
1347 | | const UA_NodeId *nodeId, void **nodeContext); |
1348 | | |
1349 | | /* Can be NULL. May replace the nodeContext. */ |
1350 | | void (*destructor)(UA_Server *server, |
1351 | | const UA_NodeId *sessionId, void *sessionContext, |
1352 | | const UA_NodeId *typeNodeId, void *typeNodeContext, |
1353 | | const UA_NodeId *nodeId, void **nodeContext); |
1354 | | |
1355 | | /* Can be NULL. Called after the global earlyConstructor and before |
1356 | | * automatic child instantiation. May replace the nodeContext. */ |
1357 | | UA_StatusCode (*earlyConstructor)(UA_Server *server, |
1358 | | const UA_NodeId *sessionId, |
1359 | | void *sessionContext, |
1360 | | const UA_NodeId *typeNodeId, |
1361 | | void *typeNodeContext, |
1362 | | const UA_NodeId *nodeId, |
1363 | | void **nodeContext); |
1364 | | } UA_NodeTypeLifecycle; |
1365 | | |
1366 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1367 | | UA_Server_setNodeTypeLifecycle(UA_Server *server, UA_NodeId nodeId, |
1368 | | UA_NodeTypeLifecycle lifecycle); |
1369 | | |
1370 | | /** |
1371 | | * Detailed Node Construction |
1372 | | * ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1373 | | * The method pair UA_Server_addNode_begin and _finish splits the AddNodes |
1374 | | * service in two parts. This is useful if the node shall be modified before |
1375 | | * finish the instantiation. For example to add children with specific NodeIds. |
1376 | | * Otherwise, mandatory children (e.g. of an ObjectType) are added with |
1377 | | * pseudo-random unique NodeIds. Existing children are detected during the |
1378 | | * _finish part via their matching BrowseName. |
1379 | | * |
1380 | | * The _begin method: |
1381 | | * - prepares the node and adds it to the nodestore |
1382 | | * - copies some unassigned attributes from the TypeDefinition node internally |
1383 | | * - adds the references to the parent (and the TypeDefinition if applicable) |
1384 | | * - performs type-checking of variables |
1385 | | * - calls the global and node-type earlyConstructors, if configured. |
1386 | | * |
1387 | | * You can add an object node without a parent if you set the parentNodeId and |
1388 | | * referenceTypeId to UA_NODE_ID_NULL. Then you need to add the parent reference |
1389 | | * and hasTypeDef reference yourself before calling the _finish method. |
1390 | | * Not that this is only allowed for object nodes. |
1391 | | * |
1392 | | * The _finish method: |
1393 | | * - copies mandatory children |
1394 | | * - calls the node constructor(s) at the end |
1395 | | * - may remove the node if it encounters an error. |
1396 | | * |
1397 | | * The special UA_Server_addMethodNode_finish method needs to be used for method |
1398 | | * nodes, since there you need to explicitly specifiy the input and output |
1399 | | * arguments which are added in the finish step (if not yet already there) */ |
1400 | | |
1401 | | /* The ``attr`` argument must have a type according to the NodeClass. |
1402 | | * ``VariableAttributes`` for variables, ``ObjectAttributes`` for objects, and |
1403 | | * so on. Missing attributes are taken from the TypeDefinition node if |
1404 | | * applicable. */ |
1405 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1406 | | UA_Server_addNode_begin(UA_Server *server, const UA_NodeClass nodeClass, |
1407 | | const UA_NodeId requestedNewNodeId, |
1408 | | const UA_NodeId parentNodeId, |
1409 | | const UA_NodeId referenceTypeId, |
1410 | | const UA_QualifiedName browseName, |
1411 | | const UA_NodeId typeDefinition, |
1412 | | const void *attr, const UA_DataType *attributeType, |
1413 | | void *nodeContext, UA_NodeId *outNewNodeId); |
1414 | | |
1415 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1416 | | UA_Server_addNode_finish(UA_Server *server, const UA_NodeId nodeId); |
1417 | | |
1418 | | #ifdef UA_ENABLE_METHODCALLS |
1419 | | |
1420 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1421 | | UA_Server_addMethodNode_finish(UA_Server *server, const UA_NodeId nodeId, |
1422 | | UA_MethodCallback method, |
1423 | | size_t inputArgumentsSize, const UA_Argument *inputArguments, |
1424 | | size_t outputArgumentsSize, const UA_Argument *outputArguments); |
1425 | | |
1426 | | #endif |
1427 | | |
1428 | | /* Deletes a node and optionally all references leading to the node. */ |
1429 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1430 | | UA_Server_deleteNode(UA_Server *server, const UA_NodeId nodeId, |
1431 | | UA_Boolean deleteReferences); |
1432 | | |
1433 | | /** |
1434 | | * Reference Management |
1435 | | * ~~~~~~~~~~~~~~~~~~~~ */ |
1436 | | |
1437 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1438 | | UA_Server_addReference(UA_Server *server, const UA_NodeId sourceId, |
1439 | | const UA_NodeId refTypeId, |
1440 | | const UA_ExpandedNodeId targetId, UA_Boolean isForward); |
1441 | | |
1442 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1443 | | UA_Server_deleteReference(UA_Server *server, const UA_NodeId sourceNodeId, |
1444 | | const UA_NodeId referenceTypeId, UA_Boolean isForward, |
1445 | | const UA_ExpandedNodeId targetNodeId, |
1446 | | UA_Boolean deleteBidirectional); |
1447 | | |
1448 | | /** |
1449 | | * .. _async-operations: |
1450 | | * |
1451 | | * Async Operations |
1452 | | * ---------------- |
1453 | | * Some operations can take time, such as reading a sensor that needs to warm up |
1454 | | * first. In order not to block the server, a long-running operation can be |
1455 | | * handled asynchronously and the result returned at a later time. The core idea |
1456 | | * is that a userland callback can return |
1457 | | * UA_STATUSCODE_GOODCOMPLETESASYNCHRONOUSLY as the statuscode to signal that it |
1458 | | * wishes to complete the operation later. |
1459 | | * |
1460 | | * Currently, async operations are supported for the services |
1461 | | * |
1462 | | * - Read |
1463 | | * - Write |
1464 | | * - Call |
1465 | | * |
1466 | | * with the caveat that read/write need a CallbackValueSource registered for the |
1467 | | * variable. Values that are stored directly in a VariableNode are written and |
1468 | | * read immediately. |
1469 | | * |
1470 | | * Note that an async operation can be cancelled (e.g. after a timeout period or |
1471 | | * if the caller cannot wait for the result). This is signaled in the configured |
1472 | | * ``asyncOperationCancelCallback``. The provided memory locations to store the |
1473 | | * operation output are then no longer valid. */ |
1474 | | |
1475 | | /* When the UA_MethodCallback returns UA_STATUSCODE_GOODCOMPLETESASYNCHRONOUSLY, |
1476 | | * then an async operation is created in the server for later completion. The |
1477 | | * output pointer from the method callback is used to identify the async |
1478 | | * operation. Do not access the output pointer after the operation has been |
1479 | | * cancelled or after setting the result. */ |
1480 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1481 | | UA_Server_setAsyncCallMethodResult(UA_Server *server, UA_Variant *output, |
1482 | | UA_StatusCode result); |
1483 | | |
1484 | | /* See the UA_CallbackValueSource documentation */ |
1485 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1486 | | UA_Server_setAsyncReadResult(UA_Server *server, UA_DataValue *result); |
1487 | | |
1488 | | /* See the UA_CallbackValueSource documentation. The value needs to be the |
1489 | | * pointer used in the write callback. The statuscode is the result signal to be |
1490 | | * returned asynchronously. */ |
1491 | | UA_EXPORT UA_THREADSAFE UA_StatusCode |
1492 | | UA_Server_setAsyncWriteResult(UA_Server *server, const UA_DataValue *value, |
1493 | | UA_StatusCode result); |
1494 | | |
1495 | | /** |
1496 | | * The server supports asynchronous "local" read/write/call operations. The user |
1497 | | * supplies a result-callback that gets called either synchronously (if the |
1498 | | * operation terminates right away) or asynchronously at a later time. The |
1499 | | * result-callback is called exactly one time for each operation, also if the |
1500 | | * operation is cancelled. In this case a StatusCode like |
1501 | | * ``UA_STATUSCODE_BADTIMEOUT`` or ``UA_STATUSCODE_BADSHUTDOWN`` is set. |
1502 | | * |
1503 | | * If an operation returns asynchronously, then the result-callback is executed |
1504 | | * only in the next iteration of the Eventloop. An exception to this is |
1505 | | * UA_Server_cancelAsync, which can optionally call the result-callback right |
1506 | | * away (e.g. as part of a cleanup where the context of the result-callback gets |
1507 | | * removed). |
1508 | | * |
1509 | | * Async operations incur a small overhead since memory is allocated to persist |
1510 | | * the operation over time. |
1511 | | * |
1512 | | * The operation timeout is defined in milliseconds. A timeout of zero means |
1513 | | * infinite. */ |
1514 | | |
1515 | | typedef void(*UA_ServerAsyncReadResultCallback) |
1516 | | (UA_Server *server, void *asyncOpContext, const UA_DataValue *result); |
1517 | | typedef void(*UA_ServerAsyncWriteResultCallback) |
1518 | | (UA_Server *server, void *asyncOpContext, UA_StatusCode result); |
1519 | | typedef void(*UA_ServerAsyncMethodResultCallback) |
1520 | | (UA_Server *server, void *asyncOpContext, const UA_CallMethodResult *result); |
1521 | | |
1522 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1523 | | UA_Server_read_async(UA_Server *server, const UA_ReadValueId *operation, |
1524 | | UA_TimestampsToReturn timestamps, |
1525 | | UA_ServerAsyncReadResultCallback callback, |
1526 | | void *asyncOpContext, UA_UInt32 timeout); |
1527 | | |
1528 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1529 | | UA_Server_write_async(UA_Server *server, const UA_WriteValue *operation, |
1530 | | UA_ServerAsyncWriteResultCallback callback, |
1531 | | void *asyncOpContext, UA_UInt32 timeout); |
1532 | | |
1533 | | #ifdef UA_ENABLE_METHODCALLS |
1534 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1535 | | UA_Server_call_async(UA_Server *server, const UA_CallMethodRequest *operation, |
1536 | | UA_ServerAsyncMethodResultCallback callback, |
1537 | | void *asyncOpContext, UA_UInt32 timeout); |
1538 | | #endif |
1539 | | |
1540 | | /** |
1541 | | * Local async operations can be manually cancelled (besides an internal cancel |
1542 | | * due to a timeout or server shutdown). The local async operations to be |
1543 | | * cancelled are selected by matching their asyncOpContext pointer. This can |
1544 | | * cancel multiple operations that use the same context pointer. |
1545 | | * |
1546 | | * For operations where the async result was not yet set, the |
1547 | | * asyncOperationCancelCallback from the server-config gets called and the |
1548 | | * cancel-status is set in the operation result. |
1549 | | * |
1550 | | * For async operations where the result has already been set, but not yet |
1551 | | * notified with the result-callback (to be done in the next EventLoop |
1552 | | * iteration), the asyncOperationCancelCallback is not called and no cancel |
1553 | | * status is set in the result. |
1554 | | * |
1555 | | * Each operation's result-callback gets called exactly once. When the operation |
1556 | | * is cancelled, the result-callback can be called synchronously using the |
1557 | | * synchronousResultCallback flag. Otherwise the result gets returned "normally" |
1558 | | * in the next EventLoop iteration. The synchronous option ensures that all |
1559 | | * (matching) async operations are fully cancelled right away. This can be |
1560 | | * important in a cleanup situation where the asyncOpContext is no longer valid |
1561 | | * in the future. */ |
1562 | | |
1563 | | void UA_EXPORT UA_THREADSAFE |
1564 | | UA_Server_cancelAsync(UA_Server *server, void *asyncOpContext, |
1565 | | UA_StatusCode status, |
1566 | | UA_Boolean synchronousResultCallback); |
1567 | | |
1568 | | /** |
1569 | | * .. _events: |
1570 | | * |
1571 | | * Events |
1572 | | * ------ |
1573 | | * Events are emitted by objects in the OPC UA information model. Starting at |
1574 | | * the source-node, the events "bubble up" in the hierarchy of objects and are |
1575 | | * caught by MonitoredItems listening for them. |
1576 | | * |
1577 | | * EventTypes are special ObjectTypeNodes that describe the (data) fields of an |
1578 | | * event instance. An EventType can simply contain a flat list of VariableNodes. |
1579 | | * But (deep) nesting of objects and variables is also allowed. The individual |
1580 | | * MonitoredItems then contain an EventFilter (with a select-clause) that |
1581 | | * defines the event fields to be transmitted to a particular client. |
1582 | | * |
1583 | | * In open62541, there are three possible sources for the event fields. When the |
1584 | | * select-clause of an EventFilter is resolved, the sources are evaluated in the |
1585 | | * following order: |
1586 | | * |
1587 | | * 1. An key-value map that defines event fields. The key of its entries is a |
1588 | | * "path-string", a :ref:``human-readable encoding of a |
1589 | | * SimpleAttributeOperand<parse-sao>`. For example ``/SourceNode`` or |
1590 | | * ``/EventType``. |
1591 | | * 2. A NodeId pointing to an ObjectNode that instantiates an EventType. The |
1592 | | * ``SimpleAttributeOperands`` from the EventFilter are resolved in its |
1593 | | * context. |
1594 | | * 3. The event fields defined as mandatory for the *BaseEventType* have a |
1595 | | * default that gets used if they are not defined otherwise: |
1596 | | * |
1597 | | * /EventId |
1598 | | * ByteString to uniquely identify the event instance |
1599 | | * (default: random 16-byte ByteString) |
1600 | | * |
1601 | | * /EventType |
1602 | | * NodeId of the EventType (default: argument of ``_createEvent``) |
1603 | | * |
1604 | | * /SourceNode |
1605 | | * NodeId of the emitting node (default: argument of ``_createEvent``) |
1606 | | * |
1607 | | * /SourceName |
1608 | | * LocalizedText with the DisplayName of the source node |
1609 | | * (default: read from the information model) |
1610 | | * |
1611 | | * /Time |
1612 | | * DateTime with the timestamp when the event occurred |
1613 | | * (default: current time) |
1614 | | * |
1615 | | * /ReceiveTime |
1616 | | * DateTime when the server received the information about the event from an |
1617 | | * underlying device (default: current time) |
1618 | | * |
1619 | | * /Message |
1620 | | * LocalizedText with a human-readable description of the event (default: |
1621 | | * argument of ``_createEvent``) |
1622 | | * |
1623 | | * /Severity |
1624 | | * UInt16 for the urgency of the event defined to be between 1 (lowest) and |
1625 | | * 1000 (catastrophic) (default: argument of ``_createEvent``) |
1626 | | * |
1627 | | * The "path-string" (SimpleAttributeOperand expression) can use |
1628 | | * namespace-indices and point into nested objects and variables. For example |
1629 | | * ``/1:Truck/2:Wheel``. |
1630 | | * |
1631 | | * The key-value map source for the event-fields uses a QualifiedName for the |
1632 | | * key. The NamespaceIndex from the key is used as the default NamespaceIndex |
1633 | | * for the path elements that do not define it explicitly. So the key |
1634 | | * ``2:"/1:Truck/Wheel"`` becomes ``/1:Truck/2:Wheel``. |
1635 | | * |
1636 | | * An event field that is missing from all sources resolves to an empty variant. |
1637 | | * |
1638 | | * It is typically faster to define event-fields in the key-value map than to |
1639 | | * look them up from an event instance in the information model. This is |
1640 | | * particularly important for events emitted at a high frequency. */ |
1641 | | |
1642 | | #ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS |
1643 | | |
1644 | | /* Create an event in the server. The eventFields and eventInstance pointer can |
1645 | | * be NULL and are then not considered as a source of event fields. The |
1646 | | * outEventId pointer can be NULL. If set, the EventId of a successfully created |
1647 | | * Event gets copied into the argument. */ |
1648 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1649 | | UA_Server_createEvent(UA_Server *server, const UA_NodeId sourceNode, |
1650 | | const UA_NodeId eventType, UA_UInt16 severity, |
1651 | | const UA_LocalizedText message, |
1652 | | const UA_KeyValueMap *eventFields, |
1653 | | const UA_NodeId *eventInstance, |
1654 | | UA_ByteString *outEventId); |
1655 | | |
1656 | | /* Extended version of the _createEvent API. The members of the |
1657 | | * UA_EventDescription structure have the same meaning as above. |
1658 | | * |
1659 | | * In addition, the extended version allows the filtering of Events to be only |
1660 | | * transmitted to a particular Session/Subscription/MonitoredItem. The filtering |
1661 | | * criteria can be NULL. But the subscriptionId requires a sessionId and the |
1662 | | * monitoredItemId requires a subscriptionId as context. */ |
1663 | | |
1664 | | typedef struct { |
1665 | | /* Event fields */ |
1666 | | UA_NodeId sourceNode; |
1667 | | UA_NodeId eventType; |
1668 | | UA_UInt16 severity; |
1669 | | UA_LocalizedText message; |
1670 | | const UA_KeyValueMap *eventFields; |
1671 | | const UA_NodeId *eventInstance; |
1672 | | |
1673 | | /* Restrict who can receive the event */ |
1674 | | const UA_NodeId *sessionId; |
1675 | | const UA_UInt32 *subscriptionId; |
1676 | | const UA_UInt32 *monitoredItemId; |
1677 | | } UA_EventDescription; |
1678 | | |
1679 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1680 | | UA_Server_createEventEx(UA_Server *server, |
1681 | | const UA_EventDescription *ed, |
1682 | | UA_ByteString *outEventId); |
1683 | | |
1684 | | #endif /* UA_ENABLE_SUBSCRIPTIONS_EVENTS */ |
1685 | | |
1686 | | /** |
1687 | | * .. _model-semantic-changes: |
1688 | | * |
1689 | | * Model and Semantic Changes |
1690 | | * ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1691 | | * With ``UA_ENABLE_SUBSCRIPTIONS_EVENTS``, the server automatically emits the |
1692 | | * standard ``GeneralModelChangeEventType`` and ``SemanticChangeEventType`` for |
1693 | | * changes made through OPC UA Services and the corresponding local |
1694 | | * ``UA_Server_*`` APIs. Changes made while the server's namespace is initially |
1695 | | * populated are suppressed. Both EventTypes are emitted by the Server object. |
1696 | | * |
1697 | | * A structural change is reported only if the affected Node has a |
1698 | | * scalar ``NodeVersion`` Property with the String DataType. The server updates |
1699 | | * that Property with the decimal representation of a server-wide, increasing |
1700 | | * Int64. Nodes without a suitable ``NodeVersion`` Property are not |
1701 | | * included in a ModelChangeEvent. The following successful operations are |
1702 | | * reported: |
1703 | | * |
1704 | | * .. list-table:: |
1705 | | * :header-rows: 1 |
1706 | | * |
1707 | | * * - Operation |
1708 | | * - ModelChange verb |
1709 | | * * - Add a Node |
1710 | | * - ``NodeAdded`` |
1711 | | * * - Delete a Node |
1712 | | * - ``NodeDeleted`` |
1713 | | * * - Add a Reference |
1714 | | * - ``ReferenceAdded`` |
1715 | | * * - Delete a Reference |
1716 | | * - ``ReferenceDeleted`` |
1717 | | * * - Change the DataType Attribute |
1718 | | * - ``DataTypeChanged`` |
1719 | | * |
1720 | | * Changes to ValueRank and ArrayDimensions are not structural ModelChanges. |
1721 | | * |
1722 | | * A SemanticChange is reported when a successful Value write changes a |
1723 | | * Variable whose AccessLevel contains ``UA_ACCESSLEVELMASK_SEMANTICCHANGE``. |
1724 | | * The Variable must be a Property connected to its owner by ``HasProperty`` or |
1725 | | * a subtype. The owner is reported as the affected Node. Same-value writes are |
1726 | | * suppressed when the previous value is directly available. For callback-based |
1727 | | * value sources the previous value may not be available for comparison, so a |
1728 | | * successful write is treated as a SemanticChange. |
1729 | | * |
1730 | | * A SemanticChange also marks Value MonitoredItems on the affected Variable. |
1731 | | * Their next DataChange notification contains the ``SemanticsChanged`` |
1732 | | * StatusCode bit. MonitoredItems with a zero SamplingInterval are sampled |
1733 | | * immediately. For cyclic sampling the bit remains pending until the next |
1734 | | * notification. |
1735 | | * |
1736 | | * Changes are accumulated until the outermost local operation or decoded |
1737 | | * Service request completes. Entries for the same affected Node are coalesced |
1738 | | * by combining their ModelChange verbs. Model and Semantic changes collected |
1739 | | * together are emitted as separate standard Events. Failed operations are not |
1740 | | * reported. |
1741 | | * |
1742 | | * See ``examples/events/server_modelchange.c`` for a complete local example. */ |
1743 | | |
1744 | | #ifdef UA_ENABLE_DISCOVERY |
1745 | | |
1746 | | /** |
1747 | | * Remote Discovery Server Registration |
1748 | | * ------------------------------------ |
1749 | | * The current server can register itself at a discovery. For that it requires |
1750 | | * to open a client connection. */ |
1751 | | |
1752 | | /* Register the given server instance at a discovery server. This should be |
1753 | | * called periodically, for example every 10 minutes, depending on the |
1754 | | * configuration of the discovery server. |
1755 | | * |
1756 | | * The supplied client configuration is used to create a new client to connect |
1757 | | * to the discovery server. The client configuration is moved over to the server |
1758 | | * and eventually cleaned up internally. The structure pointed at by `cc` is |
1759 | | * zeroed to avoid accessing outdated information. |
1760 | | * |
1761 | | * The eventloop and logging plugins in the client configuration are replaced by |
1762 | | * those configured in the server. */ |
1763 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1764 | | UA_Server_registerDiscovery(UA_Server *server, UA_ClientConfig *cc, |
1765 | | const UA_String discoveryServerUrl, |
1766 | | const UA_String semaphoreFilePath); |
1767 | | |
1768 | | /* Deregister the given server instance from the discovery server. |
1769 | | * This should be called when the server is shutting down. */ |
1770 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1771 | | UA_Server_deregisterDiscovery(UA_Server *server, UA_ClientConfig *cc, |
1772 | | const UA_String discoveryServerUrl); |
1773 | | |
1774 | | /** |
1775 | | * Local Discovery Server Records |
1776 | | * ------------------------------ |
1777 | | * The Discovery Service-Set allows the registering of local (for FindServers) |
1778 | | * and also remote servers (for FindServersOnNetwork). |
1779 | | * |
1780 | | * We uniquely identify records by their combination of ServerUri + one matching |
1781 | | * DiscoveryUrl. */ |
1782 | | |
1783 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1784 | | UA_Server_findServers(UA_Server *server, UA_String endpointUrl, |
1785 | | size_t localeIdsSize, UA_LocaleId *localeIds, |
1786 | | size_t serverUrisSize, UA_String *serverUris, |
1787 | | size_t *outServersSize, |
1788 | | UA_ApplicationDescription **outServers); |
1789 | | |
1790 | | /* Local API for the RegisterServer2 service. If configurationResults is |
1791 | | * non-Null, then it must point to an array of discoveryConfigurationSize |
1792 | | * length. */ |
1793 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1794 | | UA_Server_registerServer(UA_Server *server, |
1795 | | const UA_RegisteredServer *registeredServer, |
1796 | | const size_t discoveryConfigurationSize, |
1797 | | const UA_ExtensionObject *discoveryConfiguration, |
1798 | | UA_StatusCode *configurationResults); |
1799 | | |
1800 | | /* Remove the servers matching the ServerUri and at least one of the |
1801 | | * provided DiscoveryUrls */ |
1802 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1803 | | UA_Server_deregisterServer(UA_Server *server, const UA_String serverUri, |
1804 | | size_t discoveryUrlsSize, |
1805 | | const UA_String *discoveryUrls); |
1806 | | |
1807 | | /** |
1808 | | * The server internally manages the ServersOnNetwork list. Multicast discovery |
1809 | | * is implemented on top in a driver outside of the core library. */ |
1810 | | |
1811 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1812 | | UA_Server_findServersOnNetwork(UA_Server *server, UA_String endpointUrl, |
1813 | | UA_UInt32 startingRecordId, |
1814 | | UA_UInt32 maxRecordsToReturn, |
1815 | | size_t serverCapabilityFilterSize, |
1816 | | const UA_String *serverCapabilityFilter, |
1817 | | UA_DateTime *outLastCounterResetTime, |
1818 | | size_t *outServersSize, |
1819 | | UA_ServerOnNetwork **outServers); |
1820 | | |
1821 | | /* Register a remote server. If the server name was previously known, the |
1822 | | * existing entry gets updated. The parameter kv-map can be extended with |
1823 | | * additional parameters in the future. Currently supported are: |
1824 | | * |
1825 | | * 0:remote-address [String] |
1826 | | * IP-address or other host identifier from which the information |
1827 | | * was received. |
1828 | | * 0:ttl [UInt32] |
1829 | | * Time-to-live of DNS information. Zero means infinite. */ |
1830 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1831 | | UA_Server_registerServerOnNetwork(UA_Server *server, |
1832 | | const UA_ServerOnNetwork *son, |
1833 | | const UA_KeyValueMap params); |
1834 | | |
1835 | | /* Remove the entry of the remote server with the matching ServerName */ |
1836 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
1837 | | UA_Server_deregisterServerOnNetwork(UA_Server *server, |
1838 | | UA_String serverName); |
1839 | | |
1840 | | #endif /* UA_ENABLE_DISCOVERY */ |
1841 | | |
1842 | | /** |
1843 | | * .. _drivers: |
1844 | | * |
1845 | | * Drivers |
1846 | | * ------- |
1847 | | * Drivers are different from other "plugins" in that they have an explicit |
1848 | | * stateful lifecycle and can be started/stopped at runtime. Their lifecycle is |
1849 | | * however dependent on the server into which the drivers are embedded. When the |
1850 | | * server shuts down, the drivers are also stopped. |
1851 | | * |
1852 | | * Drivers can use the server's public API to the full extent. For example |
1853 | | * add/remove nodes, or register connections and timers in the server's |
1854 | | * EventLoop. |
1855 | | * |
1856 | | * Some drivers define core functionality and are added internally in the server |
1857 | | * implementation. */ |
1858 | | |
1859 | | typedef enum { |
1860 | | UA_DRIVERTYPE_GENERIC = 0, |
1861 | | UA_DRIVERTYPE_GDS_RECEIVER |
1862 | | } UA_DriverType; |
1863 | | |
1864 | | struct UA_Driver; |
1865 | | typedef struct UA_Driver UA_Driver; |
1866 | | |
1867 | | /* Callback through which the server notifies the driver |
1868 | | * about runtime changes and internal events. */ |
1869 | | typedef void |
1870 | | (*UA_DriverNotificationCallback)(UA_Driver *drv, |
1871 | | UA_ApplicationNotificationType type, |
1872 | | const UA_KeyValueMap payload); |
1873 | | |
1874 | | struct UA_Driver { |
1875 | | UA_Driver *next; /* linked-list */ |
1876 | | |
1877 | | /* |
1878 | | * Configuration |
1879 | | */ |
1880 | | |
1881 | | UA_DriverType driverType; |
1882 | | UA_String name; |
1883 | | |
1884 | | /* See the driver-specific documentation for possible parameters. |
1885 | | * The params need to be cleaned up within the _free method. */ |
1886 | | UA_KeyValueMap params; |
1887 | | |
1888 | | /* Backpointer to the server. Must be set before _start is called. If NULL |
1889 | | * this is set by the server during registering. Generally the server must |
1890 | | * not be switched out once the driver has been started. */ |
1891 | | UA_Server *server; |
1892 | | |
1893 | | /* The server forwards its internal notifications to all drivers. In order |
1894 | | * to avoid overload, the filter must be set. The top 32bit are ANDed with |
1895 | | * the notification type to see if the driver is interested in the |
1896 | | * notification. See the common.h for details on the notification types and |
1897 | | * their payload. */ |
1898 | | UA_DriverNotificationCallback notificationCallback; |
1899 | | UA_ApplicationNotificationType notificationFilter; |
1900 | | |
1901 | | /* |
1902 | | * Lifecycle management |
1903 | | */ |
1904 | | |
1905 | | UA_LifecycleState state; |
1906 | | |
1907 | | /* Start the Driver. It will typically register timers/connections in the |
1908 | | * EventLoop and may add nodes in the server's information model. Starting |
1909 | | * can fail if the server is not already started also. |
1910 | | * |
1911 | | * During startup, the server calls start on all registered drivers. */ |
1912 | | UA_StatusCode (*start)(UA_Driver *sc); |
1913 | | |
1914 | | /* Stopping is asynchronous and might need a few iterations of the eventloop |
1915 | | * to succeed. All Drivers are stopped during the shutdown of the server. |
1916 | | * Once fully stopped, the Driver must no longer rely on the server |
1917 | | * backpointer. So it can be detached and _free'd at runtime of the |
1918 | | * server. */ |
1919 | | void (*stop)(UA_Driver *sc); |
1920 | | |
1921 | | /* Clean up and delete the Driver. Can fail if it is not fully stopped. When |
1922 | | * successfully removed, the Driver must no longer be accessed from the |
1923 | | * server. |
1924 | | * |
1925 | | * Drivers are all free'd when the server is deleted. If a Driver is |
1926 | | * manually removed before, then it needs to be unlinked from the server's |
1927 | | * internal linked-list before. */ |
1928 | | UA_StatusCode (*free)(UA_Driver *sc); |
1929 | | }; |
1930 | | |
1931 | | /* Adds the Driver to the server. Starts the driver if the server is already |
1932 | | * started. */ |
1933 | | UA_StatusCode |
1934 | | UA_Server_addDriver(UA_Server *server, UA_Driver *drv); |
1935 | | |
1936 | | /* Remove the Driver from the server. This will fail if the driver is not fully |
1937 | | * stopped. */ |
1938 | | UA_StatusCode |
1939 | | UA_Server_removeDriver(UA_Server *server, UA_Driver *drv); |
1940 | | |
1941 | | /* Get the first entry of the server's driver linked list. */ |
1942 | | UA_Driver * |
1943 | | UA_Server_getDrivers(UA_Server *server); |
1944 | | |
1945 | | /** |
1946 | | * Statistics |
1947 | | * ---------- |
1948 | | * Statistic counters keeping track of the current state of the stack. Counters |
1949 | | * are structured per OPC UA communication layer. */ |
1950 | | |
1951 | | typedef struct { |
1952 | | UA_SecureChannelStatistics scs; |
1953 | | UA_SessionStatistics ss; |
1954 | | } UA_ServerStatistics; |
1955 | | |
1956 | | UA_ServerStatistics UA_EXPORT UA_THREADSAFE |
1957 | | UA_Server_getStatistics(UA_Server *server); |
1958 | | |
1959 | | /** |
1960 | | * Reverse Connect |
1961 | | * --------------- |
1962 | | * The reverse connect feature of OPC UA permits the server instead of the |
1963 | | * client to establish the connection. The client must expose the listening port |
1964 | | * so the server is able to reach it. */ |
1965 | | |
1966 | | /* The reverse connect state change callback is called whenever the state of a |
1967 | | * reverse connect is changed by a connection attempt, a successful connection |
1968 | | * or a connection loss. |
1969 | | * |
1970 | | * The reverse connect states reflect the state of the secure channel currently |
1971 | | * associated with a reverse connect. The state will remain |
1972 | | * UA_SECURECHANNELSTATE_CONNECTING while the server attempts repeatedly to |
1973 | | * establish a connection. */ |
1974 | | typedef void (*UA_Server_ReverseConnectStateCallback)(UA_Server *server, |
1975 | | UA_UInt64 handle, |
1976 | | UA_SecureChannelState state, |
1977 | | void *context); |
1978 | | |
1979 | | /* Registers a reverse connect in the server. The server periodically attempts |
1980 | | * to establish a connection if the initial connect fails or if the connection |
1981 | | * breaks. |
1982 | | * |
1983 | | * @param server The server object |
1984 | | * @param url The URL of the remote client |
1985 | | * @param stateCallback The callback which will be called on state changes |
1986 | | * @param callbackContext The context for the state callback |
1987 | | * @param handle Is set to the handle of the reverse connect if not NULL |
1988 | | * @return Returns UA_STATUSCODE_GOOD if the reverse connect has been registered */ |
1989 | | UA_StatusCode UA_EXPORT |
1990 | | UA_Server_addReverseConnect(UA_Server *server, UA_String url, |
1991 | | UA_Server_ReverseConnectStateCallback stateCallback, |
1992 | | void *callbackContext, UA_UInt64 *handle); |
1993 | | |
1994 | | /* Removes a reverse connect from the server and closes the connection if it is |
1995 | | * currently open. |
1996 | | * |
1997 | | * @param server The server object |
1998 | | * @param handle The handle of the reverse connect to remove |
1999 | | * @return Returns UA_STATUSCODE_GOOD if the reverse connect has been |
2000 | | * successfully removed */ |
2001 | | UA_StatusCode UA_EXPORT |
2002 | | UA_Server_removeReverseConnect(UA_Server *server, UA_UInt64 handle); |
2003 | | |
2004 | | /** |
2005 | | * Utility Functions |
2006 | | * ----------------- */ |
2007 | | |
2008 | | /* Lookup a datatype by its NodeId. Takes the custom types in the server |
2009 | | * configuration into account. Return NULL if none found. */ |
2010 | | UA_EXPORT const UA_DataType * |
2011 | | UA_Server_findDataType(UA_Server *server, const UA_NodeId *typeId); |
2012 | | |
2013 | | /* Add a new namespace to the server. Returns the index of the new namespace */ |
2014 | | UA_UInt16 UA_EXPORT UA_THREADSAFE |
2015 | | UA_Server_addNamespace(UA_Server *server, const char* name); |
2016 | | |
2017 | | /* Get namespace by name from the server. */ |
2018 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2019 | | UA_Server_getNamespaceByName(UA_Server *server, const UA_String namespaceUri, |
2020 | | size_t* foundIndex); |
2021 | | |
2022 | | /* Get namespace by id from the server. */ |
2023 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2024 | | UA_Server_getNamespaceByIndex(UA_Server *server, const size_t namespaceIndex, |
2025 | | UA_String *foundUri); |
2026 | | |
2027 | | /** |
2028 | | * Some convenience functions are provided to simplify the interaction with |
2029 | | * objects. */ |
2030 | | |
2031 | | /* Write an object property. The property is represented as a VariableNode with |
2032 | | * a ``HasProperty`` reference from the ObjectNode. The VariableNode is |
2033 | | * identified by its BrowseName. Writing the property sets the value attribute |
2034 | | * of the VariableNode. |
2035 | | * |
2036 | | * @param server The server object |
2037 | | * @param objectId The identifier of the object (node) |
2038 | | * @param propertyName The name of the property |
2039 | | * @param value The value to be set for the event attribute |
2040 | | * @return The StatusCode for setting the event attribute */ |
2041 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2042 | | UA_Server_writeObjectProperty(UA_Server *server, const UA_NodeId objectId, |
2043 | | const UA_QualifiedName propertyName, |
2044 | | const UA_Variant value); |
2045 | | |
2046 | | /* Directly point to the scalar value instead of a variant */ |
2047 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2048 | | UA_Server_writeObjectProperty_scalar(UA_Server *server, const UA_NodeId objectId, |
2049 | | const UA_QualifiedName propertyName, |
2050 | | const void *value, const UA_DataType *type); |
2051 | | |
2052 | | /* Read an object property. |
2053 | | * |
2054 | | * @param server The server object |
2055 | | * @param objectId The identifier of the object (node) |
2056 | | * @param propertyName The name of the property |
2057 | | * @param value Contains the property value after reading. Must not be NULL. |
2058 | | * @return The StatusCode for setting the event attribute */ |
2059 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2060 | | UA_Server_readObjectProperty(UA_Server *server, const UA_NodeId objectId, |
2061 | | const UA_QualifiedName propertyName, |
2062 | | UA_Variant *value); |
2063 | | |
2064 | | /** |
2065 | | * Role-Based Access Control (RBAC) |
2066 | | * -------------------------------- |
2067 | | * |
2068 | | * Role-Based Access Control implementation per OPC UA Part 18 v1.05. |
2069 | | * |
2070 | | * **WARNING**: This feature is EXPERIMENTAL and NOT FOR PRODUCTION USE. |
2071 | | * The RBAC implementation is under active development and the API may change. |
2072 | | * Use only for testing and development purposes. |
2073 | | * |
2074 | | * RBAC allows fine-grained access control by assigning roles to sessions and |
2075 | | * defining permissions per role on individual nodes or entire namespaces. |
2076 | | * |
2077 | | * Type Definitions |
2078 | | * ~~~~~~~~~~~~~~~~ |
2079 | | */ |
2080 | | |
2081 | | #ifdef UA_ENABLE_RBAC |
2082 | | |
2083 | | /* UA_RolePermission |
2084 | | * Maps a single role to its permissions bitmask. Used in the server |
2085 | | * configuration to define presets and in the public API to set or query |
2086 | | * role permissions on nodes. */ |
2087 | | typedef struct { |
2088 | | UA_NodeId roleId; |
2089 | | UA_PermissionType permissions; |
2090 | | } UA_RolePermission; |
2091 | | |
2092 | | /* UA_RolePermissionSet |
2093 | | * A set of role-permission mappings. Used in the server configuration |
2094 | | * to define initial role-permission presets. */ |
2095 | | typedef struct { |
2096 | | size_t rolePermissionsSize; |
2097 | | UA_RolePermission *rolePermissions; |
2098 | | } UA_RolePermissionSet; |
2099 | | |
2100 | | /* UA_RolePermissionSet Type Management */ |
2101 | | void UA_EXPORT |
2102 | | UA_RolePermissionSet_init(UA_RolePermissionSet *rps); |
2103 | | |
2104 | | void UA_EXPORT |
2105 | | UA_RolePermissionSet_clear(UA_RolePermissionSet *rps); |
2106 | | |
2107 | | UA_StatusCode UA_EXPORT |
2108 | | UA_RolePermissionSet_copy(const UA_RolePermissionSet *src, |
2109 | | UA_RolePermissionSet *dst); |
2110 | | |
2111 | | /* UA_Role |
2112 | | * Represents an OPC UA role with identity mapping rules and optional |
2113 | | * application/endpoint restrictions per OPC UA Part 18 v1.05 §4.4. */ |
2114 | | typedef struct { |
2115 | | UA_NodeId roleId; |
2116 | | UA_QualifiedName roleName; /* BrowseName of the role */ |
2117 | | |
2118 | | /* Identity Mapping Rules - determine which sessions get this role */ |
2119 | | size_t identityMappingRulesSize; |
2120 | | UA_IdentityMappingRuleType *identityMappingRules; |
2121 | | |
2122 | | /* Application restrictions (empty list = ignore) */ |
2123 | | UA_Boolean applicationsExclude; |
2124 | | size_t applicationsSize; |
2125 | | UA_String *applications; |
2126 | | |
2127 | | /* Endpoint restrictions (empty list = ignore) */ |
2128 | | UA_Boolean endpointsExclude; |
2129 | | size_t endpointsSize; |
2130 | | UA_EndpointType *endpoints; |
2131 | | } UA_Role; |
2132 | | |
2133 | | /* UA_Role Type Management */ |
2134 | | void UA_EXPORT |
2135 | | UA_Role_init(UA_Role *role); |
2136 | | |
2137 | | void UA_EXPORT |
2138 | | UA_Role_clear(UA_Role *role); |
2139 | | |
2140 | | UA_StatusCode UA_EXPORT |
2141 | | UA_Role_copy(const UA_Role *src, UA_Role *dst); |
2142 | | |
2143 | | UA_Boolean UA_EXPORT |
2144 | | UA_Role_equal(const UA_Role *r1, const UA_Role *r2); |
2145 | | |
2146 | | #endif /* UA_ENABLE_RBAC */ |
2147 | | |
2148 | | /** |
2149 | | * .. _server-configuration: |
2150 | | * |
2151 | | * Server Configuration |
2152 | | * -------------------- |
2153 | | * The configuration structure is passed to the server during initialization. |
2154 | | * The server expects that the configuration is not modified during runtime. |
2155 | | * Currently, only one server can use a configuration at a time. During |
2156 | | * shutdown, the server will clean up the parts of the configuration that are |
2157 | | * modified at runtime through the provided API. |
2158 | | * |
2159 | | * Examples for configurations are provided in the ``/plugins`` folder. |
2160 | | * The usual usage is as follows: |
2161 | | * |
2162 | | * 1. Create a server configuration with default settings as a starting point |
2163 | | * 2. Modifiy the configuration, e.g. by adding a server certificate |
2164 | | * 3. Instantiate a server with it |
2165 | | * 4. After shutdown of the server, clean up the configuration (free memory) |
2166 | | * |
2167 | | * The :ref:`tutorials` provide a good starting point for this. */ |
2168 | | |
2169 | | /* Encryption mode requirement for OPC UA Binary over WebSockets */ |
2170 | | typedef enum { |
2171 | | UA_WEBSOCKET_ENCRYPTION_OPTIONAL = 0, /* Allow both opc.ws:// (unencrypted) and opc.wss:// (TLS) */ |
2172 | | UA_WEBSOCKET_ENCRYPTION_REQUIRED = 1, /* Allow only opc.wss:// (TLS); reject opc.ws:// */ |
2173 | | UA_WEBSOCKET_ENCRYPTION_DISABLED = 2 /* Allow only opc.ws:// (unencrypted); reject opc.wss:// */ |
2174 | | } UA_WebSocketEncryptionMode; |
2175 | | |
2176 | | struct UA_ServerConfig { |
2177 | | void *context; /* Used to attach custom data to a server config. This can |
2178 | | * then be retrieved e.g. in a callback that forwards a |
2179 | | * pointer to the server. */ |
2180 | | UA_Logger *logging; /* Plugin for log output */ |
2181 | | |
2182 | | /* Server Description |
2183 | | * ~~~~~~~~~~~~~~~~~~ |
2184 | | * The description must be internally consistent. The ApplicationUri set in |
2185 | | * the ApplicationDescription must match the URI set in the server |
2186 | | * certificate. |
2187 | | * The applicationType is not just descriptive, it changes the actual |
2188 | | * functionality of the server. The RegisterServer service is available only |
2189 | | * if the server is a DiscoveryServer and the applicationType is set to the |
2190 | | * appropriate value.*/ |
2191 | | UA_BuildInfo buildInfo; |
2192 | | UA_ApplicationDescription applicationDescription; |
2193 | | |
2194 | | /* Server Lifecycle |
2195 | | * ~~~~~~~~~~~~~~~~ |
2196 | | * Delay in ms from the shutdown signal (ctrl-c) until the actual shutdown. |
2197 | | * Clients need to be able to get a notification ahead of time. */ |
2198 | | UA_Double shutdownDelay; |
2199 | | |
2200 | | /* If an asynchronous server shutdown is used, this callback notifies about |
2201 | | * the current lifecycle state (notably the STOPPING -> STOPPED |
2202 | | * transition). */ |
2203 | | void (*notifyLifecycleState)(UA_Server *server, UA_LifecycleState state); |
2204 | | |
2205 | | /* Rule Handling |
2206 | | * ~~~~~~~~~~~~~ |
2207 | | * Override the handling of standard-defined behavior. These settings are |
2208 | | * used to balance the following contradicting requirements: |
2209 | | * |
2210 | | * - Strict conformance with the standard (for certification). |
2211 | | * - Ensure interoperability with old/non-conforming implementations |
2212 | | * encountered in the wild. |
2213 | | * |
2214 | | * The defaults are set for compatibility with the largest number of OPC UA |
2215 | | * vendors (with log warnings activated). Cf. Postel's Law "be conservative |
2216 | | * in what you send, be liberal in what you accept". |
2217 | | * |
2218 | | * See the section :ref:`rule-handling` for the possible settings. */ |
2219 | | |
2220 | | /* Verify that the server sends a timestamp in the request header */ |
2221 | | UA_RuleHandling verifyRequestTimestamp; |
2222 | | |
2223 | | /* Variables (that don't have a DataType of BaseDataType) must not have an |
2224 | | * empty variant value. The default behaviour is to auto-create a matching |
2225 | | * zeroed-out value for empty VariableNodes when they are added. */ |
2226 | | UA_RuleHandling allowEmptyVariables; |
2227 | | |
2228 | | UA_RuleHandling allowAllCertificateUris; |
2229 | | |
2230 | | /* Verify that client ApplicationInstanceCertificates and X509IdentityTokens |
2231 | | * permit clientAuth. For RSA application certificates the EKU extension is |
2232 | | * mandatory. For ECC application certificates and user certificates it is |
2233 | | * optional, but must permit clientAuth when present. ABORT rejects invalid |
2234 | | * usage, DEFAULT and WARN log and continue, and ACCEPT continues silently. */ |
2235 | | UA_RuleHandling certificateEkuRule; |
2236 | | |
2237 | | /* Custom Data Types |
2238 | | * ~~~~~~~~~~~~~~~~~ |
2239 | | * The following is a linked list of arrays with custom data types. All data |
2240 | | * types that are accessible from here are automatically considered for the |
2241 | | * decoding of received messages. Custom data types are not cleaned up |
2242 | | * together with the configuration. So it is possible to allocate them on |
2243 | | * ROM. |
2244 | | * |
2245 | | * See the section on :ref:`generic-types`. Examples for working with custom |
2246 | | * data types are provided in ``/examples/custom_datatype/``. */ |
2247 | | UA_DataTypeArray *customDataTypes; |
2248 | | |
2249 | | /* EventLoop |
2250 | | * ~~~~~~~~~ |
2251 | | * The sever can be plugged into an external EventLoop. Otherwise the |
2252 | | * EventLoop is considered to be attached to the server's lifecycle and will |
2253 | | * be destroyed when the config is cleaned up. */ |
2254 | | UA_EventLoop *eventLoop; |
2255 | | UA_Boolean externalEventLoop; /* The EventLoop is not deleted with the config */ |
2256 | | |
2257 | | /* Application Notification |
2258 | | * ~~~~~~~~~~~~~~~~~~~~~~~~ |
2259 | | * The notification callbacks can be NULL. The global callback receives all |
2260 | | * notifications. The specialized callbacks receive only the subset |
2261 | | * indicated by their name. */ |
2262 | | UA_ServerNotificationCallback globalNotificationCallback; |
2263 | | UA_ServerNotificationCallback lifecycleNotificationCallback; |
2264 | | UA_ServerNotificationCallback secureChannelNotificationCallback; |
2265 | | UA_ServerNotificationCallback sessionNotificationCallback; |
2266 | | UA_ServerNotificationCallback serviceNotificationCallback; |
2267 | | UA_ServerNotificationCallback subscriptionNotificationCallback; |
2268 | | UA_ServerNotificationCallback discoveryNotificationCallback; |
2269 | | #ifdef UA_ENABLE_AUDITING |
2270 | | UA_ServerNotificationCallback auditNotificationCallback; |
2271 | | #endif |
2272 | | |
2273 | | /* Networking |
2274 | | * ~~~~~~~~~~ |
2275 | | * The `serverUrls` array contains the server URLs like |
2276 | | * `opc.tcp://my-server:4840` or `opc.wss://localhost:443`. The URLs are |
2277 | | * used both for discovery and to set up the server sockets based on the |
2278 | | * defined hostnames, ports and WebSocket paths. |
2279 | | * |
2280 | | * - If the list is empty: Listen on all network interfaces with TCP port 4840. |
2281 | | * - If the hostname of a URL is empty: Use the define protocol and port and |
2282 | | * listen on all interfaces. */ |
2283 | | UA_String *serverUrls; |
2284 | | size_t serverUrlsSize; |
2285 | | |
2286 | | /* The following settings are specific to OPC UA with TCP transport. */ |
2287 | | UA_Boolean tcpEnabled; /* Enable the TCP listener (default: true) */ |
2288 | | UA_UInt32 tcpBufSize; /* Max length of sent and received chunks (packets) |
2289 | | * (default: 64kB) */ |
2290 | | UA_UInt32 tcpMaxMsgSize; /* Max length of messages |
2291 | | * (default: 0 -> unbounded) */ |
2292 | | UA_UInt32 tcpMaxChunks; /* Max number of chunks per message |
2293 | | * (default: 0 -> unbounded) */ |
2294 | | UA_Boolean tcpReuseAddr; |
2295 | | |
2296 | | |
2297 | | /* The following settings are specific to OPC UA Binary over WebSockets. |
2298 | | * The transport is opt-in and controlled via webSocketEnabled (default: false). |
2299 | | * TLS credentials protect opc.wss:// endpoints independently of OPC UA SecurityPolicies. */ |
2300 | | UA_Boolean webSocketEnabled; /* Enable the WebSocket listener (default: false) */ |
2301 | | UA_Boolean webSocketAllowUnencrypted; /* Allow non-standard unencrypted opc.ws:// endpoints (default: false) */ |
2302 | | UA_WebSocketEncryptionMode webSocketEncryptionMode; /* Encryption requirement (default: UA_WEBSOCKET_ENCRYPTION_OPTIONAL) */ |
2303 | | UA_UInt32 webSocketBufSize; /* Max length of sent and received chunks |
2304 | | * (default: 64kB) */ |
2305 | | UA_UInt32 webSocketMaxMsgSize; /* Max length of messages |
2306 | | * (default: 0 -> unbounded) */ |
2307 | | UA_UInt32 webSocketMaxChunks; /* Max number of chunks per message |
2308 | | * (default: 0 -> unbounded) */ |
2309 | | UA_UInt32 webSocketMaxQueueSize; /* Max bytes queued for a slow WebSocket |
2310 | | * peer (default: 16 * webSocketBufSize) */ |
2311 | | UA_ByteString webSocketCertificate; /* TLS certificate, DER or PEM */ |
2312 | | UA_ByteString webSocketPrivateKey; /* TLS private key, DER or PEM */ |
2313 | | UA_String webSocketPrivateKeyPassword; |
2314 | | |
2315 | | /* Security and Encryption |
2316 | | * ~~~~~~~~~~~~~~~~~~~~~~~ */ |
2317 | | size_t securityPoliciesSize; |
2318 | | UA_SecurityPolicy* securityPolicies; |
2319 | | |
2320 | | /* Endpoints with combinations of SecurityPolicy and SecurityMode. If the |
2321 | | * UserIdentityToken array of the Endpoint is not set, then it will be |
2322 | | * filled by the server for all UserTokenPolicies that are configured in the |
2323 | | * AccessControl plugin. */ |
2324 | | size_t endpointsSize; |
2325 | | UA_EndpointDescription *endpoints; |
2326 | | |
2327 | | /* Only allow the following discovery services to be executed on a |
2328 | | * SecureChannel with SecurityPolicyNone: GetEndpointsRequest, |
2329 | | * FindServersRequest and FindServersOnNetworkRequest. |
2330 | | * |
2331 | | * Only enable this option if there is no endpoint with SecurityPolicy#None |
2332 | | * in the endpoints list. The SecurityPolicy#None must be present in the |
2333 | | * securityPolicies list. */ |
2334 | | UA_Boolean securityPolicyNoneDiscoveryOnly; |
2335 | | |
2336 | | /* Allow clients without encryption support to connect with username and password. |
2337 | | * This requires to transmit the password in plain text over the network which is |
2338 | | * why this option is disabled by default. |
2339 | | * Make sure you really need this before enabling plain text passwords. */ |
2340 | | UA_Boolean allowNonePolicyPassword; |
2341 | | |
2342 | | /* Different sets of certificates are trusted for SecureChannel / Session. |
2343 | | * They correspond to the CertificateGroups "DefaultApplicationGroup" and |
2344 | | * "DefaultUserTokenGroup" from Part 12. |
2345 | | * |
2346 | | * If the client authenticates with an X509IdentityToken (ActivateSession |
2347 | | * Service), then this certificate is validated with the sessionPKI before |
2348 | | * forwarding the token to the AccessControl plugin. */ |
2349 | | UA_CertificateGroup secureChannelPKI; |
2350 | | UA_CertificateGroup sessionPKI; |
2351 | | |
2352 | | /* See the AccessControl Plugin API */ |
2353 | | UA_AccessControl accessControl; |
2354 | | |
2355 | | /* Nodes and Node Lifecycle |
2356 | | * ~~~~~~~~~~~~~~~~~~~~~~~~ |
2357 | | * See the section for :ref:`node lifecycle handling<node-lifecycle>`. */ |
2358 | | UA_Nodestore *nodestore; |
2359 | | UA_GlobalNodeLifecycle *nodeLifecycle; |
2360 | | |
2361 | | /* Copy the HasModellingRule reference in instances from the type |
2362 | | * definition in UA_Server_addObjectNode and UA_Server_addVariableNode. |
2363 | | * |
2364 | | * Part 3 - 6.4.4: [...] it is not required that newly created or referenced |
2365 | | * instances based on InstanceDeclarations have a ModellingRule, however, it |
2366 | | * is allowed that they have any ModellingRule independent of the |
2367 | | * ModellingRule of their InstanceDeclaration */ |
2368 | | UA_Boolean modellingRulesOnInstances; |
2369 | | |
2370 | | /* Copy Method instance declarations into each Object instance instead of |
2371 | | * adding a reference to the Method on the ObjectType. The default is false |
2372 | | * for backwards compatibility. */ |
2373 | | UA_Boolean copyMethodsOnInstances; |
2374 | | |
2375 | | /* Limits |
2376 | | * ~~~~~~ */ |
2377 | | /* Limits for SecureChannels */ |
2378 | | UA_UInt16 maxSecureChannels; |
2379 | | UA_UInt32 maxSecurityTokenLifetime; /* in ms */ |
2380 | | |
2381 | | /* Limits for Sessions */ |
2382 | | UA_UInt16 maxSessions; |
2383 | | UA_Double maxSessionTimeout; /* in ms */ |
2384 | | |
2385 | | /* Operation limits */ |
2386 | | UA_UInt32 maxNodesPerRead; |
2387 | | UA_UInt32 maxNodesPerWrite; |
2388 | | UA_UInt32 maxNodesPerMethodCall; |
2389 | | UA_UInt32 maxNodesPerBrowse; |
2390 | | UA_UInt32 maxNodesPerRegisterNodes; |
2391 | | UA_UInt32 maxNodesPerTranslateBrowsePathsToNodeIds; |
2392 | | UA_UInt32 maxNodesPerNodeManagement; |
2393 | | UA_UInt32 maxMonitoredItemsPerCall; |
2394 | | |
2395 | | /* Limits for Requests */ |
2396 | | UA_UInt32 maxReferencesPerNode; |
2397 | | |
2398 | | /* Reverse Connect |
2399 | | * ~~~~~~~~~~~~~~~ */ |
2400 | | UA_UInt32 reverseReconnectInterval; /* Default is 15000 ms */ |
2401 | | |
2402 | | /* Async Operations |
2403 | | * ~~~~~~~~~~~~~~~~ |
2404 | | * See the section for :ref:`async operations<async-operations>`. */ |
2405 | | UA_Double asyncOperationTimeout; /* in ms, 0 => unlimited */ |
2406 | | size_t maxAsyncOperationQueueSize; /* 0 => unlimited */ |
2407 | | |
2408 | | /* Notifies the userland that an async operation has been canceled. The |
2409 | | * memory for setting the output value is then freed internally and should |
2410 | | * not be touched afterwards. */ |
2411 | | void (*asyncOperationCancelCallback)(UA_Server *server, const void *out); |
2412 | | |
2413 | | #ifdef UA_ENABLE_ENCRYPTION |
2414 | | /* Limits for TrustList */ |
2415 | | UA_UInt32 maxTrustListSize; /* in bytes, 0 => unlimited */ |
2416 | | UA_UInt32 maxRejectedListSize; /* 0 => unlimited */ |
2417 | | #endif |
2418 | | |
2419 | | /* Discovery |
2420 | | * ~~~~~~~~~ */ |
2421 | | #ifdef UA_ENABLE_DISCOVERY |
2422 | | /* Enable the internal management of RegisteredServers (besides the local |
2423 | | * server itself) via the RegisterServer and FindServer services. */ |
2424 | | UA_Boolean registeredServersEnabled; |
2425 | | |
2426 | | /* Timeout in seconds when to automatically remove a registered server from |
2427 | | * the list, if it doesn't re-register within the given time frame. A value |
2428 | | * of 0 disables automatic removal. Default is 60 Minutes (60*60). Must be |
2429 | | * bigger than 10 seconds, because cleanup is only triggered approximately |
2430 | | * every 10 seconds. The server will still be removed depending on the |
2431 | | * state of the semaphore file. */ |
2432 | | UA_UInt32 registeredServerCleanupTimeout; |
2433 | | |
2434 | | /* mDNS based Announcement and Discovery is implemented in a driver that |
2435 | | * attach to a server outside the main configuration. The |
2436 | | * FindServersOnNetwork Server is however implemented by the server itself. |
2437 | | * The drivers interact with the server via the Discovery API. For example |
2438 | | * to add/update/remove a ServerOnNetwork structure. */ |
2439 | | |
2440 | | /* Enable the internal management of ServerOnNetwork entries and the |
2441 | | * FindServersOnNetwork Service. This is used in conjunction with mDNS to |
2442 | | * implement a Discovery Server that detects other servers on the |
2443 | | * network. */ |
2444 | | UA_Boolean serversOnNetworkEnabled; |
2445 | | #endif |
2446 | | |
2447 | | /* Subscriptions |
2448 | | * ~~~~~~~~~~~~~ */ |
2449 | | UA_Boolean subscriptionsEnabled; |
2450 | | #ifdef UA_ENABLE_SUBSCRIPTIONS |
2451 | | /* Limits for Subscriptions */ |
2452 | | UA_UInt32 maxSubscriptions; |
2453 | | UA_UInt32 maxSubscriptionsPerSession; |
2454 | | UA_DurationRange publishingIntervalLimits; /* in ms (must not be less than 5) */ |
2455 | | UA_UInt32Range lifeTimeCountLimits; |
2456 | | UA_UInt32Range keepAliveCountLimits; |
2457 | | UA_UInt32 maxNotificationsPerPublish; |
2458 | | UA_Boolean enableRetransmissionQueue; |
2459 | | UA_UInt32 maxRetransmissionQueueSize; /* 0 -> unlimited size */ |
2460 | | # ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS |
2461 | | UA_UInt32 maxEventsPerNode; /* 0 -> unlimited size */ |
2462 | | # endif |
2463 | | |
2464 | | /* Limits for MonitoredItems */ |
2465 | | UA_UInt32 maxMonitoredItems; |
2466 | | UA_UInt32 maxMonitoredItemsPerSubscription; |
2467 | | UA_DurationRange samplingIntervalLimits; /* in ms (must not be less than 5) */ |
2468 | | UA_UInt32Range queueSizeLimits; /* Negotiated with the client */ |
2469 | | |
2470 | | /* Limits for PublishRequests */ |
2471 | | UA_UInt32 maxPublishReqPerSession; |
2472 | | |
2473 | | /* Register MonitoredItem in Userland. |
2474 | | * Deprecated now. Use the ServerNotificationCallback mechanism with |
2475 | | * UA_APPLICATIONNOTIFICATIONTYPE_MONITOREDITEM for the same feature. |
2476 | | void (*monitoredItemRegisterCallback)(UA_Server *server, |
2477 | | const UA_NodeId *sessionId, |
2478 | | void *sessionContext, |
2479 | | const UA_NodeId *nodeId, |
2480 | | void *nodeContext, |
2481 | | UA_UInt32 attibuteId, |
2482 | | UA_Boolean removed); |
2483 | | */ |
2484 | | #endif |
2485 | | |
2486 | | /* PubSub |
2487 | | * ~~~~~~ */ |
2488 | | #ifdef UA_ENABLE_PUBSUB |
2489 | | UA_Boolean pubsubEnabled; |
2490 | | UA_PubSubConfiguration pubSubConfig; |
2491 | | #endif |
2492 | | |
2493 | | /* Auditing |
2494 | | * ~~~~~~~~ |
2495 | | * Drops audit events into the auditNotificationCallback and generates |
2496 | | * the corresponding Audit Events (if Events are enabled). */ |
2497 | | UA_Boolean auditingEnabled; |
2498 | | #ifdef UA_ENABLE_AUDITING |
2499 | | UA_Boolean auditWriteUpdateEnabled; /* Mind the runtime overhead */ |
2500 | | UA_Boolean auditMethodUpdateEnabled; /* Mind the runtime overhead */ |
2501 | | #endif |
2502 | | |
2503 | | /* Historical Access |
2504 | | * ~~~~~~~~~~~~~~~~~ */ |
2505 | | UA_Boolean historizingEnabled; |
2506 | | #ifdef UA_ENABLE_HISTORIZING |
2507 | | UA_HistoryDatabase historyDatabase; |
2508 | | |
2509 | | UA_Boolean accessHistoryDataCapability; |
2510 | | UA_UInt32 maxReturnDataValues; /* 0 -> unlimited size */ |
2511 | | |
2512 | | UA_Boolean accessHistoryEventsCapability; |
2513 | | UA_UInt32 maxReturnEventValues; /* 0 -> unlimited size */ |
2514 | | |
2515 | | UA_Boolean insertDataCapability; |
2516 | | UA_Boolean insertEventCapability; |
2517 | | UA_Boolean insertAnnotationsCapability; |
2518 | | |
2519 | | UA_Boolean replaceDataCapability; |
2520 | | UA_Boolean replaceEventCapability; |
2521 | | |
2522 | | UA_Boolean updateDataCapability; |
2523 | | UA_Boolean updateEventCapability; |
2524 | | |
2525 | | UA_Boolean deleteRawCapability; |
2526 | | UA_Boolean deleteEventCapability; |
2527 | | UA_Boolean deleteAtTimeDataCapability; |
2528 | | #endif |
2529 | | |
2530 | | /* Certificate Password Callback |
2531 | | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
2532 | | #ifdef UA_ENABLE_ENCRYPTION |
2533 | | /* If the private key is in PEM format and password protected, this callback |
2534 | | * is called during initialization to get the password to decrypt the |
2535 | | * private key. The memory containing the password is freed by the client |
2536 | | * after use. The callback should be set early, other parts of the client |
2537 | | * config setup may depend on it. */ |
2538 | | UA_StatusCode (*privateKeyPasswordCallback)(UA_ServerConfig *sc, |
2539 | | UA_ByteString *password); |
2540 | | #endif |
2541 | | |
2542 | | #ifdef UA_ENABLE_RBAC |
2543 | | /* Initial Role-Permission Presets |
2544 | | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2545 | | * Array of initial role-permission presets. Each entry is a set of |
2546 | | * UA_RolePermission mappings that define which roles get which |
2547 | | * permissions on nodes that reference this preset. |
2548 | | * |
2549 | | * During server startup, these presets are copied into the server's |
2550 | | * internal role-permissions array. The preset entries form the initial |
2551 | | * configuration with the following guarantees: |
2552 | | * |
2553 | | * - Preset entries are **never deleted** during server runtime. |
2554 | | * - Their position (index) in the internal array is **kept stable**, |
2555 | | * ensuring that nodes assigned to a preset continue to reference |
2556 | | * the same configuration throughout the server's lifetime. |
2557 | | * - Custom nodestore implementations should be aware of these |
2558 | | * index-stability guarantees when managing node permission storage. |
2559 | | * |
2560 | | * Additional role-permission sets can be added at runtime through |
2561 | | * the server API (UA_Server_setNodeRolePermissions). Runtime entries |
2562 | | * may be garbage-collected when no longer referenced by any node. */ |
2563 | | size_t rolePermissionPresetsSize; |
2564 | | UA_RolePermissionSet *rolePermissionPresets; |
2565 | | |
2566 | | /* Initial Role Definitions |
2567 | | * ~~~~~~~~~~~~~~~~~~~~~~~~ |
2568 | | * Array of initial role definitions. During server startup, these roles |
2569 | | * are copied into the server's internal role registry. Config roles are |
2570 | | * treated as **protected**: they cannot be removed at runtime via |
2571 | | * UA_Server_removeRole. |
2572 | | * |
2573 | | * Additional roles can be added at runtime through UA_Server_addRole. |
2574 | | * Runtime-added roles can be removed via UA_Server_removeRole. */ |
2575 | | size_t rolesSize; |
2576 | | UA_Role *roles; |
2577 | | |
2578 | | /* If true, all permissions are granted regardless of roles. |
2579 | | * WARNING: Effectively disables authorization. Use for testing only. */ |
2580 | | UA_Boolean allPermissionsForAnonymous; |
2581 | | #endif |
2582 | | }; |
2583 | | |
2584 | | void UA_EXPORT |
2585 | | UA_ServerConfig_clear(UA_ServerConfig *config); |
2586 | | |
2587 | | UA_DEPRECATED static UA_INLINE void |
2588 | 0 | UA_ServerConfig_clean(UA_ServerConfig *config) { |
2589 | 0 | UA_ServerConfig_clear(config); |
2590 | 0 | } Unexecuted instantiation: fuzz_binary_message.cc:UA_ServerConfig_clean(UA_ServerConfig*) Unexecuted instantiation: ua_util.c:UA_ServerConfig_clean Unexecuted instantiation: ua_session.c:UA_ServerConfig_clean Unexecuted instantiation: ua_nodes.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_ns0.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_ns0_diagnostics.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_config.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_binary.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_binary_tcp.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_binary_tcp_reverse.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_utils.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_auditing.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_async.c:UA_ServerConfig_clean Unexecuted instantiation: ua_subscription.c:UA_ServerConfig_clean Unexecuted instantiation: ua_subscription_datachange.c:UA_ServerConfig_clean Unexecuted instantiation: ua_subscription_event.c:UA_ServerConfig_clean Unexecuted instantiation: alarms_conditions.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_view.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_method.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_session.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_attribute.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_discovery.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_subscription.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_monitoreditem.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_securechannel.c:UA_ServerConfig_clean Unexecuted instantiation: ua_services_nodemanagement.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_ws.c:UA_ServerConfig_clean Unexecuted instantiation: namespace0_generated.c:UA_ServerConfig_clean Unexecuted instantiation: ua_server_modelchange.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_connection.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_dataset.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_writer.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_writergroup.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_reader.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_readergroup.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_manager.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_ns0.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_ns0_sks.c:UA_ServerConfig_clean Unexecuted instantiation: ua_pubsub_keystorage.c:UA_ServerConfig_clean Unexecuted instantiation: discovery_mdns_mdnsd.c:UA_ServerConfig_clean Unexecuted instantiation: ua_discovery.c:UA_ServerConfig_clean Unexecuted instantiation: ua_accesscontrol_default.c:UA_ServerConfig_clean Unexecuted instantiation: ua_nodestore_ziptree.c:UA_ServerConfig_clean Unexecuted instantiation: ua_config_default.c:UA_ServerConfig_clean Unexecuted instantiation: ua_config_json.c:UA_ServerConfig_clean Unexecuted instantiation: ua_history_data_backend_memory.c:UA_ServerConfig_clean Unexecuted instantiation: ua_history_data_gathering_default.c:UA_ServerConfig_clean Unexecuted instantiation: ua_history_database_default.c:UA_ServerConfig_clean |
2591 | | |
2592 | | /* Adds certificates and Certificate Revocation Lists (CRLs) to a specific |
2593 | | * certificate group on the server. |
2594 | | * |
2595 | | * @param server The server object |
2596 | | * @param certificateGroupId The NodeId of the certificate group where |
2597 | | * certificates will be added |
2598 | | * @param certificates The certificates to be added |
2599 | | * @param certificatesSize The number of certificates |
2600 | | * @param crls The associated CRLs for the certificates, required when adding |
2601 | | * issuer certificates |
2602 | | * @param crlsSize The number of CRLs |
2603 | | * @param isTrusted Indicates whether the certificates should be added to the |
2604 | | * trusted list or the issuer list |
2605 | | * @param appendCertificates Indicates whether the certificates should be added |
2606 | | * to the list or replace the existing list |
2607 | | * @return ``UA_STATUSCODE_GOOD`` on success */ |
2608 | | UA_StatusCode UA_EXPORT |
2609 | | UA_Server_addCertificates(UA_Server *server, |
2610 | | const UA_NodeId certificateGroupId, |
2611 | | UA_ByteString *certificates, |
2612 | | size_t certificatesSize, |
2613 | | UA_ByteString *crls, |
2614 | | size_t crlsSize, |
2615 | | const UA_Boolean isTrusted, |
2616 | | const UA_Boolean appendCertificates); |
2617 | | |
2618 | | /* Removes certificates from a specific certificate group on the server. The |
2619 | | * corresponding CRLs are removed automatically. |
2620 | | * |
2621 | | * @param server The server object |
2622 | | * @param certificateGroupId The NodeId of the certificate group from which |
2623 | | * certificates will be removed |
2624 | | * @param certificates The certificates to be removed |
2625 | | * @param certificatesSize The number of certificates |
2626 | | * @param isTrusted Indicates whether the certificates are being removed from |
2627 | | * the trusted list or the issuer list |
2628 | | * @return ``UA_STATUSCODE_GOOD`` on success */ |
2629 | | UA_StatusCode UA_EXPORT |
2630 | | UA_Server_removeCertificates(UA_Server *server, |
2631 | | const UA_NodeId certificateGroupId, |
2632 | | UA_ByteString *certificates, |
2633 | | size_t certificatesSize, |
2634 | | const UA_Boolean isTrusted); |
2635 | | |
2636 | | /** |
2637 | | * RBAC API |
2638 | | * ~~~~~~~~ |
2639 | | */ |
2640 | | |
2641 | | #ifdef UA_ENABLE_RBAC |
2642 | | |
2643 | | /** |
2644 | | * Node Role-Permission Management |
2645 | | * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
2646 | | * Functions for managing role permissions on individual nodes. */ |
2647 | | |
2648 | | /* Set role permissions for a node. |
2649 | | * |
2650 | | * Assigns the given set of role-permission mappings to the specified node. |
2651 | | * If an identical permission configuration already exists internally, the |
2652 | | * node will reference the existing configuration (deduplication). Otherwise, |
2653 | | * a new internal entry is created. |
2654 | | * |
2655 | | * @param server The server instance |
2656 | | * @param nodeId The NodeId of the node |
2657 | | * @param rolePermissionsSize Number of role-permission entries |
2658 | | * @param rolePermissions Array of role-permission mappings |
2659 | | * @param recursive If true, also set for all hierarchically referenced |
2660 | | * child nodes |
2661 | | * @param options Reserved for future use (e.g. to restrict the reference |
2662 | | * type for recursive traversal). Pass NULL for now. |
2663 | | * @return UA_STATUSCODE_GOOD on success */ |
2664 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2665 | | UA_Server_setNodeRolePermissions(UA_Server *server, |
2666 | | const UA_NodeId nodeId, |
2667 | | size_t rolePermissionsSize, |
2668 | | const UA_RolePermission *rolePermissions, |
2669 | | UA_Boolean recursive, |
2670 | | const UA_KeyValueMap *options); |
2671 | | |
2672 | | /* Get the role permissions of a node. |
2673 | | * |
2674 | | * Returns a copy of the role-permission mappings currently assigned to |
2675 | | * the node. The output array and its entries are allocated and must be |
2676 | | * freed by the caller. |
2677 | | * |
2678 | | * If the node has no specific role permissions assigned, the output size |
2679 | | * is set to 0 and the output pointer to NULL. |
2680 | | * |
2681 | | * @param server The server instance |
2682 | | * @param nodeId The NodeId of the node |
2683 | | * @param rolePermissionsSize Output: number of entries |
2684 | | * @param rolePermissions Output: deep-copy array of role-permission mappings |
2685 | | * @return UA_STATUSCODE_GOOD on success */ |
2686 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2687 | | UA_Server_getNodeRolePermissions(UA_Server *server, |
2688 | | const UA_NodeId nodeId, |
2689 | | size_t *rolePermissionsSize, |
2690 | | UA_RolePermission **rolePermissions); |
2691 | | |
2692 | | /* Remove role permissions from a node. |
2693 | | * |
2694 | | * Resets the node to have no specific role permissions. Default access |
2695 | | * control behavior then applies. The internal reference count for the |
2696 | | * previously assigned permission configuration is decremented. |
2697 | | * |
2698 | | * @param server The server instance |
2699 | | * @param nodeId The NodeId of the node |
2700 | | * @param recursive If true, also remove from all hierarchically referenced |
2701 | | * child nodes |
2702 | | * @return UA_STATUSCODE_GOOD on success */ |
2703 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2704 | | UA_Server_removeNodeRolePermissions(UA_Server *server, |
2705 | | const UA_NodeId nodeId, |
2706 | | UA_Boolean recursive); |
2707 | | |
2708 | | /** |
2709 | | * Role Management |
2710 | | * ^^^^^^^^^^^^^^^ |
2711 | | * Functions for managing the server's role registry. Roles define which |
2712 | | * sessions get which access rights. Config-provided roles are protected |
2713 | | * and cannot be removed at runtime. */ |
2714 | | |
2715 | | /* Add a role to the server's role registry. |
2716 | | * |
2717 | | * The role's BrowseName (roleName) is the primary unique identifier, |
2718 | | * per OPC UA Part 18 v1.05 §4.2.2 (AddRole: "The BrowseName shall be |
2719 | | * unique within the RoleSet Object"). A role with the same roleName or |
2720 | | * roleId must not already exist. |
2721 | | * |
2722 | | * If role->roleId is null, the server auto-assigns a random numeric |
2723 | | * NodeId in namespace 0. To control the namespace or identifier, set |
2724 | | * role->roleId before calling. |
2725 | | * |
2726 | | * @param server The server instance |
2727 | | * @param role The role definition to add (deep-copied) |
2728 | | * @param outRoleNodeId Output: the assigned NodeId (deep copy). May be NULL. |
2729 | | * @return UA_STATUSCODE_GOOD on success, |
2730 | | * UA_STATUSCODE_BADALREADYEXISTS if a role with the same |
2731 | | * roleName or roleId already exists */ |
2732 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2733 | | UA_Server_addRole(UA_Server *server, const UA_Role *role, |
2734 | | UA_NodeId *outRoleNodeId); |
2735 | | |
2736 | | /* Remove a role from the server's role registry. |
2737 | | * |
2738 | | * Config-provided (protected) roles cannot be removed. |
2739 | | * |
2740 | | * @param server The server instance |
2741 | | * @param roleName The BrowseName (QualifiedName) of the role to remove |
2742 | | * @return UA_STATUSCODE_GOOD on success, |
2743 | | * UA_STATUSCODE_BADUSERACCESSDENIED if the role is protected, |
2744 | | * UA_STATUSCODE_BADNOTFOUND if the role does not exist */ |
2745 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2746 | | UA_Server_removeRole(UA_Server *server, |
2747 | | const UA_QualifiedName roleName); |
2748 | | |
2749 | | /* Get a copy of a role by its BrowseName. |
2750 | | * |
2751 | | * @param server The server instance |
2752 | | * @param roleName The BrowseName (QualifiedName) of the role |
2753 | | * @param outRole Output: deep copy of the role (caller must clear) |
2754 | | * @return UA_STATUSCODE_GOOD on success, |
2755 | | * UA_STATUSCODE_BADNOTFOUND if the role does not exist */ |
2756 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2757 | | UA_Server_getRole(UA_Server *server, |
2758 | | const UA_QualifiedName roleName, |
2759 | | UA_Role *outRole); |
2760 | | |
2761 | | /* Get a copy of a role by its NodeId. |
2762 | | * |
2763 | | * @param server The server instance |
2764 | | * @param roleId The NodeId of the role |
2765 | | * @param outRole Output: deep copy of the role (caller must clear) |
2766 | | * @return UA_STATUSCODE_GOOD on success, |
2767 | | * UA_STATUSCODE_BADNOTFOUND if the role does not exist */ |
2768 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2769 | | UA_Server_getRoleById(UA_Server *server, UA_NodeId roleId, |
2770 | | UA_Role *outRole); |
2771 | | |
2772 | | /* Get the BrowseNames of all registered roles. |
2773 | | * |
2774 | | * @param server The server instance |
2775 | | * @param rolesSize Output: number of roles |
2776 | | * @param roleNames Output: array of role BrowseNames (caller must |
2777 | | * clear each entry and free the array) |
2778 | | * @return UA_STATUSCODE_GOOD on success */ |
2779 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2780 | | UA_Server_getRoles(UA_Server *server, size_t *rolesSize, |
2781 | | UA_QualifiedName **roleNames); |
2782 | | |
2783 | | /* Update a role in the server's role registry. |
2784 | | * |
2785 | | * The existing role is matched by roleId, roleName (QualifiedName) or |
2786 | | * both. At least one must be set. If both are provided they must |
2787 | | * identify the same role. Replaces all mutable fields (identityMappingRules, |
2788 | | * applications, endpoints and their exclude flags) with deep copies |
2789 | | * from the provided role. The roleId and roleName of the stored role |
2790 | | * are not changed. |
2791 | | * |
2792 | | * Anonymous and AuthenticatedUser are well-known roles defined by the |
2793 | | * OPC UA specification and cannot be modified. |
2794 | | * |
2795 | | * @param server The server instance |
2796 | | * @param role The role with updated fields |
2797 | | * @return UA_STATUSCODE_GOOD on success, |
2798 | | * UA_STATUSCODE_BADINVALIDARGUMENT if neither roleId nor |
2799 | | * roleName is set, |
2800 | | * UA_STATUSCODE_BADNOTFOUND if no matching role exists, |
2801 | | * UA_STATUSCODE_BADUSERACCESSDENIED if the matched role is |
2802 | | * Anonymous or AuthenticatedUser */ |
2803 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2804 | | UA_Server_updateRole(UA_Server *server, const UA_Role *role); |
2805 | | |
2806 | | /** |
2807 | | * Session Role Management |
2808 | | * ^^^^^^^^^^^^^^^^^^^^^^^ |
2809 | | * Session roles are managed via the generic session attribute API using the |
2810 | | * key ``UA_QUALIFIEDNAME(0, "roles")``. The value is a ``UA_NodeId[]`` |
2811 | | * array of the roles assigned to the session. |
2812 | | * |
2813 | | * All role NodeIds are validated against the server's role registry on write. |
2814 | | * |
2815 | | * **Set roles:** |
2816 | | * |
2817 | | * .. code-block:: c |
2818 | | * |
2819 | | * UA_NodeId roles[2] = { role1Id, role2Id }; |
2820 | | * UA_Variant v; |
2821 | | * UA_Variant_setArray(&v, roles, 2, &UA_TYPES[UA_TYPES_NODEID]); |
2822 | | * UA_Server_setSessionAttribute(server, &sessionId, |
2823 | | * UA_QUALIFIEDNAME(0, "roles"), &v); |
2824 | | * |
2825 | | * **Get roles (deep copy):** |
2826 | | * |
2827 | | * .. code-block:: c |
2828 | | * |
2829 | | * UA_Variant out; |
2830 | | * UA_Server_getSessionAttributeCopy(server, &sessionId, |
2831 | | * UA_QUALIFIEDNAME(0, "roles"), &out); |
2832 | | * UA_NodeId *roles = (UA_NodeId *)out.data; |
2833 | | * size_t count = out.arrayLength; |
2834 | | * // ... use roles ... |
2835 | | * UA_Variant_clear(&out); |
2836 | | * |
2837 | | * **Clear roles:** |
2838 | | * |
2839 | | * .. code-block:: c |
2840 | | * |
2841 | | * UA_Server_deleteSessionAttribute(server, &sessionId, |
2842 | | * UA_QUALIFIEDNAME(0, "roles")); */ |
2843 | | |
2844 | | /* Convenience: Get role QualifiedNames assigned to a session. |
2845 | | * Returns a deep copy of the role names. Free the result with |
2846 | | * UA_Array_delete(roleNames, count, &UA_TYPES[UA_TYPES_QUALIFIEDNAME]). |
2847 | | * |
2848 | | * @param server The server instance |
2849 | | * @param sessionId The session to query |
2850 | | * @param outSize Output: number of roles |
2851 | | * @param outRoleNames Output: deep-copy array of QualifiedNames |
2852 | | * @return UA_STATUSCODE_GOOD on success */ |
2853 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2854 | | UA_Server_getSessionRoleNames(UA_Server *server, const UA_NodeId sessionId, |
2855 | | size_t *outSize, UA_QualifiedName **outRoleNames); |
2856 | | |
2857 | | /* Convenience bitmask: all permission bits set */ |
2858 | | #define UA_PERMISSIONTYPE_ALL ((UA_PermissionType)0xFFFFFFFF) |
2859 | | |
2860 | | /** |
2861 | | * Per-Role Node Permission Management |
2862 | | * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
2863 | | * Functions that add or remove permissions for a specific role on a node. |
2864 | | * Unlike setNodeRolePermissions (which replaces the entire set), these |
2865 | | * functions modify individual role entries within the node's permission |
2866 | | * configuration. */ |
2867 | | |
2868 | | /* Add role permissions to a node for a specific role. |
2869 | | * |
2870 | | * @param server The server instance |
2871 | | * @param nodeId The node to modify |
2872 | | * @param roleId The role to add permissions for |
2873 | | * @param permissions Permission bitmask to set |
2874 | | * @param overwriteExisting If true, replace the role's existing permission |
2875 | | * bitmask entirely; if false, OR (merge) the new bits into the |
2876 | | * existing bitmask |
2877 | | * @param recursive If true, apply recursively to child nodes |
2878 | | * @return UA_STATUSCODE_GOOD on success */ |
2879 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2880 | | UA_Server_addRolePermissions(UA_Server *server, const UA_NodeId nodeId, |
2881 | | const UA_NodeId roleId, |
2882 | | UA_PermissionType permissions, |
2883 | | UA_Boolean overwriteExisting, |
2884 | | UA_Boolean recursive); |
2885 | | |
2886 | | /* Remove role permissions from a node for a specific role. |
2887 | | * |
2888 | | * @param server The server instance |
2889 | | * @param nodeId The node to modify |
2890 | | * @param roleId The role to remove permissions for |
2891 | | * @param permissions Permission bitmask to clear |
2892 | | * @param recursive If true, apply recursively to child nodes |
2893 | | * @return UA_STATUSCODE_GOOD on success */ |
2894 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2895 | | UA_Server_removeRolePermissions(UA_Server *server, const UA_NodeId nodeId, |
2896 | | const UA_NodeId roleId, |
2897 | | UA_PermissionType permissions, |
2898 | | UA_Boolean recursive); |
2899 | | |
2900 | | /** |
2901 | | * Namespace Default Role Permissions |
2902 | | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2903 | | * Per OPC UA Part 5: if a node has no explicit RolePermissions, |
2904 | | * the DefaultRolePermissions from the NamespaceMetadata apply. |
2905 | | * |
2906 | | * Permission resolution order: |
2907 | | * 1. Explicit node RolePermissions (set via addRolePermissions) |
2908 | | * 2. Namespace default RolePermissions (set via this API) */ |
2909 | | |
2910 | | /* Set default role permissions for a namespace. |
2911 | | * Overwrites any previously set defaults for the given namespace. |
2912 | | * |
2913 | | * @param server The server instance |
2914 | | * @param namespaceIndex The namespace index |
2915 | | * @param entriesSize Number of role-permission entries |
2916 | | * @param entries Array of role-permission entries (deep-copied) |
2917 | | * @return UA_STATUSCODE_GOOD on success */ |
2918 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2919 | | UA_Server_setNamespaceDefaultRolePermissions(UA_Server *server, |
2920 | | UA_UInt16 namespaceIndex, |
2921 | | size_t entriesSize, |
2922 | | const UA_RolePermission *entries); |
2923 | | |
2924 | | /* Get default role permissions for a namespace. |
2925 | | * Returns a deep copy. The caller must free each entry's roleId |
2926 | | * with UA_NodeId_clear and the array with UA_free. |
2927 | | * |
2928 | | * @param server The server instance |
2929 | | * @param namespaceIndex The namespace index |
2930 | | * @param entriesSize Output: number of entries |
2931 | | * @param entries Output: deep-copied array (caller must free) |
2932 | | * @return UA_STATUSCODE_GOOD on success */ |
2933 | | UA_StatusCode UA_EXPORT UA_THREADSAFE |
2934 | | UA_Server_getNamespaceDefaultRolePermissions(UA_Server *server, |
2935 | | UA_UInt16 namespaceIndex, |
2936 | | size_t *entriesSize, |
2937 | | UA_RolePermission **entries); |
2938 | | |
2939 | | #endif /* UA_ENABLE_RBAC */ |
2940 | | |
2941 | | /** |
2942 | | * .. _server-json-config: |
2943 | | * |
2944 | | * Configuration from File |
2945 | | * ----------------------- |
2946 | | * |
2947 | | * The server can be configured from JSON5-formatted content stored in a |
2948 | | * ``UA_ByteString``. |
2949 | | * |
2950 | | * The example files ``examples/json_config/server_json_config.json5`` and |
2951 | | * ``examples/server_json_config.c`` document the intended workflow and the |
2952 | | * currently supported keys. They cover the common runtime limits as well as |
2953 | | * optional blocks for discovery, subscriptions, historizing, PubSub and |
2954 | | * security policy configuration. TCP is enabled by default. WebSockets are |
2955 | | * disabled by default and can be configured with ``webSocketEnabled`` and the |
2956 | | * ``webSocket`` block when ``UA_ENABLE_LWS`` is compiled in. |
2957 | | * |
2958 | | * The following functions require JSON encoding support |
2959 | | * (``UA_ENABLE_JSON_ENCODING``). */ |
2960 | | |
2961 | | #ifdef UA_ENABLE_JSON_ENCODING |
2962 | | |
2963 | | /* Loads the server configuration from a Json5 file into the server. |
2964 | | * |
2965 | | * @param jsonConfig The configuration in json5 format. |
2966 | | */ |
2967 | | UA_EXPORT UA_Server * |
2968 | | UA_Server_newFromFile(const UA_ByteString jsonConfig); |
2969 | | |
2970 | | /* Loads a server configuration from a file. The passed server configuration |
2971 | | * is cleared. Memory will be allocated for fields in config. |
2972 | | * |
2973 | | * @param config The server configuration. |
2974 | | * @param jsonConfig The configuration in json5 format. |
2975 | | */ |
2976 | | UA_EXPORT UA_StatusCode |
2977 | | UA_ServerConfig_loadFromFile(UA_ServerConfig *config, const UA_ByteString jsonConfig); |
2978 | | |
2979 | | #endif /* UA_ENABLE_JSON_ENCODING */ |
2980 | | |
2981 | | _UA_END_DECLS |
2982 | | |
2983 | | #ifdef UA_ENABLE_PUBSUB |
2984 | | #include <open62541/server_pubsub.h> |
2985 | | #endif |
2986 | | |
2987 | | #endif /* UA_SERVER_H_ */ |