Browse code

preliminary support for FIFO/t_uac added -- compiles, but not completed yet

Jiri Kuthan authored on 21/01/2003 13:53:48
Showing 39 changed files
... ...
@@ -47,6 +47,8 @@
47 47
 /* too many branches demanded */
48 48
 #define E_TOO_MANY_BRANCHES -12
49 49
 #define E_BAD_TO	-13
50
+/* invalid params */
51
+#define E_INVALID_PARAMS -14
50 52
 
51 53
 #define E_SEND		  -477
52 54
 /* unresolveable next-hop address */
... ...
@@ -217,7 +217,7 @@ int read_line_set(char *buf, int max_len, FILE *fifo, int *len)
217 217
 			return 0;
218 218
 		}
219 219
 		/* end encountered ... return */
220
-		if (line_len==0) {
220
+		if (line_len==0 || (line_len==1 && c[0]=='.' )) {
221 221
 			*len=set_len;
222 222
 			return 1;
223 223
 		}
... ...
@@ -231,6 +231,7 @@ int read_line_set(char *buf, int max_len, FILE *fifo, int *len)
231 231
 	}
232 232
 }
233 233
 
234
+
234 235
 /* read from input until line with only dot in it is encountered */
235 236
 int read_body(char *buf, int max_len, FILE *fifo, int *len)
236 237
 {
... ...
@@ -322,3 +322,13 @@ Known Issues
322 322
   for keeing SUB-NOT dialog state, etc. Currently, there are only
323 323
   place-holders for in in TM.
324 324
 - places labeled with "HACK" strongly deserve beautification
325
+
326
+
327
+ * ***************************************************
328
+ *             IMPORTANT NOTE
329
+ *
330
+ *    All UACs but t_uac_dlg are being deprecated now
331
+ *    and will be removed from future versions of TM
332
+ *    module. Eliminate all dependancies on them asap.
333
+ *
334
+ * ****************************************************
... ...
@@ -30,6 +30,8 @@
30 30
 #ifndef _TM_CONFIG_H
31 31
 #define _TM_CONFIG_H
32 32
 
33
+#include "defs.h"
34
+
33 35
 #ifdef _OBSOLETED
34 36
 /* moved to hash.h */
35 37
 /* always use a power of 2 for hash table size */
36 38
new file mode 100644
... ...
@@ -0,0 +1,35 @@
0
+/*
1
+ * $Id$
2
+ *
3
+ *
4
+ * Copyright (C) 2001-2003 Fhg Fokus
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser 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
+ * 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,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License 
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
26
+ */
27
+
28
+
29
+#ifndef _TM_DEFS_H
30
+#define _TM_DEFS_H
31
+
32
+#undef DEPRECATE_OLD_STUFF
33
+
34
+#endif
... ...
@@ -35,6 +35,9 @@
35 35
 #ifndef _FIX_LUMPS_H
36 36
 #define _FIX_LUMPS_H
37 37
 
38
+#include "defs.h"
39
+
40
+
38 41
 /* used to delete attached via lumps from msg; msg can
39 42
    be either an original pkg msg, whose Via lump I want
40 43
    to delete before generating next branch, or a shmem-stored
... ...
@@ -25,6 +25,9 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
+#include "defs.h"
29
+
30
+
28 31
 #include <stdlib.h>
29 32
 #include "../../mem/shm_mem.h"
30 33
 #include "../../hash_func.h"
... ...
@@ -25,6 +25,7 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
+#include "defs.h"
28 29
 
29 30
 
30 31
 #ifndef _H_TABLE_H
... ...
@@ -26,6 +26,8 @@
26 26
  */
27 27
 
28 28
 
29
+#include "defs.h"
30
+
29 31
 
30 32
 #include <errno.h>
31 33
 
... ...
@@ -25,6 +25,7 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
+#include "defs.h"
28 29
 
29 30
 
30 31
 #ifndef __lock_h
... ...
@@ -36,6 +36,8 @@
36 36
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
37 37
  */
38 38
 
39
+#include "defs.h"
40
+
39 41
 
40 42
 #include <stdio.h>
41 43
 #include "sip_msg.h"
... ...
@@ -30,6 +30,9 @@
30 30
 #ifndef _SIP_MSG_H
31 31
 #define _SIP_MSG_H
32 32
 
33
+#include "defs.h"
34
+
35
+
33 36
 #include "../../parser/msg_parser.h"
34 37
 #include "../../mem/shm_mem.h"
35 38
 
... ...
@@ -27,6 +27,8 @@
27 27
  */
28 28
 
29 29
 
30
+#include "defs.h"
31
+
30 32
 
31 33
 #include "t_funcs.h"
32 34
 #include "../../dprint.h"
... ...
@@ -30,6 +30,9 @@
30 30
 #ifndef _CANCEL_H
31 31
 #define _CANCEL_H
32 32
 
33
+#include "defs.h"
34
+
35
+
33 36
 /* a buffer is empty but cannot be used by anyone else;
34 37
    particularly, we use this value in the buffer pointer
35 38
    in local_buffer to tell "a process is already scheduled
... ...
@@ -27,6 +27,8 @@
27 27
  */
28 28
 
29 29
 
30
+#include "defs.h"
31
+
30 32
 #include "t_dlg.h"
31 33
 
32 34
 dlg_t dlg=0;
... ...
@@ -30,6 +30,9 @@
30 30
 #ifndef _T_DLG_H
31 31
 #define _T_DLG_H
32 32
 
33
+#include "defs.h"
34
+
35
+
33 36
 #include "../../parser/msg_parser.h"
34 37
 
35 38
 struct dialog {
... ...
@@ -28,6 +28,9 @@
28 28
  */
29 29
 
30 30
 
31
+#include "defs.h"
32
+
33
+
31 34
 #include <limits.h>
32 35
 #include "../../dprint.h"
33 36
 #include "../../config.h"
... ...
@@ -30,6 +30,9 @@
30 30
 #ifndef _T_FUNCS_H
31 31
 #define _T_FUNCS_H
32 32
 
33
+#include "defs.h"
34
+
35
+
33 36
 #include <errno.h>
34 37
 #include <netdb.h>
35 38
 
... ...
@@ -26,6 +26,8 @@
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 27
  */
28 28
 
29
+#include "defs.h"
30
+
29 31
 
30 32
 #include "../../dprint.h"
31 33
 #include "../../config.h"
... ...
@@ -30,6 +30,8 @@
30 30
 #ifndef _T_FWD_H
31 31
 #define _T_FWD_H
32 32
 
33
+#include "defs.h"
34
+
33 35
 #include "../../proxy.h"
34 36
 
35 37
 typedef int (*tfwd_f)(struct sip_msg* p_msg , struct proxy_l * proxy );
... ...
@@ -25,6 +25,8 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
+#include "defs.h"
29
+
28 30
 
29 31
 #include "stdlib.h"
30 32
 #include "../../dprint.h"
... ...
@@ -29,6 +29,9 @@
29 29
 #ifndef _HOOKS_H
30 30
 #define _HOOKS_H
31 31
 
32
+#include "defs.h"
33
+
34
+
32 35
 struct sip_msg;
33 36
 struct cell;
34 37
 
... ...
@@ -51,6 +51,9 @@
51 51
  */
52 52
 
53 53
 
54
+#include "defs.h"
55
+
56
+
54 57
 #include <assert.h>
55 58
 #include "../../dprint.h"
56 59
 #include "../../config.h"
... ...
@@ -30,6 +30,9 @@
30 30
 #ifndef _T_LOOKUP_H
31 31
 #define _T_LOOKUP_H
32 32
 
33
+#include "defs.h"
34
+
35
+
33 36
 #include "config.h"
34 37
 #include "t_funcs.h"
35 38
 
... ...
@@ -27,6 +27,8 @@
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 28
  */
29 29
 
30
+#include "defs.h"
31
+
30 32
 
31 33
 #include "../../hash_func.h"
32 34
 #include "../../globals.h"
... ...
@@ -166,7 +168,7 @@ error:
166 166
 }
167 167
 
168 168
 
169
-
169
+#ifndef DEPRECATE_OLD_STUFF
170 170
 char *build_uac_request(  str msg_type, str dst, str from,
171 171
 	str fromtag, int cseq, str callid, str headers, 
172 172
 	str body, int branch, 
... ...
@@ -315,6 +317,7 @@ error:
315 315
 	return buf;
316 316
 	
317 317
 }
318
+#endif
318 319
 
319 320
 
320 321
 char *build_uac_request_dlg(str* msg,           /* Method */
... ...
@@ -30,6 +30,9 @@
30 30
 #ifndef _MSGBUILDER_H
31 31
 #define _MSGBUILDER_H
32 32
 
33
+#include "defs.h"
34
+
35
+
33 36
 #define CSEQ "CSeq: "
34 37
 #define CSEQ_LEN (sizeof(CSEQ)-1)
35 38
 #define TO "To: "
... ...
@@ -30,6 +30,7 @@
30 30
  * 2003-01-19 faked lump list created in on_reply handlers
31 31
  */
32 32
 
33
+#include "defs.h"
33 34
 
34 35
 
35 36
 #include "../../hash_func.h"
... ...
@@ -30,6 +30,9 @@
30 30
 #ifndef _T_REPLY_H
31 31
 #define _T_REPLY_H
32 32
 
33
+#include "defs.h"
34
+
35
+
33 36
 #include "h_table.h"
34 37
 
35 38
 /* reply processing status */
... ...
@@ -28,6 +28,8 @@
28 28
  */
29 29
 
30 30
 
31
+#include "defs.h"
32
+
31 33
 
32 34
 #include <stdio.h>
33 35
 #include "t_stats.h"
... ...
@@ -31,6 +31,9 @@
31 31
 #ifndef _T_STATS_H
32 32
 #define _T_STATS_H
33 33
 
34
+#include "defs.h"
35
+
36
+
34 37
 #include "../../pt.h"
35 38
 
36 39
 
... ...
@@ -26,6 +26,7 @@
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 27
  */
28 28
 
29
+#include "defs.h"
29 30
 
30 31
 
31 32
 #include "../../hash_func.h"
... ...
@@ -93,6 +93,9 @@
93 93
 
94 94
 */
95 95
 
96
+#include "defs.h"
97
+
98
+
96 99
 
97 100
 #include "config.h"
98 101
 #include "h_table.h"
... ...
@@ -29,6 +29,8 @@
29 29
 #ifndef _TIMER_H
30 30
 #define _TIMER_H
31 31
 
32
+#include "defs.h"
33
+
32 34
 #include "lock.h"
33 35
 #include "t_funcs.h"
34 36
 
... ...
@@ -53,6 +53,9 @@
53 53
  */
54 54
 
55 55
 
56
+#include "defs.h"
57
+
58
+
56 59
 #include <stdio.h>
57 60
 #include <string.h>
58 61
 #include <netdb.h>
... ...
@@ -129,7 +132,9 @@ struct module_exports exports= {
129 129
 				/* not applicable from script ... */
130 130
 
131 131
 				"register_tmcb",
132
+#ifndef DEPRECATE_OLD_STUFF
132 133
 				T_UAC,
134
+#endif
133 135
 				T_UAC_DLG,
134 136
 				"load_tm",
135 137
 				"t_newdlg"
... ...
@@ -150,7 +155,9 @@ struct module_exports exports= {
150 150
 					w_t_on_negative,
151 151
 
152 152
 					(cmd_function) register_tmcb,
153
+#ifndef DEPRECATE_OLD_STUFF
153 154
 					(cmd_function) t_uac,
155
+#endif
154 156
 					(cmd_function) t_uac_dlg,
155 157
 					(cmd_function) load_tm,
156 158
 					w_t_newdlg,
... ...
@@ -170,7 +177,9 @@ struct module_exports exports= {
170 170
 				2, /* t_forward_nonack */
171 171
 				1, /* t_on_negative */
172 172
 				NO_SCRIPT /* register_tmcb */,
173
+#ifndef DEPRECATE_OLD_STUFF
173 174
 				NO_SCRIPT /* t_uac */,
175
+#endif
174 176
 				NO_SCRIPT /* t_uac_dlg */,
175 177
 				NO_SCRIPT /* load_tm */,
176 178
 				0 /* t_newdlg */
... ...
@@ -190,16 +199,21 @@ struct module_exports exports= {
190 190
 				fixup_hostport2proxy,	/* t_forward_nonack */
191 191
 				fixup_str2int,			/* t_on_negative */
192 192
 				0,						/* register_tmcb */
193
+#ifndef DEPRECATE_OLD_STUFF
193 194
 				0,						/* t_uac */
195
+#endif
194 196
 				0,                                              /* t_uac_dlg */
195 197
 				0,						/* load_tm */
196 198
 				0						/* t_newdlg */
197 199
 	
198 200
 		},
201
+#ifndef DEPRECATE_OLD_STUFF
202
+	1+
203
+#endif
199 204
 #ifdef _OBSO
200
-	16,
201
-#else
202 205
 	15,
206
+#else
207
+	14,
203 208
 #endif
204 209
 
205 210
 	/* ------------ exported variables ---------- */
... ...
@@ -212,8 +226,10 @@ struct module_exports exports= {
212 212
 		"retr_timer1p2",
213 213
 		"retr_timer1p3",
214 214
 		"retr_timer2",
215
-		"noisy_ctimer",
216
-		"uac_from"
215
+		"noisy_ctimer"
216
+#ifndef DEPRECATE_OLD_STUFF
217
+		,"uac_from"
218
+#endif
217 219
 	},
218 220
 	(modparam_t[]) { /* variable types */
219 221
 		INT_PARAM, /* fr_timer */
... ...
@@ -224,8 +240,10 @@ struct module_exports exports= {
224 224
 		INT_PARAM, /* retr_timer1p2 */
225 225
 		INT_PARAM, /* retr_timer1p3 */
226 226
 		INT_PARAM, /* retr_timer2 */
227
-		INT_PARAM, /* noisy_ctimer */
228
-		STR_PARAM, /* uac_from */
227
+		INT_PARAM /* noisy_ctimer */
228
+#ifndef DEPRECATE_OLD_STUFF
229
+		,STR_PARAM /* uac_from */
230
+#endif
229 231
 	},
230 232
 	(void *[]) { /* variable pointers */
231 233
 		&(timer_id2timeout[FR_TIMER_LIST]),
... ...
@@ -236,10 +254,15 @@ struct module_exports exports= {
236 236
 		&(timer_id2timeout[RT_T1_TO_2]),
237 237
 		&(timer_id2timeout[RT_T1_TO_3]),
238 238
 		&(timer_id2timeout[RT_T2]),
239
-		&noisy_ctimer,
240
-		&uac_from
239
+		&noisy_ctimer
240
+#ifndef DEPRECATE_OLD_STUFF
241
+		,&uac_from
242
+#endif
241 243
 	},
242
-	11,      /* Number of module paramers */
244
+#ifndef DEPRECATE_OLD_STUFF
245
+	1+
246
+#endif
247
+	10,      /* Number of module paramers */
243 248
 
244 249
 	mod_init, /* module initialization function */
245 250
 	(response_function) t_on_reply,
... ...
@@ -301,6 +324,7 @@ static int mod_init(void)
301 301
 	}
302 302
 
303 303
 
304
+#ifndef DEPRECATE_OLD_STUFF
304 305
 	if (register_fifo_cmd(fifo_uac, "t_uac", 0)<0) {
305 306
 		LOG(L_CRIT, "cannot register fifo uac\n");
306 307
 		return -1;
... ...
@@ -309,6 +333,11 @@ static int mod_init(void)
309 309
 		LOG(L_CRIT, "cannot register fifo uac\n");
310 310
 		return -1;
311 311
 	}
312
+#endif
313
+	if (register_fifo_cmd(fifo_uac_dlg, "t_uac_dlg", 0)<0) {
314
+		LOG(L_CRIT, "cannot register fifo uac\n");
315
+		return -1;
316
+	}
312 317
 	if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) {
313 318
 		LOG(L_CRIT, "cannot register hash\n");
314 319
 		return -1;
... ...
@@ -25,6 +25,8 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
+#include "defs.h"
29
+
28 30
 
29 31
 #include "tm_load.h"
30 32
 #include "uac.h"
... ...
@@ -47,10 +49,12 @@ int load_tm( struct tm_binds *tmb)
47 47
 		LOG(L_ERR, LOAD_ERROR "'t_relay' not found\n");
48 48
 		return -1;
49 49
 	}
50
+#ifndef DEPRECATE_OLD_STUFF
50 51
 	if (!(tmb->t_uac=(tuac_f)find_export(T_UAC, NO_SCRIPT)) ) {
51 52
 		LOG( L_ERR, LOAD_ERROR "'t_uac' not found\n");
52 53
 		return -1;
53 54
 	}
55
+#endif
54 56
 	if (!(tmb->t_uac_dlg=(tuacdlg_f)find_export(T_UAC_DLG, NO_SCRIPT)) ) {
55 57
 		LOG( L_ERR, LOAD_ERROR "'t_uac_dlg' not found\n");
56 58
 		return -1;
... ...
@@ -29,6 +29,9 @@
29 29
 #ifndef _TM_BIND_H
30 30
 #define _TM_BIND_H
31 31
 
32
+#include "defs.h"
33
+
34
+
32 35
 #include "../../sr_module.h"
33 36
 #include "t_hooks.h"
34 37
 #include "uac.h"
... ...
@@ -40,7 +43,9 @@
40 40
 
41 41
 #define T_RELAY_TO "t_relay_to"
42 42
 #define T_RELAY "t_relay"
43
-#define T_UAC "t_uac"
43
+#ifndef DEPRECATE_OLD_STUFF
44
+#	define T_UAC "t_uac"
45
+#endif
44 46
 #define T_UAC_DLG "t_uac_dlg"
45 47
 #define T_REPLY "t_reply"
46 48
 #define T_REPLY_UNSAFE "t_reply_unsafe"
... ...
@@ -52,7 +57,9 @@ struct tm_binds {
52 52
 	register_tmcb_f	register_tmcb;
53 53
 	cmd_function	t_relay_to;
54 54
 	cmd_function 	t_relay;
55
+#ifndef DEPRECATE_OLD_STUFF
55 56
 	tuac_f			t_uac;
57
+#endif
56 58
 	tuacdlg_f               t_uac_dlg;
57 59
 	treply_f		t_reply;
58 60
 	treply_f		t_reply_unsafe;
... ...
@@ -29,9 +29,24 @@
29 29
  * You should have received a copy of the GNU General Public License 
30 30
  * along with this program; if not, write to the Free Software 
31 31
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
+ *
33
+ * ***************************************************
34
+ *             IMPORTANT NOTE
35
+ *
36
+ *    All UACs but t_uac_dlg are being deprecated now
37
+ *    and will be removed from future versions of TM
38
+ *    module. Eliminate all dependancies on them asap.
39
+ *    For backwards compatibility (NOT RECOMMENDED)
40
+ *    turn off DEPRECATE_OLD_STUFF in defs.h. Similarly,
41
+ *    there is a new FIFO UAC.
42
+ *
43
+ * ****************************************************
32 44
  */
33 45
 
34 46
 
47
+#include "defs.h"
48
+
49
+
35 50
 #include <stdlib.h>
36 51
 #include <sys/types.h>
37 52
 #include <unistd.h>
... ...
@@ -82,9 +97,10 @@ static int callid_suffix_len;
82 82
 static int rand_len;	/* number of chars to display max rand */
83 83
 static char callid[CALLID_NR_LEN+CALLID_SUFFIX_LEN];
84 84
 
85
+#ifndef DEPRECATE_OLD_STUFF
85 86
 char *uac_from="\"UAC Account\" <sip:uac@dev.null:9>";
86
-
87 87
 str uac_from_str;
88
+#endif
88 89
 
89 90
 static char from_tag[ FROM_TAG_LEN+1 ];
90 91
 
... ...
@@ -147,8 +163,10 @@ int uac_init() {
147 147
 	MDStringArray( from_tag, src, 3 );
148 148
 	from_tag[MD5_LEN]=CID_SEP;
149 149
 
150
+#ifndef DEPRECATE_OLD_STUFF
150 151
 	uac_from_str.s = uac_from;
151 152
 	uac_from_str.len = strlen(uac_from);
153
+#endif
152 154
 
153 155
 	return 1;
154 156
 }
... ...
@@ -168,6 +186,7 @@ int uac_child_init( int rank )
168 168
 	return 1;
169 169
 }
170 170
 
171
+#ifndef DEPRECATE_OLD_STUFF
171 172
 int t_uac( str *msg_type, str *dst, 
172 173
 	str *headers, str *body, str *from, 
173 174
 	transaction_cb completion_cb, void *cbp, 
... ...
@@ -302,10 +321,59 @@ done:
302 302
 	if (cbp) shm_free(cbp);
303 303
 	return ser_error=ret;
304 304
 }
305
+#endif
305 306
 
306 307
 
307 308
 /*
308 309
  * Send a request within a dialog
310
+ * 
311
+ * Some parameters are required, some are optional (i.e., ephemeral
312
+ * or default values are created if 0 is passed as parameter). The
313
+ * optional parameters are typically used to set some header fields
314
+ * to dialog-related values (as opposed to having them set to
315
+ * ephemeral values).
316
+ *
317
+ * Required:
318
+ * - msg ..   specifies type of message, such as "OPTIONS"
319
+ * - ruri ..  specifies request URI; 
320
+ * - from ..  value of From header field (if it already includes from tag, 
321
+ *            the fromtag parameter MUST point to en empty string)
322
+ * - to ...   value of To header field (if it already includes to tag,
323
+ *            the totag parameter MUST point to an empty string)
324
+ * - totag .. to tag
325
+ * 
326
+ * Optional:
327
+ * - dst     transport destination (expressed as URI) -- if present,
328
+ *           request is physically forwarded to address indicated in it,
329
+ *           overriding the transport address in ruri; useful for use with 
330
+ *           outbound proxies or loose routers (that is where the first 
331
+ *           element of route set comes in)
332
+ * - fromtag from HF tag -- dialog-less applications do not to set it (==0),
333
+ *           in which case an ephemeral value is created; if fromtag present,
334
+ *           its appended to the From header field; it may be also present 
335
+ *           and point to an empty string -- that only makes sense if
336
+ *           application includes the tag in From and does not care to
337
+ *           separate the tag from the rest of header field
338
+ * - cid ..  callid; if 0, ephemeral value is created; transactions
339
+ *           within a dialog need to set this value to dialog's callid
340
+ * - cseq .. CSeq; if 0, default value (DEFAULT_CSEQ) is used; transactions
341
+ *           within a dialog need to set this value to current local cseq,
342
+ *           which grows continously with transactions sent
343
+ * - headers .. block of header fields that will be included in the
344
+ *           message. It MAY NOT include header fields already described
345
+ *           in other parameters (From, to, cid, cseq) or created 
346
+ *           automatically   (Content_length)   otherwise the parameter
347
+ *           would appear multiple times. It MUST include all additional
348
+ *           header fields required for a given SIP message, like Content-Type 
349
+ *           for any messages including a body or Contact for INVITEs.
350
+ * - body .. if present, body and Content-Length is appended to the 
351
+ *           SIP message; Content-Type then needs to be present inside
352
+ *           'headers' parameter
353
+ * - cb ..   callback to be called when transaction completes; if none
354
+ *           present, no callback will be called
355
+ * - cbp ..  callback parameter -- value passed to callback function
356
+ *           when called
357
+ *
309 358
  */
310 359
 int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OPTIONS etc. */
311 360
 	      str* dst,                     /* Real destination (can be different than R-URI) */
... ...
@@ -336,7 +404,18 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
336 336
 	/* make -Wall shut up */
337 337
 	ret=0;
338 338
 
339
-	proxy = uri2proxy((dst) ? (dst) : ((ruri) ? (ruri) : (to)));
339
+	/* check for invalid parameter */
340
+	if (!msg || !msg->s
341
+				|| !ruri || !ruri->s
342
+				|| !from || !from->s
343
+				|| !to || !to->s
344
+				|| !totag || !totag->s ) {
345
+		LOG(L_ERR, "ERROR: t_uac_dlg: invalud parameters\n");
346
+		ser_error = ret = E_INVALID_PARAMS;
347
+		goto done;
348
+	}
349
+
350
+	proxy = uri2proxy((dst) ? (dst) : ruri);
340 351
 	if (proxy == 0) {
341 352
 		ser_error = ret = E_BAD_ADDRESS;
342 353
 		LOG(L_ERR, "ERROR: t_uac_dlg: Can't create a dst proxy\n");
... ...
@@ -401,9 +480,9 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
401 401
 	}
402 402
 
403 403
 	buf = build_uac_request_dlg(msg, 
404
-				    (ruri) ? (ruri) : (to),
404
+				    ruri,
405 405
 				    to, 
406
-				    (from) ? (from) : (&uac_from_str), 
406
+				    from,
407 407
 				    totag,
408 408
 				    (fromtag) ? (fromtag) : (&ftag), 
409 409
 				    (cseq) ? (*cseq) : DEFAULT_CSEQ, 
... ...
@@ -431,10 +510,8 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
431 431
 	if (SEND_BUFFER(request) == -1) {
432 432
 		if (dst) {
433 433
 			tmp = *dst;
434
-		} else if (ruri) {
435
-			tmp = *ruri;
436 434
 		} else {
437
-			tmp = *to;
435
+			tmp = *ruri;
438 436
 		}
439 437
 		LOG(L_ERR, "ERROR: t_uac: UAC sending to \'%.*s\' failed\n", tmp.len, tmp.s);
440 438
 		proxy->errors++;
... ...
@@ -566,6 +643,8 @@ int fifo_uac( FILE *stream, char *response_file )
566 566
 	return 1;
567 567
 }
568 568
 
569
+#ifndef DEPRECATE_OLD_STUFF
570
+
569 571
 /* syntax:
570 572
 
571 573
 	:t_uac_from:[file] EOL
... ...
@@ -671,3 +750,225 @@ int fifo_uac_from( FILE *stream, char *response_file )
671 671
 	return 1;
672 672
 
673 673
 }
674
+
675
+#endif
676
+
677
+
678
+static void fifo_uac_error(char *reply_fifo, int code, char *msg)
679
+{
680
+	LOG(L_ERR, "ERROR: fifo_uac: %s\n", msg ); 
681
+	fifo_reply(reply_fifo, "%d fifo_uac: %s", code, msg);
682
+}
683
+
684
+/* syntax:
685
+
686
+	:t_uac_dlg:[file] EOL
687
+	method EOL
688
+	r-uri EOL 
689
+	dst EOL 				// ("." if no outbound server used)
690
+							// must be used with dialogs/lr
691
+	<EOL separated HFs>+	// From and To must be present at least;
692
+							// dialog-apps must include tag in From
693
+ 							// (an ephemeral is appended otherwise)
694
+							// and supply CSeq/CallId
695
+	.[EOL]
696
+	[body] 
697
+	.EOL
698
+
699
+*/
700
+
701
+int fifo_uac_dlg( FILE *stream, char *response_file ) 
702
+{
703
+	char method_buf[MAX_METHOD];
704
+	char ruri_buf[MAX_URI_SIZE];
705
+	char outbound_buf[MAX_URI_SIZE];
706
+	char header_buf[MAX_HEADER]; 
707
+	char body_buf[MAX_BODY]; 
708
+	str method, ruri, outbound, header, body;
709
+	struct sip_uri parsed_ruri, parsed_outbound;
710
+	str dummy_empty;
711
+	int fromtag;
712
+	int cseq;
713
+	struct cseq_body *parsed_cseq;
714
+	int i;
715
+	char c;
716
+	struct to_body *parsed_from;
717
+
718
+
719
+	char *shmem_file;
720
+	int fn_len;
721
+	int ret;
722
+	int sip_error;
723
+	char err_buf[MAX_REASON_LEN];
724
+	int err_ret;
725
+	struct sip_msg faked_msg;
726
+
727
+
728
+	if (!read_line(method_buf, MAX_METHOD, stream,&method.len)
729
+					||method.len==0) {
730
+		/* line breaking must have failed -- consume the rest
731
+		   and proceed to a new request
732
+		*/
733
+		fifo_uac_error(response_file, 400, "method expected");
734
+		return 1;
735
+	}
736
+	method.s=method_buf;
737
+	DBG("DEBUG: fifo_uac: method: %.*s\n", method.len, method.s );
738
+
739
+	if (!read_line(ruri_buf, MAX_URI_SIZE, stream, &ruri.len)
740
+					|| ruri.len==0) {
741
+		fifo_uac_error(response_file, 400, "ruri expected");
742
+		return 1;
743
+	}
744
+	if (!parse_uri(ruri_buf, ruri.len, &parsed_ruri) < 0 ) {
745
+		fifo_uac_error(response_file, 400, "ruri invalid\n");
746
+		return 1;
747
+	}
748
+	ruri.s=ruri_buf;
749
+	DBG("DEBUG: fifo_uac:  ruri: %.*s\n", ruri.len, ruri.s);
750
+
751
+	if (!read_line(outbound_buf, MAX_URI_SIZE, stream, &outbound.len)
752
+					||outbound.len==0) {
753
+		fifo_uac_error(response_file, 400, "outbound address expected");
754
+		return 1;
755
+	}
756
+	if (outbound.len==1 && outbound_buf[0]=='.' ) {
757
+		DBG("DEBUG: fifo_uac: outbound empty");
758
+		outbound.s=0; outbound.len=0;
759
+	} else if (!parse_uri(outbound_buf, outbound.len, 
760
+							&parsed_outbound) < 0 ) {
761
+		fifo_uac_error(response_file, 400, "outbound uri invalid\n");
762
+		return 1;
763
+	} else {
764
+		outbound.s=outbound_buf;
765
+		DBG("DEBUG: fifo_uac:  dst: %.*s\n", outbound.len, outbound.s);
766
+	}
767
+
768
+
769
+	/* now read and parse header fields */
770
+	if (!read_line_set(header_buf, MAX_HEADER, stream, &header.len)
771
+					|| header.len==0 ) {
772
+		fifo_uac_error(response_file, 400, "HFs expected");
773
+		return 1;
774
+	}
775
+	header.s=header_buf;
776
+	DBG("DEBUG: fifo_uac: header: %.*s\n", header.len, header.s );
777
+	/* use SIP parser to look at what is in the FIFO request */
778
+	memset(&faked_msg, 0, sizeof(struct sip_msg));
779
+	faked_msg.len=header.len; faked_msg.unparsed=header_buf;
780
+	if (parse_headers(&faked_msg, HDR_EOH, 0)==-1 ) {
781
+			fifo_uac_error(response_file, 400, "HFs unparseable");
782
+			goto error;
783
+	}
784
+
785
+	/* and eventually body */
786
+	if (!read_body(body_buf, MAX_BODY, stream, &body.len)) {
787
+		fifo_uac_error(response_file, 400, "body expected");
788
+		goto error;
789
+	}
790
+	body.s=body_buf;
791
+	DBG("DEBUG: fifo_uac: body: %.*s\n", body.len, body.s );
792
+
793
+
794
+	/* at this moment, we collected all the things we got, let's
795
+	 * verify user has not forgotten something */
796
+	if (body.len && !faked_msg.content_type) {
797
+		fifo_uac_error(response_file, 400, "Content_type missing");
798
+		goto error;
799
+	}
800
+	if (body.len && faked_msg.content_length) {
801
+		fifo_uac_error(response_file, 400, "Content_length disallowed");
802
+		goto error;
803
+	}
804
+	if (!faked_msg.to) {
805
+		fifo_uac_error(response_file, 400, "To missing");
806
+		goto error;
807
+	}
808
+	if (!faked_msg.from) {
809
+		fifo_uac_error(response_file, 400, "From missing");
810
+		goto error;
811
+	}
812
+	/* we also need to know if there is from-tag and add it otherwise */
813
+	if (parse_from_header(&faked_msg)<0) {
814
+		fifo_uac_error(response_file, 400, "Error in From");
815
+		goto error;
816
+	}
817
+	parsed_from=(struct to_body*)faked_msg.from->parsed;
818
+	fromtag=parsed_from->tag_value.s &&
819
+			parsed_from->tag_value.len;
820
+	cseq=0;
821
+	if (faked_msg.cseq && (parsed_cseq=get_cseq(&faked_msg))) {
822
+		for (i=0; i<parsed_cseq->number.len; i++ ) {
823
+			c=parsed_cseq->number.s[i];
824
+			if (c>='0' && c<'9' ) cseq=cseq*10+c-'0';
825
+			else {
826
+				fifo_uac_error(response_file, 400, "non-nummerical CSeq");
827
+				goto error;
828
+			}
829
+		}
830
+		if (parsed_cseq->method.len!=method.len 
831
+				|| memcmp(parsed_cseq->method.s, method.s, method.len)!=0) {
832
+			fifo_uac_error(response_file, 400, "CSeq method mismatch");
833
+			goto error;
834
+		}
835
+	}
836
+
837
+
838
+
839
+
840
+	DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n");
841
+	/* we got it all, initiate transaction now! */
842
+	if (response_file) {
843
+		fn_len=strlen(response_file)+1;
844
+		shmem_file=shm_malloc(fn_len);
845
+		if (shmem_file==0) {
846
+			fifo_uac_error(response_file, 500, "no shmem");
847
+			goto error;
848
+		}
849
+		memcpy(shmem_file, response_file, fn_len );
850
+	} else {
851
+		shmem_file=0;
852
+	}
853
+	/* HACK: there is yet a shortcoming -- if t_uac fails, callback
854
+	   will not be triggered and no feedback will be printed
855
+	   to shmem_file
856
+	*/
857
+	dummy_empty.s=0; dummy_empty.len=0;
858
+	ret=t_uac_dlg( &method, 
859
+		outbound.len ? &outbound: 0,
860
+		&ruri, 
861
+		&faked_msg.to->body,	/* possibly w/to-tag in it */
862
+		&faked_msg.from->body,
863
+		&dummy_empty,			/* if present, to-tag passed in to */
864
+		fromtag ? 				/* if fromtag present, ... */
865
+			&dummy_empty: 		/* ... pass it in from ... */
866
+			0,					/* use ephemeral otherwise */
867
+		cseq ? &cseq : 0,
868
+		faked_msg.callid ?
869
+			&faked_msg.callid->body:
870
+			0,
871
+		0, 						/* headers -- TBD */
872
+		&body,
873
+		fifo_callback, shmem_file );
874
+
875
+
876
+	if (ret<=0) {
877
+		err_ret=err2reason_phrase(ret, &sip_error, err_buf,
878
+				sizeof(err_buf), "FIFO/UAC" ) ;
879
+		if (err_ret > 0 )
880
+		{
881
+
882
+			fifo_uac_error(response_file, sip_error, err_buf);
883
+		} else {
884
+			fifo_uac_error(response_file, 500, "FIFO/UAC error" );
885
+#ifdef _OBSO
886
+			fifo_reply(response_file, "500 FIFO/UAC error: %d\n",
887
+				ret );
888
+#endif
889
+		}
890
+	}
891
+
892
+error:
893
+	free_sip_msg(&faked_msg);
894
+	return 1;
895
+}
... ...
@@ -30,6 +30,9 @@
30 30
 #ifndef _UAC_H
31 31
 #define _UAC_H
32 32
 
33
+#include "defs.h"
34
+
35
+
33 36
 #include <stdio.h>
34 37
 #include "config.h"
35 38
 #include "t_dlg.h"
... ...
@@ -111,7 +114,12 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
111 111
 	      void* cbp                     /* Callback pointer */
112 112
 	      );
113 113
 
114
-
114
+#ifndef DEPRECATE_OLD_STUFF
115 115
 int fifo_uac( FILE *stream, char *response_file );
116 116
 int fifo_uac_from( FILE *stream, char *response_file );
117 117
 #endif
118
+
119
+int fifo_uac_dlg( FILE *stream, char *response_file );
120
+
121
+
122
+#endif
... ...
@@ -32,6 +32,9 @@
32 32
 #ifndef _TM_UT_H
33 33
 #define _TM_UT_H
34 34
 
35
+#include "defs.h"
36
+
37
+
35 38
 #include "../../dprint.h"
36 39
 #include "../../error.h"
37 40
 #include "../../ut.h"