ua_client.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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, client->config.customDataTypes);
  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. } else if(((UA_ResponseHeader*)response)->serviceResult != UA_STATUSCODE_GOOD) {
  198. /* Decode as a ServiceFault, i.e. only the response header */
  199. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  200. "The ServiceResult has the StatusCode %s",
  201. UA_StatusCode_name(((UA_ResponseHeader*)response)->serviceResult));
  202. }
  203. /* Call the callback */
  204. if(ac->callback)
  205. ac->callback(client, ac->userdata, requestId, response);
  206. UA_deleteMembers(response, ac->responseType);
  207. /* Remove the callback */
  208. LIST_REMOVE(ac, pointers);
  209. UA_free(ac);
  210. return retval;
  211. }
  212. /* Processes the received service response. Either with an async callback or by
  213. * decoding the message and returning it "upwards" in the
  214. * SyncResponseDescription. */
  215. static void
  216. processServiceResponse(void *application, UA_SecureChannel *channel,
  217. UA_MessageType messageType, UA_UInt32 requestId,
  218. const UA_ByteString *message) {
  219. SyncResponseDescription *rd = (SyncResponseDescription*)application;
  220. /* Must be OPN or MSG */
  221. if(messageType != UA_MESSAGETYPE_OPN &&
  222. messageType != UA_MESSAGETYPE_MSG) {
  223. UA_LOG_TRACE_CHANNEL(&rd->client->config.logger, channel,
  224. "Invalid message type");
  225. return;
  226. }
  227. /* Forward declaration for the goto */
  228. UA_NodeId expectedNodeId = UA_NODEID_NULL;
  229. /* Decode the data type identifier of the response */
  230. size_t offset = 0;
  231. UA_NodeId responseId;
  232. UA_StatusCode retval = UA_NodeId_decodeBinary(message, &offset, &responseId);
  233. if(retval != UA_STATUSCODE_GOOD)
  234. goto finish;
  235. /* Got an asynchronous response. Don't expected a synchronous response
  236. * (responseType NULL) or the id does not match. */
  237. if(!rd->responseType || requestId != rd->requestId) {
  238. retval = processAsyncResponse(rd->client, requestId, &responseId, message, &offset);
  239. goto finish;
  240. }
  241. /* Got the synchronous response */
  242. rd->received = true;
  243. /* Check that the response type matches */
  244. expectedNodeId = UA_NODEID_NUMERIC(0, rd->responseType->binaryEncodingId);
  245. if(!UA_NodeId_equal(&responseId, &expectedNodeId)) {
  246. if(UA_NodeId_equal(&responseId, &serviceFaultId)) {
  247. UA_init(rd->response, rd->responseType);
  248. retval = UA_decodeBinary(message, &offset, rd->response,
  249. &UA_TYPES[UA_TYPES_SERVICEFAULT],
  250. rd->client->config.customDataTypes);
  251. if(retval != UA_STATUSCODE_GOOD)
  252. ((UA_ResponseHeader*)rd->response)->serviceResult = retval;
  253. UA_LOG_INFO(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  254. "Received a ServiceFault response with StatusCode %s",
  255. UA_StatusCode_name(((UA_ResponseHeader*)rd->response)->serviceResult));
  256. } else {
  257. /* Close the connection */
  258. UA_LOG_ERROR(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  259. "Reply contains the wrong service response");
  260. retval = UA_STATUSCODE_BADCOMMUNICATIONERROR;
  261. }
  262. goto finish;
  263. }
  264. #ifdef UA_ENABLE_TYPENAMES
  265. UA_LOG_DEBUG(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  266. "Decode a message of type %s", rd->responseType->typeName);
  267. #else
  268. UA_LOG_DEBUG(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  269. "Decode a message of type %u", responseId.identifier.numeric);
  270. #endif
  271. /* Decode the response */
  272. retval = UA_decodeBinary(message, &offset, rd->response, rd->responseType,
  273. rd->client->config.customDataTypes);
  274. finish:
  275. UA_NodeId_deleteMembers(&responseId);
  276. if(retval != UA_STATUSCODE_GOOD) {
  277. if(retval == UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED)
  278. retval = UA_STATUSCODE_BADRESPONSETOOLARGE;
  279. UA_LOG_INFO(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  280. "Error receiving the response with status code %s",
  281. UA_StatusCode_name(retval));
  282. if(rd->response) {
  283. UA_ResponseHeader *respHeader = (UA_ResponseHeader*)rd->response;
  284. respHeader->serviceResult = retval;
  285. }
  286. }
  287. }
  288. /* Forward complete chunks directly to the securechannel */
  289. static UA_StatusCode
  290. client_processChunk(void *application, UA_Connection *connection, UA_ByteString *chunk) {
  291. SyncResponseDescription *rd = (SyncResponseDescription*)application;
  292. UA_StatusCode retval = UA_SecureChannel_decryptAddChunk(&rd->client->channel, chunk, true);
  293. if(retval != UA_STATUSCODE_GOOD)
  294. return retval;
  295. return UA_SecureChannel_persistIncompleteMessages(&rd->client->channel);
  296. }
  297. /* Receive and process messages until a synchronous message arrives or the
  298. * timout finishes */
  299. UA_StatusCode
  300. receiveServiceResponse(UA_Client *client, void *response, const UA_DataType *responseType,
  301. UA_DateTime maxDate, const UA_UInt32 *synchronousRequestId) {
  302. /* Prepare the response and the structure we give into processServiceResponse */
  303. SyncResponseDescription rd = { client, false, 0, response, responseType };
  304. /* Return upon receiving the synchronized response. All other responses are
  305. * processed with a callback "in the background". */
  306. if(synchronousRequestId)
  307. rd.requestId = *synchronousRequestId;
  308. UA_StatusCode retval;
  309. do {
  310. UA_DateTime now = UA_DateTime_nowMonotonic();
  311. /* >= avoid timeout to be set to 0 */
  312. if(now >= maxDate)
  313. return UA_STATUSCODE_GOODNONCRITICALTIMEOUT;
  314. /* round always to upper value to avoid timeout to be set to 0
  315. * if(maxDate - now) < (UA_DATETIME_MSEC/2) */
  316. UA_UInt32 timeout = (UA_UInt32)(((maxDate - now) + (UA_DATETIME_MSEC - 1)) / UA_DATETIME_MSEC);
  317. retval = UA_Connection_receiveChunksBlocking(&client->connection, &rd, client_processChunk, timeout);
  318. UA_SecureChannel_processCompleteMessages(&client->channel, &rd, processServiceResponse);
  319. if(retval != UA_STATUSCODE_GOOD && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  320. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
  321. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  322. UA_Client_disconnect(client);
  323. break;
  324. }
  325. } while(!rd.received);
  326. return retval;
  327. }
  328. void
  329. __UA_Client_Service(UA_Client *client, const void *request,
  330. const UA_DataType *requestType, void *response,
  331. const UA_DataType *responseType) {
  332. UA_init(response, responseType);
  333. UA_ResponseHeader *respHeader = (UA_ResponseHeader*)response;
  334. /* Send the request */
  335. UA_UInt32 requestId;
  336. UA_StatusCode retval = sendSymmetricServiceRequest(client, request, requestType, &requestId);
  337. if(retval != UA_STATUSCODE_GOOD) {
  338. if(retval == UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED)
  339. respHeader->serviceResult = UA_STATUSCODE_BADREQUESTTOOLARGE;
  340. else
  341. respHeader->serviceResult = retval;
  342. UA_Client_disconnect(client);
  343. return;
  344. }
  345. /* Retrieve the response */
  346. UA_DateTime maxDate = UA_DateTime_nowMonotonic() +
  347. (client->config.timeout * UA_DATETIME_MSEC);
  348. retval = receiveServiceResponse(client, response, responseType, maxDate, &requestId);
  349. if(retval == UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  350. /* In synchronous service, if we have don't have a reply we need to close the connection */
  351. UA_Client_disconnect(client);
  352. retval = UA_STATUSCODE_BADCONNECTIONCLOSED;
  353. }
  354. if(retval != UA_STATUSCODE_GOOD)
  355. respHeader->serviceResult = retval;
  356. }
  357. UA_StatusCode
  358. receiveServiceResponseAsync(UA_Client *client, void *response,
  359. const UA_DataType *responseType) {
  360. SyncResponseDescription rd = { client, false, 0, response, responseType };
  361. UA_StatusCode retval = UA_Connection_receiveChunksNonBlocking(
  362. &client->connection, &rd, client_processChunk);
  363. UA_SecureChannel_processCompleteMessages(&client->channel, &rd, processServiceResponse);
  364. /*let client run when non critical timeout*/
  365. if(retval != UA_STATUSCODE_GOOD
  366. && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  367. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED) {
  368. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  369. }
  370. UA_Client_disconnect(client);
  371. }
  372. return retval;
  373. }
  374. UA_StatusCode
  375. receivePacketAsync(UA_Client *client) {
  376. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  377. if (UA_Client_getState(client) == UA_CLIENTSTATE_DISCONNECTED ||
  378. UA_Client_getState(client) == UA_CLIENTSTATE_WAITING_FOR_ACK) {
  379. retval = UA_Connection_receiveChunksNonBlocking(&client->connection, client, processACKResponseAsync);
  380. }
  381. else if(UA_Client_getState(client) == UA_CLIENTSTATE_CONNECTED) {
  382. retval = UA_Connection_receiveChunksNonBlocking(&client->connection, client, processOPNResponseAsync);
  383. }
  384. if(retval != UA_STATUSCODE_GOOD && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  385. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
  386. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  387. UA_Client_disconnect(client);
  388. }
  389. return retval;
  390. }
  391. void
  392. UA_Client_AsyncService_cancel(UA_Client *client, AsyncServiceCall *ac,
  393. UA_StatusCode statusCode) {
  394. /* Create an empty response with the statuscode */
  395. UA_STACKARRAY(UA_Byte, responseBuf, ac->responseType->memSize);
  396. void *resp = (void*)(uintptr_t)&responseBuf[0]; /* workaround aliasing rules */
  397. UA_init(resp, ac->responseType);
  398. ((UA_ResponseHeader*)resp)->serviceResult = statusCode;
  399. if(ac->callback)
  400. ac->callback(client, ac->userdata, ac->requestId, resp);
  401. /* Clean up the response. Users might move data into it. For whatever reasons. */
  402. UA_deleteMembers(resp, ac->responseType);
  403. }
  404. void UA_Client_AsyncService_removeAll(UA_Client *client, UA_StatusCode statusCode) {
  405. AsyncServiceCall *ac, *ac_tmp;
  406. LIST_FOREACH_SAFE(ac, &client->asyncServiceCalls, pointers, ac_tmp) {
  407. LIST_REMOVE(ac, pointers);
  408. UA_Client_AsyncService_cancel(client, ac, statusCode);
  409. UA_free(ac);
  410. }
  411. }
  412. UA_StatusCode
  413. __UA_Client_AsyncServiceEx(UA_Client *client, const void *request,
  414. const UA_DataType *requestType,
  415. UA_ClientAsyncServiceCallback callback,
  416. const UA_DataType *responseType,
  417. void *userdata, UA_UInt32 *requestId,
  418. UA_UInt32 timeout) {
  419. /* Prepare the entry for the linked list */
  420. AsyncServiceCall *ac = (AsyncServiceCall*)UA_malloc(sizeof(AsyncServiceCall));
  421. if(!ac)
  422. return UA_STATUSCODE_BADOUTOFMEMORY;
  423. ac->callback = callback;
  424. ac->responseType = responseType;
  425. ac->userdata = userdata;
  426. ac->timeout = timeout;
  427. /* Call the service and set the requestId */
  428. UA_StatusCode retval = sendSymmetricServiceRequest(client, request, requestType, &ac->requestId);
  429. if(retval != UA_STATUSCODE_GOOD) {
  430. UA_free(ac);
  431. return retval;
  432. }
  433. ac->start = UA_DateTime_nowMonotonic();
  434. /* Store the entry for async processing */
  435. LIST_INSERT_HEAD(&client->asyncServiceCalls, ac, pointers);
  436. if(requestId)
  437. *requestId = ac->requestId;
  438. return UA_STATUSCODE_GOOD;
  439. }
  440. UA_StatusCode
  441. __UA_Client_AsyncService(UA_Client *client, const void *request,
  442. const UA_DataType *requestType,
  443. UA_ClientAsyncServiceCallback callback,
  444. const UA_DataType *responseType,
  445. void *userdata, UA_UInt32 *requestId) {
  446. return __UA_Client_AsyncServiceEx(client, request, requestType, callback,
  447. responseType, userdata, requestId,
  448. client->config.timeout);
  449. }
  450. UA_StatusCode
  451. UA_Client_sendAsyncRequest(UA_Client *client, const void *request,
  452. const UA_DataType *requestType,
  453. UA_ClientAsyncServiceCallback callback,
  454. const UA_DataType *responseType, void *userdata,
  455. UA_UInt32 *requestId) {
  456. if (UA_Client_getState(client) < UA_CLIENTSTATE_SECURECHANNEL) {
  457. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  458. "Cient must be connected to send high-level requests");
  459. return UA_STATUSCODE_GOOD;
  460. }
  461. return __UA_Client_AsyncService(client, request, requestType, callback,
  462. responseType, userdata, requestId);
  463. }
  464. UA_StatusCode UA_EXPORT
  465. UA_Client_addTimedCallback(UA_Client *client, UA_ClientCallback callback,
  466. void *data, UA_DateTime date, UA_UInt64 *callbackId) {
  467. return UA_Timer_addTimedCallback(&client->timer, (UA_ApplicationCallback) callback,
  468. client, data, date, callbackId);
  469. }
  470. UA_StatusCode
  471. UA_Client_addRepeatedCallback(UA_Client *client, UA_ClientCallback callback,
  472. void *data, UA_Double interval_ms, UA_UInt64 *callbackId) {
  473. return UA_Timer_addRepeatedCallback(&client->timer, (UA_ApplicationCallback) callback,
  474. client, data, interval_ms, callbackId);
  475. }
  476. UA_StatusCode
  477. UA_Client_changeRepeatedCallbackInterval(UA_Client *client, UA_UInt64 callbackId,
  478. UA_Double interval_ms) {
  479. return UA_Timer_changeRepeatedCallbackInterval(&client->timer, callbackId,
  480. interval_ms);
  481. }
  482. void
  483. UA_Client_removeCallback(UA_Client *client, UA_UInt64 callbackId) {
  484. UA_Timer_removeCallback(&client->timer, callbackId);
  485. }