You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ssl_util.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SRC_LIBUTIL_SSL_UTIL_H_
  17. #define SRC_LIBUTIL_SSL_UTIL_H_
  18. #include "config.h"
  19. #include "libutil/addr.h"
  20. struct rspamd_ssl_connection;
  21. typedef void (*rspamd_ssl_handler_t)(gint fd, short what, gpointer d);
  22. typedef void (*rspamd_ssl_error_handler_t)(gpointer d, GError *err);
  23. /**
  24. * Creates a new ssl connection data structure
  25. * @param ssl_ctx initialized SSL_CTX structure
  26. * @return opaque connection data
  27. */
  28. struct rspamd_ssl_connection * rspamd_ssl_connection_new (gpointer ssl_ctx,
  29. struct event_base *ev_base, gboolean verify_peer);
  30. /**
  31. * Connects SSL session using the specified (connected) FD
  32. * @param conn connection
  33. * @param fd fd to use
  34. * @param hostname hostname for SNI
  35. * @param ev event to use
  36. * @param tv timeout for connection
  37. * @param handler connected session handler
  38. * @param handler_data opaque data
  39. * @return TRUE if a session has been connected
  40. */
  41. gboolean rspamd_ssl_connect_fd (struct rspamd_ssl_connection *conn, gint fd,
  42. const gchar *hostname, struct event *ev, struct timeval *tv,
  43. rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler,
  44. gpointer handler_data);
  45. /**
  46. * Perform async read from SSL socket
  47. * @param conn
  48. * @param buf
  49. * @param buflen
  50. * @return
  51. */
  52. gssize rspamd_ssl_read (struct rspamd_ssl_connection *conn, gpointer buf,
  53. gsize buflen);
  54. /**
  55. * Perform async write to ssl buffer
  56. * @param conn
  57. * @param buf
  58. * @param buflen
  59. * @param ev
  60. * @param tv
  61. * @return
  62. */
  63. gssize rspamd_ssl_write (struct rspamd_ssl_connection *conn, gconstpointer buf,
  64. gsize buflen);
  65. /**
  66. * Emulate writev by copying iovec to a temporary buffer
  67. * @param conn
  68. * @param buf
  69. * @param buflen
  70. * @return
  71. */
  72. gssize rspamd_ssl_writev (struct rspamd_ssl_connection *conn, struct iovec *iov,
  73. gsize iovlen);
  74. /**
  75. * Removes connection data
  76. * @param conn
  77. */
  78. void rspamd_ssl_connection_free (struct rspamd_ssl_connection *conn);
  79. #endif /* SRC_LIBUTIL_SSL_UTIL_H_ */