Index: gwlib/cfg.def
===================================================================
--- gwlib/cfg.def	(revision 33)
+++ gwlib/cfg.def	(working copy)
@@ -295,6 +295,7 @@
 MULTI_GROUP(smsc,
     OCTSTR(smsc)
     OCTSTR(smsc-id)
+    OCTSTR(smsc-dlr-alias)
     OCTSTR(denied-smsc-id)
     OCTSTR(allowed-smsc-id)
     OCTSTR(preferred-smsc-id)
Index: gw/smsc/smsc_emi.c
===================================================================
--- gw/smsc/smsc_emi.c	(revision 32)
+++ gw/smsc/smsc_emi.c	(working copy)
@@ -848,19 +848,19 @@
 	switch(st_code)
 	{
 	case 0: /* delivered */
-		msg = dlr_find((conn->id ? conn->id : privdata->name),
+		msg = dlr_find((conn->dlr_alias ? conn->dlr_alias : privdata->name),
 			emimsg->fields[E50_SCTS], /* timestamp */
 			emimsg->fields[E50_OADC], /* destination */
 			DLR_SUCCESS);
 		break;
 	case 1: /* buffered */
-		msg = dlr_find((conn->id ? conn->id : privdata->name),
+		msg = dlr_find((conn->dlr_alias ? conn->dlr_alias : privdata->name),
 			emimsg->fields[E50_SCTS], /* timestamp */
 			emimsg->fields[E50_OADC], /* destination */
 			DLR_BUFFERED);
 		break;
 	case 2: /* not delivered */
-		msg = dlr_find((conn->id ? conn->id : privdata->name),
+		msg = dlr_find((conn->dlr_alias ? conn->dlr_alias : privdata->name),
 			emimsg->fields[E50_SCTS], /* timestamp */
 			emimsg->fields[E50_OADC], /* destination */
 			DLR_FAIL);
@@ -1113,7 +1113,7 @@
 				    info(0,"EMI2[%s]: uhhh m is NULL, very bad",
 					 octstr_get_cstr(privdata->name));
 				} else if (DLR_IS_ENABLED_DEVICE(m->sms.dlr_mask)) {
-				    dlr_add((conn->id ? conn->id : privdata->name), ts, m);
+				    dlr_add((conn->dlr_alias ? conn->dlr_alias : privdata->name), ts, m);
 				}
 				octstr_destroy(ts);
 				octstr_destroy(adc);
Index: gw/smsc/smsc_fake.c
===================================================================
--- gw/smsc/smsc_fake.c	(revision 32)
+++ gw/smsc/smsc_fake.c	(working copy)
@@ -288,7 +288,7 @@
 
                     uuid_unparse(copy->sms.id, id);
                     tmp = octstr_create(id);
-                    dlrmsg = dlr_find(conn->id,
+                    dlrmsg = dlr_find(conn->dlr_alias,
                                       tmp, /* smsc message id */
                                       copy->sms.receiver, /* destination */
                                       dlrstat);
@@ -446,7 +446,7 @@
         char id[UUID_STR_LEN + 1];
         uuid_unparse(sms->sms.id, id);
         tmp = octstr_format("%s", id);
-        dlr_add(conn->id, tmp, sms);
+        dlr_add(conn->dlr_alias, tmp, sms);
         octstr_destroy(tmp);
     }
     gwlist_produce(privdata->outgoing_queue, copy);
Index: gw/smsc/smsc_soap.c
===================================================================
--- gw/smsc/smsc_soap.c	(revision 32)
+++ gw/smsc/smsc_soap.c	(working copy)
@@ -1173,7 +1173,7 @@
         sprintf(tmpid,"%lld",msgID);
         debug("bb.soap.read_response",0,"SOAP[%s]: ACK - id: %lld", octstr_get_cstr(privdata->name), msgID);
 
-        dlr_add(conn->id, octstr_imm(tmpid), msg);
+        dlr_add(conn->dlr_alias, octstr_imm(tmpid), msg);
 
         /* send msg back to bearerbox for recycling */
         bb_smscconn_sent(conn, msg, NULL);
@@ -1615,7 +1615,7 @@
 
     /* fetch the DLR */
 
-    dlrmsg = dlr_find(conn->id, octstr_imm(msgid), octstr_imm("receiver"), /* destination */
+    dlrmsg = dlr_find(conn->dlr_alias, octstr_imm(msgid), octstr_imm("receiver"), /* destination */
                       dlrtype);
 
     if (!dlrmsg) {
Index: gw/smsc/smsc_cgw.c
===================================================================
--- gw/smsc/smsc_cgw.c	(revision 32)
+++ gw/smsc/smsc_cgw.c	(working copy)
@@ -1134,19 +1134,19 @@
 
             switch (stat) {
             case 0:     /* delivered */
-                dlrmsg = dlr_find(conn->id,
+                dlrmsg = dlr_find(conn->dlr_alias,
                                             ts,     /* timestamp */
                                             msid,   /* destination */
                                   DLR_SUCCESS);
                 break;
             case 1:     /* buffered */
-                dlrmsg = dlr_find(conn->id,
+                dlrmsg = dlr_find(conn->dlr_alias,
                                             ts,     /* timestamp */
                                             msid,   /* destination */
                                   DLR_BUFFERED);
                 break;
             case 2:     /* not delivered */
-                dlrmsg = dlr_find(conn->id,
+                dlrmsg = dlr_find(conn->dlr_alias,
                                             ts,     /* timestamp */
                                             msid,   /* destination */
                                   DLR_FAIL);
@@ -1181,7 +1181,7 @@
             octstr_append_char(ts, '-');
             octstr_append_decimal(ts, trn);
 
-            dlr_add(conn->id, ts, msg);
+            dlr_add(conn->dlr_alias, ts, msg);
 
             octstr_destroy(ts);
             privdata->dlr[trn] = 1;
Index: gw/smsc/smsc_cimd2.c
===================================================================
--- gw/smsc/smsc_cimd2.c	(revision 32)
+++ gw/smsc/smsc_cimd2.c	(working copy)
@@ -1976,7 +1976,7 @@
 
     ret = cimd2_request(packet, conn, &ts);
     if((ret == 0) && (ts) && DLR_IS_SUCCESS_OR_FAIL(msg->sms.dlr_mask) && !pdata->no_dlr) {
-        dlr_add(conn->name, ts, msg);
+        dlr_add((conn->dlr_alias ? conn->dlr_alias : conn->name), ts, msg);
     }
     octstr_destroy(ts);
     packet_destroy(packet);
@@ -2114,7 +2114,7 @@
         code = 0;
     }
     if(code)
-    	msg = dlr_find(conn->name, timestamp, destination, code);
+    	msg = dlr_find((conn->dlr_alias ? conn->dlr_alias : conn->name), timestamp, destination, code);
     else
         msg = NULL;
 
Index: gw/smsc/smsc_oisd.c
===================================================================
--- gw/smsc/smsc_oisd.c	(revision 32)
+++ gw/smsc/smsc_oisd.c	(working copy)
@@ -1171,7 +1171,7 @@
 
     ret = oisd_request(packet, conn, &ts);
     if((ret == 0) && (ts) && DLR_IS_SUCCESS_OR_FAIL(msg->sms.dlr_mask) && !pdata->no_dlr) {
-        dlr_add(conn->name, ts, msg);
+        dlr_add((conn->dlr_alias ? conn->dlr_alias : conn->name), ts, msg);
     }
     octstr_destroy(ts);
     packet_destroy(packet);
@@ -1308,7 +1308,7 @@
     }
 
     if (code)
-        msg = dlr_find(conn->name, timestamp, destination, code);
+        msg = dlr_find((conn->dlr_alias ? conn->dlr_alias : conn->name), timestamp, destination, code);
 
     octstr_destroy(destination);
     octstr_destroy(timestamp);
Index: gw/smsc/smsc_smpp.c
===================================================================
--- gw/smsc/smsc_smpp.c	(revision 33)
+++ gw/smsc/smsc_smpp.c	(working copy)
@@ -1364,7 +1364,7 @@
             }
         }
 
-        dlrmsg = dlr_find(smpp->conn->id,
+        dlrmsg = dlr_find(smpp->conn->dlr_alias,
             tmp, /* smsc message id */
             destination_addr, /* destination */
             dlrstat);
@@ -1605,7 +1605,7 @@
 
                 /* SMSC ACK.. now we have the message id. */
                 if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask))
-                    dlr_add(smpp->conn->id, tmp, msg);
+                    dlr_add(smpp->conn->dlr_alias, tmp, msg);
 
                 octstr_destroy(tmp);
                 bb_smscconn_sent(smpp->conn, msg, NULL);
Index: gw/smsc/smsc_http.c
===================================================================
--- gw/smsc/smsc_http.c	(revision 32)
+++ gw/smsc/smsc_http.c	(working copy)
@@ -494,7 +494,7 @@
     
         /* add to our own DLR storage */               
         if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask))
-            dlr_add(conn->id, mid, msg);
+            dlr_add(conn->dlr_alias, mid, msg);
 
         octstr_destroy(mid);            
             
@@ -573,7 +573,7 @@
         /* we got a DLR, and we don't require additional values */
         Msg *dlrmsg;
         
-        dlrmsg = dlr_find(conn->id,
+        dlrmsg = dlr_find(conn->dlr_alias,
             dlrmid, /* message id */
             to, /* destination */
             dlrmask);
@@ -762,7 +762,7 @@
 
             /* SMSC ACK.. now we have the message id. */
             if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask))
-                dlr_add(conn->id, msgid, msg);
+                dlr_add(conn->dlr_alias, msgid, msg);
 
             bb_smscconn_sent(conn, msg, NULL);
 
@@ -862,7 +862,7 @@
 	    dlrstat = 16; /* smsc reject */
 	    break;
 	}
-        dlrmsg = dlr_find(conn->id,
+        dlrmsg = dlr_find(conn->dlr_alias,
             apimsgid, /* smsc message id */
             dest , /* destination */
             dlrstat);
@@ -1267,7 +1267,7 @@
 
             /* SMSC ACK.. now we have the message id. */
             if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask))
-                dlr_add(conn->id, mid, msg);
+                dlr_add(conn->dlr_alias, mid, msg);
 
             octstr_destroy(mid);
             bb_smscconn_sent(conn, msg, NULL);
@@ -1341,7 +1341,7 @@
         else
             dlrstat = DLR_FAIL;
 
-        dlrmsg = dlr_find(conn->id,
+        dlrmsg = dlr_find(conn->dlr_alias,
             mid, /* smsc message id */
             dest , /* destination */
             dlrstat);
Index: gw/smsc/smsc_at.c
===================================================================
--- gw/smsc/smsc_at.c	(revision 32)
+++ gw/smsc/smsc_at.c	(working copy)
@@ -2101,7 +2101,7 @@
      * categories. It will catch "reserved" values where the first 3 MSBits 
      * are not set as "Success" which may not be correct. */
 
-    if ((dlrmsg = dlr_find(privdata->conn->id, msg_id, receiver, type)) == NULL) {
+    if ((dlrmsg = dlr_find(privdata->conn->dlr_alias, msg_id, receiver, type)) == NULL) {
         debug("bb.smsc.at2", 1, "AT2[%s]: Received delivery notification but can't find that ID in the DLR storage",
               octstr_get_cstr(privdata->name));
 	    goto error;
@@ -2296,7 +2296,7 @@
                     else {
                         Octstr *dlrmsgid = octstr_format("%d", msg_id);
 
-                        dlr_add(privdata->conn->id, dlrmsgid, msg);
+                        dlr_add(privdata->conn->dlr_alias, dlrmsgid, msg);
 
                         O_DESTROY(dlrmsgid);
 
Index: gw/bb_smscconn.c
===================================================================
--- gw/bb_smscconn.c	(revision 32)
+++ gw/bb_smscconn.c	(working copy)
@@ -275,7 +275,7 @@
 	    reply = octstr_create("");
 
 	octstr_insert_data(reply, 0, "ACK/", 4);
-        dlrmsg = create_dlr_from_msg((conn->id?conn->id:conn->name), sms,
+        dlrmsg = create_dlr_from_msg((conn->dlr_alias?conn->dlr_alias:conn->name), sms,
 	                reply, DLR_SMSC_SUCCESS);
         if (dlrmsg != NULL) {
             bb_smscconn_receive(conn, dlrmsg);
@@ -342,7 +342,7 @@
 	        reply = octstr_create("");
 
 	    octstr_insert_data(reply, 0, "NACK/", 5);
-            dlrmsg = create_dlr_from_msg((conn ? (conn->id?conn->id:conn->name) : NULL), sms,
+            dlrmsg = create_dlr_from_msg((conn ? (conn->dlr_alias?conn->dlr_alias:conn->name) : NULL), sms,
 	                                 reply, DLR_SMSC_FAIL);
             if (dlrmsg != NULL) {
                 bb_smscconn_receive(conn, dlrmsg);
Index: gw/smscconn.c
===================================================================
--- gw/smscconn.c	(revision 32)
+++ gw/smscconn.c	(working copy)
@@ -222,6 +222,10 @@
         octstr_destroy(tmp);
         info(0, "Set throughput to %.3f for smsc id <%s>", conn->throughput, octstr_get_cstr(conn->id));
     }
+    /* Set the alias to be used when storing dlrs. Equals the connection id if empty */
+    GET_OPTIONAL_VAL(conn->dlr_alias, "smsc-dlr-alias");
+    if (conn->dlr_alias == NULL)
+        conn->dlr_alias = octstr_duplicate(conn->id);
 
     /* configure the internal rerouting rules for this smsc id */
     init_reroute(conn, grp);
@@ -335,6 +339,7 @@
 
     octstr_destroy(conn->name);
     octstr_destroy(conn->id);
+    octstr_destroy(conn->dlr_alias);
     gwlist_destroy(conn->allowed_smsc_id, octstr_destroy_item);
     gwlist_destroy(conn->denied_smsc_id, octstr_destroy_item);
     gwlist_destroy(conn->preferred_smsc_id, octstr_destroy_item);
Index: gw/smscconn_p.h
===================================================================
--- gw/smscconn_p.h	(revision 32)
+++ gw/smscconn_p.h	(working copy)
@@ -168,6 +168,7 @@
     Octstr *name;		/* Descriptive name filled from connection info */
     Octstr *id;			/* Abstract name specified in configuration and
 				   used for logging and routing */
+    Octstr *dlr_alias;
     List *allowed_smsc_id;
     List *denied_smsc_id;
     List *preferred_smsc_id;
