Browse code

dispatcher: added defines for dst address update operations

Daniel-Constantin Mierla authored on 12/06/2018 07:01:18
Showing 3 changed files
... ...
@@ -1669,7 +1669,7 @@ static inline int ds_update_dst(
1669 1669
 	struct action act;
1670 1670
 	struct run_act_ctx ra_ctx;
1671 1671
 	switch(mode) {
1672
-		case 1:
1672
+		case DS_SETOP_RURI:
1673 1673
 			memset(&act, '\0', sizeof(act));
1674 1674
 			act.type = SET_HOSTALL_T;
1675 1675
 			act.val[0].type = STRING_ST;
... ...
@@ -1688,7 +1688,7 @@ static inline int ds_update_dst(
1688 1688
 			}
1689 1689
 			break;
1690 1690
 
1691
-		case 2:
1691
+		case DS_SETOP_XAVP:
1692 1692
 			/* no update to d-uri/r-uri */
1693 1693
 			return 0;
1694 1694
 
... ...
@@ -1703,8 +1703,9 @@ static inline int ds_update_dst(
1703 1703
 			ruri_mark_new(); /* re-use uri for serial forking */
1704 1704
 			break;
1705 1705
 	}
1706
-	if(sock)
1706
+	if(sock) {
1707 1707
 		msg->force_send_socket = sock;
1708
+	}
1708 1709
 	return 0;
1709 1710
 }
1710 1711
 
... ...
@@ -1718,12 +1719,12 @@ int ds_add_branches(sip_msg_t *msg, ds_set_t *idx, unsigned int hash, int mode)
1718 1719
 	sip_uri_t *puri = NULL;
1719 1720
 	char buri[MAX_URI_SIZE];
1720 1721
 
1721
-	if(hash+1>=idx->nr) {
1722
+	if(mode!=DS_SETOP_XAVP && hash+1>=idx->nr) {
1722 1723
 		/* nothing to add */
1723 1724
 		return 0;
1724 1725
 	}
1725 1726
 
1726
-	if(mode==1) {
1727
+	if(mode==DS_SETOP_RURI) {
1727 1728
 		/* ruri updates */
1728 1729
 		LM_DBG("adding branches with ruri\n");
1729 1730
 		if(parse_sip_msg_uri(msg)<0) {
... ...
@@ -1735,8 +1736,13 @@ int ds_add_branches(sip_msg_t *msg, ds_set_t *idx, unsigned int hash, int mode)
1735 1736
 		/* duri updates */
1736 1737
 		LM_DBG("adding branches with duri\n");
1737 1738
 	}
1738
-	for(i=hash+1; i<idx->nr; i++) {
1739
-		if(mode==1) {
1739
+	if(mode!=DS_SETOP_XAVP) {
1740
+		i = hash + 1;
1741
+	} else {
1742
+		i = hash;
1743
+	}
1744
+	for(; i<idx->nr; i++) {
1745
+		if(mode==DS_SETOP_RURI) {
1740 1746
 			/* ruri updates */
1741 1747
 			if(puri->user.len<=0) {
1742 1748
 				/* no username to preserve */
... ...
@@ -1911,7 +1917,7 @@ int ds_select_dst_limit(
1911 1917
 	}
1912 1918
 	--limit; /* reserving 1 slot for selected dst */
1913 1919
 
1914
-	if((mode == 0) && (ds_force_dst == 0)
1920
+	if((mode == DS_SETOP_DSTURI) && (ds_force_dst == 0)
1915 1921
 			&& (msg->dst_uri.s != NULL || msg->dst_uri.len > 0)) {
1916 1922
 		LM_ERR("destination already set [%.*s]\n", msg->dst_uri.len,
1917 1923
 				msg->dst_uri.s);
... ...
@@ -2140,7 +2146,7 @@ int ds_select_dst_limit(
2140 2146
 		cnt++;
2141 2147
 	}
2142 2148
 
2143
-	if(crt_added==0 && mode!=2) {
2149
+	if(crt_added==0) {
2144 2150
 		LM_DBG("using entry [%d/%d]\n", set, hash);
2145 2151
 		if(ds_add_xavp_record(idx, hash, set, alg)<0) {
2146 2152
 			LM_ERR("failed to add destination in the xavp (%d/%d)\n", hash, set);
... ...
@@ -56,6 +56,10 @@
56 56
 #define DS_MATCH_NOPORT		1
57 57
 #define DS_MATCH_NOPROTO	2
58 58
 
59
+#define DS_SETOP_DSTURI		0
60
+#define DS_SETOP_RURI		1
61
+#define DS_SETOP_XAVP		2
62
+
59 63
 #define DS_XAVP_DST_SKIP_ATTRS	1
60 64
 #define DS_XAVP_CTX_SKIP_CNT	1
61 65
 
... ...
@@ -540,8 +540,8 @@ static int w_ds_select_addr(
540 540
  */
541 541
 static int w_ds_select(struct sip_msg *msg, char *set, char *alg)
542 542
 {
543
-	return w_ds_select_addr(
544
-			msg, set, alg, 0 /* limit number of dst*/, 2 /*set no dst/uri*/);
543
+	return w_ds_select_addr(msg, set, alg, 0 /* limit number of dst*/,
544
+					DS_SETOP_XAVP /*set no dst/uri*/);
545 545
 }
546 546
 
547 547
 /**
... ...
@@ -551,7 +551,7 @@ static int w_ds_select_limit(
551 551
 		struct sip_msg *msg, char *set, char *alg, char *limit)
552 552
 {
553 553
 	return w_ds_select_addr(msg, set, alg, limit /* limit number of dst*/,
554
-			2 /*set no dst/uri*/);
554
+			DS_SETOP_XAVP /*set no dst/uri*/);
555 555
 }
556 556
 
557 557
 /**
... ...
@@ -559,8 +559,8 @@ static int w_ds_select_limit(
559 559
  */
560 560
 static int w_ds_select_dst(struct sip_msg *msg, char *set, char *alg)
561 561
 {
562
-	return w_ds_select_addr(
563
-			msg, set, alg, 0 /* limit number of dst*/, 0 /*set dst uri*/);
562
+	return w_ds_select_addr(msg, set, alg, 0 /* limit number of dst*/,
563
+				DS_SETOP_DSTURI /*set dst uri*/);
564 564
 }
565 565
 
566 566
 /**
... ...
@@ -569,8 +569,8 @@ static int w_ds_select_dst(struct sip_msg *msg, char *set, char *alg)
569 569
 static int w_ds_select_dst_limit(
570 570
 		struct sip_msg *msg, char *set, char *alg, char *limit)
571 571
 {
572
-	return w_ds_select_addr(
573
-			msg, set, alg, limit /* limit number of dst*/, 0 /*set dst uri*/);
572
+	return w_ds_select_addr(msg, set, alg, limit /* limit number of dst*/,
573
+			DS_SETOP_DSTURI /*set dst uri*/);
574 574
 }
575 575
 
576 576
 /**
... ...
@@ -578,8 +578,8 @@ static int w_ds_select_dst_limit(
578 578
  */
579 579
 static int w_ds_select_domain(struct sip_msg *msg, char *set, char *alg)
580 580
 {
581
-	return w_ds_select_addr(
582
-			msg, set, alg, 0 /* limit number of dst*/, 1 /*set host port*/);
581
+	return w_ds_select_addr(msg, set, alg, 0 /* limit number of dst*/,
582
+			DS_SETOP_RURI /*set host port*/);
583 583
 }
584 584
 
585 585
 /**
... ...
@@ -588,8 +588,8 @@ static int w_ds_select_domain(struct sip_msg *msg, char *set, char *alg)
588 588
 static int w_ds_select_domain_limit(
589 589
 		struct sip_msg *msg, char *set, char *alg, char *limit)
590 590
 {
591
-	return w_ds_select_addr(
592
-			msg, set, alg, limit /* limit number of dst*/, 1 /*set host port*/);
591
+	return w_ds_select_addr(msg, set, alg, limit /* limit number of dst*/,
592
+			DS_SETOP_RURI /*set host port*/);
593 593
 }
594 594
 
595 595
 /**
... ...
@@ -597,7 +597,7 @@ static int w_ds_select_domain_limit(
597 597
  */
598 598
 static int w_ds_next_dst(struct sip_msg *msg, char *str1, char *str2)
599 599
 {
600
-	return ds_next_dst(msg, 0 /*set dst uri*/);
600
+	return ds_next_dst(msg, DS_SETOP_DSTURI /*set dst uri*/);
601 601
 }
602 602
 
603 603
 /**
... ...
@@ -605,7 +605,7 @@ static int w_ds_next_dst(struct sip_msg *msg, char *str1, char *str2)
605 605
  */
606 606
 static int w_ds_next_domain(struct sip_msg *msg, char *str1, char *str2)
607 607
 {
608
-	return ds_next_dst(msg, 1 /*set host port*/);
608
+	return ds_next_dst(msg, DS_SETOP_RURI /*set host port*/);
609 609
 }
610 610
 
611 611
 /**