RE: Add receiver based smsc-route to opensmppbox
"Porter, Kelvin" <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <73E6BC00A0E3DC4FB8B924269261D52D2E043DB5DA@mail1.hypercube-llc.com> |
Hi, Here is the .diff file as an attachment. Regards, Kelvin R. Porter From: spameden [mailto:[email protected]] Sent: Monday, July 08, 2013 9:45 AM To: Porter, Kelvin Cc: [email protected]; [email protected] Subject: Re: Add receiver based smsc-route to opensmppbox Maybe you could just attach whole patch as a .diff? Would be handy for developers :) Thanks 2013/7/8 Porter, Kelvin <[email protected]<mailto:[email protected]>> Hi, Included below is the diff with the documentation update. Please let me know if you have any questions or comments. Regards, Kelvin R. Porter Index: doc/userguide.xml =================================================================== --- doc/userguide.xml (revision 72) +++ doc/userguide.xml (working copy) @@ -954,6 +954,18 @@ originating from the smsbox A, B or C will be assigned a smsc id "mysmsc". </para> + <para>Yet another example: + + <programlisting> +group = smsc-route +smsc-id = mysmsc +receiver-shortcode = "+18887778888;+18887779999;+18886665555" + </programlisting> + + Which means all outbound messages with receiver number +18887778888, +18887779999, +18886665555 + will be assigned a smsc id "mysmsc". + </para> + <para> If none of the rules have been defined or none match the criteria, the default smsc route defined in route-to-smsc configuration variable @@ -1024,6 +1036,21 @@ smsboxes are matched against the shortcode list. </entry> </row> + <row> + <entry> + <literal>receiver-shortcode (o)</literal> + </entry> + <entry> + <literal>number-list</literal> + </entry> + <entry valign="bottom"> + If set, specifies which receiver numbers for outbound + messages should be routed to this smsc. List contains + numbers separated by semicolon (";"). + This option takes higher precedence than smsbox-id and + shortcode; it supercedes these options. + </entry> + </row> </tbody> </tgroup> </table> Index: gw/opensmppbox-cfg.def =================================================================== --- gw/opensmppbox-cfg.def (revision 72) +++ gw/opensmppbox-cfg.def (working copy) @@ -86,4 +86,5 @@ OCTSTR(smsc-id) OCTSTR(smsbox-id) OCTSTR(shortcode) + OCTSTR(receiver-shortcode) ) Index: gw/opensmppbox.c =================================================================== --- gw/opensmppbox.c (revision 72) +++ gw/opensmppbox.c (working copy) @@ -116,6 +116,7 @@ static long smpp_dest_addr_ton = -1; static long smpp_dest_addr_npi = -1; +static Dict *smsc_by_receiver = NULL; static Dict *smsc_by_smsbox_id = NULL; static Dict *smsc_by_sender = NULL; static Dict *smsc_by_sender_smsbox_id = NULL; @@ -1784,10 +1785,17 @@ if (msg->sms.smsc_id != NULL) return msg->sms.smsc_id; - os = octstr_format("%s:%s", octstr_get_cstr(msg->sms.sender), - octstr_get_cstr(box->boxc_id)); + char *receiver = octstr_get_cstr(msg->sms.receiver); + if ( (receiver) && (strlen(receiver) > 0) ) { + smsc_id = dict_get(smsc_by_receiver, msg->sms.receiver); + os = octstr_format("receiver:%s", receiver); + }; - smsc_id = dict_get(smsc_by_sender_smsbox_id, os); + if (!smsc_id) { + os = octstr_format("%s:%s", octstr_get_cstr(msg->sms.sender), + octstr_get_cstr(box->boxc_id)); + smsc_id = dict_get(smsc_by_sender_smsbox_id, os); + }; if (!smsc_id) smsc_id = dict_get(smsc_by_sender, msg->sms.sender); if (!smsc_id) @@ -2251,14 +2259,15 @@ { CfgGroup *grp; List *list, *items; - Octstr *smsc_id, *boxc_ids, *shortcodes; + Octstr *smsc_id, *boxc_ids, *shortcodes, *receiver_shortcodes; int i, j; + smsc_by_receiver = dict_create(1000, (void(*)(void *)) octstr_destroy); smsc_by_smsbox_id = dict_create(30, (void(*)(void *)) octstr_destroy); smsc_by_sender = dict_create(50, (void(*)(void *)) octstr_destroy); smsc_by_sender_smsbox_id = dict_create(50, (void(*)(void *)) octstr_destroy); - smsc_id = boxc_ids = shortcodes = NULL; + smsc_id = boxc_ids = shortcodes = receiver_shortcodes = NULL; list = items = NULL; list = cfg_get_multi_group(cfg, octstr_imm("smsc-route")); @@ -2281,7 +2290,26 @@ */ boxc_ids = cfg_get(grp, octstr_imm("smsbox-id")); shortcodes = cfg_get(grp, octstr_imm("shortcode")); + receiver_shortcodes = cfg_get(grp, octstr_imm("receiver-shortcode")); + /* Consider the receiver options: receiver-shortcode. */ + { + /* receiver-shortcode applies to all MTs from all smscs */ + items = octstr_split(receiver_shortcodes, octstr_imm(";")); + for (i = 0; i < gwlist_len(items); i++) { + Octstr *item = gwlist_get(items, i); + octstr_strip_blanks(item); + + debug("opensmppbox",0,"Adding smsc routing to id <%s> for receiver no <%s>", + octstr_get_cstr(smsc_id), octstr_get_cstr(item)); + + if (!dict_put_once(smsc_by_receiver, item, octstr_duplicate(smsc_id))) + panic(0, "Routing for receiver no <%s> already exists!", + octstr_get_cstr(item)); + } + gwlist_destroy(items, octstr_destroy_item); + }; + /* consider now the 3 possibilities: */ if (boxc_ids && !shortcodes) { /* smsbox-id only, so all MT traffic */ @@ -2311,7 +2339,7 @@ octstr_get_cstr(smsc_id), octstr_get_cstr(item)); if (!dict_put_once(smsc_by_sender, item, octstr_duplicate(smsc_id))) - panic(0, "Routing for receiver no <%s> already exists!", + panic(0, "Routing for sender no <%s> already exists!", octstr_get_cstr(item)); } gwlist_destroy(items, octstr_destroy_item); @@ -2354,6 +2382,9 @@ static void destroy_smsc_routes(void) { + dict_destroy(smsc_by_receiver); + smsc_by_receiver = NULL; + dict_destroy(smsc_by_smsbox_id); smsc_by_smsbox_id = NULL; -----Original Message----- From: Porter, Kelvin Sent: Wednesday, July 03, 2013 9:05 AM To: [email protected]<mailto:[email protected]> Cc: [email protected]<mailto:[email protected]>; Porter, Kelvin Subject: Re: Add receiver based smsc-route to opensmppbox Hi, I will add the documentation next week. I am on vacation the remainder of this week. Regards, Kelvin R. Porter Sent from my iPhone On Jul 3, 2013, at 5:44 AM, "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> wrote: > Hi Kevin, > > Yes there is interest for this patch please provide the documentation > to enable it to be submitted. > We hope the Kannel maintainers will include this useful patch. > > thanks > > ---------------------------------------------------------------------- > > Date: Tue, 2 Jul 2013 13:27:44 -0500 > From: "Porter, Kelvin" <[email protected]<mailto:[email protected]>> > To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> > Subject: Add receiver based smsc-route to opensmppbox > Message-ID: > > <73E6BC00A0E3DC4FB8B924269261D52D2E042B82FE@mail1.hypercube-llc.com<mailto:73E6BC00A0E3DC4FB8B924269261D52D2E042B82FE@mail1.hypercube-llc.com>> > Content-Type: text/plain; charset="us-ascii" > > Hi, > > I am faced with a need to do receiver-based routing to different SMSC > connections within a opensmppbox and bearerbox configuration. I have > a large number of numbers that need to be routed and they do not share > a common prefix. I have not seen a way to do this using existing > functionality. > > I have developed the following enhancement to opensmppbox. I have > added "receiver-shortcode" to the group "smsc-route". "receiver-shortcode" > enables the user to specify that a message should be assigned to a > smsc-id based upon the _receiver_ of a message; not the _sender_. The > receiver-based routing takes higher precedence than the sender "shortcode" > or "smsbox-id" or combination. I did not implement a combination > logic; although I could consider it, if it was desired.... > > I have included the patch below. If there is interest in > incorporating it, then I can develop a patch for the documentation, as well. > > Please share any feedback. > > Thank you. > > Regards, > > Kelvin R. Porter > > Index: gw/opensmppbox-cfg.def > =================================================================== > --- gw/opensmppbox-cfg.def (revision 72) > +++ gw/opensmppbox-cfg.def (working copy) > @@ -86,4 +86,5 @@ > OCTSTR(smsc-id) > OCTSTR(smsbox-id) > OCTSTR(shortcode) > + OCTSTR(receiver-shortcode) > ) > Index: gw/opensmppbox.c > =================================================================== > --- gw/opensmppbox.c (revision 72) > +++ gw/opensmppbox.c (working copy) > @@ -116,6 +116,7 @@ > static long smpp_dest_addr_ton = -1; > static long smpp_dest_addr_npi = -1; > +static Dict *smsc_by_receiver = NULL; > static Dict *smsc_by_smsbox_id = NULL; static Dict *smsc_by_sender = > NULL; static Dict *smsc_by_sender_smsbox_id = NULL; @@ -1784,10 > +1785,17 @@ > if (msg->sms.smsc_id != NULL) > return msg->sms.smsc_id; > - os = octstr_format("%s:%s", octstr_get_cstr(msg->sms.sender), > - octstr_get_cstr(box->boxc_id)); > + char *receiver = octstr_get_cstr(msg->sms.receiver); > + if ( (receiver) && (strlen(receiver) > 0) ) { > + smsc_id = dict_get(smsc_by_receiver, msg->sms.receiver); > + os = octstr_format("receiver:%s", receiver); > + }; > - smsc_id = dict_get(smsc_by_sender_smsbox_id, os); > + if (!smsc_id) { > + os = octstr_format("%s:%s", > octstr_get_cstr(msg->sms.sender), > + octstr_get_cstr(box->boxc_id)); > + smsc_id = dict_get(smsc_by_sender_smsbox_id, os); > + }; > if (!smsc_id) > smsc_id = dict_get(smsc_by_sender, > msg->sms.sender); > if (!smsc_id) > @@ -2251,14 +2259,15 @@ > { > CfgGroup *grp; > List *list, *items; > - Octstr *smsc_id, *boxc_ids, *shortcodes; > + Octstr *smsc_id, *boxc_ids, *shortcodes, *receiver_shortcodes; > int i, j; > + smsc_by_receiver = dict_create(1000, (void(*)(void *)) > + octstr_destroy); > smsc_by_smsbox_id = dict_create(30, (void(*)(void *)) octstr_destroy); > smsc_by_sender = dict_create(50, (void(*)(void *)) octstr_destroy); > smsc_by_sender_smsbox_id = dict_create(50, (void(*)(void *)) > octstr_destroy); > - smsc_id = boxc_ids = shortcodes = NULL; > + smsc_id = boxc_ids = shortcodes = receiver_shortcodes = NULL; > list = items = NULL; > list = cfg_get_multi_group(cfg, octstr_imm("smsc-route")); @@ > -2281,7 > +2290,26 @@ > */ > boxc_ids = cfg_get(grp, octstr_imm("smsbox-id")); > shortcodes = cfg_get(grp, octstr_imm("shortcode")); > + receiver_shortcodes = cfg_get(grp, > octstr_imm("receiver-shortcode")); > + /* Consider the receiver options: receiver-shortcode. */ > + { > + /* receiver-shortcode applies to all MTs from all smscs */ > + items = octstr_split(receiver_shortcodes, octstr_imm(";")); > + for (i = 0; i < gwlist_len(items); i++) { > + Octstr *item = gwlist_get(items, i); > + octstr_strip_blanks(item); > + > + debug("opensmppbox",0,"Adding smsc routing to id <%s> > + for > receiver no <%s>", > + octstr_get_cstr(smsc_id), > + octstr_get_cstr(item)); > + > + if (!dict_put_once(smsc_by_receiver, item, > octstr_duplicate(smsc_id))) > + panic(0, "Routing for receiver no <%s> already > exists!", > + octstr_get_cstr(item)); > + } > + gwlist_destroy(items, octstr_destroy_item); > + }; > + > /* consider now the 3 possibilities: */ > if (boxc_ids && !shortcodes) { > /* smsbox-id only, so all MT traffic */ @@ -2311,7 +2339,7 @@ > octstr_get_cstr(smsc_id), octstr_get_cstr(item)); > if (!dict_put_once(smsc_by_sender, item, > octstr_duplicate(smsc_id))) > - panic(0, "Routing for receiver no <%s> already > exists!", > + panic(0, "Routing for sender no <%s> already > + exists!", > octstr_get_cstr(item)); > } > gwlist_destroy(items, octstr_destroy_item); @@ -2354,6 > +2382,9 @@ static void destroy_smsc_routes(void) { > + dict_destroy(smsc_by_receiver); > + smsc_by_receiver = NULL; > + > dict_destroy(smsc_by_smsbox_id); > smsc_by_smsbox_id = NULL; > >
opensmppbox.diff
(application/octet-stream, 5.6 KB)
Index: doc/userguide.xml
===================================================================
--- doc/userguide.xml (revision 72)
+++ doc/userguide.xml (working copy)
@@ -954,6 +954,18 @@
originating from the smsbox A, B or C will be assigned a smsc id "mysmsc".
</para>
+ <para>Yet another example:
+
+ <programlisting>
+group = smsc-route
+smsc-id = mysmsc
+receiver-shortcode = "+18887778888;+18887779999;+18886665555"
+ </programlisting>
+
+ Which means all outbound messages with receiver number +18887778888, +18887779999, +18886665555
+ will be assigned a smsc id "mysmsc".
+ </para>
+
<para>
If none of the rules have been defined or none match the criteria, the
default smsc route defined in route-to-smsc configuration variable
@@ -1024,6 +1036,21 @@
smsboxes are matched against the shortcode list.
</entry>
</row>
+ <row>
+ <entry>
+ <literal>receiver-shortcode (o)</literal>
+ </entry>
+ <entry>
+ <literal>number-list</literal>
+ </entry>
+ <entry valign="bottom">
+ If set, specifies which receiver numbers for outbound
+ messages should be routed to this smsc. List contains
+ numbers separated by semicolon (";").
+ This option takes higher precedence than smsbox-id and
+ shortcode; it supercedes these options.
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
Index: gw/opensmppbox-cfg.def
===================================================================
--- gw/opensmppbox-cfg.def (revision 72)
+++ gw/opensmppbox-cfg.def (working copy)
@@ -86,4 +86,5 @@
OCTSTR(smsc-id)
OCTSTR(smsbox-id)
OCTSTR(shortcode)
+ OCTSTR(receiver-shortcode)
)
Index: gw/opensmppbox.c
===================================================================
--- gw/opensmppbox.c (revision 72)
+++ gw/opensmppbox.c (working copy)
@@ -116,6 +116,7 @@
static long smpp_dest_addr_ton = -1;
static long smpp_dest_addr_npi = -1;
+static Dict *smsc_by_receiver = NULL;
static Dict *smsc_by_smsbox_id = NULL;
static Dict *smsc_by_sender = NULL;
static Dict *smsc_by_sender_smsbox_id = NULL;
@@ -1784,10 +1785,17 @@
if (msg->sms.smsc_id != NULL)
return msg->sms.smsc_id;
- os = octstr_format("%s:%s", octstr_get_cstr(msg->sms.sender),
- octstr_get_cstr(box->boxc_id));
+ char *receiver = octstr_get_cstr(msg->sms.receiver);
+ if ( (receiver) && (strlen(receiver) > 0) ) {
+ smsc_id = dict_get(smsc_by_receiver, msg->sms.receiver);
+ os = octstr_format("receiver:%s", receiver);
+ };
- smsc_id = dict_get(smsc_by_sender_smsbox_id, os);
+ if (!smsc_id) {
+ os = octstr_format("%s:%s", octstr_get_cstr(msg->sms.sender),
+ octstr_get_cstr(box->boxc_id));
+ smsc_id = dict_get(smsc_by_sender_smsbox_id, os);
+ };
if (!smsc_id)
smsc_id = dict_get(smsc_by_sender, msg->sms.sender);
if (!smsc_id)
@@ -2251,14 +2259,15 @@
{
CfgGroup *grp;
List *list, *items;
- Octstr *smsc_id, *boxc_ids, *shortcodes;
+ Octstr *smsc_id, *boxc_ids, *shortcodes, *receiver_shortcodes;
int i, j;
+ smsc_by_receiver = dict_create(1000, (void(*)(void *)) octstr_destroy);
smsc_by_smsbox_id = dict_create(30, (void(*)(void *)) octstr_destroy);
smsc_by_sender = dict_create(50, (void(*)(void *)) octstr_destroy);
smsc_by_sender_smsbox_id = dict_create(50, (void(*)(void *)) octstr_destroy);
- smsc_id = boxc_ids = shortcodes = NULL;
+ smsc_id = boxc_ids = shortcodes = receiver_shortcodes = NULL;
list = items = NULL;
list = cfg_get_multi_group(cfg, octstr_imm("smsc-route"));
@@ -2281,7 +2290,26 @@
*/
boxc_ids = cfg_get(grp, octstr_imm("smsbox-id"));
shortcodes = cfg_get(grp, octstr_imm("shortcode"));
+ receiver_shortcodes = cfg_get(grp, octstr_imm("receiver-shortcode"));
+ /* Consider the receiver options: receiver-shortcode. */
+ {
+ /* receiver-shortcode applies to all MTs from all smscs */
+ items = octstr_split(receiver_shortcodes, octstr_imm(";"));
+ for (i = 0; i < gwlist_len(items); i++) {
+ Octstr *item = gwlist_get(items, i);
+ octstr_strip_blanks(item);
+
+ debug("opensmppbox",0,"Adding smsc routing to id <%s> for receiver no <%s>",
+ octstr_get_cstr(smsc_id), octstr_get_cstr(item));
+
+ if (!dict_put_once(smsc_by_receiver, item, octstr_duplicate(smsc_id)))
+ panic(0, "Routing for receiver no <%s> already exists!",
+ octstr_get_cstr(item));
+ }
+ gwlist_destroy(items, octstr_destroy_item);
+ };
+
/* consider now the 3 possibilities: */
if (boxc_ids && !shortcodes) {
/* smsbox-id only, so all MT traffic */
@@ -2311,7 +2339,7 @@
octstr_get_cstr(smsc_id), octstr_get_cstr(item));
if (!dict_put_once(smsc_by_sender, item, octstr_duplicate(smsc_id)))
- panic(0, "Routing for receiver no <%s> already exists!",
+ panic(0, "Routing for sender no <%s> already exists!",
octstr_get_cstr(item));
}
gwlist_destroy(items, octstr_destroy_item);
@@ -2354,6 +2382,9 @@
static void destroy_smsc_routes(void)
{
+ dict_destroy(smsc_by_receiver);
+ smsc_by_receiver = NULL;
+
dict_destroy(smsc_by_smsbox_id);
smsc_by_smsbox_id = NULL;