[sr-dev] git:master:684da612: dispatcher: remove duplicate code in ds_load_remove()

Henning Westerholt henningw at users.noreply.github.com
Tue Feb 5 21:11:09 CET 2019


Module: kamailio
Branch: master
Commit: 684da61208bcf5a3077a931b2808563d4d71e0e8
URL: https://github.com/kamailio/kamailio/commit/684da61208bcf5a3077a931b2808563d4d71e0e8

Author: Alex Hermann <alex at hexla.nl>
Committer: Henning Westerholt <henningw at users.noreply.github.com>
Date: 2019-02-05T21:11:03+01:00

dispatcher: remove duplicate code in ds_load_remove()

---

Modified: src/modules/dispatcher/dispatch.c

---

Diff:  https://github.com/kamailio/kamailio/commit/684da61208bcf5a3077a931b2808563d4d71e0e8.diff
Patch: https://github.com/kamailio/kamailio/commit/684da61208bcf5a3077a931b2808563d4d71e0e8.patch

---

diff --git a/src/modules/dispatcher/dispatch.c b/src/modules/dispatcher/dispatch.c
index 727dbe0cc0..9255e9eae6 100644
--- a/src/modules/dispatcher/dispatch.c
+++ b/src/modules/dispatcher/dispatch.c
@@ -1613,83 +1613,57 @@ int ds_load_replace(struct sip_msg *msg, str *duid)
 /**
  *
  */
-int ds_load_remove(struct sip_msg *msg)
+int ds_load_remove_byid(int set, str *duid)
 {
-	ds_cell_t *it;
-	int set;
 	int olddst;
 	ds_set_t *idx = NULL;
 	int i;
 
-	if((it = ds_get_cell(_dsht_load, &msg->callid->body)) == NULL) {
-		LM_ERR("cannot find load for (%.*s)\n", msg->callid->body.len,
-				msg->callid->body.s);
-		return -1;
-	}
-	set = it->dset;
 	/* get the index of the set */
 	if(ds_get_index(set, *crt_idx, &idx) != 0) {
-		ds_unlock_cell(_dsht_load, &msg->callid->body);
 		LM_ERR("destination set [%d] not found\n", set);
 		return -1;
 	}
 	olddst = -1;
 	for(i = 0; i < idx->nr; i++) {
-		if(idx->dlist[i].attrs.duid.len == it->duid.len
-				&& strncasecmp(
-						   idx->dlist[i].attrs.duid.s, it->duid.s, it->duid.len)
+		if(idx->dlist[i].attrs.duid.len == duid->len
+				&& strncasecmp(idx->dlist[i].attrs.duid.s, duid->s, duid->len)
 						   == 0) {
 			olddst = i;
 			break;
 		}
 	}
 	if(olddst == -1) {
-		ds_unlock_cell(_dsht_load, &msg->callid->body);
 		LM_ERR("old destination address not found for [%d, %.*s]\n", set,
-				it->duid.len, it->duid.s);
+				duid->len, duid->s);
 		return -1;
 	}
 
-	ds_unlock_cell(_dsht_load, &msg->callid->body);
-	ds_del_cell(_dsht_load, &msg->callid->body);
 	if(idx->dlist[olddst].dload > 0)
 		idx->dlist[olddst].dload--;
 
 	return 0;
 }
 
-
 /**
  *
  */
-int ds_load_remove_byid(int set, str *duid)
+int ds_load_remove(struct sip_msg *msg)
 {
-	int olddst;
-	ds_set_t *idx = NULL;
-	int i;
+	ds_cell_t *it;
 
-	/* get the index of the set */
-	if(ds_get_index(set, *crt_idx, &idx) != 0) {
-		LM_ERR("destination set [%d] not found\n", set);
+	if((it = ds_get_cell(_dsht_load, &msg->callid->body)) == NULL) {
+		LM_ERR("cannot find load for (%.*s)\n", msg->callid->body.len,
+				msg->callid->body.s);
 		return -1;
 	}
-	olddst = -1;
-	for(i = 0; i < idx->nr; i++) {
-		if(idx->dlist[i].attrs.duid.len == duid->len
-				&& strncasecmp(idx->dlist[i].attrs.duid.s, duid->s, duid->len)
-						   == 0) {
-			olddst = i;
-			break;
-		}
-	}
-	if(olddst == -1) {
-		LM_ERR("old destination address not found for [%d, %.*s]\n", set,
-				duid->len, duid->s);
+
+	if (ds_load_remove_byid(it->dset, &it->duid) < 0) {
+		ds_unlock_cell(_dsht_load, &msg->callid->body);
 		return -1;
 	}
-
-	if(idx->dlist[olddst].dload > 0)
-		idx->dlist[olddst].dload--;
+	ds_unlock_cell(_dsht_load, &msg->callid->body);
+	ds_del_cell(_dsht_load, &msg->callid->body);
 
 	return 0;
 }




More information about the sr-dev mailing list