fuzz_common.h 1.6 KB

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