[PATCH] SMPP deferred and validity period

Alex Judd <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
While we're there adding quick patches to SMPP here's one to add defered 
and validity support to SMPP. I've done limited testing with it so would 
appreciate any of the other SMPP users giving it a once over.

SMPP v3.4 specifies tenths of second which I just set to 0 as defacto and 
we calculate 1/4 hour time relative to UTC/GMT according to the SMPP Time 
Format documentation (section 7.5)

Alex

-- 
Alex Judd
http://www.skywire.co.uk
smsc_smpp.c.diff (text/plain, 2.2 KB)
Index: gw/smsc_smpp.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_smpp.c,v
retrieving revision 1.58
diff -u -r1.58 smsc_smpp.c
--- gw/smsc_smpp.c	20 May 2002 14:14:13 -0000	1.58
+++ gw/smsc_smpp.c	21 May 2002 15:34:35 -0000
@@ -222,6 +222,11 @@
 static SMPP_PDU *msg_to_pdu(SMPP *smpp, Msg *msg) 
 { 
     SMPP_PDU *pdu; 
+    char buffer[16];
+    Octstr *relation_UTC_time;
+    struct tm gmtime, localtime, tm;
+    int gwqdiff;
+
     pdu = smpp_pdu_create(submit_sm,  
     	    	    	  counter_increase(smpp->message_id_counter)); 
     	    	    
@@ -290,9 +295,41 @@
         if (pdu->u.submit_sm.data_coding == 0 ) /* no reencoding for unicode! */ 
             charset_latin1_to_gsm(pdu->u.submit_sm.short_message);		 
     } 
+
+    /* work out 1/4 hour difference between local time and UTC/GMT */
+    gmtime = gw_gmtime(time(NULL));
+    localtime = gw_localtime(time(NULL));
+    if (localtime.tm_hour >= gmtime.tm_hour) {
+        relation_UTC_time = octstr_create("+");
+        gwqdiff = (localtime.tm_hour - gmtime.tm_hour) * 4;
+    } else {
+        relation_UTC_time = octstr_create("-");
+        gwqdiff = (gmtime.tm_hour - localtime.tm_hour) * 4;
+    }
+
+    if (msg->sms.validity) {
+        tm = gw_localtime(time(NULL) + msg->sms.validity * 60);
+        sprintf(buffer, "%02d%02d%02d%02d%02d%02d0%01d%02d%1s",
+           tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday,
+           tm.tm_hour, tm.tm_min, tm.tm_sec,
+           0, gwqdiff, relation_UTC_time );
+        pdu->u.submit_sm.validity_period = octstr_create(buffer);
+    }
+
+    if (msg->sms.deferred) {
+        tm = gw_localtime(time(NULL) + msg->sms.deferred * 60);
+        sprintf(buffer, "%02d%02d%02d%02d%02d%02d0%01d%02d%1s",
+           tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday,
+           tm.tm_hour, tm.tm_min, tm.tm_sec,
+           0, gwqdiff, relation_UTC_time );
+        pdu->u.submit_sm.schedule_delivery_time = octstr_create(buffer);
+    }
+
     /* ask for the delivery reports if needed */ 
     if (msg->sms.dlr_mask & (DLR_SUCCESS|DLR_FAIL)) 
         pdu->u.submit_sm.registered_delivery = 1;  
+
+    octstr_destroy(relation_UTC_time);
  
     return pdu; 
 }
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.