Browse code

topos: reset vavu variable, otherwise we will get errors in contact_mode 2 (GH #2852)

Henning Westerholt authored on 28/09/2021 11:27:50
Showing 1 changed files
... ...
@@ -352,7 +352,8 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
352 352
 			td->cp++;
353 353
 		}
354 354
 
355
-		/* contact_host xavu takes preference */
355
+		/* contact_host xavu takes preference, reset vavu */
356
+		vavu = NULL;
356 357
 		if (_tps_xavu_cfg.len>0 && _tps_xavu_field_contact_host.len>0) {
357 358
 			vavu = xavu_get_child_with_sval(&_tps_xavu_cfg,
358 359
 					&_tps_xavu_field_contact_host);
Browse code

topos: fix missing xavu_field_contact_host evaluation for contact_mode 0

- fix missing xavu_field_contact_host evaluation for contact_mode 0
- it works currently only for contact_mode 1 and 2, but not for default mode

Henning Westerholt authored on 08/07/2021 14:57:27
Showing 1 changed files
... ...
@@ -411,13 +411,23 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
411 411
 		*td->cp = '@';
412 412
 		td->cp++;
413 413
 
414
-		if (_tps_contact_host.len) {
415
-			/* using configured hostname in the contact header */
416
-			memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len);
417
-			td->cp += _tps_contact_host.len;
414
+		/* contact_host xavu takes preference */
415
+		if (_tps_xavu_cfg.len>0 && _tps_xavu_field_contact_host.len>0) {
416
+			vavu = xavu_get_child_with_sval(&_tps_xavu_cfg,
417
+					&_tps_xavu_field_contact_host);
418
+		}
419
+		if(vavu!=NULL && vavu->val.v.s.len>0) {
420
+			memcpy(td->cp, vavu->val.v.s.s, vavu->val.v.s.len);
421
+			td->cp += vavu->val.v.s.len;
418 422
 		} else {
419
-			memcpy(td->cp, puri.host.s, puri.host.len);
420
-			td->cp += puri.host.len;
423
+			if (_tps_contact_host.len) {
424
+				/* using configured hostname in the contact header */
425
+				memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len);
426
+				td->cp += _tps_contact_host.len;
427
+			} else {
428
+				memcpy(td->cp, puri.host.s, puri.host.len);
429
+				td->cp += puri.host.len;
430
+			}
421 431
 		}
422 432
 		if(puri.port.len>0) {
423 433
 			*td->cp = ':';
Browse code

topos: explicitely set the db match operator and value type for uuid

Daniel-Constantin Mierla authored on 26/04/2021 12:58:39
Showing 1 changed files
... ...
@@ -1148,20 +1148,32 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1148 1148
 		if(md->a_uuid.len>0) {
1149 1149
 			if(md->a_uuid.s[0]=='a') {
1150 1150
 				db_keys[nr_keys]=&tt_col_a_uuid;
1151
+				db_ops[nr_keys]=OP_EQ;
1152
+				db_vals[nr_keys].type = DB1_STR;
1153
+				db_vals[nr_keys].nul = 0;
1151 1154
 				db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
1152 1155
 				nr_keys++;
1153 1156
 			} else if(md->a_uuid.s[0]=='b') {
1154 1157
 				db_keys[nr_keys]=&tt_col_b_uuid;
1158
+				db_ops[nr_keys]=OP_EQ;
1159
+				db_vals[nr_keys].type = DB1_STR;
1160
+				db_vals[nr_keys].nul = 0;
1155 1161
 				db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
1156 1162
 				nr_keys++;
1157 1163
 			}
1158 1164
 		} else if(md->b_uuid.len>0) {
1159 1165
 			if(md->b_uuid.s[0]=='a') {
1160 1166
 				db_keys[nr_keys]=&tt_col_a_uuid;
1167
+				db_ops[nr_keys]=OP_EQ;
1168
+				db_vals[nr_keys].type = DB1_STR;
1169
+				db_vals[nr_keys].nul = 0;
1161 1170
 				db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
1162 1171
 				nr_keys++;
1163 1172
 			} else if(md->b_uuid.s[0]=='b') {
1164 1173
 				db_keys[nr_keys]=&tt_col_b_uuid;
1174
+				db_ops[nr_keys]=OP_EQ;
1175
+				db_vals[nr_keys].type = DB1_STR;
1176
+				db_vals[nr_keys].nul = 0;
1165 1177
 				db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
1166 1178
 				nr_keys++;
1167 1179
 			}
Browse code

topos: increase the number of db keys for query when using uuid for branch

- debug message to print a/b uuid

Daniel-Constantin Mierla authored on 26/04/2021 12:51:55
Showing 1 changed files
... ...
@@ -1149,17 +1149,21 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1149 1149
 			if(md->a_uuid.s[0]=='a') {
1150 1150
 				db_keys[nr_keys]=&tt_col_a_uuid;
1151 1151
 				db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
1152
+				nr_keys++;
1152 1153
 			} else if(md->a_uuid.s[0]=='b') {
1153 1154
 				db_keys[nr_keys]=&tt_col_b_uuid;
1154 1155
 				db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
1156
+				nr_keys++;
1155 1157
 			}
1156 1158
 		} else if(md->b_uuid.len>0) {
1157 1159
 			if(md->b_uuid.s[0]=='a') {
1158 1160
 				db_keys[nr_keys]=&tt_col_a_uuid;
1159 1161
 				db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
1162
+				nr_keys++;
1160 1163
 			} else if(md->b_uuid.s[0]=='b') {
1161 1164
 				db_keys[nr_keys]=&tt_col_b_uuid;
1162 1165
 				db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
1166
+				nr_keys++;
1163 1167
 			}
1164 1168
 		}
1165 1169
 	}
Browse code

topos: check if event field exists for NOTIFY

Daniel-Constantin Mierla authored on 26/04/2021 11:43:21
Showing 1 changed files
... ...
@@ -1110,7 +1110,7 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1110 1110
 
1111 1111
 	if((get_cseq(msg)->method_id == METHOD_SUBSCRIBE)
1112 1112
 			|| ((get_cseq(msg)->method_id == METHOD_NOTIFY)
1113
-				&& (msg->event->len > 0))) {
1113
+				&& (msg->event && msg->event->len > 0))) {
1114 1114
 		bInviteDlg = 0;
1115 1115
 	}
1116 1116
 
Browse code

topos: load associated early dialog transaction using also uuid

Daniel-Constantin Mierla authored on 26/04/2021 11:02:11
Showing 1 changed files
... ...
@@ -1144,6 +1144,24 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1144 1144
 		db_vals[nr_keys].nul = 0;
1145 1145
 		db_vals[nr_keys].val.str_val = bInviteDlg ? sinv : ssub;
1146 1146
 		nr_keys++;
1147
+
1148
+		if(md->a_uuid.len>0) {
1149
+			if(md->a_uuid.s[0]=='a') {
1150
+				db_keys[nr_keys]=&tt_col_a_uuid;
1151
+				db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
1152
+			} else if(md->a_uuid.s[0]=='b') {
1153
+				db_keys[nr_keys]=&tt_col_b_uuid;
1154
+				db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
1155
+			}
1156
+		} else if(md->b_uuid.len>0) {
1157
+			if(md->b_uuid.s[0]=='a') {
1158
+				db_keys[nr_keys]=&tt_col_a_uuid;
1159
+				db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
1160
+			} else if(md->b_uuid.s[0]=='b') {
1161
+				db_keys[nr_keys]=&tt_col_b_uuid;
1162
+				db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
1163
+			}
1164
+		}
1147 1165
 	}
1148 1166
 
1149 1167
 	if(msg->first_line.type==SIP_REQUEST && md->x_context.len>0) {
Browse code

topos: use context to load stored branch attributes only for requests

Daniel-Constantin Mierla authored on 23/04/2021 07:53:07
Showing 1 changed files
... ...
@@ -1146,7 +1146,7 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1146 1146
 		nr_keys++;
1147 1147
 	}
1148 1148
 
1149
-	if(md->x_context.len>0) {
1149
+	if(msg->first_line.type==SIP_REQUEST && md->x_context.len>0) {
1150 1150
 		db_keys[nr_keys]=&tt_col_x_context;
1151 1151
 		db_ops[nr_keys]=OP_EQ;
1152 1152
 		db_vals[nr_keys].type = DB1_STR;
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 1 changed files
... ...
@@ -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
 
Browse code

topos: use context for sruid

Daniel-Constantin Mierla authored on 31/03/2021 22:01:22
Showing 1 changed files
... ...
@@ -64,6 +64,9 @@ extern pv_spec_t _tps_bcontact_spec;
64 64
 extern str _tps_contact_host_avp;
65 65
 extern pv_spec_t _tps_contact_host_avp_spec;
66 66
 
67
+extern str _tps_context_param;
68
+extern str _tps_context_value;
69
+
67 70
 #define TPS_STORAGE_LOCK_SIZE	1<<9
68 71
 static gen_lock_set_t *_tps_storage_lock_set = NULL;
69 72
 
... ...
@@ -546,9 +549,16 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir)
546 549
 {
547 550
 	int ret = -1; /* error if dialog == 0 */
548 551
 	str suid;
552
+	str *sx = NULL;
553
+
554
+	if(_tps_context_value.len>0) {
555
+		sx = &_tps_context_value;
556
+	} else if(_tps_context_param.len>0) {
557
+		sx = &_tps_context_param;
558
+	}
549 559
 
550 560
 	if(dialog==0) {
551
-		sruid_next(&_tps_sruid);
561
+		sruid_nextx(&_tps_sruid, sx);
552 562
 		suid = _tps_sruid.uid;
553 563
 	} else {
554 564
 		if(td->a_uuid.len>0) {
Browse code

topos: option to set a context value via modparam or function

- ability to group records

Daniel-Constantin Mierla authored on 31/03/2021 19:46:14
Showing 1 changed files
... ...
@@ -612,6 +612,7 @@ str td_col_a_srcaddr = str_init("a_srcaddr");
612 612
 str td_col_b_srcaddr = str_init("b_srcaddr");
613 613
 str td_col_s_method = str_init("s_method");
614 614
 str td_col_s_cseq = str_init("s_cseq");
615
+str td_col_x_context = str_init("x_context");
615 616
 
616 617
 str tt_table_name = str_init("topos_t");
617 618
 str tt_col_rectime = str_init("rectime");
... ...
@@ -634,6 +635,7 @@ str tt_col_a_tag = str_init("a_tag");
634 635
 str tt_col_b_tag = str_init("b_tag");
635 636
 str tt_col_s_method = str_init("s_method");
636 637
 str tt_col_s_cseq = str_init("s_cseq");
638
+str tt_col_x_context = str_init("x_context");
637 639
 
638 640
 #define TPS_NR_KEYS	48
639 641
 
... ...
@@ -763,6 +765,13 @@ int tps_db_insert_dialog(tps_data_t *td)
763 765
 	db_vals[nr_keys].val.str_val = TPS_STRZ(td->s_cseq);
764 766
 	nr_keys++;
765 767
 
768
+	if(td->x_context.len>0) {
769
+		db_keys[nr_keys] = &td_col_x_context;
770
+		db_vals[nr_keys].type = DB1_STR;
771
+		db_vals[nr_keys].val.str_val = TPS_STRZ(td->x_context);
772
+		nr_keys++;
773
+	}
774
+
766 775
 	if (_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) {
767 776
 		LM_ERR("failed to perform use table\n");
768 777
 		return -1;
... ...
@@ -949,6 +958,13 @@ int tps_db_insert_branch(tps_data_t *td)
949 958
 	db_vals[nr_keys].val.str_val = TPS_STRZ(td->b_tag);
950 959
 	nr_keys++;
951 960
 
961
+	if(td->x_context.len>0) {
962
+		db_keys[nr_keys] = &tt_col_x_context;
963
+		db_vals[nr_keys].type = DB1_STR;
964
+		db_vals[nr_keys].val.str_val = TPS_STRZ(td->x_context);
965
+		nr_keys++;
966
+	}
967
+
952 968
 	if (_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) {
953 969
 		LM_ERR("failed to perform use table\n");
954 970
 		return -1;
... ...
@@ -1054,9 +1070,9 @@ int tps_db_clean_branches(void)
1054 1070
 int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1055 1071
 		uint32_t mode)
1056 1072
 {
1057
-	db_key_t db_keys[4];
1058
-	db_op_t  db_ops[4];
1059
-	db_val_t db_vals[4];
1073
+	db_key_t db_keys[5];
1074
+	db_op_t  db_ops[5];
1075
+	db_val_t db_vals[5];
1060 1076
 	db_key_t db_cols[TPS_NR_KEYS];
1061 1077
 	db1_res_t* db_res = NULL;
1062 1078
 	str sinv = str_init("INVITE");
... ...
@@ -1073,7 +1089,8 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1073 1089
 	nr_keys = 0;
1074 1090
 	nr_cols = 0;
1075 1091
 
1076
-	if((get_cseq(msg)->method_id == METHOD_SUBSCRIBE) || ((get_cseq(msg)->method_id == METHOD_NOTIFY) && (msg->event->len > 0))) {
1092
+	if((get_cseq(msg)->method_id == METHOD_SUBSCRIBE)
1093
+			|| ((get_cseq(msg)->method_id == METHOD_NOTIFY) && (msg->event->len > 0))) {
1077 1094
 		bInviteDlg = 0;
1078 1095
 	}
1079 1096
 
... ...
@@ -1109,6 +1126,15 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1109 1126
 		nr_keys++;
1110 1127
 	}
1111 1128
 
1129
+	if(md->x_context.len>0) {
1130
+		db_keys[nr_keys]=&tt_col_x_context;
1131
+		db_ops[nr_keys]=OP_EQ;
1132
+		db_vals[nr_keys].type = DB1_STR;
1133
+		db_vals[nr_keys].nul = 0;
1134
+		db_vals[nr_keys].val.str_val = TPS_STRZ(md->x_context);
1135
+		nr_keys++;
1136
+	}
1137
+
1112 1138
 	db_cols[nr_cols++] = &tt_col_rectime;
1113 1139
 	db_cols[nr_cols++] = &tt_col_a_callid;
1114 1140
 	db_cols[nr_cols++] = &tt_col_a_uuid;
... ...
@@ -1129,6 +1155,9 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1129 1155
 	db_cols[nr_cols++] = &tt_col_bs_contact;
1130 1156
 	db_cols[nr_cols++] = &tt_col_a_tag;
1131 1157
 	db_cols[nr_cols++] = &tt_col_b_tag;
1158
+	if(md->x_context.len>0) {
1159
+		db_cols[nr_cols++] = &tt_col_x_context;
1160
+	}
1132 1161
 
1133 1162
 	if (_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) {
1134 1163
 		LM_ERR("failed to perform use table\n");
... ...
@@ -1177,6 +1206,9 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1177 1206
 	TPS_DATA_APPEND_DB(sd, db_res, n, &sd->bs_contact); n++;
1178 1207
 	TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_tag); n++;
1179 1208
 	TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_tag); n++;
1209
+	if(md->x_context.len>0) {
1210
+		TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_context); n++;
1211
+	}
1180 1212
 
1181 1213
 done:
1182 1214
 	if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0)
... ...
@@ -1205,9 +1237,9 @@ int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1205 1237
  */
1206 1238
 int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1207 1239
 {
1208
-	db_key_t db_keys[4];
1209
-	db_op_t  db_ops[4];
1210
-	db_val_t db_vals[4];
1240
+	db_key_t db_keys[5];
1241
+	db_op_t  db_ops[5];
1242
+	db_val_t db_vals[5];
1211 1243
 	db_key_t db_cols[TPS_NR_KEYS];
1212 1244
 	db1_res_t* db_res = NULL;
1213 1245
 	int nr_keys;
... ...
@@ -1253,6 +1285,15 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1253 1285
 	}
1254 1286
 	nr_keys++;
1255 1287
 
1288
+	if(md->x_context.len>0) {
1289
+		db_keys[nr_keys]=&td_col_x_context;
1290
+		db_ops[nr_keys]=OP_EQ;
1291
+		db_vals[nr_keys].type = DB1_STR;
1292
+		db_vals[nr_keys].nul = 0;
1293
+		db_vals[nr_keys].val.str_val = TPS_STRZ(md->x_context);
1294
+		nr_keys++;
1295
+	}
1296
+
1256 1297
 	db_cols[nr_cols++] = &td_col_rectime;
1257 1298
 	db_cols[nr_cols++] = &td_col_a_callid;
1258 1299
 	db_cols[nr_cols++] = &td_col_a_uuid;
... ...
@@ -1274,7 +1315,9 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1274 1315
 	db_cols[nr_cols++] = &td_col_b_srcaddr;
1275 1316
 	db_cols[nr_cols++] = &td_col_s_method;
1276 1317
 	db_cols[nr_cols++] = &td_col_s_cseq;
1277
-
1318
+	if(md->x_context.len>0) {
1319
+		db_cols[nr_cols++] = &td_col_x_context;
1320
+	}
1278 1321
 
1279 1322
 	if (_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) {
1280 1323
 		LM_ERR("failed to perform use table\n");
... ...
@@ -1318,6 +1361,9 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1318 1361
 	TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_srcaddr); n++;
1319 1362
 	TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_method); n++;
1320 1363
 	TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_cseq); n++;
1364
+	if(md->x_context.len>0) {
1365
+		TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_context); n++;
1366
+	}
1321 1367
 
1322 1368
 done:
1323 1369
 	if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0)
... ...
@@ -1388,6 +1434,15 @@ int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1388 1434
 	}
1389 1435
 	nr_keys++;
1390 1436
 
1437
+	if(sd->x_context.len>0) {
1438
+		db_keys[nr_keys]=&tt_col_x_context;
1439
+		db_ops[nr_keys]=OP_EQ;
1440
+		db_vals[nr_keys].type = DB1_STR;
1441
+		db_vals[nr_keys].nul = 0;
1442
+		db_vals[nr_keys].val.str_val = TPS_STRZ(sd->x_context);
1443
+		nr_keys++;
1444
+	}
1445
+
1391 1446
 	if(mode & TPS_DBU_CONTACT) {
1392 1447
 		TPS_DB_ADD_STRV(db_ucols, db_uvals, nr_ucols,
1393 1448
 				tt_col_a_contact, md->a_contact);
... ...
@@ -1494,6 +1549,15 @@ int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1494 1549
 	}
1495 1550
 	nr_keys++;
1496 1551
 
1552
+	if(sd->x_context.len>0) {
1553
+		db_keys[nr_keys]=&td_col_x_context;
1554
+		db_ops[nr_keys]=OP_EQ;
1555
+		db_vals[nr_keys].type = DB1_STR;
1556
+		db_vals[nr_keys].nul = 0;
1557
+		db_vals[nr_keys].val.str_val = TPS_STRZ(sd->x_context);
1558
+		nr_keys++;
1559
+	}
1560
+
1497 1561
 	if(mode & TPS_DBU_CONTACT) {
1498 1562
 		TPS_DB_ADD_STRV(db_ucols, db_uvals, nr_ucols,
1499 1563
 				td_col_a_contact, md->a_contact);
... ...
@@ -1638,6 +1702,15 @@ int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1638 1702
 	}
1639 1703
 	nr_keys++;
1640 1704
 
1705
+	if(sd->x_context.len>0) {
1706
+		db_keys[nr_keys]=&td_col_x_context;
1707
+		db_ops[nr_keys]=OP_EQ;
1708
+		db_vals[nr_keys].type = DB1_STR;
1709
+		db_vals[nr_keys].nul = 0;
1710
+		db_vals[nr_keys].val.str_val = TPS_STRZ(sd->x_context);
1711
+		nr_keys++;
1712
+	}
1713
+
1641 1714
 	db_ucols[nr_ucols] = &td_col_rectime;
1642 1715
 	db_uvals[nr_ucols].type = DB1_DATETIME;
1643 1716
 	db_uvals[nr_ucols].val.time_val = time(NULL);
Browse code

topos: add functionality to set a variable host part for the Contact header

- add functionality to set a variable host part for the Contact header
- could be refactored to use a xavp instead of avp, together with the other
parameters in this area ([a,b]_contact_avp)

Henning Westerholt authored on 31/03/2021 13:28:30
Showing 1 changed files
... ...
@@ -61,6 +61,8 @@ extern str _tps_acontact_avp;
61 61
 extern str _tps_bcontact_avp;
62 62
 extern pv_spec_t _tps_acontact_spec;
63 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;
64 66
 
65 67
 #define TPS_STORAGE_LOCK_SIZE	1<<9
66 68
 static gen_lock_set_t *_tps_storage_lock_set = NULL;
... ...
@@ -343,12 +345,23 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
343 345
 			td->cp++;
344 346
 		}
345 347
 
346
-		if (_tps_contact_host.len) { // using configured hostname in the contact header
347
-			memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len);
348
-			td->cp += _tps_contact_host.len;
348
+		// contact_host AVP takes preference
349
+		if (_tps_contact_host_avp.len) {
350
+			if ((pv_get_spec_value(msg, &_tps_contact_host_avp_spec, &pv_val) != 0) &&
351
+					(pv_val.flags & PV_VAL_STR) && (pv_val.rs.len <= 0)) {
352
+				LM_ERR("could not evaluate contact_host AVP\n");
353
+				return -1;
354
+			}
355
+			memcpy(td->cp, pv_val.rs.s, pv_val.rs.len);
356
+			td->cp += pv_val.rs.len;
349 357
 		} else {
350
-			memcpy(td->cp, puri.host.s, puri.host.len);
351
-			td->cp += puri.host.len;
358
+			if (_tps_contact_host.len) { // using configured hostname in the contact header
359
+				memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len);
360
+				td->cp += _tps_contact_host.len;
361
+			} else {
362
+				memcpy(td->cp, puri.host.s, puri.host.len);
363
+				td->cp += puri.host.len;
364
+			}
352 365
 		}
353 366
 		if(puri.port.len>0) {
354 367
 			*td->cp = ':';
Browse code

topos: when contact mode is set to 1, contact uri created is malformed if received contact has no user part topos: SUBSCRIBE dialog topos: documentation for SUBSCRIBE dialog topos: add description for dialog_expire key

frederic authored on 08/02/2021 14:54:02
Showing 1 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #include "../../core/parser/contact/parse_contact.h"
42 42
 #include "../../core/parser/parse_from.h"
43 43
 #include "../../core/parser/parse_to.h"
44
+#include "../../core/parser/parse_expires.h"
44 45
 
45 46
 #include "../../lib/srdb1/db.h"
46 47
 #include "../../core/utils/sruid.h"
... ...
@@ -336,8 +337,11 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
336 337
 				td->cp += pv_val.rs.len;
337 338
 			}
338 339
 		}
339
-		*td->cp = '@';
340
-		td->cp++;
340
+
341
+		if (!((ctmode == 1) && (dir==TPS_DIR_DOWNSTREAM) && (curi.user.len <= 0))) {
342
+			*td->cp = '@';
343
+			td->cp++;
344
+		}
341 345
 
342 346
 		if (_tps_contact_host.len) { // using configured hostname in the contact header
343 347
 			memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len);
... ...
@@ -465,8 +469,8 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
465 469
 
466 470
 	/* extract the contact address */
467 471
 	if(parse_headers(msg, HDR_CONTACT_F, 0)<0 || msg->contact==NULL) {
468
-		if(td->s_method_id != METHOD_INVITE) {
469
-			/* no mandatory contact unless is INVITE - done */
472
+		if((td->s_method_id != METHOD_INVITE) && (td->s_method_id != METHOD_SUBSCRIBE)){
473
+			/* no mandatory contact unless is INVITE or SUBSCRIBE - done */
470 474
 			return 0;
471 475
 		}
472 476
 		if(msg->first_line.type==SIP_REPLY) {
... ...
@@ -504,6 +508,13 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
504 508
 		}
505 509
 	}
506 510
 
511
+	if  (td->s_method_id == METHOD_SUBSCRIBE) {
512
+		if(msg->expires && (msg->expires->body.len > 0) && (msg->expires->parsed || (parse_expires(msg->expires) >= 0))) {
513
+			td->expires = ((exp_body_t *)msg->expires->parsed)->val;
514
+		}
515
+	}
516
+
517
+
507 518
 	LM_DBG("downstream: %s - acontact: [%.*s] - bcontact: [%.*s]\n",
508 519
 			(dir==TPS_DIR_DOWNSTREAM)?"yes":"no",
509 520
 			td->a_contact.len, (td->a_contact.len>0)?td->a_contact.s:"",
... ...
@@ -1036,6 +1047,8 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1036 1047
 	db_key_t db_cols[TPS_NR_KEYS];
1037 1048
 	db1_res_t* db_res = NULL;
1038 1049
 	str sinv = str_init("INVITE");
1050
+	str ssub = str_init("SUBSCRIBE");
1051
+	int bInviteDlg = 1;
1039 1052
 	int nr_keys;
1040 1053
 	int nr_cols;
1041 1054
 	int n;
... ...
@@ -1047,6 +1060,10 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1047 1060
 	nr_keys = 0;
1048 1061
 	nr_cols = 0;
1049 1062
 
1063
+	if((get_cseq(msg)->method_id == METHOD_SUBSCRIBE) || ((get_cseq(msg)->method_id == METHOD_NOTIFY) && (msg->event->len > 0))) {
1064
+		bInviteDlg = 0;
1065
+	}
1066
+
1050 1067
 	if(mode==0) {
1051 1068
 		/* load same transaction using Via branch */
1052 1069
 		db_keys[nr_keys]=&tt_col_x_vbranch;
... ...
@@ -1075,7 +1092,7 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1075 1092
 		db_ops[nr_keys]=OP_EQ;
1076 1093
 		db_vals[nr_keys].type = DB1_STR;
1077 1094
 		db_vals[nr_keys].nul = 0;
1078
-		db_vals[nr_keys].val.str_val = sinv;
1095
+		db_vals[nr_keys].val.str_val = bInviteDlg ? sinv : ssub;
1079 1096
 		nr_keys++;
1080 1097
 	}
1081 1098
 
... ...
@@ -1407,7 +1424,7 @@ int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1407 1424
 	if(msg==NULL || md==NULL || sd==NULL)
1408 1425
 		return -1;
1409 1426
 
1410
-	if(md->s_method_id != METHOD_INVITE) {
1427
+	if((md->s_method_id != METHOD_INVITE) && (md->s_method_id != METHOD_SUBSCRIBE)) {
1411 1428
 		return 0;
1412 1429
 	}
1413 1430
 
... ...
@@ -1514,6 +1531,14 @@ int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1514 1531
 			}
1515 1532
 		}
1516 1533
 	}
1534
+	if ((mode & TPS_DBU_TIME) && ((sd->b_tag.len > 0)
1535
+			&& ((md->direction == TPS_DIR_UPSTREAM) && (msg->first_line.type==SIP_REQUEST))
1536
+			&& (msg->first_line.u.request.method_value == METHOD_SUBSCRIBE))) {
1537
+		db_ucols[nr_ucols] = &td_col_rectime;
1538
+		db_uvals[nr_ucols].type = DB1_DATETIME;
1539
+		db_uvals[nr_ucols].val.time_val = time(NULL);
1540
+		nr_ucols++;
1541
+	}
1517 1542
 
1518 1543
 	if(nr_ucols==0) {
1519 1544
 		return 0;
... ...
@@ -1543,7 +1568,7 @@ int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1543 1568
 	if(msg==NULL || md==NULL || sd==NULL)
1544 1569
 		return -1;
1545 1570
 
1546
-	if(md->s_method_id != METHOD_INVITE) {
1571
+	if((md->s_method_id != METHOD_INVITE) && (md->s_method_id != METHOD_SUBSCRIBE)) {
1547 1572
 		return 0;
1548 1573
 	}
1549 1574
 	if(msg->first_line.type==SIP_REPLY) {
... ...
@@ -1575,7 +1600,7 @@ int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1575 1600
 	if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL)
1576 1601
 		return -1;
1577 1602
 
1578
-	if(md->s_method_id != METHOD_BYE) {
1603
+	if((md->s_method_id != METHOD_BYE) && !((md->s_method_id == METHOD_SUBSCRIBE) && (md->expires == 0))) {
1579 1604
 		return 0;
1580 1605
 	}
1581 1606
 
Browse code

topos: db storage of record route based on rr_update param

Daniel-Constantin Mierla authored on 07/01/2021 09:23:35
Showing 1 changed files
... ...
@@ -1492,6 +1492,29 @@ int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1492 1492
 			nr_ucols++;
1493 1493
 		}
1494 1494
 	}
1495
+	if(sd->b_tag.len>0 && ((mode & TPS_DBU_BRR) || (mode & TPS_DBU_ARR))) {
1496
+		if(((md->direction == TPS_DIR_DOWNSTREAM) && (msg->first_line.type==SIP_REPLY)) ||
1497
+					((md->direction == TPS_DIR_UPSTREAM) && (msg->first_line.type==SIP_REQUEST))) {
1498
+			if(((sd->iflags&TPS_IFLAG_DLGON) == 0) && (mode & TPS_DBU_BRR)) {
1499
+				db_ucols[nr_ucols] = &td_col_b_rr;
1500
+				db_uvals[nr_ucols].type = DB1_STR;
1501
+				db_uvals[nr_ucols].val.str_val = TPS_STRZ(md->b_rr);
1502
+				nr_ucols++;
1503
+			}
1504
+		} else {
1505
+			if(((sd->iflags&TPS_IFLAG_DLGON) == 0) && (mode & TPS_DBU_ARR)) {
1506
+				db_ucols[nr_ucols] = &td_col_a_rr;
1507
+				db_uvals[nr_ucols].type = DB1_STR;
1508
+				db_uvals[nr_ucols].val.str_val = TPS_STRZ(md->a_rr);
1509
+				nr_ucols++;
1510
+				db_ucols[nr_ucols] = &td_col_s_rr;
1511
+				db_uvals[nr_ucols].type = DB1_STR;
1512
+				db_uvals[nr_ucols].val.str_val = TPS_STRZ(md->s_rr);
1513
+				nr_ucols++;
1514
+			}
1515
+		}
1516
+	}
1517
+
1495 1518
 	if(nr_ucols==0) {
1496 1519
 		return 0;
1497 1520
 	}
Browse code

topos: update to-tag and rr on reply even to-tag is already set

- GH #2489

Daniel-Constantin Mierla authored on 01/10/2020 08:04:50
Showing 1 changed files
... ...
@@ -1343,7 +1343,7 @@ int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1343 1343
 	nr_keys = 0;
1344 1344
 	nr_ucols = 0;
1345 1345
 
1346
-	db_keys[nr_keys]=&td_col_a_uuid;
1346
+	db_keys[nr_keys]=&tt_col_a_uuid;
1347 1347
 	db_ops[nr_keys]=OP_EQ;
1348 1348
 	db_vals[nr_keys].type = DB1_STR;
1349 1349
 	db_vals[nr_keys].nul = 0;
... ...
@@ -1366,8 +1366,7 @@ int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1366 1366
 	}
1367 1367
 
1368 1368
 	if((mode & TPS_DBU_RPLATTRS) && msg->first_line.type==SIP_REPLY) {
1369
-		if(sd->b_tag.len<=0
1370
-				&& msg->first_line.u.reply.statuscode>=180
1369
+		if(msg->first_line.u.reply.statuscode>=180
1371 1370
 				&& msg->first_line.u.reply.statuscode<200) {
1372 1371
 
1373 1372
 			db_ucols[nr_ucols] = &tt_col_y_rr;
Browse code

topos: store branch record before dialog record

Daniel-Constantin Mierla authored on 01/10/2020 07:44:59
Showing 1 changed files
... ...
@@ -545,6 +545,8 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir)
545 545
 
546 546
 	ret = tps_storage_link_msg(msg, td, dir);
547 547
 	if(ret<0) goto error;
548
+	ret = _tps_storage_api.insert_branch(td);
549
+	if(ret<0) goto error;
548 550
 	if(dialog==0) {
549 551
 		if(td->as_contact.len <= 0 && td->bs_contact.len <= 0) {
550 552
 			LM_WARN("no local address - do record routing for all initial requests\n");
... ...
@@ -552,8 +554,6 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir)
552 554
 		ret = _tps_storage_api.insert_dialog(td);
553 555
 		if(ret<0) goto error;
554 556
 	}
555
-	ret = _tps_storage_api.insert_branch(td);
556
-	if(ret<0) goto error;
557 557
 
558 558
 	return 0;
559 559
 
Browse code

topos: add two new modes for topology hiding to preserve Contact user

- add two new modes for topology hiding to preserve Contact user
- add new variables contact_mode, cparam_name, a_contact_avp and b_contact_avp
- if contact_mode is 1, the internal key will be stored in a URI parameter
instead of the Contact user, and the Contact users will be taken from the msg
- contact_mode 2 is the same as 1, but the Contact users will be taken from AVPs
- default is contact_mode 0 - the existing (old) behaviour

Henning Westerholt authored on 23/07/2020 13:48:58
Showing 1 changed files
... ...
@@ -54,6 +54,12 @@ extern db1_con_t* _tps_db_handle;
54 54
 extern db_func_t _tpsdbf;
55 55
 
56 56
 extern str _tps_contact_host;
57
+extern int _tps_contact_mode;
58
+extern str _tps_cparam_name;
59
+extern str _tps_acontact_avp;
60
+extern str _tps_bcontact_avp;
61
+extern pv_spec_t _tps_acontact_spec;
62
+extern pv_spec_t _tps_bcontact_spec;
57 63
 
58 64
 #define TPS_STORAGE_LOCK_SIZE	1<<9
59 65
 static gen_lock_set_t *_tps_storage_lock_set = NULL;
... ...
@@ -205,12 +211,14 @@ int tps_storage_branch_rm(sip_msg_t *msg, tps_data_t *td)
205 211
 /**
206 212
  *
207 213
  */
208
-int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir)
214
+int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, int ctmode)
209 215
 {
210 216
 	str sv;
211
-	sip_uri_t puri;
217
+	sip_uri_t puri, curi;
218
+	pv_value_t pv_val;
212 219
 	int i;
213 220
 	int contact_len;
221
+	int cparam_len;
214 222
 
215 223
 	if(dir==TPS_DIR_DOWNSTREAM) {
216 224
 		sv = td->bs_contact;
... ...
@@ -231,11 +239,17 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir)
231 239
 	if (_tps_contact_host.len)
232 240
 		contact_len = sv.len - puri.host.len + _tps_contact_host.len;
233 241
 
234
-	if(td->cp + 8 + (2*uuid->len) + contact_len >= td->cbuf + TPS_DATA_SIZE) {
242
+	if (ctmode == 1 || ctmode == 2) {
243
+		cparam_len = _tps_cparam_name.len;
244
+	} else {
245
+		cparam_len = 0;
246
+	}
247
+
248
+	if(td->cp + 8 + (2*uuid->len) + cparam_len + contact_len >= td->cbuf + TPS_DATA_SIZE) {
235 249
 		LM_ERR("insufficient data buffer\n");
236 250
 		return -1;
237 251
 	}
238
-
252
+	// copy uuid
239 253
 	if(dir==TPS_DIR_DOWNSTREAM) {
240 254
 		td->b_uuid.s = td->cp;
241 255
 		*td->cp = 'b';
... ...
@@ -255,51 +269,153 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir)
255 269
 
256 270
 		td->as_contact.s = td->cp;
257 271
 	}