Browse code

uac: Added ability to set Call-Id through $uac_req(callid).

Konstantin Mosesov authored on 17/05/2013 18:14:29
Showing 5 changed files
... ...
@@ -762,7 +762,10 @@ int request(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop)
762 762
 
763 763
 	if (check_params(uac_r, to, from) < 0) goto err;
764 764
 
765
-	generate_callid(&callid);
765
+	if (uac_r->callid == NULL || uac_r->callid->len <= 0)
766
+	    generate_callid(&callid);
767
+	else
768
+	    callid = *uac_r->callid;
766 769
 	generate_fromtag(&fromtag, &callid);
767 770
 
768 771
 	if (new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &dialog) < 0) {
... ...
@@ -58,6 +58,7 @@ typedef struct uac_req {
58 58
 	int	cb_flags;
59 59
 	transaction_cb	*cb;
60 60
 	void	*cbp;
61
+	str	*callid;
61 62
 } uac_req_t;
62 63
 
63 64
 /* macro for setting the values of uac_req_t struct */
... ...
@@ -605,6 +605,7 @@ $uac_req(method)="OPTIONS";
605 605
 $uac_req(ruri)="sip:kamailio.org";
606 606
 $uac_req(furi)="sip:kamailio.org";
607 607
 $uac_req(turi)="sip:kamailio.org";
608
+$uac_req(callid)=$(mb{s.md5});
608 609
 uac_req_send();
609 610
 ...
610 611
 
... ...
@@ -713,6 +713,7 @@ $uac_req(method)="OPTIONS";
713 713
 $uac_req(ruri)="sip:kamailio.org";
714 714
 $uac_req(furi)="sip:kamailio.org";
715 715
 $uac_req(turi)="sip:kamailio.org";
716
+$uac_req(callid)=$(mb{s.md5});
716 717
 uac_req_send();
717 718
 ...
718 719
 				</programlisting>
... ...
@@ -61,6 +61,8 @@ typedef struct _uac_send_info {
61 61
 	char  b_apasswd[64];
62 62
 	str   s_apasswd;
63 63
 	unsigned int onreply;
64
+	char  b_callid[128];
65
+	str   s_callid;
64 66
 } uac_send_info_t;
65 67
 
66 68
 static struct _uac_send_info _uac_req;
... ...
@@ -84,6 +86,7 @@ uac_send_info_t *uac_send_info_clone(uac_send_info_t *ur)
84 84
 	tp->s_ouri.s    = tp->b_ouri;
85 85
 	tp->s_auser.s   = tp->b_auser;
86 86
 	tp->s_apasswd.s = tp->b_apasswd;
87
+	tp->s_callid.s  = tp->b_callid;
87 88
 
88 89
 	return tp;
89 90
 }
... ...
@@ -134,6 +137,10 @@ int pv_get_uac_req(struct sip_msg *msg, pv_param_t *param,
134 134
 			if(_uac_req.s_apasswd.len<=0)
135 135
 				return pv_get_null(msg, param, res);
136 136
 			return pv_get_strval(msg, param, res, &_uac_req.s_apasswd);
137
+		case 11:
138
+			if(_uac_req.s_callid.len<=0)
139
+				return pv_get_null(msg, param, res);
140
+			return pv_get_strval(msg, param, res, &_uac_req.s_callid);
137 141
 		default:
138 142
 			return pv_get_uintval(msg, param, res, _uac_req.flags);
139 143
 	}
... ...
@@ -160,6 +167,7 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
160 160
 				_uac_req.s_body.len = 0;
161 161
 				_uac_req.s_method.len = 0;
162 162
 				_uac_req.onreply = 0;
163
+				_uac_req.s_callid.len = 0;
163 164
 			}
164 165
 			break;
165 166
 		case 1:
... ...
@@ -360,6 +368,21 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
360 360
 			_uac_req.s_apasswd.s[val->rs.len] = '\0';
361 361
 			_uac_req.s_apasswd.len = val->rs.len;
362 362
 			break;
363
+		case 11:
364
+			if(val==NULL)
365
+			{
366
+				_uac_req.s_callid.len = 0;
367
+				return 0;
368
+			}
369
+			if(!(val->flags&PV_VAL_STR))
370
+			{
371
+				LM_ERR("Invalid value type\n");
372
+				return -1;
373
+			}
374
+                        memcpy(_uac_req.s_callid.s, val->rs.s, val->rs.len);
375
+                        _uac_req.s_callid.s[val->rs.len] = '\0';
376
+                        _uac_req.s_callid.len = val->rs.len;
377
+			break;
363 378
 	}
364 379
 	return 0;
365 380
 }
... ...
@@ -399,6 +422,8 @@ int pv_parse_uac_req_name(pv_spec_p sp, str *in)
399 399
 		case 6: 
400 400
 			if(strncmp(in->s, "method", 6)==0)
401 401
 				sp->pvp.pvn.u.isname.name.n = 7;
402
+			else if(strncmp(in->s, "callid", 6)==0)
403
+				sp->pvp.pvn.u.isname.name.n = 11;
402 404
 			else goto error;
403 405
 		break;
404 406
 		case 7: 
... ...
@@ -439,6 +464,7 @@ void uac_req_init(void)
439 439
 	_uac_req.s_method.s = _uac_req.b_method;
440 440
 	_uac_req.s_auser.s  = _uac_req.b_auser;
441 441
 	_uac_req.s_apasswd.s  = _uac_req.b_apasswd;
442
+	_uac_req.s_callid.s  = _uac_req.b_callid;
442 443
 	return;
443 444
 }
444 445
 
... ...
@@ -612,6 +638,7 @@ int uac_req_send(struct sip_msg *msg, char *s1, char *s2)
612 612
 		/* Callback parameter */
613 613
 		uac_r.cbp = (void*)tp;
614 614
 	}
615
+        uac_r.callid = (_uac_req.s_callid.len <= 0) ? NULL : &_uac_req.s_callid;
615 616
 	ret = tmb.t_request(&uac_r,  /* UAC Req */
616 617
 						&_uac_req.s_ruri,        /* Request-URI */
617 618
 						(_uac_req.s_turi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_turi, /* To */