Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,112 +0,0 @@
1
-/*
2
- * Copyright (C) 2007 iptelorg GmbH 
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-/**
18
- * @file
19
- * @brief Kamailio TLS support :: TLS hooks for modules
20
- * @ingroup tls
21
- * Module: @ref tls
22
- */
23
-
24
-
25
-#ifndef _tls_hooks_h
26
-#define _tls_hooks_h
27
-
28
-#ifdef TLS_HOOKS
29
-
30
-#ifndef USE_TLS
31
-#error "USE_TLS required and not defined (please compile with make \
32
-	TLS_HOOKS=1)"
33
-#endif
34
-
35
-#ifdef CORE_TLS
36
-#error "Conflict: CORE_TLS and TLS_HOOKS cannot be defined in the same time"
37
-#endif
38
-
39
-#include "tcp_conn.h"
40
-
41
-
42
-
43
-struct tls_hooks{
44
-	/* read using tls (should use tcp internal read functions to
45
-	   get the data from the connection) */
46
-	int  (*read)(struct tcp_connection* c, int* flags);
47
-	/* process data for sending. Should replace pbuf & plen with
48
-	   an internal buffer containing the tls records. If it was not able
49
-	   to process the whole pbuf, it should set (rest_buf, rest_len) to
50
-	   the remaining unprocessed part, else they must be set to 0.
51
-	   send_flags are passed as a pointer and they can also be changed
52
-	   (e.g. reset a FORCE_CLOSE flag if there is internal queued data
53
-	    waiting to be written).
54
-	   If rest_len or rest_buf are not 0 the call will be repeated after the
55
-	   contents of pbuf is sent, with (rest_buf, rest_len) as input.
56
-	   Should return *plen (if >=0).
57
-	   If it returns < 0 => error (tcp connection will be closed).
58
-	*/
59
-	int (*encode)(struct tcp_connection* c,
60
-					const char** pbuf, unsigned int* plen,
61
-					const char** rest_buf, unsigned int* rest_len,
62
-					snd_flags_t* send_flags);
63
-	int  (*on_tcpconn_init)(struct tcp_connection *c, int sock);
64
-	void (*tcpconn_clean)(struct tcp_connection* c);
65
-	void (*tcpconn_close)(struct tcp_connection*c , int fd);
66
-	
67
-	/* per listening socket init, called on kamailio startup (after modules,
68
-	 *  process table, init() and udp socket initialization)*/
69
-	int (*init_si)(struct socket_info* si);
70
-	/* generic init function (called at kamailio init, after module initialization
71
-	 *  and process table creation)*/
72
-	int (*init)(void);
73
-	/* destroy function, called after the modules are destroyed, and 
74
-	 * after  destroy_tcp() */
75
-	void (*destroy)(void);
76
-	/* generic pre-init function (called at kamailio start, before module
77
-	 * initialization (after modparams) */
78
-	int (*pre_init)(void);
79
-};
80
-
81
-
82
-extern struct tls_hooks tls_hook;
83
-
84
-#ifdef __SUNPRO_C
85
-	#define tls_hook_call(name, ret_not_set, ...) \
86
-		((tls_hook.name)?(tls_hook.name(__VA_ARGS__)): (ret_not_set))
87
-	#define tls_hook_call_v(name, ...) \
88
-		do{ \
89
-			if (tls_hook.name) tls_hook.name(__VA_ARGS__); \
90
-		}while(0)
91
-#else
92
-	#define tls_hook_call(name, ret_not_set, args...) \
93
-		((tls_hook.name)?(tls_hook.name(args)): (ret_not_set))
94
-	#define tls_hook_call_v(name, args...) \
95
-		do{ \
96
-			if (tls_hook.name) tls_hook.name(args); \
97
-		}while(0)
98
-#endif
99
-
100
-/* hooks */
101
-
102
-#define tls_tcpconn_init(c, s)	tls_hook_call(on_tcpconn_init, 0, (c), (s))
103
-#define tls_tcpconn_clean(c)	tls_hook_call_v(tcpconn_clean, (c))
104
-#define tls_encode(c, pbuf, plen, rbuf, rlen, sflags) \
105
-	tls_hook_call(encode, -1, (c), (pbuf), (plen), (rbuf), (rlen), (sflags))
106
-#define tls_close(conn, fd)		tls_hook_call_v(tcpconn_close, (conn), (fd))
107
-#define tls_read(c, flags)				tls_hook_call(read, -1, (c), (flags))
108
-
109
-int register_tls_hooks(struct tls_hooks* h);
110
-
111
-#endif /* TLS_HOOKS */
112
-#endif
Browse code

core: fix Sun Studio build

- update Makefile.defs for recent versions of Solaris Studio

Spencer Thomason authored on 30/06/2016 19:44:11
Showing 1 changed files
... ...
@@ -84,7 +84,7 @@ extern struct tls_hooks tls_hook;
84 84
 #ifdef __SUNPRO_C
85 85
 	#define tls_hook_call(name, ret_not_set, ...) \
86 86
 		((tls_hook.name)?(tls_hook.name(__VA_ARGS__)): (ret_not_set))
87
-	#define tls_hook_call_v(name, __VA_ARGS__) \
87
+	#define tls_hook_call_v(name, ...) \
88 88
 		do{ \
89 89
 			if (tls_hook.name) tls_hook.name(__VA_ARGS__); \
90 90
 		}while(0)
Browse code

core: tls hooks can execute a callback before modules init function is executed

- useful to prepare tls environment before a module might access it
- executed after modparam but before mod_init

Daniel-Constantin Mierla authored on 25/01/2015 09:57:00
Showing 1 changed files
... ...
@@ -64,15 +64,18 @@ struct tls_hooks{
64 64
 	void (*tcpconn_clean)(struct tcp_connection* c);
65 65
 	void (*tcpconn_close)(struct tcp_connection*c , int fd);
66 66
 	
67
-	/* per listening socket init, called on ser startup (after modules,
67
+	/* per listening socket init, called on kamailio startup (after modules,
68 68
 	 *  process table, init() and udp socket initialization)*/
69 69
 	int (*init_si)(struct socket_info* si);
70
-	/* generic init function (called at ser init, after module initialization
70
+	/* generic init function (called at kamailio init, after module initialization
71 71
 	 *  and process table creation)*/
72 72
 	int (*init)(void);
73 73
 	/* destroy function, called after the modules are destroyed, and 
74 74
 	 * after  destroy_tcp() */
75 75
 	void (*destroy)(void);
76
+	/* generic pre-init function (called at kamailio start, before module
77
+	 * initialization (after modparams) */
78
+	int (*pre_init)(void);
76 79
 };
77 80
 
78 81
 
Browse code

core: Modify doxygen, remove history, remove SVN IDs, change "ser" and "sip-router" to "KAMAILIO"

Olle E. Johansson authored on 16/01/2015 16:38:46
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2007 iptelorg GmbH 
5 3
  *
6 4
  * Permission to use, copy, modify, and distribute this software for any
... ...
@@ -15,18 +13,10 @@
15 13
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 14
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 15
  */
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 16
 
27 17
 /**
28 18
  * @file
29
- * @brief SIP-router TLS support :: TLS hooks for modules
19
+ * @brief Kamailio TLS support :: TLS hooks for modules
30 20
  * @ingroup tls
31 21
  * Module: @ref tls
32 22
  */
Browse code

core: Added void to declarations of functions with empty argument list

In C language, a declaration in the form int f(); is equivalent to int f(...);, thus being able to accept an indefinit number of parameters. With the -Wstrict-prototypes GCC options, these declarations are reported as "function declaration isn’t a prototype".
On some cases, this may trick the compiler into generating unoptimized code (like preparing to handle variadic argument list).
In all cases having a declaration int f() and a definition inf f(int) is missleading, even if standard compliant.
This is still Work in Progress. (maybe adding the -Wstrict-prototypes option to default is desireable)

Marius Zbihlei authored on 02/04/2012 14:19:17
Showing 1 changed files
... ...
@@ -79,10 +79,10 @@ struct tls_hooks{
79 79
 	int (*init_si)(struct socket_info* si);
80 80
 	/* generic init function (called at ser init, after module initialization
81 81
 	 *  and process table creation)*/
82
-	int (*init)();
82
+	int (*init)(void);
83 83
 	/* destroy function, called after the modules are destroyed, and 
84 84
 	 * after  destroy_tcp() */
85
-	void (*destroy)();
85
+	void (*destroy)(void);
86 86
 };
87 87
 
88 88
 
Browse code

tcp: support for tls partial encoding

The tls_encode() callback supports now partial encoding. It can
encode only part of the input buffer (e.g. tls partial write
enabled and not enough space in the internal buffers for all the
tls records) and ask to be called back later with the remaining
un-encoded part.
The send flags are also passed to it, so that it can modify them
if needed (e.g. reset SND_F_CON_CLOSE on partial tls write or when
reading some data is needed before continuing the tls write).

Andrei Pelinescu-Onciul authored on 05/07/2010 12:44:14
Showing 1 changed files
... ...
@@ -55,12 +55,21 @@ struct tls_hooks{
55 55
 	   get the data from the connection) */
56 56
 	int  (*read)(struct tcp_connection* c, int* flags);
57 57
 	/* process data for sending. Should replace pbuf & plen with
58
-	   an internal buffer containing the tls records.
58
+	   an internal buffer containing the tls records. If it was not able
59
+	   to process the whole pbuf, it should set (rest_buf, rest_len) to
60
+	   the remaining unprocessed part, else they must be set to 0.
61
+	   send_flags are passed as a pointer and they can also be changed
62
+	   (e.g. reset a FORCE_CLOSE flag if there is internal queued data
63
+	    waiting to be written).
64
+	   If rest_len or rest_buf are not 0 the call will be repeated after the
65
+	   contents of pbuf is sent, with (rest_buf, rest_len) as input.
59 66
 	   Should return *plen (if >=0).
60 67
 	   If it returns < 0 => error (tcp connection will be closed).
61 68
 	*/
62
-	int (*encode)(struct tcp_connection* c, const char** pbuf,
63
-						unsigned int* plen);
69
+	int (*encode)(struct tcp_connection* c,
70
+					const char** pbuf, unsigned int* plen,
71
+					const char** rest_buf, unsigned int* rest_len,
72
+					snd_flags_t* send_flags);
64 73
 	int  (*on_tcpconn_init)(struct tcp_connection *c, int sock);
65 74
 	void (*tcpconn_clean)(struct tcp_connection* c);
66 75
 	void (*tcpconn_close)(struct tcp_connection*c , int fd);
... ...
@@ -99,8 +108,8 @@ extern struct tls_hooks tls_hook;
99 108
 
100 109
 #define tls_tcpconn_init(c, s)	tls_hook_call(on_tcpconn_init, 0, (c), (s))
101 110
 #define tls_tcpconn_clean(c)	tls_hook_call_v(tcpconn_clean, (c))
102
-#define tls_encode(c, pbuf, plen) \
103
-	tls_hook_call(encode, -1, (c), (pbuf), (plen))
111
+#define tls_encode(c, pbuf, plen, rbuf, rlen, sflags) \
112
+	tls_hook_call(encode, -1, (c), (pbuf), (plen), (rbuf), (rlen), (sflags))
104 113
 #define tls_close(conn, fd)		tls_hook_call_v(tcpconn_close, (conn), (fd))
105 114
 #define tls_read(c, flags)				tls_hook_call(read, -1, (c), (flags))
106 115
 
Browse code

tcp: change tls send callback interface

Instead of 2 different tls send callbacks (with a 3rd one needed),
switch to a different model: 1 tls callback that is supposed to
replace the passed buffer with a tls processed version of it.
This simplifies the tls code and more importantly doesn't require
that the tls send code has very detailed knowledge about the tcp
state machine. Some of the saved complexity moved from the tls
module to the tcp code, but at least this way on changes there's
only one place to update.
The tls callbacks for reading and sending are now very different:
while the send callback has become now more of an encoder
callback, the read callback should still perform the tcp read by
itself. While this is not very consistent it does saves unneeded
memory copies.

Andrei Pelinescu-Onciul authored on 23/06/2010 21:17:15
Showing 1 changed files
... ...
@@ -51,15 +51,16 @@
51 51
 
52 52
 
53 53
 struct tls_hooks{
54
+	/* read using tls (should use tcp internal read functions to
55
+	   get the data from the connection) */
54 56
 	int  (*read)(struct tcp_connection* c, int* flags);
55
-	/* send using tls on a tcp connection */
56
-	int (*do_send)(int fd, struct tcp_connection* c, const char* buf,
57
-							unsigned int len, snd_flags_t send_flags,
58
-							long* resp);
59
-	/* 1st send using tls on a new async. tcp connection */
60
-	int (*fst_send)(int fd, struct tcp_connection* c, const char* buf,
61
-							unsigned int len, snd_flags_t send_flags,
62
-							long* resp);
57
+	/* process data for sending. Should replace pbuf & plen with
58
+	   an internal buffer containing the tls records.
59
+	   Should return *plen (if >=0).
60
+	   If it returns < 0 => error (tcp connection will be closed).
61
+	*/
62
+	int (*encode)(struct tcp_connection* c, const char** pbuf,
63
+						unsigned int* plen);
63 64
 	int  (*on_tcpconn_init)(struct tcp_connection *c, int sock);
64 65
 	void (*tcpconn_clean)(struct tcp_connection* c);
65 66
 	void (*tcpconn_close)(struct tcp_connection*c , int fd);
... ...
@@ -98,10 +99,8 @@ extern struct tls_hooks tls_hook;
98 99
 
99 100
 #define tls_tcpconn_init(c, s)	tls_hook_call(on_tcpconn_init, 0, (c), (s))
100 101
 #define tls_tcpconn_clean(c)	tls_hook_call_v(tcpconn_clean, (c))
101
-#define tls_do_send(fd, c, buf, len, send_flags, resp) \
102
-	tls_hook_call(do_send, -1, (fd), (c), (buf), (len), (send_flags), (resp))
103
-#define tls_1st_send(fd, c, buf, len, send_flags, resp) \
104
-	tls_hook_call(fst_send, -1, (fd), (c), (buf), (len), (send_flags), (resp))
102
+#define tls_encode(c, pbuf, plen) \
103
+	tls_hook_call(encode, -1, (c), (pbuf), (plen))
105 104
 #define tls_close(conn, fd)		tls_hook_call_v(tcpconn_close, (conn), (fd))
106 105
 #define tls_read(c, flags)				tls_hook_call(read, -1, (c), (flags))
107 106
 
Browse code

tcp: new tls hooks interface and async tls changes

- new tls hooks interface that better accommodates tls async use.
Changed read() (takes an extra flags parameter now), removed
blocking_write() and fix_read_con(), added do_send() and
fst_send() (both of them handle snd_flags now and might return a
command that should be sent to tcp_main).
- more tcp send functions (tcpconn_1st_send(),
tcpconn_send_unsafe()) and more send functions exported
(tls_int_send.h) for use from the tls module.
- split tcp_read() into tcp_read() and tcp_read_data() and
exported tcp_read_data() (tcp_read.h).
- support for repeating a tcp_read() if indicated
(RD_CONN_REPEAT_READ), needed for tls.

Andrei Pelinescu-Onciul authored on 20/05/2010 14:00:29
Showing 1 changed files
... ...
@@ -21,6 +21,7 @@
21 21
  * History:
22 22
  * --------
23 23
  *  2007-02-09  created by andrei
24
+ *  2010-05-14  new hook interface (better suited for async. tcp) (andrei)
24 25
  */
25 26
 
26 27
 /**
... ...
@@ -50,21 +51,18 @@
50 51
 
51 52
 
52 53
 struct tls_hooks{
53
-	int  (*read)(struct tcp_connection* c);
54
-	int (*blocking_write)(struct tcp_connection* c, int fd, const char* buf,
55
-							unsigned int len);
54
+	int  (*read)(struct tcp_connection* c, int* flags);
55
+	/* send using tls on a tcp connection */
56
+	int (*do_send)(int fd, struct tcp_connection* c, const char* buf,
57
+							unsigned int len, snd_flags_t send_flags,
58
+							long* resp);
59
+	/* 1st send using tls on a new async. tcp connection */
60
+	int (*fst_send)(int fd, struct tcp_connection* c, const char* buf,
61
+							unsigned int len, snd_flags_t send_flags,
62
+							long* resp);
56 63
 	int  (*on_tcpconn_init)(struct tcp_connection *c, int sock);
57 64
 	void (*tcpconn_clean)(struct tcp_connection* c);
58 65
 	void (*tcpconn_close)(struct tcp_connection*c , int fd);
59
-	/* checks if a tls connection is fully established before a read, and if 
60
-	 * not it runs tls_accept() or tls_connect() as needed
61
-	 * (tls_accept and tls_connect are deferred to the "reader" process for
62
-	 *  performance reasons)
63
-	 * returns 1 if the read can continue, 0 if the connection is not yet
64
-	 * ready for the read and fix_read_con() should be attempted at a latter
65
-	 * time and <0 on error.
66
-	 */
67
-	int (*fix_read_con)(struct tcp_connection* c);
68 66
 	
69 67
 	/* per listening socket init, called on ser startup (after modules,
70 68
 	 *  process table, init() and udp socket initialization)*/
... ...
@@ -100,11 +98,12 @@ extern struct tls_hooks tls_hook;
100 98
 
101 99
 #define tls_tcpconn_init(c, s)	tls_hook_call(on_tcpconn_init, 0, (c), (s))
102 100
 #define tls_tcpconn_clean(c)	tls_hook_call_v(tcpconn_clean, (c))
103
-#define tls_blocking_write(c, fd, buf, len) \
104
-	tls_hook_call(blocking_write, -1, (c), (fd), (buf), (len))
101
+#define tls_do_send(fd, c, buf, len, send_flags, resp) \
102
+	tls_hook_call(do_send, -1, (fd), (c), (buf), (len), (send_flags), (resp))
103
+#define tls_1st_send(fd, c, buf, len, send_flags, resp) \
104
+	tls_hook_call(fst_send, -1, (fd), (c), (buf), (len), (send_flags), (resp))
105 105
 #define tls_close(conn, fd)		tls_hook_call_v(tcpconn_close, (conn), (fd))
106
-#define tls_read(c)				tls_hook_call(read, -1, (c))
107
-#define tls_fix_read_conn(c)	tls_hook_call(fix_read_con, -1, (c))
106
+#define tls_read(c, flags)				tls_hook_call(read, -1, (c), (flags))
108 107
 
109 108
 int register_tls_hooks(struct tls_hooks* h);
110 109
 
Browse code

Doxygen updates

oej authored on 22/10/2009 17:59:29
Showing 1 changed files
... ...
@@ -23,6 +23,14 @@
23 23
  *  2007-02-09  created by andrei
24 24
  */
25 25
 
26
+/**
27
+ * @file
28
+ * @brief SIP-router TLS support :: TLS hooks for modules
29
+ * @ingroup tls
30
+ * Module: @ref tls
31
+ */
32
+
33
+
26 34
 #ifndef _tls_hooks_h
27 35
 #define _tls_hooks_h
28 36
 
Browse code

tcp: tls fix_read_con hook return changes

tls_fix_read_con doesn't change the tcp connection state any
longer, relying instead on different return codes.

Andrei Pelinescu-Onciul authored on 21/09/2009 16:41:26
Showing 1 changed files
... ...
@@ -51,7 +51,11 @@ struct tls_hooks{
51 51
 	/* checks if a tls connection is fully established before a read, and if 
52 52
 	 * not it runs tls_accept() or tls_connect() as needed
53 53
 	 * (tls_accept and tls_connect are deferred to the "reader" process for
54
-	 *  performance reasons) */
54
+	 *  performance reasons)
55
+	 * returns 1 if the read can continue, 0 if the connection is not yet
56
+	 * ready for the read and fix_read_con() should be attempted at a latter
57
+	 * time and <0 on error.
58
+	 */
55 59
 	int (*fix_read_con)(struct tcp_connection* c);
56 60
 	
57 61
 	/* per listening socket init, called on ser startup (after modules,
Browse code

- fixes: missing extern for variables declared in *.h files (can cause different symbols with the same name => unexpected bugs)

Andrei Pelinescu-Onciul authored on 15/04/2008 17:38:33
Showing 1 changed files
... ...
@@ -66,7 +66,7 @@ struct tls_hooks{
66 66
 };
67 67
 
68 68
 
69
-struct tls_hooks tls_hook;
69
+extern struct tls_hooks tls_hook;
70 70
 
71 71
 #ifdef __SUNPRO_C
72 72
 	#define tls_hook_call(name, ret_not_set, ...) \
Browse code

- tls hooks support: special tls hooks added in core that allow a module or core part to provide a tls implementation. Support for the old in-core tls compile options is preserved (but one can compile with either tls hooks support or tls-in-core support, not with both in the same time). Changes were kept to a minimum. - Makefiles: make TLS=1 deprecated, use instead make TLS_HOOKS=1 or make CORE_TLS=1 (if in-core tls support is needed). Added TLS_EXTRA_LIBS (e.g. make CORE_TLS=1 TLS_EXTRA_LIBS="-lz -lkrb5").

Andrei Pelinescu-Onciul authored on 10/02/2007 18:52:48
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,100 @@
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
+ */
25
+
26
+#ifndef _tls_hooks_h
27
+#define _tls_hooks_h
28
+
29
+#ifdef TLS_HOOKS
30
+
31
+#ifndef USE_TLS
32
+#error "USE_TLS required and not defined (please compile with make \
33
+	TLS_HOOKS=1)"
34
+#endif
35
+
36
+#ifdef CORE_TLS
37
+#error "Conflict: CORE_TLS and TLS_HOOKS cannot be defined in the same time"
38
+#endif
39
+
40
+#include "tcp_conn.h"
41
+
42
+
43
+
44
+struct tls_hooks{
45
+	int  (*read)(struct tcp_connection* c);
46
+	int (*blocking_write)(struct tcp_connection* c, int fd, const char* buf,
47
+							unsigned int len);
48
+	int  (*on_tcpconn_init)(struct tcp_connection *c, int sock);
49
+	void (*tcpconn_clean)(struct tcp_connection* c);
50
+	void (*tcpconn_close)(struct tcp_connection*c , int fd);
51
+	/* checks if a tls connection is fully established before a read, and if 
52
+	 * not it runs tls_accept() or tls_connect() as needed
53
+	 * (tls_accept and tls_connect are deferred to the "reader" process for
54
+	 *  performance reasons) */
55
+	int (*fix_read_con)(struct tcp_connection* c);
56
+	
57
+	/* per listening socket init, called on ser startup (after modules,
58
+	 *  process table, init() and udp socket initialization)*/
59
+	int (*init_si)(struct socket_info* si);
60
+	/* generic init function (called at ser init, after module initialization
61
+	 *  and process table creation)*/
62
+	int (*init)();
63
+	/* destroy function, called after the modules are destroyed, and 
64
+	 * after  destroy_tcp() */
65
+	void (*destroy)();
66
+};
67
+
68
+
69
+struct tls_hooks tls_hook;
70
+
71
+#ifdef __SUNPRO_C
72
+	#define tls_hook_call(name, ret_not_set, ...) \
73
+		((tls_hook.name)?(tls_hook.name(__VA_ARGS__)): (ret_not_set))
74
+	#define tls_hook_call_v(name, __VA_ARGS__) \
75
+		do{ \
76
+			if (tls_hook.name) tls_hook.name(__VA_ARGS__); \
77
+		}while(0)
78
+#else
79
+	#define tls_hook_call(name, ret_not_set, args...) \
80
+		((tls_hook.name)?(tls_hook.name(args)): (ret_not_set))
81
+	#define tls_hook_call_v(name, args...) \
82
+		do{ \
83
+			if (tls_hook.name) tls_hook.name(args); \
84
+		}while(0)
85
+#endif
86
+
87
+/* hooks */
88
+
89
+#define tls_tcpconn_init(c, s)	tls_hook_call(on_tcpconn_init, 0, (c), (s))
90
+#define tls_tcpconn_clean(c)	tls_hook_call_v(tcpconn_clean, (c))
91
+#define tls_blocking_write(c, fd, buf, len) \
92
+	tls_hook_call(blocking_write, -1, (c), (fd), (buf), (len))
93
+#define tls_close(conn, fd)		tls_hook_call_v(tcpconn_close, (conn), (fd))
94
+#define tls_read(c)				tls_hook_call(read, -1, (c))
95
+#define tls_fix_read_conn(c)	tls_hook_call(fix_read_con, -1, (c))
96
+
97
+int register_tls_hooks(struct tls_hooks* h);
98
+
99
+#endif /* TLS_HOOKS */
100
+#endif