ua_server.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. #include "ua_types.h"
  2. #include "ua_server_internal.h"
  3. #include "ua_securechannel_manager.h"
  4. #include "ua_session_manager.h"
  5. #include "ua_util.h"
  6. #include "ua_services.h"
  7. #include "ua_nodeids.h"
  8. const UA_ServerConfig UA_ServerConfig_standard = {
  9. UA_TRUE,
  10. UA_TRUE,
  11. (char *[]){"user1","user2"},
  12. (char *[]){"password","password1"},
  13. 2,
  14. "urn:unconfigured:open62541:open62541Server",
  15. "Unconfigured open62541 application"
  16. };
  17. /**********************/
  18. /* Namespace Handling */
  19. /**********************/
  20. static void UA_ExternalNamespace_init(UA_ExternalNamespace *ens) {
  21. ens->index = 0;
  22. UA_String_init(&ens->url);
  23. }
  24. static void UA_ExternalNamespace_deleteMembers(UA_ExternalNamespace *ens) {
  25. UA_String_deleteMembers(&ens->url);
  26. ens->externalNodeStore.destroy(ens->externalNodeStore.ensHandle);
  27. }
  28. /*****************/
  29. /* Configuration */
  30. /*****************/
  31. UA_Logger * UA_Server_getLogger(UA_Server *server) {
  32. return &server->logger;
  33. }
  34. void UA_Server_addNetworkLayer(UA_Server *server, UA_ServerNetworkLayer networkLayer) {
  35. UA_ServerNetworkLayer *newlayers =
  36. UA_realloc(server->nls, sizeof(UA_ServerNetworkLayer)*(server->nlsSize+1));
  37. if(!newlayers) {
  38. UA_LOG_ERROR(server->logger, UA_LOGGERCATEGORY_SERVER, "Networklayer added");
  39. return;
  40. }
  41. server->nls = newlayers;
  42. server->nls[server->nlsSize] = networkLayer;
  43. server->nlsSize++;
  44. if(networkLayer.discoveryUrl){
  45. if(server->description.discoveryUrlsSize < 0)
  46. server->description.discoveryUrlsSize = 0;
  47. UA_String* newUrls = UA_realloc(server->description.discoveryUrls,
  48. sizeof(UA_String)*(server->description.discoveryUrlsSize+1));
  49. if(!newUrls) {
  50. UA_LOG_ERROR(server->logger, UA_LOGGERCATEGORY_SERVER, "Adding discoveryUrl");
  51. return;
  52. }
  53. server->description.discoveryUrls = newUrls;
  54. UA_String_copy(networkLayer.discoveryUrl,
  55. &server->description.discoveryUrls[server->description.discoveryUrlsSize]);
  56. server->description.discoveryUrlsSize++;
  57. }
  58. }
  59. void UA_Server_setServerCertificate(UA_Server *server, UA_ByteString certificate) {
  60. for(UA_Int32 i = 0; i < server->endpointDescriptionsSize; i++)
  61. UA_ByteString_copy(&certificate, &server->endpointDescriptions[i].serverCertificate);
  62. }
  63. void UA_Server_setLogger(UA_Server *server, UA_Logger logger) {
  64. server->logger = logger;
  65. }
  66. UA_UInt16 UA_Server_addNamespace(UA_Server *server, const char* name) {
  67. server->namespaces = UA_realloc(server->namespaces, sizeof(UA_String) * (server->namespacesSize+1));
  68. server->namespaces[server->namespacesSize] = UA_STRING_ALLOC(name);
  69. server->namespacesSize++;
  70. return server->namespacesSize-1;
  71. }
  72. /**********/
  73. /* Server */
  74. /**********/
  75. /* The server needs to be stopped before it can be deleted */
  76. void UA_Server_delete(UA_Server *server) {
  77. // Delete the timed work
  78. UA_Server_deleteTimedWork(server);
  79. // Delete all internal data
  80. UA_ApplicationDescription_deleteMembers(&server->description);
  81. UA_SecureChannelManager_deleteMembers(&server->secureChannelManager);
  82. UA_SessionManager_deleteMembers(&server->sessionManager);
  83. UA_NodeStore_delete(server->nodestore);
  84. UA_ByteString_deleteMembers(&server->serverCertificate);
  85. UA_Array_delete(server->namespaces, &UA_TYPES[UA_TYPES_STRING], server->namespacesSize);
  86. UA_Array_delete(server->endpointDescriptions, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION],
  87. server->endpointDescriptionsSize);
  88. // Delete the network layers
  89. for(UA_Int32 i = 0; i < server->nlsSize; i++) {
  90. server->nls[i].free(server->nls[i].nlHandle);
  91. }
  92. UA_free(server->nls);
  93. #ifdef UA_MULTITHREADING
  94. pthread_cond_destroy(&server->dispatchQueue_condition); // so the workers don't spin if the queue is empty
  95. rcu_barrier(); // wait for all scheduled call_rcu work to complete
  96. #endif
  97. UA_free(server);
  98. }
  99. /**
  100. * Recurring cleanup. Removing unused and timed-out channels and sessions
  101. * Todo: make this thread-safe
  102. */
  103. static void UA_Server_cleanup(UA_Server *server, void *nothing) {
  104. UA_DateTime now = UA_DateTime_now();
  105. channel_list_entry *entry = LIST_FIRST(&server->secureChannelManager.channels);
  106. /* remove channels that were not renewed or who have no connection attached */
  107. while(entry) {
  108. if(entry->channel.securityToken.createdAt +
  109. (10000 * entry->channel.securityToken.revisedLifetime) > now &&
  110. entry->channel.connection) {
  111. entry = LIST_NEXT(entry, pointers);
  112. } else {
  113. channel_list_entry *next = LIST_NEXT(entry, pointers);
  114. LIST_REMOVE(entry, pointers);
  115. UA_Connection *c = entry->channel.connection;
  116. if (c) {
  117. UA_Connection_detachSecureChannel(c);
  118. c->close(c);
  119. }
  120. UA_SecureChannel_detachSession(&entry->channel);
  121. UA_SecureChannel_deleteMembers(&entry->channel);
  122. UA_free(entry);
  123. entry = next;
  124. }
  125. }
  126. session_list_entry *sentry = LIST_FIRST(&server->sessionManager.sessions);
  127. while(sentry) {
  128. if(sentry->session.validTill < now) {
  129. session_list_entry *next = LIST_NEXT(sentry, pointers);
  130. LIST_REMOVE(sentry, pointers);
  131. UA_SecureChannel_detachSession(sentry->session.channel);
  132. UA_Session_deleteMembers(&sentry->session);
  133. UA_free(sentry);
  134. sentry = next;
  135. }
  136. }
  137. }
  138. static UA_StatusCode readStatus(void *handle, UA_Boolean sourceTimeStamp, UA_DataValue *value) {
  139. UA_ServerStatusDataType *status = UA_ServerStatusDataType_new();
  140. status->startTime = ((const UA_Server*)handle)->startTime;
  141. status->currentTime = UA_DateTime_now();
  142. status->state = UA_SERVERSTATE_RUNNING;
  143. status->buildInfo.productUri = UA_STRING("http://www.open62541.org");
  144. status->buildInfo.manufacturerName = UA_STRING("open62541");
  145. status->buildInfo.productName = UA_STRING("open62541 OPC UA Server");
  146. #define STRINGIFY(x) #x //some magic
  147. #define TOSTRING(x) STRINGIFY(x) //some magic
  148. status->buildInfo.softwareVersion = UA_STRING(TOSTRING(OPEN62541_VERSION_MAJOR) "." TOSTRING(OPEN62541_VERSION_MINOR) "." TOSTRING(OPEN62541_VERSION_PATCH));
  149. status->buildInfo.buildNumber = UA_STRING("0");
  150. status->buildInfo.buildDate = ((const UA_Server*)handle)->buildDate;
  151. status->secondsTillShutdown = 0;
  152. value->value.type = &UA_TYPES[UA_TYPES_SERVERSTATUSDATATYPE];
  153. value->value.arrayLength = -1;
  154. value->value.data = status;
  155. value->value.arrayDimensionsSize = -1;
  156. value->value.arrayDimensions = UA_NULL;
  157. value->hasValue = UA_TRUE;
  158. if(sourceTimeStamp) {
  159. value->hasSourceTimestamp = UA_TRUE;
  160. value->sourceTimestamp = UA_DateTime_now();
  161. }
  162. return UA_STATUSCODE_GOOD;
  163. }
  164. static void releaseStatus(void *handle, UA_DataValue *value) {
  165. UA_free(value->value.data);
  166. value->value.data = UA_NULL;
  167. value->hasValue = UA_FALSE;
  168. UA_DataValue_deleteMembers(value);
  169. }
  170. static UA_StatusCode readNamespaces(void *handle, UA_Boolean sourceTimestamp, UA_DataValue *value) {
  171. UA_Server *server = (UA_Server*)handle;
  172. value->hasValue = UA_TRUE;
  173. value->value.storageType = UA_VARIANT_DATA_NODELETE;
  174. value->value.type = &UA_TYPES[UA_TYPES_STRING];
  175. value->value.arrayLength = server->namespacesSize;
  176. value->value.data = server->namespaces;
  177. if(sourceTimestamp) {
  178. value->hasSourceTimestamp = UA_TRUE;
  179. value->sourceTimestamp = UA_DateTime_now();
  180. }
  181. return UA_STATUSCODE_GOOD;
  182. }
  183. static void releaseNamespaces(void *handle, UA_DataValue *value) {
  184. }
  185. static UA_StatusCode readCurrentTime(void *handle, UA_Boolean sourceTimeStamp, UA_DataValue *value) {
  186. UA_DateTime *currentTime = UA_DateTime_new();
  187. if(!currentTime)
  188. return UA_STATUSCODE_BADOUTOFMEMORY;
  189. *currentTime = UA_DateTime_now();
  190. value->value.type = &UA_TYPES[UA_TYPES_DATETIME];
  191. value->value.arrayLength = -1;
  192. value->value.data = currentTime;
  193. value->value.arrayDimensionsSize = -1;
  194. value->value.arrayDimensions = NULL;
  195. value->hasValue = UA_TRUE;
  196. if(sourceTimeStamp) {
  197. value->hasSourceTimestamp = UA_TRUE;
  198. value->sourceTimestamp = *currentTime;
  199. }
  200. return UA_STATUSCODE_GOOD;
  201. }
  202. static void releaseCurrentTime(void *handle, UA_DataValue *value) {
  203. UA_DateTime_delete((UA_DateTime*)value->value.data);
  204. }
  205. static void copyNames(UA_Node *node, char *name) {
  206. node->browseName = UA_QUALIFIEDNAME_ALLOC(0, name);
  207. node->displayName = UA_LOCALIZEDTEXT_ALLOC("", name);
  208. node->description = UA_LOCALIZEDTEXT_ALLOC("", name);
  209. }
  210. static void addDataTypeNode(UA_Server *server, char* name, UA_UInt32 datatypeid, UA_Int32 parent) {
  211. UA_DataTypeNode *datatype = UA_DataTypeNode_new();
  212. copyNames((UA_Node*)datatype, name);
  213. datatype->nodeId.identifier.numeric = datatypeid;
  214. UA_Server_addNode(server, (UA_Node*)datatype,
  215. &UA_EXPANDEDNODEID_NUMERIC(0, parent),
  216. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  217. }
  218. static void addObjectTypeNode(UA_Server *server, char* name, UA_UInt32 objecttypeid, UA_Int32 parent) {
  219. UA_ObjectTypeNode *objecttype = UA_ObjectTypeNode_new();
  220. copyNames((UA_Node*)objecttype, name);
  221. objecttype->nodeId.identifier.numeric = objecttypeid;
  222. printf("parent %i\n", parent);
  223. UA_Server_addNode(server, (UA_Node*)objecttype,
  224. &UA_EXPANDEDNODEID_NUMERIC(0, parent),
  225. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  226. }
  227. static UA_VariableTypeNode*
  228. createVariableTypeNode(UA_Server *server, char* name, UA_UInt32 variabletypeid,
  229. UA_Int32 parent, UA_Boolean abstract)
  230. {
  231. UA_VariableTypeNode *variabletype = UA_VariableTypeNode_new();
  232. copyNames((UA_Node*)variabletype, name);
  233. variabletype->nodeId.identifier.numeric = variabletypeid;
  234. variabletype->isAbstract = abstract;
  235. variabletype->value.variant.type = &UA_TYPES[UA_TYPES_VARIANT];
  236. return variabletype;
  237. }
  238. static void addVariableTypeNode_organized(UA_Server *server, char* name, UA_UInt32 variabletypeid,
  239. UA_Int32 parent, UA_Boolean abstract) {
  240. UA_VariableTypeNode *variabletype = createVariableTypeNode(server, name, variabletypeid, parent, abstract);
  241. UA_Server_addNode(server, (UA_Node*)variabletype,
  242. &UA_EXPANDEDNODEID_NUMERIC(0, parent),
  243. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  244. }
  245. static void addVariableTypeNode_subtype(UA_Server *server, char* name, UA_UInt32 variabletypeid,
  246. UA_Int32 parent, UA_Boolean abstract) {
  247. UA_VariableTypeNode *variabletype = createVariableTypeNode(server, name, variabletypeid, parent, abstract);
  248. UA_Server_addNode(server, (UA_Node*)variabletype,
  249. &UA_EXPANDEDNODEID_NUMERIC(0, parent),
  250. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  251. }
  252. UA_Server * UA_Server_new(UA_ServerConfig config) {
  253. UA_Server *server = UA_malloc(sizeof(UA_Server));
  254. if(!server)
  255. return UA_NULL;
  256. //FIXME: config contains strings, for now its okay, but consider copying them aswell
  257. server->config = config;
  258. LIST_INIT(&server->timedWork);
  259. #ifdef UA_MULTITHREADING
  260. rcu_init();
  261. cds_wfcq_init(&server->dispatchQueue_head, &server->dispatchQueue_tail);
  262. server->delayedWork = UA_NULL;
  263. #endif
  264. // logger
  265. server->logger = (UA_Logger){ UA_NULL, UA_NULL, UA_NULL, UA_NULL, UA_NULL, UA_NULL };
  266. // random seed
  267. server->random_seed = (UA_UInt32)UA_DateTime_now();
  268. // networklayers
  269. server->nls = UA_NULL;
  270. server->nlsSize = 0;
  271. UA_ByteString_init(&server->serverCertificate);
  272. // mockup application description
  273. UA_ApplicationDescription_init(&server->description);
  274. server->description.productUri = UA_STRING_ALLOC(PRODUCT_URI);
  275. server->description.applicationUri = UA_STRING_ALLOC(server->config.Application_applicationURI);
  276. server->description.discoveryUrlsSize = 0;
  277. server->description.applicationName = UA_LOCALIZEDTEXT_ALLOC("", server->config.Application_applicationName);
  278. server->description.applicationType = UA_APPLICATIONTYPE_SERVER;
  279. server->externalNamespacesSize = 0;
  280. server->externalNamespaces = UA_NULL;
  281. server->namespaces = UA_String_new();
  282. *server->namespaces = UA_STRING_ALLOC("http://opcfoundation.org/UA/");
  283. server->namespacesSize = 1;
  284. server->endpointDescriptions = UA_NULL;
  285. server->endpointDescriptionsSize = 0;
  286. UA_EndpointDescription *endpoint = UA_EndpointDescription_new(); // todo: check return code
  287. if(endpoint) {
  288. endpoint->securityMode = UA_MESSAGESECURITYMODE_NONE;
  289. endpoint->securityPolicyUri = UA_STRING_ALLOC("http://opcfoundation.org/UA/SecurityPolicy#None");
  290. endpoint->transportProfileUri = UA_STRING_ALLOC("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary");
  291. int size = 0;
  292. if(server->config.Login_enableAnonymous){
  293. size++;
  294. }
  295. if(server->config.Login_enableUsernamePassword){
  296. size++;
  297. }
  298. endpoint->userIdentityTokensSize = size;
  299. endpoint->userIdentityTokens = UA_Array_new(&UA_TYPES[UA_TYPES_USERTOKENPOLICY], size);
  300. int currentIndex = 0;
  301. if(server->config.Login_enableAnonymous){
  302. UA_UserTokenPolicy_init(&endpoint->userIdentityTokens[currentIndex]);
  303. endpoint->userIdentityTokens[currentIndex].tokenType = UA_USERTOKENTYPE_ANONYMOUS;
  304. endpoint->userIdentityTokens[currentIndex].policyId = UA_STRING_ALLOC(ANONYMOUS_POLICY); // defined per server
  305. currentIndex++;
  306. }
  307. if(server->config.Login_enableUsernamePassword){
  308. UA_UserTokenPolicy_init(&endpoint->userIdentityTokens[currentIndex]);
  309. endpoint->userIdentityTokens[currentIndex].tokenType = UA_USERTOKENTYPE_USERNAME;
  310. endpoint->userIdentityTokens[currentIndex].policyId = UA_STRING_ALLOC(USERNAME_POLICY); // defined per server
  311. currentIndex++;
  312. }
  313. /* UA_String_copy(endpointUrl, &endpoint->endpointUrl); */
  314. /* /\* The standard says "the HostName specified in the Server Certificate is the */
  315. /* same as the HostName contained in the endpointUrl provided in the */
  316. /* EndpointDescription *\/ */
  317. /* UA_String_copy(&server->serverCertificate, &endpoint->serverCertificate); */
  318. UA_ApplicationDescription_copy(&server->description, &endpoint->server);
  319. server->endpointDescriptions = endpoint;
  320. server->endpointDescriptionsSize = 1;
  321. }
  322. #define MAXCHANNELCOUNT 100
  323. #define STARTCHANNELID 1
  324. #define TOKENLIFETIME 600000
  325. #define STARTTOKENID 1
  326. UA_SecureChannelManager_init(&server->secureChannelManager, MAXCHANNELCOUNT,
  327. TOKENLIFETIME, STARTCHANNELID, STARTTOKENID);
  328. #define MAXSESSIONCOUNT 1000
  329. #define MAXSESSIONLIFETIME 10000
  330. #define STARTSESSIONID 1
  331. UA_SessionManager_init(&server->sessionManager, MAXSESSIONCOUNT, MAXSESSIONLIFETIME, STARTSESSIONID);
  332. server->nodestore = UA_NodeStore_new();
  333. /* UA_WorkItem cleanup = {.type = UA_WORKITEMTYPE_METHODCALL, */
  334. /* .work.methodCall = {.method = UA_Server_cleanup, .data = NULL} }; */
  335. /* UA_Server_addRepeatedWorkItem(server, &cleanup, 100000, NULL); */
  336. /**********************/
  337. /* Server Information */
  338. /**********************/
  339. server->startTime = UA_DateTime_now();
  340. static struct tm ct;
  341. ct.tm_year = (__DATE__[7] - '0') * 1000 + (__DATE__[8] - '0') * 100 + (__DATE__[9] - '0') * 10 + (__DATE__[10] - '0')- 1900;
  342. if ((__DATE__[0]=='J') && (__DATE__[1]=='a') && (__DATE__[2]=='n')) ct.tm_mon = 1-1;
  343. else if ((__DATE__[0]=='F') && (__DATE__[1]=='e') && (__DATE__[2]=='b')) ct.tm_mon = 2-1;
  344. else if ((__DATE__[0]=='M') && (__DATE__[1]=='a') && (__DATE__[2]=='r')) ct.tm_mon = 3-1;
  345. else if ((__DATE__[0]=='A') && (__DATE__[1]=='p') && (__DATE__[2]=='r')) ct.tm_mon = 4-1;
  346. else if ((__DATE__[0]=='M') && (__DATE__[1]=='a') && (__DATE__[2]=='y')) ct.tm_mon = 5-1;
  347. else if ((__DATE__[0]=='J') && (__DATE__[1]=='u') && (__DATE__[2]=='n')) ct.tm_mon = 6-1;
  348. else if ((__DATE__[0]=='J') && (__DATE__[1]=='u') && (__DATE__[2]=='l')) ct.tm_mon = 7-1;
  349. else if ((__DATE__[0]=='A') && (__DATE__[1]=='u') && (__DATE__[2]=='g')) ct.tm_mon = 8-1;
  350. else if ((__DATE__[0]=='S') && (__DATE__[1]=='e') && (__DATE__[2]=='p')) ct.tm_mon = 9-1;
  351. else if ((__DATE__[0]=='O') && (__DATE__[1]=='c') && (__DATE__[2]=='t')) ct.tm_mon = 10-1;
  352. else if ((__DATE__[0]=='N') && (__DATE__[1]=='o') && (__DATE__[2]=='v')) ct.tm_mon = 11-1;
  353. else if ((__DATE__[0]=='D') && (__DATE__[1]=='e') && (__DATE__[2]=='c')) ct.tm_mon = 12-1;
  354. // special case to handle __DATE__ not inserting leading zero on day of month
  355. // if Day of month is less than 10 - it inserts a blank character
  356. // this results in a negative number for tm_mday
  357. if(__DATE__[4] == ' ')
  358. ct.tm_mday = __DATE__[5]-'0';
  359. else
  360. ct.tm_mday = (__DATE__[4]-'0')*10 + (__DATE__[5]-'0');
  361. ct.tm_hour = ((__TIME__[0] - '0') * 10 + __TIME__[1] - '0');
  362. ct.tm_min = ((__TIME__[3] - '0') * 10 + __TIME__[4] - '0');
  363. ct.tm_sec = ((__TIME__[6] - '0') * 10 + __TIME__[7] - '0');
  364. ct.tm_isdst = -1; // information is not available.
  365. //FIXME: next 3 lines are copy-pasted from ua_types.c
  366. #define UNIX_EPOCH_BIAS_SEC 11644473600LL // Number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
  367. #define HUNDRED_NANOSEC_PER_USEC 10LL
  368. #define HUNDRED_NANOSEC_PER_SEC (HUNDRED_NANOSEC_PER_USEC * 1000000LL)
  369. server->buildDate = (mktime(&ct) + UNIX_EPOCH_BIAS_SEC) * HUNDRED_NANOSEC_PER_SEC;
  370. /**************/
  371. /* References */
  372. /**************/
  373. /* bootstrap by manually inserting "references" and "hassubtype" */
  374. UA_ReferenceTypeNode *references = UA_ReferenceTypeNode_new();
  375. copyNames((UA_Node*)references, "References");
  376. references->nodeId.identifier.numeric = UA_NS0ID_REFERENCES;
  377. references->isAbstract = UA_TRUE;
  378. references->symmetric = UA_TRUE;
  379. // this node has no parent??
  380. UA_NodeStore_insert(server->nodestore, (UA_Node*)references, UA_NULL);
  381. UA_ReferenceTypeNode *hassubtype = UA_ReferenceTypeNode_new();
  382. copyNames((UA_Node*)hassubtype, "HasSubtype");
  383. hassubtype->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "HasSupertype");
  384. hassubtype->nodeId.identifier.numeric = UA_NS0ID_HASSUBTYPE;
  385. hassubtype->isAbstract = UA_FALSE;
  386. hassubtype->symmetric = UA_FALSE;
  387. UA_NodeStore_insert(server->nodestore, (UA_Node*)hassubtype, UA_NULL);
  388. /* continue adding reference types with normal "addnode" */
  389. UA_ReferenceTypeNode *hierarchicalreferences = UA_ReferenceTypeNode_new();
  390. copyNames((UA_Node*)hierarchicalreferences, "Hierarchicalreferences");
  391. hierarchicalreferences->nodeId.identifier.numeric = UA_NS0ID_HIERARCHICALREFERENCES;
  392. hierarchicalreferences->isAbstract = UA_TRUE;
  393. hierarchicalreferences->symmetric = UA_FALSE;
  394. UA_Server_addNode(server, (UA_Node*)hierarchicalreferences,
  395. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_REFERENCES),
  396. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  397. UA_ReferenceTypeNode *nonhierarchicalreferences = UA_ReferenceTypeNode_new();
  398. copyNames((UA_Node*)nonhierarchicalreferences, "NonHierarchicalReferences");
  399. nonhierarchicalreferences->nodeId.identifier.numeric = UA_NS0ID_NONHIERARCHICALREFERENCES;
  400. nonhierarchicalreferences->isAbstract = UA_TRUE;
  401. nonhierarchicalreferences->symmetric = UA_FALSE;
  402. UA_Server_addNode(server, (UA_Node*)nonhierarchicalreferences,
  403. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_REFERENCES),
  404. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  405. UA_ReferenceTypeNode *haschild = UA_ReferenceTypeNode_new();
  406. copyNames((UA_Node*)haschild, "HasChild");
  407. haschild->nodeId.identifier.numeric = UA_NS0ID_HASCHILD;
  408. haschild->isAbstract = UA_TRUE;
  409. haschild->symmetric = UA_FALSE;
  410. UA_Server_addNode(server, (UA_Node*)haschild,
  411. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  412. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  413. UA_ReferenceTypeNode *organizes = UA_ReferenceTypeNode_new();
  414. copyNames((UA_Node*)organizes, "Organizes");
  415. organizes->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "OrganizedBy");
  416. organizes->nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  417. organizes->isAbstract = UA_FALSE;
  418. organizes->symmetric = UA_FALSE;
  419. UA_Server_addNode(server, (UA_Node*)organizes,
  420. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  421. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  422. UA_ReferenceTypeNode *haseventsource = UA_ReferenceTypeNode_new();
  423. copyNames((UA_Node*)haseventsource, "HasEventSource");
  424. haseventsource->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "EventSourceOf");
  425. haseventsource->nodeId.identifier.numeric = UA_NS0ID_HASEVENTSOURCE;
  426. haseventsource->isAbstract = UA_FALSE;
  427. haseventsource->symmetric = UA_FALSE;
  428. UA_Server_addNode(server, (UA_Node*)haseventsource,
  429. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  430. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  431. UA_ReferenceTypeNode *hasmodellingrule = UA_ReferenceTypeNode_new();
  432. copyNames((UA_Node*)hasmodellingrule, "HasModellingRule");
  433. hasmodellingrule->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "ModellingRuleOf");
  434. hasmodellingrule->nodeId.identifier.numeric = UA_NS0ID_HASMODELLINGRULE;
  435. hasmodellingrule->isAbstract = UA_FALSE;
  436. hasmodellingrule->symmetric = UA_FALSE;
  437. UA_Server_addNode(server, (UA_Node*)hasmodellingrule,
  438. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  439. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  440. UA_ReferenceTypeNode *hasencoding = UA_ReferenceTypeNode_new();
  441. copyNames((UA_Node*)hasencoding, "HasEncoding");
  442. hasencoding->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "EncodingOf");
  443. hasencoding->nodeId.identifier.numeric = UA_NS0ID_HASENCODING;
  444. hasencoding->isAbstract = UA_FALSE;
  445. hasencoding->symmetric = UA_FALSE;
  446. UA_Server_addNode(server, (UA_Node*)hasencoding,
  447. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  448. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  449. UA_ReferenceTypeNode *hasdescription = UA_ReferenceTypeNode_new();
  450. copyNames((UA_Node*)hasdescription, "HasDescription");
  451. hasdescription->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "DescriptionOf");
  452. hasdescription->nodeId.identifier.numeric = UA_NS0ID_HASDESCRIPTION;
  453. hasdescription->isAbstract = UA_FALSE;
  454. hasdescription->symmetric = UA_FALSE;
  455. UA_Server_addNode(server, (UA_Node*)hasdescription,
  456. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  457. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  458. UA_ReferenceTypeNode *hastypedefinition = UA_ReferenceTypeNode_new();
  459. copyNames((UA_Node*)hastypedefinition, "HasTypeDefinition");
  460. hastypedefinition->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "TypeDefinitionOf");
  461. hastypedefinition->nodeId.identifier.numeric = UA_NS0ID_HASTYPEDEFINITION;
  462. hastypedefinition->isAbstract = UA_FALSE;
  463. hastypedefinition->symmetric = UA_FALSE;
  464. UA_Server_addNode(server, (UA_Node*)hastypedefinition,
  465. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  466. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  467. UA_ReferenceTypeNode *generatesevent = UA_ReferenceTypeNode_new();
  468. copyNames((UA_Node*)generatesevent, "GeneratesEvent");
  469. generatesevent->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "GeneratedBy");
  470. generatesevent->nodeId.identifier.numeric = UA_NS0ID_GENERATESEVENT;
  471. generatesevent->isAbstract = UA_FALSE;
  472. generatesevent->symmetric = UA_FALSE;
  473. UA_Server_addNode(server, (UA_Node*)generatesevent,
  474. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  475. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  476. UA_ReferenceTypeNode *aggregates = UA_ReferenceTypeNode_new();
  477. copyNames((UA_Node*)aggregates, "Aggregates");
  478. // Todo: Is there an inverse name?
  479. aggregates->nodeId.identifier.numeric = UA_NS0ID_AGGREGATES;
  480. aggregates->isAbstract = UA_TRUE;
  481. aggregates->symmetric = UA_FALSE;
  482. UA_Server_addNode(server, (UA_Node*)aggregates,
  483. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HASCHILD),
  484. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  485. // complete bootstrap of hassubtype
  486. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_HASCHILD), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  487. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  488. UA_ReferenceTypeNode *hasproperty = UA_ReferenceTypeNode_new();
  489. copyNames((UA_Node*)hasproperty, "HasProperty");
  490. hasproperty->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "PropertyOf");
  491. hasproperty->nodeId.identifier.numeric = UA_NS0ID_HASPROPERTY;
  492. hasproperty->isAbstract = UA_FALSE;
  493. hasproperty->symmetric = UA_FALSE;
  494. UA_Server_addNode(server, (UA_Node*)hasproperty,
  495. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_AGGREGATES),
  496. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  497. UA_ReferenceTypeNode *hascomponent = UA_ReferenceTypeNode_new();
  498. copyNames((UA_Node*)hascomponent, "HasComponent");
  499. hascomponent->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "ComponentOf");
  500. hascomponent->nodeId.identifier.numeric = UA_NS0ID_HASCOMPONENT;
  501. hascomponent->isAbstract = UA_FALSE;
  502. hascomponent->symmetric = UA_FALSE;
  503. UA_Server_addNode(server, (UA_Node*)hascomponent,
  504. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_AGGREGATES),
  505. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  506. UA_ReferenceTypeNode *hasnotifier = UA_ReferenceTypeNode_new();
  507. copyNames((UA_Node*)hasnotifier, "HasNotifier");
  508. hasnotifier->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "NotifierOf");
  509. hasnotifier->nodeId.identifier.numeric = UA_NS0ID_HASNOTIFIER;
  510. hasnotifier->isAbstract = UA_FALSE;
  511. hasnotifier->symmetric = UA_FALSE;
  512. UA_Server_addNode(server, (UA_Node*)hasnotifier,
  513. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HASEVENTSOURCE),
  514. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  515. UA_ReferenceTypeNode *hasorderedcomponent = UA_ReferenceTypeNode_new();
  516. copyNames((UA_Node*)hasorderedcomponent, "HasOrderedComponent");
  517. hasorderedcomponent->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "OrderedComponentOf");
  518. hasorderedcomponent->nodeId.identifier.numeric = UA_NS0ID_HASORDEREDCOMPONENT;
  519. hasorderedcomponent->isAbstract = UA_FALSE;
  520. hasorderedcomponent->symmetric = UA_FALSE;
  521. UA_Server_addNode(server, (UA_Node*)hasorderedcomponent,
  522. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  523. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  524. UA_ReferenceTypeNode *hasmodelparent = UA_ReferenceTypeNode_new();
  525. copyNames((UA_Node*)hasmodelparent, "HasModelParent");
  526. hasmodelparent->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "ModelParentOf");
  527. hasmodelparent->nodeId.identifier.numeric = UA_NS0ID_HASMODELPARENT;
  528. hasmodelparent->isAbstract = UA_FALSE;
  529. hasmodelparent->symmetric = UA_FALSE;
  530. UA_Server_addNode(server, (UA_Node*)hasmodelparent,
  531. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  532. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  533. UA_ReferenceTypeNode *fromstate = UA_ReferenceTypeNode_new();
  534. copyNames((UA_Node*)fromstate, "FromState");
  535. fromstate->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "ToTransition");
  536. fromstate->nodeId.identifier.numeric = UA_NS0ID_FROMSTATE;
  537. fromstate->isAbstract = UA_FALSE;
  538. fromstate->symmetric = UA_FALSE;
  539. UA_Server_addNode(server, (UA_Node*)fromstate,
  540. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  541. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  542. UA_ReferenceTypeNode *tostate = UA_ReferenceTypeNode_new();
  543. copyNames((UA_Node*)tostate, "ToState");
  544. tostate->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "FromTransition");
  545. tostate->nodeId.identifier.numeric = UA_NS0ID_TOSTATE;
  546. tostate->isAbstract = UA_FALSE;
  547. tostate->symmetric = UA_FALSE;
  548. UA_Server_addNode(server, (UA_Node*)tostate,
  549. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  550. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  551. UA_ReferenceTypeNode *hascause = UA_ReferenceTypeNode_new();
  552. copyNames((UA_Node*)hascause, "HasCause");
  553. hascause->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "MayBeCausedBy");
  554. hascause->nodeId.identifier.numeric = UA_NS0ID_HASCAUSE;
  555. hascause->isAbstract = UA_FALSE;
  556. hascause->symmetric = UA_FALSE;
  557. UA_Server_addNode(server, (UA_Node*)hascause,
  558. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  559. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  560. UA_ReferenceTypeNode *haseffect = UA_ReferenceTypeNode_new();
  561. copyNames((UA_Node*)haseffect, "HasEffect");
  562. haseffect->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "MayBeEffectedBy");
  563. haseffect->nodeId.identifier.numeric = UA_NS0ID_HASEFFECT;
  564. haseffect->isAbstract = UA_FALSE;
  565. haseffect->symmetric = UA_FALSE;
  566. UA_Server_addNode(server, (UA_Node*)haseffect,
  567. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  568. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  569. UA_ReferenceTypeNode *hashistoricalconfiguration = UA_ReferenceTypeNode_new();
  570. copyNames((UA_Node*)hashistoricalconfiguration, "HasHistoricalConfiguration");
  571. hashistoricalconfiguration->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "HistoricalConfigurationOf");
  572. hashistoricalconfiguration->nodeId.identifier.numeric = UA_NS0ID_HASHISTORICALCONFIGURATION;
  573. hashistoricalconfiguration->isAbstract = UA_FALSE;
  574. hashistoricalconfiguration->symmetric = UA_FALSE;
  575. UA_Server_addNode(server, (UA_Node*)hashistoricalconfiguration,
  576. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_AGGREGATES),
  577. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  578. /**********************/
  579. /* Basic Object Types */
  580. /**********************/
  581. UA_ObjectTypeNode *baseObjectType = UA_ObjectTypeNode_new();
  582. baseObjectType->nodeId.identifier.numeric = UA_NS0ID_BASEOBJECTTYPE;
  583. copyNames((UA_Node*)baseObjectType, "BaseObjectType");
  584. UA_NodeStore_insert(server->nodestore, (UA_Node*)baseObjectType, UA_NULL);
  585. UA_ObjectTypeNode *baseDataVarialbeType = UA_ObjectTypeNode_new();
  586. baseDataVarialbeType->nodeId.identifier.numeric = UA_NS0ID_BASEDATAVARIABLETYPE;
  587. copyNames((UA_Node*)baseDataVarialbeType, "BaseDataVariableType");
  588. UA_NodeStore_insert(server->nodestore, (UA_Node*)baseDataVarialbeType, UA_NULL);
  589. UA_ObjectTypeNode *folderType = UA_ObjectTypeNode_new();
  590. folderType->nodeId.identifier.numeric = UA_NS0ID_FOLDERTYPE;
  591. copyNames((UA_Node*)folderType, "FolderType");
  592. UA_NodeStore_insert(server->nodestore, (UA_Node*)folderType, UA_NULL);
  593. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  594. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  595. /*****************/
  596. /* Basic Folders */
  597. /*****************/
  598. UA_ObjectNode *root = UA_ObjectNode_new();
  599. copyNames((UA_Node*)root, "Root");
  600. root->nodeId.identifier.numeric = UA_NS0ID_ROOTFOLDER;
  601. UA_NodeStore_insert(server->nodestore, (UA_Node*)root, UA_NULL);
  602. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  603. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  604. UA_ObjectNode *objects = UA_ObjectNode_new();
  605. copyNames((UA_Node*)objects, "Objects");
  606. objects->nodeId.identifier.numeric = UA_NS0ID_OBJECTSFOLDER;
  607. UA_Server_addNode(server, (UA_Node*)objects,
  608. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER),
  609. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  610. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  611. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  612. UA_ObjectNode *types = UA_ObjectNode_new();
  613. copyNames((UA_Node*)types, "Types");
  614. types->nodeId.identifier.numeric = UA_NS0ID_TYPESFOLDER;
  615. UA_Server_addNode(server, (UA_Node*)types,
  616. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER),
  617. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  618. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_TYPESFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  619. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  620. UA_ObjectNode *views = UA_ObjectNode_new();
  621. copyNames((UA_Node*)views, "Views");
  622. views->nodeId.identifier.numeric = UA_NS0ID_VIEWSFOLDER;
  623. UA_Server_addNode(server, (UA_Node*)views,
  624. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER),
  625. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  626. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  627. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  628. /**********************/
  629. /* Further Data Types */
  630. /**********************/
  631. UA_ObjectNode *datatypes = UA_ObjectNode_new();
  632. copyNames((UA_Node*)datatypes, "DataTypes");
  633. datatypes->nodeId.identifier.numeric = UA_NS0ID_DATATYPESFOLDER;
  634. UA_Server_addNode(server, (UA_Node*)datatypes,
  635. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_TYPESFOLDER),
  636. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  637. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_DATATYPESFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  638. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  639. addDataTypeNode(server, "BaseDataType", UA_NS0ID_BASEDATATYPE, UA_NS0ID_DATATYPESFOLDER);
  640. addDataTypeNode(server, "Boolean", UA_NS0ID_BOOLEAN, UA_NS0ID_BASEDATATYPE);
  641. addDataTypeNode(server, "Number", UA_NS0ID_NUMBER, UA_NS0ID_BASEDATATYPE);
  642. addDataTypeNode(server, "Float", UA_NS0ID_FLOAT, UA_NS0ID_NUMBER);
  643. addDataTypeNode(server, "Double", UA_NS0ID_DOUBLE, UA_NS0ID_NUMBER);
  644. addDataTypeNode(server, "Integer", UA_NS0ID_INTEGER, UA_NS0ID_NUMBER);
  645. addDataTypeNode(server, "SByte", UA_NS0ID_SBYTE, UA_NS0ID_INTEGER);
  646. addDataTypeNode(server, "Int16", UA_NS0ID_INT16, UA_NS0ID_INTEGER);
  647. addDataTypeNode(server, "Int32", UA_NS0ID_INT32, UA_NS0ID_INTEGER);
  648. addDataTypeNode(server, "Int64", UA_NS0ID_INT64, UA_NS0ID_INTEGER);
  649. addDataTypeNode(server, "UInteger", UA_NS0ID_UINTEGER, UA_NS0ID_INTEGER);
  650. addDataTypeNode(server, "Byte", UA_NS0ID_BYTE, UA_NS0ID_UINTEGER);
  651. addDataTypeNode(server, "UInt16", UA_NS0ID_UINT16, UA_NS0ID_UINTEGER);
  652. addDataTypeNode(server, "UInt32", UA_NS0ID_UINT32, UA_NS0ID_UINTEGER);
  653. addDataTypeNode(server, "UInt64", UA_NS0ID_UINT64, UA_NS0ID_UINTEGER);
  654. addDataTypeNode(server, "String", UA_NS0ID_STRING, UA_NS0ID_BASEDATATYPE);
  655. addDataTypeNode(server, "DateTime", UA_NS0ID_DATETIME, UA_NS0ID_BASEDATATYPE);
  656. addDataTypeNode(server, "Guid", UA_NS0ID_GUID, UA_NS0ID_BASEDATATYPE);
  657. addDataTypeNode(server, "ByteString", UA_NS0ID_BYTESTRING, UA_NS0ID_BASEDATATYPE);
  658. addDataTypeNode(server, "XmlElement", UA_NS0ID_XMLELEMENT, UA_NS0ID_BASEDATATYPE);
  659. addDataTypeNode(server, "NodeId", UA_NS0ID_NODEID, UA_NS0ID_BASEDATATYPE);
  660. addDataTypeNode(server, "ExpandedNodeId", UA_NS0ID_EXPANDEDNODEID, UA_NS0ID_BASEDATATYPE);
  661. addDataTypeNode(server, "StatusCode", UA_NS0ID_STATUSCODE, UA_NS0ID_BASEDATATYPE);
  662. addDataTypeNode(server, "QualifiedName", UA_NS0ID_QUALIFIEDNAME, UA_NS0ID_BASEDATATYPE);
  663. addDataTypeNode(server, "LocalizedText", UA_NS0ID_LOCALIZEDTEXT, UA_NS0ID_BASEDATATYPE);
  664. addDataTypeNode(server, "Structure", UA_NS0ID_STRUCTURE, UA_NS0ID_BASEDATATYPE);
  665. addDataTypeNode(server, "DataValue", UA_NS0ID_DATAVALUE, UA_NS0ID_BASEDATATYPE);
  666. addDataTypeNode(server, "DiagnosticInfo", UA_NS0ID_DIAGNOSTICINFO, UA_NS0ID_BASEDATATYPE);
  667. addDataTypeNode(server, "Enumeration", UA_NS0ID_ENUMERATION, UA_NS0ID_BASEDATATYPE);
  668. addDataTypeNode(server, "ServerState", UA_NS0ID_SERVERSTATE, UA_NS0ID_ENUMERATION);
  669. UA_ObjectNode *variabletypes = UA_ObjectNode_new();
  670. copyNames((UA_Node*)variabletypes, "VariableTypes");
  671. variabletypes->nodeId.identifier.numeric = UA_NS0ID_VARIABLETYPESFOLDER;
  672. UA_Server_addNode(server, (UA_Node*)variabletypes,
  673. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_TYPESFOLDER),
  674. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  675. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_VARIABLETYPESFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  676. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  677. addVariableTypeNode_organized(server, "BaseVariableType", UA_NS0ID_BASEVARIABLETYPE, UA_NS0ID_VARIABLETYPESFOLDER, UA_TRUE);
  678. addVariableTypeNode_subtype(server, "PropertyType", UA_NS0ID_PROPERTYTYPE, UA_NS0ID_BASEVARIABLETYPE, UA_FALSE);
  679. /****************/
  680. /* Object Types */
  681. /****************/
  682. UA_ObjectNode *objecttypes = UA_ObjectNode_new();
  683. copyNames((UA_Node*)objecttypes, "ObjectTypes");
  684. objecttypes->nodeId.identifier.numeric = UA_NS0ID_OBJECTTYPESFOLDER;
  685. UA_Server_addNode(server, (UA_Node*)objecttypes,
  686. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_TYPESFOLDER),
  687. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  688. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTTYPESFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  689. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  690. addObjectTypeNode(server, "BaseObjectType", UA_NS0ID_BASEOBJECTTYPE, UA_NS0ID_OBJECTTYPESFOLDER);
  691. /*******************/
  692. /* Further Objects */
  693. /*******************/
  694. UA_ObjectNode *servernode = UA_ObjectNode_new();
  695. copyNames((UA_Node*)servernode, "Server");
  696. servernode->nodeId.identifier.numeric = UA_NS0ID_SERVER;
  697. UA_Server_addNode(server, (UA_Node*)servernode,
  698. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  699. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  700. UA_VariableNode *namespaceArray = UA_VariableNode_new();
  701. copyNames((UA_Node*)namespaceArray, "NamespaceArray");
  702. namespaceArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_NAMESPACEARRAY;
  703. namespaceArray->valueSource = UA_VALUESOURCE_DATASOURCE;
  704. namespaceArray->value.dataSource = (UA_DataSource) {.handle = server, .read = readNamespaces,
  705. .release = releaseNamespaces, .write = UA_NULL};
  706. namespaceArray->valueRank = 1;
  707. namespaceArray->minimumSamplingInterval = 1.0;
  708. namespaceArray->historizing = UA_FALSE;
  709. UA_Server_addNode(server, (UA_Node*)namespaceArray,
  710. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  711. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY));
  712. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_NAMESPACEARRAY),
  713. UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  714. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
  715. UA_VariableNode *serverArray = UA_VariableNode_new();
  716. copyNames((UA_Node*)serverArray, "ServerArray");
  717. serverArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERARRAY;
  718. serverArray->value.variant.data = UA_Array_new(&UA_TYPES[UA_TYPES_STRING], 1);
  719. serverArray->value.variant.arrayLength = 1;
  720. serverArray->value.variant.type = &UA_TYPES[UA_TYPES_STRING];
  721. *(UA_String *)serverArray->value.variant.data = UA_STRING_ALLOC(server->config.Application_applicationURI);
  722. serverArray->valueRank = 1;
  723. serverArray->minimumSamplingInterval = 1.0;
  724. serverArray->historizing = UA_FALSE;
  725. UA_Server_addNode(server, (UA_Node*)serverArray,
  726. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  727. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY));
  728. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERARRAY),
  729. UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  730. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
  731. UA_ObjectNode *servercapablities = UA_ObjectNode_new();
  732. copyNames((UA_Node*)servercapablities, "ServerCapabilities");
  733. servercapablities->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERCAPABILITIES;
  734. UA_Server_addNode(server, (UA_Node*)servercapablities,
  735. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  736. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT));
  737. UA_VariableNode *localeIdArray = UA_VariableNode_new();
  738. copyNames((UA_Node*)localeIdArray, "LocaleIdArray");
  739. localeIdArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERCAPABILITIES_LOCALEIDARRAY;
  740. localeIdArray->value.variant.data = UA_Array_new(&UA_TYPES[UA_TYPES_STRING], 1);
  741. localeIdArray->value.variant.arrayLength = 1;
  742. localeIdArray->value.variant.type = &UA_TYPES[UA_TYPES_STRING];
  743. *(UA_String *)localeIdArray->value.variant.data = UA_STRING_ALLOC("en");
  744. localeIdArray->valueRank = 1;
  745. localeIdArray->minimumSamplingInterval = 1.0;
  746. localeIdArray->historizing = UA_FALSE;
  747. UA_Server_addNode(server, (UA_Node*)localeIdArray,
  748. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERCAPABILITIES),
  749. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY));
  750. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERCAPABILITIES_LOCALEIDARRAY), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  751. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
  752. UA_ObjectNode *serverdiagnostics = UA_ObjectNode_new();
  753. copyNames((UA_Node*)serverdiagnostics, "ServerDiagnostics");
  754. serverdiagnostics->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERDIAGNOSTICS;
  755. UA_Server_addNode(server, (UA_Node*)serverdiagnostics,
  756. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  757. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT));
  758. UA_VariableNode *enabledFlag = UA_VariableNode_new();
  759. copyNames((UA_Node*)enabledFlag, "EnabledFlag");
  760. enabledFlag->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERDIAGNOSTICS_ENABLEDFLAG;
  761. enabledFlag->value.variant.data = UA_Boolean_new(); //itialized as false
  762. enabledFlag->value.variant.type = &UA_TYPES[UA_TYPES_BOOLEAN];
  763. enabledFlag->valueRank = 1;
  764. enabledFlag->minimumSamplingInterval = 1.0;
  765. enabledFlag->historizing = UA_FALSE;
  766. UA_Server_addNode(server, (UA_Node*)enabledFlag,
  767. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERDIAGNOSTICS),
  768. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY));
  769. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERDIAGNOSTICS_ENABLEDFLAG), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  770. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
  771. UA_VariableNode *serverstatus = UA_VariableNode_new();
  772. copyNames((UA_Node*)serverstatus, "ServerStatus");
  773. serverstatus->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS);
  774. serverstatus->valueSource = UA_VALUESOURCE_DATASOURCE;
  775. serverstatus->value.dataSource = (UA_DataSource) {.handle = server, .read = readStatus,
  776. .release = releaseStatus, .write = UA_NULL};
  777. UA_Server_addNode(server, (UA_Node*)serverstatus, &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  778. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT));
  779. UA_VariableNode *state = UA_VariableNode_new();
  780. UA_ServerState *stateEnum = UA_ServerState_new();
  781. *stateEnum = UA_SERVERSTATE_RUNNING;
  782. copyNames((UA_Node*)state, "State");
  783. state->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERSTATUS_STATE;
  784. state->value.variant.type = &UA_TYPES[UA_TYPES_SERVERSTATE];
  785. state->value.variant.arrayLength = -1;
  786. state->value.variant.data = stateEnum; // points into the other object.
  787. UA_NodeStore_insert(server->nodestore, (UA_Node*)state, UA_NULL);
  788. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS), UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  789. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE));
  790. UA_VariableNode *currenttime = UA_VariableNode_new();
  791. copyNames((UA_Node*)currenttime, "CurrentTime");
  792. currenttime->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  793. currenttime->valueSource = UA_VALUESOURCE_DATASOURCE;
  794. currenttime->value.dataSource = (UA_DataSource) {.handle = NULL, .read = readCurrentTime,
  795. .release = releaseCurrentTime, .write = UA_NULL};
  796. UA_Server_addNode(server, (UA_Node*)currenttime, &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS),
  797. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT));
  798. #ifdef DEMO_NODESET
  799. /**************/
  800. /* Demo Nodes */
  801. /**************/
  802. #define DEMOID 990
  803. UA_ObjectNode *demo = UA_ObjectNode_new();
  804. copyNames((UA_Node*)demo, "Demo");
  805. demo->nodeId = UA_NODEID_NUMERIC(1, DEMOID);
  806. UA_Server_addNode(server, (UA_Node*)demo,
  807. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  808. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  809. ADDREFERENCE(UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  810. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  811. #define SCALARID 991
  812. UA_ObjectNode *scalar = UA_ObjectNode_new();
  813. copyNames((UA_Node*)scalar, "Scalar");
  814. scalar->nodeId = UA_NODEID_NUMERIC(1, SCALARID);
  815. UA_Server_addNode(server, (UA_Node*)scalar,
  816. &UA_EXPANDEDNODEID_NUMERIC(1, DEMOID),
  817. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  818. ADDREFERENCE(UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  819. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  820. #define ARRAYID 992
  821. UA_ObjectNode *array = UA_ObjectNode_new();
  822. copyNames((UA_Node*)array, "Arrays");
  823. array->nodeId = UA_NODEID_NUMERIC(1, ARRAYID);
  824. UA_Server_addNode(server, (UA_Node*)array,
  825. &UA_EXPANDEDNODEID_NUMERIC(1, DEMOID),
  826. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  827. ADDREFERENCE(UA_NODEID_NUMERIC(1, ARRAYID), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  828. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  829. UA_UInt32 id = 1000; //running id in namespace 1
  830. for(UA_UInt32 type = 0; UA_IS_BUILTIN(type); type++) {
  831. if(type == UA_TYPES_VARIANT || type == UA_TYPES_DIAGNOSTICINFO)
  832. continue;
  833. //add a scalar node for every built-in type
  834. void *value = UA_new(&UA_TYPES[type]);
  835. UA_Variant *variant = UA_Variant_new();
  836. UA_Variant_setScalar(variant, value, &UA_TYPES[type]);
  837. char name[15];
  838. sprintf(name, "%02d", type);
  839. UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, name);
  840. UA_Server_addVariableNode(server, variant, myIntegerName, UA_NODEID_NUMERIC(1, ++id),
  841. UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  842. //add an array node for every built-in type
  843. UA_Variant *arrayvar = UA_Variant_new();
  844. UA_Variant_setArray(arrayvar, UA_Array_new(&UA_TYPES[type], 10), 10, &UA_TYPES[type]);
  845. UA_Server_addVariableNode(server, arrayvar, myIntegerName, UA_NODEID_NUMERIC(1, ++id),
  846. UA_NODEID_NUMERIC(1, ARRAYID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  847. }
  848. #endif
  849. return server;
  850. }