ua_client.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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 2015-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2015-2016 (c) Sten Grüner
  7. * Copyright 2015-2016 (c) Chris Iatrou
  8. * Copyright 2015 (c) hfaham
  9. * Copyright 2015-2017 (c) Florian Palm
  10. * Copyright 2017-2018 (c) Thomas Stalder, Blue Time Concept SA
  11. * Copyright 2015 (c) Holger Jeromin
  12. * Copyright 2015 (c) Oleksiy Vasylyev
  13. * Copyright 2016 (c) TorbenD
  14. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  15. * Copyright 2016 (c) Lykurg
  16. * Copyright 2017 (c) Mark Giraud, Fraunhofer IOSB
  17. * Copyright 2018 (c) Kalycito Infotech Private Limited
  18. */
  19. #include "ua_client_internal.h"
  20. #include "ua_connection_internal.h"
  21. #include "ua_types_encoding_binary.h"
  22. #include "ua_types_generated_encoding_binary.h"
  23. #include "ua_util.h"
  24. #include "ua_securitypolicies.h"
  25. #include "ua_pki_certificate.h"
  26. #define STATUS_CODE_BAD_POINTER 0x01
  27. /********************/
  28. /* Client Lifecycle */
  29. /********************/
  30. static void
  31. UA_Client_init(UA_Client* client) {
  32. memset(client, 0, sizeof(UA_Client));
  33. UA_SecurityPolicy_None(&client->securityPolicy, NULL, UA_BYTESTRING_NULL,
  34. &client->config.logger);
  35. UA_SecureChannel_init(&client->channel);
  36. if(client->config.stateCallback)
  37. client->config.stateCallback(client, client->state);
  38. /* Catch error during async connection */
  39. client->connectStatus = UA_STATUSCODE_GOOD;
  40. UA_Timer_init(&client->timer);
  41. UA_WorkQueue_init(&client->workQueue);
  42. }
  43. UA_Client *
  44. UA_Client_new() {
  45. UA_Client *client = (UA_Client*)UA_malloc(sizeof(UA_Client));
  46. if(!client)
  47. return NULL;
  48. UA_Client_init(client);
  49. return client;
  50. }
  51. static void
  52. UA_Client_deleteMembers(UA_Client *client) {
  53. UA_Client_disconnect(client);
  54. client->securityPolicy.deleteMembers(&client->securityPolicy);
  55. /* Commented as UA_SecureChannel_deleteMembers already done
  56. * in UA_Client_disconnect function */
  57. //UA_SecureChannel_deleteMembersCleanup(&client->channel);
  58. if (client->connection.free)
  59. client->connection.free(&client->connection);
  60. UA_Connection_deleteMembers(&client->connection);
  61. if(client->endpointUrl.data)
  62. UA_String_deleteMembers(&client->endpointUrl);
  63. UA_UserTokenPolicy_deleteMembers(&client->token);
  64. UA_NodeId_deleteMembers(&client->authenticationToken);
  65. if(client->username.data)
  66. UA_String_deleteMembers(&client->username);
  67. if(client->password.data)
  68. UA_String_deleteMembers(&client->password);
  69. /* Delete the async service calls */
  70. UA_Client_AsyncService_removeAll(client, UA_STATUSCODE_BADSHUTDOWN);
  71. /* Delete the subscriptions */
  72. #ifdef UA_ENABLE_SUBSCRIPTIONS
  73. UA_Client_Subscriptions_clean(client);
  74. #endif
  75. /* Delete the timed work */
  76. UA_Timer_deleteMembers(&client->timer);
  77. /* Clean up the work queue */
  78. UA_WorkQueue_cleanup(&client->workQueue);
  79. }
  80. void
  81. UA_Client_reset(UA_Client* client) {
  82. UA_Client_deleteMembers(client);
  83. UA_Client_init(client);
  84. }
  85. void
  86. UA_Client_delete(UA_Client* client) {
  87. /* certificate verification is initialized for secure client
  88. * which is deallocated */
  89. if(client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGN ||
  90. client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT) {
  91. if (client->securityPolicy.certificateVerification->deleteMembers)
  92. client->securityPolicy.certificateVerification->deleteMembers(client->securityPolicy.certificateVerification);
  93. UA_free(client->securityPolicy.certificateVerification);
  94. }
  95. UA_Client_deleteMembers(client);
  96. UA_free(client);
  97. }
  98. UA_ClientState
  99. UA_Client_getState(UA_Client *client) {
  100. return client->state;
  101. }
  102. UA_ClientConfig *
  103. UA_Client_getConfig(UA_Client *client) {
  104. if(!client)
  105. return NULL;
  106. return &client->config;
  107. }
  108. /****************/
  109. /* Raw Services */
  110. /****************/
  111. /* For synchronous service calls. Execute async responses with a callback. When
  112. * the response with the correct requestId turns up, return it via the
  113. * SyncResponseDescription pointer. */
  114. typedef struct {
  115. UA_Client *client;
  116. UA_Boolean received;
  117. UA_UInt32 requestId;
  118. void *response;
  119. const UA_DataType *responseType;
  120. } SyncResponseDescription;
  121. /* For both synchronous and asynchronous service calls */
  122. static UA_StatusCode
  123. sendSymmetricServiceRequest(UA_Client *client, const void *request,
  124. const UA_DataType *requestType, UA_UInt32 *requestId) {
  125. /* Make sure we have a valid session */
  126. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  127. /* FIXME: this is just a dirty workaround. We need to rework some of the sync and async processing
  128. * FIXME: in the client. Currently a lot of stuff is semi broken and in dire need of cleaning up.*/
  129. /*UA_StatusCode retval = openSecureChannel(client, true);
  130. if(retval != UA_STATUSCODE_GOOD)
  131. return retval;*/
  132. /* Adjusting the request header. The const attribute is violated, but we
  133. * only touch the following members: */
  134. UA_RequestHeader *rr = (UA_RequestHeader*)(uintptr_t)request;
  135. rr->authenticationToken = client->authenticationToken; /* cleaned up at the end */
  136. rr->timestamp = UA_DateTime_now();
  137. rr->requestHandle = ++client->requestHandle;
  138. /* Send the request */
  139. UA_UInt32 rqId = ++client->requestId;
  140. UA_LOG_DEBUG(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  141. "Sending a request of type %i", requestType->typeId.identifier.numeric);
  142. if (client->channel.nextSecurityToken.tokenId != 0) // Change to the new security token if the secure channel has been renewed.
  143. UA_SecureChannel_revolveTokens(&client->channel);
  144. retval = UA_SecureChannel_sendSymmetricMessage(&client->channel, rqId, UA_MESSAGETYPE_MSG,
  145. rr, requestType);
  146. UA_NodeId_init(&rr->authenticationToken); /* Do not return the token to the user */
  147. if(retval != UA_STATUSCODE_GOOD)
  148. return retval;
  149. *requestId = rqId;
  150. return UA_STATUSCODE_GOOD;
  151. }
  152. static const UA_NodeId
  153. serviceFaultId = {0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_SERVICEFAULT_ENCODING_DEFAULTBINARY}};
  154. /* Look for the async callback in the linked list, execute and delete it */
  155. static UA_StatusCode
  156. processAsyncResponse(UA_Client *client, UA_UInt32 requestId, const UA_NodeId *responseTypeId,
  157. const UA_ByteString *responseMessage, size_t *offset) {
  158. /* Find the callback */
  159. AsyncServiceCall *ac;
  160. LIST_FOREACH(ac, &client->asyncServiceCalls, pointers) {
  161. if(ac->requestId == requestId)
  162. break;
  163. }
  164. if(!ac)
  165. return UA_STATUSCODE_BADREQUESTHEADERINVALID;
  166. /* Allocate the response */
  167. UA_STACKARRAY(UA_Byte, responseBuf, ac->responseType->memSize);
  168. void *response = (void*)(uintptr_t)&responseBuf[0]; /* workaround aliasing rules */
  169. /* Verify the type of the response */
  170. const UA_DataType *responseType = ac->responseType;
  171. const UA_NodeId expectedNodeId = UA_NODEID_NUMERIC(0, ac->responseType->binaryEncodingId);
  172. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  173. if(!UA_NodeId_equal(responseTypeId, &expectedNodeId)) {
  174. UA_init(response, ac->responseType);
  175. if(UA_NodeId_equal(responseTypeId, &serviceFaultId)) {
  176. /* Decode as a ServiceFault, i.e. only the response header */
  177. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  178. "Received a ServiceFault response");
  179. responseType = &UA_TYPES[UA_TYPES_SERVICEFAULT];
  180. } else {
  181. /* Close the connection */
  182. UA_LOG_ERROR(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  183. "Reply contains the wrong service response");
  184. retval = UA_STATUSCODE_BADCOMMUNICATIONERROR;
  185. goto process;
  186. }
  187. }
  188. /* Decode the response */
  189. retval = UA_decodeBinary(responseMessage, offset, response, responseType, NULL);
  190. process:
  191. if(retval != UA_STATUSCODE_GOOD) {
  192. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  193. "Could not decode the response with id %u due to %s",
  194. requestId, UA_StatusCode_name(retval));
  195. ((UA_ResponseHeader*)response)->serviceResult = retval;
  196. }
  197. /* Call the callback */
  198. if(ac->callback)
  199. ac->callback(client, ac->userdata, requestId, response);
  200. UA_deleteMembers(response, ac->responseType);
  201. /* Remove the callback */
  202. LIST_REMOVE(ac, pointers);
  203. UA_free(ac);
  204. return retval;
  205. }
  206. /* Processes the received service response. Either with an async callback or by
  207. * decoding the message and returning it "upwards" in the
  208. * SyncResponseDescription. */
  209. static void
  210. processServiceResponse(void *application, UA_SecureChannel *channel,
  211. UA_MessageType messageType, UA_UInt32 requestId,
  212. const UA_ByteString *message) {
  213. SyncResponseDescription *rd = (SyncResponseDescription*)application;
  214. /* Must be OPN or MSG */
  215. if(messageType != UA_MESSAGETYPE_OPN &&
  216. messageType != UA_MESSAGETYPE_MSG) {
  217. UA_LOG_TRACE_CHANNEL(&rd->client->config.logger, channel,
  218. "Invalid message type");
  219. return;
  220. }
  221. /* Forward declaration for the goto */
  222. UA_NodeId expectedNodeId = UA_NODEID_NULL;
  223. /* Decode the data type identifier of the response */
  224. size_t offset = 0;
  225. UA_NodeId responseId;
  226. UA_StatusCode retval = UA_NodeId_decodeBinary(message, &offset, &responseId);
  227. if(retval != UA_STATUSCODE_GOOD)
  228. goto finish;
  229. /* Got an asynchronous response. Don't expected a synchronous response
  230. * (responseType NULL) or the id does not match. */
  231. if(!rd->responseType || requestId != rd->requestId) {
  232. retval = processAsyncResponse(rd->client, requestId, &responseId, message, &offset);
  233. goto finish;
  234. }
  235. /* Got the synchronous response */
  236. rd->received = true;
  237. /* Check that the response type matches */
  238. expectedNodeId = UA_NODEID_NUMERIC(0, rd->responseType->binaryEncodingId);
  239. if(!UA_NodeId_equal(&responseId, &expectedNodeId)) {
  240. if(UA_NodeId_equal(&responseId, &serviceFaultId)) {
  241. UA_LOG_INFO(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  242. "Received a ServiceFault response");
  243. UA_init(rd->response, rd->responseType);
  244. retval = UA_decodeBinary(message, &offset, rd->response,
  245. &UA_TYPES[UA_TYPES_SERVICEFAULT], NULL);
  246. } else {
  247. /* Close the connection */
  248. UA_LOG_ERROR(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  249. "Reply contains the wrong service response");
  250. retval = UA_STATUSCODE_BADCOMMUNICATIONERROR;
  251. }
  252. goto finish;
  253. }
  254. #ifdef UA_ENABLE_TYPENAMES
  255. UA_LOG_DEBUG(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  256. "Decode a message of type %s", rd->responseType->typeName);
  257. #else
  258. UA_LOG_DEBUG(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  259. "Decode a message of type %u", responseId.identifier.numeric);
  260. #endif
  261. /* Decode the response */
  262. retval = UA_decodeBinary(message, &offset, rd->response, rd->responseType,
  263. rd->client->config.customDataTypes);
  264. finish:
  265. UA_NodeId_deleteMembers(&responseId);
  266. if(retval != UA_STATUSCODE_GOOD) {
  267. if(retval == UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED)
  268. retval = UA_STATUSCODE_BADRESPONSETOOLARGE;
  269. UA_LOG_INFO(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  270. "Error receiving the response with status code %s",
  271. UA_StatusCode_name(retval));
  272. if(rd->response) {
  273. UA_ResponseHeader *respHeader = (UA_ResponseHeader*)rd->response;
  274. respHeader->serviceResult = retval;
  275. }
  276. }
  277. }
  278. /* Forward complete chunks directly to the securechannel */
  279. static UA_StatusCode
  280. client_processChunk(void *application, UA_Connection *connection, UA_ByteString *chunk) {
  281. SyncResponseDescription *rd = (SyncResponseDescription*)application;
  282. UA_StatusCode retval = UA_SecureChannel_decryptAddChunk(&rd->client->channel, chunk, true);
  283. if(retval != UA_STATUSCODE_GOOD)
  284. return retval;
  285. return UA_SecureChannel_persistIncompleteMessages(&rd->client->channel);
  286. }
  287. /* Receive and process messages until a synchronous message arrives or the
  288. * timout finishes */
  289. UA_StatusCode
  290. receiveServiceResponse(UA_Client *client, void *response, const UA_DataType *responseType,
  291. UA_DateTime maxDate, UA_UInt32 *synchronousRequestId) {
  292. /* Prepare the response and the structure we give into processServiceResponse */
  293. SyncResponseDescription rd = { client, false, 0, response, responseType };
  294. /* Return upon receiving the synchronized response. All other responses are
  295. * processed with a callback "in the background". */
  296. if(synchronousRequestId)
  297. rd.requestId = *synchronousRequestId;
  298. UA_StatusCode retval;
  299. do {
  300. UA_DateTime now = UA_DateTime_nowMonotonic();
  301. /* >= avoid timeout to be set to 0 */
  302. if(now >= maxDate)
  303. return UA_STATUSCODE_GOODNONCRITICALTIMEOUT;
  304. /* round always to upper value to avoid timeout to be set to 0
  305. * if(maxDate - now) < (UA_DATETIME_MSEC/2) */
  306. UA_UInt32 timeout = (UA_UInt32)(((maxDate - now) + (UA_DATETIME_MSEC - 1)) / UA_DATETIME_MSEC);
  307. retval = UA_Connection_receiveChunksBlocking(&client->connection, &rd, client_processChunk, timeout);
  308. UA_SecureChannel_processCompleteMessages(&client->channel, &rd, processServiceResponse);
  309. if(retval != UA_STATUSCODE_GOOD && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  310. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
  311. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  312. UA_Client_disconnect(client);
  313. break;
  314. }
  315. } while(!rd.received);
  316. return retval;
  317. }
  318. void
  319. __UA_Client_Service(UA_Client *client, const void *request,
  320. const UA_DataType *requestType, void *response,
  321. const UA_DataType *responseType) {
  322. UA_init(response, responseType);
  323. UA_ResponseHeader *respHeader = (UA_ResponseHeader*)response;
  324. /* Send the request */
  325. UA_UInt32 requestId;
  326. UA_StatusCode retval = sendSymmetricServiceRequest(client, request, requestType, &requestId);
  327. if(retval != UA_STATUSCODE_GOOD) {
  328. if(retval == UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED)
  329. respHeader->serviceResult = UA_STATUSCODE_BADREQUESTTOOLARGE;
  330. else
  331. respHeader->serviceResult = retval;
  332. UA_Client_disconnect(client);
  333. return;
  334. }
  335. /* Retrieve the response */
  336. UA_DateTime maxDate = UA_DateTime_nowMonotonic() +
  337. (client->config.timeout * UA_DATETIME_MSEC);
  338. retval = receiveServiceResponse(client, response, responseType, maxDate, &requestId);
  339. if(retval == UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  340. /* In synchronous service, if we have don't have a reply we need to close the connection */
  341. UA_Client_disconnect(client);
  342. retval = UA_STATUSCODE_BADCONNECTIONCLOSED;
  343. }
  344. if(retval != UA_STATUSCODE_GOOD)
  345. respHeader->serviceResult = retval;
  346. }
  347. UA_StatusCode
  348. receiveServiceResponseAsync(UA_Client *client, void *response,
  349. const UA_DataType *responseType) {
  350. SyncResponseDescription rd = { client, false, 0, response, responseType };
  351. UA_StatusCode retval = UA_Connection_receiveChunksNonBlocking(
  352. &client->connection, &rd, client_processChunk);
  353. UA_SecureChannel_processCompleteMessages(&client->channel, &rd, processServiceResponse);
  354. /*let client run when non critical timeout*/
  355. if(retval != UA_STATUSCODE_GOOD
  356. && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  357. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED) {
  358. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  359. }
  360. UA_Client_disconnect(client);
  361. }
  362. return retval;
  363. }
  364. UA_StatusCode
  365. receivePacketAsync(UA_Client *client) {
  366. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  367. if (UA_Client_getState(client) == UA_CLIENTSTATE_DISCONNECTED ||
  368. UA_Client_getState(client) == UA_CLIENTSTATE_WAITING_FOR_ACK) {
  369. retval = UA_Connection_receiveChunksNonBlocking(&client->connection, client, processACKResponseAsync);
  370. }
  371. else if(UA_Client_getState(client) == UA_CLIENTSTATE_CONNECTED) {
  372. retval = UA_Connection_receiveChunksNonBlocking(&client->connection, client, processOPNResponseAsync);
  373. }
  374. if(retval != UA_STATUSCODE_GOOD && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  375. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
  376. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  377. UA_Client_disconnect(client);
  378. }
  379. return retval;
  380. }
  381. void
  382. UA_Client_AsyncService_cancel(UA_Client *client, AsyncServiceCall *ac,
  383. UA_StatusCode statusCode) {
  384. /* Create an empty response with the statuscode */
  385. UA_STACKARRAY(UA_Byte, responseBuf, ac->responseType->memSize);
  386. void *resp = (void*)(uintptr_t)&responseBuf[0]; /* workaround aliasing rules */
  387. UA_init(resp, ac->responseType);
  388. ((UA_ResponseHeader*)resp)->serviceResult = statusCode;
  389. if(ac->callback)
  390. ac->callback(client, ac->userdata, ac->requestId, resp);
  391. /* Clean up the response. Users might move data into it. For whatever reasons. */
  392. UA_deleteMembers(resp, ac->responseType);
  393. }
  394. void UA_Client_AsyncService_removeAll(UA_Client *client, UA_StatusCode statusCode) {
  395. AsyncServiceCall *ac, *ac_tmp;
  396. LIST_FOREACH_SAFE(ac, &client->asyncServiceCalls, pointers, ac_tmp) {
  397. LIST_REMOVE(ac, pointers);
  398. UA_Client_AsyncService_cancel(client, ac, statusCode);
  399. UA_free(ac);
  400. }
  401. }
  402. UA_StatusCode
  403. __UA_Client_AsyncServiceEx(UA_Client *client, const void *request,
  404. const UA_DataType *requestType,
  405. UA_ClientAsyncServiceCallback callback,
  406. const UA_DataType *responseType,
  407. void *userdata, UA_UInt32 *requestId,
  408. UA_UInt32 timeout) {
  409. /* Prepare the entry for the linked list */
  410. AsyncServiceCall *ac = (AsyncServiceCall*)UA_malloc(sizeof(AsyncServiceCall));
  411. if(!ac)
  412. return UA_STATUSCODE_BADOUTOFMEMORY;
  413. ac->callback = callback;
  414. ac->responseType = responseType;
  415. ac->userdata = userdata;
  416. ac->timeout = timeout;
  417. /* Call the service and set the requestId */
  418. UA_StatusCode retval = sendSymmetricServiceRequest(client, request, requestType, &ac->requestId);
  419. if(retval != UA_STATUSCODE_GOOD) {
  420. UA_free(ac);
  421. return retval;
  422. }
  423. ac->start = UA_DateTime_nowMonotonic();
  424. /* Store the entry for async processing */
  425. LIST_INSERT_HEAD(&client->asyncServiceCalls, ac, pointers);
  426. if(requestId)
  427. *requestId = ac->requestId;
  428. return UA_STATUSCODE_GOOD;
  429. }
  430. UA_StatusCode
  431. __UA_Client_AsyncService(UA_Client *client, const void *request,
  432. const UA_DataType *requestType,
  433. UA_ClientAsyncServiceCallback callback,
  434. const UA_DataType *responseType,
  435. void *userdata, UA_UInt32 *requestId) {
  436. return __UA_Client_AsyncServiceEx(client, request, requestType, callback,
  437. responseType, userdata, requestId,
  438. client->config.timeout);
  439. }
  440. UA_StatusCode
  441. UA_Client_sendAsyncRequest(UA_Client *client, const void *request,
  442. const UA_DataType *requestType,
  443. UA_ClientAsyncServiceCallback callback,
  444. const UA_DataType *responseType, void *userdata,
  445. UA_UInt32 *requestId) {
  446. if (UA_Client_getState(client) < UA_CLIENTSTATE_SECURECHANNEL) {
  447. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  448. "Cient must be connected to send high-level requests");
  449. return UA_STATUSCODE_GOOD;
  450. }
  451. return __UA_Client_AsyncService(client, request, requestType, callback,
  452. responseType, userdata, requestId);
  453. }
  454. UA_StatusCode UA_EXPORT
  455. UA_Client_addTimedCallback(UA_Client *client, UA_ClientCallback callback,
  456. void *data, UA_DateTime date, UA_UInt64 *callbackId) {
  457. return UA_Timer_addTimedCallback(&client->timer, (UA_ApplicationCallback) callback,
  458. client, data, date, callbackId);
  459. }
  460. UA_StatusCode
  461. UA_Client_addRepeatedCallback(UA_Client *client, UA_ClientCallback callback,
  462. void *data, UA_Double interval_ms, UA_UInt64 *callbackId) {
  463. return UA_Timer_addRepeatedCallback(&client->timer, (UA_ApplicationCallback) callback,
  464. client, data, interval_ms, callbackId);
  465. }
  466. UA_StatusCode
  467. UA_Client_changeRepeatedCallbackInterval(UA_Client *client, UA_UInt64 callbackId,
  468. UA_Double interval_ms) {
  469. return UA_Timer_changeRepeatedCallbackInterval(&client->timer, callbackId,
  470. interval_ms);
  471. }
  472. void
  473. UA_Client_removeCallback(UA_Client *client, UA_UInt64 callbackId) {
  474. UA_Timer_removeCallback(&client->timer, callbackId);
  475. }