[sr-dev] git:master: modules_k/dispatcher: Fixes to handling of empty DB and hostnames that cannot be resolved

Peter Dunkley peter.dunkley at crocodile-rcs.com
Fri Oct 14 15:03:05 CEST 2011


Module: sip-router
Branch: master
Commit: 92da08fde8ee3273cb7b181f3320fd0f613aeb17
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=92da08fde8ee3273cb7b181f3320fd0f613aeb17

Author: pd <peter.dunkley at crocodile-rcs.com>
Committer: pd <peter.dunkley at crocodile-rcs.com>
Date:   Fri Oct 14 14:00:36 2011 +0100

modules_k/dispatcher: Fixes to handling of empty DB and hostnames that cannot be resolved

- Dispatcher handles an empty DB on start-up, but it doesn't do so well on a
  reload - especially when the DB is now empty, but previously contained
  records.  This commit fixes these issues.
- Dispatcher also doesn't cope well when a hostname cannot be resolved to an
  address.  This means a mis-typed DB entry can stop Kamailio from starting up
  properly.  Also fixed in this commit.

---

 modules_k/dispatcher/dispatch.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/modules_k/dispatcher/dispatch.c b/modules_k/dispatcher/dispatch.c
index 2c28fb6..9bb942a 100644
--- a/modules_k/dispatcher/dispatch.c
+++ b/modules_k/dispatcher/dispatch.c
@@ -252,6 +252,8 @@ int add_dest2list(int id, str uri, int flags, int priority, str *attrs,
 	static char hn[256];
 	struct hostent* he;
 	struct sip_uri puri;
+	int orig_id = 0, orig_nr = 0;
+	ds_set_t *orig_ds_lists = ds_lists[list_idx];
 
 	/* check uri */
 	if(parse_uri(uri.s, uri.len, &puri)!=0 || puri.host.len>254)
@@ -283,6 +285,8 @@ int add_dest2list(int id, str uri, int flags, int priority, str *attrs,
 		ds_lists[list_idx] = sp;
 		*setn = *setn+1;
 	}
+	orig_id = sp->id;
+	orig_nr = sp->nr;
 	sp->id = id;
 	sp->nr++;
 
@@ -365,6 +369,18 @@ err:
 			shm_free(dp->uri.s);
 		shm_free(dp);
 	}
+
+	if (sp != NULL)
+	{
+		sp->id = orig_id;
+		sp->nr = orig_nr;
+		if (sp->nr == 0)
+		{
+			shm_free(sp);
+			ds_lists[list_idx] = orig_ds_lists;
+		}
+	}
+
 	return -1;
 }
 
@@ -566,9 +582,8 @@ int ds_load_list(char *lfile)
 add_destination:
 		if(add_dest2list(id, uri, flags, priority, &attrs,
 					*next_idx, &setn) != 0)
-			goto error;
-					
-		
+			LM_WARN("unable to add destination %.*s to set %d -- skipping\n",
+					uri.len, uri.s, id);
 next_line:
 		p = fgets(line, 256, f);
 	}
@@ -720,11 +735,7 @@ int ds_load_db(void)
 	nr_rows = RES_ROW_N(res);
 	rows 	= RES_ROWS(res);
 	if(nr_rows == 0)
-	{
 		LM_WARN("no dispatching data in the db -- empty destination set\n");
-		ds_dbf.free_result(ds_db_handle, res);
-		return 0;
-	}
 
 	setn = 0;
 	*next_idx = (*crt_idx + 1)%2;
@@ -752,8 +763,8 @@ int ds_load_db(void)
 		}
 		if(add_dest2list(id, uri, flags, priority, &attrs,
 					*next_idx, &setn) != 0)
-			goto err2;
-
+			LM_WARN("unable to add destination %.*s to set %d -- skipping\n",
+					uri.len, uri.s, id);
 	}
 	ds_dbf.free_result(ds_db_handle, res);
 




More information about the sr-dev mailing list