Index: gw/bb_smscconn.c
===================================================================
RCS file: /home/cvs/gateway/gw/bb_smscconn.c,v
retrieving revision 1.103
diff -u -b -w -r1.103 bb_smscconn.c
--- gw/bb_smscconn.c	8 Jul 2009 17:37:36 -0000	1.103
+++ gw/bb_smscconn.c	9 Jul 2009 13:47:37 -0000
@@ -751,76 +751,60 @@
 int smsc2_restart_smsc(Octstr *id)
 {
     CfgGroup *grp;
-    SMSCConn *conn, *new_conn;
+    SMSCConn *conn;
     Octstr *smscid = NULL;
     long i = -1;
-    int hit;
-    int num = 0;
     int success = 0;
 
     if (!smsc_running)
         return -1;
 
     gw_rwlock_wrlock(&smsc_list_lock);
+    gwlist_add_producer(smsc_list);
 
-    if (bb_reload_smsc_groups() != 0) {
+    while((i = smsc2_find(id, ++i)) != -1) {
+        conn = gwlist_get(smsc_list, i);
+        gwlist_delete(smsc_list, i, 1);
+        smscconn_shutdown(conn, 0);
+        smscconn_destroy(conn);
+        success = 1;
+        i--;
+    }
+
+    if (success == 0) {
+        error(0, "Cannot reload SMSC %s: not found", octstr_get_cstr(id));
+        gwlist_remove_producer(smsc_list);
         gw_rwlock_unlock(&smsc_list_lock);
         return -1;
     }
-    /* find the specific smsc via id */
-    while((i = smsc2_find(id, ++i)) != -1) {
-        long group_index;
-        /* check if smsc has online status already */
-        conn = gwlist_get(smsc_list, i);
-        if (conn != NULL && smscconn_status(conn) != SMSCCONN_DEAD) {
-            warning(0, "HTTP: Could not re-start already running smsc-id `%s'",
-                octstr_get_cstr(id));
-            continue;
+
+    /* reload the groups from the config file */
+    if (bb_reload_smsc_groups() != 0) {
+        gwlist_remove_producer(smsc_list);
+        gw_rwlock_unlock(&smsc_list_lock);
+        return -1;
         }
-        /* find the group with equal smsc (admin-)id */
-        hit = -1;
+
+    /* add the new group entries */
+    success = 0;
         grp = NULL;
-        for (group_index = 0; group_index < gwlist_len(smsc_groups) && 
-             (grp = gwlist_get(smsc_groups, group_index)) != NULL; group_index++) {
+    for (i = 0; i < gwlist_len(smsc_groups) &&
+        (grp = gwlist_get(smsc_groups, i)) != NULL; i++) {
             smscid = cfg_get(grp, octstr_imm("smsc-admin-id"));
             if (smscid == NULL)
             smscid = cfg_get(grp, octstr_imm("smsc-id"));
+
             if (smscid != NULL && octstr_compare(smscid, id) == 0) {
-                if (hit < 0)
-                    hit = 0;
-                if (hit == num)
-                    break;
-                else
-                    hit++;
-            }
-            octstr_destroy(smscid);
-            smscid = NULL;
-        }
-        octstr_destroy(smscid);
-        if (hit != num) {
-            /* config group not found */
-            error(0, "HTTP: Could not find config for smsc-id `%s'", octstr_get_cstr(id));
-            break;
+            conn = smscconn_create(grp, 1);
+            if (conn != NULL) {
+                gwlist_append(smsc_list, conn);
+                smscconn_start(conn);
+                success = 1;
         }
-        
-        info(0,"HTTP: Re-starting smsc-id `%s'", octstr_get_cstr(id));
-
-        new_conn = smscconn_create(grp, 1);
-        if (new_conn == NULL) {
-            error(0, "Start of SMSC connection failed, smsc-id `%s'", octstr_get_cstr(id));
-            continue; /* keep old connection on the list */
         }
-        
-        /* drop old connection from the active smsc list */
-        gwlist_delete(smsc_list, i, 1);
-        /* destroy the connection */
-        smscconn_destroy(conn);
-        gwlist_insert(smsc_list, i, new_conn);
-        smscconn_start(new_conn);
-        success = 1;
-        num++;
     }
 
+    gwlist_remove_producer(smsc_list);
     gw_rwlock_unlock(&smsc_list_lock);
     
     if (success == 0) {
@@ -851,6 +835,7 @@
         smscconn_shutdown(conn, 0);
         smscconn_destroy(conn);
         success = 1;
+        i--;
     }
     gwlist_remove_producer(smsc_list);
 
