Browse code

dialog: store call-id, r-uri, f-uri and t-uri with 0-ending char

- can simplify matching with standard string comparison and regexp

Daniel-Constantin Mierla authored on 05/12/2018 11:40:16
Showing 1 changed files
... ...
@@ -457,15 +457,16 @@ struct dlg_cell* build_new_dlg( str *callid, str *from_uri, str *to_uri,
457 457
 	int len;
458 458
 	char *p;
459 459
 
460
-	len = sizeof(struct dlg_cell) + callid->len + from_uri->len +
461
-		to_uri->len + req_uri->len;
460
+	/* space for dialog  structure and values with 0-ending char */
461
+	len = sizeof(struct dlg_cell) + callid->len + 1 + from_uri->len + 1
462
+		+ to_uri->len + 1 + req_uri->len + 1;
462 463
 	dlg = (struct dlg_cell*)shm_malloc( len );
463 464
 	if (dlg==0) {
464 465
 		LM_ERR("no more shm mem (%d)\n",len);
465 466
 		return 0;
466 467
 	}
467 468
 
468
-	memset( dlg, 0, len);
469
+	memset(dlg, 0, len);
469 470
 	dlg->state = DLG_STATE_UNCONFIRMED;
470 471
 	dlg->init_ts = (unsigned int)time(NULL);
471 472
 
... ...
@@ -476,23 +477,23 @@ struct dlg_cell* build_new_dlg( str *callid, str *from_uri, str *to_uri,
476 476
 
477 477
 	dlg->callid.s = p;
478 478
 	dlg->callid.len = callid->len;
479
-	memcpy( p, callid->s, callid->len);
480
-	p += callid->len;
479
+	memcpy(p, callid->s, callid->len);
480
+	p += callid->len + 1;
481 481
 
482 482
 	dlg->from_uri.s = p;
483 483
 	dlg->from_uri.len = from_uri->len;
484
-	memcpy( p, from_uri->s, from_uri->len);
485
-	p += from_uri->len;
484
+	memcpy(p, from_uri->s, from_uri->len);
485
+	p += from_uri->len + 1;
486 486
 
487 487
 	dlg->to_uri.s = p;
488 488
 	dlg->to_uri.len = to_uri->len;
489
-	memcpy( p, to_uri->s, to_uri->len);
490
-	p += to_uri->len; 
489
+	memcpy(p, to_uri->s, to_uri->len);
490
+	p += to_uri->len + 1;
491 491
 
492 492
 	dlg->req_uri.s = p;
493 493
 	dlg->req_uri.len = req_uri->len;
494
-	memcpy( p, req_uri->s, req_uri->len);
495
-	p += req_uri->len;
494
+	memcpy(p, req_uri->s, req_uri->len);
495
+	p += req_uri->len + 1;
496 496
 
497 497
 	if ( p!=(((char*)dlg)+len) ) {
498 498
 		LM_CRIT("buffer overflow\n");