net_mosq.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (c) 2010-2020 Roger Light <roger@atchoo.org>
  3. All rights reserved. This program and the accompanying materials
  4. are made available under the terms of the Eclipse Public License 2.0
  5. and Eclipse Distribution License v1.0 which accompany this distribution.
  6. The Eclipse Public License is available at
  7. https://www.eclipse.org/legal/epl-2.0/
  8. and the Eclipse Distribution License is available at
  9. http://www.eclipse.org/org/documents/edl-v10.php.
  10. SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
  11. Contributors:
  12. Roger Light - initial implementation and documentation.
  13. */
  14. #ifndef NET_MOSQ_H
  15. #define NET_MOSQ_H
  16. #ifndef WIN32
  17. # include <unistd.h>
  18. #else
  19. # include <winsock2.h>
  20. # ifndef _SSIZE_T_DEFINED
  21. typedef SSIZE_T ssize_t;
  22. # define _SSIZE_T_DEFINED
  23. # endif
  24. #endif
  25. #include "mosquitto_internal.h"
  26. #include "mosquitto.h"
  27. #ifdef WIN32
  28. # define COMPAT_CLOSE(a) closesocket(a)
  29. # define COMPAT_ECONNRESET WSAECONNRESET
  30. # define COMPAT_EINTR WSAEINTR
  31. # define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK
  32. # ifndef EINPROGRESS
  33. # define EINPROGRESS WSAEINPROGRESS
  34. # endif
  35. #else
  36. # define COMPAT_CLOSE(a) close(a)
  37. # define COMPAT_ECONNRESET ECONNRESET
  38. # define COMPAT_EINTR EINTR
  39. # define COMPAT_EWOULDBLOCK EWOULDBLOCK
  40. #endif
  41. /* For when not using winsock libraries. */
  42. #ifndef INVALID_SOCKET
  43. #define INVALID_SOCKET -1
  44. #endif
  45. /* Macros for accessing the MSB and LSB of a uint16_t */
  46. #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8)
  47. #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF)
  48. int net__init(void);
  49. void net__cleanup(void);
  50. #ifdef WITH_TLS
  51. void net__init_tls(void);
  52. #endif
  53. int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking);
  54. int net__socket_close(struct mosquitto *mosq);
  55. int net__try_connect(const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking);
  56. int net__try_connect_step1(struct mosquitto *mosq, const char *host);
  57. int net__try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock);
  58. int net__socket_connect_step3(struct mosquitto *mosq, const char *host);
  59. int net__socket_nonblock(mosq_sock_t *sock);
  60. int net__socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2);
  61. ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count);
  62. ssize_t net__write(struct mosquitto *mosq, const void *buf, size_t count);
  63. #ifdef WITH_TLS
  64. void net__print_ssl_error(struct mosquitto *mosq);
  65. int net__socket_apply_tls(struct mosquitto *mosq);
  66. int net__socket_connect_tls(struct mosquitto *mosq);
  67. int mosquitto__verify_ocsp_status_cb(SSL * ssl, void *arg);
  68. UI_METHOD *net__get_ui_method(void);
  69. #define ENGINE_FINISH(e) if(e) ENGINE_finish(e)
  70. #define ENGINE_SECRET_MODE "SECRET_MODE"
  71. #define ENGINE_SECRET_MODE_SHA 0x1000
  72. #define ENGINE_PIN "PIN"
  73. #endif
  74. #endif