ua_server.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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. {
  70. if(UA_String_equal(&server->namespaces[idx], &namespaceUri) == true)
  71. {
  72. (*foundIndex) = idx;
  73. return UA_STATUSCODE_GOOD;
  74. }
  75. }
  76. return UA_STATUSCODE_BADNOTFOUND;
  77. }
  78. UA_StatusCode
  79. UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId,
  80. UA_NodeIteratorCallback callback, void *handle) {
  81. const UA_Node *parent = UA_Nodestore_getNode(server->nsCtx, &parentNodeId);
  82. if(!parent)
  83. return UA_STATUSCODE_BADNODEIDINVALID;
  84. /* TODO: We need to do an ugly copy of the references array since users may
  85. * delete references from within the callback. In single-threaded mode this
  86. * changes the same node we point at here. In multi-threaded mode, this
  87. * creates a new copy as nodes are truly immutable.
  88. * The callback could remove a node via the regular public API.
  89. * This can remove a member of the nodes-array we iterate over...
  90. * */
  91. UA_Node *parentCopy = UA_Node_copy_alloc(parent);
  92. if(!parentCopy) {
  93. UA_Nodestore_releaseNode(server->nsCtx, parent);
  94. return UA_STATUSCODE_BADUNEXPECTEDERROR;
  95. }
  96. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  97. for(size_t i = parentCopy->referencesSize; i > 0; --i) {
  98. UA_NodeReferenceKind *ref = &parentCopy->references[i - 1];
  99. for(size_t j = 0; j<ref->targetIdsSize; j++) {
  100. retval = callback(ref->targetIds[j].nodeId, ref->isInverse,
  101. ref->referenceTypeId, handle);
  102. if(retval != UA_STATUSCODE_GOOD)
  103. goto cleanup;
  104. }
  105. }
  106. cleanup:
  107. UA_Node_deleteMembers(parentCopy);
  108. UA_free(parentCopy);
  109. UA_Nodestore_releaseNode(server->nsCtx, parent);
  110. return retval;
  111. }
  112. /********************/
  113. /* Server Lifecycle */
  114. /********************/
  115. /* The server needs to be stopped before it can be deleted */
  116. void UA_Server_delete(UA_Server *server) {
  117. /* Delete all internal data */
  118. UA_SecureChannelManager_deleteMembers(&server->secureChannelManager);
  119. UA_SessionManager_deleteMembers(&server->sessionManager);
  120. UA_Array_delete(server->namespaces, server->namespacesSize, &UA_TYPES[UA_TYPES_STRING]);
  121. #ifdef UA_ENABLE_SUBSCRIPTIONS
  122. UA_MonitoredItem *mon, *mon_tmp;
  123. LIST_FOREACH_SAFE(mon, &server->localMonitoredItems, listEntry, mon_tmp) {
  124. LIST_REMOVE(mon, listEntry);
  125. UA_MonitoredItem_delete(server, mon);
  126. }
  127. #endif
  128. #ifdef UA_ENABLE_PUBSUB
  129. UA_PubSubManager_delete(server, &server->pubSubManager);
  130. #endif
  131. #ifdef UA_ENABLE_DISCOVERY
  132. UA_DiscoveryManager_deleteMembers(&server->discoveryManager, server);
  133. #endif
  134. /* Clean up the Admin Session */
  135. UA_Session_deleteMembersCleanup(&server->adminSession, server);
  136. /* Clean up the work queue */
  137. UA_WorkQueue_cleanup(&server->workQueue);
  138. /* Delete the timed work */
  139. UA_Timer_deleteMembers(&server->timer);
  140. /* Clean up the nodestore */
  141. UA_Nodestore_delete(server->nsCtx);
  142. /* Clean up the config */
  143. UA_ServerConfig_clean(&server->config);
  144. /* Delete the server itself */
  145. UA_free(server);
  146. }
  147. /* Recurring cleanup. Removing unused and timed-out channels and sessions */
  148. static void
  149. UA_Server_cleanup(UA_Server *server, void *_) {
  150. UA_DateTime nowMonotonic = UA_DateTime_nowMonotonic();
  151. UA_SessionManager_cleanupTimedOut(&server->sessionManager, nowMonotonic);
  152. UA_SecureChannelManager_cleanupTimedOut(&server->secureChannelManager, nowMonotonic);
  153. #ifdef UA_ENABLE_DISCOVERY
  154. UA_Discovery_cleanupTimedOut(server, nowMonotonic);
  155. #endif
  156. }
  157. /********************/
  158. /* Server Lifecycle */
  159. /********************/
  160. UA_Server *
  161. UA_Server_new() {
  162. /* Allocate the server */
  163. UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
  164. if(!server)
  165. return NULL;
  166. /* Init start time to zero, the actual start time will be sampled in
  167. * UA_Server_run_startup() */
  168. server->startTime = 0;
  169. /* Set a seed for non-cyptographic randomness */
  170. #ifndef UA_ENABLE_DETERMINISTIC_RNG
  171. UA_random_seed((UA_UInt64)UA_DateTime_now());
  172. #endif
  173. /* Initialize the handling of repeated callbacks */
  174. UA_Timer_init(&server->timer);
  175. UA_WorkQueue_init(&server->workQueue);
  176. /* Initialize the adminSession */
  177. UA_Session_init(&server->adminSession);
  178. server->adminSession.sessionId.identifierType = UA_NODEIDTYPE_GUID;
  179. server->adminSession.sessionId.identifier.guid.data1 = 1;
  180. server->adminSession.validTill = UA_INT64_MAX;
  181. /* Create Namespaces 0 and 1 */
  182. server->namespaces = (UA_String *)UA_Array_new(2, &UA_TYPES[UA_TYPES_STRING]);
  183. server->namespaces[0] = UA_STRING_ALLOC("http://opcfoundation.org/UA/");
  184. UA_String_copy(&server->config.applicationDescription.applicationUri, &server->namespaces[1]);
  185. server->namespacesSize = 2;
  186. /* Initialized SecureChannel and Session managers */
  187. UA_SecureChannelManager_init(&server->secureChannelManager, server);
  188. UA_SessionManager_init(&server->sessionManager, server);
  189. /* Add a regular callback for cleanup and maintenance. With a 10s interval. */
  190. UA_Server_addRepeatedCallback(server, (UA_ServerCallback)UA_Server_cleanup, NULL,
  191. 10000.0, NULL);
  192. /* Initialize namespace 0*/
  193. UA_StatusCode retVal = UA_Nodestore_new(&server->nsCtx);
  194. if(retVal != UA_STATUSCODE_GOOD)
  195. goto cleanup;
  196. retVal = UA_Server_initNS0(server);
  197. if(retVal != UA_STATUSCODE_GOOD)
  198. goto cleanup;
  199. /* Build PubSub information model */
  200. #ifdef UA_ENABLE_PUBSUB_INFORMATIONMODEL
  201. UA_Server_initPubSubNS0(server);
  202. #endif
  203. return server;
  204. cleanup:
  205. UA_Server_delete(server);
  206. return NULL;
  207. }
  208. /*******************/
  209. /* Timed Callbacks */
  210. /*******************/
  211. UA_StatusCode
  212. UA_Server_addTimedCallback(UA_Server *server, UA_ServerCallback callback,
  213. void *data, UA_DateTime date, UA_UInt64 *callbackId) {
  214. return UA_Timer_addTimedCallback(&server->timer,
  215. (UA_ApplicationCallback)callback,
  216. server, data, date, callbackId);
  217. }
  218. UA_StatusCode
  219. UA_Server_addRepeatedCallback(UA_Server *server, UA_ServerCallback callback,
  220. void *data, UA_Double interval_ms,
  221. UA_UInt64 *callbackId) {
  222. return UA_Timer_addRepeatedCallback(&server->timer,
  223. (UA_ApplicationCallback)callback,
  224. server, data, interval_ms, callbackId);
  225. }
  226. UA_StatusCode
  227. UA_Server_changeRepeatedCallbackInterval(UA_Server *server, UA_UInt64 callbackId,
  228. UA_Double interval_ms) {
  229. return UA_Timer_changeRepeatedCallbackInterval(&server->timer, callbackId,
  230. interval_ms);
  231. }
  232. void
  233. UA_Server_removeCallback(UA_Server *server, UA_UInt64 callbackId) {
  234. UA_Timer_removeCallback(&server->timer, callbackId);
  235. }
  236. UA_StatusCode UA_EXPORT
  237. UA_Server_updateCertificate(UA_Server *server,
  238. const UA_ByteString *oldCertificate,
  239. const UA_ByteString *newCertificate,
  240. const UA_ByteString *newPrivateKey,
  241. UA_Boolean closeSessions,
  242. UA_Boolean closeSecureChannels) {
  243. if (server == NULL || oldCertificate == NULL
  244. || newCertificate == NULL || newPrivateKey == NULL) {
  245. return UA_STATUSCODE_BADINTERNALERROR;
  246. }
  247. if (closeSessions) {
  248. UA_SessionManager *sm = &server->sessionManager;
  249. session_list_entry *current;
  250. LIST_FOREACH(current, &sm->sessions, pointers) {
  251. if (UA_ByteString_equal(oldCertificate,
  252. &current->session.header.channel->securityPolicy->localCertificate)) {
  253. UA_SessionManager_removeSession(sm, &current->session.header.authenticationToken);
  254. }
  255. }
  256. }
  257. if (closeSecureChannels) {
  258. UA_SecureChannelManager *cm = &server->secureChannelManager;
  259. channel_entry *entry;
  260. TAILQ_FOREACH(entry, &cm->channels, pointers) {
  261. if(UA_ByteString_equal(&entry->channel.securityPolicy->localCertificate, oldCertificate)){
  262. UA_SecureChannelManager_close(cm, entry->channel.securityToken.channelId);
  263. }
  264. }
  265. }
  266. size_t i = 0;
  267. while (i < server->config.endpointsSize) {
  268. UA_EndpointDescription *ed = &server->config.endpoints[i];
  269. if (UA_ByteString_equal(&ed->serverCertificate, oldCertificate)) {
  270. UA_String_deleteMembers(&ed->serverCertificate);
  271. UA_String_copy(newCertificate, &ed->serverCertificate);
  272. UA_SecurityPolicy *sp = UA_SecurityPolicy_getSecurityPolicyByUri(server, &server->config.endpoints[i].securityPolicyUri);
  273. if(!sp)
  274. return UA_STATUSCODE_BADINTERNALERROR;
  275. sp->updateCertificateAndPrivateKey(sp, *newCertificate, *newPrivateKey);
  276. }
  277. i++;
  278. }
  279. return UA_STATUSCODE_GOOD;
  280. }
  281. /***************************/
  282. /* Server lookup functions */
  283. /***************************/
  284. UA_SecurityPolicy *
  285. UA_SecurityPolicy_getSecurityPolicyByUri(const UA_Server *server,
  286. UA_ByteString *securityPolicyUri)
  287. {
  288. for(size_t i = 0; i < server->config.securityPoliciesSize; i++) {
  289. UA_SecurityPolicy *securityPolicyCandidate = &server->config.securityPolicies[i];
  290. if(UA_ByteString_equal(securityPolicyUri,
  291. &securityPolicyCandidate->policyUri))
  292. return securityPolicyCandidate;
  293. }
  294. return NULL;
  295. }
  296. #ifdef UA_ENABLE_ENCRYPTION
  297. /* The local ApplicationURI has to match the certificates of the
  298. * SecurityPolicies */
  299. static void
  300. verifyServerApplicationURI(const UA_Server *server) {
  301. #if UA_LOGLEVEL <= 400
  302. for(size_t i = 0; i < server->config.securityPoliciesSize; i++) {
  303. UA_SecurityPolicy *sp = &server->config.securityPolicies[i];
  304. if(!sp->certificateVerification)
  305. continue;
  306. UA_StatusCode retval =
  307. sp->certificateVerification->
  308. verifyApplicationURI(sp->certificateVerification->context,
  309. &sp->localCertificate,
  310. &server->config.applicationDescription.applicationUri);
  311. if(retval != UA_STATUSCODE_GOOD) {
  312. UA_LOG_WARNING(&server->config.logger, UA_LOGCATEGORY_SERVER,
  313. "The configured ApplicationURI does not match the URI "
  314. "specified in the certificate for the SecurityPolicy %.*s",
  315. (int)sp->policyUri.length, sp->policyUri.data);
  316. }
  317. }
  318. #endif
  319. }
  320. #endif
  321. /********************/
  322. /* Main Server Loop */
  323. /********************/
  324. #define UA_MAXTIMEOUT 50 /* Max timeout in ms between main-loop iterations */
  325. /* Start: Spin up the workers and the network layer and sample the server's
  326. * start time.
  327. * Iterate: Process repeated callbacks and events in the network layer. This
  328. * part can be driven from an external main-loop in an event-driven
  329. * single-threaded architecture.
  330. * Stop: Stop workers, finish all callbacks, stop the network layer, clean up */
  331. UA_StatusCode
  332. UA_Server_run_startup(UA_Server *server) {
  333. if(server->state > UA_SERVERLIFECYCLE_FRESH)
  334. return UA_STATUSCODE_GOOD;
  335. /* At least one endpoint has to be configured */
  336. if(server->config.endpointsSize == 0) {
  337. UA_LOG_WARNING(&server->config.logger, UA_LOGCATEGORY_SERVER,
  338. "There has to be at least one endpoint.");
  339. }
  340. /* Initialized discovery */
  341. #ifdef UA_ENABLE_DISCOVERY
  342. UA_DiscoveryManager_init(&server->discoveryManager, server);
  343. #endif
  344. /* Does the ApplicationURI match the local certificates? */
  345. #ifdef UA_ENABLE_ENCRYPTION
  346. verifyServerApplicationURI(server);
  347. #endif
  348. /* Sample the start time and set it to the Server object */
  349. server->startTime = UA_DateTime_now();
  350. UA_Variant var;
  351. UA_Variant_init(&var);
  352. UA_Variant_setScalar(&var, &server->startTime, &UA_TYPES[UA_TYPES_DATETIME]);
  353. UA_Server_writeValue(server,
  354. UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STARTTIME),
  355. var);
  356. /* Start the networklayers */
  357. UA_StatusCode result = UA_STATUSCODE_GOOD;
  358. for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
  359. UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
  360. result |= nl->start(nl, &server->config.customHostname);
  361. }
  362. /* Spin up the worker threads */
  363. #ifdef UA_ENABLE_MULTITHREADING
  364. UA_LOG_INFO(&server->config.logger, UA_LOGCATEGORY_SERVER,
  365. "Spinning up %u worker thread(s)", server->config.nThreads);
  366. UA_WorkQueue_start(&server->workQueue, server->config.nThreads);
  367. #endif
  368. /* Start the multicast discovery server */
  369. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  370. if(server->config.applicationDescription.applicationType ==
  371. UA_APPLICATIONTYPE_DISCOVERYSERVER)
  372. startMulticastDiscoveryServer(server);
  373. #endif
  374. server->state = UA_SERVERLIFECYCLE_FRESH;
  375. return result;
  376. }
  377. static void
  378. serverExecuteRepeatedCallback(UA_Server *server, UA_ApplicationCallback cb,
  379. void *callbackApplication, void *data) {
  380. #ifndef UA_ENABLE_MULTITHREADING
  381. cb(callbackApplication, data);
  382. #else
  383. UA_WorkQueue_enqueue(&server->workQueue, cb, callbackApplication, data);
  384. #endif
  385. }
  386. UA_UInt16
  387. UA_Server_run_iterate(UA_Server *server, UA_Boolean waitInternal) {
  388. /* Process repeated work */
  389. UA_DateTime now = UA_DateTime_nowMonotonic();
  390. UA_DateTime nextRepeated = UA_Timer_process(&server->timer, now,
  391. (UA_TimerExecutionCallback)serverExecuteRepeatedCallback, server);
  392. UA_DateTime latest = now + (UA_MAXTIMEOUT * UA_DATETIME_MSEC);
  393. if(nextRepeated > latest)
  394. nextRepeated = latest;
  395. UA_UInt16 timeout = 0;
  396. /* round always to upper value to avoid timeout to be set to 0
  397. * if(nextRepeated - now) < (UA_DATETIME_MSEC/2) */
  398. if(waitInternal)
  399. timeout = (UA_UInt16)(((nextRepeated - now) + (UA_DATETIME_MSEC - 1)) / UA_DATETIME_MSEC);
  400. /* Listen on the networklayer */
  401. for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
  402. UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
  403. nl->listen(nl, server, timeout);
  404. }
  405. #if defined(UA_ENABLE_DISCOVERY_MULTICAST) && !defined(UA_ENABLE_MULTITHREADING)
  406. if(server->config.applicationDescription.applicationType ==
  407. UA_APPLICATIONTYPE_DISCOVERYSERVER) {
  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.applicationDescription.applicationType ==
  445. UA_APPLICATIONTYPE_DISCOVERYSERVER)
  446. stopMulticastDiscoveryServer(server);
  447. #endif
  448. /* Execute all delayed callbacks */
  449. UA_WorkQueue_cleanup(&server->workQueue);
  450. return UA_STATUSCODE_GOOD;
  451. }
  452. UA_StatusCode
  453. UA_Server_run(UA_Server *server, const volatile UA_Boolean *running) {
  454. UA_StatusCode retval = UA_Server_run_startup(server);
  455. if(retval != UA_STATUSCODE_GOOD)
  456. return retval;
  457. #ifdef UA_ENABLE_VALGRIND_INTERACTIVE
  458. size_t loopCount = 0;
  459. #endif
  460. while(*running) {
  461. #ifdef UA_ENABLE_VALGRIND_INTERACTIVE
  462. if(loopCount == 0) {
  463. VALGRIND_DO_LEAK_CHECK;
  464. }
  465. ++loopCount;
  466. loopCount %= UA_VALGRIND_INTERACTIVE_INTERVAL;
  467. #endif
  468. UA_Server_run_iterate(server, true);
  469. }
  470. return UA_Server_run_shutdown(server);
  471. }
  472. #ifdef UA_ENABLE_HISTORIZING
  473. /* Allow insert of historical data */
  474. UA_Boolean
  475. UA_Server_AccessControl_allowHistoryUpdateUpdateData(UA_Server *server,
  476. const UA_NodeId *sessionId, void *sessionContext,
  477. const UA_NodeId *nodeId,
  478. UA_PerformUpdateType performInsertReplace,
  479. const UA_DataValue *value) {
  480. if(server->config.accessControl.allowHistoryUpdateUpdateData &&
  481. !server->config.accessControl.allowHistoryUpdateUpdateData(server, &server->config.accessControl,
  482. sessionId, sessionContext, nodeId,
  483. performInsertReplace, value)) {
  484. return false;
  485. }
  486. return true;
  487. }
  488. /* Allow delete of historical data */
  489. UA_Boolean
  490. UA_Server_AccessControl_allowHistoryUpdateDeleteRawModified(UA_Server *server,
  491. const UA_NodeId *sessionId, void *sessionContext,
  492. const UA_NodeId *nodeId,
  493. UA_DateTime startTimestamp,
  494. UA_DateTime endTimestamp,
  495. bool isDeleteModified) {
  496. if(server->config.accessControl.allowHistoryUpdateDeleteRawModified &&
  497. !server->config.accessControl.allowHistoryUpdateDeleteRawModified(server, &server->config.accessControl,
  498. sessionId, sessionContext, nodeId,
  499. startTimestamp, endTimestamp,
  500. isDeleteModified)) {
  501. return false;
  502. }
  503. return true;
  504. }
  505. #endif /* UA_ENABLE_HISTORIZING */