Here's a patch that fixes two deficiencies with Kannel's SMPP implementation.

*) UDH for MO messages is not supported in the unpatched driver.

This patch will correctly deal with the most common (SMPP 3.3-style) technique for sending MO's with UDH, namely esm_class |= 64 with the UDH placed in the short_message field.

*) Coding for some message types is broken.

I changed smsc_smpp.c to rely on the (dcs|fields)to(fields|dcs) functions in sms.c, and to only mess with the values if it does a transformation to UCS2 or iso-8859-1.

I have some minor qualms about the patch.

There was
pdu->u.deliver_sm.short_message = NULL;
in pdu_to_msg in smsc_smpp.c which I honestly don't understand.

Also, I'm not entirely clear on how memory is freed in Kannel from the Msg structure. Is there something like a destructor for the generated datastructures Kannel uses? Could someone give me a pointer (groan) where I should look to understand this?

So there is a small chance that it may leak a little memory. I suspect the usual segfault on a "free the dangling pointer" would have bit me by now if there were something wrong, but I don't want to rule that out until a few more eyes have a look at it.

Testing on my system(s) "works" -- i.e. no observed crashes or memory leak warnings, and correct handling of every kind of SMS data I could throw at it.

Have fun,

David WHITE
CONNECT AUSTRIA

-- PATCH --

===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_smpp.c,v
retrieving revision 1.22
diff -u -r1.22 smsc_smpp.c
--- gw/smsc/smsc_smpp.c 2 Jan 2003 14:43:00 -0000 1.22
+++ gw/smsc/smsc_smpp.c 11 Feb 2003 14:48:37 -0000
@@ -233,7 +233,8 @@

static Msg *pdu_to_msg(SMPP *smpp, SMPP_PDU *pdu)
{
- Msg *msg;
+ Msg *msg;
+ int udh_offset = 0;

gw_assert(pdu->type == deliver_sm);

@@ -242,10 +243,19 @@
pdu->u.deliver_sm.source_addr = NULL;
msg->sms.receiver = pdu->u.deliver_sm.destination_addr;
pdu->u.deliver_sm.destination_addr = NULL;
- msg->sms.msgdata = pdu->u.deliver_sm.short_message;
- pdu->u.deliver_sm.short_message = NULL;
+ /* msg->sms.msgdata = pdu->u.deliver_sm.short_message; - done later -- DAVE
+ pdu->u.deliver_sm.short_message = NULL; */
dcs_to_fields(&msg, pdu->u.deliver_sm.data_coding);

+ /* DAVE -- actually handle UDH */
+ if (pdu->u.deliver_sm.esm_class & 0x40) {
+ udh_offset = octstr_get_char(pdu->u.deliver_sm.short_message,0)+1;
+ msg->sms.udhdata = octstr_copy(pdu->u.deliver_sm.short_message,0,udh_offset);
+ }
+ info(0, "SMPP: pdu->u.deliver_sm.short_message = %x, udh_offset = %d",pdu->u.deliver_sm.short_message,udh_offset);
+ msg->sms.msgdata = octstr_copy(pdu->u.deliver_sm.short_message,udh_offset,octstr_len(pdu->u.deliver_sm.short_message)-udh_offset);
+
+
/* handle default data coding */
switch (pdu->u.deliver_sm.data_coding) {
case 0x00: /* default SMSC alphabet */
@@ -257,11 +267,11 @@
if (charset_convert(msg->sms.msgdata, octstr_get_cstr(smpp->alt_charset), "ISO-8859-1") != 0)
error(0, "Failed to convert msgdata from charset <%s> to <%s>, will leave as is.",
octstr_get_cstr(smpp->alt_charset), "ISO-8859-1");- msg->sms.coding = DC_7BIT;
+ msg->sms.coding = DC_7BIT;

} else { /* assume GSM 03.38 7-bit alphabet */
charset_gsm_to_latin1(msg->sms.msgdata);
- msg->sms.coding = DC_7BIT;
+ /* DAVE -- Don't do this, it was set OK by dcs_to_fields msg->sms.coding = DC_7BIT;*/
}
break;
case 0x01: /* ASCII or IA5 - not sure if I need to do anything */
@@ -269,7 +279,7 @@
case 0x04: /* 8 bit binary - do nothing */
break;
case 0x03: /* ISO-8859-1 - do nothing */
- msg->sms.coding = DC_8BIT; break;
+ /* DAVE -- Don't do this, it was set OK by dcs_to_fields msg->sms.coding = DC_8BIT;*/ break;
case 0x05: /* JIS - what do I do with that ? */
break;
case 0x06: /* Cyrllic - iso-8859-5, I'll convert to unicode */
@@ -288,7 +298,7 @@
* you implement them if you feel like it
*/
default:
- msg->sms.coding = DC_7BIT;
+ /* DAVE -- Don't do this, it was set OK by dcs_to_fields msg->sms.coding = DC_7BIT; */
}
msg->sms.pid = pdu->u.deliver_sm.protocol_id;



Reply via email to