ua_server.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright 2014-2018 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2014-2017 (c) Florian Palm
  7. * Copyright 2015-2016 (c) Sten Grüner
  8. * Copyright 2015-2016 (c) Chris Iatrou
  9. * Copyright 2015 (c) LEvertz
  10. * Copyright 2015-2016 (c) Oleksiy Vasylyev
  11. * Copyright 2016 (c) Julian Grothoff
  12. * Copyright 2016-2017 (c) Stefan Profanter, fortiss GmbH
  13. * Copyright 2016 (c) Lorenz Haas
  14. * Copyright 2017 (c) frax2222
  15. * Copyright 2017 (c) Mark Giraud, Fraunhofer IOSB
  16. * Copyright 2018 (c) Hilscher Gesellschaft für Systemautomation mbH (Author: Martin Lang)
  17. */
  18. #include "ua_server_internal.h"
  19. #ifdef UA_ENABLE_PUBSUB_INFORMATIONMODEL
  20. #include "ua_pubsub_ns0.h"
  21. #endif
  22. #ifdef UA_ENABLE_SUBSCRIPTIONS
  23. #include "ua_subscription.h"
  24. #endif
  25. #ifdef UA_ENABLE_VALGRIND_INTERACTIVE
  26. #include <valgrind/memcheck.h>
  27. #endif
  28. /**********************/
  29. /* Namespace Handling */
  30. /**********************/
  31. UA_UInt16 addNamespace(UA_Server *server, const UA_String name) {
  32. /* Check if the namespace already exists in the server's namespace array */
  33. for(UA_UInt16 i = 0; i < server->namespacesSize; ++i) {
  34. if(UA_String_equal(&name, &server->namespaces[i]))
  35. return i;
  36. }
  37. /* Make the array bigger */
  38. UA_String *newNS = (UA_String*)UA_realloc(server->namespaces,
  39. sizeof(UA_String) * (server->namespacesSize + 1));
  40. if(!newNS)
  41. return 0;
  42. server->namespaces = newNS;
  43. /* Copy the namespace string */
  44. UA_StatusCode retval = UA_String_copy(&name, &server->namespaces[server->namespacesSize]);
  45. if(retval != UA_STATUSCODE_GOOD)
  46. return 0;
  47. /* Announce the change (otherwise, the array appears unchanged) */
  48. ++server->namespacesSize;
  49. return (UA_UInt16)(server->namespacesSize - 1);
  50. }
  51. UA_UInt16 UA_Server_addNamespace(UA_Server *server, const char* name) {
  52. /* Override const attribute to get string (dirty hack) */
  53. UA_String nameString;
  54. nameString.length = strlen(name);
  55. nameString.data = (UA_Byte*)(uintptr_t)name;
  56. return addNamespace(server, nameString);
  57. }
  58. UA_ServerConfig*
  59. UA_Server_getConfig(UA_Server *server)
  60. {
  61. if(!server)
  62. return NULL;
  63. return &server->config;
  64. }
  65. UA_StatusCode
  66. UA_Server_getNamespaceByName(UA_Server *server, const UA_String namespaceUri,
  67. size_t* foundIndex) {
  68. for(size_t idx = 0; idx < server->namespacesSize; idx++) {
  69. if(!UA_String_equal(&server->namespaces[idx], &namespaceUri))
  70. continue;
  71. (*foundIndex) = idx;
  72. return UA_STATUSCODE_GOOD;
  73. }
  74. return UA_STATUSCODE_BADNOTFOUND;
  75. }
  76. UA_StatusCode
  77. UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId,
  78. UA_NodeIteratorCallback callback, void *handle) {
  79. const UA_Node *parent = UA_Nodestore_getNode(server->nsCtx, &parentNodeId);
  80. if(!parent)
  81. return UA_STATUSCODE_BADNODEIDINVALID;
  82. /* TODO: We need to do an ugly copy of the references array since users may
  83. * delete references from within the callback. In single-threaded mode this
  84. * changes the same node we point at here. In multi-threaded mode, this
  85. * creates a new copy as nodes are truly immutable.
  86. * The callback could remove a node via the regular public API.
  87. * This can remove a member of the nodes-array we iterate over...
  88. * */
  89. UA_Node *parentCopy = UA_Node_copy_alloc(parent);
  90. if(!parentCopy) {
  91. UA_Nodestore_releaseNode(server->nsCtx, parent);
  92. return UA_STATUSCODE_BADUNEXPECTEDERROR;
  93. }
  94. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  95. for(size_t i = parentCopy->referencesSize; i > 0; --i) {
  96. UA_NodeReferenceKind *ref = &parentCopy->references[i - 1];
  97. for(size_t j = 0; j<ref->targetIdsSize; j++) {
  98. retval = callback(ref->targetIds[j].nodeId, ref->isInverse,
  99. ref->referenceTypeId, handle);
  100. if(retval != UA_STATUSCODE_GOOD)
  101. goto cleanup;
  102. }
  103. }
  104. cleanup:
  105. UA_Node_deleteMembers(parentCopy);
  106. UA_free(parentCopy);
  107. UA_Nodestore_releaseNode(server->nsCtx, parent);
  108. return retval;
  109. }
  110. /********************/
  111. /* Server Lifecycle */
  112. /********************/
  113. /* The server needs to be stopped before it can be deleted */
  114. void UA_Server_delete(UA_Server *server) {
  115. /* Delete all internal data */
  116. UA_SecureChannelManager_deleteMembers(&server->secureChannelManager);
  117. UA_SessionManager_deleteMembers(&server->sessionManager);
  118. UA_Array_delete(server->namespaces, server->namespacesSize, &UA_TYPES[UA_TYPES_STRING]);
  119. #ifdef UA_ENABLE_SUBSCRIPTIONS
  120. UA_MonitoredItem *mon, *mon_tmp;
  121. LIST_FOREACH_SAFE(mon, &server->localMonitoredItems, listEntry, mon_tmp) {
  122. LIST_REMOVE(mon, listEntry);
  123. UA_MonitoredItem_delete(server, mon);
  124. }
  125. #endif
  126. #ifdef UA_ENABLE_PUBSUB
  127. UA_PubSubManager_delete(server, &server->pubSubManager);
  128. #endif
  129. #ifdef UA_ENABLE_DISCOVERY
  130. UA_DiscoveryManager_deleteMembers(&server->discoveryManager, server);
  131. #endif
  132. /* Clean up the Admin Session */
  133. UA_Session_deleteMembersCleanup(&server->adminSession, server);
  134. /* Clean up the work queue */
  135. UA_WorkQueue_cleanup(&server->workQueue);
  136. /* Delete the timed work */
  137. UA_Timer_deleteMembers(&server->timer);
  138. /* Clean up the nodestore */
  139. UA_Nodestore_delete(server->nsCtx);
  140. /* Clean up the config */
  141. UA_ServerConfig_clean(&server->config);
  142. /* Delete the server itself */
  143. UA_free(server);
  144. }
  145. /* Recurring cleanup. Removing unused and timed-out channels and sessions */
  146. static void
  147. UA_Server_cleanup(UA_Server *server, void *_) {
  148. UA_DateTime nowMonotonic = UA_DateTime_nowMonotonic();
  149. UA_SessionManager_cleanupTimedOut(&server->sessionManager, nowMonotonic);
  150. UA_SecureChannelManager_cleanupTimedOut(&server->secureChannelManager, nowMonotonic);
  151. #ifdef UA_ENABLE_DISCOVERY
  152. UA_Discovery_cleanupTimedOut(server, nowMonotonic);
  153. #endif
  154. }
  155. /********************/
  156. /* Server Lifecycle */
  157. /********************/
  158. UA_Server *
  159. UA_Server_new() {
  160. /* Allocate the server */
  161. UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
  162. if(!server)
  163. return NULL;
  164. /* Init start time to zero, the actual start time will be sampled in
  165. * UA_Server_run_startup() */
  166. server->startTime = 0;
  167. /* Set a seed for non-cyptographic randomness */
  168. #ifndef UA_ENABLE_DETERMINISTIC_RNG
  169. UA_random_seed((UA_UInt64)UA_DateTime_now());
  170. #endif
  171. /* Initialize the handling of repeated callbacks */
  172. UA_Timer_init(&server->timer);
  173. UA_WorkQueue_init(&server->workQueue);
  174. /* Initialize the adminSession */
  175. UA_Session_init(&server->adminSession);
  176. server->adminSession.sessionId.identifierType = UA_NODEIDTYPE_GUID;
  177. server->adminSession.sessionId.identifier.guid.data1 = 1;
  178. server->adminSession.validTill = UA_INT64_MAX;
  179. /* Create Namespaces 0 and 1 */
  180. server->namespaces = (UA_String *)UA_Array_new(2, &UA_TYPES[UA_TYPES_STRING]);
  181. if(!server->namespaces) {
  182. UA_Server_delete(server);
  183. return NULL;
  184. }
  185. server->namespaces[0] = UA_STRING_ALLOC("http://opcfoundation.org/UA/");
  186. UA_String_copy(&server->config.applicationDescription.applicationUri, &server->namespaces[1]);
  187. server->namespacesSize = 2;
  188. /* Initialized SecureChannel and Session managers */
  189. UA_SecureChannelManager_init(&server->secureChannelManager, server);
  190. UA_SessionManager_init(&server->sessionManager, server);
  191. /* Add a regular callback for cleanup and maintenance. With a 10s interval. */
  192. UA_Server_addRepeatedCallback(server, (UA_ServerCallback)UA_Server_cleanup, NULL,
  193. 10000.0, NULL);
  194. /* Initialize namespace 0*/
  195. UA_StatusCode retVal = UA_Nodestore_new(&server->nsCtx);
  196. if(retVal != UA_STATUSCODE_GOOD)
  197. goto cleanup;
  198. retVal = UA_Server_initNS0(server);
  199. if(retVal != UA_STATUSCODE_GOOD)
  200. goto cleanup;
  201. /* Build PubSub information model */
  202. #ifdef UA_ENABLE_PUBSUB_INFORMATIONMODEL
  203. UA_Server_initPubSubNS0(server);
  204. #endif
  205. return server;
  206. cleanup:
  207. UA_Server_delete(server);
  208. return NULL;
  209. }
  210. /*******************/
  211. /* Timed Callbacks */
  212. /*******************/
  213. UA_StatusCode
  214. UA_Server_addTimedCallback(UA_Server *server, UA_ServerCallback callback,
  215. void *data, UA_DateTime date, UA_UInt64 *callbackId) {
  216. return UA_Timer_addTimedCallback(&server->timer,
  217. (UA_ApplicationCallback)callback,
  218. server, data, date, callbackId);
  219. }
  220. UA_StatusCode
  221. UA_Server_addRepeatedCallback(UA_Server *server, UA_ServerCallback callback,
  222. void *data, UA_Double interval_ms,
  223. UA_UInt64 *callbackId) {
  224. return UA_Timer_addRepeatedCallback(&server->timer,
  225. (UA_ApplicationCallback)callback,
  226. server, data, interval_ms, callbackId);
  227. }
  228. UA_StatusCode
  229. UA_Server_changeRepeatedCallbackInterval(UA_Server *server, UA_UInt64 callbackId,
  230. UA_Double interval_ms) {
  231. return UA_Timer_changeRepeatedCallbackInterval(&server->timer, callbackId,
  232. interval_ms);
  233. }
  234. void
  235. UA_Server_removeCallback(UA_Server *server, UA_UInt64 callbackId) {
  236. UA_Timer_removeCallback(&server->timer, callbackId);
  237. }
  238. UA_StatusCode UA_EXPORT
  239. UA_Server_updateCertificate(UA_Server *server,
  240. const UA_ByteString *oldCertificate,
  241. const UA_ByteString *newCertificate,
  242. const UA_ByteString *newPrivateKey,
  243. UA_Boolean closeSessions,
  244. UA_Boolean closeSecureChannels) {
  245. if (server == NULL || oldCertificate == NULL
  246. || newCertificate == NULL || newPrivateKey == NULL) {
  247. return UA_STATUSCODE_BADINTERNALERROR;
  248. }
  249. if (closeSessions) {
  250. UA_SessionManager *sm = &server->sessionManager;
  251. session_list_entry *current;
  252. LIST_FOREACH(current, &sm->sessions, pointers) {
  253. if (UA_ByteString_equal(oldCertificate,
  254. &current->session.header.channel->securityPolicy->localCertificate)) {
  255. UA_SessionManager_removeSession(sm, &current->session.header.authenticationToken);
  256. }
  257. }
  258. }
  259. if (closeSecureChannels) {
  260. UA_SecureChannelManager *cm = &server->secureChannelManager;
  261. channel_entry *entry;
  262. TAILQ_FOREACH(entry, &cm->channels, pointers) {
  263. if(UA_ByteString_equal(&entry->channel.securityPolicy->localCertificate, oldCertificate)){
  264. UA_SecureChannelManager_close(cm, entry->channel.securityToken.channelId);
  265. }
  266. }
  267. }
  268. size_t i = 0;
  269. while (i < server->config.endpointsSize) {
  270. UA_EndpointDescription *ed = &server->config.endpoints[i];
  271. if (UA_ByteString_equal(&ed->serverCertificate, oldCertificate)) {
  272. UA_String_deleteMembers(&ed->serverCertificate);
  273. UA_String_copy(newCertificate, &ed->serverCertificate);
  274. UA_SecurityPolicy *sp = UA_SecurityPolicy_getSecurityPolicyByUri(server, &server->config.endpoints[i].securityPolicyUri);
  275. if(!sp)
  276. return UA_STATUSCODE_BADINTERNALERROR;
  277. sp->updateCertificateAndPrivateKey(sp, *newCertificate, *newPrivateKey);
  278. }
  279. i++;
  280. }
  281. return UA_STATUSCODE_GOOD;
  282. }
  283. /***************************/
  284. /* Server lookup functions */
  285. /***************************/
  286. UA_SecurityPolicy *
  287. UA_SecurityPolicy_getSecurityPolicyByUri(const UA_Server *server,
  288. UA_ByteString *securityPolicyUri)
  289. {
  290. for(size_t i = 0; i < server->config.securityPoliciesSize; i++) {
  291. UA_SecurityPolicy *securityPolicyCandidate = &server->config.securityPolicies[i];
  292. if(UA_ByteString_equal(securityPolicyUri,
  293. &securityPolicyCandidate->policyUri))
  294. return securityPolicyCandidate;
  295. }
  296. return NULL;
  297. }
  298. #ifdef UA_ENABLE_ENCRYPTION
  299. /* The local ApplicationURI has to match the certificates of the
  300. * SecurityPolicies */
  301. static void
  302. verifyServerApplicationURI(const UA_Server *server) {
  303. #if UA_LOGLEVEL <= 400
  304. for(size_t i = 0; i < server->config.securityPoliciesSize; i++) {
  305. UA_SecurityPolicy *sp = &server->config.securityPolicies[i];
  306. if(!sp->certificateVerification)
  307. continue;
  308. UA_StatusCode retval =
  309. sp->certificateVerification->
  310. verifyApplicationURI(sp->certificateVerification->context,
  311. &sp->localCertificate,
  312. &server->config.applicationDescription.applicationUri);
  313. if(retval != UA_STATUSCODE_GOOD) {
  314. UA_LOG_WARNING(&server->config.logger, UA_LOGCATEGORY_SERVER,
  315. "The configured ApplicationURI does not match the URI "
  316. "specified in the certificate for the SecurityPolicy %.*s",
  317. (int)sp->policyUri.length, sp->policyUri.data);
  318. }
  319. }
  320. #endif
  321. }
  322. #endif
  323. /********************/
  324. /* Main Server Loop */
  325. /********************/
  326. #define UA_MAXTIMEOUT 50 /* Max timeout in ms between main-loop iterations */
  327. /* Start: Spin up the workers and the network layer and sample the server's
  328. * start time.
  329. * Iterate: Process repeated callbacks and events in the network layer. This
  330. * part can be driven from an external main-loop in an event-driven
  331. * single-threaded architecture.
  332. * Stop: Stop workers, finish all callbacks, stop the network layer, clean up */
  333. UA_StatusCode
  334. UA_Server_run_startup(UA_Server *server) {
  335. if(server->state > UA_SERVERLIFECYCLE_FRESH)
  336. return UA_STATUSCODE_GOOD;
  337. /* At least one endpoint has to be configured */
  338. if(server->config.endpointsSize == 0) {
  339. UA_LOG_WARNING(&server->config.logger, UA_LOGCATEGORY_SERVER,
  340. "There has to be at least one endpoint.");
  341. }
  342. /* Initialized discovery */
  343. #ifdef UA_ENABLE_DISCOVERY
  344. UA_DiscoveryManager_init(&server->discoveryManager, server);
  345. #endif
  346. /* Does the ApplicationURI match the local certificates? */
  347. #ifdef UA_ENABLE_ENCRYPTION
  348. verifyServerApplicationURI(server);
  349. #endif
  350. /* Sample the start time and set it to the Server object */
  351. server->startTime = UA_DateTime_now();
  352. UA_Variant var;
  353. UA_Variant_init(&var);
  354. UA_Variant_setScalar(&var, &server->startTime, &UA_TYPES[UA_TYPES_DATETIME]);
  355. UA_Server_writeValue(server,
  356. UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STARTTIME),
  357. var);
  358. /* Start the networklayers */
  359. UA_StatusCode result = UA_STATUSCODE_GOOD;
  360. for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
  361. UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
  362. result |= nl->start(nl, &server->config.customHostname);
  363. }
  364. /* Spin up the worker threads */
  365. #ifdef UA_ENABLE_MULTITHREADING
  366. UA_LOG_INFO(&server->config.logger, UA_LOGCATEGORY_SERVER,
  367. "Spinning up %u worker thread(s)", server->config.nThreads);
  368. UA_WorkQueue_start(&server->workQueue, server->config.nThreads);
  369. #endif
  370. /* Start the multicast discovery server */
  371. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  372. if(server->config.discovery.mdnsEnable)
  373. startMulticastDiscoveryServer(server);
  374. #endif
  375. server->state = UA_SERVERLIFECYCLE_FRESH;
  376. return result;
  377. }
  378. static void
  379. serverExecuteRepeatedCallback(UA_Server *server, UA_ApplicationCallback cb,
  380. void *callbackApplication, void *data) {
  381. #ifndef UA_ENABLE_MULTITHREADING
  382. cb(callbackApplication, data);
  383. #else
  384. UA_WorkQueue_enqueue(&server->workQueue, cb, callbackApplication, data);
  385. #endif
  386. }
  387. UA_UInt16
  388. UA_Server_run_iterate(UA_Server *server, UA_Boolean waitInternal) {
  389. /* Process repeated work */
  390. UA_DateTime now = UA_DateTime_nowMonotonic();
  391. UA_DateTime nextRepeated = UA_Timer_process(&server->timer, now,
  392. (UA_TimerExecutionCallback)serverExecuteRepeatedCallback, server);
  393. UA_DateTime latest = now + (UA_MAXTIMEOUT * UA_DATETIME_MSEC);
  394. if(nextRepeated > latest)
  395. nextRepeated = latest;
  396. UA_UInt16 timeout = 0;
  397. /* round always to upper value to avoid timeout to be set to 0
  398. * if(nextRepeated - now) < (UA_DATETIME_MSEC/2) */
  399. if(waitInternal)
  400. timeout = (UA_UInt16)(((nextRepeated - now) + (UA_DATETIME_MSEC - 1)) / UA_DATETIME_MSEC);
  401. /* Listen on the networklayer */
  402. for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
  403. UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
  404. nl->listen(nl, server, timeout);
  405. }
  406. #if defined(UA_ENABLE_DISCOVERY_MULTICAST) && !defined(UA_ENABLE_MULTITHREADING)
  407. if(server->config.discovery.mdnsEnable) {
  408. // TODO multicastNextRepeat does not consider new input data (requests)
  409. // on the socket. It will be handled on the next call. if needed, we
  410. // need to use select with timeout on the multicast socket
  411. // server->mdnsSocket (see example in mdnsd library) on higher level.
  412. UA_DateTime multicastNextRepeat = 0;
  413. UA_StatusCode hasNext =
  414. iterateMulticastDiscoveryServer(server, &multicastNextRepeat, true);
  415. if(hasNext == UA_STATUSCODE_GOOD && multicastNextRepeat < nextRepeated)
  416. nextRepeated = multicastNextRepeat;
  417. }
  418. #endif
  419. #ifndef UA_ENABLE_MULTITHREADING
  420. UA_WorkQueue_manuallyProcessDelayed(&server->workQueue);
  421. #endif
  422. now = UA_DateTime_nowMonotonic();
  423. timeout = 0;
  424. if(nextRepeated > now)
  425. timeout = (UA_UInt16)((nextRepeated - now) / UA_DATETIME_MSEC);
  426. return timeout;
  427. }
  428. UA_StatusCode
  429. UA_Server_run_shutdown(UA_Server *server) {
  430. /* Stop the netowrk layer */
  431. for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
  432. UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
  433. nl->stop(nl, server);
  434. }
  435. #ifdef UA_ENABLE_MULTITHREADING
  436. /* Shut down the workers */
  437. UA_LOG_INFO(&server->config.logger, UA_LOGCATEGORY_SERVER,
  438. "Shutting down %u worker thread(s)",
  439. (UA_UInt32)server->workQueue.workersSize);
  440. UA_WorkQueue_stop(&server->workQueue);
  441. #endif
  442. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  443. /* Stop multicast discovery */
  444. if(server->config.discovery.mdnsEnable)
  445. stopMulticastDiscoveryServer(server);
  446. #endif
  447. /* Execute all delayed callbacks */
  448. UA_WorkQueue_cleanup(&server->workQueue);
  449. return UA_STATUSCODE_GOOD;
  450. }
  451. UA_StatusCode
  452. UA_Server_run(UA_Server *server, const volatile UA_Boolean *running) {
  453. UA_StatusCode retval = UA_Server_run_startup(server);
  454. if(retval != UA_STATUSCODE_GOOD)
  455. return retval;
  456. #ifdef UA_ENABLE_VALGRIND_INTERACTIVE
  457. size_t loopCount = 0;
  458. #endif
  459. while(*running) {
  460. #ifdef UA_ENABLE_VALGRIND_INTERACTIVE
  461. if(loopCount == 0) {
  462. VALGRIND_DO_LEAK_CHECK;
  463. }
  464. ++loopCount;
  465. loopCount %= UA_VALGRIND_INTERACTIVE_INTERVAL;
  466. #endif
  467. UA_Server_run_iterate(server, true);
  468. }
  469. return UA_Server_run_shutdown(server);
  470. }
  471. #ifdef UA_ENABLE_HISTORIZING
  472. /* Allow insert of historical data */
  473. UA_Boolean
  474. UA_Server_AccessControl_allowHistoryUpdateUpdateData(UA_Server *server,
  475. const UA_NodeId *sessionId, void *sessionContext,
  476. const UA_NodeId *nodeId,
  477. UA_PerformUpdateType performInsertReplace,
  478. const UA_DataValue *value) {
  479. if(server->config.accessControl.allowHistoryUpdateUpdateData &&
  480. !server->config.accessControl.allowHistoryUpdateUpdateData(server, &server->config.accessControl,
  481. sessionId, sessionContext, nodeId,
  482. performInsertReplace, value)) {
  483. return false;
  484. }
  485. return true;
  486. }
  487. /* Allow delete of historical data */
  488. UA_Boolean
  489. UA_Server_AccessControl_allowHistoryUpdateDeleteRawModified(UA_Server *server,
  490. const UA_NodeId *sessionId, void *sessionContext,
  491. const UA_NodeId *nodeId,
  492. UA_DateTime startTimestamp,
  493. UA_DateTime endTimestamp,
  494. bool isDeleteModified) {
  495. if(server->config.accessControl.allowHistoryUpdateDeleteRawModified &&
  496. !server->config.accessControl.allowHistoryUpdateDeleteRawModified(server, &server->config.accessControl,
  497. sessionId, sessionContext, nodeId,
  498. startTimestamp, endTimestamp,
  499. isDeleteModified)) {
  500. return false;
  501. }
  502. return true;
  503. }
  504. #endif /* UA_ENABLE_HISTORIZING */