[PATCH] alt-charset handling in HTTP SMSC module
Stipe Tolj <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Organization | tolj.org system architecture |
| Message-ID | <[email protected]> |
Hi all,
here is small issue that I resolved some days ago for a client that uses the
HTTP SMSC towards an own HTTP API (via the generic type).
In the abstractive layer call httpsmsc_send() we handle the conversion to an
alternative character encoding, based on the value of 'alt-charset' of the
corresponding 'group = smsc' context. So far so good.
The point is: the function ASSUMES that all MTs have our internal encoding
(UTF-8) in the msg->sms.msgdata payload. Which is NOT the case if the smsbox
connection passed a coding=2, hence we have msg->sms.coding = 2 indicating that
the msgdata is UCS-2 and NOT UTF-8. That's why we need to handle both cases
here. The patch does this, and also ensures that the msg->sms.coding is also
reset to DC_UNDEF to ensure that any specific API functions don't indicate a
"wrong assumptive" encoding.
Please review and vote for commitment, should be pretty obvious.
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
-------------------------------------------------------------------
smsc_http-alt-charset.diff
(text/plain, 2.3 KB)
Index: gw/smsc/smsc_http.c
===================================================================
--- gw/smsc/smsc_http.c (revision 4879)
+++ gw/smsc/smsc_http.c (working copy)
@@ -127,7 +127,8 @@
#include "dlr.h"
#include "urltrans.h"
-#define DEFAULT_CHARSET "UTF-8"
+#define DEFAULT_CHARSET "UTF-8"
+#define DEFAULT_UCS2_CHARSET "UCS-2BE"
/*
* This maps fields to values for MO parameters
@@ -1890,11 +1891,35 @@
}
/* convert character encoding if required */
- if (conndata->alt_charset &&
- charset_convert(sms->sms.msgdata, DEFAULT_CHARSET,
- octstr_get_cstr(conndata->alt_charset)) != 0)
- error(0, "Failed to convert msgdata from charset <%s> to <%s>, will send as is.",
- DEFAULT_CHARSET, octstr_get_cstr(conndata->alt_charset));
+ if (conndata->alt_charset) {
+ /*
+ * Converted now to the target character set based on the
+ * one we got in the msg, which is either UTF-8 (our normal
+ * inter-box encoding), but may also be UCS-2, so beware.
+ * In addition, IF we convert to an "extra" encoding here
+ * we also revert the .coding vaue to DC_UNDEF, in order
+ * that all API specific code doesn't indicate an encoding
+ * which is no longer inside the payload here.
+ */
+ if (sms->sms.coding == DC_7BIT) {
+ if (charset_convert(sms->sms.msgdata, DEFAULT_CHARSET,
+ octstr_get_cstr(conndata->alt_charset)) == 0) {
+ sms->sms.coding = DC_UNDEF;
+ } else {
+ error(0, "Failed to convert msgdata from charset <%s> to <%s>, will send as is.",
+ DEFAULT_CHARSET, octstr_get_cstr(conndata->alt_charset));
+ }
+ }
+ else if (sms->sms.coding == DC_UCS2) {
+ if (charset_convert(sms->sms.msgdata, DEFAULT_UCS2_CHARSET,
+ octstr_get_cstr(conndata->alt_charset)) == 0) {
+ sms->sms.coding = DC_UNDEF;
+ } else {
+ error(0, "Failed to convert msgdata from charset <%s> to <%s>, will send as is.",
+ DEFAULT_UCS2_CHARSET, octstr_get_cstr(conndata->alt_charset));
+ }
+ }
+ }
conndata->open_sends++;
conndata->send_sms(conn, sms);
smime.p7s
(application/pkcs7-signature, 5.8 KB) - not displayed