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,2516 +0,0 @@
1
-/*
2
- * TM (transaction management) module
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- *
6
- * This file is part of Kamailio, a free SIP server.
7
- *
8
- * Kamailio is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
12
- *
13
- * Kamailio is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
- */
22
-
23
-/** TM :: Module API (core).
24
- * @file
25
- * @ingroup tm
26
- */
27
-
28
-/**
29
- * @defgroup tm TM :: Transaction stateful proxy support
30
- *
31
- * The TM module enables stateful processing of SIP transactions. The main use
32
- * of stateful logic, which is costly in terms of memory and CPU, is some
33
- * services that inherently need state.
34
- *
35
- * For example, transaction-based accounting (module acc) needs to process
36
- * transaction state as opposed to individual messages, and any kinds of
37
- * forking must be implemented statefully. Other use of stateful processing
38
- * is it trading CPU caused by retransmission processing for memory.
39
- * That however only makes sense if CPU consumption per request is huge.
40
- * For example, if you want to avoid costly DNS resolution for every
41
- * retransmission of a request to an unresolvable destination, use stateful
42
- * mode. Then, only the initial message burdens server by DNS queries,
43
- * subsequent retransmissions will be dropped and will not result in more
44
- * processes blocked by DNS resolution. The price is more memory consumption
45
- * and higher processing latency.
46
- */
47
-
48
-
49
-#include "defs.h"
50
-
51
-
52
-#include <stdio.h>
53
-#include <string.h>
54
-#include <netdb.h>
55
-
56
-#include "../../sr_module.h"
57
-#include "../../dprint.h"
58
-#include "../../error.h"
59
-#include "../../ut.h"
60
-#include "../../script_cb.h"
61
-#include "../../usr_avp.h"
62
-#include "../../mem/mem.h"
63
-#include "../../route_struct.h"
64
-#include "../../route.h"
65
-#include "../../cfg/cfg.h"
66
-#include "../../globals.h"
67
-#include "../../timer_ticks.h"
68
-#include "../../mod_fix.h"
69
-#include "../../kemi.h"
70
-
71
-#include "config.h"
72
-#include "sip_msg.h"
73
-#include "h_table.h"
74
-#include "t_hooks.h"
75
-#include "tm_load.h"
76
-#include "ut.h"
77
-#include "t_reply.h"
78
-#include "uac.h"
79
-#include "t_fwd.h"
80
-#include "t_lookup.h"
81
-#include "t_stats.h"
82
-#include "callid.h"
83
-#include "t_cancel.h"
84
-#include "t_fifo.h"
85
-#include "timer.h"
86
-#include "t_msgbuilder.h"
87
-#include "select.h"
88
-#include "t_serial.h"
89
-#include "rpc_uac.h"
90
-
91
-MODULE_VERSION
92
-
93
-/* fixup functions */
94
-static int fixup_hostport2proxy(void** param, int param_no);
95
-static int fixup_proto_hostport2proxy(void** param, int param_no);
96
-static int fixup_on_failure(void** param, int param_no);
97
-static int fixup_on_branch_failure(void** param, int param_no);
98
-static int fixup_on_reply(void** param, int param_no);
99
-static int fixup_on_branch(void** param, int param_no);
100
-static int fixup_t_reply(void** param, int param_no);
101
-static int fixup_on_sl_reply(modparam_t type, void* val);
102
-static int fixup_t_relay_to(void** param, int param_no);
103
-static int fixup_t_is_set(void** param, int param_no);
104
-
105
-/* init functions */
106
-static int mod_init(void);
107
-static int child_init(int rank);
108
-
109
-
110
-/* exported functions */
111
-inline static int w_t_check(struct sip_msg* msg, char* str, char* str2);
112
-inline static int w_t_lookup_cancel(struct sip_msg* msg, char* str, char* str2);
113
-inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2);
114
-inline static int w_t_release(struct sip_msg* msg, char* str, char* str2);
115
-inline static int w_t_retransmit_reply(struct sip_msg* p_msg, char* foo,
116
-		char* bar );
117
-inline static int w_t_newtran(struct sip_msg* p_msg, char* foo, char* bar );
118
-inline static int w_t_relay( struct sip_msg  *p_msg , char *_foo, char *_bar);
119
-inline static int w_t_relay2( struct sip_msg  *p_msg , char *proxy, char*);
120
-inline static int w_t_relay_to_udp( struct sip_msg  *p_msg , char *proxy,
121
-		char *);
122
-inline static int w_t_relay_to_udp_uri( struct sip_msg  *p_msg , char*, char*);
123
-#ifdef USE_TCP
124
-inline static int w_t_relay_to_tcp( struct sip_msg  *p_msg , char *proxy,
125
-		char *);
126
-inline static int w_t_relay_to_tcp_uri( struct sip_msg  *p_msg , char*, char*);
127
-#endif
128
-#ifdef USE_TLS
129
-inline static int w_t_relay_to_tls( struct sip_msg  *p_msg , char *proxy,
130
-		char *);
131
-inline static int w_t_relay_to_tls_uri( struct sip_msg  *p_msg , char*, char*);
132
-#endif
133
-#ifdef USE_SCTP
134
-inline static int w_t_relay_to_sctp( struct sip_msg  *p_msg , char *proxy,
135
-		char *);
136
-inline static int w_t_relay_to_sctp_uri( struct sip_msg*, char*, char*);
137
-#endif
138
-inline static int w_t_relay_to_avp(struct sip_msg* msg, char* str,char*);
139
-inline static int w_t_relay_to(struct sip_msg* msg, char* str,char*);
140
-inline static int w_t_replicate_uri( struct sip_msg  *p_msg ,
141
-		char *uri,       /* sip uri as string or variable */
142
-		char *_foo       /* nothing expected */ );
143
-inline static int w_t_replicate( struct sip_msg  *p_msg ,
144
-		char *proxy, /* struct proxy_l *proxy expected */
145
-		char *_foo       /* nothing expected */ );
146
-inline static int w_t_replicate_udp( struct sip_msg  *p_msg ,
147
-		char *proxy, /* struct proxy_l *proxy expected */
148
-		char *_foo       /* nothing expected */ );
149
-#ifdef USE_TCP
150
-inline static int w_t_replicate_tcp( struct sip_msg  *p_msg ,
151
-		char *proxy, /* struct proxy_l *proxy expected */
152
-		char *_foo       /* nothing expected */ );
153
-#endif
154
-#ifdef USE_TLS
155
-inline static int w_t_replicate_tls( struct sip_msg  *p_msg ,
156
-		char *proxy, /* struct proxy_l *proxy expected */
157
-		char *_foo       /* nothing expected */ );
158
-#endif
159
-#ifdef USE_SCTP
160
-inline static int w_t_replicate_sctp( struct sip_msg  *p_msg ,
161
-		char *proxy, /* struct proxy_l *proxy expected */
162
-		char *_foo       /* nothing expected */ );
163
-#endif
164
-inline static int w_t_replicate_to(struct sip_msg* msg, char* str,char*);
165
-inline static int w_t_forward_nonack(struct sip_msg* msg, char* str, char* );
166
-inline static int w_t_forward_nonack_uri(struct sip_msg* msg, char* str,char*);
167
-inline static int w_t_forward_nonack_udp(struct sip_msg* msg, char* str,char*);
168
-#ifdef USE_TCP
169
-inline static int w_t_forward_nonack_tcp(struct sip_msg*, char* str,char*);
170
-#endif
171
-#ifdef USE_TLS
172
-inline static int w_t_forward_nonack_tls(struct sip_msg*, char* str,char*);
173
-#endif
174
-#ifdef USE_SCTP
175
-inline static int w_t_forward_nonack_sctp(struct sip_msg*, char* str,char*);
176
-#endif
177
-inline static int w_t_forward_nonack_to(struct sip_msg* msg, char* str,char*);
178
-inline static int w_t_relay_cancel(struct sip_msg *p_msg, char *_foo,
179
-		char *_bar);
180
-inline static int w_t_on_failure(struct sip_msg* msg, char *go_to, char *foo);
181
-inline static int w_t_on_branch_failure(struct sip_msg* msg, char *go_to,
182
-		char *foo);
183
-inline static int w_t_on_branch(struct sip_msg* msg, char *go_to, char *foo);
184
-inline static int w_t_on_reply(struct sip_msg* msg, char *go_to, char *foo );
185
-inline static int t_check_status(struct sip_msg* msg, char *match, char *foo);
186
-static int t_set_fr_inv(struct sip_msg* msg, char* fr_inv, char* foo);
187
-static int t_set_fr_all(struct sip_msg* msg, char* fr_inv, char* fr);
188
-static int w_t_reset_fr(struct sip_msg* msg, char* foo, char* bar);
189
-static int w_t_set_retr(struct sip_msg* msg, char* retr_t1, char* retr_t2);
190
-static int w_t_reset_retr(struct sip_msg* msg, char* foo, char* bar);
191
-static int w_t_set_max_lifetime(struct sip_msg* msg, char* inv, char* noninv);
192
-static int w_t_reset_max_lifetime(struct sip_msg* msg, char* foo, char* bar);
193
-static int t_set_auto_inv_100(struct sip_msg* msg, char* on_off, char* foo);
194
-static int t_set_disable_6xx(struct sip_msg* msg, char* on_off, char* foo);
195
-static int t_set_disable_failover(struct sip_msg* msg, char* on_off, char* f);
196
-#ifdef CANCEL_REASON_SUPPORT
197
-static int t_set_no_e2e_cancel_reason(struct sip_msg* msg, char* on_off,
198
-		char* f);
199
-#endif /* CANCEL_REASON_SUPPORT */
200
-static int t_set_disable_internal_reply(struct sip_msg* msg, char* on_off,
201
-		char* f);
202
-static int t_branch_timeout(struct sip_msg* msg, char*, char*);
203
-static int t_branch_replied(struct sip_msg* msg, char*, char*);
204
-static int t_any_timeout(struct sip_msg* msg, char*, char*);
205
-static int t_any_replied(struct sip_msg* msg, char*, char*);
206
-static int w_t_is_canceled(struct sip_msg* msg, char*, char*);
207
-static int t_is_expired(struct sip_msg* msg, char*, char*);
208
-static int w_t_is_retr_async_reply(struct sip_msg* msg, char*, char*);
209
-static int t_grep_status(struct sip_msg* msg, char*, char*);
210
-static int w_t_drop_replies(struct sip_msg* msg, char* foo, char* bar);
211
-static int w_t_save_lumps(struct sip_msg* msg, char* foo, char* bar);
212
-static int w_t_check_trans(struct sip_msg* msg, char* foo, char* bar);
213
-static int w_t_is_set(struct sip_msg* msg, char* target, char* bar);
214
-static int w_t_use_uac_headers(sip_msg_t* msg, char* foo, char* bar);
215
-
216
-
217
-/* by default the fr timers avps are not set, so that the avps won't be
218
- * searched for nothing each time a new transaction is created */
219
-static char *fr_timer_param = 0 /*FR_TIMER_AVP*/;
220
-static char *fr_inv_timer_param = 0 /*FR_INV_TIMER_AVP*/;
221
-
222
-str contacts_avp = {0, 0};
223
-str contact_flows_avp = {0, 0};
224
-str ulattrs_xavp_name = {NULL, 0};
225
-
226
-int tm_remap_503_500 = 1;
227
-
228
-int tm_failure_exec_mode = 0;
229
-
230
-int tm_dns_reuse_rcv_socket = 0;
231
-
232
-static rpc_export_t tm_rpc[];
233
-
234
-str tm_event_callback = STR_NULL;
235
-
236
-static int fixup_t_check_status(void** param, int param_no);
237
-
238
-static cmd_export_t cmds[]={
239
-	{"t_newtran",          w_t_newtran,             0, 0,
240
-		REQUEST_ROUTE},
241
-	{"t_lookup_request",   w_t_check,               0, 0,
242
-		REQUEST_ROUTE},
243
-	{"t_lookup_cancel",    w_t_lookup_cancel,       0, 0,
244
-		REQUEST_ROUTE},
245
-	{"t_lookup_cancel",    w_t_lookup_cancel,       1, fixup_int_1,
246
-		REQUEST_ROUTE},
247
-	{"t_reply",              w_t_reply,               2, fixup_t_reply,
248
-		REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE },
249
-	{"t_retransmit_reply", w_t_retransmit_reply,    0, 0,
250
-		REQUEST_ROUTE},
251
-	{"t_release",          w_t_release,             0, 0,
252
-		REQUEST_ROUTE},
253
-	{"t_relay_to_udp",       w_t_relay_to_udp,        2, fixup_hostport2proxy,
254
-		REQUEST_ROUTE|FAILURE_ROUTE},
255
-	{"t_relay_to_udp",       w_t_relay_to_udp_uri,    0, 0,
256
-		REQUEST_ROUTE|FAILURE_ROUTE},
257
-#ifdef USE_TCP
258
-	{"t_relay_to_tcp",       w_t_relay_to_tcp,        2, fixup_hostport2proxy,
259
-		REQUEST_ROUTE|FAILURE_ROUTE},
260
-	{"t_relay_to_tcp",       w_t_relay_to_tcp_uri,    0, 0,
261
-		REQUEST_ROUTE|FAILURE_ROUTE},
262
-#endif
263
-#ifdef USE_TLS
264
-	{"t_relay_to_tls",       w_t_relay_to_tls,        2, fixup_hostport2proxy,
265
-		REQUEST_ROUTE|FAILURE_ROUTE},
266
-	{"t_relay_to_tls",       w_t_relay_to_tls_uri,    0, 0,
267
-		REQUEST_ROUTE|FAILURE_ROUTE},
268
-#endif
269
-#ifdef USE_SCTP
270
-	{"t_relay_to_sctp",       w_t_relay_to_sctp,       2, fixup_hostport2proxy,
271
-		REQUEST_ROUTE|FAILURE_ROUTE},
272
-	{"t_relay_to_sctp",       w_t_relay_to_sctp_uri,    0, 0,
273
-		REQUEST_ROUTE|FAILURE_ROUTE},
274
-#endif
275
-	{"t_replicate",        w_t_replicate_uri,       0, 0,
276
-		REQUEST_ROUTE},
277
-	{"t_replicate",        w_t_replicate_uri,       1, fixup_spve_null,
278
-		REQUEST_ROUTE},
279
-	{"t_replicate",        w_t_replicate,           2, fixup_hostport2proxy,
280
-		REQUEST_ROUTE},
281
-	{"t_replicate_udp",    w_t_replicate_udp,       2, fixup_hostport2proxy,
282
-		REQUEST_ROUTE},
283
-#ifdef USE_TCP
284
-	{"t_replicate_tcp",    w_t_replicate_tcp,       2, fixup_hostport2proxy,
285
-		REQUEST_ROUTE},
286
-#endif
287
-#ifdef USE_TLS
288
-	{"t_replicate_tls",    w_t_replicate_tls,       2, fixup_hostport2proxy,
289
-		REQUEST_ROUTE},
290
-#endif
291
-#ifdef USE_SCTP
292
-	{"t_replicate_sctp",    w_t_replicate_sctp,     2, fixup_hostport2proxy,
293
-		REQUEST_ROUTE},
294
-#endif
295
-	{"t_replicate_to", w_t_replicate_to,  		2, fixup_proto_hostport2proxy,
296
-		REQUEST_ROUTE},
297
-	{"t_relay",              w_t_relay,               0, 0,
298
-		REQUEST_ROUTE | FAILURE_ROUTE },
299
-	{"t_relay",              w_t_relay2,              2, fixup_hostport2proxy,
300
-		REQUEST_ROUTE | FAILURE_ROUTE },
301
-	{"t_relay_to_avp", w_t_relay_to_avp,  		2, fixup_proto_hostport2proxy,
302
-		REQUEST_ROUTE},
303
-	{"t_relay_to",			w_t_relay_to,           0, 0,
304
-		REQUEST_ROUTE | FAILURE_ROUTE },
305
-	{"t_relay_to",			w_t_relay_to,           1, fixup_t_relay_to,
306
-		REQUEST_ROUTE | FAILURE_ROUTE },
307
-	{"t_relay_to",			w_t_relay_to,           2, fixup_t_relay_to,
308
-		REQUEST_ROUTE | FAILURE_ROUTE },
309
-	{"t_forward_nonack",     w_t_forward_nonack,      2, fixup_hostport2proxy,
310
-		REQUEST_ROUTE},
311
-	{"t_forward_nonack_uri", w_t_forward_nonack_uri,  0, 0,
312
-		REQUEST_ROUTE},
313
-	{"t_forward_nonack_udp", w_t_forward_nonack_udp,  2, fixup_hostport2proxy,
314
-		REQUEST_ROUTE},
315
-#ifdef USE_TCP
316
-	{"t_forward_nonack_tcp", w_t_forward_nonack_tcp,  2, fixup_hostport2proxy,
317
-		REQUEST_ROUTE},
318
-#endif
319
-#ifdef USE_TLS
320
-	{"t_forward_nonack_tls", w_t_forward_nonack_tls,  2, fixup_hostport2proxy,
321
-		REQUEST_ROUTE},
322
-#endif
323
-#ifdef USE_SCTP
324
-	{"t_forward_nonack_sctp", w_t_forward_nonack_sctp, 2, fixup_hostport2proxy,
325
-		REQUEST_ROUTE},
326
-#endif
327
-	{"t_forward_nonack_to", w_t_forward_nonack_to,  2, fixup_proto_hostport2proxy,
328
-		REQUEST_ROUTE},
329
-	{"t_relay_cancel",     w_t_relay_cancel,        0, 0,
330
-		REQUEST_ROUTE},
331
-	{"t_on_failure",       w_t_on_failure,         1, fixup_on_failure,
332
-		REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
333
-	{"t_on_branch_failure",w_t_on_branch_failure,  1, fixup_on_branch_failure,
334
-		REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
335
-	{"t_on_reply",         w_t_on_reply,            1, fixup_on_reply,
336
-		REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
337
-	{"t_on_branch",       w_t_on_branch,         1, fixup_on_branch,
338
-		REQUEST_ROUTE | FAILURE_ROUTE },
339
-	{"t_check_status",     t_check_status,          1, fixup_t_check_status,
340
-		REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
341
-	{"t_write_req",       t_write_req,              2, fixup_t_write,
342
-		REQUEST_ROUTE | FAILURE_ROUTE },
343
-	{"t_write_unix",      t_write_unix,             2, fixup_t_write,
344
-		REQUEST_ROUTE | FAILURE_ROUTE },
345
-	{"t_set_fr",          t_set_fr_inv,             1, fixup_var_int_1,
346
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
347
-	{"t_set_fr",          t_set_fr_all,             2, fixup_var_int_12,
348
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
349
-	{"t_reset_fr",        w_t_reset_fr,             0, 0,
350
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
351
-	{"t_set_retr",        w_t_set_retr,               2, fixup_var_int_12,
352
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
353
-	{"t_reset_retr",      w_t_reset_retr,           0, 0,
354
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
355
-	{"t_set_max_lifetime", w_t_set_max_lifetime,      2, fixup_var_int_12,
356
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
357
-	{"t_reset_max_lifetime", w_t_reset_max_lifetime, 0, 0,
358
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
359
-	{"t_set_auto_inv_100", t_set_auto_inv_100,       1, fixup_var_int_1,
360
-		REQUEST_ROUTE},
361
-	{"t_set_disable_6xx", t_set_disable_6xx,         1, fixup_var_int_1,
362
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
363
-	{"t_set_disable_failover", t_set_disable_failover, 1, fixup_var_int_1,
364
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
365
-#ifdef CANCEL_REASON_SUPPORT
366
-	{"t_set_no_e2e_cancel_reason", t_set_no_e2e_cancel_reason, 1,
367
-		fixup_var_int_1,
368
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
369
-	/* alias for t_set_no_e2e_cancel_reason */
370
-	{"t_disable_e2e_cancel_reason", t_set_no_e2e_cancel_reason, 1,
371
-		fixup_var_int_1,
372
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
373
-#endif /* CANCEL_REASON_SUPPORT */
374
-	{"t_set_disable_internal_reply", t_set_disable_internal_reply, 1,
375
-		fixup_var_int_1,
376
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
377
-	{"t_branch_timeout",  t_branch_timeout,         0, 0,
378
-		FAILURE_ROUTE|EVENT_ROUTE},
379
-	{"t_branch_replied",  t_branch_replied,         0, 0,
380
-		FAILURE_ROUTE|EVENT_ROUTE},
381
-	{"t_any_timeout",     t_any_timeout,            0, 0,
382
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
383
-	{"t_any_replied",     t_any_replied,            0, 0,
384
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
385
-	{"t_is_canceled",     w_t_is_canceled,          0, 0,
386
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
387
-	{"t_is_retr_async_reply",     w_t_is_retr_async_reply,          0, 0,
388
-		TM_ONREPLY_ROUTE},
389
-	{"t_is_expired",      t_is_expired,             0, 0,
390
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
391
-	{"t_grep_status",     t_grep_status,            1, fixup_var_int_1,
392
-		REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
393
-	{"t_drop_replies",    w_t_drop_replies,         0, 0,
394
-		FAILURE_ROUTE},
395
-	{"t_drop_replies",    w_t_drop_replies,         1, 0,
396
-		FAILURE_ROUTE},
397
-	{"t_save_lumps",      w_t_save_lumps,           0, 0,
398
-		REQUEST_ROUTE},
399
-	{"t_check_trans",	  w_t_check_trans,			0, 0,
400
-		REQUEST_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE },
401
-	{"t_is_set",	      w_t_is_set,				1, fixup_t_is_set,
402
-		ANY_ROUTE },
403
-	{"t_use_uac_headers",  w_t_use_uac_headers,		0, 0,
404
-		ANY_ROUTE },
405
-
406
-	{"t_load_contacts", t_load_contacts,            0, 0,
407
-		REQUEST_ROUTE | FAILURE_ROUTE},
408
-	{"t_next_contacts", t_next_contacts,            0, 0,
409
-		REQUEST_ROUTE | FAILURE_ROUTE},
410
-	{"t_next_contact_flow", t_next_contact_flow,            0, 0,
411
-		REQUEST_ROUTE },
412
-
413
-	/* not applicable from the script */
414
-	{"load_tm",            (cmd_function)load_tm,           NO_SCRIPT,   0, 0},
415
-	{"load_xtm",           (cmd_function)load_xtm,          NO_SCRIPT,   0, 0},
416
-	{0,0,0,0,0}
417
-};
418
-
419
-
420
-static param_export_t params[]={
421
-	{"ruri_matching",       PARAM_INT, &default_tm_cfg.ruri_matching         },
422
-	{"via1_matching",       PARAM_INT, &default_tm_cfg.via1_matching         },
423
-	{"callid_matching",     PARAM_INT, &default_tm_cfg.callid_matching       },
424
-	{"fr_timer",            PARAM_INT, &default_tm_cfg.fr_timeout            },
425
-	{"fr_inv_timer",        PARAM_INT, &default_tm_cfg.fr_inv_timeout        },
426
-	{"wt_timer",            PARAM_INT, &default_tm_cfg.wait_timeout          },
427
-	{"delete_timer",        PARAM_INT, &default_tm_cfg.delete_timeout        },
428
-	{"retr_timer1",         PARAM_INT, &default_tm_cfg.rt_t1_timeout_ms      },
429
-	{"retr_timer2"  ,       PARAM_INT, &default_tm_cfg.rt_t2_timeout_ms      },
430
-	{"max_inv_lifetime",    PARAM_INT, &default_tm_cfg.tm_max_inv_lifetime   },
431
-	{"max_noninv_lifetime", PARAM_INT, &default_tm_cfg.tm_max_noninv_lifetime},
432
-	{"noisy_ctimer",        PARAM_INT, &default_tm_cfg.noisy_ctimer          },
433
-	{"auto_inv_100",        PARAM_INT, &default_tm_cfg.tm_auto_inv_100       },
434
-	{"auto_inv_100_reason", PARAM_STRING, &default_tm_cfg.tm_auto_inv_100_r  },
435
-	{"unix_tx_timeout",     PARAM_INT, &default_tm_cfg.tm_unix_tx_timeout    },
436
-	{"restart_fr_on_each_reply", PARAM_INT,
437
-		&default_tm_cfg.restart_fr_on_each_reply},
438
-	{"fr_timer_avp",        PARAM_STRING, &fr_timer_param                    },
439
-	{"fr_inv_timer_avp",    PARAM_STRING, &fr_inv_timer_param                },
440
-	{"tw_append",           PARAM_STRING|PARAM_USE_FUNC,
441
-		(void*)parse_tw_append   },
442
-	{"pass_provisional_replies", PARAM_INT,
443
-		&default_tm_cfg.pass_provisional_replies },
444
-	{"aggregate_challenges", PARAM_INT, &default_tm_cfg.tm_aggregate_auth    },
445
-	{"unmatched_cancel",    PARAM_INT, &default_tm_cfg.unmatched_cancel      },
446
-	{"default_code",        PARAM_INT, &default_tm_cfg.default_code          },
447
-	{"default_reason",      PARAM_STRING, &default_tm_cfg.default_reason     },
448
-	{"reparse_invite",      PARAM_INT, &default_tm_cfg.reparse_invite        },
449
-	{"ac_extra_hdrs",       PARAM_STR, &default_tm_cfg.ac_extra_hdrs         },
450
-	{"blst_503",            PARAM_INT, &default_tm_cfg.tm_blst_503           },
451
-	{"blst_503_def_timeout",PARAM_INT, &default_tm_cfg.tm_blst_503_default   },
452
-	{"blst_503_min_timeout",PARAM_INT, &default_tm_cfg.tm_blst_503_min       },
453
-	{"blst_503_max_timeout",PARAM_INT, &default_tm_cfg.tm_blst_503_max       },
454
-	{"blst_methods_add",    PARAM_INT, &default_tm_cfg.tm_blst_methods_add   },
455
-	{"blst_methods_lookup", PARAM_INT, &default_tm_cfg.tm_blst_methods_lookup},
456
-	{"cancel_b_method",     PARAM_INT, &default_tm_cfg.cancel_b_flags},
457
-	{"reparse_on_dns_failover", PARAM_INT,
458
-		&default_tm_cfg.reparse_on_dns_failover},
459
-	{"on_sl_reply",         PARAM_STRING|PARAM_USE_FUNC, fixup_on_sl_reply   },
460
-	{"contacts_avp",        PARAM_STR, &contacts_avp                },
461
-	{"contact_flows_avp",   PARAM_STR, &contact_flows_avp           },
462
-	{"disable_6xx_block",   PARAM_INT, &default_tm_cfg.disable_6xx           },
463
-	{"local_ack_mode",      PARAM_INT, &default_tm_cfg.local_ack_mode        },
464
-	{"failure_reply_mode",  PARAM_INT, &failure_reply_mode                   },
465
-	{"faked_reply_prio",    PARAM_INT, &faked_reply_prio                     },
466
-	{"remap_503_500",       PARAM_INT, &tm_remap_503_500                     },
467
-	{"failure_exec_mode",   PARAM_INT, &tm_failure_exec_mode                 },
468
-	{"dns_reuse_rcv_socket",PARAM_INT, &tm_dns_reuse_rcv_socket              },
469
-#ifdef CANCEL_REASON_SUPPORT
470
-	{"local_cancel_reason", PARAM_INT, &default_tm_cfg.local_cancel_reason   },
471
-	{"e2e_cancel_reason",   PARAM_INT, &default_tm_cfg.e2e_cancel_reason     },
472
-#endif /* CANCEL_REASON_SUPPORT */
473
-	{"xavp_contact",        PARAM_STR, &ulattrs_xavp_name                    },
474
-	{"event_callback",      PARAM_STR, &tm_event_callback                    },
475
-	{0,0,0}
476
-};
477
-
478
-#ifdef STATIC_TM
479
-struct module_exports tm_exports = {
480
-#else
481
-struct module_exports exports= {
482
-#endif
483
-	"tm",
484
-	/* -------- exported functions ----------- */
485
-	cmds,
486
-	tm_rpc,    /* RPC methods */
487
-	/* ------------ exported variables ---------- */
488
-	params,
489
-
490
-	mod_init, /* module initialization function */
491
-	(response_function) reply_received,
492
-	(destroy_function) tm_shutdown,
493
-	0, /* w_onbreak, */
494
-	child_init /* per-child init function */
495
-};
496
-
497
-
498
-
499
-/* helper for fixup_on_* */
500
-static int fixup_routes(char* r_type, struct route_list* rt, void** param)
501
-{
502
-	int i;
503
-
504
-	i=route_get(rt, (char*)*param);
505
-	if (i==-1){
506
-		LM_ERR("route_get failed\n");
507
-		return E_UNSPEC;
508
-	}
509
-	if (r_type && rt->rlist[i]==0){
510
-		LM_WARN("%s(\"%s\"): empty/non existing route\n",
511
-				r_type, (char*)*param);
512
-	}
513
-	*param=(void*)(long)i;
514
-	return 0;
515
-}
516
-
517
-static int fixup_t_reply(void** param, int param_no)
518
-{
519
-	if (param_no == 1) {
520
-		if (fixup_var_int_12(param, 1) != 0) return -1;
521
-	} else if (param_no == 2) {
522
-		return fixup_var_str_12(param, 2);
523
-	}
524
-	return 0;
525
-}
526
-
527
-static int fixup_on_failure(void** param, int param_no)
528
-{
529
-	if (param_no==1){
530
-		if(strlen((char*)*param)<=1
531
-				&& (*(char*)(*param)==0 || *(char*)(*param)=='0')) {
532
-			*param = (void*)0;
533
-			return 0;
534
-		}
535
-		return fixup_routes("t_on_failure", &failure_rt, param);
536
-	}
537
-	return 0;
538
-}
539
-
540
-#define BRANCH_FAILURE_ROUTE_PREFIX "tm:branch-failure"
541
-static int fixup_on_branch_failure(void** param, int param_no)
542
-{
543
-	char *full_route_name = NULL;
544
-	int len;
545
-	int ret = 0;
546
-	if (param_no==1){
547
-		if((len = strlen((char*)*param))<=1
548
-				&& (*(char*)(*param)==0 || *(char*)(*param)=='0')) {
549
-			*param = (void*)0;
550
-			return 0;
551
-		}
552
-		len += strlen(BRANCH_FAILURE_ROUTE_PREFIX) + 1;
553
-		if ((full_route_name = pkg_malloc(len+1)) == NULL)
554
-		{
555
-			LM_ERR("No memory left in branch_failure fixup\n");
556
-			return -1;
557
-		}
558
-		sprintf(full_route_name, "%s:%s", BRANCH_FAILURE_ROUTE_PREFIX, (char*)*param);
559
-		*param=(void*)full_route_name;
560
-		ret = fixup_routes("t_on_branch_failure", &event_rt, param);
561
-		pkg_free(full_route_name);
562
-	}
563
-	return ret;
564
-}
565
-
566
-
567
-static int fixup_on_reply(void** param, int param_no)
568
-{
569
-	if (param_no==1){
570
-		if(strlen((char*)*param)<=1
571
-				&& (*(char*)(*param)==0 || *(char*)(*param)=='0')) {
572
-			*param = (void*)0;
573
-			return 0;
574
-		}
575
-		return fixup_routes("t_on_reply", &onreply_rt, param);
576
-	}
577
-	return 0;
578
-}
579
-
580
-
581
-
582
-static int fixup_on_branch(void** param, int param_no)
583
-{
584
-	if (param_no==1){
585
-		if(strlen((char*)*param)<=1
586
-				&& (*(char*)(*param)==0 || *(char*)(*param)=='0')) {
587
-			*param = (void*)0;
588
-			return 0;
589
-		}
590
-		return fixup_routes("t_on_branch", &branch_rt, param);
591
-	}
592
-	return 0;
593
-}
594
-
595
-static int fixup_on_sl_reply(modparam_t type, void* val)
596
-{
597
-	if ((type & PARAM_STRING) == 0) {
598
-		LM_ERR("not a string parameter\n");
599
-		return -1;
600
-	}
601
-
602
-	if (fixup_routes(0, &onreply_rt, &val))
603
-		return -1;
604
-
605
-	goto_on_sl_reply = (int)(long)val;
606
-	return 0;
607
-}
608
-
609
-
610
-
611
-/* (char *hostname, char *port_nr) ==> (struct proxy_l *, -)  */
612
-static int fixup_hostport2proxy(void** param, int param_no)
613
-{
614
-	unsigned int port;
615
-	char *host;
616
-	int err;
617
-	struct proxy_l *proxy;
618
-	action_u_t *a;
619
-	str s;
620
-
621
-	DBG("TM module: fixup_hostport2proxy(%s, %d)\n", (char*)*param, param_no);
622
-	if (param_no==1){
623
-		return 0;
624
-	} else if (param_no==2) {
625
-		a = fixup_get_param(param, param_no, 1);
626
-		host= a->u.string;
627
-		port=str2s(*param, strlen(*param), &err);
628
-		if (err!=0) {
629
-			LM_ERR("bad port number <%s>\n",
630
-					(char*)(*param));
631
-			return E_UNSPEC;
632
-		}
633
-		s.s = host;
634
-		s.len = strlen(host);
635
-		proxy=mk_proxy(&s, port, 0); /* FIXME: udp or tcp? */
636
-		if (proxy==0) {
637
-			LM_ERR("bad host name in URI <%s>\n",
638
-					host );
639
-			return E_BAD_ADDRESS;
640
-		}
641
-		/* success -- fix the first parameter to proxy now ! */
642
-
643
-		a->u.data=proxy;
644
-		return 0;
645
-	} else {
646
-		LM_ERR("called with parameter number different than {1,2}\n");
647
-		return E_BUG;
648
-	}
649
-}
650
-
651
-/* (char *$proto, char *$host:port) ==> (fparam, fparam)  */
652
-static int fixup_proto_hostport2proxy(void** param, int param_no) {
653
-	int ret;
654
-
655
-	ret = fix_param(FPARAM_AVP, param);
656
-	if (ret <= 0) return ret;
657
-	if (fix_param(FPARAM_STRING, param) != 0) return -1;
658
-	return 0;
659
-}
660
-
661
-
662
-static int fixup_t_check_status(void** param, int param_no)
663
-{
664
-	int ret;
665
-
666
-	ret = fix_param(FPARAM_AVP, param);
667
-	if (ret <= 0) return ret;
668
-
669
-	ret = fix_param(FPARAM_SELECT, param);
670
-	if (ret <= 0) return ret;
671
-
672
-	if (fix_param(FPARAM_REGEX, param) != 0) return -1;
673
-	return 0;
674
-}
675
-
676
-
677
-/***************************** init functions *****************************/
678
-static int w_t_unref( struct sip_msg *foo, unsigned int flags, void *bar)
679
-{
680
-	return t_unref(foo);
681
-}
682
-
683
-
684
-static int script_init( struct sip_msg *foo, unsigned int flags, void *bar)
685
-{
686
-	/* we primarily reset all private memory here to make sure
687
-	 * private values left over from previous message will
688
-	 * not be used again */
689
-
690
-	/* make sure the new message will not inherit previous
691
-	   message's t_on_failure value
692
-	   */
693
-	t_on_failure( 0 );
694
-	t_on_branch_failure(0);
695
-	t_on_reply(0);
696
-	t_on_branch(0);
697
-	/* reset the kr status */
698
-	reset_kr();
699
-	/* set request mode so that multiple-mode actions know
700
-	 * how to behave */
701
-	set_route_type(REQUEST_ROUTE);
702
-	lumps_are_cloned = 0;
703
-	return 1;
704
-}
705
-
706
-
707
-static int mod_init(void)
708
-{
709
-	DBG( "TM - (sizeof cell=%ld, sip_msg=%ld) initializing...\n",
710
-			(long)sizeof(struct cell), (long)sizeof(struct sip_msg));
711
-
712
-	/* checking if we have sufficient bitmap capacity for given
713
-	 * maximum number of  branches */
714
-	if (sr_dst_max_branches+1>31) {
715
-		LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n",
716
-				sr_dst_max_branches );
717
-		return -1;
718
-	}
719
-
720
-	if (init_callid() < 0) {
721
-		LM_CRIT("Error while initializing Call-ID generator\n");
722
-		return -1;
723
-	}
724
-
725
-	/* building the hash table*/
726
-	if (!init_hash_table()) {
727
-		LM_ERR("initializing hash_table failed\n");
728
-		return -1;
729
-	}
730
-
731
-	/* init static hidden values */
732
-	init_t();
733
-
734
-	if (tm_init_selects()==-1) {
735
-		LM_ERR("select init failed\n");
736
-		return -1;
737
-	}
738
-
739
-	/* the default timer values must be fixed-up before
740
-	 * declaring the configuration (Miklos) */
741
-	if (tm_init_timers()==-1) {
742
-		LM_ERR("timer init failed\n");
743
-		return -1;
744
-	}
745
-
746
-	/* the cancel branch flags must be fixed before declaring the
747
-	 * configuration */
748
-	if (cancel_b_flags_get(&default_tm_cfg.cancel_b_flags,
749
-				default_tm_cfg.cancel_b_flags)<0){
750
-		LM_ERR("bad cancel branch method\n");
751
-		return -1;
752
-	}
753
-
754
-#ifdef USE_DNS_FAILOVER
755
-	if (default_tm_cfg.reparse_on_dns_failover && mhomed) {
756
-		LM_WARN("reparse_on_dns_failover is enabled on a"
757
-				" multihomed host -- check the readme of tm module!\n");
758
-	}
759
-#endif
760
-
761
-	/* declare the configuration */
762
-	if (cfg_declare("tm", tm_cfg_def, &default_tm_cfg, cfg_sizeof(tm),
763
-				&tm_cfg)) {
764
-		LM_ERR("failed to declare the configuration\n");
765
-		return -1;
766
-	}
767
-
768
-	/* First tm_stat initialization function only allocates the top level stat
769
-	 * structure in shared memory, the initialization will complete in child
770
-	 * init with init_tm_stats_child when the final value of
771
-	 * estimated_process_count is known
772
-	 */
773
-	if (init_tm_stats() < 0) {
774
-		LM_CRIT("failed to init stats\n");
775
-		return -1;
776
-	}
777
-
778
-	if (uac_init()==-1) {
779
-		LM_ERR("uac_init failed\n");
780
-		return -1;
781
-	}
782
-
783
-	if (init_tmcb_lists()!=1) {
784
-		LM_CRIT("failed to init tmcb lists\n");
785
-		return -1;
786
-	}
787
-
788
-	tm_init_tags();
789
-	init_twrite_lines();
790
-	if (init_twrite_sock() < 0) {
791
-		LM_ERR("Unable to create socket\n");
792
-		return -1;
793
-	}
794
-
795
-	/* register post-script clean-up function */
796
-	if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQUEST_CB, 0)<0 ) {
797
-		LM_ERR("failed to register POST request callback\n");
798
-		return -1;
799
-	}
800
-	if (register_script_cb( script_init, PRE_SCRIPT_CB|REQUEST_CB , 0)<0 ) {
801
-		LM_ERR("failed to register PRE request callback\n");
802
-		return -1;
803
-	}
804
-
805
-	if (init_avp_params(fr_timer_param, fr_inv_timer_param) < 0) {
806
-		LM_ERR("failed to process AVP params\n");
807
-		return -1;
808
-	}
809
-	if ((contacts_avp.len > 0) && (contact_flows_avp.len == 0)) {
810
-		LM_ERR("contact_flows_avp param has not been defined\n");
811
-		return -1;
812
-	}
813
-
814
-#ifdef WITH_EVENT_LOCAL_REQUEST
815
-	goto_on_local_req=route_lookup(&event_rt, "tm:local-request");
816
-	if (goto_on_local_req>=0 && event_rt.rlist[goto_on_local_req]==0)
817
-		goto_on_local_req=-1; /* disable */
818
-	if (goto_on_local_req>=0 || tm_event_callback.len>0)
819
-		set_child_rpc_sip_mode();
820
-#endif /* WITH_EVENT_LOCAL_REQUEST */
821
-	if (goto_on_sl_reply && onreply_rt.rlist[goto_on_sl_reply]==0)
822
-		LM_WARN("empty/non existing on_sl_reply route\n");
823
-
824
-#ifdef WITH_TM_CTX
825
-	tm_ctx_init();
826
-#endif
827
-	tm_init = 1;
828
-	return 0;
829
-}
830
-
831
-static int child_init(int rank)
832
-{
833
-	if (rank == PROC_INIT) {
834
-		/* we must init stats when rank==PROC_INIT: after mod_init we know
835
-		 * the exact number of processes and we must init the shared structure
836
-		 * before any other process is starting (or else some new process
837
-		 * might try to use the stats before the stats array is allocated) */
838
-		if (init_tm_stats_child() < 0) {
839
-			LM_ERR("Error while initializing tm statistics structures\n");
840
-			return -1;
841
-		}
842
-	}else if (child_init_callid(rank) < 0) {
843
-		/* don't init callid for PROC_INIT*/
844
-		LM_ERR("Error while initializing Call-ID generator\n");
845
-		return -2;
846
-	}
847
-	return 0;
848
-}
849
-
850
-
851
-
852
-/**************************** wrapper functions ***************************/
853
-static int t_check_status(struct sip_msg* msg, char *p1, char *foo)
854
-{
855
-	regmatch_t pmatch;
856
-	struct cell *t;
857
-	char *status, *s = NULL;
858
-	char backup;
859
-	int lowest_status, n, ret;
860
-	fparam_t* fp;
861
-	regex_t* re = NULL;
862
-	str tmp;
863
-
864
-	fp = (fparam_t*)p1;
865
-	t = 0;
866
-	/* first get the transaction */
867
-	if (t_check(msg, 0 ) == -1) return -1;
868
-	if ((t = get_t()) == 0) {
869
-		LM_ERR("cannot check status for a reply"
870
-				" which has no T-state established\n");
871
-		goto error;
872
-	}
873
-	backup = 0;
874
-
875
-	switch(fp->type) {
876
-		case FPARAM_REGEX:
877
-			re = fp->v.regex;
878
-			break;
879
-
880
-		default:
881
-			/* AVP or select, get the value and compile the regex */
882
-			if (get_str_fparam(&tmp, msg, fp) < 0) goto error;
883
-			s = pkg_malloc(tmp.len + 1);
884
-			if (s == NULL) {
885
-				LM_ERR("Out of memory\n");
886
-				goto error;
887
-			}
888
-			memcpy(s, tmp.s, tmp.len);
889
-			s[tmp.len] = '\0';
890
-
891
-			if ((re = pkg_malloc(sizeof(regex_t))) == 0) {
892
-				LM_ERR("No memory left\n");
893
-				goto error;
894
-			}
895
-
896
-			if (regcomp(re, s, REG_EXTENDED|REG_ICASE|REG_NEWLINE)) {
897