Просмотр исходного кода

added features:
- possibility of automatical tag generation when creating dialog
- exported uac_t function (will be used from dialog module)
- added parameter next_hop to t_request for sending request through "proxy"

Vaclav Kubart 19 лет назад
Родитель
Сommit
460d624bc3
6 измененных файлов с 32 добавлено и 5 удалено
  1. 19 1
      modules/tm/dlg.c
  2. 1 0
      modules/tm/tm.c
  3. 4 0
      modules/tm/tm_load.c
  4. 1 0
      modules/tm/tm_load.h
  5. 4 1
      modules/tm/uac.c
  6. 3 3
      modules/tm/uac.h

+ 19 - 1
modules/tm/dlg.c

@@ -45,6 +45,9 @@
 #include "t_reply.h"
 #include "../../parser/parser_f.h"
 
+/* next added to allow automatical tag generation */
+#include "callid.h"
+#include "uac.h"
 
 #define NORMAL_ORDER 0  /* Create route set in normal order - UAS */
 #define REVERSE_ORDER 1 /* Create route set in reverse order - UAC */
@@ -130,7 +133,10 @@ static inline int calculate_hooks(dlg_t* _d)
 			_d->hooks.request_uri = &_d->route_set->nameaddr.uri;
 			_d->hooks.next_hop = _d->hooks.request_uri;
 			_d->hooks.first_route = _d->route_set->next;
-			_d->hooks.last_route = &_d->rem_target;
+			if (_d->rem_target.len > 0) 
+				_d->hooks.last_route = &_d->rem_target;
+			else 
+				_d->hooks.last_route = NULL; /* ? */
 		}
 	} else {
 		if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target;
@@ -169,6 +175,18 @@ int w_calculate_hooks(dlg_t* _d)
 int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _ruri, dlg_t** _d)
 {
 	dlg_t* res;
+	str generated_cid;
+	str generated_ltag;
+
+	if (!_cid) { /* if not given, compute new one */
+		generate_callid(&generated_cid);
+		_cid = &generated_cid;
+	}
+	if (_cid && (!_ltag)) { /* if not given, compute new one */
+		generate_fromtag(&generated_ltag, _cid);
+		_ltag = &generated_ltag;
+	}
+	if (_lseq == 0) _lseq = DEFAULT_CSEQ;
 
 	if (!_cid || !_ltag || !_luri || !_ruri || !_d) {
 		LOG(L_ERR, "new_dlg_uac(): Invalid parameter value\n");

+ 1 - 0
modules/tm/tm.c

@@ -262,6 +262,7 @@ static cmd_export_t cmds[]={
 	{"print_dlg",          (cmd_function)print_dlg,         NO_SCRIPT,   0, 0},
 	{T_GETT,               (cmd_function)get_t,             NO_SCRIPT,   0, 0},
 	{"calculate_hooks",    (cmd_function)w_calculate_hooks, NO_SCRIPT,   0, 0},
+	{"t_uac",              (cmd_function)t_uac,             NO_SCRIPT,   0, 0},
 	{0,0,0,0,0}
 };
 

+ 4 - 0
modules/tm/tm_load.c

@@ -152,6 +152,10 @@ int load_tm( struct tm_binds *tmb)
 		LOG( L_ERR, LOAD_ERROR "' calculate_hooks ' not found\n");
 		return -1;
 	}
+	if (!(tmb->t_uac=(t_uac_t)find_export("t_uac", NO_SCRIPT, 0)) ) {
+		LOG( L_ERR, LOAD_ERROR "'t_uac' not found\n");
+		return -1;
+	}
 
 	tmb->route_mode = &rmode;
 	return 1;

+ 1 - 0
modules/tm/tm_load.h

@@ -99,6 +99,7 @@ struct tm_binds {
 	print_dlg_f        print_dlg;
 	tgett_f            t_gett;
 	calculate_hooks_f  calculate_hooks;
+	t_uac_t            t_uac;
 	enum route_mode*   route_mode;
 };
 

+ 4 - 1
modules/tm/uac.c

@@ -332,7 +332,7 @@ int req_outside(str* method, str* to, str* from, str* headers, str* body, dlg_t*
 /*
  * Send a transactional request, no dialogs involved
  */
-int request(str* m, str* ruri, str* to, str* from, str* h, str* b, transaction_cb c, void* cp)
+int request(str* m, str* ruri, str* to, str* from, str* h, str* b, str *next_hop, transaction_cb c, void* cp)
 {
 	str callid, fromtag;
 	dlg_t* dialog;
@@ -355,6 +355,9 @@ int request(str* m, str* ruri, str* to, str* from, str* h, str* b, transaction_c
 	}
 	w_calculate_hooks(dialog);
 
+	if (next_hop) 
+		if ((next_hop->len > 0) && next_hop->s) dialog->hooks.next_hop = next_hop;
+
 	res = t_uac(m, h, b, dialog, c, cp);
 	dialog->rem_target.s = 0;
 	free_dlg(dialog);

+ 3 - 3
modules/tm/uac.h

@@ -48,7 +48,8 @@ extern int pass_provisional_replies; /* Pass provisional replies to fifo applica
  */
 typedef int (*reqwith_t)(str* m, str* h, str* b, dlg_t* d, transaction_cb c, void* cp);
 typedef int (*reqout_t)(str* m, str* t, str* f, str* h, str* b, dlg_t** d, transaction_cb c, void* cp);
-typedef int (*req_t)(str* m, str* ruri, str* t, str* f, str* h, str* b, transaction_cb c, void* cp);
+typedef int (*req_t)(str* m, str* ruri, str* t, str* f, str* h, str* b, str *next_hop, transaction_cb c, void* cp);
+typedef int (*t_uac_t)(str* method, str* headers, str* body, dlg_t* dialog, transaction_cb cb, void* cbp);
 
 
 /*
@@ -80,11 +81,10 @@ int req_within(str* m, str* h, str* b, dlg_t* d, transaction_cb c, void* cp);
  */
 int req_outside(str* m, str* t, str* f, str* h, str* b, dlg_t** d, transaction_cb c, void* cp);
 
-
 /*
  * Send a transactional request, no dialogs involved
  */
-int request(str* m, str* ruri, str* to, str* from, str* h, str* b, transaction_cb c, void* cp);
+int request(str* m, str* ruri, str* to, str* from, str* h, str* b, str *next_hop, transaction_cb c, void* cp);
 
 
 #endif