[PATCH] Default 'dlr-[url|mask]' for 'group = sms-service' context

Stipe Tolj <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization Kannel Software Foundation (KSF)
Message-ID <[email protected]>
Hi list,

here is a simple patch that adds the capability to define an "default" 
DLR URL and bit mask for the 'group = sms-service', when we use the HTTP 
response (or a defined fixed reply string) directly as MT back to the user.

At the moment we can parse the X-Kannel HTTP headers for a 
[get|post]-url'ed sms-service, but, i.e. have no mechanism to do this 
for exec'ed or fixed replies. This config directive allows it to define 
a default DLR URL with the corresponding escape codes defined, that are 
called on the DLR event getting back to the smsbox scope.

The patch is considerable easy and adds just a couple of checks. We'll 
still use the X-Kannel HTTP header values in favor, before falling back 
to the default config values from these directives.

Please review and comment.

Stipe

-- 
-------------------------------------------------------------------
Kölner Landstrasse 419
40589 DÃŒsseldorf, NRW, Germany

tolj.org system architecture      Kannel Software Foundation (KSF)
http://www.tolj.org/              http://www.kannel.org/

mailto:st_{at}_tolj.org           mailto:stolj_{at}_kannel.org
-------------------------------------------------------------------
sms-service-dlr.diff (text/plain, 5.3 KB)
Index: doc/userguide/userguide.xml
===================================================================
--- doc/userguide/userguide.xml	(revision 5021)
+++ doc/userguide/userguide.xml	(working copy)
@@ -6834,6 +6834,24 @@
         </entry>   
      </row>
 
+     <row><entry><literal>dlr-url</literal></entry>
+        <entry>string (URL)</entry>
+        <entry valign="bottom">
+        Optional Defines a default URL which is fetched for DLR event, if no 
+        specific X-Kannel HTTP header parameter is returned by the HTTP response.
+        </entry>   
+     </row>
+
+     <row><entry><literal>dlr-mask</literal></entry>
+        <entry>number (bit mask)</entry>
+        <entry valign="bottom">
+        Optional. Defines a default DLR event bit mask which is used in 
+        combination with the <literal>dlr-url</literal> config directive, 
+        if no specific X-Kannel HTTP header parameter is returned by the 
+        HTTP response.
+        </entry>   
+     </row>
+
   </tbody>
   </tgroup>
  </table>
Index: gw/smsbox.c
===================================================================
--- gw/smsbox.c	(revision 5040)
+++ gw/smsbox.c	(working copy)
@@ -316,13 +316,13 @@
     gw_assert(msg_type(msg) == sms);
 
     if (trans != NULL)
-	max_msgs = urltrans_max_messages(trans);
+        max_msgs = urltrans_max_messages(trans);
     else
-	max_msgs = 1;
+        max_msgs = 1;
 
     if (max_msgs == 0) {
-	info(0, "No reply sent, denied.");
-	return 0;
+        info(0, "No reply sent, denied.");
+        return 0;
     }
 
     /*
@@ -348,26 +348,36 @@
     }
 
     if (trans == NULL) {
-	header = NULL;
-	footer = NULL;
-	suffix = NULL;
-	split_chars = NULL;
-	catenate = 0;
+        header = NULL;
+        footer = NULL;
+        suffix = NULL;
+        split_chars = NULL;
+        catenate = 0;
     } else {
-    	header = urltrans_header(trans);
-	footer = urltrans_footer(trans);
-	suffix = urltrans_split_suffix(trans);
-	split_chars = urltrans_split_chars(trans);
-	catenate = urltrans_concatenation(trans);
+        header = urltrans_header(trans);
+        footer = urltrans_footer(trans);
+        suffix = urltrans_split_suffix(trans);
+        split_chars = urltrans_split_chars(trans);
+        catenate = urltrans_concatenation(trans);
+
+        /*
+         * If there hasn't been yet any DLR-URL set in the message
+         * and we have configured values from the URLTranslation,
+         * hence the 'group = sms-service' context group, then use
+         * them in the message.
+         */
+        if (msg->sms.dlr_url == NULL &&
+                (msg->sms.dlr_url = octstr_duplicate(urltrans_dlr_url(trans))) != NULL)
+            msg->sms.dlr_mask = urltrans_dlr_mask(trans);
     }
 
     if (catenate)
-    	msg_sequence = counter_increase(catenated_sms_counter) & 0xFF;
+        msg_sequence = counter_increase(catenated_sms_counter) & 0xFF;
     else
-    	msg_sequence = 0;
+        msg_sequence = 0;
 
     list = sms_split(msg, header, footer, suffix, split_chars, catenate,
-    	    	     msg_sequence, max_msgs, sms_max_length);
+                     msg_sequence, max_msgs, sms_max_length);
     msg_count = gwlist_len(list);
     
     debug("sms", 0, "message length %ld, sending %ld messages",
@@ -388,7 +398,7 @@
         }
         write_to_bearerbox(new_msg);
     } else {
-        /* msgs are the independed parts so sent those as is */
+        /* msgs are the independent parts so sent those as is */
         while ((part = gwlist_extract_first(list)) != NULL)
             write_to_bearerbox(part);
     }
Index: gw/urltrans.c
===================================================================
--- gw/urltrans.c	(revision 5032)
+++ gw/urltrans.c	(working copy)
@@ -71,6 +71,7 @@
 #include "urltrans.h"
 #include "gwlib/gwlib.h"
 #include "gw/sms.h"
+#include "gw/dlr.h"
 
 
 /***********************************************************************
@@ -126,7 +127,8 @@
     int args;
     int has_catchall_arg;
     int catch_all;
-    Octstr *dlr_url;	/* Url to call for delivery reports */
+    Octstr *dlr_url;    /* URL to call for delivery reports */
+    long dlr_mask;       /* DLR event mask */
 
     regex_t *keyword_regex;       /* the compiled regular expression for the keyword*/
     regex_t *accepted_smsc_regex;
@@ -879,8 +881,17 @@
     return t->send_sender;
 }
 
+Octstr *urltrans_dlr_url(URLTranslation *t)
+{
+    return t->dlr_url;
+}
 
+int urltrans_dlr_mask(URLTranslation *t)
+{
+    return t->dlr_mask;
+}
 
+
 /***********************************************************************
  * Internal functions.
  */
@@ -928,6 +939,8 @@
         cfg_get_bool(&ot->catch_all, grp, octstr_imm("catch-all"));
 
         ot->dlr_url = cfg_get(grp, octstr_imm("dlr-url"));
+        if (cfg_get_integer(&ot->dlr_mask, grp, octstr_imm("dlr-mask")) == -1)
+            ot->dlr_mask = DLR_UNDEFINED;
         ot->alt_charset = cfg_get(grp, octstr_imm("alt-charset"));
 	    
         url = cfg_get(grp, octstr_imm("get-url"));
Index: gw/urltrans.h
===================================================================
--- gw/urltrans.h	(revision 5032)
+++ gw/urltrans.h	(working copy)
@@ -332,4 +332,8 @@
 int urltrans_strip_keyword(URLTranslation *t);
 int urltrans_send_sender(URLTranslation *t);
 
+/* Return DLR related values */
+Octstr *urltrans_dlr_url(URLTranslation *t);
+int urltrans_dlr_mask(URLTranslation *t);
+
 #endif
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.