forked from fluisgirardi/fpopen62541
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open62541.pas
2593 lines (2318 loc) · 120 KB
/
open62541.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
* open62541 is licensed under the Mozilla Public License v2.0 (MPLv2).
* This allows the open62541 library to be combined and distributed with any proprietary software.
* Only changes to the open62541 library itself need to be licensed under the MPLv2 when copied and distributed.
* The plugins, as well as the server and client examples are in the public domain (CC0 license).
* They can be reused under any license and changes do not have to be published.
*
* Version 1.2-rc2 released on 23 Dec 2020
*
* BEWARE: between version 1.1 and version 1.2 many structures
* and ids have changed so the two versions are not binary compatible
* (i.e you cannot use these headers with version 1.1)
*
* Author: Lacak <lacak At Sourceforge>
*
* Contributors:
* Luca Olivetti <luca@ventoso.org>
*)
unit open62541;
(*
* Example:
* var
* client: PUA_Client;
* config: PUA_ClientConfig;
* nodeId: UA_NodeId;
* value: UA_Variant;
* begin
* client := UA_Client_new();
* config := UA_Client_getConfig(client);
* UA_ClientConfig_setDefault(config);
* if UA_Client_connect(client, 'opc.tcp://localhost...') = UA_STATUSCODE_GOOD then begin
* nodeId := UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
* UA_Variant_init(value);
* if (UA_Client_readValueAttribute(client, nodeId, value) = UA_STATUSCODE_GOOD) and
* (UA_Variant_hasScalarType(@value, @UA_TYPES[UA_TYPES_DATETIME])) then begin
* ...
* end;
* UA_Variant_clear(value);
* end;
* UA_Client_delete(client);
* end;
*)
{$DEFINE LOAD_DYNAMICALLY}
{$IFDEF FPC}
{$IFDEF LOAD_DYNAMICALLY}
{$MODE DELPHI}
{$ENDIF}
{$PACKENUM 4} // GCC on x86 enums have size of 4 bytes
{$PACKRECORDS C}
{$ELSE}
{$MINENUMSIZE 4}
{$ALIGN 4}
{$ENDIF}
{$H+}
{$POINTERMATH ON}
{$DEFINE ENABLE_SERVER}
// Use open62541 v1.3
{$DEFINE UA_VER1_3}
interface
{ ---------------- }
{ --- config.h --- }
{ ---------------- }
{$DEFINE UA_ENABLE_METHODCALLS}
{$DEFINE UA_ENABLE_SUBSCRIPTIONS}
{$DEFINE UA_ENABLE_STATUSCODE_DESCRIPTIONS}
{$DEFINE UA_ENABLE_TYPEDESCRIPTION}
{ $DEFINE UA_ENABLE_ENCRYPTION} // disabled in pre-compiled "libopen62541" library (required for SIGN and SIGN&ENCRYPT)
const
{$IFDEF UNIX}
libopen62541 = 'libopen62541.so';
{$ELSE}
libopen62541 = 'libopen62541.dll'; // GCC libgcc_s_sjlj-1.dll and libwinpthread-1.dll are also required
// they can be downloaded from packages at http://win-builds.org/1.5.0/packages/windows_32/
{$ENDIF}
UA_VER = {$IFDEF UA_VER1_3}1.3{$ELSE}1.2{$ENDIF};
type
{$IFNDEF FPC}
// Delphi XE compatibility
DWord = LongWord; // FixedUInt 32-bit
size_t = NativeUInt; // DWord on 32-bit platforms, QWord on 64-bit platforms
{$ENDIF}
{$IF NOT DECLARED(size_t)}
size_t = NativeUInt;
{$IFEND}
UA_Client = record end;
PUA_Client = ^UA_Client;
{ --------------- }
{ --- types.h --- }
{ --------------- }
UA_Boolean = bytebool;PUA_Boolean = ^UA_Boolean;
UA_Byte = Byte; PUA_Byte = ^UA_Byte;
UA_Int16 = Smallint; PUA_Int16 = ^UA_Int16;
UA_UInt16 = Word; PUA_UInt16 = ^UA_UInt16;
UA_Int32 = integer; PUA_Int32 = ^UA_Int32;
UA_UInt32 = DWord; PUA_UInt32 = ^UA_UInt32;
UA_Int64 = Int64; PUA_Int64 = ^UA_Int64;
UA_UInt64 = UInt64; PUA_UInt64 = ^UA_UInt64;
UA_Float = single; PUA_Float = ^UA_Float;
UA_Double = double; PUA_Double = ^UA_Double;
(**
* .. _statuscode:
*
* StatusCode
* ^^^^^^^^^^
* A numeric identifier for a error or condition that is associated with a value
* or an operation. See the section :ref:`statuscodes` for the meaning of a
* specific code. *)
UA_StatusCode = DWord; // uint32_t
PUA_StatusCode = ^UA_StatusCode;
(**
* String
* ^^^^^^
* A sequence of Unicode characters. Strings are just an array of UA_Byte. *)
UA_String = record
length: size_t; (* The length of the string *)
data: PUA_Byte; (* The content (not null-terminated) *)
end;
PUA_String = ^UA_String;
(**
* .. _datetime:
*
* DateTime
* ^^^^^^^^
* An instance in time. A DateTime value is encoded as a 64-bit signed integer
* which represents the number of 100 nanosecond intervals since January 1, 1601
* (UTC).
*
* The methods providing an interface to the system clock are architecture-
* specific. Usually, they provide a UTC clock that includes leap seconds. The
* OPC UA standard allows the use of International Atomic Time (TAI) for the
* DateTime instead. But this is still unusual and not implemented for most
* SDKs. Currently (2019), UTC and TAI are 37 seconds apart due to leap
* seconds. *)
UA_DateTime = Int64;
PUA_DateTime = ^UA_DateTime;
UA_DateTimeStruct = record
nanoSec : UA_UInt16;
microSec : UA_UInt16;
milliSec : UA_UInt16;
sec : UA_UInt16;
min : UA_UInt16;
hour : UA_UInt16;
day : UA_UInt16;
month : UA_UInt16;
year : UA_UInt16;
end;
(**
* ByteString
* ^^^^^^^^^^
* A sequence of octets. *)
UA_ByteString = UA_String;
PUA_ByteString = ^UA_ByteString;
(**
* Guid
* ^^^^
* A 16 byte value that can be used as a globally unique identifier. *)
UA_Guid = record
data1: UA_UInt32;
data2: UA_UInt16;
data3: UA_UInt16 ;
data4: array[0..7] of UA_Byte;
end;
UA_LogLevel = (
UA_LOGLEVEL_TRACE,
UA_LOGLEVEL_DEBUG,
UA_LOGLEVEL_INFO,
UA_LOGLEVEL_WARNING,
UA_LOGLEVEL_ERROR,
UA_LOGLEVEL_FATAL
);
UA_LogCategory = (
UA_LOGCATEGORY_NETWORK,
UA_LOGCATEGORY_SECURECHANNEL,
UA_LOGCATEGORY_SESSION,
UA_LOGCATEGORY_SERVER,
UA_LOGCATEGORY_CLIENT,
UA_LOGCATEGORY_USERLAND,
UA_LOGCATEGORY_SECURITYPOLICY
);
UA_Logger = record
(* Log a message. The message string and following varargs are formatted
* according to the rules of the printf command. Use the convenience macros
* below that take the minimum log-level defined in ua_config.h into
* account. *)
log: procedure(logContext: Pointer; level:UA_LogLevel; category:UA_LogCategory; msg: PAnsiChar; args: {va_list}array of const); cdecl;
context: Pointer; (* Logger state *)
clear: procedure(context: Pointer); cdecl; (* Clean up the logger plugin *)
end;
PUA_Logger = ^UA_Logger;
(**
* .. _nodeid:
*
* NodeId
* ^^^^^^
* An identifier for a node in the address space of an OPC UA Server. *)
UA_NodeIdType = (
UA_NODEIDTYPE_NUMERIC = 0, (* In the binary encoding, this can also
* become 1 or 2 (two-byte and four-byte
* encoding of small numeric nodeids) *)
UA_NODEIDTYPE_STRING = 3,
UA_NODEIDTYPE_GUID = 4,
UA_NODEIDTYPE_BYTESTRING = 5
);
UA_NodeId = record
namespaceIndex : UA_UInt16;
identifierType : UA_NodeIdType;
identifier : record
case longint of
0 : ( numeric : UA_UInt32 );
1 : ( _string : UA_String );
2 : ( guid : UA_Guid );
3 : ( byteString : UA_ByteString );
end;
end;
PUA_NodeId = ^UA_NodeId;
(**
* ExpandedNodeId
* ^^^^^^^^^^^^^^
* A NodeId that allows the namespace URI to be specified instead of an index. *)
UA_ExpandedNodeId = record
nodeId: UA_NodeId;
namespaceUri: UA_String;
serverIndex: UA_UInt32;
end;
PUA_ExpandedNodeId = ^UA_ExpandedNodeId;
(**
* .. _qualifiedname:
*
* QualifiedName
* ^^^^^^^^^^^^^
* A name qualified by a namespace. *)
UA_QualifiedName = record
namespaceIndex: UA_UInt16;
name: UA_String;
end;
PUA_QualifiedName = ^UA_QualifiedName;
(**
* LocalizedText
* ^^^^^^^^^^^^^
* Human readable text with an optional locale identifier. *)
UA_LocalizedText = record
locale: UA_String;
text: UA_String;
end;
PUA_LocalizedText = ^UA_LocalizedText;
(**
* NumericRange
* ^^^^^^^^^^^^
* NumericRanges are used to indicate subsets of a (multidimensional) array.
* They no official data type in the OPC UA standard and are transmitted only
* with a string encoding, such as "1:2,0:3,5". The colon separates min/max
* index and the comma separates dimensions. A single value indicates a range
* with a single element (min==max). *)
UA_NumericRangeDimension = record
min,
max: UA_UInt32;
end;
UA_NumericRange = record
dimensionsSize: size_t;
dimensions: ^UA_NumericRangeDimension;
end;
PUA_NumericRange = ^UA_NumericRange;
PUA_DataType = ^UA_DataType;
(**
* .. _variant:
*
* Variant
* ^^^^^^^
*
* Variants may contain values of any type together with a description of the
* content. See the section on :ref:`generic-types` on how types are described.
* The standard mandates that variants contain built-in data types only. If the
* value is not of a builtin type, it is wrapped into an :ref:`extensionobject`.
* open62541 hides this wrapping transparently in the encoding layer. If the
* data type is unknown to the receiver, the variant contains the original
* ExtensionObject in binary or XML encoding.
*
* Variants may contain a scalar value or an array. For details on the handling
* of arrays, see the section on :ref:`array-handling`. Array variants can have
* an additional dimensionality (matrix, 3-tensor, ...) defined in an array of
* dimension lengths. The actual values are kept in an array of dimensions one.
* For users who work with higher-dimensions arrays directly, keep in mind that
* dimensions of higher rank are serialized first (the highest rank dimension
* has stride 1 and elements follow each other directly). Usually it is simplest
* to interact with higher-dimensional arrays via ``UA_NumericRange``
* descriptions (see :ref:`array-handling`).
*
* To differentiate between scalar / array variants, the following definition is
* used. ``UA_Variant_isScalar`` provides simplified access to these checks.
*
* - ``arrayLength == 0 && data == NULL``: undefined array of length -1
* - ``arrayLength == 0 && data == UA_EMPTY_ARRAY_SENTINEL``: array of length 0
* - ``arrayLength == 0 && data > UA_EMPTY_ARRAY_SENTINEL``: scalar value
* - ``arrayLength > 0``: array of the given length
*
* Variants can also be *empty*. Then, the pointer to the type description is
* ``NULL``. *)
UA_VariantStorageType = (
UA_VARIANT_DATA, (* The data has the same lifecycle as the variant *)
UA_VARIANT_DATA_NODELETE (* The data is "borrowed" by the variant and shall not be deleted at the end of the variant's lifecycle.*)
);
UA_Variant = record
_type : PUA_DataType; (* The data type description *)
storageType : UA_VariantStorageType;
arrayLength : size_t;
data : pointer; (* Points to the scalar or array data *)
arrayDimensionsSize : size_t; (* The number of dimensions *)
arrayDimensions : ^UA_UInt32; (* The length of each dimension *)
end;
PUA_Variant = ^UA_Variant;
(**
* .. _extensionobject:
*
* ExtensionObject
* ^^^^^^^^^^^^^^^
*
* ExtensionObjects may contain scalars of any data type. Even those that are
* unknown to the receiver. See the section on :ref:`generic-types` on how types
* are described. If the received data type is unknown, the encoded string and
* target NodeId is stored instead of the decoded value. *)
UA_ExtensionObjectEncoding = (
UA_EXTENSIONOBJECT_ENCODED_NOBODY = 0,
UA_EXTENSIONOBJECT_ENCODED_BYTESTRING = 1,
UA_EXTENSIONOBJECT_ENCODED_XML = 2,
UA_EXTENSIONOBJECT_DECODED = 3,
UA_EXTENSIONOBJECT_DECODED_NODELETE = 4 (* Don't delete the content
together with the ExtensionObject *)
);
UA_ExtensionObject = record
encoding : UA_ExtensionObjectEncoding;
content : record
case longint of
0 : ( encoded : record
typeId : UA_NodeId; (* The nodeid of the datatype *)
body : UA_ByteString; (* The bytestring of the encoded data *)
end );
1 : ( decoded : record
_type : PUA_DataType;
data : pointer;
end );
end;
end;
PUA_ExtensionObject = ^UA_ExtensionObject;
(**
* DataValue
* ^^^^^^^^^
* A data value with an associated status code and timestamps. *)
UA_DataValue = record
value: UA_Variant;
sourceTimestamp: UA_DateTime;
serverTimestamp: UA_DateTime;
sourcePicoseconds: UA_UInt16;
serverPicoseconds: UA_UInt16;
status: UA_StatusCode;
flag: UA_Byte;
{ UA_Boolean hasValue : 1;
UA_Boolean hasStatus : 1;
UA_Boolean hasSourceTimestamp : 1;
UA_Boolean hasServerTimestamp : 1;
UA_Boolean hasSourcePicoseconds : 1;
UA_Boolean hasServerPicoseconds : 1;}
end;
PUA_DataValue = ^UA_DataValue;
(**
* DiagnosticInfo
* ^^^^^^^^^^^^^^
* A structure that contains detailed error and diagnostic information
* associated with a StatusCode. *)
PUA_DiagnosticInfo = ^UA_DiagnosticInfo;
UA_DiagnosticInfo = record
flag: UA_Boolean;
{ UA_Boolean hasSymbolicId : 1;
UA_Boolean hasNamespaceUri : 1;
UA_Boolean hasLocalizedText : 1;
UA_Boolean hasLocale : 1;
UA_Boolean hasAdditionalInfo : 1;
UA_Boolean hasInnerStatusCode : 1;
UA_Boolean hasInnerDiagnosticInfo : 1;}
symbolicId: UA_Int32;
namespaceUri: UA_Int32;
localizedText: UA_Int32;
locale: UA_Int32;
additionalInfo: UA_String;
innerStatusCode: UA_StatusCode;
innerDiagnosticInfo: PUA_DiagnosticInfo;
end;
(**
* .. _generic-types:
*
* Generic Type Handling
* ---------------------
*
* All information about a (builtin/structured) data type is stored in a
* ``UA_DataType``. The array ``UA_TYPES`` contains the description of all
* standard-defined types. This type description is used for the following
* generic operations that work on all types:
*
* - ``void T_init(T *ptr)``: Initialize the data type. This is synonymous with
* zeroing out the memory, i.e. ``memset(ptr, 0, sizeof(T))``.
* - ``T* T_new()``: Allocate and return the memory for the data type. The
* value is already initialized.
* - ``UA_StatusCode T_copy(const T *src, T *dst)``: Copy the content of the
* data type. Returns ``UA_STATUSCODE_GOOD`` or
* ``UA_STATUSCODE_BADOUTOFMEMORY``.
* - ``void T_clear(T *ptr)``: Delete the dynamically allocated content
* of the data type and perform a ``T_init`` to reset the type.
* - ``void T_delete(T *ptr)``: Delete the content of the data type and the
* memory for the data type itself.
*
* Specializations, such as ``UA_Int32_new()`` are derived from the generic
* type operations as static inline functions. *)
{$IFDEF UA_VER1_3}
UA_DataTypeMember = bitpacked record
{$ifdef UA_ENABLE_TYPEDESCRIPTION}
memberName: PAnsiChar;
{$endif}
memberType : PUA_DataType;
padding : 0..63; (* How much padding is there before this
member element? For arrays this is the
padding before the size_t length member.
(No padding between size_t and the
following ptr.) *)
isArray : 0..1;
isOptional : 0..1;
fill : UA_Byte;
fill1 : UA_Byte;
fill2 : UA_Byte;
{namespaceZero: UA_Boolean:1;} (* The type of the member is defined in
namespace zero. In this implementation,
types from custom namespace may contain
members from the same namespace or
namespace zero only.*)
{isArray: UA_Boolean:1;} (* The member is an array *)
{isOptional: UA_Boolean:1;} (* The member is an optional field *)
end;
{$ELSE}
UA_DataTypeMember = record
memberTypeIndex: UA_UInt16; (* Index of the member in the array of data
types *)
padding: UA_Byte; (* How much padding is there before this
member element? For arrays this is the
padding before the size_t length member.
(No padding between size_t and the
following ptr.) *)
flag: Byte;
{namespaceZero: UA_Boolean:1;} (* The type of the member is defined in
namespace zero. In this implementation,
types from custom namespace may contain
members from the same namespace or
namespace zero only.*)
{isArray: UA_Boolean:1;} (* The member is an array *)
{isOptional: UA_Boolean:1;} (* The member is an optional field *)
{$ifdef UA_ENABLE_TYPEDESCRIPTION}
memberName: PAnsiChar;
{$endif}
end;
{$ENDIF}
(* The DataType "kind" is an internal type classification. It is used to
* dispatch handling to the correct routines. *)
UA_DataTypeKind = (
UA_DATATYPEKIND_BOOLEAN = 0,
UA_DATATYPEKIND_SBYTE = 1,
UA_DATATYPEKIND_BYTE = 2,
UA_DATATYPEKIND_INT16 = 3,
UA_DATATYPEKIND_UINT16 = 4,
UA_DATATYPEKIND_INT32 = 5,
UA_DATATYPEKIND_UINT32 = 6,
UA_DATATYPEKIND_INT64 = 7,
UA_DATATYPEKIND_UINT64 = 8,
UA_DATATYPEKIND_FLOAT = 9,
UA_DATATYPEKIND_DOUBLE = 10,
UA_DATATYPEKIND_STRING = 11,
UA_DATATYPEKIND_DATETIME = 12,
UA_DATATYPEKIND_GUID = 13,
UA_DATATYPEKIND_BYTESTRING = 14,
UA_DATATYPEKIND_XMLELEMENT = 15,
UA_DATATYPEKIND_NODEID = 16,
UA_DATATYPEKIND_EXPANDEDNODEID = 17,
UA_DATATYPEKIND_STATUSCODE = 18,
UA_DATATYPEKIND_QUALIFIEDNAME = 19,
UA_DATATYPEKIND_LOCALIZEDTEXT = 20,
UA_DATATYPEKIND_EXTENSIONOBJECT = 21,
UA_DATATYPEKIND_DATAVALUE = 22,
UA_DATATYPEKIND_VARIANT = 23,
UA_DATATYPEKIND_DIAGNOSTICINFO = 24,
UA_DATATYPEKIND_DECIMAL = 25,
UA_DATATYPEKIND_ENUM = 26,
UA_DATATYPEKIND_STRUCTURE = 27,
UA_DATATYPEKIND_OPTSTRUCT = 28, (* struct with optional fields *)
UA_DATATYPEKIND_UNION = 29,
UA_DATATYPEKIND_BITFIELDCLUSTER = 30 (* bitfields + padding *)
);
{$IFDEF UA_VER1_3}
UA_DataType = bitpacked record
{$ifdef UA_ENABLE_TYPEDESCRIPTION}
typeName: PAnsiChar;
{$endif}
typeId: UA_NodeId; (* The nodeid of the type *)
binaryEncodingId: UA_NodeId; (* NodeId of datatype when encoded as binary *)
//xmlEncodingId: UA_NodeId; (* NodeId of datatype when encoded as XML *)
memSize: UA_UInt16; (* Size of the struct in memory *)
typeKind : 0..63; (* Dispatch index for the handling routines *)
pointerFree : 0..1; (* The type (and its members) contains no
* pointers that need to be freed *)
overlayable : 0..1; (* The type has the identical memory layout
* in memory and on the binary stream. *)
membersSize : UA_Byte; (* How many members does the type have? *)
members: ^UA_DataTypeMember;
end;
{$ELSE}
UA_DataType = bitpacked record
typeId: UA_NodeId; (* The nodeid of the type *)
binaryEncodingId: UA_NodeId; (* NodeId of datatype when encoded as binary *)
memSize: UA_UInt16; (* Size of the struct in memory *)
typeIndex: UA_UInt16; (* Index of the type in the datatypetable *)
typeKind : 0..63; (* Dispatch index for the handling routines *)
pointerFree : 0..1; (* The type (and its members) contains no
* pointers that need to be freed *)
overlayable : 0..1; (* The type has the identical memory layout
* in memory and on the binary stream. *)
membersSize : UA_Byte; (* How many members does the type have? *)
members: ^UA_DataTypeMember;
{$ifdef UA_ENABLE_TYPEDESCRIPTION}
typeName: PAnsiChar;
{$endif}
end;
{$ENDIF}
(* Datatype arrays with custom type definitions can be added in a linked list to
* the client or server configuration. Datatype members can point to types in
* the same array via the ``memberTypeIndex``. If ``namespaceZero`` is set to
* true, the member datatype is looked up in the array of builtin datatypes
* instead. *)
PUA_DataTypeArray = ^UA_DataTypeArray;
UA_DataTypeArray = record
next : PUA_DataTypeArray;
typesSize : size_t;
types : ^UA_DataType;
end;
{ ------------------------- }
{ --- types_generated.h --- }
{ ------------------------- }
{$IFDEF UA_VER1_3}
{$I types_generated_1_3.inc}
{$ELSE}
{$I types_generated.inc}
{$ENDIF}
{ ---------------- }
{ --- common.h --- }
{ ---------------- }
type
(**
* Standard-Defined Constants
* ==========================
* This section contains numerical and string constants that are defined in the
* OPC UA standard.
*
* .. _attribute-id:
*
* Attribute Id
* ------------
* Every node in an OPC UA information model contains attributes depending on
* the node type. Possible attributes are as follows: *)
UA_AttributeId = (
UA_ATTRIBUTEID_NODEID = 1,
UA_ATTRIBUTEID_NODECLASS = 2,
UA_ATTRIBUTEID_BROWSENAME = 3,
UA_ATTRIBUTEID_DISPLAYNAME = 4,
UA_ATTRIBUTEID_DESCRIPTION = 5,
UA_ATTRIBUTEID_WRITEMASK = 6,
UA_ATTRIBUTEID_USERWRITEMASK = 7,
UA_ATTRIBUTEID_ISABSTRACT = 8,
UA_ATTRIBUTEID_SYMMETRIC = 9,
UA_ATTRIBUTEID_INVERSENAME = 10,
UA_ATTRIBUTEID_CONTAINSNOLOOPS = 11,
UA_ATTRIBUTEID_EVENTNOTIFIER = 12,
UA_ATTRIBUTEID_VALUE = 13,
UA_ATTRIBUTEID_DATATYPE = 14,
UA_ATTRIBUTEID_VALUERANK = 15,
UA_ATTRIBUTEID_ARRAYDIMENSIONS = 16,
UA_ATTRIBUTEID_ACCESSLEVEL = 17,
UA_ATTRIBUTEID_USERACCESSLEVEL = 18,
UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL = 19,
UA_ATTRIBUTEID_HISTORIZING = 20,
UA_ATTRIBUTEID_EXECUTABLE = 21,
UA_ATTRIBUTEID_USEREXECUTABLE = 22,
UA_ATTRIBUTEID_DATATYPEDEFINITION = 23
);
(**
* Rule Handling
* -------------
*
* The RuleHanding settings define how error cases that result from rules in the
* OPC UA specification shall be handled. The rule handling can be softened,
* e.g. to workaround misbehaving implementations or to mitigate the impact of
* additional rules that are introduced in later versions of the OPC UA
* specification. *)
UA_RuleHandling = (
UA_RULEHANDLING_DEFAULT = 0,
UA_RULEHANDLING_ABORT, (* Abort the operation and return an error code *)
UA_RULEHANDLING_WARN, (* Print a message in the logs and continue *)
UA_RULEHANDLING_ACCEPT (* Continue and disregard the broken rule *)
);
(**
* Connection State
* ---------------- *)
UA_SecureChannelState = (
UA_SECURECHANNELSTATE_CLOSED,
UA_SECURECHANNELSTATE_HEL_SENT,
UA_SECURECHANNELSTATE_HEL_RECEIVED,
UA_SECURECHANNELSTATE_ACK_SENT,
UA_SECURECHANNELSTATE_ACK_RECEIVED,
UA_SECURECHANNELSTATE_OPN_SENT,
UA_SECURECHANNELSTATE_OPEN,
UA_SECURECHANNELSTATE_CLOSING
);
PUA_SecureChannelState = ^UA_SecureChannelState;
UA_SessionState = (
UA_SESSIONSTATE_CLOSED,
UA_SESSIONSTATE_CREATE_REQUESTED,
UA_SESSIONSTATE_CREATED,
UA_SESSIONSTATE_ACTIVATE_REQUESTED,
UA_SESSIONSTATE_ACTIVATED,
UA_SESSIONSTATE_CLOSING
);
PUA_SessionState = ^UA_SessionState;
(**
* Statistic counters
* ------------------
*
* The stack manage statistic counter for the following layers:
*
* - Network
* - Secure channel
* - Session
*
* The session layer counters are matching the counters of the
* ServerDiagnosticsSummaryDataType that are defined in the OPC UA Part 5
* specification. Counter of the other layers are not specified by OPC UA but
* are harmonized with the session layer counters if possible. *)
UA_NetworkStatistics = record
currentConnectionCount:size_t;
cumulatedConnectionCount:size_t;
rejectedConnectionCount:size_t;
connectionTimeoutCount:size_t;
connectionAbortCount:size_t;
end;
PUA_NetworkStatistics = ^UA_NetworkStatistics;
UA_SecureChannelStatistics = record
currentChannelCount:size_t;
cumulatedChannelCount:size_t;
rejectedChannelCount:size_t;
channelTimeoutCount:size_t; (* only used by servers *)
channelAbortCount:size_t;
channelPurgeCount:size_t; (* only used by servers *)
end;
PUA_SecureChannelStatistics = ^UA_SecureChannelStatistics;
UA_SessionStatistics = record
currentSessionCount:size_t;
cumulatedSessionCount:size_t;
securityRejectedSessionCount:size_t; (* only used by servers *)
rejectedSessionCount:size_t;
sessionTimeoutCount:size_t; (* only used by servers *)
sessionAbortCount:size_t; (* only used by servers *)
end;
PUA_SessionStatistics = ^UA_SessionStatistics;
{ ----------------- }
{ --- network.h --- }
{ ----------------- }
(**
* .. _networking:
*
* Networking Plugin API
* =====================
*
* Connection
* ----------
* Client-server connections are represented by a `UA_Connection`. The
* connection is stateful and stores partially received messages, and so on. In
* addition, the connection contains function pointers to the underlying
* networking implementation. An example for this is the `send` function. So the
* connection encapsulates all the required networking functionality. This lets
* users on embedded (or otherwise exotic) systems implement their own
* networking plugins with a clear interface to the main open62541 library. *)
UA_ConnectionConfig = record
protocolVersion: UA_UInt32;
recvBufferSize: UA_UInt32;
sendBufferSize: UA_UInt32;
localMaxMessageSize: UA_UInt32; (* (0 = unbounded) *)
remoteMaxMessageSize: UA_UInt32; (* (0 = unbounded) *)
localMaxChunkCount: UA_UInt32; (* (0 = unbounded) *)
remoteMaxChunkCount: UA_UInt32; (* (0 = unbounded) *)
end;
UA_ConnectionState = (UA_CONNECTION_CLOSED, UA_CONNECTION_OPENING, UA_CONNECTION_ESTABLISHED);
UA_SecureChannel = record {undefined structure} end;
UA_SOCKET = Integer;
PUA_Connection = ^UA_Connection;
UA_Connection = record
state : UA_ConnectionState;
config : UA_ConnectionConfig;
channel : ^UA_SecureChannel;
sockfd : UA_SOCKET;
openingDate : UA_DateTime;
handle : pointer;
incompleteChunk : UA_ByteString;
connectCallbackID : UA_UInt64;
getSendBuffer : function (connection:PUA_Connection; length:size_t; buf:PUA_ByteString):UA_StatusCode;cdecl;
releaseSendBuffer : procedure (connection:PUA_Connection; buf:PUA_ByteString);cdecl;
send : function (connection:PUA_Connection; buf:PUA_ByteString):UA_StatusCode;cdecl;
recv : function (connection:PUA_Connection; response:PUA_ByteString; timeout:UA_UInt32):UA_StatusCode;cdecl;
releaseRecvBuffer : procedure (connection:PUA_Connection; buf:PUA_ByteString);cdecl;
close : procedure (connection:PUA_Connection);cdecl;
free : procedure (connection:PUA_Connection);cdecl;
end;
UA_ConnectClientConnection = function (config:UA_ConnectionConfig; endpointUrl:UA_String; timeout:UA_UInt32; logger:PUA_Logger):UA_Connection; cdecl;
{$IFDEF ENABLE_SERVER}
PUA_ServerNetworkLayer = ^UA_ServerNetworkLayer;
PUA_Server = ^UA_Server;
UA_ServerNetworkLayer = record
handle:pointer; (* Internal data *)
(* Points to external memory, i.e. handled by server or client *)
statistics:PUA_NetworkStatistics;
discoveryUrl:UA_String;
localConnectionConfig:UA_ConnectionConfig;
(* Start listening on the networklayer.
*
* @param nl The network layer
* @return Returns UA_STATUSCODE_GOOD or an error code. *)
start:function(nl:PUA_ServerNetworkLayer; const logger:PUA_Logger;
const customHostname:PUA_String):UA_StatusCode;cdecl;
(* Listen for new and closed connections and arriving packets. Calls
* UA_Server_processBinaryMessage for the arriving packets. Closed
* connections are picked up here and forwarded to
* UA_Server_removeConnection where they are cleaned up and freed.
*
* @param nl The network layer
* @param server The server for processing the incoming packets and for
* closing connections.
* @param timeout The timeout during which an event must arrive in
* milliseconds
* @return A statuscode for the status of the network layer. *)
listen:function(nl:PUA_ServerNetworkLayer; server:PUA_Server;
timeout:UA_UInt16):UA_StatusCode;cdecl;
(* Close the network socket and all open connections. Afterwards, the
* network layer can be safely deleted.
*
* @param nl The network layer
* @param server The server that processes the incoming packets and for
* closing connections before deleting them.
* @return A statuscode for the status of the closing operation. *)
stop:procedure(nl:PUA_ServerNetworkLayer; server:PUA_Server);cdecl;
(* Deletes the network layer context. Call only after stopping. *)
clear:procedure(nl:PUA_ServerNetworkLayer);cdecl;
end;
{$ENDIF}
{ ------------------------ }
{ --- securitypolicy.h --- }
{ ------------------------ }
PUA_SecurityPolicy = ^UA_SecurityPolicy;
UA_SecurityPolicy = record
(* Additional data *)
policyContext: Pointer;
(* The policy uri that identifies the implemented algorithms *)
policyUri: UA_ByteString;
(* The local certificate is specific for each SecurityPolicy since it
* depends on the used key length. *)
localCertificate: UA_ByteString;
(* Function pointers grouped into modules *)
{ TODO:
UA_SecurityPolicyAsymmetricModule asymmetricModule;
UA_SecurityPolicySymmetricModule symmetricModule;
UA_SecurityPolicySignatureAlgorithm certificateSigningAlgorithm;
UA_SecurityPolicyChannelModule channelModule;
UA_CertificateVerification *certificateVerification;
}
logger: PUA_Logger;
(* Updates the ApplicationInstanceCertificate and the corresponding private
* key at runtime. *)
updateCertificateAndPrivateKey: function(policy: PUA_SecurityPolicy;
const newCertificate: UA_ByteString;
const newPrivateKey: UA_ByteString): UA_StatusCode;
(* Deletes the dynamic content of the policy *)
deleteMembers: procedure(policy: PUA_SecurityPolicy);
end;
{ -------------------- }
{ --- plugin/pki.h --- }
{ -------------------- }
PUA_CertificateVerification = ^UA_CertificateVerification;
UA_CertificateVerification = record
context : pointer;
verifyCertificate : function (verificationContext:pointer; certificate:PUA_ByteString):UA_StatusCode; cdecl;
verifyApplicationURI : function (verificationContext:pointer; certificate:PUA_ByteString; applicationURI:PUA_String):UA_StatusCode; cdecl;
deleteMembers : procedure (cv:PUA_CertificateVerification); cdecl;
end;
{ ----------------------- }
{ --- client_config.h --- }
{ ----------------------- }
UA_ClientConfig = record
(* Basic client configuration *)
clientContext: Pointer; (* User-defined data attached to the client *)
logger: UA_Logger; (* Logger used by the client *)
timeout: UA_UInt32; (* Response timeout in ms *)
(* The description must be internally consistent.
* - The ApplicationUri set in the ApplicationDescription must match the
* URI set in the server certificate *)
clientDescription: UA_ApplicationDescription;
(* Basic connection configuration *)
userIdentityToken: UA_ExtensionObject; (* Configured User-Identity Token *)
securityMode: UA_MessageSecurityMode; (* None, Sign, SignAndEncrypt. The
* default is invalid. This indicates
* the client to select any matching
* endpoint. *)
securityPolicyUri: UA_String; (* SecurityPolicy for the SecureChannel. An
* empty string indicates the client to select
* any matching SecurityPolicy. *)
(* Advanced connection configuration
*
* If either endpoint or userTokenPolicy has been set (at least one non-zero
* byte in either structure), then the selected Endpoint and UserTokenPolicy
* overwrite the settings in the basic connection configuration. The
* userTokenPolicy array in the EndpointDescription is ignored. The selected
* userTokenPolicy is set in the dedicated configuration field.
*
* If the advanced configuration is not set, the client will write to it the
* selected Endpoint and UserTokenPolicy during GetEndpoints.
*
* The information in the advanced configuration is used during reconnect
* when the SecureChannel was broken. *)
endpoint: UA_EndpointDescription;
userTokenPolicy: UA_UserTokenPolicy;
(* Advanced client configuration *)
secureChannelLifeTime: UA_UInt32; (* Lifetime in ms (then the channel needs
to be renewed) *)
requestedSessionTimeout: UA_UInt32; (* Session timeout in ms *)
localConnectionConfig: UA_ConnectionConfig;
connectivityCheckInterval: UA_UInt32 ; (* Connectivity check interval in ms.
* 0 = background task disabled *)
customDataTypes: ^UA_DataTypeArray; (* Custom DataTypes. Attention!
* Custom datatypes are not cleaned
* up together with the
* configuration. So it is possible
* to allocate them on ROM. *)
(* Available SecurityPolicies *)
securityPoliciesSize: size_t;
securityPolicies: ^UA_SecurityPolicy;
(* Certificate Verification Plugin *)
certificateVerification: UA_CertificateVerification;
(* Callbacks for async connection handshakes *)
initConnectionFunc: UA_ConnectClientConnection;
pollConnectionFunc: function(client:PUA_Client; context:pointer; timeout: UA_UInt32):UA_StatusCode; cdecl;
(* Callback for state changes. The client state is differentated into the
* SecureChannel state and the Session state. The connectStatus is set if
* the client connection (including reconnects) has failed and the client
* has to "give up". If the connectStatus is not set, the client still has
* hope to connect or recover. *)
stateCallback : procedure (client:PUA_Client;
channelState: UA_SecureChannelState;
sessionState: UA_SessionState;
connectStatus: UA_StatusCode); cdecl;
(* When connectivityCheckInterval is greater than 0, every
* connectivityCheckInterval (in ms), a async read request is performed on
* the server. inactivityCallback is called when the client receive no
* response for this read request The connection can be closed, this in an
* attempt to recreate a healthy connection. *)
inactivityCallback : procedure (client:PUA_Client);cdecl;
{$IFDEF UA_ENABLE_SUBSCRIPTIONS}
(* Number of PublishResponse queued up in the server *)
outStandingPublishRequests : UA_UInt16;
(* If the client does not receive a PublishResponse after the defined delay
* of ``(sub->publishingInterval * sub->maxKeepAliveCount) +
* client->config.timeout)``, then subscriptionInactivityCallback is called
* for the subscription.. *)
subscriptionInactivityCallback : procedure (client:PUA_Client; subscriptionId:UA_UInt32; subContext:pointer);cdecl;
{$ENDIF}
end;
PUA_ClientConfig = ^UA_ClientConfig;
{$IFDEF UA_ENABLE_SUBSCRIPTIONS}
{ ------------------------------ }
{ --- client_subscriptions.h --- }
{ ------------------------------ }
(* Callbacks defined for Subscriptions *)
UA_Client_DeleteSubscriptionCallback = procedure(client: PUA_Client; subId: UA_UInt32; subContext: Pointer); cdecl;
UA_Client_StatusChangeNotificationCallback = procedure(client: PUA_Client; subId: UA_UInt32; subContext: Pointer; notification: PUA_StatusChangeNotification); cdecl;
(* Callback for the deletion of a MonitoredItem *)
UA_Client_DeleteMonitoredItemCallback = procedure(client: PUA_Client; subId: UA_UInt32; subContext: Pointer; monId: UA_UInt32; monContext: Pointer); cdecl;
(* Callback for DataChange notifications *)
UA_Client_DataChangeNotificationCallback = procedure(client: PUA_Client; subId: UA_UInt32; subContext: Pointer; monId: UA_UInt32; monContext: Pointer; value: PUA_DataValue); cdecl;
(* Callback for Event notifications *)
UA_Client_EventNotificationCallback = procedure(client: PUA_Client; subId: UA_UInt32; subContext: Pointer; monId: UA_UInt32; monContext: Pointer; nEventFields: size_t; eventFields: PUA_Variant); cdecl;
{$ENDIF}
{$IFDEF ENABLE_SERVER}
{ ---------------- }
{ --- server.h --- }
{ ---------------- }
UA_Server = record end;
UA_MethodCallback = function (server: PUA_Server;
const sessionId: PUA_NodeId; sessionContext:pointer;
const methodId: PUA_NodeId; methodContext:pointer;
const objectId: PUA_NodeId; objectContext:pointer;
inputSize: SIZE_T; const input:PUA_Variant;
outputSize: SIZE_T; output:PUA_Variant): UA_StatusCode; cdecl;
{ ----------------------- }
{ --- server_config.h --- }