fuzz_common.h 1.6 KB

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