Browse code

dispatcher: remove duplicate code in ds_load_remove()

Alex Hermann authored on 05/11/2018 09:37:02 • Henning Westerholt committed on 05/02/2019 20:11:03
Showing 1 changed files
... ...
@@ -1613,83 +1613,57 @@ int ds_load_replace(struct sip_msg *msg, str *duid)
1613 1613
 /**
1614 1614
  *
1615 1615
  */
1616
-int ds_load_remove(struct sip_msg *msg)
1616
+int ds_load_remove_byid(int set, str *duid)
1617 1617
 {
1618
-	ds_cell_t *it;
1619
-	int set;
1620 1618
 	int olddst;
1621 1619
 	ds_set_t *idx = NULL;
1622 1620
 	int i;
1623 1621
 
1624
-	if((it = ds_get_cell(_dsht_load, &msg->callid->body)) == NULL) {
1625
-		LM_ERR("cannot find load for (%.*s)\n", msg->callid->body.len,
1626
-				msg->callid->body.s);
1627
-		return -1;
1628
-	}
1629
-	set = it->dset;
1630 1622
 	/* get the index of the set */
1631 1623
 	if(ds_get_index(set, *crt_idx, &idx) != 0) {
1632
-		ds_unlock_cell(_dsht_load, &msg->callid->body);
1633 1624
 		LM_ERR("destination set [%d] not found\n", set);
1634 1625
 		return -1;
1635 1626
 	}
1636 1627
 	olddst = -1;
1637 1628
 	for(i = 0; i < idx->nr; i++) {
1638
-		if(idx->dlist[i].attrs.duid.len == it->duid.len
1639
-				&& strncasecmp(
1640
-						   idx->dlist[i].attrs.duid.s, it->duid.s, it->duid.len)
1629
+		if(idx->dlist[i].attrs.duid.len == duid->len
1630
+				&& strncasecmp(idx->dlist[i].attrs.duid.s, duid->s, duid->len)
1641 1631
 						   == 0) {
1642 1632
 			olddst = i;
1643 1633
 			break;
1644 1634
 		}
1645 1635
 	}
1646 1636
 	if(olddst == -1) {
1647
-		ds_unlock_cell(_dsht_load, &msg->callid->body);
1648 1637
 		LM_ERR("old destination address not found for [%d, %.*s]\n", set,
1649
-				it->duid.len, it->duid.s);
1638
+				duid->len, duid->s);
1650 1639
 		return -1;
1651 1640
 	}
1652 1641
 
1653
-	ds_unlock_cell(_dsht_load, &msg->callid->body);
1654
-	ds_del_cell(_dsht_load, &msg->callid->body);
1655 1642
 	if(idx->dlist[olddst].dload > 0)
1656 1643
 		idx->dlist[olddst].dload--;
1657 1644
 
1658 1645
 	return 0;
1659 1646
 }
1660 1647
 
1661
-
1662 1648
 /**
1663 1649
  *
1664 1650
  */
1665
-int ds_load_remove_byid(int set, str *duid)
1651
+int ds_load_remove(struct sip_msg *msg)
1666 1652
 {
1667
-	int olddst;
1668
-	ds_set_t *idx = NULL;
1669
-	int i;
1653
+	ds_cell_t *it;
1670 1654
 
1671
-	/* get the index of the set */
1672
-	if(ds_get_index(set, *crt_idx, &idx) != 0) {
1673
-		LM_ERR("destination set [%d] not found\n", set);
1655
+	if((it = ds_get_cell(_dsht_load, &msg->callid->body)) == NULL) {
1656
+		LM_ERR("cannot find load for (%.*s)\n", msg->callid->body.len,
1657
+				msg->callid->body.s);
1674 1658
 		return -1;
1675 1659
 	}
1676
-	olddst = -1;
1677
-	for(i = 0; i < idx->nr; i++) {
1678
-		if(idx->dlist[i].attrs.duid.len == duid->len
1679
-				&& strncasecmp(idx->dlist[i].attrs.duid.s, duid->s, duid->len)
1680
-						   == 0) {
1681
-			olddst = i;
1682
-			break;
1683
-		}
1684
-	}
1685
-	if(olddst == -1) {
1686
-		LM_ERR("old destination address not found for [%d, %.*s]\n", set,
1687
-				duid->len, duid->s);
1660
+
1661
+	if (ds_load_remove_byid(it->dset, &it->duid) < 0) {
1662
+		ds_unlock_cell(_dsht_load, &msg->callid->body);
1688 1663
 		return -1;
1689 1664
 	}
1690
-
1691
-	if(idx->dlist[olddst].dload > 0)
1692
-		idx->dlist[olddst].dload--;
1665
+	ds_unlock_cell(_dsht_load, &msg->callid->body);
1666
+	ds_del_cell(_dsht_load, &msg->callid->body);
1693 1667
 
1694 1668
 	return 0;
1695 1669
 }