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,295 +0,0 @@
1
-/*
2
- * Copyright (C) 2001-2003 FhG Fokus
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version
10
- *
11
- * Kamailio is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
- */
20
-/*!
21
-* \file
22
-* \brief Kamailio core :: Message forwarding
23
-* \author andrei
24
-* \ingroup core
25
-* Module: \ref core
26
-*/
27
-
28
-#ifndef forward_h
29
-#define forward_h
30
-
31
-#include "globals.h"
32
-#include "parser/msg_parser.h"
33
-#include "route.h"
34
-#include "proxy.h"
35
-#include "ip_addr.h"
36
-
37
-#include "stats.h"
38
-#include "udp_server.h"
39
-#ifdef USE_TCP
40
-#include "tcp_server.h"
41
-#include "tcp_conn.h"
42
-#endif
43
-#ifdef USE_SCTP
44
-#include "sctp_core.h"
45
-#endif
46
-
47
-#include "compiler_opt.h"
48
-#include "events.h"
49
-
50
-
51
-enum ss_mismatch {
52
-	SS_MISMATCH_OK=0,
53
-	SS_MISMATCH_PROTO, /* proto mismatch, but found same addr:port */
54
-	SS_MISMATCH_ADDR,  /* proto and addr:port mismatch */
55
-	SS_MISMATCH_AF,    /* af mismatch */
56
-	SS_MISMATCH_MCAST  /* mcast forced send socket */
57
-};
58
-
59
-
60
-struct socket_info* get_send_socket2(struct socket_info* force_send_socket,
61
-									union sockaddr_union* su, int proto,
62
-									enum ss_mismatch* mismatch);
63
-
64
-
65
-inline static struct socket_info* get_send_socket(struct sip_msg* msg,
66
-									union sockaddr_union* su, int proto)
67
-{
68
-	return get_send_socket2(msg?msg->force_send_socket:0, su, proto, 0);
69
-}
70
-
71
-
72
-#define GET_URI_PORT(uri) ((uri)->port_no?(uri)->port_no:(((uri)->proto==PROTO_TLS)?SIPS_PORT:SIP_PORT))
73
-
74
-struct socket_info* get_out_socket(union sockaddr_union* to, int proto);
75
-typedef int (*check_self_f)(str* host, unsigned short port,
76
-		unsigned short proto);
77
-int register_check_self_func(check_self_f f);
78
-int check_self(str* host, unsigned short port, unsigned short proto);
79
-int check_self_port(unsigned short port, unsigned short proto);
80
-int forward_request( struct sip_msg* msg, str* dst,  unsigned short port,
81
-						struct dest_info* send_info);
82
-int update_sock_struct_from_via( union sockaddr_union* to,
83
-								 struct sip_msg* msg,
84
-								 struct via_body* via );
85
-
86
-/* use src_ip, port=src_port if rport, via port if via port, 5060 otherwise */
87
-#define update_sock_struct_from_ip(  to, msg ) \
88
-	init_su((to), &(msg)->rcv.src_ip, \
89
-			(((msg)->via1->rport)|| \
90
-			 (((msg)->msg_flags|global_req_flags)&FL_FORCE_RPORT))? \
91
-							(msg)->rcv.src_port: \
92
-							((msg)->via1->port)?(msg)->via1->port: SIP_PORT )
93
-
94
-int forward_reply( struct sip_msg* msg);
95
-int forward_reply_nocb( struct sip_msg* msg);
96
-
97
-void forward_set_send_info(int v);
98
-
99
-int is_check_self_func_list_set(void);
100
-
101
-#define msg_send(_dst, _buf, _len) msg_send_buffer((_dst), (_buf), (_len), 0)
102
-
103
-/* params:
104
- * dst = struct dest_info containing:
105
- *    send_sock = 0 if not known (e.g. for udp in some cases), non-0 otherwise;
106
- *                if 0 or mcast a new send_sock will be automatically choosen
107
- *    proto = TCP|UDP
108
- *    to = destination (sockaddr_union)
109
- *    id = only used on tcp, it will force sending on connection "id" if id!=0 
110
- *         and the connection exists, else it will send to "to" 
111
- *        (useful for sending replies on  the same connection as the request
112
- *         that generated them; use 0 if you don't want this)
113
- * buf, len = buffer
114
- * flags = control internal behavior
115
- *    * 1 - skip executing event SREV_NET_DATA_OUT
116
- * returns: 0 if ok, -1 on error*/
117
-
118
-static inline int msg_send_buffer(struct dest_info* dst, char* buf, int len,
119
-		int flags)
120
-{
121
-	struct dest_info new_dst;
122
-	str outb;
123
-	sr_net_info_t netinfo;
124
-
125
-#ifdef USE_TCP 
126
-	int port;
127
-	struct ip_addr ip;
128
-	union sockaddr_union* from = NULL;
129
-	union sockaddr_union local_addr;
130
-	struct tcp_connection *con = NULL;
131
-	struct ws_event_info wsev;
132
-	int ret;
133
-#endif
134
-	
135
-	outb.s = buf;
136
-	outb.len = len;
137
-	if(!(flags&1)) {
138
-		sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
139
-	}
140
-
141
-	if(outb.s==NULL) {
142
-		LM_ERR("failed to update outgoing buffer\n");
143
-		return -1;
144
-	}
145
-
146
-#ifdef USE_TCP
147
-	if (unlikely((dst->proto == PROTO_WS
148
-#ifdef USE_TLS
149
-		|| dst->proto == PROTO_WSS
150
-#endif
151
-	) && sr_event_enabled(SREV_TCP_WS_FRAME_OUT))) {
152
-		if (unlikely(dst->send_flags.f & SND_F_FORCE_SOCKET
153
-				&& dst->send_sock)) {
154
-			local_addr = dst->send_sock->su;
155
-			su_setport(&local_addr, 0); /* any local port will do */
156
-			from = &local_addr;
157
-		}
158
-
159
-		port = su_getport(&dst->to);
160
-		if (likely(port)) {
161
-			su2ip_addr(&ip, &dst->to);
162
-			con = tcpconn_get(dst->id, &ip, port, from, 0);
163
-		}
164
-		else if (likely(dst->id))
165
-			con = tcpconn_get(dst->id, 0, 0, 0, 0);
166
-		else {
167
-			LM_CRIT("null_id & to\n");
168
-			goto error;
169
-		}
170
-
171
-		if (con == NULL)
172
-		{
173
-			LM_WARN("TCP/TLS connection for WebSocket could not be found\n");
174
-			goto error;
175
-		}
176
-
177
-		memset(&wsev, 0, sizeof(ws_event_info_t));
178
-		wsev.type = SREV_TCP_WS_FRAME_OUT;
179
-		wsev.buf = outb.s;
180
-		wsev.len = outb.len;
181
-		wsev.id = con->id;
182
-		ret = sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
183
-		tcpconn_put(con);
184
-		goto done;
185
-	}
186
-#endif
187
-
188
-	if (likely(dst->proto==PROTO_UDP)){
189
-		if (unlikely((dst->send_sock==0) || 
190
-					(dst->send_sock->flags & SI_IS_MCAST))){
191
-			new_dst=*dst;
192
-			new_dst.send_sock=get_send_socket(0, &dst->to, dst->proto);
193
-			if (unlikely(new_dst.send_sock==0)){
194
-				LM_ERR("no sending socket found\n");
195
-				goto error;
196
-			}
197
-			dst=&new_dst;
198
-		}
199
-		if (unlikely(udp_send(dst, outb.s, outb.len)==-1)){
200
-			STATS_TX_DROPS;
201
-			LOG(cfg_get(core, core_cfg, corelog), "udp_send failed\n");
202
-			goto error;
203
-		}
204
-	}
205
-#ifdef USE_TCP
206
-	else if (dst->proto==PROTO_TCP){
207
-		if (unlikely(tcp_disable)){
208
-			STATS_TX_DROPS;
209
-			LM_WARN("attempt to send on tcp and tcp support is disabled\n");
210
-			goto error;
211
-		}else{
212
-			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
213
-						dst->send_sock)) {
214
-				local_addr=dst->send_sock->su;
215
-				su_setport(&local_addr, 0); /* any local port will do */
216
-				from=&local_addr;
217
-			}
218
-			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
219
-				STATS_TX_DROPS;
220
-				LOG(cfg_get(core, core_cfg, corelog), "tcp_send failed\n");
221
-				goto error;
222
-			}
223
-		}
224
-	}
225
-#ifdef USE_TLS
226
-	else if (dst->proto==PROTO_TLS){
227
-		if (unlikely(tls_disable)){
228
-			STATS_TX_DROPS;
229
-			LM_WARN("attempt to send on tls and tls support is disabled\n");
230
-			goto error;
231
-		}else{
232
-			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
233
-						dst->send_sock)) {
234
-				local_addr=dst->send_sock->su;
235
-				su_setport(&local_addr, 0); /* any local port will do */
236
-				from=&local_addr;
237
-			}
238
-			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
239
-				STATS_TX_DROPS;
240
-				LOG(cfg_get(core, core_cfg, corelog), "tcp_send failed\n");
241
-				goto error;
242
-			}
243
-		}
244
-	}
245
-#endif /* USE_TLS */
246
-#endif /* USE_TCP */
247
-#ifdef USE_SCTP
248
-	else if (dst->proto==PROTO_SCTP){
249
-		if (unlikely(sctp_disable)){
250
-			STATS_TX_DROPS;
251
-			LM_WARN("attempt to send on sctp and sctp support is disabled\n");
252
-			goto error;
253
-		}else{
254
-			if (unlikely(dst->send_sock==0)){
255
-				new_dst=*dst;
256
-				new_dst.send_sock=get_send_socket(0, &dst->to, dst->proto);
257
-				if (unlikely(new_dst.send_sock==0)){
258
-					LM_ERR("no sending SCTP socket found\n");
259
-					goto error;
260
-				}
261
-				dst=&new_dst;
262
-			}
263
-			if (unlikely(sctp_core_msg_send(dst, outb.s, outb.len)<0)){
264
-				STATS_TX_DROPS;
265
-				LOG(cfg_get(core, core_cfg, corelog), "sctp_msg_send failed\n");
266
-				goto error;
267
-			}
268
-		}
269
-	}
270
-#endif /* USE_SCTP */
271
-	else{
272
-			LM_CRIT("unknown proto %d\n", dst->proto);
273
-			goto error;
274
-	}
275
-	ret = 0;
276
-done:
277
-
278
-	if(!(flags&1)) {
279
-		memset(&netinfo, 0, sizeof(sr_net_info_t));
280
-		netinfo.data.s = outb.s;
281
-		netinfo.data.len = outb.len;
282
-		netinfo.dst = dst;
283
-		sr_event_exec(SREV_NET_DATA_SEND, (void*)&netinfo);
284
-	}
285
-
286
-	if(outb.s != buf)
287
-		pkg_free(outb.s);
288
-	return ret;
289
-error:
290
-	if(outb.s != buf)
291
-		pkg_free(outb.s);
292
-	return -1;
293
-}
294
-
295
-#endif
Browse code

core: relocated sr_net_info_t struct for availability

Daniel-Constantin Mierla authored on 11/01/2016 21:20:43
Showing 1 changed files
... ...
@@ -56,10 +56,6 @@ enum ss_mismatch {
56 56
 	SS_MISMATCH_MCAST  /* mcast forced send socket */
57 57
 };
58 58
 
59
-typedef struct sr_send_info {
60
-	str data;
61
-	struct dest_info* dst;
62
-} sr_net_info_t;
63 59
 
64 60
 struct socket_info* get_send_socket2(struct socket_info* force_send_socket,
65 61
 									union sockaddr_union* su, int proto,
Browse code

core: execute event SREV_NET_DATA_SEND if data was sent to network

Daniel-Constantin Mierla authored on 11/01/2016 11:40:59
Showing 1 changed files
... ...
@@ -56,6 +56,11 @@ enum ss_mismatch {
56 56
 	SS_MISMATCH_MCAST  /* mcast forced send socket */
57 57
 };
58 58
 
59
+typedef struct sr_send_info {
60
+	str data;
61
+	struct dest_info* dst;
62
+} sr_net_info_t;
63
+
59 64
 struct socket_info* get_send_socket2(struct socket_info* force_send_socket,
60 65
 									union sockaddr_union* su, int proto,
61 66
 									enum ss_mismatch* mismatch);
... ...
@@ -119,6 +124,8 @@ static inline int msg_send_buffer(struct dest_info* dst, char* buf, int len,
119 124
 {
120 125
 	struct dest_info new_dst;
121 126
 	str outb;
127
+	sr_net_info_t netinfo;
128
+
122 129
 #ifdef USE_TCP 
123 130
 	int port;
124 131
 	struct ip_addr ip;
... ...
@@ -271,6 +278,15 @@ static inline int msg_send_buffer(struct dest_info* dst, char* buf, int len,
271 278
 	}
272 279
 	ret = 0;
273 280
 done:
281
+
282
+	if(!(flags&1)) {
283
+		memset(&netinfo, 0, sizeof(sr_net_info_t));
284
+		netinfo.data.s = outb.s;
285
+		netinfo.data.len = outb.len;
286
+		netinfo.dst = dst;
287
+		sr_event_exec(SREV_NET_DATA_SEND, (void*)&netinfo);
288
+	}
289
+
274 290
 	if(outb.s != buf)
275 291
 		pkg_free(outb.s);
276 292
 	return ret;
Browse code

core: added msg_send_buffer() function to allow skipping execution of core events

- useful for non-sip messages sent out to skip execution of
SREV_NET_DATA_OUT, like HEP packets for sipcapture
- msg_send() is now a defined alias for msg_send_buffer()

Daniel-Constantin Mierla authored on 06/01/2016 09:03:00
Showing 1 changed files
... ...
@@ -97,6 +97,7 @@ void forward_set_send_info(int v);
97 97
 
98 98
 int is_check_self_func_list_set(void);
99 99
 
100
+#define msg_send(_dst, _buf, _len) msg_send_buffer((_dst), (_buf), (_len), 0)
100 101
 
101 102
 /* params:
102 103
  * dst = struct dest_info containing:
... ...
@@ -109,9 +110,12 @@ int is_check_self_func_list_set(void);
109 110
  *        (useful for sending replies on  the same connection as the request
110 111
  *         that generated them; use 0 if you don't want this)
111 112
  * buf, len = buffer
113
+ * flags = control internal behavior
114
+ *    * 1 - skip executing event SREV_NET_DATA_OUT
112 115
  * returns: 0 if ok, -1 on error*/
113 116
 
114
-static inline int msg_send(struct dest_info* dst, char* buf, int len)
117
+static inline int msg_send_buffer(struct dest_info* dst, char* buf, int len,
118
+		int flags)
115 119
 {
116 120
 	struct dest_info new_dst;
117 121
 	str outb;
... ...
@@ -127,7 +131,9 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
127 131
 	
128 132
 	outb.s = buf;
129 133
 	outb.len = len;
130
-	sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
134
+	if(!(flags&1)) {
135
+		sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
136
+	}
131 137
 
132 138
 	if(outb.s==NULL) {
133 139
 		LM_ERR("failed to update outgoing buffer\n");
Browse code

core : Update include files - delete IDs, update doxygen, delete history

Olle E. Johansson authored on 03/01/2015 10:55:48
Showing 1 changed files
... ...
@@ -1,21 +1,14 @@
1 1
 /*
2
- *  $Id$
3
- *
4 2
  * Copyright (C) 2001-2003 FhG Fokus
5 3
  *
6
- * This file is part of ser, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
7 5
  *
8
- * ser is free software; you can redistribute it and/or modify
6
+ * Kamailio is free software; you can redistribute it and/or modify
9 7
  * it under the terms of the GNU General Public License as published by
10 8
  * the Free Software Foundation; either version 2 of the License, or
11 9
  * (at your option) any later version
12 10
  *
13
- * For a license to use the ser software under conditions
14
- * other than those described here, or to purchase support for this
15
- * software, please contact iptel.org by e-mail at the following addresses:
16
- *    info@iptel.org
17
- *
18
- * ser is distributed in the hope that it will be useful,
11
+ * Kamailio is distributed in the hope that it will be useful,
19 12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 14
  * GNU General Public License for more details.
... ...
@@ -24,22 +17,13 @@
24 17
  * along with this program; if not, write to the Free Software 
25 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 19
  */
27
-/*
28
- * History:
29
- * -------
30
- *  2001-??-?? created by andrei
31
- *  ????-??-?? lots of changes by a lot of people
32
- *  2003-02-11 added inline msg_send (andrei)
33
- *  2003-04-07 changed all ports to host byte order (andrei)
34
- *  2003-04-12  FORCE_RPORT_T added (andrei)
35
- *  2003-04-15  added tcp_disable support (andrei)
36
- *  2006-04-12  reduced msg_send() parameter list: it uses now a struct 
37
- *               dest_info param. (andrei)
38
- *  2007-10-08  msg_send() will ignore a mcast send_sock and choose another
39
- *               one by itself (andrei)
40
- */
41
-
42
-
20
+/*!
21
+* \file
22
+* \brief Kamailio core :: Message forwarding
23
+* \author andrei
24
+* \ingroup core
25
+* Module: \ref core
26
+*/
43 27
 
44 28
 #ifndef forward_h
45 29
 #define forward_h
Browse code

core: use corelog level for debug messages when sending out fails

- allow better control of what is printed, FS#68

Daniel-Constantin Mierla authored on 23/12/2014 09:25:58
Showing 1 changed files
... ...
@@ -205,7 +205,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
205 205
 		}
206 206
 		if (unlikely(udp_send(dst, outb.s, outb.len)==-1)){
207 207
 			STATS_TX_DROPS;
208
-			LM_ERR("udp_send failed\n");
208
+			LOG(cfg_get(core, core_cfg, corelog), "udp_send failed\n");
209 209
 			goto error;
210 210
 		}
211 211
 	}
... ...
@@ -224,7 +224,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
224 224
 			}
225 225
 			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
226 226
 				STATS_TX_DROPS;
227
-				LM_ERR("tcp_send failed\n");
227
+				LOG(cfg_get(core, core_cfg, corelog), "tcp_send failed\n");
228 228
 				goto error;
229 229
 			}
230 230
 		}
... ...
@@ -244,7 +244,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
244 244
 			}
245 245
 			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
246 246
 				STATS_TX_DROPS;
247
-				LM_ERR("tcp_send failed\n");
247
+				LOG(cfg_get(core, core_cfg, corelog), "tcp_send failed\n");
248 248
 				goto error;
249 249
 			}
250 250
 		}
... ...
@@ -269,7 +269,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
269 269
 			}
270 270
 			if (unlikely(sctp_core_msg_send(dst, outb.s, outb.len)<0)){
271 271
 				STATS_TX_DROPS;
272
-				LM_ERR("sctp_msg_send failed\n");
272
+				LOG(cfg_get(core, core_cfg, corelog), "sctp_msg_send failed\n");
273 273
 				goto error;
274 274
 			}
275 275
 		}
Browse code

forward.h: logging: convert LOG to LM_*

Ovidiu Sas authored on 03/10/2014 20:53:49
Showing 1 changed files
... ...
@@ -171,7 +171,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
171 171
 		else if (likely(dst->id))
172 172
 			con = tcpconn_get(dst->id, 0, 0, 0, 0);
173 173
 		else {
174
-			LM_CRIT("BUG: msg_send called with null_id & to\n");
174
+			LM_CRIT("null_id & to\n");
175 175
 			goto error;
176 176
 		}
177 177
 
... ...
@@ -198,14 +198,14 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
198 198
 			new_dst=*dst;
199 199
 			new_dst.send_sock=get_send_socket(0, &dst->to, dst->proto);
200 200
 			if (unlikely(new_dst.send_sock==0)){
201
-				LOG(L_ERR, "msg_send: ERROR: no sending socket found\n");
201
+				LM_ERR("no sending socket found\n");
202 202
 				goto error;
203 203
 			}
204 204
 			dst=&new_dst;
205 205
 		}
206 206
 		if (unlikely(udp_send(dst, outb.s, outb.len)==-1)){
207 207
 			STATS_TX_DROPS;
208
-			LOG(L_ERR, "msg_send: ERROR: udp_send failed\n");
208
+			LM_ERR("udp_send failed\n");
209 209
 			goto error;
210 210
 		}
211 211
 	}
... ...
@@ -213,8 +213,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
213 213
 	else if (dst->proto==PROTO_TCP){
214 214
 		if (unlikely(tcp_disable)){
215 215
 			STATS_TX_DROPS;
216
-			LOG(L_WARN, "msg_send: WARNING: attempt to send on tcp and tcp"
217
-					" support is disabled\n");
216
+			LM_WARN("attempt to send on tcp and tcp support is disabled\n");
218 217
 			goto error;
219 218
 		}else{
220 219
 			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
... ...
@@ -225,7 +224,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
225 224
 			}
226 225
 			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
227 226
 				STATS_TX_DROPS;
228
-				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
227
+				LM_ERR("tcp_send failed\n");
229 228
 				goto error;
230 229
 			}
231 230
 		}
... ...
@@ -234,8 +233,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
234 233
 	else if (dst->proto==PROTO_TLS){
235 234
 		if (unlikely(tls_disable)){
236 235
 			STATS_TX_DROPS;
237
-			LOG(L_WARN, "msg_send: WARNING: attempt to send on tls and tls"
238
-					" support is disabled\n");
236
+			LM_WARN("attempt to send on tls and tls support is disabled\n");
239 237
 			goto error;
240 238
 		}else{
241 239
 			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
... ...
@@ -246,7 +244,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
246 244
 			}
247 245
 			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
248 246
 				STATS_TX_DROPS;
249
-				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
247
+				LM_ERR("tcp_send failed\n");
250 248
 				goto error;
251 249
 			}
252 250
 		}
... ...
@@ -257,29 +255,28 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
257 255
 	else if (dst->proto==PROTO_SCTP){
258 256
 		if (unlikely(sctp_disable)){
259 257
 			STATS_TX_DROPS;
260
-			LOG(L_WARN, "msg_send: WARNING: attempt to send on sctp and sctp"
261
-					" support is disabled\n");
258
+			LM_WARN("attempt to send on sctp and sctp support is disabled\n");
262 259
 			goto error;
263 260
 		}else{
264 261
 			if (unlikely(dst->send_sock==0)){
265 262
 				new_dst=*dst;
266 263
 				new_dst.send_sock=get_send_socket(0, &dst->to, dst->proto);
267 264
 				if (unlikely(new_dst.send_sock==0)){
268
-					LOG(L_ERR, "msg_send: ERROR: no sending SCTP socket found\n");
265
+					LM_ERR("no sending SCTP socket found\n");
269 266
 					goto error;
270 267
 				}
271 268
 				dst=&new_dst;
272 269
 			}
273 270
 			if (unlikely(sctp_core_msg_send(dst, outb.s, outb.len)<0)){
274 271
 				STATS_TX_DROPS;
275
-				LOG(L_ERR, "msg_send: ERROR: sctp_msg_send failed\n");
272
+				LM_ERR("sctp_msg_send failed\n");
276 273
 				goto error;
277 274
 			}
278 275
 		}
279 276
 	}
280 277
 #endif /* USE_SCTP */
281 278
 	else{
282
-			LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", dst->proto);
279
+			LM_CRIT("unknown proto %d\n", dst->proto);
283 280
 			goto error;
284 281
 	}
285 282
 	ret = 0;
Browse code

core: safety check for outbound buffer

- pointer can end up being NULL if replacement fails to be built (e.g.,
via topoh)

Daniel-Constantin Mierla authored on 16/09/2014 21:38:35
Showing 1 changed files
... ...
@@ -145,6 +145,11 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
145 145
 	outb.len = len;
146 146
 	sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
147 147
 
148
+	if(outb.s==NULL) {
149
+		LM_ERR("failed to update outgoing buffer\n");
150
+		return -1;
151
+	}
152
+
148 153
 #ifdef USE_TCP
149 154
 	if (unlikely((dst->proto == PROTO_WS
150 155
 #ifdef USE_TLS
Browse code

core: hanlde replacement buffer free for WS/WSS frame sending

- affected when using topoh for ws/wss traffic

Daniel-Constantin Mierla authored on 16/09/2014 21:33:20
Showing 1 changed files
... ...
@@ -183,7 +183,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
183 183
 		wsev.id = con->id;
184 184
 		ret = sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
185 185
 		tcpconn_put(con);
186
-		return ret;
186
+		goto done;
187 187
 	}
188 188
 #endif
189 189
 
... ...
@@ -277,9 +277,11 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
277 277
 			LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", dst->proto);
278 278
 			goto error;
279 279
 	}
280
+	ret = 0;
281
+done:
280 282
 	if(outb.s != buf)
281 283
 		pkg_free(outb.s);
282
-	return 0;
284
+	return ret;
283 285
 error:
284 286
 	if(outb.s != buf)
285 287
 		pkg_free(outb.s);
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -22,7 +22,7 @@
22 22
  *
23 23
  * You should have received a copy of the GNU General Public License 
24 24
  * along with this program; if not, write to the Free Software 
25
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 26
  */
27 27
 /*
28 28
  * History:
Browse code

core: option to specify whether the send info has to be set before sending out

Daniel-Constantin Mierla authored on 26/05/2014 12:16:49
Showing 1 changed files
... ...
@@ -109,6 +109,8 @@ int update_sock_struct_from_via( union sockaddr_union* to,
109 109
 int forward_reply( struct sip_msg* msg);
110 110
 int forward_reply_nocb( struct sip_msg* msg);
111 111
 
112
+void forward_set_send_info(int v);
113
+
112 114
 int is_check_self_func_list_set(void);
113 115
 
114 116
 
Browse code

core: use port 5061 for checking self when uri has transport tls

- 5060 was used, failing to match myself condition

Daniel-Constantin Mierla authored on 15/05/2014 10:48:04
Showing 1 changed files
... ...
@@ -84,6 +84,8 @@ inline static struct socket_info* get_send_socket(struct sip_msg* msg,
84 84
 }
85 85
 
86 86
 
87
+#define GET_URI_PORT(uri) ((uri)->port_no?(uri)->port_no:(((uri)->proto==PROTO_TLS)?SIPS_PORT:SIP_PORT))
88
+
87 89
 struct socket_info* get_out_socket(union sockaddr_union* to, int proto);
88 90
 typedef int (*check_self_f)(str* host, unsigned short port,
89 91
 		unsigned short proto);
Browse code

core: Fix connection leak with websockets

- Decrease connection ref count after using connection

Hugh Waite authored on 04/07/2013 09:30:51
Showing 1 changed files
... ...
@@ -134,6 +134,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
134 134
 	union sockaddr_union local_addr;
135 135
 	struct tcp_connection *con = NULL;
136 136
 	struct ws_event_info wsev;
137
+	int ret;
137 138
 #endif
138 139
 	
139 140
 	outb.s = buf;
... ...
@@ -162,13 +163,13 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
162 163
 			con = tcpconn_get(dst->id, 0, 0, 0, 0);
163 164
 		else {
164 165
 			LM_CRIT("BUG: msg_send called with null_id & to\n");
165
-			return -1;
166
+			goto error;
166 167
 		}
167 168
 
168 169
 		if (con == NULL)
169 170
 		{
170 171
 			LM_WARN("TCP/TLS connection for WebSocket could not be found\n");
171
-			return -1;
172
+			goto error;
172 173
 		}
173 174
 
174 175
 		memset(&wsev, 0, sizeof(ws_event_info_t));
... ...
@@ -176,7 +177,9 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
176 177
 		wsev.buf = outb.s;
177 178
 		wsev.len = outb.len;
178 179
 		wsev.id = con->id;
179
-		return sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
180
+		ret = sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
181
+		tcpconn_put(con);
182
+		return ret;
180 183
 	}
181 184
 #endif
182 185
 
Browse code

sctp: new module for SCTP transport

- moved the sctp specific code from core to a module to make it easy to
enable/disable sctp by loading/not loading the module instead of
recompiling

Daniel-Constantin Mierla authored on 25/05/2013 07:33:39
Showing 1 changed files
... ...
@@ -57,7 +57,7 @@
57 57
 #include "tcp_conn.h"
58 58
 #endif
59 59
 #ifdef USE_SCTP
60
-#include "sctp_server.h"
60
+#include "sctp_core.h"
61 61
 #endif
62 62
 
63 63
 #include "compiler_opt.h"
... ...
@@ -258,7 +258,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
258 258
 				}
259 259
 				dst=&new_dst;
260 260
 			}
261
-			if (unlikely(sctp_msg_send(dst, outb.s, outb.len)<0)){
261
+			if (unlikely(sctp_core_msg_send(dst, outb.s, outb.len)<0)){
262 262
 				STATS_TX_DROPS;
263 263
 				LOG(L_ERR, "msg_send: ERROR: sctp_msg_send failed\n");
264 264
 				goto error;
Browse code

core: made a wrapper forward_reply_nocb()

- it forwards a reply without calling the callbacks from modules for sip
response handling
- fixes the issue of sl_forward_reply() looping when used in TM onreply
routes

Daniel-Constantin Mierla authored on 25/01/2013 16:30:42
Showing 1 changed files
... ...
@@ -105,6 +105,7 @@ int update_sock_struct_from_via( union sockaddr_union* to,
105 105
 							((msg)->via1->port)?(msg)->via1->port: SIP_PORT )
106 106
 
107 107
 int forward_reply( struct sip_msg* msg);
108
+int forward_reply_nocb( struct sip_msg* msg);
108 109
 
109 110
 int is_check_self_func_list_set(void);
110 111
 
Browse code

core: Fixed segmentation fault

- Tiny window for this... but I hit it when Google Chrome crashed during
a WebSocket session

Peter Dunkley authored on 30/06/2012 19:35:10
Showing 1 changed files
... ...
@@ -164,6 +164,12 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
164 164
 			return -1;
165 165
 		}
166 166
 
167
+		if (con == NULL)
168
+		{
169
+			LM_WARN("TCP/TLS connection for WebSocket could not be found\n");
170
+			return -1;
171
+		}
172
+
167 173
 		memset(&wsev, 0, sizeof(ws_event_info_t));
168 174
 		wsev.type = SREV_TCP_WS_FRAME_OUT;
169 175
 		wsev.buf = outb.s;
Browse code

core: Changed WS from being a flag on a TCP/TLS connection to a protocol in its own right

- Also added ;transport=ws parameter parsing for URIs

Peter Dunkley authored on 29/06/2012 16:44:15
Showing 1 changed files
... ...
@@ -140,11 +140,11 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
140 140
 	sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
141 141
 
142 142
 #ifdef USE_TCP
143
-	if (dst->proto == PROTO_TCP
143
+	if (unlikely((dst->proto == PROTO_WS
144 144
 #ifdef USE_TLS
145
-		|| dst->proto == PROTO_TLS
145
+		|| dst->proto == PROTO_WSS
146 146
 #endif
147
-	) {
147
+	) && sr_event_enabled(SREV_TCP_WS_FRAME_OUT))) {
148 148
 		if (unlikely(dst->send_flags.f & SND_F_FORCE_SOCKET
149 149
 				&& dst->send_sock)) {
150 150
 			local_addr = dst->send_sock->su;
... ...
@@ -152,29 +152,24 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
152 152
 			from = &local_addr;
153 153
 		}
154 154
 
155
-		if (unlikely(sr_event_enabled(SREV_TCP_WS_FRAME_OUT))) {
156
-			port = su_getport(&dst->to);
157
-			if (likely(port)) {
158
-				su2ip_addr(&ip, &dst->to);
159
-				con = tcpconn_get(dst->id, &ip, port, from, 0);
160
-			}
161
-			else if (likely(dst->id))
162
-				con = tcpconn_get(dst->id, 0, 0, 0, 0);
163
-			else {
164
-				LM_CRIT("BUG: msg_send called with null_id & to\n");
165
-				return -1;
166
-			}
167
-
168
-			if (con && con->flags & F_CONN_WS)
169
-			{
170
-				memset(&wsev, 0, sizeof(ws_event_info_t));
171
-				wsev.type = SREV_TCP_WS_FRAME_OUT;
172
-				wsev.buf = outb.s;
173
-				wsev.len = outb.len;
174
-				wsev.id = con->id;
175
-				return sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
176
-			}
155
+		port = su_getport(&dst->to);
156
+		if (likely(port)) {
157
+			su2ip_addr(&ip, &dst->to);
158
+			con = tcpconn_get(dst->id, &ip, port, from, 0);
177 159
 		}
160
+		else if (likely(dst->id))
161
+			con = tcpconn_get(dst->id, 0, 0, 0, 0);
162
+		else {
163
+			LM_CRIT("BUG: msg_send called with null_id & to\n");
164
+			return -1;
165
+		}
166
+
167
+		memset(&wsev, 0, sizeof(ws_event_info_t));
168
+		wsev.type = SREV_TCP_WS_FRAME_OUT;
169
+		wsev.buf = outb.s;
170
+		wsev.len = outb.len;
171
+		wsev.id = con->id;
172
+		return sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
178 173
 	}
179 174
 #endif
180 175
 
... ...
@@ -203,6 +198,12 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
203 198
 					" support is disabled\n");
204 199
 			goto error;
205 200
 		}else{
201
+			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
202
+						dst->send_sock)) {
203
+				local_addr=dst->send_sock->su;
204
+				su_setport(&local_addr, 0); /* any local port will do */
205
+				from=&local_addr;
206
+			}
206 207
 			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
207 208
 				STATS_TX_DROPS;
208 209
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
... ...
@@ -218,6 +219,12 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
218 219
 					" support is disabled\n");
219 220
 			goto error;
220 221
 		}else{
222
+			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
223
+						dst->send_sock)) {
224
+				local_addr=dst->send_sock->su;
225
+				su_setport(&local_addr, 0); /* any local port will do */
226
+				from=&local_addr;
227
+			}
221 228
 			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
222 229
 				STATS_TX_DROPS;
223 230
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
Browse code

core: Fix to msg_send() so that requests destined for a WebSocket connection go through the websocket module

- responses already worked

Peter Dunkley authored on 28/06/2012 16:54:45
Showing 1 changed files
... ...
@@ -127,7 +127,9 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
127 127
 	struct dest_info new_dst;
128 128
 	str outb;
129 129
 #ifdef USE_TCP 
130
-	union sockaddr_union* from;
130
+	int port;
131
+	struct ip_addr ip;
132
+	union sockaddr_union* from = NULL;
131 133
 	union sockaddr_union local_addr;
132 134
 	struct tcp_connection *con = NULL;
133 135
 	struct ws_event_info wsev;
... ...
@@ -138,21 +140,40 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
138 140
 	sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
139 141
 
140 142
 #ifdef USE_TCP
141
-	if (unlikely(sr_event_enabled(SREV_TCP_WS_FRAME_OUT))) {
142
-		if (dst->proto == PROTO_TCP)
143
-			con = tcpconn_get(dst->id, 0, 0, 0, 0);
143
+	if (dst->proto == PROTO_TCP
144 144
 #ifdef USE_TLS
145
-		else if (dst->proto == PROTO_TLS)
146
-			con = tcpconn_get(dst->id, 0, 0, 0, 0);
145
+		|| dst->proto == PROTO_TLS
147 146
 #endif
148
-		if (con && con->flags & F_CONN_WS)
149
-		{
150
-			memset(&wsev, 0, sizeof(ws_event_info_t));
151
-			wsev.type = SREV_TCP_WS_FRAME_OUT;
152
-			wsev.buf = outb.s;
153
-			wsev.len = outb.len;
154
-			wsev.id = dst->id;
155
-			return sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
147
+	) {
148
+		if (unlikely(dst->send_flags.f & SND_F_FORCE_SOCKET
149
+				&& dst->send_sock)) {
150
+			local_addr = dst->send_sock->su;
151
+			su_setport(&local_addr, 0); /* any local port will do */
152
+			from = &local_addr;
153
+		}
154
+
155
+		if (unlikely(sr_event_enabled(SREV_TCP_WS_FRAME_OUT))) {
156
+			port = su_getport(&dst->to);
157
+			if (likely(port)) {
158
+				su2ip_addr(&ip, &dst->to);
159
+				con = tcpconn_get(dst->id, &ip, port, from, 0);
160
+			}
161
+			else if (likely(dst->id))
162
+				con = tcpconn_get(dst->id, 0, 0, 0, 0);
163
+			else {
164
+				LM_CRIT("BUG: msg_send called with null_id & to\n");
165
+				return -1;
166
+			}
167
+
168
+			if (con && con->flags & F_CONN_WS)
169
+			{
170
+				memset(&wsev, 0, sizeof(ws_event_info_t));
171
+				wsev.type = SREV_TCP_WS_FRAME_OUT;
172
+				wsev.buf = outb.s;
173
+				wsev.len = outb.len;
174
+				wsev.id = con->id;
175
+				return sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
176
+			}
156 177
 		}
157 178
 	}
158 179
 #endif
... ...
@@ -182,13 +203,6 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
182 203
 					" support is disabled\n");
183 204
 			goto error;
184 205
 		}else{
185
-			from=0;
186
-			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
187
-						dst->send_sock)) {
188
-				local_addr=dst->send_sock->su;
189
-				su_setport(&local_addr, 0); /* any local port will do */
190
-				from=&local_addr;
191
-			}
192 206
 			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
193 207
 				STATS_TX_DROPS;
194 208
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
... ...
@@ -204,13 +218,6 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
204 218
 					" support is disabled\n");
205 219
 			goto error;
206 220
 		}else{
207
-			from=0;
208
-			if (unlikely((dst->send_flags.f & SND_F_FORCE_SOCKET) &&
209
-						dst->send_sock)) {
210
-				local_addr=dst->send_sock->su;
211
-				su_setport(&local_addr, 0); /* any local port will do */
212
-				from=&local_addr;
213
-			}
214 221
 			if (unlikely(tcp_send(dst, from, outb.s, outb.len)<0)){
215 222
 				STATS_TX_DROPS;
216 223
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
Browse code

core: fixed segmentation fault I had added to forward.h

Peter Dunkley authored on 23/06/2012 20:52:15
Showing 1 changed files
... ...
@@ -145,7 +145,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
145 145
 		else if (dst->proto == PROTO_TLS)
146 146
 			con = tcpconn_get(dst->id, 0, 0, 0, 0);
147 147
 #endif
148
-		if (con->flags & F_CONN_WS)
148
+		if (con && con->flags & F_CONN_WS)
149 149
 		{
150 150
 			memset(&wsev, 0, sizeof(ws_event_info_t));
151 151
 			wsev.type = SREV_TCP_WS_FRAME_OUT;
Browse code

core: added events and data-structures so that Kamailio core can transmit through the WebSocket module

Peter Dunkley authored on 23/06/2012 18:10:03
Showing 1 changed files
... ...
@@ -54,6 +54,7 @@
54 54
 #include "udp_server.h"
55 55
 #ifdef USE_TCP