File: tls_hooks.h

package info (click to toggle)
kamailio 4.2.0-2+deb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 56,276 kB
  • sloc: ansic: 552,836; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (119 lines) | stat: -rw-r--r-- 3,988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * $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{
	/* read using tls (should use tcp internal read functions to
	   get the data from the connection) */
	int  (*read)(struct tcp_connection* c, int* flags);
	/* process data for sending. Should replace pbuf & plen with
	   an internal buffer containing the tls records. If it was not able
	   to process the whole pbuf, it should set (rest_buf, rest_len) to
	   the remaining unprocessed part, else they must be set to 0.
	   send_flags are passed as a pointer and they can also be changed
	   (e.g. reset a FORCE_CLOSE flag if there is internal queued data
	    waiting to be written).
	   If rest_len or rest_buf are not 0 the call will be repeated after the
	   contents of pbuf is sent, with (rest_buf, rest_len) as input.
	   Should return *plen (if >=0).
	   If it returns < 0 => error (tcp connection will be closed).
	*/
	int (*encode)(struct tcp_connection* c,
					const char** pbuf, unsigned int* plen,
					const char** rest_buf, unsigned int* rest_len,
					snd_flags_t* send_flags);
	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)(void);
	/* destroy function, called after the modules are destroyed, and 
	 * after  destroy_tcp() */
	void (*destroy)(void);
};


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_encode(c, pbuf, plen, rbuf, rlen, sflags) \
	tls_hook_call(encode, -1, (c), (pbuf), (plen), (rbuf), (rlen), (sflags))
#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