ua_server.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. #include "ua_server.h"
  2. #include "ua_services_internal.h" // AddReferences
  3. #include "ua_namespace_0.h"
  4. #include "ua_securechannel_manager.h"
  5. #include "ua_session_manager.h"
  6. #include "ua_util.h"
  7. #include "ua_services.h"
  8. UA_Int32 UA_Server_deleteMembers(UA_Server *server) {
  9. UA_ApplicationDescription_deleteMembers(&server->description);
  10. UA_SecureChannelManager_delete(server->secureChannelManager);
  11. UA_SessionManager_delete(server->sessionManager);
  12. UA_NodeStore_delete(server->nodestore);
  13. UA_ByteString_deleteMembers(&server->serverCertificate);
  14. return UA_SUCCESS;
  15. }
  16. void UA_Server_init(UA_Server *server, UA_String *endpointUrl) {
  17. UA_ApplicationDescription_init(&server->description);
  18. UA_ByteString_init(&server->serverCertificate);
  19. #define MAXCHANNELCOUNT 100
  20. #define STARTCHANNELID 1
  21. #define TOKENLIFETIME 10000
  22. #define STARTTOKENID 1
  23. UA_SecureChannelManager_new(&server->secureChannelManager, MAXCHANNELCOUNT,
  24. TOKENLIFETIME, STARTCHANNELID, STARTTOKENID, endpointUrl);
  25. #define MAXSESSIONCOUNT 1000
  26. #define SESSIONLIFETIME 10000
  27. #define STARTSESSIONID 1
  28. UA_SessionManager_new(&server->sessionManager, MAXSESSIONCOUNT, SESSIONLIFETIME,
  29. STARTSESSIONID);
  30. UA_NodeStore_new(&server->nodestore);
  31. //ns0: C2UA_STRING("http://opcfoundation.org/UA/"));
  32. //ns1: C2UA_STRING("http://localhost:16664/open62541/"));
  33. /**************/
  34. /* References */
  35. /**************/
  36. // ReferenceType Ids
  37. UA_ExpandedNodeId RefTypeId_References; NS0EXPANDEDNODEID(RefTypeId_References, 31);
  38. UA_ExpandedNodeId RefTypeId_NonHierarchicalReferences; NS0EXPANDEDNODEID(RefTypeId_NonHierarchicalReferences, 32);
  39. UA_ExpandedNodeId RefTypeId_HierarchicalReferences; NS0EXPANDEDNODEID(RefTypeId_HierarchicalReferences, 33);
  40. UA_ExpandedNodeId RefTypeId_HasChild; NS0EXPANDEDNODEID(RefTypeId_HasChild, 34);
  41. UA_ExpandedNodeId RefTypeId_Organizes; NS0EXPANDEDNODEID(RefTypeId_Organizes, 35);
  42. UA_ExpandedNodeId RefTypeId_HasEventSource; NS0EXPANDEDNODEID(RefTypeId_HasEventSource, 36);
  43. UA_ExpandedNodeId RefTypeId_HasModellingRule; NS0EXPANDEDNODEID(RefTypeId_HasModellingRule, 37);
  44. UA_ExpandedNodeId RefTypeId_HasEncoding; NS0EXPANDEDNODEID(RefTypeId_HasEncoding, 38);
  45. UA_ExpandedNodeId RefTypeId_HasDescription; NS0EXPANDEDNODEID(RefTypeId_HasDescription, 39);
  46. UA_ExpandedNodeId RefTypeId_HasTypeDefinition; NS0EXPANDEDNODEID(RefTypeId_HasTypeDefinition, 40);
  47. UA_ExpandedNodeId RefTypeId_GeneratesEvent; NS0EXPANDEDNODEID(RefTypeId_GeneratesEvent, 41);
  48. UA_ExpandedNodeId RefTypeId_Aggregates; NS0EXPANDEDNODEID(RefTypeId_Aggregates, 44);
  49. UA_ExpandedNodeId RefTypeId_HasSubtype; NS0EXPANDEDNODEID(RefTypeId_HasSubtype, 45);
  50. UA_ExpandedNodeId RefTypeId_HasProperty; NS0EXPANDEDNODEID(RefTypeId_HasProperty, 46);
  51. UA_ExpandedNodeId RefTypeId_HasComponent; NS0EXPANDEDNODEID(RefTypeId_HasComponent, 47);
  52. UA_ExpandedNodeId RefTypeId_HasNotifier; NS0EXPANDEDNODEID(RefTypeId_HasNotifier, 48);
  53. UA_ExpandedNodeId RefTypeId_HasOrderedComponent; NS0EXPANDEDNODEID(RefTypeId_HasOrderedComponent, 49);
  54. UA_ExpandedNodeId RefTypeId_HasModelParent; NS0EXPANDEDNODEID(RefTypeId_HasModelParent, 50);
  55. UA_ExpandedNodeId RefTypeId_FromState; NS0EXPANDEDNODEID(RefTypeId_FromState, 51);
  56. UA_ExpandedNodeId RefTypeId_ToState; NS0EXPANDEDNODEID(RefTypeId_ToState, 52);
  57. UA_ExpandedNodeId RefTypeId_HasCause; NS0EXPANDEDNODEID(RefTypeId_HasCause, 53);
  58. UA_ExpandedNodeId RefTypeId_HasEffect; NS0EXPANDEDNODEID(RefTypeId_HasEffect, 54);
  59. UA_ExpandedNodeId RefTypeId_HasHistoricalConfiguration; NS0EXPANDEDNODEID(RefTypeId_HasHistoricalConfiguration, 56);
  60. #define ADDREFERENCE(NODE, REFTYPE, INVERSE, TARGET_NODEID) do { \
  61. static struct UA_ReferenceNode NODE##REFTYPE##TARGET_NODEID; \
  62. UA_ReferenceNode_init(&NODE##REFTYPE##TARGET_NODEID); \
  63. NODE##REFTYPE##TARGET_NODEID.referenceTypeId = REFTYPE.nodeId; \
  64. NODE##REFTYPE##TARGET_NODEID.isInverse = INVERSE; \
  65. NODE##REFTYPE##TARGET_NODEID.targetId = TARGET_NODEID; \
  66. AddReference(server->nodestore, (UA_Node *)NODE, &NODE##REFTYPE##TARGET_NODEID); \
  67. } while(0)
  68. UA_ReferenceTypeNode *references;
  69. UA_ReferenceTypeNode_new(&references);
  70. references->nodeId = RefTypeId_References.nodeId;
  71. references->nodeClass = UA_NODECLASS_REFERENCETYPE;
  72. UA_QualifiedName_copycstring("References", &references->browseName);
  73. UA_LocalizedText_copycstring("References", &references->displayName);
  74. UA_LocalizedText_copycstring("References", &references->description);
  75. references->isAbstract = UA_TRUE;
  76. references->symmetric = UA_TRUE;
  77. UA_NodeStore_insert(server->nodestore, (UA_Node**)&references, UA_NODESTORE_INSERT_UNIQUE);
  78. UA_ReferenceTypeNode *hierarchicalreferences;
  79. UA_ReferenceTypeNode_new(&hierarchicalreferences);
  80. hierarchicalreferences->nodeId = RefTypeId_HierarchicalReferences.nodeId;
  81. hierarchicalreferences->nodeClass = UA_NODECLASS_REFERENCETYPE;
  82. UA_QualifiedName_copycstring("HierarchicalReferences", &hierarchicalreferences->browseName);
  83. UA_LocalizedText_copycstring("HierarchicalReferences", &hierarchicalreferences->displayName);
  84. UA_LocalizedText_copycstring("HierarchicalReferences", &hierarchicalreferences->description);
  85. hierarchicalreferences->isAbstract = UA_TRUE;
  86. hierarchicalreferences->symmetric = UA_FALSE;
  87. ADDREFERENCE(hierarchicalreferences, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_References);
  88. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hierarchicalreferences, UA_NODESTORE_INSERT_UNIQUE);
  89. UA_ReferenceTypeNode *nonhierarchicalreferences;
  90. UA_ReferenceTypeNode_new(&nonhierarchicalreferences);
  91. nonhierarchicalreferences->nodeId = RefTypeId_NonHierarchicalReferences.nodeId;
  92. nonhierarchicalreferences->nodeClass = UA_NODECLASS_REFERENCETYPE;
  93. UA_QualifiedName_copycstring("NonHierarchicalReferences", &nonhierarchicalreferences->browseName);
  94. UA_LocalizedText_copycstring("NonHierarchicalReferences", &nonhierarchicalreferences->displayName);
  95. UA_LocalizedText_copycstring("NonHierarchicalReferences", &nonhierarchicalreferences->description);
  96. nonhierarchicalreferences->isAbstract = UA_TRUE;
  97. nonhierarchicalreferences->symmetric = UA_FALSE;
  98. ADDREFERENCE(nonhierarchicalreferences, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_References);
  99. UA_NodeStore_insert(server->nodestore, (UA_Node**)&nonhierarchicalreferences, UA_NODESTORE_INSERT_UNIQUE);
  100. UA_ReferenceTypeNode *haschild;
  101. UA_ReferenceTypeNode_new(&haschild);
  102. haschild->nodeId = RefTypeId_HasChild.nodeId;
  103. haschild->nodeClass = UA_NODECLASS_REFERENCETYPE;
  104. UA_QualifiedName_copycstring("HasChild", &haschild->browseName);
  105. UA_LocalizedText_copycstring("HasChild", &haschild->displayName);
  106. UA_LocalizedText_copycstring("HasChild", &haschild->description);
  107. haschild->isAbstract = UA_TRUE;
  108. haschild->symmetric = UA_FALSE;
  109. ADDREFERENCE(haschild, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_HierarchicalReferences);
  110. UA_NodeStore_insert(server->nodestore, (UA_Node**)&haschild, UA_NODESTORE_INSERT_UNIQUE);
  111. UA_ReferenceTypeNode *organizes;
  112. UA_ReferenceTypeNode_new(&organizes);
  113. organizes->nodeId = RefTypeId_Organizes.nodeId;
  114. organizes->nodeClass = UA_NODECLASS_REFERENCETYPE;
  115. UA_QualifiedName_copycstring("Organizes", &organizes->browseName);
  116. UA_LocalizedText_copycstring("Organizes", &organizes->displayName);
  117. UA_LocalizedText_copycstring("Organizes", &organizes->description);
  118. organizes->isAbstract = UA_FALSE;
  119. organizes->symmetric = UA_FALSE;
  120. UA_LocalizedText_copycstring("OrganizedBy", &organizes->inverseName);
  121. ADDREFERENCE(organizes, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_HierarchicalReferences);
  122. UA_NodeStore_insert(server->nodestore, (UA_Node**)&organizes, UA_NODESTORE_INSERT_UNIQUE);
  123. UA_ReferenceTypeNode *haseventsource;
  124. UA_ReferenceTypeNode_new(&haseventsource);
  125. haseventsource->nodeId = RefTypeId_HasEventSource.nodeId;
  126. haseventsource->nodeClass = UA_NODECLASS_REFERENCETYPE;
  127. UA_QualifiedName_copycstring("HasEventSource", &haseventsource->browseName);
  128. UA_LocalizedText_copycstring("HasEventSource", &haseventsource->displayName);
  129. UA_LocalizedText_copycstring("HasEventSource", &haseventsource->description);
  130. haseventsource->isAbstract = UA_FALSE;
  131. haseventsource->symmetric = UA_FALSE;
  132. UA_LocalizedText_copycstring("EventSourceOf", &haseventsource->inverseName);
  133. ADDREFERENCE(haseventsource, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_HierarchicalReferences);
  134. UA_NodeStore_insert(server->nodestore, (UA_Node**)&haseventsource, UA_NODESTORE_INSERT_UNIQUE);
  135. UA_ReferenceTypeNode *hasmodellingrule;
  136. UA_ReferenceTypeNode_new(&hasmodellingrule);
  137. hasmodellingrule->nodeId = RefTypeId_HasModellingRule.nodeId;
  138. hasmodellingrule->nodeClass = UA_NODECLASS_REFERENCETYPE;
  139. UA_QualifiedName_copycstring("HasModellingRule", &hasmodellingrule->browseName);
  140. UA_LocalizedText_copycstring("HasModellingRule", &hasmodellingrule->displayName);
  141. UA_LocalizedText_copycstring("HasModellingRule", &hasmodellingrule->description);
  142. hasmodellingrule->isAbstract = UA_FALSE;
  143. hasmodellingrule->symmetric = UA_FALSE;
  144. UA_LocalizedText_copycstring("ModellingRuleOf", &hasmodellingrule->inverseName);
  145. ADDREFERENCE(hasmodellingrule, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  146. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hasmodellingrule, UA_NODESTORE_INSERT_UNIQUE);
  147. UA_ReferenceTypeNode *hasencoding;
  148. UA_ReferenceTypeNode_new(&hasencoding);
  149. hasencoding->nodeId = RefTypeId_HasEncoding.nodeId;
  150. hasencoding->nodeClass = UA_NODECLASS_REFERENCETYPE;
  151. UA_QualifiedName_copycstring("HasEncoding", &hasencoding->browseName);
  152. UA_LocalizedText_copycstring("HasEncoding", &hasencoding->displayName);
  153. UA_LocalizedText_copycstring("HasEncoding", &hasencoding->description);
  154. hasencoding->isAbstract = UA_FALSE;
  155. hasencoding->symmetric = UA_FALSE;
  156. UA_LocalizedText_copycstring("EncodingOf", &hasencoding->inverseName);
  157. ADDREFERENCE(hasencoding, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  158. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hasencoding, UA_NODESTORE_INSERT_UNIQUE);
  159. UA_ReferenceTypeNode *hasdescription;
  160. UA_ReferenceTypeNode_new(&hasdescription);
  161. hasdescription->nodeId = RefTypeId_HasDescription.nodeId;
  162. hasdescription->nodeClass = UA_NODECLASS_REFERENCETYPE;
  163. UA_QualifiedName_copycstring("HasDescription", &hasdescription->browseName);
  164. UA_LocalizedText_copycstring("HasDescription", &hasdescription->displayName);
  165. UA_LocalizedText_copycstring("HasDescription", &hasdescription->description);
  166. hasdescription->isAbstract = UA_FALSE;
  167. hasdescription->symmetric = UA_FALSE;
  168. UA_LocalizedText_copycstring("DescriptionOf", &hasdescription->inverseName);
  169. ADDREFERENCE(hasdescription, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  170. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hasdescription, UA_NODESTORE_INSERT_UNIQUE);
  171. UA_ReferenceTypeNode *hastypedefinition;
  172. UA_ReferenceTypeNode_new(&hastypedefinition);
  173. hastypedefinition->nodeId = RefTypeId_HasTypeDefinition.nodeId;
  174. hastypedefinition->nodeClass = UA_NODECLASS_REFERENCETYPE;
  175. UA_QualifiedName_copycstring("HasTypeDefinition", &hastypedefinition->browseName);
  176. UA_LocalizedText_copycstring("HasTypeDefinition", &hastypedefinition->displayName);
  177. UA_LocalizedText_copycstring("HasTypeDefinition", &hastypedefinition->description);
  178. hastypedefinition->isAbstract = UA_FALSE;
  179. hastypedefinition->symmetric = UA_FALSE;
  180. UA_LocalizedText_copycstring("TypeDefinitionOf", &hastypedefinition->inverseName);
  181. ADDREFERENCE(hastypedefinition, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  182. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hastypedefinition, UA_NODESTORE_INSERT_UNIQUE);
  183. UA_ReferenceTypeNode *generatesevent;
  184. UA_ReferenceTypeNode_new(&generatesevent);
  185. generatesevent->nodeId = RefTypeId_GeneratesEvent.nodeId;
  186. generatesevent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  187. UA_QualifiedName_copycstring("GeneratesEvent", &generatesevent->browseName);
  188. UA_LocalizedText_copycstring("GeneratesEvent", &generatesevent->displayName);
  189. UA_LocalizedText_copycstring("GeneratesEvent", &generatesevent->description);
  190. generatesevent->isAbstract = UA_FALSE;
  191. generatesevent->symmetric = UA_FALSE;
  192. UA_LocalizedText_copycstring("GeneratedBy", &generatesevent->inverseName);
  193. ADDREFERENCE(generatesevent, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  194. UA_NodeStore_insert(server->nodestore, (UA_Node**)&generatesevent, UA_NODESTORE_INSERT_UNIQUE);
  195. UA_ReferenceTypeNode *aggregates;
  196. UA_ReferenceTypeNode_new(&aggregates);
  197. aggregates->nodeId = RefTypeId_Aggregates.nodeId;
  198. aggregates->nodeClass = UA_NODECLASS_REFERENCETYPE;
  199. UA_QualifiedName_copycstring("Aggregates", &aggregates->browseName);
  200. UA_LocalizedText_copycstring("Aggregates", &aggregates->displayName);
  201. UA_LocalizedText_copycstring("Aggregates", &aggregates->description);
  202. aggregates->isAbstract = UA_TRUE;
  203. aggregates->symmetric = UA_FALSE;
  204. ADDREFERENCE(aggregates, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_HasChild);
  205. UA_NodeStore_insert(server->nodestore, (UA_Node**)&aggregates, UA_NODESTORE_INSERT_UNIQUE);
  206. UA_ReferenceTypeNode *hassubtype;
  207. UA_ReferenceTypeNode_new(&hassubtype);
  208. hassubtype->nodeId = RefTypeId_HasSubtype.nodeId;
  209. hassubtype->nodeClass = UA_NODECLASS_REFERENCETYPE;
  210. UA_QualifiedName_copycstring("HasSubtype", &hassubtype->browseName);
  211. UA_LocalizedText_copycstring("HasSubtype", &hassubtype->displayName);
  212. UA_LocalizedText_copycstring("HasSubtype", &hassubtype->description);
  213. hassubtype->isAbstract = UA_FALSE;
  214. hassubtype->symmetric = UA_FALSE;
  215. UA_LocalizedText_copycstring("SubtypeOf", &hassubtype->inverseName);
  216. ADDREFERENCE(hassubtype, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_HasChild);
  217. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hassubtype, UA_NODESTORE_INSERT_UNIQUE);
  218. UA_ReferenceTypeNode *hasproperty;
  219. UA_ReferenceTypeNode_new(&hasproperty);
  220. hasproperty->nodeId = RefTypeId_HasProperty.nodeId;
  221. hasproperty->nodeClass = UA_NODECLASS_REFERENCETYPE;
  222. UA_QualifiedName_copycstring("HasProperty", &hasproperty->browseName);
  223. UA_LocalizedText_copycstring("HasProperty", &hasproperty->displayName);
  224. UA_LocalizedText_copycstring("HasProperty", &hasproperty->description);
  225. hasproperty->isAbstract = UA_FALSE;
  226. hasproperty->symmetric = UA_FALSE;
  227. UA_LocalizedText_copycstring("PropertyOf", &hasproperty->inverseName);
  228. ADDREFERENCE(hasproperty, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_Aggregates);
  229. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hasproperty, UA_NODESTORE_INSERT_UNIQUE);
  230. UA_ReferenceTypeNode *hascomponent;
  231. UA_ReferenceTypeNode_new(&hascomponent);
  232. hascomponent->nodeId = RefTypeId_HasComponent.nodeId;
  233. hascomponent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  234. UA_QualifiedName_copycstring("HasComponent", &hascomponent->browseName);
  235. UA_LocalizedText_copycstring("HasComponent", &hascomponent->displayName);
  236. UA_LocalizedText_copycstring("HasComponent", &hascomponent->description);
  237. hascomponent->isAbstract = UA_FALSE;
  238. hascomponent->symmetric = UA_FALSE;
  239. UA_LocalizedText_copycstring("ComponentOf", &hascomponent->inverseName);
  240. ADDREFERENCE(hascomponent, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_Aggregates);
  241. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hascomponent, UA_NODESTORE_INSERT_UNIQUE);
  242. UA_ReferenceTypeNode *hasnotifier;
  243. UA_ReferenceTypeNode_new(&hasnotifier);
  244. hasnotifier->nodeId = RefTypeId_HasNotifier.nodeId;
  245. hasnotifier->nodeClass = UA_NODECLASS_REFERENCETYPE;
  246. UA_QualifiedName_copycstring("HasNotifier", &hasnotifier->browseName);
  247. UA_LocalizedText_copycstring("HasNotifier", &hasnotifier->displayName);
  248. UA_LocalizedText_copycstring("HasNotifier", &hasnotifier->description);
  249. hasnotifier->isAbstract = UA_FALSE;
  250. hasnotifier->symmetric = UA_FALSE;
  251. UA_LocalizedText_copycstring("NotifierOf", &hasnotifier->inverseName);
  252. ADDREFERENCE(hasnotifier, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_HasEventSource);
  253. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hasnotifier, UA_NODESTORE_INSERT_UNIQUE);
  254. UA_ReferenceTypeNode *hasorderedcomponent;
  255. UA_ReferenceTypeNode_new(&hasorderedcomponent);
  256. hasorderedcomponent->nodeId = RefTypeId_HasOrderedComponent.nodeId;
  257. hasorderedcomponent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  258. UA_QualifiedName_copycstring("HasOrderedComponent", &hasorderedcomponent->browseName);
  259. UA_LocalizedText_copycstring("HasOrderedComponent", &hasorderedcomponent->displayName);
  260. UA_LocalizedText_copycstring("HasOrderedComponent", &hasorderedcomponent->description);
  261. hasorderedcomponent->isAbstract = UA_FALSE;
  262. hasorderedcomponent->symmetric = UA_FALSE;
  263. UA_LocalizedText_copycstring("OrderedComponentOf", &hasorderedcomponent->inverseName);
  264. ADDREFERENCE(hasorderedcomponent, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_HasComponent);
  265. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hasorderedcomponent, UA_NODESTORE_INSERT_UNIQUE);
  266. UA_ReferenceTypeNode *hasmodelparent;
  267. UA_ReferenceTypeNode_new(&hasmodelparent);
  268. hasmodelparent->nodeId = RefTypeId_HasModelParent.nodeId;
  269. hasmodelparent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  270. UA_QualifiedName_copycstring("HasModelParent", &hasmodelparent->browseName);
  271. UA_LocalizedText_copycstring("HasModelParent", &hasmodelparent->displayName);
  272. UA_LocalizedText_copycstring("HasModelParent", &hasmodelparent->description);
  273. hasmodelparent->isAbstract = UA_FALSE;
  274. hasmodelparent->symmetric = UA_FALSE;
  275. UA_LocalizedText_copycstring("ModelParentOf", &hasmodelparent->inverseName);
  276. ADDREFERENCE(hasmodelparent, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  277. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hasmodelparent, UA_NODESTORE_INSERT_UNIQUE);
  278. UA_ReferenceTypeNode *fromstate;
  279. UA_ReferenceTypeNode_new(&fromstate);
  280. fromstate->nodeId = RefTypeId_FromState.nodeId;
  281. fromstate->nodeClass = UA_NODECLASS_REFERENCETYPE;
  282. UA_QualifiedName_copycstring("FromState", &fromstate->browseName);
  283. UA_LocalizedText_copycstring("FromState", &fromstate->displayName);
  284. UA_LocalizedText_copycstring("FromState", &fromstate->description);
  285. fromstate->isAbstract = UA_FALSE;
  286. fromstate->symmetric = UA_FALSE;
  287. UA_LocalizedText_copycstring("ToTransition", &fromstate->inverseName);
  288. ADDREFERENCE(fromstate, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  289. UA_NodeStore_insert(server->nodestore, (UA_Node**)&fromstate, UA_NODESTORE_INSERT_UNIQUE);
  290. UA_ReferenceTypeNode *tostate;
  291. UA_ReferenceTypeNode_new(&tostate);
  292. tostate->nodeId = RefTypeId_ToState.nodeId;
  293. tostate->nodeClass = UA_NODECLASS_REFERENCETYPE;
  294. UA_QualifiedName_copycstring("ToState", &tostate->browseName);
  295. UA_LocalizedText_copycstring("ToState", &tostate->displayName);
  296. UA_LocalizedText_copycstring("ToState", &tostate->description);
  297. tostate->isAbstract = UA_FALSE;
  298. tostate->symmetric = UA_FALSE;
  299. UA_LocalizedText_copycstring("FromTransition", &tostate->inverseName);
  300. ADDREFERENCE(tostate, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  301. UA_NodeStore_insert(server->nodestore, (UA_Node**)&tostate, UA_NODESTORE_INSERT_UNIQUE);
  302. UA_ReferenceTypeNode *hascause;
  303. UA_ReferenceTypeNode_new(&hascause);
  304. hascause->nodeId = RefTypeId_HasCause.nodeId;
  305. hascause->nodeClass = UA_NODECLASS_REFERENCETYPE;
  306. UA_QualifiedName_copycstring("HasCause", &hascause->browseName);
  307. UA_LocalizedText_copycstring("HasCause", &hascause->displayName);
  308. UA_LocalizedText_copycstring("HasCause", &hascause->description);
  309. hascause->isAbstract = UA_FALSE;
  310. hascause->symmetric = UA_FALSE;
  311. UA_LocalizedText_copycstring("MayBeCausedBy", &hascause->inverseName);
  312. ADDREFERENCE(hascause, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  313. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hascause, UA_NODESTORE_INSERT_UNIQUE);
  314. UA_ReferenceTypeNode *haseffect;
  315. UA_ReferenceTypeNode_new(&haseffect);
  316. haseffect->nodeId = RefTypeId_HasEffect.nodeId;
  317. haseffect->nodeClass = UA_NODECLASS_REFERENCETYPE;
  318. UA_QualifiedName_copycstring("HasEffect", &haseffect->browseName);
  319. UA_LocalizedText_copycstring("HasEffect", &haseffect->displayName);
  320. UA_LocalizedText_copycstring("HasEffect", &haseffect->description);
  321. haseffect->isAbstract = UA_FALSE;
  322. haseffect->symmetric = UA_FALSE;
  323. UA_LocalizedText_copycstring("MayBeEffectedBy", &haseffect->inverseName);
  324. ADDREFERENCE(haseffect, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_NonHierarchicalReferences);
  325. UA_NodeStore_insert(server->nodestore, (UA_Node**)&haseffect, UA_NODESTORE_INSERT_UNIQUE);
  326. UA_ReferenceTypeNode *hashistoricalconfiguration;
  327. UA_ReferenceTypeNode_new(&hashistoricalconfiguration);
  328. hashistoricalconfiguration->nodeId = RefTypeId_HasHistoricalConfiguration.nodeId;
  329. hashistoricalconfiguration->nodeClass = UA_NODECLASS_REFERENCETYPE;
  330. UA_QualifiedName_copycstring("HasHistoricalConfiguration", &hashistoricalconfiguration->browseName);
  331. UA_LocalizedText_copycstring("HasHistoricalConfiguration", &hashistoricalconfiguration->displayName);
  332. UA_LocalizedText_copycstring("HasHistoricalConfiguration", &hashistoricalconfiguration->description);
  333. hashistoricalconfiguration->isAbstract = UA_FALSE;
  334. hashistoricalconfiguration->symmetric = UA_FALSE;
  335. UA_LocalizedText_copycstring("HistoricalConfigurationOf", &hashistoricalconfiguration->inverseName);
  336. ADDREFERENCE(hashistoricalconfiguration, RefTypeId_HasSubtype, UA_TRUE, RefTypeId_Aggregates);
  337. UA_NodeStore_insert(server->nodestore, (UA_Node**)&hashistoricalconfiguration, UA_NODESTORE_INSERT_UNIQUE);
  338. // ObjectTypes (Ids only)
  339. UA_ExpandedNodeId ObjTypeId_FolderType; NS0EXPANDEDNODEID(ObjTypeId_FolderType, 61);
  340. // Objects (Ids only)
  341. UA_ExpandedNodeId ObjId_ObjectsFolder; NS0EXPANDEDNODEID(ObjId_ObjectsFolder, 85);
  342. UA_ExpandedNodeId ObjId_TypesFolder; NS0EXPANDEDNODEID(ObjId_TypesFolder, 86);
  343. UA_ExpandedNodeId ObjId_ViewsFolder; NS0EXPANDEDNODEID(ObjId_ViewsFolder, 87);
  344. UA_ExpandedNodeId ObjId_Server; NS0EXPANDEDNODEID(ObjId_Server, 2253);
  345. UA_ExpandedNodeId ObjId_ServerArray; NS0EXPANDEDNODEID(ObjId_ServerArray, 2254);
  346. UA_ExpandedNodeId ObjId_NamespaceArray; NS0EXPANDEDNODEID(ObjId_NamespaceArray, 2255);
  347. UA_ExpandedNodeId ObjId_ServerStatus; NS0EXPANDEDNODEID(ObjId_ServerStatus, 2256);
  348. UA_ExpandedNodeId ObjId_ServerCapabilities; NS0EXPANDEDNODEID(ObjId_ServerCapabilities, 2268);
  349. UA_ExpandedNodeId ObjId_State; NS0EXPANDEDNODEID(ObjId_State, 2259);
  350. // FolderType
  351. UA_ObjectNode *folderType;
  352. UA_ObjectNode_new(&folderType);
  353. folderType->nodeId = NS0NODEID(61);
  354. folderType->nodeClass = UA_NODECLASS_OBJECTTYPE; // I should not have to set this manually
  355. UA_QualifiedName_copycstring("FolderType", &folderType->browseName);
  356. UA_LocalizedText_copycstring("FolderType", &folderType->displayName);
  357. UA_LocalizedText_copycstring("FolderType", &folderType->description);
  358. UA_NodeStore_insert(server->nodestore, (UA_Node**)&folderType, UA_NODESTORE_INSERT_UNIQUE);
  359. // Root
  360. UA_ObjectNode *root;
  361. UA_ObjectNode_new(&root);
  362. root->nodeId = NS0NODEID(84);
  363. root->nodeClass = UA_NODECLASS_OBJECT; // I should not have to set this manually
  364. UA_QualifiedName_copycstring("Root", &root->browseName);
  365. UA_LocalizedText_copycstring("Root", &root->displayName);
  366. UA_LocalizedText_copycstring("Root", &root->description);
  367. ADDREFERENCE(root, RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType);
  368. ADDREFERENCE(root, RefTypeId_Organizes, UA_FALSE, ObjId_ObjectsFolder);
  369. ADDREFERENCE(root, RefTypeId_Organizes, UA_FALSE, ObjId_TypesFolder);
  370. ADDREFERENCE(root, RefTypeId_Organizes, UA_FALSE, ObjId_ViewsFolder);
  371. /* root becomes a managed node. we need to release it at the end.*/
  372. UA_NodeStore_insert(server->nodestore, (UA_Node**)&root, UA_NODESTORE_INSERT_UNIQUE | UA_NODESTORE_INSERT_GETMANAGED);
  373. // Objects
  374. UA_ObjectNode *objects;
  375. UA_ObjectNode_new(&objects);
  376. objects->nodeId = ObjId_ObjectsFolder.nodeId;
  377. objects->nodeClass = UA_NODECLASS_OBJECT;
  378. UA_QualifiedName_copycstring("Objects", &objects->browseName);
  379. UA_LocalizedText_copycstring("Objects", &objects->displayName);
  380. UA_LocalizedText_copycstring("Objects", &objects->description);
  381. ADDREFERENCE(objects, RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType);
  382. ADDREFERENCE(objects, RefTypeId_Organizes, UA_FALSE, ObjId_Server);
  383. UA_NodeStore_insert(server->nodestore, (UA_Node**)&objects, UA_NODESTORE_INSERT_UNIQUE);
  384. // Types
  385. UA_ObjectNode *types;
  386. UA_ObjectNode_new(&types);
  387. types->nodeId = ObjId_TypesFolder.nodeId;
  388. types->nodeClass = UA_NODECLASS_OBJECT;
  389. UA_QualifiedName_copycstring("Types", &types->browseName);
  390. UA_LocalizedText_copycstring("Types", &types->displayName);
  391. UA_LocalizedText_copycstring("Types", &types->description);
  392. ADDREFERENCE(types, RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType);
  393. UA_NodeStore_insert(server->nodestore, (UA_Node**)&types, UA_NODESTORE_INSERT_UNIQUE);
  394. // Views
  395. UA_ObjectNode *views;
  396. UA_ObjectNode_new(&views);
  397. views->nodeId = ObjId_ViewsFolder.nodeId;
  398. views->nodeClass = UA_NODECLASS_OBJECT;
  399. UA_QualifiedName_copycstring("Views", &views->browseName);
  400. UA_LocalizedText_copycstring("Views", &views->displayName);
  401. UA_LocalizedText_copycstring("Views", &views->description);
  402. ADDREFERENCE(views, RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType);
  403. UA_NodeStore_insert(server->nodestore, (UA_Node**)&views, UA_NODESTORE_INSERT_UNIQUE);
  404. // Server
  405. UA_ObjectNode *servernode;
  406. UA_ObjectNode_new(&servernode);
  407. servernode->nodeId = ObjId_Server.nodeId;
  408. servernode->nodeClass = UA_NODECLASS_OBJECT;
  409. UA_QualifiedName_copycstring("Server", &servernode->browseName);
  410. UA_LocalizedText_copycstring("Server", &servernode->displayName);
  411. UA_LocalizedText_copycstring("Server", &servernode->description);
  412. ADDREFERENCE(servernode, RefTypeId_HasComponent, UA_FALSE, ObjId_ServerCapabilities);
  413. ADDREFERENCE(servernode, RefTypeId_HasComponent, UA_FALSE, ObjId_NamespaceArray);
  414. ADDREFERENCE(servernode, RefTypeId_HasProperty, UA_FALSE, ObjId_ServerStatus);
  415. ADDREFERENCE(servernode, RefTypeId_HasProperty, UA_FALSE, ObjId_ServerArray);
  416. UA_NodeStore_insert(server->nodestore, (UA_Node**)&servernode, UA_NODESTORE_INSERT_UNIQUE);
  417. // NamespaceArray
  418. UA_VariableNode *namespaceArray;
  419. UA_VariableNode_new(&namespaceArray);
  420. namespaceArray->nodeId = ObjId_NamespaceArray.nodeId;
  421. namespaceArray->nodeClass = UA_NODECLASS_VARIABLE; //FIXME: this should go into _new?
  422. UA_QualifiedName_copycstring("NodeStoreArray", &namespaceArray->browseName);
  423. UA_LocalizedText_copycstring("NodeStoreArray", &namespaceArray->displayName);
  424. UA_LocalizedText_copycstring("NodeStoreArray", &namespaceArray->description);
  425. UA_Array_new((void **)&namespaceArray->value.storage.data.dataPtr, 2, &UA_[UA_STRING]);
  426. namespaceArray->value.vt = &UA_[UA_STRING];
  427. namespaceArray->value.storage.data.arrayLength = 2;
  428. UA_String_copycstring("http://opcfoundation.org/UA/", &((UA_String *)(namespaceArray->value.storage.data.dataPtr))[0]);
  429. UA_String_copycstring("http://localhost:16664/open62541/", &((UA_String *)(namespaceArray->value.storage.data.dataPtr))[1]);
  430. namespaceArray->arrayDimensionsSize = 1;
  431. UA_UInt32 *dimensions = UA_NULL;
  432. UA_alloc((void **)&dimensions, sizeof(UA_UInt32));
  433. *dimensions = 2;
  434. namespaceArray->arrayDimensions = dimensions;
  435. namespaceArray->dataType = NS0NODEID(UA_STRING_NS0);
  436. namespaceArray->valueRank = 1;
  437. namespaceArray->minimumSamplingInterval = 1.0;
  438. namespaceArray->historizing = UA_FALSE;
  439. UA_NodeStore_insert(server->nodestore, (UA_Node**)&namespaceArray, UA_NODESTORE_INSERT_UNIQUE);
  440. // ServerStatus
  441. UA_VariableNode *serverstatus;
  442. UA_VariableNode_new(&serverstatus);
  443. serverstatus->nodeId = ObjId_ServerStatus.nodeId;
  444. serverstatus->nodeClass = UA_NODECLASS_VARIABLE;
  445. UA_QualifiedName_copycstring("ServerStatus", &serverstatus->browseName);
  446. UA_LocalizedText_copycstring("ServerStatus", &serverstatus->displayName);
  447. UA_LocalizedText_copycstring("ServerStatus", &serverstatus->description);
  448. UA_ServerStatusDataType *status;
  449. UA_ServerStatusDataType_new(&status);
  450. status->startTime = UA_DateTime_now();
  451. status->currentTime = UA_DateTime_now();
  452. status->state = UA_SERVERSTATE_RUNNING;
  453. UA_String_copycstring("open62541.org", &status->buildInfo.productUri);
  454. UA_String_copycstring("open62541", &status->buildInfo.manufacturerName);
  455. UA_String_copycstring("open62541", &status->buildInfo.productName);
  456. UA_String_copycstring("0.0", &status->buildInfo.softwareVersion);
  457. UA_String_copycstring("0.0", &status->buildInfo.buildNumber);
  458. status->buildInfo.buildDate = UA_DateTime_now();
  459. status->secondsTillShutdown = 99999999;
  460. UA_LocalizedText_copycstring("because", &status->shutdownReason);
  461. serverstatus->value.vt = &UA_[UA_SERVERSTATUSDATATYPE]; // gets encoded as an extensionobject
  462. serverstatus->value.storage.data.arrayLength = 1;
  463. serverstatus->value.storage.data.dataPtr = status;
  464. UA_NodeStore_insert(server->nodestore, (UA_Node**)&serverstatus, UA_NODESTORE_INSERT_UNIQUE);
  465. // State (Component of ServerStatus)
  466. UA_VariableNode *state;
  467. UA_VariableNode_new(&state);
  468. state->nodeId = ObjId_State.nodeId;
  469. state->nodeClass = UA_NODECLASS_VARIABLE;
  470. UA_QualifiedName_copycstring("State", &state->browseName);
  471. UA_LocalizedText_copycstring("State", &state->displayName);
  472. UA_LocalizedText_copycstring("State", &state->description);
  473. state->value.vt = &UA_[UA_SERVERSTATE];
  474. state->value.storage.data.arrayDimensionsLength = 1; // added to ensure encoding in readreponse
  475. state->value.storage.data.arrayLength = 1;
  476. state->value.storage.data.dataPtr = &status->state; // points into the other object.
  477. state->value.storageType = UA_VARIANT_DATA_NODELETE;
  478. UA_NodeStore_insert(server->nodestore, (UA_Node**)&state, UA_NODESTORE_INSERT_UNIQUE);
  479. UA_NodeStore_releaseManagedNode((const UA_Node *)root);
  480. }
  481. UA_AddNodesResult UA_Server_addNode(UA_Server *server, UA_Node **node, UA_ExpandedNodeId *parentNodeId,
  482. UA_NodeId *referenceTypeId) {
  483. return AddNode(server, &adminSession, node, parentNodeId, referenceTypeId);
  484. }
  485. void UA_Server_addReference(UA_Server *server, const UA_AddReferencesRequest *request,
  486. UA_AddReferencesResponse *response) {
  487. Service_AddReferences(server, &adminSession, request, response);
  488. }