• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

tls_hooks.h

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2007 iptelorg GmbH 
00005  *
00006  * Permission to use, copy, modify, and distribute this software for any
00007  * purpose with or without fee is hereby granted, provided that the above
00008  * copyright notice and this permission notice appear in all copies.
00009  *
00010  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00011  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00012  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00013  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00014  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00016  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00017  */
00018 /*
00019  * tls hooks for modules
00020  *
00021  * History:
00022  * --------
00023  *  2007-02-09  created by andrei
00024  *  2010-05-14  new hook interface (better suited for async. tcp) (andrei)
00025  */
00026 
00035 #ifndef _tls_hooks_h
00036 #define _tls_hooks_h
00037 
00038 #ifdef TLS_HOOKS
00039 
00040 #ifndef USE_TLS
00041 #error "USE_TLS required and not defined (please compile with make \
00042         TLS_HOOKS=1)"
00043 #endif
00044 
00045 #ifdef CORE_TLS
00046 #error "Conflict: CORE_TLS and TLS_HOOKS cannot be defined in the same time"
00047 #endif
00048 
00049 #include "tcp_conn.h"
00050 
00051 
00052 
00053 struct tls_hooks{
00054         /* read using tls (should use tcp internal read functions to
00055            get the data from the connection) */
00056         int  (*read)(struct tcp_connection* c, int* flags);
00057         /* process data for sending. Should replace pbuf & plen with
00058            an internal buffer containing the tls records. If it was not able
00059            to process the whole pbuf, it should set (rest_buf, rest_len) to
00060            the remaining unprocessed part, else they must be set to 0.
00061            send_flags are passed as a pointer and they can also be changed
00062            (e.g. reset a FORCE_CLOSE flag if there is internal queued data
00063             waiting to be written).
00064            If rest_len or rest_buf are not 0 the call will be repeated after the
00065            contents of pbuf is sent, with (rest_buf, rest_len) as input.
00066            Should return *plen (if >=0).
00067            If it returns < 0 => error (tcp connection will be closed).
00068         */
00069         int (*encode)(struct tcp_connection* c,
00070                                         const char** pbuf, unsigned int* plen,
00071                                         const char** rest_buf, unsigned int* rest_len,
00072                                         snd_flags_t* send_flags);
00073         int  (*on_tcpconn_init)(struct tcp_connection *c, int sock);
00074         void (*tcpconn_clean)(struct tcp_connection* c);
00075         void (*tcpconn_close)(struct tcp_connection*c , int fd);
00076         
00077         /* per listening socket init, called on ser startup (after modules,
00078          *  process table, init() and udp socket initialization)*/
00079         int (*init_si)(struct socket_info* si);
00080         /* generic init function (called at ser init, after module initialization
00081          *  and process table creation)*/
00082         int (*init)(void);
00083         /* destroy function, called after the modules are destroyed, and 
00084          * after  destroy_tcp() */
00085         void (*destroy)(void);
00086 };
00087 
00088 
00089 extern struct tls_hooks tls_hook;
00090 
00091 #ifdef __SUNPRO_C
00092         #define tls_hook_call(name, ret_not_set, ...) \
00093                 ((tls_hook.name)?(tls_hook.name(__VA_ARGS__)): (ret_not_set))
00094         #define tls_hook_call_v(name, __VA_ARGS__) \
00095                 do{ \
00096                         if (tls_hook.name) tls_hook.name(__VA_ARGS__); \
00097                 }while(0)
00098 #else
00099         #define tls_hook_call(name, ret_not_set, args...) \
00100                 ((tls_hook.name)?(tls_hook.name(args)): (ret_not_set))
00101         #define tls_hook_call_v(name, args...) \
00102                 do{ \
00103                         if (tls_hook.name) tls_hook.name(args); \
00104                 }while(0)
00105 #endif
00106 
00107 /* hooks */
00108 
00109 #define tls_tcpconn_init(c, s)  tls_hook_call(on_tcpconn_init, 0, (c), (s))
00110 #define tls_tcpconn_clean(c)    tls_hook_call_v(tcpconn_clean, (c))
00111 #define tls_encode(c, pbuf, plen, rbuf, rlen, sflags) \
00112         tls_hook_call(encode, -1, (c), (pbuf), (plen), (rbuf), (rlen), (sflags))
00113 #define tls_close(conn, fd)             tls_hook_call_v(tcpconn_close, (conn), (fd))
00114 #define tls_read(c, flags)                              tls_hook_call(read, -1, (c), (flags))
00115 
00116 int register_tls_hooks(struct tls_hooks* h);
00117 
00118 #endif /* TLS_HOOKS */
00119 #endif

Generated on Tue May 22 2012 13:10:17 for SIP Router by  doxygen 1.7.1