RE: SMPP: data_coding (deliver_sm)
"Oded Arbel" <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
> -----Original Message----- > From: Alan McNatty [mailto:[email protected]] > > ok - my mistake, according to the specs, it should be > > if ( pdu->u.deliver_sm.data_coding == 0x00 ) > > charset_gsm_to_latin1(msg->sms.msgdata); > > > > yes - I'm aware that this does not solve your problem, but > SMPP servers send GSM 7 bit alphabet > > encoded messages using data_coding 0x00. > > Yes - this is what I thought. What's your opionion on having an > additional config directive stating what the SMSC default alphabet. I > don't know how in the world anyone is suppost to know in advance what > the SMSC default alphabet is... > > ie: > > default_alphabet = 0x01 I hate putting in more configuration paremeters. how about this rewrite of data_coding handling (see attached patch file). a similar version is running on our system for about half a year now, I only now had the incentive to generalize it, but I changed some stuff, to treat this code as untested. -- Oded Arbel m-Wise mobile solutions [email protected] +972-9-9581711 (116) +972-67-340014 ::.. "Let's suppose you have a table with 2^n cups..." "Wait a second - is n a natural number?"
smsc_smpp.patch
(application/octet-stream, 5.8 KB)
--- gw/smsc/smsc_smpp.c 2002-10-22 18:54:39.000000000 +0200
+++ gw/smsc/smsc_smpp.c 2002-10-31 13:11:13.000000000 +0200
@@ -102,6 +102,7 @@
time_t throttling_err_time;
int smpp_msg_id_type; /* msg id in C string, hex or decimal */
int autodetect_addr;
+ Octstr* alt_charset;
SMSCConn *conn;
} SMPP;
@@ -115,7 +119,8 @@
int alt_dcs, int enquire_link_interval,
int max_pending_submits, int reconnect_delay,
int version, int priority, Octstr *my_number,
- int smpp_msg_id_type, int autodetect_addr)
+ int smpp_msg_id_type, int autodetect_addr,
Octstr* alt_charset)
+
{
SMPP *smpp;
@@ -147,8 +153,9 @@
smpp->quitting = 0;
smpp->version = version;
smpp->priority = priority;
+ smpp->alt_charset = octstr_duplicate(alt_charset);
smpp->conn = conn;
smpp->throttling_err_time = 0;
smpp->smpp_msg_id_type = smpp_msg_id_type;
smpp->autodetect_addr = autodetect_addr;
@@ -169,6 +178,8 @@
octstr_destroy(smpp->system_type);
octstr_destroy(smpp->address_range);
octstr_destroy(smpp->our_host);
+ octstr_destroy(smpp->my_number);
+ octstr_destroy(smpp->alt_charset);
gw_free(smpp);
}
}
@@ -236,9 +247,43 @@
pdu->u.deliver_sm.destination_addr = NULL;
msg->sms.msgdata = pdu->u.deliver_sm.short_message;
pdu->u.deliver_sm.short_message = NULL;
+ dcs_to_fields(&msg, pdu->u.deliver_sm.data_coding);
+ switch (pdu->u.deliver_sm.data_coding) {// handle default data coding
+ case 0x00: // default SMSC alphabet
+ if (smpp->alt_charset) { // try to convert from something interesting if specified so
+ if (octstr_compare(smpp->alt_charset, octstr_imm("binary")) != 0) // unless it was specified binary
+ if (charset_convert(msg->sms.msgdata, octstr_get_cstr(smpp->alt_charset), "ISO-8859-1") != 0)
+ error(0, "Failed to convert msgdata from %s to %s, will leave as is",
+ octstr_get_cstr(smpp->alt_charset), "ISO-8859-1");
+
+ msg->sms.coding = DC_8BIT;
+ } else { // assume GSM 03.38 7 bit alphabet
charset_gsm_to_latin1(msg->sms.msgdata);
+ msg->sms.coding = DC_7BIT;
+ }
+ break;
+ case 0x01: // ASCII or IA5 - not sure if I need to do anything
+ case 0x02: // 8 bit binary - do nothing
+ case 0x04: // 8 bit binary - do nothing
+ break;
+ case 0x03: // ISO-8859-1 - do nothing
+ 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
+ if (charset_convert(msg->sms.msgdata, "ISO-8859-5", "UCS-2BE") != 0)
+ error(0, "Failed to convert msgdata from cyrllic to UCS-2, will leave as is");
+ msg->sms.coding = DC_UCS2; break;
+ case 0x07: // Hebrew iso-8859-8, I'll convert to unicode
+ if (charset_convert(msg->sms.msgdata, "ISO-8859-8", "UCS-2BE") != 0)
+ error(0, "Failed to convert msgdata from hebrew to UCS-2, will leave as is");
+ msg->sms.coding = DC_UCS2; break;
+ case 0x08: // unicode UCS-2, yey
+ msg->sms.coding = DC_UCS2; break;
+ default: // don't much care about the others - you implement them if you feel like it
+ msg->sms.coding = DC_8BIT;
+ }
msg->sms.pid = pdu->u.deliver_sm.protocol_id;
- dcs_to_fields(&msg, pdu->u.deliver_sm.data_coding);
return msg;
}
@@ -359,9 +403,18 @@
octstr_format("%S%S", msg->sms.udhdata, msg->sms.msgdata);
} else {
pdu->u.submit_sm.short_message = octstr_duplicate(msg->sms.msgdata);
- if (pdu->u.submit_sm.data_coding == 0 ) /* no reencoding for unicode! */
+ if (pdu->u.submit_sm.data_coding == 0 ) /* no reencoding for unicode! */ {
+ if (smpp->alt_charset && octstr_compare(smpp->alt_charset, octstr_imm("binary")) != 0) {
+ if (charset_convert(pdu->u.submit_sm.short_message, "ISO-8859-1",
+ octstr_get_cstr(smpp->alt_charset)) != 0)
+ error(0, "Failed to convert msgdata from %s to %s will send as is",
+ "ISO-8859-1", octstr_get_cstr(smpp->alt_charset));
+ debug("smsc_smpp.c", 0, "alt_charset!=0");
+ }
+ else
charset_latin1_to_gsm(pdu->u.submit_sm.short_message);
}
+ }
/*
* check for validity and defered settings
@@ -1126,7 +1188,8 @@
long max_pending_submits;
long reconnect_delay;
long version;
+ Octstr* alt_charset;
long priority;
long smpp_msg_id_type;
int autodetect_addr;
@@ -1234,13 +1302,17 @@
panic(0,"SMPP: Invlid value for msg-id-type directive in configuraton");
}
+
+ /* check for charset specific */
+ alt_charset = cfg_get(grp, octstr_imm("alt-charset"));
+
smpp = smpp_create(conn, host, port, receive_port, system_type,
username, password, address_range, our_host,
source_addr_ton, source_addr_npi, dest_addr_ton,
dest_addr_npi, alt_dcs, enquire_link_interval,
max_pending_submits, reconnect_delay,
version, priority, my_number, smpp_msg_id_type,
- autodetect_addr);
+ autodetect_addr,
alt_charset);
conn->data = smpp;
conn->name = octstr_format("SMPP:%S:%d/%d:%S:%S",
@@ -1261,6 +1334,7 @@
octstr_destroy(our_host);
octstr_destroy(my_number);
octstr_destroy(smsc_id);
+ octstr_destroy(alt_charset);
conn->status = SMSCCONN_CONNECTING;