[RFC] emi2 charset encoding patch

Nisan Bloch <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi

Attached is a small patch to use the same alt-charset scheme in EMI2 module 
as is currently used in the SMPP module.  The charset patch  is for MT 
encoding only. The patch also fixes a small bug in the INC_TRN macro. It 
was using EMI2_MAX_TRN instead of PRIVDATA(conn)->window for the window size.

I havent done charset encoding for MO messages. I have also removed the 
charset_nrc_iso_21_german_to_gsm from the MO code, sure this should be 
charset_gsm_to_nrc_iso_21_german? These two functions seem to be identical. 
Can anyone shed some light on this?

Nisan
smsc_emi2.c.diff (text/plain, 3.4 KB)
--- ../../cvs/gateway/gw/smsc/smsc_emi2.c	Sat Mar 22 15:47:06 2003
+++ ../../gateway-clickcvs/gw/smsc/smsc_emi2.c	Wed Mar 26 21:12:48 2003
@@ -70,7 +70,7 @@
 				   If 0, no idle timeout is in effect */
     Octstr   *npid; /* Notification PID value */
     Octstr   *nadc; /* Notification Address */
-    int alt_charset; /* Alternative GSM charset, defined via values in gwlib/alt_charsets.h */
+    Octstr *alt_charset; /* Alternative GSM charset */
 } PrivData;

 typedef enum {
@@ -434,13 +434,22 @@
     else {
 	emimsg->fields[E50_MT] = octstr_create("3");
 	str = octstr_duplicate(msg->sms.msgdata);
-	charset_latin1_to_gsm(str);

     /*
-     * Check if we have to apply some after GSM transcoding kludges
+	 * convert to the given alternative charset
+	 * otherwise assume to convert to GSM 03.38 7-bit alphabet
      */
-    if (privdata->alt_charset == EMI_NRC_ISO_21)
-        charset_gsm_to_nrc_iso_21_german(str);
+	if (privdata->alt_charset) {
+		if (charset_convert(str, "ISO-8859-1",
+							octstr_get_cstr(privdata->alt_charset)) != 0)
+   			error(0, "Failed to convert msgdata from charset <%s> to <%s>, will send as is.",
+					 "ISO-8859-1", octstr_get_cstr(privdata->alt_charset));
+	} else {
+		charset_latin1_to_gsm(str);
+	}
+
+
+

 	/* Could still be too long after truncation if there's an UDH part,
 	 * but this is only to notice errors elsewhere (should never happen).*/
@@ -523,10 +532,6 @@
 	    msg->sms.msgdata = emimsg->fields[E01_AMSG];
 	    emimsg->fields[E01_AMSG] = NULL; /* So it's not freed */

-        /* obey the NRC (national replacement codes) */
-        if (privdata->alt_charset == EMI_NRC_ISO_21)
-            charset_nrc_iso_21_german_to_gsm(msg->sms.msgdata);
-
 	    charset_gsm_to_latin1(msg->sms.msgdata);
 	}
 	else {
@@ -630,10 +635,6 @@
 	    msg->sms.msgdata = emimsg->fields[E50_AMSG];
 	    emimsg->fields[E50_AMSG] = NULL; /* So it's not freed */

-        /* obey the NRC (national replacement codes) */
-        if (privdata->alt_charset == EMI_NRC_ISO_21)
-            charset_nrc_iso_21_german_to_gsm(msg->sms.msgdata);
-
 	    charset_gsm_to_latin1(msg->sms.msgdata);
 	}
 	else if (octstr_get_char(emimsg->fields[E50_MT], 0) == '4') {
@@ -806,7 +807,7 @@
  */
 static int emi2_next_trn (SMSCConn *conn)
 {
-#define INC_TRN(x) ((x)=((x) + 1) % EMI2_MAX_TRN)
+#define INC_TRN(x) ((x)=((x) + 1) % PRIVDATA(conn)->window)
     int result;

     while (SLOTBUSY(conn,PRIVDATA(conn)->priv_nexttrn))
@@ -1310,6 +1311,7 @@
     octstr_destroy(privdata->password);
     octstr_destroy(privdata->npid);
     octstr_destroy(privdata->nadc);
+    octstr_destroy(privdata->alt_charset);
     gw_free(privdata);
     conn->data = NULL;

@@ -1523,7 +1525,8 @@
     PrivData *privdata;
     Octstr *allow_ip, *deny_ip, *host, *alt_host;
     long portno, our_port, keepalive, flowcontrol, waitack, throughput,
-         idle_timeout, alt_portno, alt_charset, waitack_expire;
+         idle_timeout, alt_portno, waitack_expire;
+	Octstr *alt_charset;
     long window;
     	/* has to be long because of cfg_get_integer */
     int i;
@@ -1678,10 +1681,7 @@
 	goto error;
     }

-    if (cfg_get_integer(&alt_charset, cfg, octstr_imm("alt-charset")) < 0)
-        privdata->alt_charset = 0;
-    else
-        privdata->alt_charset = alt_charset;
+    privdata->alt_charset = cfg_get(cfg, octstr_imm("alt-charset"));

     privdata->allow_ip = allow_ip;
     privdata->deny_ip = deny_ip;
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.