forked from open62541/open62541
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_ctt.c
1351 lines (1212 loc) · 54 KB
/
server_ctt.c
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
/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
* See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
*
* Copyright 2019 (c) Kalycito Infotech Private Limited
* Copyright 2019 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
*/
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS /* disable fopen deprication warning in msvs */
#endif
#include <open62541/server.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/pki_default.h>
#include <signal.h>
#include <stdlib.h>
#include "common.h"
#define MAX_OPERATION_LIMIT 10000
/* This server is configured to the Compliance Testing Tools (CTT) against. The
* corresponding CTT configuration is available at
* https://github.com/open62541/open62541-ctt */
static const UA_NodeId baseDataVariableType = {0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_BASEDATAVARIABLETYPE}};
static const UA_NodeId accessDenied = {1, UA_NODEIDTYPE_NUMERIC, {1337}};
/* Custom AccessControl policy that disallows access to one specific node */
static UA_Byte
getUserAccessLevel_disallowSpecific(UA_Server *server, UA_AccessControl *ac,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext) {
if(UA_NodeId_equal(nodeId, &accessDenied))
return 0x00;
return 0xFF;
}
/* Datasource Example */
static UA_StatusCode
readTimeData(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_DateTime currentTime = UA_DateTime_now();
UA_Variant_setScalarCopy(&value->value, ¤tTime, &UA_TYPES[UA_TYPES_DATETIME]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = currentTime;
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomBoolData(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_Boolean toggle = !((UA_UInt32_random() % 10 ) % 2);
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_BOOLEAN]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomInt16Data(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_Int16 toggle = (UA_Int16)UA_UInt32_random();
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_INT16]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomInt32Data(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_Int32 toggle = (UA_Int32)UA_UInt32_random();
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_INT32]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomInt64Data(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_Int64 toggle = (UA_Int64)UA_UInt32_random();
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_INT64]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomUInt16Data(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_UInt16 toggle = (UA_UInt16)UA_UInt32_random();
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_UINT16]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomUInt32Data(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_UInt32 toggle = UA_UInt32_random();
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_UINT32]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomUInt64Data(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_UInt64 toggle = UA_UInt32_random();
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_UINT64]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomStringData (UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
char randomName[12];
UA_snprintf(randomName, 12, "Random%u", UA_UInt32_random());
UA_String toggle = UA_STRING(randomName);
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_STRING]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomFloatData (UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_Float toggle = (UA_Float)UA_UInt32_random();
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_FLOAT]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readRandomDoubleData (UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
UA_Double toggle = (UA_Double)UA_UInt32_random();
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_DOUBLE]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
readByteString (UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext,
UA_Boolean sourceTimeStamp,
const UA_NumericRange *range, UA_DataValue *value) {
if(range) {
value->hasStatus = true;
value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
return UA_STATUSCODE_GOOD;
}
char randomName[8];
UA_snprintf(randomName, 8, "%u%u", UA_UInt32_random(), UA_UInt32_random());
UA_ByteString randomByte = UA_BYTESTRING(randomName);
UA_Variant_setScalarCopy(&value->value, &randomByte, &UA_TYPES[UA_TYPES_BYTESTRING]);
value->hasValue = true;
if(sourceTimeStamp) {
value->hasSourceTimestamp = true;
value->sourceTimestamp = UA_DateTime_now();
}
return UA_STATUSCODE_GOOD;
}
#ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
static UA_NodeId eventId;
static void
writeEventTrigger(UA_Server *server, const UA_NodeId *sessionId,
void *sessionContext, const UA_NodeId *nodeId,
void *nodeContext, const UA_NumericRange *range,
const UA_DataValue *data) {
UA_Server_triggerEvent(server, eventId,
UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER),
NULL, false);
}
static void
cyclicEventTriger(UA_Server *server, void *data) {
(void)data;
UA_Server_triggerEvent(server, eventId,
UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER),
NULL, false);
}
#endif
/* Method Node Example */
#ifdef UA_ENABLE_METHODCALLS
static UA_StatusCode
helloWorld(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *methodId, void *methodContext,
const UA_NodeId *objectId, void *objectContext,
size_t inputSize, const UA_Variant *input,
size_t outputSize, UA_Variant *output) {
/* input is a scalar string (checked by the server) */
UA_String *name = (UA_String *)input[0].data;
UA_String hello = UA_STRING("Hello ");
UA_String greet;
greet.length = hello.length + name->length;
greet.data = (UA_Byte *)UA_malloc(greet.length);
memcpy(greet.data, hello.data, hello.length);
memcpy(greet.data + hello.length, name->data, name->length);
UA_Variant_setScalarCopy(output, &greet, &UA_TYPES[UA_TYPES_STRING]);
UA_String_clear(&greet);
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
noargMethod(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *methodId, void *methodContext,
const UA_NodeId *objectId, void *objectContext,
size_t inputSize, const UA_Variant *input,
size_t outputSize, UA_Variant *output) {
return UA_STATUSCODE_GOOD;
}
static UA_StatusCode
outargMethod(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *methodId, void *methodContext,
const UA_NodeId *objectId, void *objectContext,
size_t inputSize, const UA_Variant *input,
size_t outputSize, UA_Variant *output) {
UA_Int32 out = 42;
UA_Variant_setScalarCopy(output, &out, &UA_TYPES[UA_TYPES_INT32]);
return UA_STATUSCODE_GOOD;
}
#endif
static void
setInformationModel(UA_Server *server) {
/* add a static variable node to the server */
UA_VariableAttributes myVar = UA_VariableAttributes_default;
myVar.description = UA_LOCALIZEDTEXT("en-US", "the answer");
myVar.displayName = UA_LOCALIZEDTEXT("en-US", "the answer");
myVar.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
myVar.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
myVar.valueRank = UA_VALUERANK_SCALAR;
UA_Int32 myInteger = 42;
UA_Variant_setScalar(&myVar.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId, parentReferenceNodeId,
myIntegerName, baseDataVariableType, myVar, NULL, NULL);
/* add a static variable that is readable but not writable*/
myVar = UA_VariableAttributes_default;
myVar.description = UA_LOCALIZEDTEXT("en-US", "the answer - not readable");
myVar.displayName = UA_LOCALIZEDTEXT("en-US", "the answer - not readable");
myVar.accessLevel = UA_ACCESSLEVELMASK_WRITE;
myVar.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
myVar.valueRank = UA_VALUERANK_SCALAR;
UA_Variant_setScalar(&myVar.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
const UA_QualifiedName myInteger2Name = UA_QUALIFIEDNAME(1, "the answer - not readable");
const UA_NodeId myInteger2NodeId = UA_NODEID_STRING(1, "the.answer.no.read");
UA_Server_addVariableNode(server, myInteger2NodeId, parentNodeId, parentReferenceNodeId,
myInteger2Name, baseDataVariableType, myVar, NULL, NULL);
/* add a variable that is not readable or writable for the current user */
myVar = UA_VariableAttributes_default;
myVar.description = UA_LOCALIZEDTEXT("en-US", "the answer - not current user");
myVar.displayName = UA_LOCALIZEDTEXT("en-US", "the answer - not current user");
myVar.accessLevel = UA_ACCESSLEVELMASK_WRITE;
myVar.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
myVar.valueRank = UA_VALUERANK_SCALAR;
myVar.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
UA_Variant_setScalar(&myVar.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
const UA_QualifiedName accessDeniedName = UA_QUALIFIEDNAME(1, "the answer - not current user");
UA_Server_addVariableNode(server, accessDenied, parentNodeId, parentReferenceNodeId,
accessDeniedName, baseDataVariableType, myVar, NULL, NULL);
/* add a variable with the datetime data source */
UA_DataSource dateDataSource;
dateDataSource.read = readTimeData;
dateDataSource.write = NULL;
UA_VariableAttributes v_attr = UA_VariableAttributes_default;
v_attr.description = UA_LOCALIZEDTEXT("en-US", "current time");
v_attr.displayName = UA_LOCALIZEDTEXT("en-US", "current time");
v_attr.accessLevel = UA_ACCESSLEVELMASK_READ;
v_attr.dataType = UA_TYPES[UA_TYPES_DATETIME].typeId;
v_attr.valueRank = UA_VALUERANK_SCALAR;
const UA_QualifiedName dateName = UA_QUALIFIEDNAME(1, "current time");
UA_Server_addDataSourceVariableNode(server, UA_NODEID_NUMERIC(1, 2345),
UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), dateName,
baseDataVariableType, v_attr, dateDataSource, NULL, NULL);
/* add a bytestring variable with some content */
myVar = UA_VariableAttributes_default;
myVar.description = UA_LOCALIZEDTEXT("", "");
myVar.displayName = UA_LOCALIZEDTEXT("", "example bytestring");
myVar.dataType = UA_TYPES[UA_TYPES_BYTESTRING].typeId;
myVar.valueRank = UA_VALUERANK_SCALAR;
myVar.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
UA_ByteString myByteString = UA_BYTESTRING("test123\0test123");
UA_Variant_setScalar(&myVar.value, &myByteString, &UA_TYPES[UA_TYPES_BYTESTRING]);
const UA_QualifiedName byteStringName = UA_QUALIFIEDNAME(1, "example bytestring");
UA_Server_addVariableNode(server, UA_NODEID_STRING(1, "myByteString"),
UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), byteStringName,
baseDataVariableType, myVar, NULL, NULL);
/* Add HelloWorld method to the server */
#ifdef UA_ENABLE_METHODCALLS
/* Method with IO Arguments */
UA_Argument inputArguments;
UA_Argument_init(&inputArguments);
inputArguments.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
inputArguments.description = UA_LOCALIZEDTEXT("en-US", "Say your name");
inputArguments.name = UA_STRING("Name");
inputArguments.valueRank = UA_VALUERANK_SCALAR; /* scalar argument */
UA_Argument outputArguments;
UA_Argument_init(&outputArguments);
outputArguments.arrayDimensionsSize = 0;
outputArguments.arrayDimensions = NULL;
outputArguments.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
outputArguments.description = UA_LOCALIZEDTEXT("en-US", "Receive a greeting");
outputArguments.name = UA_STRING("greeting");
outputArguments.valueRank = UA_VALUERANK_SCALAR;
UA_MethodAttributes addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "Hello World");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, 62541),
UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
UA_QUALIFIEDNAME(1, "hello_world"), addmethodattributes,
&helloWorld, /* callback of the method node */
1, &inputArguments, 1, &outputArguments, NULL, NULL);
#endif
/* Add folders for demo information model */
#define DEMOID 50000
#define SCALARID 50001
#define ARRAYID 50002
#define MATRIXID 50003
#define DEPTHID 50004
#define SCALETESTID 40005
UA_ObjectAttributes object_attr = UA_ObjectAttributes_default;
object_attr.description = UA_LOCALIZEDTEXT("en-US", "Demo");
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Demo");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_QUALIFIEDNAME(1, "Demo"),
UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
object_attr.description = UA_LOCALIZEDTEXT("en-US", "Scalar");
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Scalar");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SCALARID),
UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
UA_QUALIFIEDNAME(1, "Scalar"),
UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
object_attr.description = UA_LOCALIZEDTEXT("en-US", "Array");
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Array");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, ARRAYID),
UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
UA_QUALIFIEDNAME(1, "Array"),
UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
object_attr.description = UA_LOCALIZEDTEXT("en-US", "Matrix");
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Matrix");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, MATRIXID), UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_QUALIFIEDNAME(1, "Matrix"),
UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
object_attr.description = UA_LOCALIZEDTEXT("en-US", "ScaleTest");
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "ScaleTest");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SCALETESTID), UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_QUALIFIEDNAME(1, "ScaleTest"),
UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
/* Fill demo nodes for each type*/
UA_UInt32 matrixDims[2] = {3, 3};
UA_UInt32 id = 51000; // running id in namespace 0
for(UA_UInt32 type = 0; type < UA_TYPES_DIAGNOSTICINFO; type++) {
if(type == UA_TYPES_VARIANT || type == UA_TYPES_DIAGNOSTICINFO)
continue;
UA_VariableAttributes attr = UA_VariableAttributes_default;
attr.dataType = UA_TYPES[type].typeId;
#ifndef UA_ENABLE_TYPEDESCRIPTION
char name[15];
UA_snprintf(name, 15, "%02d", type);
attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
UA_QualifiedName qualifiedName = UA_QUALIFIEDNAME(1, name);
#else
attr.displayName = UA_LOCALIZEDTEXT_ALLOC("en-US", UA_TYPES[type].typeName);
UA_QualifiedName qualifiedName = UA_QUALIFIEDNAME_ALLOC(1, UA_TYPES[type].typeName);
#endif
attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
attr.writeMask = UA_WRITEMASK_DISPLAYNAME | UA_WRITEMASK_DESCRIPTION;
attr.userWriteMask = UA_WRITEMASK_DISPLAYNAME | UA_WRITEMASK_DESCRIPTION;
/* add a scalar node for every built-in type */
attr.valueRank = UA_VALUERANK_SCALAR;
void *value = UA_new(&UA_TYPES[type]);
UA_Variant_setScalar(&attr.value, value, &UA_TYPES[type]);
UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id),
UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
qualifiedName, baseDataVariableType, attr, NULL, NULL);
UA_Variant_clear(&attr.value);
/* add an array node for every built-in type */
UA_UInt32 arrayDims = 0;
attr.valueRank = UA_VALUERANK_ONE_DIMENSION;
attr.arrayDimensions = &arrayDims;
attr.arrayDimensionsSize = 1;
UA_Variant_setArray(&attr.value, UA_Array_new(10, &UA_TYPES[type]), 10, &UA_TYPES[type]);
UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), UA_NODEID_NUMERIC(1, ARRAYID),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), qualifiedName,
baseDataVariableType, attr, NULL, NULL);
UA_Variant_clear(&attr.value);
/* add an matrix node for every built-in type */
attr.valueRank = UA_VALUERANK_TWO_DIMENSIONS;
attr.arrayDimensions = matrixDims;
attr.arrayDimensionsSize = 2;
void *myMultiArray = UA_Array_new(9, &UA_TYPES[type]);
attr.value.arrayDimensions = (UA_UInt32 *)UA_Array_new(2, &UA_TYPES[UA_TYPES_INT32]);
attr.value.arrayDimensions[0] = 3;
attr.value.arrayDimensions[1] = 3;
attr.value.arrayDimensionsSize = 2;
attr.value.arrayLength = 9;
attr.value.data = myMultiArray;
attr.value.type = &UA_TYPES[type];
UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), UA_NODEID_NUMERIC(1, MATRIXID),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), qualifiedName,
baseDataVariableType, attr, NULL, NULL);
UA_Variant_clear(&attr.value);
#ifdef UA_ENABLE_TYPEDESCRIPTION
UA_LocalizedText_clear(&attr.displayName);
UA_QualifiedName_clear(&qualifiedName);
#endif
}
/* Add Integer and UInteger variables */
UA_VariableAttributes iattr = UA_VariableAttributes_default;
iattr.dataType = UA_NODEID_NUMERIC(0, UA_NS0ID_INTEGER);
iattr.displayName = UA_LOCALIZEDTEXT("en-US", "Integer");
iattr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
iattr.writeMask = UA_WRITEMASK_DISPLAYNAME | UA_WRITEMASK_DESCRIPTION;
iattr.userWriteMask = UA_WRITEMASK_DISPLAYNAME | UA_WRITEMASK_DESCRIPTION;
iattr.valueRank = UA_VALUERANK_SCALAR;
UA_QualifiedName iQualifiedName = UA_QUALIFIEDNAME(1, "integer");
UA_Server_addVariableNode(server, UA_NODEID_STRING(1, "integer"),
UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
iQualifiedName, baseDataVariableType, iattr, NULL, NULL);
iattr.dataType = UA_NODEID_NUMERIC(0, UA_NS0ID_UINTEGER);
iattr.displayName = UA_LOCALIZEDTEXT("en-US", "UInteger");
UA_QualifiedName uQualifiedName = UA_QUALIFIEDNAME(1, "uinteger");
UA_Server_addVariableNode(server, UA_NODEID_STRING(1, "uinteger"),
UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
uQualifiedName, baseDataVariableType, iattr, NULL, NULL);
UA_Variant_clear(&iattr.value);
/* Hierarchy of depth 10 for CTT testing with forward and inverse references */
/* Enter node "depth 9" in CTT configuration - Project->Settings->Server
Test->NodeIds->Paths->Starting Node 1 */
object_attr.description = UA_LOCALIZEDTEXT("en-US", "DepthDemo");
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "DepthDemo");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, DEPTHID), UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_QUALIFIEDNAME(1, "DepthDemo"),
UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
id = DEPTHID; // running id in namespace 0 - Start with Matrix NODE
for(UA_UInt32 i = 1; i <= 20; i++) {
char name[15];
UA_snprintf(name, 15, "depth%u", i);
object_attr.description = UA_LOCALIZEDTEXT("en-US", name);
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, id + i),
UA_NODEID_NUMERIC(1, i == 1 ? DEPTHID : id + i - 1),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
UA_QUALIFIEDNAME(1, name),
UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
}
/* Scale Test: 100 nodes of each type */
int scale_i = 0;
UA_UInt32 scale_nodeid = 43000;
for(UA_UInt32 type = 0; type < 15; type++) {
if(type == UA_TYPES_SBYTE || type == UA_TYPES_BYTE
|| type == UA_TYPES_GUID)
continue;
UA_DataSource scaleTestDataSource;
scaleTestDataSource.read = NULL;
scaleTestDataSource.write = NULL;
UA_VariableAttributes attr = UA_VariableAttributes_default;
attr.dataType = UA_TYPES[type].typeId;
attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
attr.writeMask = UA_WRITEMASK_DISPLAYNAME | UA_WRITEMASK_DESCRIPTION;
attr.userWriteMask = UA_WRITEMASK_DISPLAYNAME | UA_WRITEMASK_DESCRIPTION;
attr.valueRank = UA_VALUERANK_SCALAR;
switch(UA_TYPES[type].typeKind) {
case UA_DATATYPEKIND_BOOLEAN: {
scaleTestDataSource.read = readRandomBoolData;
break;
}
case UA_DATATYPEKIND_INT16: {
scaleTestDataSource.read = readRandomInt16Data;
break;
}
case UA_DATATYPEKIND_UINT16: {
scaleTestDataSource.read = readRandomUInt16Data;
break;
}
case UA_DATATYPEKIND_INT32: {
scaleTestDataSource.read = readRandomInt32Data;
break;
}
case UA_DATATYPEKIND_UINT32: {
scaleTestDataSource.read = readRandomUInt32Data;
break;
}
case UA_DATATYPEKIND_INT64: {
scaleTestDataSource.read = readRandomInt64Data;
break;
}
case UA_DATATYPEKIND_UINT64: {
scaleTestDataSource.read = readRandomUInt64Data;
break;
}
case UA_DATATYPEKIND_STRING: {
scaleTestDataSource.read = readRandomStringData;
break;
}
case UA_DATATYPEKIND_FLOAT: {
scaleTestDataSource.read = readRandomFloatData;
break;
}
case UA_DATATYPEKIND_DOUBLE: {
scaleTestDataSource.read = readRandomDoubleData;
break;
}
case UA_DATATYPEKIND_DATETIME:
scaleTestDataSource.read = readTimeData;
break;
case UA_DATATYPEKIND_BYTESTRING:
scaleTestDataSource.read = readByteString;
break;
default:
break;
}
for(size_t j = 0; j < 100; j++) {
char name[32];
#ifndef UA_ENABLE_TYPEDESCRIPTION
UA_snprintf(name, 20, "%02d - %i", type, scale_i);
#else
UA_snprintf(name, 20, "%s - %i", UA_TYPES[type].typeName, scale_i);
#endif
attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
UA_QualifiedName qualifiedName = UA_QUALIFIEDNAME(1, name);
UA_Server_addDataSourceVariableNode(server, UA_NODEID_NUMERIC(1, ++scale_nodeid),
UA_NODEID_NUMERIC(1, SCALETESTID),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),qualifiedName,
baseDataVariableType, attr, scaleTestDataSource, NULL, NULL);
scale_i++;
}
UA_Variant_clear(&attr.value);
}
/* Add the variable to some more places to get a node with three inverse references for the CTT */
UA_ExpandedNodeId answer_nodeid = UA_EXPANDEDNODEID_STRING(1, "the.answer");
UA_Server_addReference(server, UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), answer_nodeid, true);
UA_Server_addReference(server, UA_NODEID_NUMERIC(1, SCALARID),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), answer_nodeid, true);
/* Example for manually setting an attribute within the server */
UA_LocalizedText objectsName = UA_LOCALIZEDTEXT("en-US", "Objects");
UA_Server_writeDisplayName(server, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), objectsName);
#define NOARGID 60000
#define INARGID 60001
#define OUTARGID 60002
#define INOUTARGID 60003
#ifdef UA_ENABLE_METHODCALLS
/* adding some more method nodes to pass CTT */
/* Method without arguments */
addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "noarg");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, NOARGID),
UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
UA_QUALIFIEDNAME(1, "noarg"), addmethodattributes,
&noargMethod, /* callback of the method node */
0, NULL, 0, NULL, NULL, NULL);
/* Method with in arguments */
addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "inarg");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
UA_Argument_init(&inputArguments);
inputArguments.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
inputArguments.description = UA_LOCALIZEDTEXT("en-US", "Input");
inputArguments.name = UA_STRING("Input");
inputArguments.valueRank = UA_VALUERANK_SCALAR; //uaexpert will crash if set to 0 ;)
UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, INARGID),
UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
UA_QUALIFIEDNAME(1, "noarg"), addmethodattributes,
&noargMethod, /* callback of the method node */
1, &inputArguments, 0, NULL, NULL, NULL);
/* Method with out arguments */
addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "outarg");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
UA_Argument_init(&outputArguments);
outputArguments.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
outputArguments.description = UA_LOCALIZEDTEXT("en-US", "Output");
outputArguments.name = UA_STRING("Output");
outputArguments.valueRank = UA_VALUERANK_SCALAR;
UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, OUTARGID),
UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
UA_QUALIFIEDNAME(1, "outarg"), addmethodattributes,
&outargMethod, /* callback of the method node */
0, NULL, 1, &outputArguments, NULL, NULL);
/* Method with inout arguments */
addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "inoutarg");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, INOUTARGID),
UA_NODEID_NUMERIC(1, DEMOID),
UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
UA_QUALIFIEDNAME(1, "inoutarg"), addmethodattributes,
&outargMethod, /* callback of the method node */
1, &inputArguments, 1, &outputArguments, NULL, NULL);
#endif
#ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
/* Create the reusable event instance */
UA_Server_createEvent(server, UA_NODEID_NUMERIC(0, UA_NS0ID_BASEEVENTTYPE), &eventId);
UA_UInt16 eventSeverity = 500;
UA_Server_writeObjectProperty_scalar(server, eventId,
UA_QUALIFIEDNAME(0, "Severity"),
&eventSeverity, &UA_TYPES[UA_TYPES_UINT16]);
/* Trigger the event from two variables */
UA_ValueCallback eventTriggerValueBackend;
eventTriggerValueBackend.onRead = NULL;
eventTriggerValueBackend.onWrite = writeEventTrigger;
UA_VariableAttributes_init(&myVar);
myVar.description = UA_LOCALIZEDTEXT("en-US", "event trigger 1");
myVar.displayName = UA_LOCALIZEDTEXT("en-US", "event trigger 1");
myVar.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
myVar.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
myVar.valueRank = UA_VALUERANK_SCALAR;
myInteger = 0;
UA_Variant_setScalar(&myVar.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
UA_Server_addVariableNode(server, UA_NODEID_STRING(1, "event-trigger-1"),
parentNodeId, parentReferenceNodeId,
UA_QUALIFIEDNAME(1, "event trigger 1"),
baseDataVariableType, myVar, NULL, NULL);
UA_Server_setVariableNode_valueCallback(server,
UA_NODEID_STRING(1, "event-trigger-1"),
eventTriggerValueBackend);
myVar.description = UA_LOCALIZEDTEXT("en-US", "event trigger 2");
myVar.displayName = UA_LOCALIZEDTEXT("en-US", "event trigger 2");
UA_Server_addVariableNode(server, UA_NODEID_STRING(1, "event-trigger-2"),
parentNodeId, parentReferenceNodeId,
UA_QUALIFIEDNAME(1, "event trigger 2"),
baseDataVariableType, myVar, NULL, NULL);
UA_Server_setVariableNode_valueCallback(server,
UA_NODEID_STRING(1, "event-trigger-2"),
eventTriggerValueBackend);
/* Auto-trigger the event every 500 ms */
UA_Server_addRepeatedCallback(server, cyclicEventTriger, NULL, 500.0, NULL);
#endif
}
static void
disableAnonymous(UA_ServerConfig *config) {
for(size_t i = 0; i < config->endpointsSize; i++) {
UA_EndpointDescription *ep = &config->endpoints[i];
for(size_t j = 0; j < ep->userIdentityTokensSize; j++) {
UA_UserTokenPolicy *utp = &ep->userIdentityTokens[j];
if(utp->tokenType != UA_USERTOKENTYPE_ANONYMOUS)
continue;
UA_UserTokenPolicy_clear(utp);
/* Move the last to this position */
if(j + 1 < ep->userIdentityTokensSize) {
ep->userIdentityTokens[j] = ep->userIdentityTokens[ep->userIdentityTokensSize-1];
j--;
}
ep->userIdentityTokensSize--;
}
/* Delete the entire array if the last UserTokenPolicy was removed */
if(ep->userIdentityTokensSize == 0) {
UA_free(ep->userIdentityTokens);
ep->userIdentityTokens = NULL;
}
}
}
#ifdef UA_ENABLE_ENCRYPTION
static void
disableUnencrypted(UA_ServerConfig *config) {
for(size_t i = 0; i < config->endpointsSize; i++) {
UA_EndpointDescription *ep = &config->endpoints[i];
if(ep->securityMode != UA_MESSAGESECURITYMODE_NONE)
continue;
UA_EndpointDescription_clear(ep);
/* Move the last to this position */
if(i + 1 < config->endpointsSize) {
config->endpoints[i] = config->endpoints[config->endpointsSize-1];
i--;
}
config->endpointsSize--;
}
/* Delete the entire array if the last Endpoint was removed */
if(config->endpointsSize== 0) {
UA_free(config->endpoints);
config->endpoints = NULL;
}
}
static void
disableOutdatedSecurityPolicy(UA_ServerConfig *config) {
for(size_t i = 0; i < config->endpointsSize; i++) {
UA_EndpointDescription *ep = &config->endpoints[i];
UA_ByteString basic128uri = UA_BYTESTRING("http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15");
UA_ByteString basic256uri = UA_BYTESTRING("http://opcfoundation.org/UA/SecurityPolicy#Basic256");
if(!UA_String_equal(&ep->securityPolicyUri, &basic128uri) &&
!UA_String_equal(&ep->securityPolicyUri, &basic256uri))
continue;
UA_EndpointDescription_clear(ep);
/* Move the last to this position */
if(i + 1 < config->endpointsSize) {
config->endpoints[i] = config->endpoints[config->endpointsSize-1];
i--;
}
config->endpointsSize--;
}
/* Delete the entire array if the last Endpoint was removed */
if(config->endpointsSize== 0) {
UA_free(config->endpoints);
config->endpoints = NULL;
}
}
static void
disableBasic128SecurityPolicy(UA_ServerConfig *config) {
for(size_t i = 0; i < config->endpointsSize; i++) {
UA_EndpointDescription *ep = &config->endpoints[i];
UA_ByteString basic128uri = UA_BYTESTRING("http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15");
if(!UA_String_equal(&ep->securityPolicyUri, &basic128uri))
continue;
UA_EndpointDescription_clear(ep);
/* Move the last to this position */
if(i + 1 < config->endpointsSize) {
config->endpoints[i] = config->endpoints[config->endpointsSize-1];
i--;
}
config->endpointsSize--;
}
/* Delete the entire array if the last Endpoint was removed */
if(config->endpointsSize== 0) {
UA_free(config->endpoints);
config->endpoints = NULL;
}
}
static void
disableBasic256SecurityPolicy(UA_ServerConfig *config) {
for(size_t i = 0; i < config->endpointsSize; i++) {
UA_EndpointDescription *ep = &config->endpoints[i];
UA_ByteString basic256uri = UA_BYTESTRING("http://opcfoundation.org/UA/SecurityPolicy#Basic256");
if(!UA_String_equal(&ep->securityPolicyUri, &basic256uri))
continue;
UA_EndpointDescription_clear(ep);
/* Move the last to this position */
if(i + 1 < config->endpointsSize) {
config->endpoints[i] = config->endpoints[config->endpointsSize-1];
i--;
}
config->endpointsSize--;
}
/* Delete the entire array if the last Endpoint was removed */
if(config->endpointsSize== 0) {
UA_free(config->endpoints);
config->endpoints = NULL;
}
}
static void
disableBasic256Sha256SecurityPolicy(UA_ServerConfig *config) {
for(size_t i = 0; i < config->endpointsSize; i++) {
UA_EndpointDescription *ep = &config->endpoints[i];
UA_ByteString basic256sha256uri = UA_BYTESTRING("http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256");
if(!UA_String_equal(&ep->securityPolicyUri, &basic256sha256uri))
continue;
UA_EndpointDescription_clear(ep);
/* Move the last to this position */
if(i + 1 < config->endpointsSize) {
config->endpoints[i] = config->endpoints[config->endpointsSize-1];
i--;
}
config->endpointsSize--;
}
/* Delete the entire array if the last Endpoint was removed */
if(config->endpointsSize== 0) {
UA_free(config->endpoints);
config->endpoints = NULL;
}
}
#endif
UA_Boolean running = true;
static void
stopHandler(int sign) {
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Received Ctrl-C");
running = 0;
}
static void
usage(void) {
UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
"Usage:\n"
#ifndef UA_ENABLE_ENCRYPTION
"server_ctt [<server-certificate.der>]\n"
#else
"server_ctt <server-certificate.der> <private-key.der>\n"
#ifndef __linux__
"\t[--trustlist <tl1.ctl> <tl2.ctl> ... ]\n"
"\t[--issuerlist <il1.der> <il2.der> ... ]\n"
"\t[--revocationlist <rv1.crl> <rv2.crl> ...]\n"
#else