Browse code

topos: use xavu instead of avp

- replaced params refering to avp with corresponding xavp alternatives

Daniel-Constantin Mierla authored on 01/04/2021 06:40:25
Showing 2 changed files
... ...
@@ -105,13 +105,12 @@ static str _tps_eventrt_receiving_name = str_init("topos:msg-receiving");
105 105
 
106 106
 str _tps_contact_host = str_init("");
107 107
 int _tps_contact_mode = 0;
108
-str _tps_contact_host_avp = str_init("");
109
-pv_spec_t _tps_contact_host_avp_spec;
110 108
 str _tps_cparam_name = str_init("tps");
111
-str _tps_acontact_avp;
112
-str _tps_bcontact_avp;
113
-pv_spec_t _tps_acontact_spec;
114
-pv_spec_t _tps_bcontact_spec;
109
+
110
+str _tps_xavu_cfg = str_init("");
111
+str _tps_xavu_field_acontact = str_init("");
112
+str _tps_xavu_field_bcontact = str_init("");
113
+str _tps_xavu_field_contact_host = str_init("");
115 114
 
116 115
 str _tps_context_param = str_init("");
117 116
 str _tps_context_value = str_init("");
... ...
@@ -160,9 +159,10 @@ static param_export_t params[]={
160 159
 	{"contact_host",	PARAM_STR, &_tps_contact_host},
161 160
 	{"contact_mode",	PARAM_INT, &_tps_contact_mode},
162 161
 	{"cparam_name",		PARAM_STR, &_tps_cparam_name},
163
-	{"a_contact_avp",	PARAM_STR, &_tps_acontact_avp},
164
-	{"b_contact_avp",	PARAM_STR, &_tps_bcontact_avp},
165
-	{"contact_host_avp",    PARAM_STR, &_tps_contact_host_avp},
162
+	{"xavu_cfg",		PARAM_STR, &_tps_xavu_cfg},
163
+	{"xavu_field_a_contact",	PARAM_STR, &_tps_xavu_field_acontact},
164
+	{"xavu_field_b_contact",	PARAM_STR, &_tps_xavu_field_bcontact},
165
+	{"xavu_field_contact_host", PARAM_STR, &_tps_xavu_field_contact_host},
166 166
 	{"rr_update",		PARAM_INT, &_tps_rr_update},
167 167
 	{"context",			PARAM_STR, &_tps_context_param},
168 168
 	{0,0,0}
... ...
@@ -247,34 +247,12 @@ static int mod_init(void)
247 247
 	if(sruid_init(&_tps_sruid, '-', "tpsh", SRUID_INC)<0)
248 248
 		return -1;
249 249
 
250
-	if (_tps_contact_mode == 2 && (_tps_acontact_avp.s == NULL || _tps_acontact_avp.len == 0 ||
251
-			 _tps_bcontact_avp.s == NULL || _tps_bcontact_avp.len == 0)) {
252
-		LM_ERR("contact_mode parameter is 2, but a_contact and/or b_contact AVPs not defined\n");
250
+	if (_tps_contact_mode == 2 && (_tps_xavu_field_acontact.len <= 0
251
+				|| _tps_xavu_field_bcontact.len <= 0)) {
252
+		LM_ERR("contact_mode parameter is 2,"
253
+				" but a_contact or b_contact xavu fields not defined\n");
253 254
 		return -1;
254 255
 	}
255
-	if(_tps_acontact_avp.len > 0 && _tps_acontact_avp.s != NULL) {
256
-		if(pv_parse_spec(&_tps_acontact_avp, &_tps_acontact_spec) == 0 || _tps_acontact_spec.type != PVT_AVP) {
257
-			LM_ERR("malformed or non AVP %.*s AVP definition\n",
258
-				_tps_acontact_avp.len, _tps_acontact_avp.s);
259
-			return -1;
260
-		}
261
-	}
262
-	if(_tps_bcontact_avp.len > 0 && _tps_bcontact_avp.s != NULL) {
263
-		if(pv_parse_spec(&_tps_bcontact_avp, &_tps_bcontact_spec) == 0 || _tps_bcontact_spec.type != PVT_AVP) {
264
-			LM_ERR("malformed or non AVP %.*s AVP definition\n",
265
-				_tps_bcontact_avp.len, _tps_bcontact_avp.s);
266
-			return -1;
267
-		}
268
-	}
269
-
270
-	if(_tps_contact_host_avp.len > 0 && _tps_contact_host_avp.s != NULL) {
271
-		if(pv_parse_spec(&_tps_contact_host_avp, &_tps_contact_host_avp_spec) == 0
272
-				|| _tps_contact_host_avp_spec.type != PVT_AVP) {
273
-			LM_ERR("malformed or non AVP %.*s AVP definition\n",
274
-			_tps_contact_host_avp.len, _tps_contact_host_avp.s);
275
-			return -1;
276
-		}
277
-	}
278 256
 
279 257
 	sr_event_register_cb(SREV_NET_DATA_IN,  tps_msg_received);
280 258
 	sr_event_register_cb(SREV_NET_DATA_OUT, tps_msg_sent);
... ...
@@ -37,6 +37,7 @@
37 37
 #include "../../core/hashes.h"
38 38
 #include "../../core/locking.h"
39 39
 #include "../../core/trim.h"
40
+#include "../../core/xavp.h"
40 41
 #include "../../core/parser/parse_uri.h"
41 42
 #include "../../core/parser/contact/parse_contact.h"
42 43
 #include "../../core/parser/parse_from.h"
... ...
@@ -57,12 +58,10 @@ extern db_func_t _tpsdbf;
57 58
 extern str _tps_contact_host;
58 59
 extern int _tps_contact_mode;
59 60
 extern str _tps_cparam_name;
60
-extern str _tps_acontact_avp;
61
-extern str _tps_bcontact_avp;
62
-extern pv_spec_t _tps_acontact_spec;
63
-extern pv_spec_t _tps_bcontact_spec;
64
-extern str _tps_contact_host_avp;
65
-extern pv_spec_t _tps_contact_host_avp_spec;
61
+extern str _tps_xavu_cfg;
62
+extern str _tps_xavu_field_acontact;
63
+extern str _tps_xavu_field_bcontact;
64
+extern str _tps_xavu_field_contact_host;
66 65
 
67 66
 extern str _tps_context_param;
68 67
 extern str _tps_context_value;
... ...
@@ -217,14 +216,15 @@ int tps_storage_branch_rm(sip_msg_t *msg, tps_data_t *td)
217 216
 /**
218 217
  *
219 218
  */
220
-int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, int ctmode)
219
+int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
220
+		int ctmode)
221 221
 {
222 222
 	str sv;
223 223
 	sip_uri_t puri, curi;
224
-	pv_value_t pv_val;
225 224
 	int i;
226 225
 	int contact_len;
227 226
 	int cparam_len;
227
+	sr_xavp_t *vavu = NULL;
228 228
 
229 229
 	if(dir==TPS_DIR_DOWNSTREAM) {
230 230
 		sv = td->bs_contact;
... ...
@@ -251,11 +251,12 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
251 251
 		cparam_len = 0;
252 252
 	}
253 253
 
254
-	if(td->cp + 8 + (2*uuid->len) + cparam_len + contact_len >= td->cbuf + TPS_DATA_SIZE) {
254
+	if(td->cp + 8 + (2*uuid->len) + cparam_len + contact_len >= td->cbuf
255
+			+ TPS_DATA_SIZE) {
255 256
 		LM_ERR("insufficient data buffer\n");
256 257
 		return -1;
257 258
 	}
258
-	// copy uuid
259
+	/* copy uuid */
259 260
 	if(dir==TPS_DIR_DOWNSTREAM) {
260 261
 		td->b_uuid.s = td->cp;
261 262
 		*td->cp = 'b';
... ...
@@ -278,14 +279,14 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
278 279
 
279 280
 	*td->cp = '<';
280 281
 	td->cp++;
281
-	// look for sip:
282
+	/* look for sip: */
282 283
 	for(i=0; i<sv.len; i++) {
283 284
 		*td->cp = sv.s[i];
284 285
 		td->cp++;
285 286
 		if(sv.s[i]==':') break;
286 287
 	}
287
-	// create new URI parameter for Contact header
288 288
 	if (ctmode == 1 || ctmode == 2) {
289
+		/* create new URI parameter for Contact header */
289 290
 		if (ctmode == 1) {
290 291
 			if (dir==TPS_DIR_DOWNSTREAM) {
291 292
 				/* extract the contact address */
... ...
@@ -300,7 +301,7 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
300 301
 						return -1;
301 302
 					} else {
302 303
 						if (parse_uri(((contact_body_t*)msg->contact->parsed)->contacts->uri.s,
303
-						((contact_body_t*)msg->contact->parsed)->contacts->uri.len, &curi) < 0) {
304
+							((contact_body_t*)msg->contact->parsed)->contacts->uri.len, &curi) < 0) {
304 305
 							LM_ERR("failed to parse the contact uri\n");
305 306
 							return -1;
306 307
 						}
... ...
@@ -324,41 +325,44 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
324 325
 		} else if (ctmode == 2) {
325 326
 			if (dir==TPS_DIR_DOWNSTREAM) {
326 327
 				/* extract the a contact */
327
-				if ((pv_get_spec_value(msg, &_tps_acontact_spec, &pv_val) != 0)
328
-						&& (pv_val.flags & PV_VAL_STR) && (pv_val.rs.len <= 0)) {
329
-					LM_ERR("could not evaluate a_contact AVP\n");
328
+				vavu = xavu_get_child_with_sval(&_tps_xavu_cfg,
329
+							&_tps_xavu_field_acontact);
330
+				if(vavu==NULL || vavu->val.v.s.len<=0) {
331
+					LM_ERR("could not evaluate a_contact xavu\n");
330 332
 					return -1;
331 333
 				}
332
-				memcpy(td->cp, pv_val.rs.s, pv_val.rs.len);
333
-				td->cp += pv_val.rs.len;
334
+				memcpy(td->cp, vavu->val.v.s.s, vavu->val.v.s.len);
335
+				td->cp += vavu->val.v.s.len;
334 336
 			} else {
335 337
 				/* extract the b contact */
336
-				if ((pv_get_spec_value(msg, &_tps_bcontact_spec, &pv_val) != 0)
337
-						&& (pv_val.flags & PV_VAL_STR) && (pv_val.rs.len <= 0)) {
338
-					LM_ERR("could not evaluate b_contact AVP\n");
338
+				vavu = xavu_get_child_with_sval(&_tps_xavu_cfg,
339
+							&_tps_xavu_field_bcontact);
340
+				if(vavu==NULL || vavu->val.v.s.len<=0) {
341
+					LM_ERR("could not evaluate b_contact xavu\n");
339 342
 					return -1;
340 343
 				}
341
-				memcpy(td->cp, pv_val.rs.s, pv_val.rs.len);
342
-				td->cp += pv_val.rs.len;
344
+				memcpy(td->cp, vavu->val.v.s.s, vavu->val.v.s.len);
345
+				td->cp += vavu->val.v.s.len;
343 346
 			}
344 347
 		}
345 348
 
346
-		if (!((ctmode == 1) && (dir==TPS_DIR_DOWNSTREAM) && (curi.user.len <= 0))) {
349
+		if (!((ctmode == 1) && (dir==TPS_DIR_DOWNSTREAM)
350
+					&& (curi.user.len <= 0))) {
347 351
 			*td->cp = '@';
348 352
 			td->cp++;
349 353
 		}
350 354
 
351
-		// contact_host AVP takes preference
352
-		if (_tps_contact_host_avp.len) {
353
-			if ((pv_get_spec_value(msg, &_tps_contact_host_avp_spec, &pv_val) != 0) &&
354
-					(pv_val.flags & PV_VAL_STR) && (pv_val.rs.len <= 0)) {
355
-				LM_ERR("could not evaluate contact_host AVP\n");
356
-				return -1;
357
-			}
358
-			memcpy(td->cp, pv_val.rs.s, pv_val.rs.len);
359
-			td->cp += pv_val.rs.len;
355
+		/* contact_host xavu takes preference */
356
+		if (_tps_xavu_cfg.len>0 && _tps_xavu_field_contact_host.len>0) {
357
+			vavu = xavu_get_child_with_sval(&_tps_xavu_cfg,
358
+					&_tps_xavu_field_contact_host);
359
+		}
360
+		if(vavu!=NULL && vavu->val.v.s.len>0) {
361
+			memcpy(td->cp, vavu->val.v.s.s, vavu->val.v.s.len);
362
+			td->cp += vavu->val.v.s.len;
360 363
 		} else {
361
-			if (_tps_contact_host.len) { // using configured hostname in the contact header
364
+			if (_tps_contact_host.len) {
365
+				/* using configured hostname in the contact header */
362 366
 				memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len);
363 367
 				td->cp += _tps_contact_host.len;
364 368
 			} else {
... ...
@@ -394,8 +398,8 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
394 398
 		memcpy(td->cp, uuid->s, uuid->len);
395 399
 		td->cp += uuid->len;
396 400
 
397
-	// create new user part for Contact header URI
398 401
 	} else {
402
+		/* create new user part for Contact header URI */
399 403
 		if(dir==TPS_DIR_DOWNSTREAM) {
400 404
 			*td->cp = 'b';
401 405
 		} else {
... ...
@@ -407,7 +411,8 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
407 411
 		*td->cp = '@';
408 412
 		td->cp++;
409 413
 
410
-		if (_tps_contact_host.len) { // using configured hostname in the contact header
414
+		if (_tps_contact_host.len) {
415
+			/* using configured hostname in the contact header */
411 416
 			memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len);
412 417
 			td->cp += _tps_contact_host.len;
413 418
 		} else {
... ...
@@ -485,7 +490,8 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
485 490
 
486 491
 	/* extract the contact address */
487 492
 	if(parse_headers(msg, HDR_CONTACT_F, 0)<0 || msg->contact==NULL) {
488
-		if((td->s_method_id != METHOD_INVITE) && (td->s_method_id != METHOD_SUBSCRIBE)){
493
+		if((td->s_method_id != METHOD_INVITE)
494
+				&& (td->s_method_id != METHOD_SUBSCRIBE)){
489 495
 			/* no mandatory contact unless is INVITE or SUBSCRIBE - done */
490 496
 			return 0;
491 497
 		}
... ...
@@ -525,7 +531,8 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
525 531
 	}
526 532
 
527 533
 	if  (td->s_method_id == METHOD_SUBSCRIBE) {
528
-		if(msg->expires && (msg->expires->body.len > 0) && (msg->expires->parsed || (parse_expires(msg->expires) >= 0))) {
534
+		if(msg->expires && (msg->expires->body.len > 0) && (msg->expires->parsed
535
+					|| (parse_expires(msg->expires) >= 0))) {
529 536
 			td->expires = ((exp_body_t *)msg->expires->parsed)->val;
530 537
 		}
531 538
 	}
... ...
@@ -572,9 +579,11 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir)
572 579
 		suid.len--;
573 580
 	}
574 581
 
575
-	ret = tps_storage_fill_contact(msg, td, &suid, TPS_DIR_DOWNSTREAM, _tps_contact_mode);
582
+	ret = tps_storage_fill_contact(msg, td, &suid, TPS_DIR_DOWNSTREAM,
583
+			_tps_contact_mode);
576 584
 	if(ret<0) goto error;
577
-	ret = tps_storage_fill_contact(msg, td, &suid, TPS_DIR_UPSTREAM, _tps_contact_mode);
585
+	ret = tps_storage_fill_contact(msg, td, &suid, TPS_DIR_UPSTREAM,
586
+			_tps_contact_mode);
578 587
 	if(ret<0) goto error;
579 588
 
580 589
 	ret = tps_storage_link_msg(msg, td, dir);
... ...
@@ -1100,7 +1109,8 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1100 1109
 	nr_cols = 0;
1101 1110
 
1102 1111
 	if((get_cseq(msg)->method_id == METHOD_SUBSCRIBE)
1103
-			|| ((get_cseq(msg)->method_id == METHOD_NOTIFY) && (msg->event->len > 0))) {
1112
+			|| ((get_cseq(msg)->method_id == METHOD_NOTIFY)
1113
+				&& (msg->event->len > 0))) {
1104 1114
 		bInviteDlg = 0;
1105 1115
 	}
1106 1116
 
... ...
@@ -1502,7 +1512,8 @@ int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1502 1512
 	if(msg==NULL || md==NULL || sd==NULL)
1503 1513
 		return -1;
1504 1514
 
1505
-	if((md->s_method_id != METHOD_INVITE) && (md->s_method_id != METHOD_SUBSCRIBE)) {
1515
+	if((md->s_method_id != METHOD_INVITE)
1516
+			&& (md->s_method_id != METHOD_SUBSCRIBE)) {
1506 1517
 		return 0;
1507 1518
 	}
1508 1519
 
... ...
@@ -1597,8 +1608,10 @@ int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1597 1608
 		}
1598 1609
 	}
1599 1610
 	if(sd->b_tag.len>0 && ((mode & TPS_DBU_BRR) || (mode & TPS_DBU_ARR))) {
1600
-		if(((md->direction == TPS_DIR_DOWNSTREAM) && (msg->first_line.type==SIP_REPLY)) ||
1601
-					((md->direction == TPS_DIR_UPSTREAM) && (msg->first_line.type==SIP_REQUEST))) {
1611
+		if(((md->direction == TPS_DIR_DOWNSTREAM)
1612
+					&& (msg->first_line.type==SIP_REPLY))
1613
+				|| ((md->direction == TPS_DIR_UPSTREAM)
1614
+					 && (msg->first_line.type==SIP_REQUEST))) {
1602 1615
 			if(((sd->iflags&TPS_IFLAG_DLGON) == 0) && (mode & TPS_DBU_BRR)) {
1603 1616
 				db_ucols[nr_ucols] = &td_col_b_rr;
1604 1617
 				db_uvals[nr_ucols].type = DB1_STR;
... ...
@@ -1619,7 +1632,8 @@ int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1619 1632
 		}
1620 1633
 	}
1621 1634
 	if ((mode & TPS_DBU_TIME) && ((sd->b_tag.len > 0)
1622
-			&& ((md->direction == TPS_DIR_UPSTREAM) && (msg->first_line.type==SIP_REQUEST))
1635
+			&& ((md->direction == TPS_DIR_UPSTREAM)
1636
+				&& (msg->first_line.type==SIP_REQUEST))
1623 1637
 			&& (msg->first_line.u.request.method_value == METHOD_SUBSCRIBE))) {
1624 1638
 		db_ucols[nr_ucols] = &td_col_rectime;
1625 1639
 		db_uvals[nr_ucols].type = DB1_DATETIME;
... ...
@@ -1687,7 +1701,8 @@ int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1687 1701
 	if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL)
1688 1702
 		return -1;
1689 1703
 
1690
-	if((md->s_method_id != METHOD_BYE) && !((md->s_method_id == METHOD_SUBSCRIBE) && (md->expires == 0))) {
1704
+	if((md->s_method_id != METHOD_BYE) && !((md->s_method_id == METHOD_SUBSCRIBE)
1705
+				&& (md->expires == 0))) {
1691 1706
 		return 0;
1692 1707
 	}
1693 1708