ua_client.c 21 KB

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