ua_server.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. #ifdef UA_MULTITHREADING
  2. #define _LGPL_SOURCE
  3. #include <urcu.h>
  4. #endif
  5. #include "ua_types.h"
  6. #include "ua_server_internal.h"
  7. #include "ua_securechannel_manager.h"
  8. #include "ua_session_manager.h"
  9. #include "ua_util.h"
  10. #include "ua_services.h"
  11. #include "ua_nodeids.h"
  12. /**********************/
  13. /* Namespace Handling */
  14. /**********************/
  15. static void UA_ExternalNamespace_init(UA_ExternalNamespace *ens) {
  16. ens->index = 0;
  17. UA_String_init(&ens->url);
  18. }
  19. static void UA_ExternalNamespace_deleteMembers(UA_ExternalNamespace *ens) {
  20. UA_String_deleteMembers(&ens->url);
  21. ens->externalNodeStore.destroy(ens->externalNodeStore.ensHandle);
  22. }
  23. /*****************/
  24. /* Configuration */
  25. /*****************/
  26. void UA_Server_addNetworkLayer(UA_Server *server, UA_ServerNetworkLayer networkLayer) {
  27. server->nls = UA_realloc(server->nls, sizeof(UA_ServerNetworkLayer)*(server->nlsSize+1));
  28. server->nls[server->nlsSize] = networkLayer;
  29. server->nlsSize++;
  30. }
  31. void UA_Server_setServerCertificate(UA_Server *server, UA_ByteString certificate) {
  32. UA_ByteString_copy(&certificate, &server->serverCertificate);
  33. }
  34. /**********/
  35. /* Server */
  36. /**********/
  37. void UA_Server_delete(UA_Server *server) {
  38. // The server needs to be stopped before it can be deleted
  39. // Delete the network layers
  40. for(UA_Int32 i=0;i<server->nlsSize;i++) {
  41. server->nls[i].free(server->nls[i].nlHandle);
  42. }
  43. UA_free(server->nls);
  44. // Delete the timed work
  45. UA_Server_deleteTimedWork(server);
  46. // Delete all internal data
  47. UA_ApplicationDescription_deleteMembers(&server->description);
  48. UA_SecureChannelManager_deleteMembers(&server->secureChannelManager);
  49. UA_SessionManager_deleteMembers(&server->sessionManager);
  50. UA_NodeStore_delete(server->nodestore);
  51. UA_ByteString_deleteMembers(&server->serverCertificate);
  52. UA_Array_delete(server->endpointDescriptions, server->endpointDescriptionsSize,
  53. &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
  54. #ifdef UA_MULTITHREADING
  55. pthread_cond_destroy(&server->dispatchQueue_condition); // so the workers don't spin if the queue is empty
  56. rcu_barrier(); // wait for all scheduled call_rcu work to complete
  57. #endif
  58. UA_free(server);
  59. }
  60. UA_Server * UA_Server_new(void) {
  61. UA_Server *server = UA_malloc(sizeof(UA_Server));
  62. if(!server)
  63. return UA_NULL;
  64. LIST_INIT(&server->timedWork);
  65. #ifdef UA_MULTITHREADING
  66. rcu_init();
  67. cds_wfcq_init(&server->dispatchQueue_head, &server->dispatchQueue_tail);
  68. server->delayedWork = UA_NULL;
  69. #endif
  70. // random seed
  71. server->random_seed = (UA_UInt32) UA_DateTime_now();
  72. // networklayers
  73. server->nls = UA_NULL;
  74. server->nlsSize = 0;
  75. UA_ByteString_init(&server->serverCertificate);
  76. // mockup application description
  77. UA_ApplicationDescription_init(&server->description);
  78. UA_String_copycstring("urn:unconfigured:open62541:application", &server->description.productUri);
  79. UA_String_copycstring("http://unconfigured.open62541/applications/", &server->description.applicationUri);
  80. UA_LocalizedText_copycstring("Unconfigured open62541 application", &server->description.applicationName);
  81. server->description.applicationType = UA_APPLICATIONTYPE_SERVER;
  82. server->externalNamespacesSize = 0;
  83. server->externalNamespaces = UA_NULL;
  84. // mockup endpoint description
  85. server->endpointDescriptionsSize = 1;
  86. UA_EndpointDescription *endpoint = UA_EndpointDescription_new(); // todo: check return code
  87. endpoint->securityMode = UA_MESSAGESECURITYMODE_NONE;
  88. UA_String_copycstring("http://opcfoundation.org/UA/SecurityPolicy#None", &endpoint->securityPolicyUri);
  89. UA_String_copycstring("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary", &endpoint->transportProfileUri);
  90. endpoint->userIdentityTokensSize = 1;
  91. endpoint->userIdentityTokens = UA_malloc(sizeof(UA_UserTokenPolicy));
  92. UA_UserTokenPolicy_init(endpoint->userIdentityTokens);
  93. UA_String_copycstring("my-anonymous-policy", &endpoint->userIdentityTokens->policyId); // defined per server
  94. endpoint->userIdentityTokens->tokenType = UA_USERTOKENTYPE_ANONYMOUS;
  95. /* UA_String_copy(endpointUrl, &endpoint->endpointUrl); */
  96. /* /\* The standard says "the HostName specified in the Server Certificate is the */
  97. /* same as the HostName contained in the endpointUrl provided in the */
  98. /* EndpointDescription *\/ */
  99. /* UA_String_copy(&server->serverCertificate, &endpoint->serverCertificate); */
  100. UA_ApplicationDescription_copy(&server->description, &endpoint->server);
  101. server->endpointDescriptions = endpoint;
  102. #define MAXCHANNELCOUNT 100
  103. #define STARTCHANNELID 1
  104. #define TOKENLIFETIME 6000000
  105. #define STARTTOKENID 1
  106. UA_SecureChannelManager_init(&server->secureChannelManager, MAXCHANNELCOUNT,
  107. TOKENLIFETIME, STARTCHANNELID, STARTTOKENID);
  108. #define MAXSESSIONCOUNT 1000
  109. #define SESSIONLIFETIME 10000
  110. #define STARTSESSIONID 1
  111. UA_SessionManager_init(&server->sessionManager, MAXSESSIONCOUNT, SESSIONLIFETIME, STARTSESSIONID);
  112. server->nodestore = UA_NodeStore_new();
  113. #define ADDREFERENCE(NODEID, REFTYPE_NODEID, TARGET_EXPNODEID) do { \
  114. UA_AddReferencesItem item; \
  115. UA_AddReferencesItem_init(&item); \
  116. item.sourceNodeId = NODEID; \
  117. item.referenceTypeId = REFTYPE_NODEID; \
  118. item.isForward = UA_TRUE; \
  119. item.targetNodeId = TARGET_EXPNODEID; \
  120. UA_Server_addReference(server, &item); \
  121. } while(0)
  122. #define COPYNAMES(TARGET, NAME) do { \
  123. UA_QualifiedName_copycstring(NAME, &TARGET->browseName); \
  124. UA_LocalizedText_copycstring(NAME, &TARGET->displayName); \
  125. UA_LocalizedText_copycstring(NAME, &TARGET->description); \
  126. } while(0)
  127. /**************/
  128. /* References */
  129. /**************/
  130. /* bootstrap by manually inserting "references" and "hassubtype" */
  131. UA_ReferenceTypeNode *references = UA_ReferenceTypeNode_new();
  132. COPYNAMES(references, "References");
  133. references->nodeId.identifier.numeric = UA_NS0ID_REFERENCES;
  134. references->nodeClass = UA_NODECLASS_REFERENCETYPE;
  135. references->isAbstract = UA_TRUE;
  136. references->symmetric = UA_TRUE;
  137. // this node has no parent??
  138. UA_NodeStore_insert(server->nodestore, (UA_Node*)references, UA_NULL);
  139. UA_ReferenceTypeNode *hassubtype = UA_ReferenceTypeNode_new();
  140. COPYNAMES(hassubtype, "HasSubtype");
  141. UA_LocalizedText_copycstring("SubtypeOf", &hassubtype->inverseName);
  142. hassubtype->nodeId.identifier.numeric = UA_NS0ID_HASSUBTYPE;
  143. hassubtype->nodeClass = UA_NODECLASS_REFERENCETYPE;
  144. hassubtype->isAbstract = UA_FALSE;
  145. hassubtype->symmetric = UA_FALSE;
  146. UA_NodeStore_insert(server->nodestore, (UA_Node*)hassubtype, UA_NULL);
  147. /* continue adding reference types with normal "addnode" */
  148. UA_ReferenceTypeNode *hierarchicalreferences = UA_ReferenceTypeNode_new();
  149. COPYNAMES(hierarchicalreferences, "Hierarchicalreferences");
  150. hierarchicalreferences->nodeId.identifier.numeric = UA_NS0ID_HIERARCHICALREFERENCES;
  151. hierarchicalreferences->nodeClass = UA_NODECLASS_REFERENCETYPE;
  152. hierarchicalreferences->isAbstract = UA_TRUE;
  153. hierarchicalreferences->symmetric = UA_FALSE;
  154. UA_Server_addNode(server, (UA_Node*)hierarchicalreferences,
  155. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_REFERENCES),
  156. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  157. UA_ReferenceTypeNode *nonhierarchicalreferences = UA_ReferenceTypeNode_new();
  158. COPYNAMES(nonhierarchicalreferences, "NonHierarchicalReferences");
  159. nonhierarchicalreferences->nodeId.identifier.numeric = UA_NS0ID_NONHIERARCHICALREFERENCES;
  160. nonhierarchicalreferences->nodeClass = UA_NODECLASS_REFERENCETYPE;
  161. nonhierarchicalreferences->isAbstract = UA_TRUE;
  162. nonhierarchicalreferences->symmetric = UA_FALSE;
  163. UA_Server_addNode(server, (UA_Node*)nonhierarchicalreferences,
  164. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_REFERENCES),
  165. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  166. UA_ReferenceTypeNode *haschild = UA_ReferenceTypeNode_new();
  167. COPYNAMES(haschild, "HasChild");
  168. haschild->nodeId.identifier.numeric = UA_NS0ID_HASCHILD;
  169. haschild->nodeClass = UA_NODECLASS_REFERENCETYPE;
  170. haschild->isAbstract = UA_TRUE;
  171. haschild->symmetric = UA_FALSE;
  172. UA_Server_addNode(server, (UA_Node*)haschild,
  173. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  174. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  175. UA_ReferenceTypeNode *organizes = UA_ReferenceTypeNode_new();
  176. COPYNAMES(organizes, "Organizes");
  177. UA_LocalizedText_copycstring("OrganizedBy", &organizes->inverseName);
  178. organizes->nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  179. organizes->nodeClass = UA_NODECLASS_REFERENCETYPE;
  180. organizes->isAbstract = UA_FALSE;
  181. organizes->symmetric = UA_FALSE;
  182. UA_Server_addNode(server, (UA_Node*)organizes,
  183. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  184. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  185. UA_ReferenceTypeNode *haseventsource = UA_ReferenceTypeNode_new();
  186. COPYNAMES(haseventsource, "HasEventSource");
  187. UA_LocalizedText_copycstring("EventSourceOf", &haseventsource->inverseName);
  188. haseventsource->nodeId.identifier.numeric = UA_NS0ID_HASEVENTSOURCE;
  189. haseventsource->nodeClass = UA_NODECLASS_REFERENCETYPE;
  190. haseventsource->isAbstract = UA_FALSE;
  191. haseventsource->symmetric = UA_FALSE;
  192. UA_Server_addNode(server, (UA_Node*)haseventsource,
  193. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  194. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  195. UA_ReferenceTypeNode *hasmodellingrule = UA_ReferenceTypeNode_new();
  196. COPYNAMES(hasmodellingrule, "HasModellingRule");
  197. UA_LocalizedText_copycstring("ModellingRuleOf", &hasmodellingrule->inverseName);
  198. hasmodellingrule->nodeId.identifier.numeric = UA_NS0ID_HASMODELLINGRULE;
  199. hasmodellingrule->nodeClass = UA_NODECLASS_REFERENCETYPE;
  200. hasmodellingrule->isAbstract = UA_FALSE;
  201. hasmodellingrule->symmetric = UA_FALSE;
  202. UA_Server_addNode(server, (UA_Node*)hasmodellingrule,
  203. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  204. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  205. UA_ReferenceTypeNode *hasencoding = UA_ReferenceTypeNode_new();
  206. COPYNAMES(hasencoding, "HasEncoding");
  207. UA_LocalizedText_copycstring("EncodingOf", &hasencoding->inverseName);
  208. hasencoding->nodeId.identifier.numeric = UA_NS0ID_HASENCODING;
  209. hasencoding->nodeClass = UA_NODECLASS_REFERENCETYPE;
  210. hasencoding->isAbstract = UA_FALSE;
  211. hasencoding->symmetric = UA_FALSE;
  212. UA_Server_addNode(server, (UA_Node*)hasencoding,
  213. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  214. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  215. UA_ReferenceTypeNode *hasdescription = UA_ReferenceTypeNode_new();
  216. COPYNAMES(hasdescription, "HasDescription");
  217. UA_LocalizedText_copycstring("DescriptionOf", &hasdescription->inverseName);
  218. hasdescription->nodeId.identifier.numeric = UA_NS0ID_HASDESCRIPTION;
  219. hasdescription->nodeClass = UA_NODECLASS_REFERENCETYPE;
  220. hasdescription->isAbstract = UA_FALSE;
  221. hasdescription->symmetric = UA_FALSE;
  222. UA_Server_addNode(server, (UA_Node*)hasdescription,
  223. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  224. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  225. UA_ReferenceTypeNode *hastypedefinition = UA_ReferenceTypeNode_new();
  226. COPYNAMES(hastypedefinition, "HasTypeDefinition");
  227. UA_LocalizedText_copycstring("TypeDefinitionOf", &hastypedefinition->inverseName);
  228. hastypedefinition->nodeId.identifier.numeric = UA_NS0ID_HASTYPEDEFINITION;
  229. hastypedefinition->nodeClass = UA_NODECLASS_REFERENCETYPE;
  230. hastypedefinition->isAbstract = UA_FALSE;
  231. hastypedefinition->symmetric = UA_FALSE;
  232. UA_Server_addNode(server, (UA_Node*)hastypedefinition,
  233. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  234. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  235. UA_ReferenceTypeNode *generatesevent = UA_ReferenceTypeNode_new();
  236. COPYNAMES(generatesevent, "GeneratesEvent");
  237. UA_LocalizedText_copycstring("GeneratedBy", &generatesevent->inverseName);
  238. generatesevent->nodeId.identifier.numeric = UA_NS0ID_GENERATESEVENT;
  239. generatesevent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  240. generatesevent->isAbstract = UA_FALSE;
  241. generatesevent->symmetric = UA_FALSE;
  242. UA_Server_addNode(server, (UA_Node*)generatesevent,
  243. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  244. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  245. UA_ReferenceTypeNode *aggregates = UA_ReferenceTypeNode_new();
  246. COPYNAMES(aggregates, "Aggregates");
  247. // Todo: Is there an inverse name?
  248. aggregates->nodeId.identifier.numeric = UA_NS0ID_AGGREGATES;
  249. aggregates->nodeClass = UA_NODECLASS_REFERENCETYPE;
  250. aggregates->isAbstract = UA_TRUE;
  251. aggregates->symmetric = UA_FALSE;
  252. UA_Server_addNode(server, (UA_Node*)aggregates,
  253. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_HASCHILD),
  254. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  255. // complete bootstrap of hassubtype
  256. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_HASCHILD), UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE),
  257. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  258. UA_ReferenceTypeNode *hasproperty = UA_ReferenceTypeNode_new();
  259. COPYNAMES(hasproperty, "HasProperty");
  260. UA_LocalizedText_copycstring("PropertyOf", &hasproperty->inverseName);
  261. hasproperty->nodeId.identifier.numeric = UA_NS0ID_HASPROPERTY;
  262. hasproperty->nodeClass = UA_NODECLASS_REFERENCETYPE;
  263. hasproperty->isAbstract = UA_FALSE;
  264. hasproperty->symmetric = UA_FALSE;
  265. UA_Server_addNode(server, (UA_Node*)hasproperty,
  266. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_AGGREGATES),
  267. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  268. UA_ReferenceTypeNode *hascomponent = UA_ReferenceTypeNode_new();
  269. COPYNAMES(hascomponent, "HasComponent");
  270. UA_LocalizedText_copycstring("ComponentOf", &hascomponent->inverseName);
  271. hascomponent->nodeId.identifier.numeric = UA_NS0ID_HASCOMPONENT;
  272. hascomponent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  273. hascomponent->isAbstract = UA_FALSE;
  274. hascomponent->symmetric = UA_FALSE;
  275. UA_Server_addNode(server, (UA_Node*)hascomponent,
  276. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_AGGREGATES),
  277. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  278. UA_ReferenceTypeNode *hasnotifier = UA_ReferenceTypeNode_new();
  279. COPYNAMES(hasnotifier, "HasNotifier");
  280. UA_LocalizedText_copycstring("NotifierOf", &hasnotifier->inverseName);
  281. hasnotifier->nodeId.identifier.numeric = UA_NS0ID_HASNOTIFIER;
  282. hasnotifier->nodeClass = UA_NODECLASS_REFERENCETYPE;
  283. hasnotifier->isAbstract = UA_FALSE;
  284. hasnotifier->symmetric = UA_FALSE;
  285. UA_Server_addNode(server, (UA_Node*)hasnotifier,
  286. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_HASEVENTSOURCE),
  287. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  288. UA_ReferenceTypeNode *hasorderedcomponent = UA_ReferenceTypeNode_new();
  289. COPYNAMES(hasorderedcomponent, "HasOrderedComponent");
  290. UA_LocalizedText_copycstring("OrderedComponentOf", &hasorderedcomponent->inverseName);
  291. hasorderedcomponent->nodeId.identifier.numeric = UA_NS0ID_HASORDEREDCOMPONENT;
  292. hasorderedcomponent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  293. hasorderedcomponent->isAbstract = UA_FALSE;
  294. hasorderedcomponent->symmetric = UA_FALSE;
  295. UA_Server_addNode(server, (UA_Node*)hasorderedcomponent,
  296. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_HASCOMPONENT),
  297. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  298. UA_ReferenceTypeNode *hasmodelparent = UA_ReferenceTypeNode_new();
  299. COPYNAMES(hasmodelparent, "HasModelParent");
  300. UA_LocalizedText_copycstring("ModelParentOf", &hasmodelparent->inverseName);
  301. hasmodelparent->nodeId.identifier.numeric = UA_NS0ID_HASMODELPARENT;
  302. hasmodelparent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  303. hasmodelparent->isAbstract = UA_FALSE;
  304. hasmodelparent->symmetric = UA_FALSE;
  305. UA_Server_addNode(server, (UA_Node*)hasmodelparent,
  306. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  307. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  308. UA_ReferenceTypeNode *fromstate = UA_ReferenceTypeNode_new();
  309. COPYNAMES(fromstate, "FromState");
  310. UA_LocalizedText_copycstring("ToTransition", &fromstate->inverseName);
  311. fromstate->nodeId.identifier.numeric = UA_NS0ID_FROMSTATE;
  312. fromstate->nodeClass = UA_NODECLASS_REFERENCETYPE;
  313. fromstate->isAbstract = UA_FALSE;
  314. fromstate->symmetric = UA_FALSE;
  315. UA_Server_addNode(server, (UA_Node*)fromstate,
  316. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  317. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  318. UA_ReferenceTypeNode *tostate = UA_ReferenceTypeNode_new();
  319. COPYNAMES(tostate, "ToState");
  320. UA_LocalizedText_copycstring("FromTransition", &tostate->inverseName);
  321. tostate->nodeId.identifier.numeric = UA_NS0ID_TOSTATE;
  322. tostate->nodeClass = UA_NODECLASS_REFERENCETYPE;
  323. tostate->isAbstract = UA_FALSE;
  324. tostate->symmetric = UA_FALSE;
  325. UA_Server_addNode(server, (UA_Node*)tostate,
  326. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  327. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  328. UA_ReferenceTypeNode *hascause = UA_ReferenceTypeNode_new();
  329. COPYNAMES(hascause, "HasCause");
  330. UA_LocalizedText_copycstring("MayBeCausedBy", &hascause->inverseName);
  331. hascause->nodeId.identifier.numeric = UA_NS0ID_HASCAUSE;
  332. hascause->nodeClass = UA_NODECLASS_REFERENCETYPE;
  333. hascause->isAbstract = UA_FALSE;
  334. hascause->symmetric = UA_FALSE;
  335. UA_Server_addNode(server, (UA_Node*)hascause,
  336. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  337. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  338. UA_ReferenceTypeNode *haseffect = UA_ReferenceTypeNode_new();
  339. COPYNAMES(haseffect, "HasEffect");
  340. UA_LocalizedText_copycstring("MayBeEffectedBy", &haseffect->inverseName);
  341. haseffect->nodeId.identifier.numeric = UA_NS0ID_HASEFFECT;
  342. haseffect->nodeClass = UA_NODECLASS_REFERENCETYPE;
  343. haseffect->isAbstract = UA_FALSE;
  344. haseffect->symmetric = UA_FALSE;
  345. UA_Server_addNode(server, (UA_Node*)haseffect,
  346. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  347. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  348. UA_ReferenceTypeNode *hashistoricalconfiguration = UA_ReferenceTypeNode_new();
  349. COPYNAMES(hashistoricalconfiguration, "HasHistoricalConfiguration");
  350. UA_LocalizedText_copycstring("HistoricalConfigurationOf", &hashistoricalconfiguration->inverseName);
  351. hashistoricalconfiguration->nodeId.identifier.numeric = UA_NS0ID_HASHISTORICALCONFIGURATION;
  352. hashistoricalconfiguration->nodeClass = UA_NODECLASS_REFERENCETYPE;
  353. hashistoricalconfiguration->isAbstract = UA_FALSE;
  354. hashistoricalconfiguration->symmetric = UA_FALSE;
  355. UA_Server_addNode(server, (UA_Node*)hashistoricalconfiguration,
  356. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_AGGREGATES),
  357. &UA_NODEID_STATIC(0, UA_NS0ID_HASSUBTYPE));
  358. /***********/
  359. /* Objects */
  360. /***********/
  361. UA_ObjectNode *folderType = UA_ObjectNode_new();
  362. folderType->nodeId.identifier.numeric = UA_NS0ID_FOLDERTYPE;
  363. folderType->nodeClass = UA_NODECLASS_OBJECTTYPE;
  364. COPYNAMES(folderType, "FolderType");
  365. UA_NodeStore_insert(server->nodestore, (UA_Node*)folderType, UA_NULL);
  366. UA_ObjectNode *root = UA_ObjectNode_new();
  367. COPYNAMES(root, "Root");
  368. root->nodeId.identifier.numeric = UA_NS0ID_ROOTFOLDER;
  369. root->nodeClass = UA_NODECLASS_OBJECT;
  370. UA_NodeStore_insert(server->nodestore, (UA_Node*)root, UA_NULL);
  371. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_ROOTFOLDER), UA_NODEID_STATIC(0, UA_NS0ID_HASTYPEDEFINITION),
  372. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_FOLDERTYPE));
  373. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_ROOTFOLDER), UA_NODEID_STATIC(0, UA_NS0ID_ORGANIZES),
  374. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_OBJECTSFOLDER));
  375. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_ROOTFOLDER), UA_NODEID_STATIC(0, UA_NS0ID_ORGANIZES),
  376. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_TYPESFOLDER));
  377. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_ROOTFOLDER), UA_NODEID_STATIC(0, UA_NS0ID_ORGANIZES),
  378. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_VIEWSFOLDER));
  379. UA_ObjectNode *objects = UA_ObjectNode_new();
  380. COPYNAMES(objects, "Objects");
  381. objects->nodeId.identifier.numeric = UA_NS0ID_OBJECTSFOLDER;
  382. objects->nodeClass = UA_NODECLASS_OBJECT;
  383. UA_NodeStore_insert(server->nodestore, (UA_Node*)objects, UA_NULL);
  384. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_STATIC(0, UA_NS0ID_HASTYPEDEFINITION),
  385. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_FOLDERTYPE));
  386. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_STATIC(0, UA_NS0ID_ORGANIZES),
  387. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_SERVER));
  388. UA_ObjectNode *types = UA_ObjectNode_new();
  389. COPYNAMES(types, "Types");
  390. types->nodeId.identifier.numeric = UA_NS0ID_TYPESFOLDER;
  391. types->nodeClass = UA_NODECLASS_OBJECT;
  392. UA_NodeStore_insert(server->nodestore, (UA_Node*)types, UA_NULL);
  393. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_TYPESFOLDER), UA_NODEID_STATIC(0, UA_NS0ID_HASTYPEDEFINITION),
  394. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_FOLDERTYPE));
  395. UA_ObjectNode *views = UA_ObjectNode_new();
  396. COPYNAMES(views, "Views");
  397. views->nodeId.identifier.numeric = UA_NS0ID_VIEWSFOLDER;
  398. views->nodeClass = UA_NODECLASS_OBJECT;
  399. UA_NodeStore_insert(server->nodestore, (UA_Node*)views, UA_NULL);
  400. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_VIEWSFOLDER), UA_NODEID_STATIC(0, UA_NS0ID_HASTYPEDEFINITION),
  401. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_FOLDERTYPE));
  402. UA_ObjectNode *servernode = UA_ObjectNode_new();
  403. COPYNAMES(servernode, "Server");
  404. servernode->nodeId.identifier.numeric = UA_NS0ID_SERVER;
  405. servernode->nodeClass = UA_NODECLASS_OBJECT;
  406. UA_NodeStore_insert(server->nodestore, (UA_Node*)servernode, UA_NULL);
  407. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_SERVER), UA_NODEID_STATIC(0, UA_NS0ID_HASCOMPONENT),
  408. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_SERVER_SERVERCAPABILITIES));
  409. ADDREFERENCE(UA_NODEID_STATIC(0, UA_NS0ID_SERVER), UA_NODEID_STATIC(0, UA_NS0ID_HASPROPERTY),
  410. UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_SERVER_SERVERARRAY));
  411. UA_VariableNode *namespaceArray = UA_VariableNode_new();
  412. COPYNAMES(namespaceArray, "NamespaceArray");
  413. namespaceArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_NAMESPACEARRAY;
  414. namespaceArray->nodeClass = UA_NODECLASS_VARIABLE;
  415. UA_Array_new(&namespaceArray->value.storage.data.dataPtr, 2, &UA_TYPES[UA_TYPES_STRING]);
  416. namespaceArray->value.storage.data.arrayLength = 2;
  417. namespaceArray->value.type = &UA_TYPES[UA_TYPES_STRING];
  418. namespaceArray->value.typeId.identifier.numeric = UA_TYPES_IDS[UA_TYPES_STRING];
  419. // Fixme: Insert the external namespaces
  420. UA_String_copycstring("http://opcfoundation.org/UA/",
  421. &((UA_String *)(namespaceArray->value.storage.data.dataPtr))[0]);
  422. UA_String_copycstring("urn:myServer:myApplication",
  423. &((UA_String *)(namespaceArray->value.storage.data.dataPtr))[1]);
  424. namespaceArray->valueRank = 1;
  425. namespaceArray->minimumSamplingInterval = 1.0;
  426. namespaceArray->historizing = UA_FALSE;
  427. UA_Server_addNode(server, (UA_Node*)namespaceArray,
  428. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_SERVER),
  429. &UA_NODEID_STATIC(0, UA_NS0ID_HASCOMPONENT));
  430. UA_ServerStatusDataType *status = UA_ServerStatusDataType_new();
  431. status->startTime = UA_DateTime_now();
  432. status->currentTime = UA_DateTime_now();
  433. status->state = UA_SERVERSTATE_RUNNING;
  434. UA_String_copycstring("open62541.org", &status->buildInfo.productUri);
  435. UA_String_copycstring("open62541", &status->buildInfo.manufacturerName);
  436. UA_String_copycstring("open62541", &status->buildInfo.productName);
  437. UA_String_copycstring("0.0", &status->buildInfo.softwareVersion);
  438. UA_String_copycstring("0.0", &status->buildInfo.buildNumber);
  439. status->buildInfo.buildDate = UA_DateTime_now();
  440. status->secondsTillShutdown = 99999999;
  441. UA_LocalizedText_copycstring("because", &status->shutdownReason);
  442. UA_VariableNode *serverstatus = UA_VariableNode_new();
  443. COPYNAMES(serverstatus, "ServerStatus");
  444. serverstatus->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERSTATUS;
  445. serverstatus->nodeClass = UA_NODECLASS_VARIABLE;
  446. serverstatus->value.type = &UA_TYPES[UA_TYPES_SERVERSTATUSDATATYPE];
  447. serverstatus->value.typeId.identifier.numeric = UA_TYPES_IDS[UA_TYPES_SERVERSTATUSDATATYPE];
  448. serverstatus->value.storage.data.arrayLength = 1;
  449. serverstatus->value.storage.data.dataPtr = status;
  450. UA_Server_addNode(server, (UA_Node*)serverstatus,
  451. &UA_EXPANDEDNODEID_STATIC(0, UA_NS0ID_SERVER),
  452. &UA_NODEID_STATIC(0, UA_NS0ID_HASPROPERTY));
  453. // todo: make this variable point to a member of the serverstatus
  454. UA_VariableNode *state = UA_VariableNode_new();
  455. UA_ServerState *stateEnum = UA_ServerState_new();
  456. *stateEnum = UA_SERVERSTATE_RUNNING;
  457. COPYNAMES(state, "State");
  458. state->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERSTATUS_STATE;
  459. state->nodeClass = UA_NODECLASS_VARIABLE;
  460. state->value.type = &UA_TYPES[UA_TYPES_SERVERSTATE];
  461. state->value.typeId.identifier.numeric = UA_TYPES_IDS[UA_TYPES_SERVERSTATE];
  462. state->value.storage.data.arrayLength = 1;
  463. state->value.storage.data.dataPtr = stateEnum; // points into the other object.
  464. state->value.storageType = UA_VARIANT_DATA;
  465. UA_NodeStore_insert(server->nodestore, (UA_Node*)state, UA_NULL);
  466. return server;
  467. }