ua_util.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 2018 (c) Stefan Profanter, fortiss GmbH
  6. */
  7. #ifndef UA_HELPER_H_
  8. #define UA_HELPER_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include "ua_config.h"
  13. #include "ua_types.h"
  14. /**
  15. * Endpoint URL Parser
  16. * -------------------
  17. * The endpoint URL parser is generally useful for the implementation of network
  18. * layer plugins. */
  19. /* Split the given endpoint url into hostname, port and path. All arguments must
  20. * be non-NULL. EndpointUrls have the form "opc.tcp://hostname:port/path", port
  21. * and path may be omitted (together with the prefix colon and slash).
  22. *
  23. * @param endpointUrl The endpoint URL.
  24. * @param outHostname Set to the parsed hostname. The string points into the
  25. * original endpointUrl, so no memory is allocated. If an IPv6 address is
  26. * given, hostname contains e.g. '[2001:0db8:85a3::8a2e:0370:7334]'
  27. * @param outPort Set to the port of the url or left unchanged.
  28. * @param outPath Set to the path if one is present in the endpointUrl.
  29. * Starting or trailing '/' are NOT included in the path. The string
  30. * points into the original endpointUrl, so no memory is allocated.
  31. * @return Returns UA_STATUSCODE_BADTCPENDPOINTURLINVALID if parsing failed. */
  32. UA_StatusCode UA_EXPORT
  33. UA_parseEndpointUrl(const UA_String *endpointUrl, UA_String *outHostname,
  34. UA_UInt16 *outPort, UA_String *outPath);
  35. /**
  36. * Convenience macros for complex types
  37. * ------------------------------------ */
  38. #define UA_PRINTF_GUID_FORMAT "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"
  39. #define UA_PRINTF_GUID_DATA(GUID) (GUID).data1, (GUID).data2, (GUID).data3, \
  40. (GUID).data4[0], (GUID).data4[1], (GUID).data4[2], (GUID).data4[3], \
  41. (GUID).data4[4], (GUID).data4[5], (GUID).data4[6], (GUID).data4[7]
  42. #define UA_PRINTF_STRING_FORMAT "\"%.*s\""
  43. #define UA_PRINTF_STRING_DATA(STRING) (int)(STRING).length, (STRING).data
  44. //TODO remove when we merge architectures pull request
  45. #ifndef UA_snprintf
  46. # include <stdio.h>
  47. # if defined(_WIN32)
  48. # define UA_snprintf(source, size, string, ...) _snprintf_s(source, size, _TRUNCATE, string, __VA_ARGS__)
  49. # else
  50. # define UA_snprintf snprintf
  51. # endif
  52. #endif
  53. /**
  54. * Helper functions for converting data types
  55. * ------------------------------------ */
  56. /*
  57. * Converts a bytestring to the corresponding base64 encoded string representation.
  58. *
  59. * @param byteString the original byte string
  60. * @param str the resulting base64 encoded byte string
  61. *
  62. * @return UA_STATUSCODE_GOOD on success.
  63. */
  64. UA_StatusCode UA_EXPORT
  65. UA_ByteString_toBase64String(const UA_ByteString *byteString, UA_String *str);
  66. /*
  67. * Converts a node id to the corresponding string representation.
  68. * It can be one of:
  69. * - Numeric: ns=0;i=123
  70. * - String: ns=0;s=Some String
  71. * - Guid: ns=0;g=A123456C-0ABC-1A2B-815F-687212AAEE1B
  72. * - ByteString: ns=0;b=AA==
  73. *
  74. */
  75. UA_StatusCode UA_EXPORT
  76. UA_NodeId_toString(const UA_NodeId *nodeId, UA_String *nodeIdStr);
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* UA_HELPER_H_ */