[PATCH] get the "foreign" (smsc-provided) message_id

Alejandro Guerrieri <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi,

Attached is the patch to provide the SMSC's message_id as %F.

As Alex suggested, the parameter is now added into dlr_add(), thus  
this should work for all SMSC's supporting the parameter.

I had to modify dlr_add()'s prototype and remove msg's "const"  
attribute to be able to modify it inside the function of course.





Regards,
--
Alejandro Guerrieri
[email protected]
message_id.patch (application/octet-stream, 4.6 KB)
Index: gw/bb_alog.c
===================================================================
RCS file: /home/cvs/gateway/gw/bb_alog.c,v
retrieving revision 1.15
diff -a -u -r1.15 bb_alog.c
--- gw/bb_alog.c	9 Jan 2008 20:06:57 -0000	1.15
+++ gw/bb_alog.c	30 Nov 2008 18:39:25 -0000
@@ -100,6 +100,7 @@
  *   %t - the time of the message, formatted as "YYYY-MM-DD HH:MM:SS"
  *   %T - the time of the message, in UNIX epoch timestamp format
  *   %I - the internal message ID
+ *   %F - the "foreign" (smsc-provided) message ID
  *
  * Most escape codes should be compatible with escape codes used in
  * sms-service groups.
@@ -299,6 +300,11 @@
             }
             break;
 
+	case 'F': /* the "foreign" (smsc-provided) message id */
+	    if (msg->sms.foreign_id != NULL)
+	        octstr_append(result, msg->sms.foreign_id);
+	    break;
+
         /* XXX add more here if needed */
 
 	case '%':
Index: gw/dlr.c
===================================================================
RCS file: /home/cvs/gateway/gw/dlr.c,v
retrieving revision 1.56
diff -a -u -r1.56 dlr.c
--- gw/dlr.c	19 Feb 2008 11:12:30 -0000	1.56
+++ gw/dlr.c	30 Nov 2008 18:39:29 -0000
@@ -311,10 +311,15 @@
 /*
  * Add new dlr entry into dlr storage
  */
-void dlr_add(const Octstr *smsc, const Octstr *ts, const Msg *msg)
+void dlr_add(const Octstr *smsc, const Octstr *ts, Msg *msg)
 {
     struct dlr_entry *dlr = NULL;
 
+    /* Add the foreign_id so all SMSC modules can use it */
+    if (msg->sms.foreign_id != NULL)
+        octstr_destroy(msg->sms.foreign_id);
+    msg->sms.foreign_id = octstr_duplicate(ts);
+
     if(octstr_len(smsc) == 0) {
 	warning(0, "DLR[%s]: Can't add a dlr without smsc-id", dlr_type());
         return;
@@ -359,7 +364,7 @@
 {
     Msg	*msg = NULL;
     struct dlr_entry *dlr = NULL;
-    
+
     if(octstr_len(smsc) == 0) {
 	warning(0, "DLR[%s]: Can't find a dlr without smsc-id", dlr_type());
         return NULL;
@@ -392,6 +397,10 @@
         O_SET(msg->sms.sender, dlr->source);
         /* if dlr_url was present, recode it here again */
         O_SET(msg->sms.dlr_url, dlr->url);
+        /* add the foreign_id */
+        Octstr *tmp = octstr_duplicate(ts);
+        O_SET(msg->sms.foreign_id, tmp);
+        octstr_destroy(tmp);
         /* 
          * insert original message to the data segment 
          * later in the smsc module 
@@ -468,6 +477,7 @@
     dlrmsg->sms.dlr_url = octstr_duplicate(msg->sms.dlr_url);
     dlrmsg->sms.msgdata = octstr_duplicate(reply);
     dlrmsg->sms.boxc_id = octstr_duplicate(msg->sms.boxc_id);
+    dlrmsg->sms.foreign_id = octstr_duplicate(msg->sms.foreign_id);
     time(&dlrmsg->sms.time);
 
     debug("dlr.dlr", 0,"SMSC[%s]: DLR = %s",
Index: gw/dlr.h
===================================================================
RCS file: /home/cvs/gateway/gw/dlr.h,v
retrieving revision 1.25
diff -a -u -r1.25 dlr.h
--- gw/dlr.h	9 Jan 2008 20:06:57 -0000	1.25
+++ gw/dlr.h	30 Nov 2008 18:39:30 -0000
@@ -95,7 +95,7 @@
 /* 
  * Add a new entry to the list
  */
-void dlr_add(const Octstr *smsc, const Octstr *ts, const Msg *msg);
+void dlr_add(const Octstr *smsc, const Octstr *ts, Msg *msg);
 
 /* 
  * Find an entry in the list. If there is one a message is returned and 
Index: gw/msg-decl.h
===================================================================
RCS file: /home/cvs/gateway/gw/msg-decl.h,v
retrieving revision 1.34
diff -a -u -r1.34 msg-decl.h
--- gw/msg-decl.h	9 Jan 2008 20:06:57 -0000	1.34
+++ gw/msg-decl.h	30 Nov 2008 18:39:30 -0000
@@ -86,6 +86,7 @@
 		INTEGER(time);
 		OCTSTR(smsc_id);
 		OCTSTR(smsc_number);
+		OCTSTR(foreign_id);
 		OCTSTR(service);
 		OCTSTR(account);
 		UUID(id);
@@ -107,8 +108,8 @@
 		INTEGER(msg_left);
 		VOID(split_parts);
 		INTEGER(priority);
-                INTEGER(resend_try);
-                INTEGER(resend_time);
+		INTEGER(resend_try);
+		INTEGER(resend_time);
 	})
 
 MSG(ack,
Index: gw/urltrans.c
===================================================================
RCS file: /home/cvs/gateway/gw/urltrans.c,v
retrieving revision 1.108
diff -a -u -r1.108 urltrans.c
--- gw/urltrans.c	24 Jun 2008 11:28:41 -0000	1.108
+++ gw/urltrans.c	30 Nov 2008 18:39:43 -0000
@@ -617,6 +617,14 @@
      *   * validity, deferred, rpi - we don't receive these from smsc
      *   * username, password, dlr-url, account - nonsense to send
      */
+    case 'F':
+        if (request->sms.foreign_id == NULL)
+        	break;
+        enc = octstr_duplicate(request->sms.foreign_id);
+        octstr_url_encode(enc);
+        octstr_append(result, enc);
+        octstr_destroy(enc);
+        break;
 
     case '%':
         octstr_format_append(result, "%%");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.