Coverage Report

Created: 2026-06-30 06:40

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