[PATCH] better smsbox-route abilities

Stipe Tolj <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization tolj.org system architecture
Message-ID <[email protected]>
Hi list,

please find attached a patch for enhancing the current smsbox routing via 
'smsbox-route' group in bearerbox scope.

Changed the config directives to 'smsc-id' and 'shortcode' for smsbox-route 
group, since this fits the naming convention more, even while these are 
semicolon seperated lists. (yep, need to update userguide.xml too ;)

The need for the routing enhancement is the following situation you want to handle:

smsc A, smsc B. Both have a shortcode X registered and deliver MOs for it. You 
have various smsbox connections, ie. for different customers. Now you want to 
route MO with receiver X from A to smsbox-id S1 and the same receiver X from B 
to smsbox-id S2. Which is not possible in our current way.

That's why I added another Dict in the gw/bb_boxc.c scope that is used as lookup 
hash for keys of the format <shortcode>:<smsc-id>. So we get the following 
routing logic:

1) get smsbox route for smsc-id
2) get smsbox route for receiver
3) get smsbox route for <receiver:smsc-id>

Route with priority: 3, 2, 1

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
-------------------------------------------------------------------
smsbox-routing.patch (text/plain, 6.9 KB)
### Eclipse Workspace Patch 1.0
#P gateway-cvs-head
Index: gwlib/cfg.def
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.def,v
retrieving revision 1.126
diff -u -r1.126 cfg.def
--- gwlib/cfg.def	22 Jan 2007 15:12:42 -0000	1.126
+++ gwlib/cfg.def	1 Feb 2007 20:51:19 -0000
@@ -281,8 +281,8 @@
 
 MULTI_GROUP(smsbox-route,
     OCTSTR(smsbox-id)
-    OCTSTR(smsc-ids)
-    OCTSTR(shortcuts)
+    OCTSTR(smsc-id)
+    OCTSTR(shortcode)
 )
 
 
Index: gw/bb_boxc.c
===================================================================
RCS file: /home/cvs/gateway/gw/bb_boxc.c,v
retrieving revision 1.88
diff -u -r1.88 bb_boxc.c
--- gw/bb_boxc.c	22 Jan 2007 14:54:30 -0000	1.88
+++ gw/bb_boxc.c	1 Feb 2007 20:51:19 -0000
@@ -110,6 +110,7 @@
 static Dict *smsbox_by_id;
 static Dict *smsbox_by_smsc;
 static Dict *smsbox_by_receiver;
+static Dict *smsbox_by_smsc_receiver;
 
 static long	smsbox_port;
 static int smsbox_port_ssl;
@@ -983,6 +984,8 @@
     smsbox_by_smsc = NULL;
     dict_destroy(smsbox_by_receiver);
     smsbox_by_receiver = NULL;
+    dict_destroy(smsbox_by_smsc_receiver);
+    smsbox_by_smsc_receiver = NULL;
     
     gwlist_remove_producer(flow_threads);
 }
@@ -1038,7 +1041,7 @@
     CfgGroup *grp;
     List *list, *items;
     Octstr *boxc_id, *smsc_ids, *shortcuts;
-    int i;
+    int i, j;
 
     boxc_id = smsc_ids = shortcuts = NULL;
 
@@ -1053,16 +1056,20 @@
         }
 
         /*
-         * If smsc-ids are given, then any message comming from the specified
-         * smsc-id will be routed to this smsbox instance.
-         * If shortcuts are given, then any message with receiver number 
+         * If smsc-id is given, then any message comming from the specified
+         * smsc-id in the list will be routed to this smsbox instance.
+         * If shortcode is given, then any message with receiver number 
          * matching those will be routed to this smsbox instance.
+         * If both are given, then only receiver within shortcode originating
+         * from smsc-id list will be routed to this smsbox instance. So if both
+         * are present then this is a logical AND operation.
          */
-        smsc_ids = cfg_get(grp, octstr_imm("smsc-ids"));
-        shortcuts = cfg_get(grp, octstr_imm("shortcuts"));
+        smsc_ids = cfg_get(grp, octstr_imm("smsc-id"));
+        shortcuts = cfg_get(grp, octstr_imm("shortcode"));
 
-        /* now parse the smsc-ids and shortcuts semicolon separated list */
-        if (smsc_ids) {
+        /* consider now the 3 possibilities: */
+        if (smsc_ids && !shortcuts) {
+            /* smsc-id only, so all MO traffic */
             items = octstr_split(smsc_ids, octstr_imm(";"));
             for (i = 0; i < gwlist_len(items); i++) {
                 Octstr *item = gwlist_get(items, i);
@@ -1078,8 +1085,8 @@
             gwlist_destroy(items, octstr_destroy_item);
             octstr_destroy(smsc_ids);
         }
-
-        if (shortcuts) {
+        else if (!smsc_ids && shortcuts) {
+            /* shortcode only, so these MOs from all smscs */
             items = octstr_split(shortcuts, octstr_imm(";"));
             for (i = 0; i < gwlist_len(items); i++) {
                 Octstr *item = gwlist_get(items, i);
@@ -1095,6 +1102,35 @@
             gwlist_destroy(items, octstr_destroy_item);
             octstr_destroy(shortcuts);
         }
+        else if (smsc_ids && shortcuts) {
+            /* both, so only specified MOs from specified smscs */
+            items = octstr_split(shortcuts, octstr_imm(";"));
+            for (i = 0; i < gwlist_len(items); i++) {
+                List *subitems;
+                Octstr *item = gwlist_get(items, i);
+                octstr_strip_blanks(item);
+                subitems = octstr_split(smsc_ids, octstr_imm(";")); 
+                for (j = 0; j < gwlist_len(subitems); j++) {
+                    Octstr *subitem = gwlist_get(subitems, j);
+                    octstr_strip_blanks(subitem);
+                    
+                    debug("bb.boxc",0,"Adding smsbox routing to id <%s> "
+                          "for receiver no <%s> and smsc id <%s>",
+                          octstr_get_cstr(boxc_id), octstr_get_cstr(item),
+                          octstr_get_cstr(subitem));
+            
+                    /* construct the dict key '<shortcode>:<smsc-id>' */
+                    octstr_insert(subitem, item, 0);
+                    octstr_insert_char(subitem, octstr_len(item), ':');
+                    if (!dict_put_once(smsbox_by_smsc_receiver, subitem, octstr_duplicate(boxc_id)))
+                        panic(0, "Routing for receiver:smsc <%s> already exists!",
+                              octstr_get_cstr(subitem));
+                }
+                gwlist_destroy(subitems, octstr_destroy_item);
+            }
+            gwlist_destroy(items, octstr_destroy_item);
+            octstr_destroy(shortcuts);
+        }
         octstr_destroy(boxc_id);
     }
 
@@ -1142,6 +1178,7 @@
     smsbox_by_id = dict_create(10, NULL);  /* and a hash directory of identified */
     smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy);
     smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
+    smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
 
     /* load the defined smsbox routing rules */
     init_smsbox_routes(cfg);
@@ -1381,7 +1418,7 @@
 int route_incoming_to_boxc(Msg *msg)
 {
     Boxc *bc = NULL, *best = NULL;
-    Octstr *s, *r;
+    Octstr *s, *r, *rs;
     long len, b, i;
     int full_found = 0;
 
@@ -1415,17 +1452,24 @@
              * for sending, so it seems this smsbox is gone
              */
             warning(0,"Could not route message to smsbox id <%s>, smsbox is gone!",
-                  octstr_get_cstr(msg->sms.boxc_id));
+                    octstr_get_cstr(msg->sms.boxc_id));
         }
     }
     else {
         /*
          * Check if we have a "smsbox-route" for this msg.
-         * Where the shortcut route has a higher priority then the smsc-id rule.
+         * Where the shortcode route has a higher priority then the smsc-id rule.
+         * Highest priority has the combined <shortcode>:<smsc-id> route.
          */
+        Octstr *os = octstr_format("%s:%s", 
+                                   octstr_get_cstr(msg->sms.receiver),
+                                   octstr_get_cstr(msg->sms.smsc_id));
         s = (msg->sms.smsc_id ? dict_get(smsbox_by_smsc, msg->sms.smsc_id) : NULL);
         r = (msg->sms.receiver ? dict_get(smsbox_by_receiver, msg->sms.receiver) : NULL);
-        bc = r ? dict_get(smsbox_by_id, r) : (s ? dict_get(smsbox_by_id, s) : NULL);
+        rs = (os ? dict_get(smsbox_by_smsc_receiver, os) : NULL);
+        octstr_destroy(os); 
+        bc = rs ? dict_get(smsbox_by_id, rs) : 
+            (r ? dict_get(smsbox_by_id, r) : (s ? dict_get(smsbox_by_id, s) : NULL));
     }
 
     /* check if we found our routing */
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.