tls_hooks.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2007 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * tls hooks for modules
  20. *
  21. * History:
  22. * --------
  23. * 2007-02-09 created by andrei
  24. * 2010-05-14 new hook interface (better suited for async. tcp) (andrei)
  25. */
  26. /**
  27. * @file
  28. * @brief SIP-router TLS support :: TLS hooks for modules
  29. * @ingroup tls
  30. * Module: @ref tls
  31. */
  32. #ifndef _tls_hooks_h
  33. #define _tls_hooks_h
  34. #ifdef TLS_HOOKS
  35. #ifndef USE_TLS
  36. #error "USE_TLS required and not defined (please compile with make \
  37. TLS_HOOKS=1)"
  38. #endif
  39. #ifdef CORE_TLS
  40. #error "Conflict: CORE_TLS and TLS_HOOKS cannot be defined in the same time"
  41. #endif
  42. #include "tcp_conn.h"
  43. struct tls_hooks{
  44. int (*read)(struct tcp_connection* c, int* flags);
  45. /* send using tls on a tcp connection */
  46. int (*do_send)(int fd, struct tcp_connection* c, const char* buf,
  47. unsigned int len, snd_flags_t send_flags,
  48. long* resp);
  49. /* 1st send using tls on a new async. tcp connection */
  50. int (*fst_send)(int fd, struct tcp_connection* c, const char* buf,
  51. unsigned int len, snd_flags_t send_flags,
  52. long* resp);
  53. int (*on_tcpconn_init)(struct tcp_connection *c, int sock);
  54. void (*tcpconn_clean)(struct tcp_connection* c);
  55. void (*tcpconn_close)(struct tcp_connection*c , int fd);
  56. /* per listening socket init, called on ser startup (after modules,
  57. * process table, init() and udp socket initialization)*/
  58. int (*init_si)(struct socket_info* si);
  59. /* generic init function (called at ser init, after module initialization
  60. * and process table creation)*/
  61. int (*init)();
  62. /* destroy function, called after the modules are destroyed, and
  63. * after destroy_tcp() */
  64. void (*destroy)();
  65. };
  66. extern struct tls_hooks tls_hook;
  67. #ifdef __SUNPRO_C
  68. #define tls_hook_call(name, ret_not_set, ...) \
  69. ((tls_hook.name)?(tls_hook.name(__VA_ARGS__)): (ret_not_set))
  70. #define tls_hook_call_v(name, __VA_ARGS__) \
  71. do{ \
  72. if (tls_hook.name) tls_hook.name(__VA_ARGS__); \
  73. }while(0)
  74. #else
  75. #define tls_hook_call(name, ret_not_set, args...) \
  76. ((tls_hook.name)?(tls_hook.name(args)): (ret_not_set))
  77. #define tls_hook_call_v(name, args...) \
  78. do{ \
  79. if (tls_hook.name) tls_hook.name(args); \
  80. }while(0)
  81. #endif
  82. /* hooks */
  83. #define tls_tcpconn_init(c, s) tls_hook_call(on_tcpconn_init, 0, (c), (s))
  84. #define tls_tcpconn_clean(c) tls_hook_call_v(tcpconn_clean, (c))
  85. #define tls_do_send(fd, c, buf, len, send_flags, resp) \
  86. tls_hook_call(do_send, -1, (fd), (c), (buf), (len), (send_flags), (resp))
  87. #define tls_1st_send(fd, c, buf, len, send_flags, resp) \
  88. tls_hook_call(fst_send, -1, (fd), (c), (buf), (len), (send_flags), (resp))
  89. #define tls_close(conn, fd) tls_hook_call_v(tcpconn_close, (conn), (fd))
  90. #define tls_read(c, flags) tls_hook_call(read, -1, (c), (flags))
  91. int register_tls_hooks(struct tls_hooks* h);
  92. #endif /* TLS_HOOKS */
  93. #endif