[PATCH] fetch the message_id from submit_sm_resp

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

As discussed before, this patch adds the %w parameter to the dlr-url  
and also to the access-log-format configuration parameter. A new  
"foreign_id" member is added to the msg structure.

To clarify further:

When sending MT, you can now pass the parameter "%w" to the dlr-url,  
and it will be filled with the "message_id" that comes on the  
submit_sm_resp PDU.

You can also add the %w to your "access-log-format" and the message_id  
will be written on your access log as well.

I've used %w, maybe %f (as in "foreign") is more appropriate?

This only works with SMPP so far. I don't have any experience nor  
availability to connect to other SMSC types (I don't even know if  
there's a field similar to SMPP's "message_id" I can hook to). If  
anybody knows anything about other SMSC's and can give me some hints,  
I can try adding support for it as well.

NOTE: The %w parameter will only be available on the _first_ dlr hit.  
If you configure "real" SMSC DLR's, further notifications will be  
carried from the SMSC on deliver_sm PDU's (according to SMPP 3.4 rev  
1.2, section 2.10.1) thus the message_id won't be available. That PDU  
have the receipted_message_id field, which is a TLV and should now be  
available as meta-data.

This shouldn't be a problem anyway, since this value _should_ be the  
same as the first one, and then a match over the %d parameter could be  
made. The application could also parse the meta-data, of course.

Regards,
--
Alejandro Guerrieri
[email protected]
message_id.patch (application/octet-stream, 3.9 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	28 Nov 2008 02:43:02 -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
+ *   %w - the smsc-provided message ID
  *
  * Most escape codes should be compatible with escape codes used in
  * sms-service groups.
@@ -299,6 +300,11 @@
             }
             break;
 
+	case 'w': /* the 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	28 Nov 2008 02:43:11 -0000
@@ -392,6 +392,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 +472,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/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	28 Nov 2008 02:43:12 -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	28 Nov 2008 02:43:37 -0000
@@ -617,6 +617,14 @@
      *   * validity, deferred, rpi - we don't receive these from smsc
      *   * username, password, dlr-url, account - nonsense to send
      */
+    case 'w':
+        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, "%%");
Index: gw/smsc/smsc_smpp.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_smpp.c,v
retrieving revision 1.107
diff -a -u -r1.107 smsc_smpp.c
--- gw/smsc/smsc_smpp.c	21 Oct 2008 12:43:07 -0000	1.107
+++ gw/smsc/smsc_smpp.c	28 Nov 2008 02:43:49 -0000
@@ -1513,6 +1513,7 @@
                     }
                 }
 
+                msg->sms.foreign_id = octstr_duplicate( tmp );
                 /* SMSC ACK.. now we have the message id. */
                 if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask))
                     dlr_add(smpp->conn->id, tmp, msg);
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.