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,401 +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
-#include "defs.h"
22
-
23
-
24
-#include "stdlib.h"
25
-#include "../../dprint.h"
26
-#include "../../error.h"
27
-#include "../../mem/mem.h"
28
-#include "../../usr_avp.h"
29
-#include "../../atomic_ops.h" /* membar_write() */
30
-#include "t_hooks.h"
31
-#include "t_lookup.h"
32
-#include "t_funcs.h"
33
-
34
-
35
-struct tmcb_head_list* req_in_tmcb_hl = 0;
36
-struct tmcb_head_list* local_req_in_tmcb_hl = 0;
37
-
38
-struct tm_early_cb {
39
-	unsigned int msgid;
40
-	struct tmcb_head_list cb_list;
41
-} tmcb_early_hl = { 0, {0, 0} };
42
-
43
-struct tmcb_head_list* get_early_tmcb_list(struct sip_msg *msg)
44
-{
45
-	struct tm_callback *cbp, *cbp_tmp;
46
-	if (msg->id!=tmcb_early_hl.msgid) {
47
-		for( cbp=(struct tm_callback*)tmcb_early_hl.cb_list.first; cbp ; ) {
48
-			cbp_tmp = cbp;
49
-			cbp = cbp->next;
50
-			if (cbp_tmp->param && cbp_tmp->release)
51
-					cbp_tmp->release( cbp_tmp->param );
52
-			shm_free( cbp_tmp );
53
-		}
54
-		memset(&tmcb_early_hl.cb_list, 0, sizeof(struct tmcb_head_list));
55
-		tmcb_early_hl.msgid = msg->id;
56
-	}
57
-	return &tmcb_early_hl.cb_list;
58
-}
59
-
60
-void set_early_tmcb_list(struct sip_msg *msg, struct cell *t)
61
-{
62
-	if (msg->id==tmcb_early_hl.msgid) {
63
-		t->tmcb_hl = tmcb_early_hl.cb_list;
64
-		memset(&tmcb_early_hl.cb_list, 0, sizeof(struct tmcb_head_list));
65
-		tmcb_early_hl.msgid = 0;
66
-	}
67
-}
68
-
69
-int init_tmcb_lists()
70
-{
71
-	req_in_tmcb_hl = (struct tmcb_head_list*)shm_malloc
72
-		( sizeof(struct tmcb_head_list) );
73
-	local_req_in_tmcb_hl = (struct tmcb_head_list*)shm_malloc
74
-		( sizeof(struct tmcb_head_list) );
75
-	if ((req_in_tmcb_hl==0) || (local_req_in_tmcb_hl==0)) {
76
-		LOG(L_CRIT,"ERROR:tm:init_tmcb_lists: no more shared mem\n");
77
-		goto error;
78
-	}
79
-	req_in_tmcb_hl->first = 0;
80
-	req_in_tmcb_hl->reg_types = 0;
81
-	local_req_in_tmcb_hl->first = 0;
82
-	local_req_in_tmcb_hl->reg_types = 0;
83
-	return 1;
84
-error:
85
-	if (req_in_tmcb_hl){
86
-		shm_free(req_in_tmcb_hl);
87
-		req_in_tmcb_hl=0;
88
-	}
89
-	if(local_req_in_tmcb_hl){
90
-		shm_free(local_req_in_tmcb_hl);
91
-		local_req_in_tmcb_hl=0;
92
-	}
93
-	return -1;
94
-}
95
-
96
-
97
-void destroy_tmcb_lists()
98
-{
99
-	struct tm_callback *cbp, *cbp_tmp;
100
-
101
-	if (req_in_tmcb_hl){
102
-		for( cbp=(struct tm_callback*)req_in_tmcb_hl->first; cbp ; ) {
103
-			cbp_tmp = cbp;
104
-			cbp = cbp->next;
105
-			if (cbp_tmp->param && cbp_tmp->release)
106
-					cbp_tmp->release( cbp_tmp->param );
107
-			shm_free( cbp_tmp );
108
-		}
109
-		shm_free(req_in_tmcb_hl);
110
-		req_in_tmcb_hl=0;
111
-	}
112
-	if(local_req_in_tmcb_hl){
113
-		for( cbp=(struct tm_callback*)local_req_in_tmcb_hl->first; cbp ; ) {
114
-			cbp_tmp = cbp;
115
-			cbp = cbp->next;
116
-			if (cbp_tmp->param && cbp_tmp->release)
117
-					cbp_tmp->release( cbp_tmp->param );
118
-			shm_free( cbp_tmp );
119
-		}
120
-		shm_free(local_req_in_tmcb_hl);
121
-		local_req_in_tmcb_hl=0;
122
-	}
123
-}
124
-
125
-
126
-
127
-/* lockless insert: should be always safe */
128
-int insert_tmcb(struct tmcb_head_list *cb_list, int types,
129
-				transaction_cb f, void *param,
130
-				release_tmcb_param rel_func)
131
-{
132
-	struct tm_callback *cbp;
133
-	struct tm_callback *old;
134
-
135
-
136
-	/* build a new callback structure */
137
-	if (!(cbp=shm_malloc( sizeof( struct tm_callback)))) {
138
-		LOG(L_ERR, "ERROR:tm:insert_tmcb: out of shm. mem\n");
139
-		return E_OUT_OF_MEM;
140
-	}
141
-
142
-	atomic_or_int(&cb_list->reg_types, types);
143
-	/* ... and fill it up */
144
-	cbp->callback = f;
145
-	cbp->param = param;
146
-	cbp->release = rel_func;
147
-	cbp->types = types;
148
-	cbp->id=0;
149
-	old=(struct tm_callback*)cb_list->first;
150
-	/* link it into the proper place... */
151
-	do{
152
-		cbp->next = old;
153
-		/*
154
-		if (cbp->next)
155
-			cbp->id = cbp->next->id+1;
156
-		else
157
-			cbp->id = 0;
158
-		 -- callback ids are useless -- andrei */
159
-		membar_write_atomic_op();
160
-		old=(void*)atomic_cmpxchg_long((void*)&cb_list->first,
161
-										(long)old, (long)cbp);
162
-	}while(old!=cbp->next);
163
-
164
-	return 1;
165
-}
166
-
167
-
168
-
169
-/* register a callback function 'f' for 'types' mask of events;
170
- * will be called back whenever one of the events occurs in transaction module
171
- * (global or per transaction, depending of event type)
172
- * It _must_ be always called either with the REPLY_LOCK held, or before the
173
- *  branches are created.
174
- *  Special cases: TMCB_REQUEST_IN & TMCB_LOCAL_REQUEST_IN - must be called 
175
- *                 from mod_init (before forking!).
176
-*/
177
-int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
178
-				   transaction_cb f, void *param,
179
-				   release_tmcb_param rel_func)
180
-{
181
-	//struct cell* t;
182
-	struct tmcb_head_list *cb_list;
183
-
184
-	/* are the callback types valid?... */
185
-	if ( types<0 || types>TMCB_MAX ) {
186
-		LOG(L_CRIT, "BUG:tm:register_tmcb: invalid callback types: mask=%d\n",
187
-			types);
188
-		return E_BUG;
189
-	}
190
-	/* we don't register null functions */
191
-	if (f==0) {
192
-		LOG(L_CRIT, "BUG:tm:register_tmcb: null callback function\n");
193
-		return E_BUG;
194
-	}
195
-
196
-	if ((types!=TMCB_MAX) && (types&TMCB_REQUEST_IN)) {
197
-		if (types!=TMCB_REQUEST_IN) {
198
-			LOG(L_CRIT, "BUG:tm:register_tmcb: callback type TMCB_REQUEST_IN "
199
-				"can't be register along with types\n");
200
-			return E_BUG;
201
-		}
202
-		cb_list = req_in_tmcb_hl;
203
-	}else if ((types!=TMCB_MAX) && (types & TMCB_LOCAL_REQUEST_IN)) {
204
-		if (types!=TMCB_LOCAL_REQUEST_IN) {
205
-			LOG(L_CRIT, "BUG:tm:register_tmcb: callback type"
206
-					" TMCB_LOCAL_REQUEST_IN can't be register along with"
207
-					" other types\n");
208
-			return E_BUG;
209
-		}
210
-		cb_list = local_req_in_tmcb_hl;
211
-	} else {
212
-		if (!t) {
213
-			if (!p_msg) {
214
-				LOG(L_CRIT,"BUG:tm:register_tmcb: no sip_msg, nor transaction"
215
-					" given\n");
216
-				return E_BUG;
217
-			}
218
-			/* look for the transaction */
219
-			t=get_t();
220
-			if ( t!=0 && t!=T_UNDEFINED) {
221
-				cb_list = &(t->tmcb_hl);
222
-			} else {
223
-				cb_list = get_early_tmcb_list(p_msg);
224
-			}
225
-		} else {
226
-			cb_list = &(t->tmcb_hl);
227
-		}
228
-	}
229
-
230
-	return insert_tmcb( cb_list, types, f, param, rel_func );
231
-}
232
-
233
-
234
-void run_trans_callbacks_internal(struct tmcb_head_list* cb_lst, int type,
235
-									struct cell *trans, 
236
-									struct tmcb_params *params)
237
-{
238
-	struct tm_callback    *cbp;
239
-	avp_list_t* backup_from, *backup_to, *backup_dom_from, *backup_dom_to, *backup_uri_from, *backup_uri_to;
240
-#ifdef WITH_XAVP
241
-	sr_xavp_t **backup_xavps;
242
-#endif
243
-
244
-	backup_uri_from = set_avp_list(AVP_CLASS_URI | AVP_TRACK_FROM,
245
-			&trans->uri_avps_from );
246
-	backup_uri_to = set_avp_list(AVP_CLASS_URI | AVP_TRACK_TO, 
247
-			&trans->uri_avps_to );
248
-	backup_from = set_avp_list(AVP_CLASS_USER | AVP_TRACK_FROM, 
249
-			&trans->user_avps_from );
250
-	backup_to = set_avp_list(AVP_CLASS_USER | AVP_TRACK_TO, 
251
-			&trans->user_avps_to );
252
-	backup_dom_from = set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_FROM, 
253
-			&trans->domain_avps_from);
254
-	backup_dom_to = set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_TO, 
255
-			&trans->domain_avps_to);
256
-#ifdef WITH_XAVP
257
-	backup_xavps = xavp_set_list(&trans->xavps_list);
258
-#endif
259
-
260
-	cbp=(struct tm_callback*)cb_lst->first;
261
-	while(cbp){
262
-		membar_depends(); /* make sure the cache has the correct cbp 
263
-							 contents */
264
-		if ( (cbp->types)&type ) {
265
-			DBG("DBG: trans=%p, callback type %d, id %d entered\n",
266
-				trans, type, cbp->id );
267
-			params->param = &(cbp->param);
268
-			cbp->callback( trans, type, params );
269
-		}
270
-		cbp=cbp->next;
271
-	}
272
-	set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_TO, backup_dom_to );
273
-	set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_FROM, backup_dom_from );
274
-	set_avp_list(AVP_CLASS_USER | AVP_TRACK_TO, backup_to );
275
-	set_avp_list(AVP_CLASS_USER | AVP_TRACK_FROM, backup_from );
276
-	set_avp_list(AVP_CLASS_URI | AVP_TRACK_TO, backup_uri_to );
277
-	set_avp_list(AVP_CLASS_URI | AVP_TRACK_FROM, backup_uri_from );
278
-#ifdef WITH_XAVP
279
-	xavp_set_list(backup_xavps);
280
-#endif
281
-}
282
-
283
-
284
-
285
-void run_trans_callbacks( int type , struct cell *trans,
286
-						struct sip_msg *req, struct sip_msg *rpl, int code )
287
-{
288
-	struct tmcb_params params;
289
-	if (trans->tmcb_hl.first==0 || ((trans->tmcb_hl.reg_types)&type)==0 )
290
-		return;
291
-	memset (&params, 0, sizeof(params));
292
-	params.req = req;
293
-	params.rpl = rpl;
294
-	params.code = code;
295
-	run_trans_callbacks_internal(&trans->tmcb_hl, type, trans, &params);
296
-}
297
-
298
-
299
-
300
-void run_trans_callbacks_with_buf(int type, struct retr_buf* rbuf,
301
-                                  struct sip_msg* req, struct sip_msg* repl,
302
-                                  short flags)
303
-{
304
-	struct tmcb_params params;
305
-	struct cell * trans;
306
-
307
-	trans=rbuf->my_T;
308
-	if ( trans==0 || trans->tmcb_hl.first==0 || 
309
-			((trans->tmcb_hl.reg_types)&type)==0 )
310
-		return;
311
-	INIT_TMCB_ONSEND_PARAMS(params, req, repl, rbuf, &rbuf->dst, rbuf->buffer,
312
-					rbuf->buffer_len, flags, rbuf->branch, rbuf->activ_type);
313
-	/* req, rpl */
314
-	run_trans_callbacks_internal(&trans->tmcb_hl, type, trans, &params);
315
-}
316
-
317
-
318
-void run_trans_callbacks_off_params(int type, struct cell* trans,
319
-                                    struct tmcb_params* p)
320
-{
321
-
322
-	if (p->t_rbuf==0) return;
323
-	if ( trans==0 || trans->tmcb_hl.first==0 || 
324
-			((trans->tmcb_hl.reg_types)&type)==0 )
325
-		return;
326
-	run_trans_callbacks_internal(&trans->tmcb_hl, type, p->t_rbuf->my_T, p);
327
-}
328
-
329
-
330
-static void run_reqin_callbacks_internal(struct tmcb_head_list* hl,
331
-							struct cell *trans, struct tmcb_params* params)
332
-{
333
-	struct tm_callback    *cbp;
334
-	avp_list_t* backup_from, *backup_to, *backup_dom_from, *backup_dom_to,
335
-				*backup_uri_from, *backup_uri_to;
336
-#ifdef WITH_XAVP
337
-	sr_xavp_t **backup_xavps;
338
-#endif
339
-
340
-	if (hl==0 || hl->first==0) return;
341
-	backup_uri_from = set_avp_list(AVP_CLASS_URI | AVP_TRACK_FROM,
342
-			&trans->uri_avps_from );
343
-	backup_uri_to = set_avp_list(AVP_CLASS_URI | AVP_TRACK_TO, 
344
-			&trans->uri_avps_to );
345
-	backup_from = set_avp_list(AVP_CLASS_USER | AVP_TRACK_FROM, 
346
-			&trans->user_avps_from );
347
-	backup_to = set_avp_list(AVP_CLASS_USER | AVP_TRACK_TO, 
348
-			&trans->user_avps_to );
349
-	backup_dom_from = set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_FROM, 
350
-			&trans->domain_avps_from);
351
-	backup_dom_to = set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_TO, 
352
-			&trans->domain_avps_to);
353
-#ifdef WITH_XAVP
354
-	backup_xavps = xavp_set_list(&trans->xavps_list);
355
-#endif
356
-	for (cbp=(struct tm_callback*)hl->first; cbp; cbp=cbp->next)  {
357
-		DBG("DBG: trans=%p, callback type %d, id %d entered\n",
358
-			trans, cbp->types, cbp->id );
359
-		params->param = &(cbp->param);
360
-		cbp->callback( trans, cbp->types, params );
361
-	}
362
-	set_avp_list(AVP_CLASS_URI | AVP_TRACK_TO, backup_uri_to );
363
-	set_avp_list(AVP_CLASS_URI | AVP_TRACK_FROM, backup_uri_from );
364
-	set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_TO, backup_dom_to );
365
-	set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_FROM, backup_dom_from );
366
-	set_avp_list(AVP_CLASS_USER | AVP_TRACK_TO, backup_to );
367
-	set_avp_list(AVP_CLASS_USER | AVP_TRACK_FROM, backup_from );
368
-#ifdef WITH_XAVP
369
-	xavp_set_list(backup_xavps);
370
-#endif
371
-}
372
-
373
-
374
-
375
-void run_reqin_callbacks( struct cell *trans, struct sip_msg *req, int code )
376
-{
377
-	static struct tmcb_params params;
378
-
379
-	if (req_in_tmcb_hl->first==0)
380
-		return;
381
-	memset (&params, 0, sizeof(params));
382
-	params.req = req;
383
-	params.code = code;
384
-	
385
-	run_reqin_callbacks_internal(req_in_tmcb_hl, trans, &params);
386
-}
387
-
388
-
389
-void run_local_reqin_callbacks( struct cell *trans, struct sip_msg *req,
390
-								int code )
391
-{
392
-	static struct tmcb_params params;
393
-
394
-	if (local_req_in_tmcb_hl->first==0)
395
-		return;
396
-	memset (&params, 0, sizeof(params));
397
-	params.req = req;
398
-	params.code = code;
399
-	
400
-	run_reqin_callbacks_internal(local_req_in_tmcb_hl, trans, &params);
401
-}
Browse code

tm Remove svn ID, remove history, rename "ser" to "kamailio"

Olle E. Johansson authored on 03/01/2015 15:48:29
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,21 +17,6 @@
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
- *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
31
- *  2003-12-04  global callbacks moved into transaction callbacks;
32
- *              multiple events per callback added; single list per
33
- *              transaction for all its callbacks (bogdan)
34
- *  2004-08-23  user avp(attribute value pair) added -> making avp list
35
- *              available in callbacks (bogdan)
36
- * 2007-03-08  membar_write() used in insert_tmcb(...) (andrei)
37
- * 2007-03-14  added *_SENT callbacks (andrei)
38
- * 2007-03-23  added local_req_in callbacks support (andrei)
39
- * 2007-05-17  insert_tmcb is now safe: it loops arround a mb_atomic_cmpxchg
40
- *              for a safe lockless list insert (andrei)
41
- */
42 20
 
43 21
 #include "defs.h"
44 22
 
Browse code

tm: backup xavps before running callbacks

regular avps were being backupped, just not xavps.

Alex Hermann authored on 14/10/2014 13:58:41
Showing 1 changed files
... ...
@@ -355,6 +355,9 @@ static void run_reqin_callbacks_internal(struct tmcb_head_list* hl,
355 355
 	struct tm_callback    *cbp;
356 356
 	avp_list_t* backup_from, *backup_to, *backup_dom_from, *backup_dom_to,
357 357
 				*backup_uri_from, *backup_uri_to;
358
+#ifdef WITH_XAVP
359
+	sr_xavp_t **backup_xavps;
360
+#endif
358 361
 
359 362
 	if (hl==0 || hl->first==0) return;
360 363
 	backup_uri_from = set_avp_list(AVP_CLASS_URI | AVP_TRACK_FROM,
... ...
@@ -369,6 +372,9 @@ static void run_reqin_callbacks_internal(struct tmcb_head_list* hl,
369 372
 			&trans->domain_avps_from);
370 373
 	backup_dom_to = set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_TO, 
371 374
 			&trans->domain_avps_to);
375
+#ifdef WITH_XAVP
376
+	backup_xavps = xavp_set_list(&trans->xavps_list);
377
+#endif
372 378
 	for (cbp=(struct tm_callback*)hl->first; cbp; cbp=cbp->next)  {
373 379
 		DBG("DBG: trans=%p, callback type %d, id %d entered\n",
374 380
 			trans, cbp->types, cbp->id );
... ...
@@ -381,6 +387,9 @@ static void run_reqin_callbacks_internal(struct tmcb_head_list* hl,
381 387
 	set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_FROM, backup_dom_from );
382 388
 	set_avp_list(AVP_CLASS_USER | AVP_TRACK_TO, backup_to );
383 389
 	set_avp_list(AVP_CLASS_USER | AVP_TRACK_FROM, backup_from );
390
+#ifdef WITH_XAVP
391
+	xavp_set_list(backup_xavps);
392
+#endif
384 393
 }
385 394
 
386 395
 
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

tm: Rename run_onsend_callbacks[2]; update, and extend documentation.

- run_onsend_callbacks -> run_trans_callbacks_with_buf.
- run_onsend_callbacks2 -> run_trans_callbacks_off_params.

Timo Reimann authored on 05/10/2011 08:57:13
Showing 1 changed files
... ...
@@ -319,8 +319,9 @@ void run_trans_callbacks( int type , struct cell *trans,
319 319
 
320 320
 
321 321
 
322
-void run_onsend_callbacks(int type, struct retr_buf* rbuf,
323
-					struct sip_msg* req, struct sip_msg* repl, short flags)
322
+void run_trans_callbacks_with_buf(int type, struct retr_buf* rbuf,
323
+                                  struct sip_msg* req, struct sip_msg* repl,
324
+                                  short flags)
324 325
 {
325 326
 	struct tmcb_params params;
326 327
 	struct cell * trans;
... ...
@@ -336,7 +337,8 @@ void run_onsend_callbacks(int type, struct retr_buf* rbuf,
336 337
 }
337 338
 
338 339
 
339
-void run_onsend_callbacks2(int type, struct cell* trans, struct tmcb_params* p)
340
+void run_trans_callbacks_off_params(int type, struct cell* trans,
341
+                                    struct tmcb_params* p)
340 342
 {
341 343
 
342 344
 	if (p->t_rbuf==0) return;
Browse code

tm: Always compile TMCB_ONSEND code, it was used unconditionally anyway.

Timo Reimann authored on 05/10/2011 08:14:21
Showing 1 changed files
... ...
@@ -319,7 +319,6 @@ void run_trans_callbacks( int type , struct cell *trans,
319 319
 
320 320
 
321 321
 
322
-#ifdef TMCB_ONSEND
323 322
 void run_onsend_callbacks(int type, struct retr_buf* rbuf,
324 323
 					struct sip_msg* req, struct sip_msg* repl, short flags)
325 324
 {
... ...
@@ -347,7 +346,6 @@ void run_onsend_callbacks2(int type, struct cell* trans, struct tmcb_params* p)
347 346
 	run_trans_callbacks_internal(&trans->tmcb_hl, type, p->t_rbuf->my_T, p);
348 347
 }
349 348
 
350
-#endif
351 349
 
352 350
 static void run_reqin_callbacks_internal(struct tmcb_head_list* hl,
353 351
 							struct cell *trans, struct tmcb_params* params)
Browse code

Merge remote branch 'origin/daniel/xavp'

* origin/daniel/xavp:
pv: export new PV class $xavp(name)
core: introducing xavp (eXtended AVP)
tm: set/reset head of xavps on TM events
pv: new pv class $xavp(...)
core: destroy xavp list once sip msg processing is done

Conflicts:
modules/tm/h_table.c
modules/tm/t_reply.c
modules/tm/uac.c
modules_k/pv/pv.c

Andrei Pelinescu-Onciul authored on 15/02/2010 14:47:37
Showing 0 changed files
Browse code

tm: fix setting the pre-T callbacks

- introduced in the fix for uac module (affecting only uac)
- credits to Andrei Pelinescu-Onciul
(cherry picked from commit 32d3e9c98943ad298f09d26db83ecf4ce5c2cc0e)

Daniel-Constantin Mierla authored on 01/02/2010 10:27:20 • Andrei Pelinescu-Onciul committed on 01/02/2010 11:25:50
Showing 1 changed files
... ...
@@ -81,7 +81,7 @@ struct tmcb_head_list* get_early_tmcb_list(struct sip_msg *msg)
81 81
 
82 82
 void set_early_tmcb_list(struct sip_msg *msg, struct cell *t)
83 83
 {
84
-	if (msg->id!=tmcb_early_hl.msgid) {
84
+	if (msg->id==tmcb_early_hl.msgid) {
85 85
 		t->tmcb_hl = tmcb_early_hl.cb_list;
86 86
 		memset(&tmcb_early_hl.cb_list, 0, sizeof(struct tmcb_head_list));
87 87
 		tmcb_early_hl.msgid = 0;
Browse code

tm: run release function for tmcb parameters

- allow early registration of tm cb (in use by k uac module for example,
reported by Vulpyne)
- release function calling was missing
(cherry picked from commit 68d63835c6ec1a3fa4984aa3eb3fcc081a4f1f86)

Daniel-Constantin Mierla authored on 15/01/2010 21:09:01 • Andrei Pelinescu-Onciul committed on 01/02/2010 11:22:11
Showing 1 changed files
... ...
@@ -57,7 +57,36 @@
57 57
 struct tmcb_head_list* req_in_tmcb_hl = 0;
58 58
 struct tmcb_head_list* local_req_in_tmcb_hl = 0;
59 59
 
60
+struct tm_early_cb {
61
+	unsigned int msgid;
62
+	struct tmcb_head_list cb_list;
63
+} tmcb_early_hl = { 0, {0, 0} };
60 64
 
65
+struct tmcb_head_list* get_early_tmcb_list(struct sip_msg *msg)
66
+{
67
+	struct tm_callback *cbp, *cbp_tmp;
68
+	if (msg->id!=tmcb_early_hl.msgid) {
69
+		for( cbp=(struct tm_callback*)tmcb_early_hl.cb_list.first; cbp ; ) {
70
+			cbp_tmp = cbp;
71
+			cbp = cbp->next;
72
+			if (cbp_tmp->param && cbp_tmp->release)
73
+					cbp_tmp->release( cbp_tmp->param );
74
+			shm_free( cbp_tmp );
75
+		}
76
+		memset(&tmcb_early_hl.cb_list, 0, sizeof(struct tmcb_head_list));
77
+		tmcb_early_hl.msgid = msg->id;
78
+	}
79
+	return &tmcb_early_hl.cb_list;
80
+}
81
+
82
+void set_early_tmcb_list(struct sip_msg *msg, struct cell *t)
83
+{
84
+	if (msg->id!=tmcb_early_hl.msgid) {
85
+		t->tmcb_hl = tmcb_early_hl.cb_list;
86
+		memset(&tmcb_early_hl.cb_list, 0, sizeof(struct tmcb_head_list));
87
+		tmcb_early_hl.msgid = 0;
88
+	}
89
+}
61 90
 
62 91
 int init_tmcb_lists()
63 92
 {
... ...
@@ -95,7 +124,8 @@ void destroy_tmcb_lists()
95 124
 		for( cbp=(struct tm_callback*)req_in_tmcb_hl->first; cbp ; ) {
96 125
 			cbp_tmp = cbp;
97 126
 			cbp = cbp->next;
98
-			if (cbp_tmp->param) shm_free( cbp_tmp->param );
127
+			if (cbp_tmp->param && cbp_tmp->release)
128
+					cbp_tmp->release( cbp_tmp->param );
99 129
 			shm_free( cbp_tmp );
100 130
 		}
101 131
 		shm_free(req_in_tmcb_hl);
... ...
@@ -105,7 +135,8 @@ void destroy_tmcb_lists()
105 135
 		for( cbp=(struct tm_callback*)local_req_in_tmcb_hl->first; cbp ; ) {
106 136
 			cbp_tmp = cbp;
107 137
 			cbp = cbp->next;
108
-			if (cbp_tmp->param) shm_free( cbp_tmp->param );
138
+			if (cbp_tmp->param && cbp_tmp->release)
139
+					cbp_tmp->release( cbp_tmp->param );
109 140
 			shm_free( cbp_tmp );
110 141
 		}
111 142
 		shm_free(local_req_in_tmcb_hl);
... ...
@@ -207,17 +238,15 @@ int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
207 238
 				return E_BUG;
208 239
 			}
209 240
 			/* look for the transaction */
210
-			if ( t_check(p_msg,0)!=1 ){
211
-				LOG(L_CRIT,"BUG:tm:register_tmcb: no transaction found\n");
212
-				return E_BUG;
213
-			}
214
-			if ( (t=get_t())==0 ) {
215
-				LOG(L_CRIT,"BUG:tm:register_tmcb: transaction found "
216
-					"is NULL\n");
217
-				return E_BUG;
241
+			t=get_t();
242
+			if ( t!=0 && t!=T_UNDEFINED) {
243
+				cb_list = &(t->tmcb_hl);
244
+			} else {
245
+				cb_list = get_early_tmcb_list(p_msg);
218 246
 			}
247
+		} else {
248
+			cb_list = &(t->tmcb_hl);
219 249
 		}
220
-		cb_list = &(t->tmcb_hl);
221 250
 	}
222 251
 
223 252
 	return insert_tmcb( cb_list, types, f, param, rel_func );
Browse code

tm: fix for dialog(k) module workaround

- check if types!=TMCB_MAX if callback registration checks
- TMCB_MAX is used to store pointer to dialog in order to clean it
quickly
(cherry picked from commit 0cab381fc93e53ca039ddbfa8ae6546fa14be066)

Daniel-Constantin Mierla authored on 25/11/2009 17:21:22 • Andrei Pelinescu-Onciul committed on 15/01/2010 11:54:17
Showing 1 changed files
... ...
@@ -184,14 +184,14 @@ int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
184 184
 		return E_BUG;
185 185
 	}
186 186
 
187
-	if (types&TMCB_REQUEST_IN) {
187
+	if ((types!=TMCB_MAX) && (types&TMCB_REQUEST_IN)) {
188 188
 		if (types!=TMCB_REQUEST_IN) {
189 189
 			LOG(L_CRIT, "BUG:tm:register_tmcb: callback type TMCB_REQUEST_IN "
190 190
 				"can't be register along with types\n");
191 191
 			return E_BUG;
192 192
 		}
193 193
 		cb_list = req_in_tmcb_hl;
194
-	}else if (types & TMCB_LOCAL_REQUEST_IN) {
194
+	}else if ((types!=TMCB_MAX) && (types & TMCB_LOCAL_REQUEST_IN)) {
195 195
 		if (types!=TMCB_LOCAL_REQUEST_IN) {
196 196
 			LOG(L_CRIT, "BUG:tm:register_tmcb: callback type"
197 197
 					" TMCB_LOCAL_REQUEST_IN can't be register along with"
Browse code

tm: set/reset head of xavps on TM events

Daniel-Constantin Mierla authored on 30/06/2009 10:16:35
Showing 1 changed files
... ...
@@ -230,6 +230,9 @@ void run_trans_callbacks_internal(struct tmcb_head_list* cb_lst, int type,
230 230
 {
231 231
 	struct tm_callback    *cbp;
232 232
 	avp_list_t* backup_from, *backup_to, *backup_dom_from, *backup_dom_to, *backup_uri_from, *backup_uri_to;
233
+#ifdef WITH_XAVP
234
+	sr_xavp_t **backup_xavps;
235
+#endif
233 236
 
234 237
 	backup_uri_from = set_avp_list(AVP_CLASS_URI | AVP_TRACK_FROM,
235 238
 			&trans->uri_avps_from );
... ...
@@ -243,6 +246,10 @@ void run_trans_callbacks_internal(struct tmcb_head_list* cb_lst, int type,
243 246
 			&trans->domain_avps_from);
244 247
 	backup_dom_to = set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_TO, 
245 248
 			&trans->domain_avps_to);
249
+#ifdef WITH_XAVP
250
+	backup_xavps = xavp_set_list(&trans->xavps_list);
251
+#endif
252
+
246 253
 	cbp=(struct tm_callback*)cb_lst->first;
247 254
 	while(cbp){
248 255
 		membar_depends(); /* make sure the cache has the correct cbp 
... ...
@@ -261,6 +268,9 @@ void run_trans_callbacks_internal(struct tmcb_head_list* cb_lst, int type,
261 268
 	set_avp_list(AVP_CLASS_USER | AVP_TRACK_FROM, backup_from );
262 269
 	set_avp_list(AVP_CLASS_URI | AVP_TRACK_TO, backup_uri_to );
263 270
 	set_avp_list(AVP_CLASS_URI | AVP_TRACK_FROM, backup_uri_from );
271
+#ifdef WITH_XAVP
272
+	xavp_set_list(backup_xavps);
273
+#endif
264 274
 }
265 275
 
266 276
 
Browse code

Kamailio compatiblity: Added pointer to a free function to tm callbacks

This patch adds a new pointer to the tm_callback structure. The
parameter contains pointer to a function which, if not NULL, will be
called to dispose the callback parameter when it is not needed anymore.

This is useful if the parameter given ti a transaction callback is a
complex data structure of it is stored on the heap and the memory needs
to be free when the corresponding transaction is being destroyed.

Patch contributed by Ovidiu Sas.

Jan Janak authored on 23/03/2009 14:04:41
Showing 1 changed files
... ...
@@ -117,7 +117,8 @@ void destroy_tmcb_lists()
117 117
 
118 118
 /* lockless insert: should be always safe */
119 119
 int insert_tmcb(struct tmcb_head_list *cb_list, int types,
120
-									transaction_cb f, void *param )
120
+				transaction_cb f, void *param,
121
+				release_tmcb_param rel_func)
121 122
 {
122 123
 	struct tm_callback *cbp;
123 124
 	struct tm_callback *old;
... ...
@@ -133,6 +134,7 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
133 134
 	/* ... and fill it up */
134 135
 	cbp->callback = f;
135 136
 	cbp->param = param;
137
+	cbp->release = rel_func;
136 138
 	cbp->types = types;
137 139
 	cbp->id=0;
138 140
 	old=(struct tm_callback*)cb_list->first;
... ...
@@ -164,7 +166,8 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
164 166
  *                 from mod_init (before forking!).
165 167
 */
166 168
 int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
167
-											transaction_cb f, void *param )
169
+				   transaction_cb f, void *param,
170
+				   release_tmcb_param rel_func)
168 171
 {
169 172
 	//struct cell* t;
170 173
 	struct tmcb_head_list *cb_list;
... ...
@@ -217,7 +220,7 @@ int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
217 220
 		cb_list = &(t->tmcb_hl);
218 221
 	}
219 222
 
220
-	return insert_tmcb( cb_list, types, f, param );
223
+	return insert_tmcb( cb_list, types, f, param, rel_func );
221 224
 }
222 225
 
223 226
 
Browse code

- added membar_depends() for run_callbacks and unmatched_totag - callbacks ids are no longer set: nobody uses them and when doing a lockeless insert they cause extra expensive writes

Andrei Pelinescu-Onciul authored on 29/05/2007 13:44:19
Showing 1 changed files
... ...
@@ -134,16 +134,19 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
134 134
 	cbp->callback = f;
135 135
 	cbp->param = param;
136 136
 	cbp->types = types;
137
+	cbp->id=0;
137 138
 	old=(struct tm_callback*)cb_list->first;
138 139
 	/* link it into the proper place... */
139 140
 	do{
140 141
 		cbp->next = old;
142
+		/*
141 143
 		if (cbp->next)
142 144
 			cbp->id = cbp->next->id+1;
143 145
 		else
144 146
 			cbp->id = 0;
145
-		/* mb_atomic_cmpxchg includes membar */
146
-		old=(void*)mb_atomic_cmpxchg_long((void*)&cb_list->first,
147
+		 -- callback ids are useless -- andrei */
148
+		membar_write_atomic_op();
149
+		old=(void*)atomic_cmpxchg_long((void*)&cb_list->first,
147 150
 										(long)old, (long)cbp);
148 151
 	}while(old!=cbp->next);
149 152
 
... ...
@@ -237,13 +240,17 @@ void run_trans_callbacks_internal(struct tmcb_head_list* cb_lst, int type,
237 240
 			&trans->domain_avps_from);
238 241
 	backup_dom_to = set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_TO, 
239 242
 			&trans->domain_avps_to);
240
-	for (cbp=(struct tm_callback*)cb_lst->first; cbp; cbp=cbp->next)  {
243
+	cbp=(struct tm_callback*)cb_lst->first;
244
+	while(cbp){
245
+		membar_depends(); /* make sure the cache has the correct cbp 
246
+							 contents */
241 247
 		if ( (cbp->types)&type ) {
242 248
 			DBG("DBG: trans=%p, callback type %d, id %d entered\n",
243 249
 				trans, type, cbp->id );
244 250
 			params->param = &(cbp->param);
245 251
 			cbp->callback( trans, type, params );
246 252
 		}
253
+		cbp=cbp->next;
247 254
 	}
248 255
 	set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_TO, backup_dom_to );
249 256
 	set_avp_list(AVP_CLASS_DOMAIN | AVP_TRACK_FROM, backup_dom_from );
Browse code

- more callback fixes (TMCB_E2E_CANCEL_IN never called after the latest changes) - some minor optimizations attempts (predict all the callback branches/ifs as not taken since in the normal case we don't have any callbacks)

Andrei Pelinescu-Onciul authored on 29/05/2007 09:36:51
Showing 1 changed files
... ...
@@ -288,16 +288,14 @@ void run_onsend_callbacks(int type, struct retr_buf* rbuf,
288 288
 }
289 289
 
290 290
 
291
-void run_onsend_callbacks2(int type , struct tmcb_params* p)
291
+void run_onsend_callbacks2(int type, struct cell* trans, struct tmcb_params* p)
292 292
 {
293
-	struct cell * trans;
294 293
 
295 294
 	if (p->t_rbuf==0) return;
296
-	trans=p->t_rbuf->my_T;
297 295
 	if ( trans==0 || trans->tmcb_hl.first==0 || 
298 296
 			((trans->tmcb_hl.reg_types)&type)==0 )
299 297
 		return;
300
-	run_trans_callbacks_internal(&trans->tmcb_hl, type, trans, p);
298
+	run_trans_callbacks_internal(&trans->tmcb_hl, type, p->t_rbuf->my_T, p);
301 299
 }
302 300
 
303 301
 #endif
Browse code

- tmcb onsend callbacks update (they get also the request or the reply if they are known when the callback is called) - added unlikely() when checking if an onsend callback has to be called (so that the branch will be predicted as untaken)

Andrei Pelinescu-Onciul authored on 24/05/2007 18:01:19
Showing 1 changed files
... ...
@@ -271,7 +271,8 @@ void run_trans_callbacks( int type , struct cell *trans,
271 271
 
272 272
 
273 273
 #ifdef TMCB_ONSEND
274
-void run_onsend_callbacks(int type, struct retr_buf* rbuf, short flags)
274
+void run_onsend_callbacks(int type, struct retr_buf* rbuf,
275
+					struct sip_msg* req, struct sip_msg* repl, short flags)
275 276
 {
276 277
 	struct tmcb_params params;
277 278
 	struct cell * trans;
... ...
@@ -280,40 +281,23 @@ void run_onsend_callbacks(int type, struct retr_buf* rbuf, short flags)
280 281
 	if ( trans==0 || trans->tmcb_hl.first==0 || 
281 282
 			((trans->tmcb_hl.reg_types)&type)==0 )
282 283
 		return;
283
-	memset (&params, 0, sizeof(params));
284
-	params.send_buf.s=rbuf->buffer;
285
-	params.send_buf.len=rbuf->buffer_len;
286
-	params.dst=&rbuf->dst;
287
-	params.flags=flags;
288
-	params.branch=rbuf->branch;
289
-	params.t_rbuf=rbuf;
290
-	params.code=rbuf->activ_type;
284
+	INIT_TMCB_ONSEND_PARAMS(params, req, repl, rbuf, &rbuf->dst, rbuf->buffer,
285
+					rbuf->buffer_len, flags, rbuf->branch, rbuf->activ_type);
291 286
 	/* req, rpl */
292 287
 	run_trans_callbacks_internal(&trans->tmcb_hl, type, trans, &params);
293 288
 }
294 289
 
295 290
 
296
-void run_onsend_callbacks2(int type , struct retr_buf* rbuf, char* buf,
297
-							int buf_len, struct dest_info* dst, int code,
298
-							short flags)
291
+void run_onsend_callbacks2(int type , struct tmcb_params* p)
299 292
 {
300
-	struct tmcb_params params;
301 293
 	struct cell * trans;
302 294
 
303
-	trans=rbuf->my_T;
295
+	if (p->t_rbuf==0) return;
296
+	trans=p->t_rbuf->my_T;
304 297
 	if ( trans==0 || trans->tmcb_hl.first==0 || 
305 298
 			((trans->tmcb_hl.reg_types)&type)==0 )
306 299
 		return;
307
-	memset (&params, 0, sizeof(params));
308
-	params.send_buf.s=buf;
309
-	params.send_buf.len=buf_len;
310
-	params.dst=dst;
311
-	params.flags=flags;
312
-	params.branch=rbuf->branch;
313
-	params.t_rbuf=rbuf;
314
-	params.code=code;
315
-	/* req, rpl */
316
-	run_trans_callbacks_internal(&trans->tmcb_hl, type, trans, &params);
300
+	run_trans_callbacks_internal(&trans->tmcb_hl, type, trans, p);
317 301
 }
318 302
 
319 303
 #endif
Browse code

- experimental lockless callback insert (callback registration should now be safe from everywhere)

Andrei Pelinescu-Onciul authored on 17/05/2007 11:04:56
Showing 1 changed files
... ...
@@ -36,6 +36,8 @@
36 36
  * 2007-03-08  membar_write() used in insert_tmcb(...) (andrei)
37 37
  * 2007-03-14  added *_SENT callbacks (andrei)
38 38
  * 2007-03-23  added local_req_in callbacks support (andrei)
39
+ * 2007-05-17  insert_tmcb is now safe: it loops arround a mb_atomic_cmpxchg
40
+ *              for a safe lockless list insert (andrei)
39 41
  */
40 42
 
41 43
 #include "defs.h"
... ...
@@ -90,7 +92,7 @@ void destroy_tmcb_lists()
90 92
 	struct tm_callback *cbp, *cbp_tmp;
91 93
 
92 94
 	if (req_in_tmcb_hl){
93
-		for( cbp=req_in_tmcb_hl->first; cbp ; ) {
95
+		for( cbp=(struct tm_callback*)req_in_tmcb_hl->first; cbp ; ) {
94 96
 			cbp_tmp = cbp;
95 97
 			cbp = cbp->next;
96 98
 			if (cbp_tmp->param) shm_free( cbp_tmp->param );
... ...
@@ -100,7 +102,7 @@ void destroy_tmcb_lists()
100 102
 		req_in_tmcb_hl=0;
101 103
 	}
102 104
 	if(local_req_in_tmcb_hl){
103
-		for( cbp=local_req_in_tmcb_hl->first; cbp ; ) {
105
+		for( cbp=(struct tm_callback*)local_req_in_tmcb_hl->first; cbp ; ) {
104 106
 			cbp_tmp = cbp;
105 107
 			cbp = cbp->next;
106 108
 			if (cbp_tmp->param) shm_free( cbp_tmp->param );
... ...
@@ -112,10 +114,14 @@ void destroy_tmcb_lists()
112 114
 }
113 115
 
114 116
 
117
+
118
+/* lockless insert: should be always safe */
115 119
 int insert_tmcb(struct tmcb_head_list *cb_list, int types,
116 120
 									transaction_cb f, void *param )
117 121
 {
118 122
 	struct tm_callback *cbp;
123
+	struct tm_callback *old;
124
+
119 125
 
120 126
 	/* build a new callback structure */
121 127
 	if (!(cbp=shm_malloc( sizeof( struct tm_callback)))) {
... ...
@@ -123,27 +129,23 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
123 129
 		return E_OUT_OF_MEM;
124 130
 	}
125 131
 
126
-	cb_list->reg_types |= types;
132
+	atomic_or_int(&cb_list->reg_types, types);
127 133
 	/* ... and fill it up */
128 134
 	cbp->callback = f;
129 135
 	cbp->param = param;
130 136
 	cbp->types = types;
137
+	old=(struct tm_callback*)cb_list->first;
131 138
 	/* link it into the proper place... */
132
-	cbp->next = cb_list->first;
133
-	if (cbp->next)
134
-		cbp->id = cbp->next->id+1;
135
-	else
136
-		cbp->id = 0;
137
-	membar_write(); /* make sure all the changes to cbp are visible on all cpus
138
-					   before we update cb_list->first. This is needed for
139
-					   three reasons: the compiler might reorder some of the 
140
-					   writes, the cpu/cache could also reorder them with
141
-					   respect to the visibility on other cpus
142
-					   (e.g. some of the changes to cbp could be visible on
143
-					    another cpu _after_ seeing cb_list->first=cbp) and
144
-					   the "readers" (callbacks callers) do not use locks and
145
-					   could be called simultaneously on another cpu.*/
146
-	cb_list->first = cbp;
139
+	do{
140
+		cbp->next = old;
141
+		if (cbp->next)
142
+			cbp->id = cbp->next->id+1;
143
+		else