... | ... |
@@ -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 |
+ * **************************************************** |
36 | 38 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,35 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * |
|
5 |
+ * Copyright (C) 2001-2003 Fhg Fokus |
|
6 |
+ * |
|
7 |
+ * This file is part of ser, a free SIP server. |
|
8 |
+ * |
|
9 |
+ * ser is free software; you can redistribute it and/or modify |
|
10 |
+ * it under the terms of the GNU General Public License as published by |
|
11 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
12 |
+ * (at your option) any later version |
|
13 |
+ * |
|
14 |
+ * For a license to use the ser software under conditions |
|
15 |
+ * other than those described here, or to purchase support for this |
|
16 |
+ * software, please contact iptel.org by e-mail at the following addresses: |
|
17 |
+ * info@iptel.org |
|
18 |
+ * |
|
19 |
+ * ser is distributed in the hope that it will be useful, |
|
20 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
+ * GNU General Public License for more details. |
|
23 |
+ * |
|
24 |
+ * You should have received a copy of the GNU General Public License |
|
25 |
+ * along with this program; if not, write to the Free Software |
|
26 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
27 |
+ */ |
|
28 |
+ |
|
29 |
+ |
|
30 |
+#ifndef _TM_DEFS_H |
|
31 |
+#define _TM_DEFS_H |
|
32 |
+ |
|
33 |
+#undef DEPRECATE_OLD_STUFF |
|
34 |
+ |
|
35 |
+#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 |
... | ... |
@@ -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 | 168 |
} |
167 | 169 |
|
168 | 170 |
|
169 |
- |
|
171 |
+#ifndef DEPRECATE_OLD_STUFF |
|
170 | 172 |
char *build_uac_request( str msg_type, str dst, str from, |
171 | 173 |
str fromtag, int cseq, str callid, str headers, |
172 | 174 |
str body, int branch, |
... | ... |
@@ -315,6 +317,7 @@ error: |
315 | 317 |
return buf; |
316 | 318 |
|
317 | 319 |
} |
320 |
+#endif |
|
318 | 321 |
|
319 | 322 |
|
320 | 323 |
char *build_uac_request_dlg(str* msg, /* Method */ |
... | ... |
@@ -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 | 132 |
/* not applicable from script ... */ |
130 | 133 |
|
131 | 134 |
"register_tmcb", |
135 |
+#ifndef DEPRECATE_OLD_STUFF |
|
132 | 136 |
T_UAC, |
137 |
+#endif |
|
133 | 138 |
T_UAC_DLG, |
134 | 139 |
"load_tm", |
135 | 140 |
"t_newdlg" |
... | ... |
@@ -150,7 +155,9 @@ struct module_exports exports= { |
150 | 155 |
w_t_on_negative, |
151 | 156 |
|
152 | 157 |
(cmd_function) register_tmcb, |
158 |
+#ifndef DEPRECATE_OLD_STUFF |
|
153 | 159 |
(cmd_function) t_uac, |
160 |
+#endif |
|
154 | 161 |
(cmd_function) t_uac_dlg, |
155 | 162 |
(cmd_function) load_tm, |
156 | 163 |
w_t_newdlg, |
... | ... |
@@ -170,7 +177,9 @@ struct module_exports exports= { |
170 | 177 |
2, /* t_forward_nonack */ |
171 | 178 |
1, /* t_on_negative */ |
172 | 179 |
NO_SCRIPT /* register_tmcb */, |
180 |
+#ifndef DEPRECATE_OLD_STUFF |
|
173 | 181 |
NO_SCRIPT /* t_uac */, |
182 |
+#endif |
|
174 | 183 |
NO_SCRIPT /* t_uac_dlg */, |
175 | 184 |
NO_SCRIPT /* load_tm */, |
176 | 185 |
0 /* t_newdlg */ |
... | ... |
@@ -190,16 +199,21 @@ struct module_exports exports= { |
190 | 199 |
fixup_hostport2proxy, /* t_forward_nonack */ |
191 | 200 |
fixup_str2int, /* t_on_negative */ |
192 | 201 |
0, /* register_tmcb */ |
202 |
+#ifndef DEPRECATE_OLD_STUFF |
|
193 | 203 |
0, /* t_uac */ |
204 |
+#endif |
|
194 | 205 |
0, /* t_uac_dlg */ |
195 | 206 |
0, /* load_tm */ |
196 | 207 |
0 /* t_newdlg */ |
197 | 208 |
|
198 | 209 |
}, |
210 |
+#ifndef DEPRECATE_OLD_STUFF |
|
211 |
+ 1+ |
|
212 |
+#endif |
|
199 | 213 |
#ifdef _OBSO |
200 |
- 16, |
|
201 |
-#else |
|
202 | 214 |
15, |
215 |
+#else |
|
216 |
+ 14, |
|
203 | 217 |
#endif |
204 | 218 |
|
205 | 219 |
/* ------------ exported variables ---------- */ |
... | ... |
@@ -212,8 +226,10 @@ struct module_exports exports= { |
212 | 226 |
"retr_timer1p2", |
213 | 227 |
"retr_timer1p3", |
214 | 228 |
"retr_timer2", |
215 |
- "noisy_ctimer", |
|
216 |
- "uac_from" |
|
229 |
+ "noisy_ctimer" |
|
230 |
+#ifndef DEPRECATE_OLD_STUFF |
|
231 |
+ ,"uac_from" |
|
232 |
+#endif |
|
217 | 233 |
}, |
218 | 234 |
(modparam_t[]) { /* variable types */ |
219 | 235 |
INT_PARAM, /* fr_timer */ |
... | ... |
@@ -224,8 +240,10 @@ struct module_exports exports= { |
224 | 240 |
INT_PARAM, /* retr_timer1p2 */ |
225 | 241 |
INT_PARAM, /* retr_timer1p3 */ |
226 | 242 |
INT_PARAM, /* retr_timer2 */ |
227 |
- INT_PARAM, /* noisy_ctimer */ |
|
228 |
- STR_PARAM, /* uac_from */ |
|
243 |
+ INT_PARAM /* noisy_ctimer */ |
|
244 |
+#ifndef DEPRECATE_OLD_STUFF |
|
245 |
+ ,STR_PARAM /* uac_from */ |
|
246 |
+#endif |
|
229 | 247 |
}, |
230 | 248 |
(void *[]) { /* variable pointers */ |
231 | 249 |
&(timer_id2timeout[FR_TIMER_LIST]), |
... | ... |
@@ -236,10 +254,15 @@ struct module_exports exports= { |
236 | 254 |
&(timer_id2timeout[RT_T1_TO_2]), |
237 | 255 |
&(timer_id2timeout[RT_T1_TO_3]), |
238 | 256 |
&(timer_id2timeout[RT_T2]), |
239 |
- &noisy_ctimer, |
|
240 |
- &uac_from |
|
257 |
+ &noisy_ctimer |
|
258 |
+#ifndef DEPRECATE_OLD_STUFF |
|
259 |
+ ,&uac_from |
|
260 |
+#endif |
|
241 | 261 |
}, |
242 |
- 11, /* Number of module paramers */ |
|
262 |
+#ifndef DEPRECATE_OLD_STUFF |
|
263 |
+ 1+ |
|
264 |
+#endif |
|
265 |
+ 10, /* Number of module paramers */ |
|
243 | 266 |
|
244 | 267 |
mod_init, /* module initialization function */ |
245 | 268 |
(response_function) t_on_reply, |
... | ... |
@@ -301,6 +324,7 @@ static int mod_init(void) |
301 | 324 |
} |
302 | 325 |
|
303 | 326 |
|
327 |
+#ifndef DEPRECATE_OLD_STUFF |
|
304 | 328 |
if (register_fifo_cmd(fifo_uac, "t_uac", 0)<0) { |
305 | 329 |
LOG(L_CRIT, "cannot register fifo uac\n"); |
306 | 330 |
return -1; |
... | ... |
@@ -309,6 +333,11 @@ static int mod_init(void) |
309 | 333 |
LOG(L_CRIT, "cannot register fifo uac\n"); |
310 | 334 |
return -1; |
311 | 335 |
} |
336 |
+#endif |
|
337 |
+ if (register_fifo_cmd(fifo_uac_dlg, "t_uac_dlg", 0)<0) { |
|
338 |
+ LOG(L_CRIT, "cannot register fifo uac\n"); |
|
339 |
+ return -1; |
|
340 |
+ } |
|
312 | 341 |
if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) { |
313 | 342 |
LOG(L_CRIT, "cannot register hash\n"); |
314 | 343 |
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 | 49 |
LOG(L_ERR, LOAD_ERROR "'t_relay' not found\n"); |
48 | 50 |
return -1; |
49 | 51 |
} |
52 |
+#ifndef DEPRECATE_OLD_STUFF |
|
50 | 53 |
if (!(tmb->t_uac=(tuac_f)find_export(T_UAC, NO_SCRIPT)) ) { |
51 | 54 |
LOG( L_ERR, LOAD_ERROR "'t_uac' not found\n"); |
52 | 55 |
return -1; |
53 | 56 |
} |
57 |
+#endif |
|
54 | 58 |
if (!(tmb->t_uac_dlg=(tuacdlg_f)find_export(T_UAC_DLG, NO_SCRIPT)) ) { |
55 | 59 |
LOG( L_ERR, LOAD_ERROR "'t_uac_dlg' not found\n"); |
56 | 60 |
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 | 43 |
|
41 | 44 |
#define T_RELAY_TO "t_relay_to" |
42 | 45 |
#define T_RELAY "t_relay" |
43 |
-#define T_UAC "t_uac" |
|
46 |
+#ifndef DEPRECATE_OLD_STUFF |
|
47 |
+# define T_UAC "t_uac" |
|
48 |
+#endif |
|
44 | 49 |
#define T_UAC_DLG "t_uac_dlg" |
45 | 50 |
#define T_REPLY "t_reply" |
46 | 51 |
#define T_REPLY_UNSAFE "t_reply_unsafe" |
... | ... |
@@ -52,7 +57,9 @@ struct tm_binds { |
52 | 57 |
register_tmcb_f register_tmcb; |
53 | 58 |
cmd_function t_relay_to; |
54 | 59 |
cmd_function t_relay; |
60 |
+#ifndef DEPRECATE_OLD_STUFF |
|
55 | 61 |
tuac_f t_uac; |
62 |
+#endif |
|
56 | 63 |
tuacdlg_f t_uac_dlg; |
57 | 64 |
treply_f t_reply; |
58 | 65 |
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 | 97 |
static int rand_len; /* number of chars to display max rand */ |
83 | 98 |
static char callid[CALLID_NR_LEN+CALLID_SUFFIX_LEN]; |
84 | 99 |
|
100 |
+#ifndef DEPRECATE_OLD_STUFF |
|
85 | 101 |
char *uac_from="\"UAC Account\" <sip:uac@dev.null:9>"; |
86 |
- |
|
87 | 102 |
str uac_from_str; |
103 |
+#endif |
|
88 | 104 |
|
89 | 105 |
static char from_tag[ FROM_TAG_LEN+1 ]; |
90 | 106 |
|
... | ... |
@@ -147,8 +163,10 @@ int uac_init() { |
147 | 163 |
MDStringArray( from_tag, src, 3 ); |
148 | 164 |
from_tag[MD5_LEN]=CID_SEP; |
149 | 165 |
|
166 |
+#ifndef DEPRECATE_OLD_STUFF |
|
150 | 167 |
uac_from_str.s = uac_from; |
151 | 168 |
uac_from_str.len = strlen(uac_from); |
169 |
+#endif |
|
152 | 170 |
|
153 | 171 |
return 1; |
154 | 172 |
} |
... | ... |
@@ -168,6 +186,7 @@ int uac_child_init( int rank ) |
168 | 186 |
return 1; |
169 | 187 |
} |
170 | 188 |
|
189 |
+#ifndef DEPRECATE_OLD_STUFF |
|
171 | 190 |
int t_uac( str *msg_type, str *dst, |
172 | 191 |
str *headers, str *body, str *from, |
173 | 192 |
transaction_cb completion_cb, void *cbp, |
... | ... |
@@ -302,10 +321,59 @@ done: |
302 | 321 |
if (cbp) shm_free(cbp); |
303 | 322 |
return ser_error=ret; |
304 | 323 |
} |
324 |
+#endif |
|
305 | 325 |
|
306 | 326 |
|
307 | 327 |
/* |
308 | 328 |
* Send a request within a dialog |
329 |
+ * |
|
330 |
+ * Some parameters are required, some are optional (i.e., ephemeral |
|
331 |
+ * or default values are created if 0 is passed as parameter). The |
|
332 |
+ * optional parameters are typically used to set some header fields |
|
333 |
+ * to dialog-related values (as opposed to having them set to |
|
334 |
+ * ephemeral values). |
|
335 |
+ * |
|
336 |
+ * Required: |
|
337 |
+ * - msg .. specifies type of message, such as "OPTIONS" |
|
338 |
+ * - ruri .. specifies request URI; |
|
339 |
+ * - from .. value of From header field (if it already includes from tag, |
|
340 |
+ * the fromtag parameter MUST point to en empty string) |
|
341 |
+ * - to ... value of To header field (if it already includes to tag, |
|
342 |
+ * the totag parameter MUST point to an empty string) |
|
343 |
+ * - totag .. to tag |
|
344 |
+ * |
|
345 |
+ * Optional: |
|
346 |
+ * - dst transport destination (expressed as URI) -- if present, |
|
347 |
+ * request is physically forwarded to address indicated in it, |
|
348 |
+ * overriding the transport address in ruri; useful for use with |
|
349 |
+ * outbound proxies or loose routers (that is where the first |
|
350 |
+ * element of route set comes in) |
|
351 |
+ * - fromtag from HF tag -- dialog-less applications do not to set it (==0), |
|
352 |
+ * in which case an ephemeral value is created; if fromtag present, |
|
353 |
+ * its appended to the From header field; it may be also present |
|
354 |
+ * and point to an empty string -- that only makes sense if |
|
355 |
+ * application includes the tag in From and does not care to |
|
356 |
+ * separate the tag from the rest of header field |
|
357 |
+ * - cid .. callid; if 0, ephemeral value is created; transactions |
|
358 |
+ * within a dialog need to set this value to dialog's callid |
|
359 |
+ * - cseq .. CSeq; if 0, default value (DEFAULT_CSEQ) is used; transactions |
|
360 |
+ * within a dialog need to set this value to current local cseq, |
|
361 |
+ * which grows continously with transactions sent |
|
362 |
+ * - headers .. block of header fields that will be included in the |
|
363 |
+ * message. It MAY NOT include header fields already described |
|
364 |
+ * in other parameters (From, to, cid, cseq) or created |
|
365 |
+ * automatically (Content_length) otherwise the parameter |
|
366 |
+ * would appear multiple times. It MUST include all additional |
|
367 |
+ * header fields required for a given SIP message, like Content-Type |
|
368 |
+ * for any messages including a body or Contact for INVITEs. |
|
369 |
+ * - body .. if present, body and Content-Length is appended to the |
|
370 |
+ * SIP message; Content-Type then needs to be present inside |
|
371 |
+ * 'headers' parameter |
|
372 |
+ * - cb .. callback to be called when transaction completes; if none |
|
373 |
+ * present, no callback will be called |
|
374 |
+ * - cbp .. callback parameter -- value passed to callback function |
|
375 |
+ * when called |
|
376 |
+ * |
|
309 | 377 |
*/ |
310 | 378 |
int t_uac_dlg(str* msg, /* Type of the message - MESSAGE, OPTIONS etc. */ |
311 | 379 |
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 | 404 |
/* make -Wall shut up */ |
337 | 405 |
ret=0; |
338 | 406 |
|
339 |
- proxy = uri2proxy((dst) ? (dst) : ((ruri) ? (ruri) : (to))); |
|
407 |
+ /* check for invalid parameter */ |
|
408 |
+ if (!msg || !msg->s |
|
409 |
+ || !ruri || !ruri->s |
|
410 |
+ || !from || !from->s |
|
411 |
+ || !to || !to->s |
|
412 |
+ || !totag || !totag->s ) { |
|
413 |
+ LOG(L_ERR, "ERROR: t_uac_dlg: invalud parameters\n"); |
|
414 |
+ ser_error = ret = E_INVALID_PARAMS; |
|
415 |
+ goto done; |
|
416 |
+ } |
|
417 |
+ |
|
418 |
+ proxy = uri2proxy((dst) ? (dst) : ruri); |
|
340 | 419 |
if (proxy == 0) { |
341 | 420 |
ser_error = ret = E_BAD_ADDRESS; |
342 | 421 |
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 | 480 |
} |
402 | 481 |
|
403 | 482 |
buf = build_uac_request_dlg(msg, |
404 |
- (ruri) ? (ruri) : (to), |
|
483 |
+ ruri, |
|
405 | 484 |
to, |
406 |
- (from) ? (from) : (&uac_from_str), |
|
485 |
+ from, |
|
407 | 486 |
totag, |
408 | 487 |
(fromtag) ? (fromtag) : (&ftag), |
409 | 488 |
(cseq) ? (*cseq) : DEFAULT_CSEQ, |
... | ... |
@@ -431,10 +510,8 @@ int t_uac_dlg(str* msg, /* Type of the message - MESSAGE, OP |
431 | 510 |
if (SEND_BUFFER(request) == -1) { |
432 | 511 |
if (dst) { |
433 | 512 |
tmp = *dst; |
434 |
- } else if (ruri) { |
|
435 |
- tmp = *ruri; |
|
436 | 513 |
} else { |
437 |
- tmp = *to; |
|
514 |
+ tmp = *ruri; |
|
438 | 515 |
} |
439 | 516 |
LOG(L_ERR, "ERROR: t_uac: UAC sending to \'%.*s\' failed\n", tmp.len, tmp.s); |
440 | 517 |
proxy->errors++; |
... | ... |
@@ -566,6 +643,8 @@ int fifo_uac( FILE *stream, char *response_file ) |
566 | 643 |
return 1; |
567 | 644 |
} |
568 | 645 |
|
646 |
+#ifndef DEPRECATE_OLD_STUFF |
|
647 |
+ |
|
569 | 648 |
/* syntax: |
570 | 649 |
|
571 | 650 |
:t_uac_from:[file] EOL |
... | ... |
@@ -671,3 +750,225 @@ int fifo_uac_from( FILE *stream, char *response_file ) |
671 | 750 |
return 1; |
672 | 751 |
|
673 | 752 |
} |
753 |
+ |
|
754 |
+#endif |
|
755 |
+ |
|
756 |
+ |
|
757 |
+static void fifo_uac_error(char *reply_fifo, int code, char *msg) |
|
758 |
+{ |
|
759 |
+ LOG(L_ERR, "ERROR: fifo_uac: %s\n", msg ); |
|
760 |
+ fifo_reply(reply_fifo, "%d fifo_uac: %s", code, msg); |
|
761 |
+} |
|
762 |
+ |
|
763 |
+/* syntax: |
|
764 |
+ |
|
765 |
+ :t_uac_dlg:[file] EOL |
|
766 |
+ method EOL |
|
767 |
+ r-uri EOL |
|
768 |
+ dst EOL // ("." if no outbound server used) |
|
769 |
+ // must be used with dialogs/lr |
|
770 |
+ <EOL separated HFs>+ // From and To must be present at least; |
|
771 |
+ // dialog-apps must include tag in From |
|
772 |
+ // (an ephemeral is appended otherwise) |
|
773 |
+ // and supply CSeq/CallId |
|
774 |
+ .[EOL] |
|
775 |
+ [body] |
|
776 |
+ .EOL |
|
777 |
+ |
|
778 |
+*/ |
|
779 |
+ |
|
780 |
+int fifo_uac_dlg( FILE *stream, char *response_file ) |
|
781 |
+{ |
|
782 |
+ char method_buf[MAX_METHOD]; |
|
783 |
+ char ruri_buf[MAX_URI_SIZE]; |
|
784 |
+ char outbound_buf[MAX_URI_SIZE]; |
|
785 |
+ char header_buf[MAX_HEADER]; |
|
786 |
+ char body_buf[MAX_BODY]; |
|
787 |
+ str method, ruri, outbound, header, body; |
|
788 |
+ struct sip_uri parsed_ruri, parsed_outbound; |
|
789 |
+ str dummy_empty; |
|
790 |
+ int fromtag; |
|
791 |
+ int cseq; |
|
792 |
+ struct cseq_body *parsed_cseq; |
|
793 |
+ int i; |
|
794 |
+ char c; |
|
795 |
+ struct to_body *parsed_from; |
|
796 |
+ |
|
797 |
+ |
|
798 |
+ char *shmem_file; |
|
799 |
+ int fn_len; |
|
800 |
+ int ret; |
|
801 |
+ int sip_error; |
|
802 |
+ char err_buf[MAX_REASON_LEN]; |
|
803 |
+ int err_ret; |
|
804 |
+ struct sip_msg faked_msg; |
|
805 |
+ |
|
806 |
+ |
|
807 |
+ if (!read_line(method_buf, MAX_METHOD, stream,&method.len) |
|
808 |
+ ||method.len==0) { |
|
809 |
+ /* line breaking must have failed -- consume the rest |
|
810 |
+ and proceed to a new request |
|
811 |
+ */ |
|
812 |
+ fifo_uac_error(response_file, 400, "method expected"); |
|
813 |
+ return 1; |
|
814 |
+ } |
|
815 |
+ method.s=method_buf; |
|
816 |
+ DBG("DEBUG: fifo_uac: method: %.*s\n", method.len, method.s ); |
|
817 |
+ |
|
818 |
+ if (!read_line(ruri_buf, MAX_URI_SIZE, stream, &ruri.len) |
|
819 |
+ || ruri.len==0) { |
|
820 |
+ fifo_uac_error(response_file, 400, "ruri expected"); |
|
821 |
+ return 1; |
|
822 |
+ } |
|
823 |
+ if (!parse_uri(ruri_buf, ruri.len, &parsed_ruri) < 0 ) { |
|
824 |
+ fifo_uac_error(response_file, 400, "ruri invalid\n"); |
|
825 |
+ return 1; |
|
826 |
+ } |
|
827 |
+ ruri.s=ruri_buf; |
|
828 |
+ DBG("DEBUG: fifo_uac: ruri: %.*s\n", ruri.len, ruri.s); |
|
829 |
+ |
|
830 |
+ if (!read_line(outbound_buf, MAX_URI_SIZE, stream, &outbound.len) |
|
831 |
+ ||outbound.len==0) { |
|
832 |
+ fifo_uac_error(response_file, 400, "outbound address expected"); |
|
833 |
+ return 1; |
|
834 |
+ } |
|
835 |
+ if (outbound.len==1 && outbound_buf[0]=='.' ) { |
|
836 |
+ DBG("DEBUG: fifo_uac: outbound empty"); |
|
837 |
+ outbound.s=0; outbound.len=0; |
|
838 |
+ } else if (!parse_uri(outbound_buf, outbound.len, |
|
839 |
+ &parsed_outbound) < 0 ) { |
|
840 |
+ fifo_uac_error(response_file, 400, "outbound uri invalid\n"); |
|
841 |
+ return 1; |
|
842 |
+ } else { |
|
843 |
+ outbound.s=outbound_buf; |
|
844 |
+ DBG("DEBUG: fifo_uac: dst: %.*s\n", outbound.len, outbound.s); |
|
845 |
+ } |
|
846 |
+ |
|
847 |
+ |
|
848 |
+ /* now read and parse header fields */ |
|
849 |
+ if (!read_line_set(header_buf, MAX_HEADER, stream, &header.len) |
|
850 |
+ || header.len==0 ) { |
|
851 |
+ fifo_uac_error(response_file, 400, "HFs expected"); |
|
852 |
+ return 1; |
|
853 |
+ } |
|
854 |
+ header.s=header_buf; |
|
855 |
+ DBG("DEBUG: fifo_uac: header: %.*s\n", header.len, header.s ); |
|
856 |
+ /* use SIP parser to look at what is in the FIFO request */ |
|
857 |
+ memset(&faked_msg, 0, sizeof(struct sip_msg)); |
|
858 |
+ faked_msg.len=header.len; faked_msg.unparsed=header_buf; |
|
859 |
+ if (parse_headers(&faked_msg, HDR_EOH, 0)==-1 ) { |
|
860 |
+ fifo_uac_error(response_file, 400, "HFs unparseable"); |
|
861 |
+ goto error; |
|
862 |
+ } |
|
863 |
+ |
|
864 |
+ /* and eventually body */ |
|
865 |
+ if (!read_body(body_buf, MAX_BODY, stream, &body.len)) { |
|
866 |
+ fifo_uac_error(response_file, 400, "body expected"); |
|
867 |
+ goto error; |
|
868 |
+ } |
|
869 |
+ body.s=body_buf; |
|
870 |
+ DBG("DEBUG: fifo_uac: body: %.*s\n", body.len, body.s ); |
|
871 |
+ |
|
872 |
+ |
|
873 |
+ /* at this moment, we collected all the things we got, let's |
|
874 |
+ * verify user has not forgotten something */ |
|
875 |
+ if (body.len && !faked_msg.content_type) { |
|
876 |
+ fifo_uac_error(response_file, 400, "Content_type missing"); |
|
877 |
+ goto error; |
|
878 |
+ } |
|
879 |
+ if (body.len && faked_msg.content_length) { |
|
880 |
+ fifo_uac_error(response_file, 400, "Content_length disallowed"); |
|
881 |
+ goto error; |
|
882 |
+ } |
|
883 |
+ if (!faked_msg.to) { |
|
884 |
+ fifo_uac_error(response_file, 400, "To missing"); |
|
885 |
+ goto error; |
|
886 |
+ } |
|
887 |
+ if (!faked_msg.from) { |
|
888 |
+ fifo_uac_error(response_file, 400, "From missing"); |
|
889 |
+ goto error; |
|
890 |
+ } |
|
891 |
+ /* we also need to know if there is from-tag and add it otherwise */ |
|
892 |
+ if (parse_from_header(&faked_msg)<0) { |
|
893 |
+ fifo_uac_error(response_file, 400, "Error in From"); |
|
894 |
+ goto error; |
|
895 |
+ } |
|
896 |
+ parsed_from=(struct to_body*)faked_msg.from->parsed; |
|
897 |
+ fromtag=parsed_from->tag_value.s && |
|
898 |
+ parsed_from->tag_value.len; |
|
899 |
+ cseq=0; |
|
900 |
+ if (faked_msg.cseq && (parsed_cseq=get_cseq(&faked_msg))) { |
|
901 |
+ for (i=0; i<parsed_cseq->number.len; i++ ) { |
|
902 |
+ c=parsed_cseq->number.s[i]; |
|
903 |
+ if (c>='0' && c<'9' ) cseq=cseq*10+c-'0'; |
|
904 |
+ else { |
|
905 |
+ fifo_uac_error(response_file, 400, "non-nummerical CSeq"); |
|
906 |
+ goto error; |
|
907 |
+ } |
|
908 |
+ } |
|
909 |
+ if (parsed_cseq->method.len!=method.len |
|
910 |
+ || memcmp(parsed_cseq->method.s, method.s, method.len)!=0) { |
|
911 |
+ fifo_uac_error(response_file, 400, "CSeq method mismatch"); |
|
912 |
+ goto error; |
|
913 |
+ } |
|
914 |
+ } |
|
915 |
+ |
|
916 |
+ |
|
917 |
+ |
|
918 |
+ |
|
919 |
+ DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n"); |
|
920 |
+ /* we got it all, initiate transaction now! */ |
|
921 |
+ if (response_file) { |
|
922 |
+ fn_len=strlen(response_file)+1; |
|
923 |
+ shmem_file=shm_malloc(fn_len); |
|
924 |
+ if (shmem_file==0) { |
|
925 |
+ fifo_uac_error(response_file, 500, "no shmem"); |
|
926 |
+ goto error; |
|
927 |
+ } |
|
928 |
+ memcpy(shmem_file, response_file, fn_len ); |
|
929 |
+ } else { |
|
930 |
+ shmem_file=0; |
|
931 |
+ } |
|
932 |
+ /* HACK: there is yet a shortcoming -- if t_uac fails, callback |
|
933 |
+ will not be triggered and no feedback will be printed |
|
934 |
+ to shmem_file |
|
935 |
+ */ |
|
936 |
+ dummy_empty.s=0; dummy_empty.len=0; |
|
937 |
+ ret=t_uac_dlg( &method, |
|
938 |
+ outbound.len ? &outbound: 0, |
|
939 |
+ &ruri, |
|
940 |
+ &faked_msg.to->body, /* possibly w/to-tag in it */ |
|
941 |
+ &faked_msg.from->body, |
|
942 |
+ &dummy_empty, /* if present, to-tag passed in to */ |
|
943 |
+ fromtag ? /* if fromtag present, ... */ |
|
944 |
+ &dummy_empty: /* ... pass it in from ... */ |
|
945 |
+ 0, /* use ephemeral otherwise */ |
|
946 |
+ cseq ? &cseq : 0, |
|
947 |
+ faked_msg.callid ? |
|
948 |
+ &faked_msg.callid->body: |
|
949 |
+ 0, |
|
950 |
+ 0, /* headers -- TBD */ |
|
951 |
+ &body, |
|
952 |
+ fifo_callback, shmem_file ); |
|
953 |
+ |
|
954 |
+ |
|
955 |
+ if (ret<=0) { |
|
956 |
+ err_ret=err2reason_phrase(ret, &sip_error, err_buf, |
|
957 |
+ sizeof(err_buf), "FIFO/UAC" ) ; |
|
958 |
+ if (err_ret > 0 ) |
|
959 |
+ { |
|
960 |
+ |
|
961 |
+ fifo_uac_error(response_file, sip_error, err_buf); |
|
962 |
+ } else { |
|
963 |
+ fifo_uac_error(response_file, 500, "FIFO/UAC error" ); |
|
964 |
+#ifdef _OBSO |
|
965 |
+ fifo_reply(response_file, "500 FIFO/UAC error: %d\n", |
|
966 |
+ ret ); |
|
967 |
+#endif |
|
968 |
+ } |
|
969 |
+ } |
|
970 |
+ |
|
971 |
+error: |
|
972 |
+ free_sip_msg(&faked_msg); |
|
973 |
+ return 1; |
|
974 |
+} |
... | ... |
@@ -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 | 114 |
void* cbp /* Callback pointer */ |
112 | 115 |
); |
113 | 116 |
|
114 |
- |
|
117 |
+#ifndef DEPRECATE_OLD_STUFF |
|
115 | 118 |
int fifo_uac( FILE *stream, char *response_file ); |
116 | 119 |
int fifo_uac_from( FILE *stream, char *response_file ); |
117 | 120 |
#endif |
121 |
+ |
|
122 |
+int fifo_uac_dlg( FILE *stream, char *response_file ); |
|
123 |
+ |
|
124 |
+ |
|
125 |
+#endif |