123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- * $Id$
- *
- * Copyright (C) 2007 iptelorg GmbH
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
- /*
- * tls hooks for modules
- *
- * History:
- * --------
- * 2007-02-09 created by andrei
- * 2010-05-14 new hook interface (better suited for async. tcp) (andrei)
- */
- /**
- * @file
- * @brief SIP-router TLS support :: TLS hooks for modules
- * @ingroup tls
- * Module: @ref tls
- */
- #ifndef _tls_hooks_h
- #define _tls_hooks_h
- #ifdef TLS_HOOKS
- #ifndef USE_TLS
- #error "USE_TLS required and not defined (please compile with make \
- TLS_HOOKS=1)"
- #endif
- #ifdef CORE_TLS
- #error "Conflict: CORE_TLS and TLS_HOOKS cannot be defined in the same time"
- #endif
- #include "tcp_conn.h"
- struct tls_hooks{
- int (*read)(struct tcp_connection* c, int* flags);
- /* send using tls on a tcp connection */
- int (*do_send)(int fd, struct tcp_connection* c, const char* buf,
- unsigned int len, snd_flags_t send_flags,
- long* resp);
- /* 1st send using tls on a new async. tcp connection */
- int (*fst_send)(int fd, struct tcp_connection* c, const char* buf,
- unsigned int len, snd_flags_t send_flags,
- long* resp);
- int (*on_tcpconn_init)(struct tcp_connection *c, int sock);
- void (*tcpconn_clean)(struct tcp_connection* c);
- void (*tcpconn_close)(struct tcp_connection*c , int fd);
-
- /* per listening socket init, called on ser startup (after modules,
- * process table, init() and udp socket initialization)*/
- int (*init_si)(struct socket_info* si);
- /* generic init function (called at ser init, after module initialization
- * and process table creation)*/
- int (*init)();
- /* destroy function, called after the modules are destroyed, and
- * after destroy_tcp() */
- void (*destroy)();
- };
- extern struct tls_hooks tls_hook;
- #ifdef __SUNPRO_C
- #define tls_hook_call(name, ret_not_set, ...) \
- ((tls_hook.name)?(tls_hook.name(__VA_ARGS__)): (ret_not_set))
- #define tls_hook_call_v(name, __VA_ARGS__) \
- do{ \
- if (tls_hook.name) tls_hook.name(__VA_ARGS__); \
- }while(0)
- #else
- #define tls_hook_call(name, ret_not_set, args...) \
- ((tls_hook.name)?(tls_hook.name(args)): (ret_not_set))
- #define tls_hook_call_v(name, args...) \
- do{ \
- if (tls_hook.name) tls_hook.name(args); \
- }while(0)
- #endif
- /* hooks */
- #define tls_tcpconn_init(c, s) tls_hook_call(on_tcpconn_init, 0, (c), (s))
- #define tls_tcpconn_clean(c) tls_hook_call_v(tcpconn_clean, (c))
- #define tls_do_send(fd, c, buf, len, send_flags, resp) \
- tls_hook_call(do_send, -1, (fd), (c), (buf), (len), (send_flags), (resp))
- #define tls_1st_send(fd, c, buf, len, send_flags, resp) \
- tls_hook_call(fst_send, -1, (fd), (c), (buf), (len), (send_flags), (resp))
- #define tls_close(conn, fd) tls_hook_call_v(tcpconn_close, (conn), (fd))
- #define tls_read(c, flags) tls_hook_call(read, -1, (c), (flags))
- int register_tls_hooks(struct tls_hooks* h);
- #endif /* TLS_HOOKS */
- #endif
|