ua_server.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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. server->namespaces[0] = UA_STRING_ALLOC("http://opcfoundation.org/UA/");
  182. UA_String_copy(&server->config.applicationDescription.applicationUri, &server->namespaces[1]);
  183. server->namespacesSize = 2;
  184. /* Initialized SecureChannel and Session managers */
  185. UA_SecureChannelManager_init(&server->secureChannelManager, server);
  186. UA_SessionManager_init(&server->sessionManager, server);
  187. /* Add a regular callback for cleanup and maintenance. With a 10s interval. */
  188. UA_Server_addRepeatedCallback(server, (UA_ServerCallback)UA_Server_cleanup, NULL,
  189. 10000.0, NULL);
  190. /* Initialize namespace 0*/
  191. UA_StatusCode retVal = UA_Nodestore_new(&server->nsCtx);
  192. if(retVal != UA_STATUSCODE_GOOD)
  193. goto cleanup;
  194. retVal = UA_Server_initNS0(server);
  195. if(retVal != UA_STATUSCODE_GOOD)
  196. goto cleanup;
  197. /* Build PubSub information model */
  198. #ifdef UA_ENABLE_PUBSUB_INFORMATIONMODEL
  199. UA_Server_initPubSubNS0(server);
  200. #endif
  201. return server;
  202. cleanup:
  203. UA_Server_delete(server);
  204. return NULL;
  205. }
  206. /*******************/
  207. /* Timed Callbacks */
  208. /*******************/
  209. UA_StatusCode
  210. UA_Server_addTimedCallback(UA_Server *server, UA_ServerCallback callback,
  211. void *data, UA_DateTime date, UA_UInt64 *callbackId) {
  212. return UA_Timer_addTimedCallback(&server->timer,
  213. (UA_ApplicationCallback)callback,
  214. server, data, date, callbackId);
  215. }
  216. UA_StatusCode
  217. UA_Server_addRepeatedCallback(UA_Server *server, UA_ServerCallback callback,
  218. void *data, UA_Double interval_ms,
  219. UA_UInt64 *callbackId) {
  220. return UA_Timer_addRepeatedCallback(&server->timer,
  221. (UA_ApplicationCallback)callback,
  222. server, data, interval_ms, callbackId);
  223. }
  224. UA_StatusCode
  225. UA_Server_changeRepeatedCallbackInterval(UA_Server *server, UA_UInt64 callbackId,
  226. UA_Double interval_ms) {
  227. return UA_Timer_changeRepeatedCallbackInterval(&server->timer, callbackId,
  228. interval_ms);
  229. }
  230. void
  231. UA_Server_removeCallback(UA_Server *server, UA_UInt64 callbackId) {
  232. UA_Timer_removeCallback(&server->timer, callbackId);
  233. }
  234. UA_StatusCode UA_EXPORT
  235. UA_Server_updateCertificate(UA_Server *server,
  236. const UA_ByteString *oldCertificate,
  237. const UA_ByteString *newCertificate,
  238. const UA_ByteString *newPrivateKey,
  239. UA_Boolean closeSessions,
  240. UA_Boolean closeSecureChannels) {
  241. if (server == NULL || oldCertificate == NULL
  242. || newCertificate == NULL || newPrivateKey == NULL) {
  243. return UA_STATUSCODE_BADINTERNALERROR;
  244. }
  245. if (closeSessions) {
  246. UA_SessionManager *sm = &server->sessionManager;
  247. session_list_entry *current;
  248. LIST_FOREACH(current, &sm->sessions, pointers) {
  249. if (UA_ByteString_equal(oldCertificate,
  250. &current->session.header.channel->securityPolicy->localCertificate)) {
  251. UA_SessionManager_removeSession(sm, &current->session.header.authenticationToken);
  252. }
  253. }
  254. }
  255. if (closeSecureChannels) {
  256. UA_SecureChannelManager *cm = &server->secureChannelManager;
  257. channel_entry *entry;
  258. TAILQ_FOREACH(entry, &cm->channels, pointers) {
  259. if(UA_ByteString_equal(&entry->channel.securityPolicy->localCertificate, oldCertificate)){
  260. UA_SecureChannelManager_close(cm, entry->channel.securityToken.channelId);
  261. }
  262. }
  263. }
  264. size_t i = 0;
  265. while (i < server->config.endpointsSize) {
  266. UA_EndpointDescription *ed = &server->config.endpoints[i];
  267. if (UA_ByteString_equal(&ed->serverCertificate, oldCertificate)) {
  268. UA_String_deleteMembers(&ed->serverCertificate);
  269. UA_String_copy(newCertificate, &ed->serverCertificate);
  270. UA_SecurityPolicy *sp = UA_SecurityPolicy_getSecurityPolicyByUri(server, &server->config.endpoints[i].securityPolicyUri);
  271. if(!sp)
  272. return UA_STATUSCODE_BADINTERNALERROR;
  273. sp->updateCertificateAndPrivateKey(sp, *newCertificate, *newPrivateKey);
  274. }
  275. i++;
  276. }
  277. return UA_STATUSCODE_GOOD;
  278. }
  279. /***************************/
  280. /* Server lookup functions */
  281. /***************************/
  282. UA_SecurityPolicy *
  283. UA_SecurityPolicy_getSecurityPolicyByUri(const UA_Server *server,
  284. UA_ByteString *securityPolicyUri)
  285. {
  286. for(size_t i = 0; i < server->config.securityPoliciesSize; i++) {
  287. UA_SecurityPolicy *securityPolicyCandidate = &server->config.securityPolicies[i];
  288. if(UA_ByteString_equal(securityPolicyUri,
  289. &securityPolicyCandidate->policyUri))
  290. return securityPolicyCandidate;
  291. }
  292. return NULL;
  293. }
  294. #ifdef UA_ENABLE_ENCRYPTION
  295. /* The local ApplicationURI has to match the certificates of the
  296. * SecurityPolicies */
  297. static void
  298. verifyServerApplicationURI(const UA_Server *server) {
  299. #if UA_LOGLEVEL <= 400
  300. for(size_t i = 0; i < server->config.securityPoliciesSize; i++) {
  301. UA_SecurityPolicy *sp = &server->config.securityPolicies[i];
  302. if(!sp->certificateVerification)
  303. continue;
  304. UA_StatusCode retval =
  305. sp->certificateVerification->
  306. verifyApplicationURI(sp->certificateVerification->context,
  307. &sp->localCertificate,
  308. &server->config.applicationDescription.applicationUri);
  309. if(retval != UA_STATUSCODE_GOOD) {
  310. UA_LOG_WARNING(&server->config.logger, UA_LOGCATEGORY_SERVER,
  311. "The configured ApplicationURI does not match the URI "
  312. "specified in the certificate for the SecurityPolicy %.*s",
  313. (int)sp->policyUri.length, sp->policyUri.data);
  314. }
  315. }
  316. #endif
  317. }
  318. #endif
  319. /********************/
  320. /* Main Server Loop */
  321. /********************/
  322. #define UA_MAXTIMEOUT 50 /* Max timeout in ms between main-loop iterations */
  323. /* Start: Spin up the workers and the network layer and sample the server's
  324. * start time.
  325. * Iterate: Process repeated callbacks and events in the network layer. This
  326. * part can be driven from an external main-loop in an event-driven
  327. * single-threaded architecture.
  328. * Stop: Stop workers, finish all callbacks, stop the network layer, clean up */
  329. UA_StatusCode
  330. UA_Server_run_startup(UA_Server *server) {
  331. if(server->state > UA_SERVERLIFECYCLE_FRESH)
  332. return UA_STATUSCODE_GOOD;
  333. /* At least one endpoint has to be configured */
  334. if(server->config.endpointsSize == 0) {
  335. UA_LOG_WARNING(&server->config.logger, UA_LOGCATEGORY_SERVER,
  336. "There has to be at least one endpoint.");
  337. }
  338. /* Initialized discovery */
  339. #ifdef UA_ENABLE_DISCOVERY
  340. UA_DiscoveryManager_init(&server->discoveryManager, server);
  341. #endif
  342. /* Does the ApplicationURI match the local certificates? */
  343. #ifdef UA_ENABLE_ENCRYPTION
  344. verifyServerApplicationURI(server);
  345. #endif
  346. /* Sample the start time and set it to the Server object */
  347. server->startTime = UA_DateTime_now();
  348. UA_Variant var;
  349. UA_Variant_init(&var);
  350. UA_Variant_setScalar(&var, &server->startTime, &UA_TYPES[UA_TYPES_DATETIME]);
  351. UA_Server_writeValue(server,
  352. UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STARTTIME),
  353. var);
  354. /* Start the networklayers */
  355. UA_StatusCode result = UA_STATUSCODE_GOOD;
  356. for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
  357. UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
  358. result |= nl->start(nl, &server->config.customHostname);
  359. }
  360. /* Spin up the worker threads */
  361. #ifdef UA_ENABLE_MULTITHREADING
  362. UA_LOG_INFO(&server->config.logger, UA_LOGCATEGORY_SERVER,
  363. "Spinning up %u worker thread(s)", server->config.nThreads);
  364. UA_WorkQueue_start(&server->workQueue, server->config.nThreads);
  365. #endif
  366. /* Start the multicast discovery server */
  367. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  368. if(server->config.applicationDescription.applicationType ==
  369. UA_APPLICATIONTYPE_DISCOVERYSERVER)
  370. startMulticastDiscoveryServer(server);
  371. #endif
  372. server->state = UA_SERVERLIFECYCLE_FRESH;
  373. return result;
  374. }
  375. static void
  376. serverExecuteRepeatedCallback(UA_Server *server, UA_ApplicationCallback cb,
  377. void *callbackApplication, void *data) {
  378. #ifndef UA_ENABLE_MULTITHREADING
  379. cb(callbackApplication, data);
  380. #else
  381. UA_WorkQueue_enqueue(&server->workQueue, cb, callbackApplication, data);
  382. #endif
  383. }
  384. UA_UInt16
  385. UA_Server_run_iterate(UA_Server *server, UA_Boolean waitInternal) {
  386. /* Process repeated work */
  387. UA_DateTime now = UA_DateTime_nowMonotonic();
  388. UA_DateTime nextRepeated = UA_Timer_process(&server->timer, now,
  389. (UA_TimerExecutionCallback)serverExecuteRepeatedCallback, server);
  390. UA_DateTime latest = now + (UA_MAXTIMEOUT * UA_DATETIME_MSEC);
  391. if(nextRepeated > latest)
  392. nextRepeated = latest;
  393. UA_UInt16 timeout = 0;
  394. /* round always to upper value to avoid timeout to be set to 0
  395. * if(nextRepeated - now) < (UA_DATETIME_MSEC/2) */
  396. if(waitInternal)
  397. timeout = (UA_UInt16)(((nextRepeated - now) + (UA_DATETIME_MSEC - 1)) / UA_DATETIME_MSEC);
  398. /* Listen on the networklayer */
  399. for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
  400. UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
  401. nl->listen(nl, server, timeout);
  402. }
  403. #if defined(UA_ENABLE_DISCOVERY_MULTICAST) && !defined(UA_ENABLE_MULTITHREADING)
  404. if(server->config.applicationDescription.applicationType ==
  405. UA_APPLICATIONTYPE_DISCOVERYSERVER) {
  406. // TODO multicastNextRepeat does not consider new input data (requests)
  407. // on the socket. It will be handled on the next call. if needed, we
  408. // need to use select with timeout on the multicast socket
  409. // server->mdnsSocket (see example in mdnsd library) on higher level.
  410. UA_DateTime multicastNextRepeat = 0;
  411. UA_StatusCode hasNext =
  412. iterateMulticastDiscoveryServer(server, &multicastNextRepeat, true);
  413. if(hasNext == UA_STATUSCODE_GOOD && multicastNextRepeat < nextRepeated)
  414. nextRepeated = multicastNextRepeat;
  415. }
  416. #endif
  417. #ifndef UA_ENABLE_MULTITHREADING
  418. UA_WorkQueue_manuallyProcessDelayed(&server->workQueue);
  419. #endif
  420. now = UA_DateTime_nowMonotonic();
  421. timeout = 0;
  422. if(nextRepeated > now)
  423. timeout = (UA_UInt16)((nextRepeated - now) / UA_DATETIME_MSEC);
  424. return timeout;
  425. }
  426. UA_StatusCode
  427. UA_Server_run_shutdown(UA_Server *server) {
  428. /* Stop the netowrk layer */
  429. for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
  430. UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
  431. nl->stop(nl, server);
  432. }
  433. #ifdef UA_ENABLE_MULTITHREADING
  434. /* Shut down the workers */
  435. UA_LOG_INFO(&server->config.logger, UA_LOGCATEGORY_SERVER,
  436. "Shutting down %u worker thread(s)",
  437. (UA_UInt32)server->workQueue.workersSize);
  438. UA_WorkQueue_stop(&server->workQueue);
  439. #endif
  440. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  441. /* Stop multicast discovery */
  442. if(server->config.applicationDescription.applicationType ==
  443. UA_APPLICATIONTYPE_DISCOVERYSERVER)
  444. stopMulticastDiscoveryServer(server);
  445. #endif
  446. /* Execute all delayed callbacks */
  447. UA_WorkQueue_cleanup(&server->workQueue);
  448. return UA_STATUSCODE_GOOD;
  449. }
  450. UA_StatusCode
  451. UA_Server_run(UA_Server *server, const volatile UA_Boolean *running) {
  452. UA_StatusCode retval = UA_Server_run_startup(server);
  453. if(retval != UA_STATUSCODE_GOOD)
  454. return retval;
  455. #ifdef UA_ENABLE_VALGRIND_INTERACTIVE
  456. size_t loopCount = 0;
  457. #endif
  458. while(*running) {
  459. #ifdef UA_ENABLE_VALGRIND_INTERACTIVE
  460. if(loopCount == 0) {
  461. VALGRIND_DO_LEAK_CHECK;
  462. }
  463. ++loopCount;
  464. loopCount %= UA_VALGRIND_INTERACTIVE_INTERVAL;
  465. #endif
  466. UA_Server_run_iterate(server, true);
  467. }
  468. return UA_Server_run_shutdown(server);
  469. }
  470. #ifdef UA_ENABLE_HISTORIZING
  471. /* Allow insert of historical data */
  472. UA_Boolean
  473. UA_Server_AccessControl_allowHistoryUpdateUpdateData(UA_Server *server,
  474. const UA_NodeId *sessionId, void *sessionContext,
  475. const UA_NodeId *nodeId,
  476. UA_PerformUpdateType performInsertReplace,
  477. const UA_DataValue *value) {
  478. if(server->config.accessControl.allowHistoryUpdateUpdateData &&
  479. !server->config.accessControl.allowHistoryUpdateUpdateData(server, &server->config.accessControl,
  480. sessionId, sessionContext, nodeId,
  481. performInsertReplace, value)) {
  482. return false;
  483. }
  484. return true;
  485. }
  486. /* Allow delete of historical data */
  487. UA_Boolean
  488. UA_Server_AccessControl_allowHistoryUpdateDeleteRawModified(UA_Server *server,
  489. const UA_NodeId *sessionId, void *sessionContext,
  490. const UA_NodeId *nodeId,
  491. UA_DateTime startTimestamp,
  492. UA_DateTime endTimestamp,
  493. bool isDeleteModified) {
  494. if(server->config.accessControl.allowHistoryUpdateDeleteRawModified &&
  495. !server->config.accessControl.allowHistoryUpdateDeleteRawModified(server, &server->config.accessControl,
  496. sessionId, sessionContext, nodeId,
  497. startTimestamp, endTimestamp,
  498. isDeleteModified)) {
  499. return false;
  500. }
  501. return true;
  502. }
  503. #endif /* UA_ENABLE_HISTORIZING */