testing_networklayers.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <stdlib.h>
  5. #include "testing_networklayers.h"
  6. #include "ua_config_standard.h"
  7. static UA_StatusCode
  8. dummyGetSendBuffer(UA_Connection *connection, size_t length, UA_ByteString *buf) {
  9. buf->data = length == 0 ? NULL : (UA_Byte*)UA_malloc(length);
  10. buf->length = length;
  11. return UA_STATUSCODE_GOOD;
  12. }
  13. static void
  14. dummyReleaseSendBuffer(UA_Connection *connection, UA_ByteString *buf) {
  15. UA_ByteString_deleteMembers(buf);
  16. }
  17. static UA_StatusCode
  18. dummySend(UA_Connection *connection, UA_ByteString *buf) {
  19. UA_ByteString_deleteMembers(buf);
  20. return UA_STATUSCODE_GOOD;
  21. }
  22. static void
  23. dummyReleaseRecvBuffer(UA_Connection *connection, UA_ByteString *buf) {
  24. UA_ByteString_deleteMembers(buf);
  25. }
  26. static void
  27. dummyClose(UA_Connection *connection) {
  28. return;
  29. }
  30. UA_Connection createDummyConnection(void) {
  31. UA_Connection c;
  32. c.state = UA_CONNECTION_ESTABLISHED;
  33. c.localConf = UA_ConnectionConfig_default;
  34. c.remoteConf = UA_ConnectionConfig_default;
  35. c.channel = NULL;
  36. c.sockfd = 0;
  37. c.handle = NULL;
  38. c.incompleteMessage = UA_BYTESTRING_NULL;
  39. c.getSendBuffer = dummyGetSendBuffer;
  40. c.releaseSendBuffer = dummyReleaseSendBuffer;
  41. c.send = dummySend;
  42. c.recv = NULL;
  43. c.releaseRecvBuffer = dummyReleaseRecvBuffer;
  44. c.close = dummyClose;
  45. return c;
  46. }