smsutil: Add alphabet support to encoding

This commit is contained in:
Aki Niemi 2011-02-03 15:20:34 +02:00 committed by Denis Kenzior
parent d7d24f55ee
commit cd1e58bd20
2 changed files with 58 additions and 7 deletions

View File

@ -3524,9 +3524,10 @@ GSList *sms_datagram_prepare(const char *to,
* @use_delivery_reports: value for the Status-Report-Request field * @use_delivery_reports: value for the Status-Report-Request field
* (23.040 3.2.9, 9.2.2.2) * (23.040 3.2.9, 9.2.2.2)
*/ */
GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref, GSList *sms_text_prepare_with_alphabet(const char *to, const char *utf8,
gboolean use_16bit, guint16 ref, gboolean use_16bit,
gboolean use_delivery_reports) gboolean use_delivery_reports,
enum sms_alphabet alphabet)
{ {
struct sms template; struct sms template;
int offset = 0; int offset = 0;
@ -3536,6 +3537,8 @@ GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
long left; long left;
guint8 seq; guint8 seq;
GSList *r = NULL; GSList *r = NULL;
enum gsm_dialect used_locking;
enum gsm_dialect used_single;
memset(&template, 0, sizeof(struct sms)); memset(&template, 0, sizeof(struct sms));
template.type = SMS_TYPE_SUBMIT; template.type = SMS_TYPE_SUBMIT;
@ -3547,8 +3550,13 @@ GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
template.submit.vp.relative = 0xA7; /* 24 Hours */ template.submit.vp.relative = 0xA7; /* 24 Hours */
sms_address_from_string(&template.submit.daddr, to); sms_address_from_string(&template.submit.daddr, to);
/* UDHI, UDL, UD and DCS actually depend on what we have in the text */ /*
gsm_encoded = convert_utf8_to_gsm(utf8, -1, NULL, &written, 0); * UDHI, UDL, UD and DCS actually depend on the contents of
* the text, and also on the GSM dialect we use to encode it.
*/
gsm_encoded = convert_utf8_to_gsm_best_lang(utf8, -1, NULL, &written, 0,
alphabet, &used_locking,
&used_single);
if (gsm_encoded == NULL) { if (gsm_encoded == NULL) {
gsize converted; gsize converted;
@ -3560,13 +3568,35 @@ GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
if (gsm_encoded == NULL && ucs2_encoded == NULL) if (gsm_encoded == NULL && ucs2_encoded == NULL)
return NULL; return NULL;
if (gsm_encoded) if (gsm_encoded != NULL)
template.submit.dcs = 0x00; /* Class Unspecified, 7 Bit */ template.submit.dcs = 0x00; /* Class Unspecified, 7 Bit */
else else
template.submit.dcs = 0x08; /* Class Unspecified, UCS2 */ template.submit.dcs = 0x08; /* Class Unspecified, UCS2 */
if (gsm_encoded != NULL && used_single != GSM_DIALECT_DEFAULT) {
if (!offset)
offset = 1;
template.submit.ud[0] += 3;
template.submit.ud[offset] = SMS_IEI_NATIONAL_LANGUAGE_SINGLE_SHIFT;
template.submit.ud[offset + 1] = 1;
template.submit.ud[offset + 2] = used_single;
offset += 3;
}
if (gsm_encoded != NULL && used_locking != GSM_DIALECT_DEFAULT) {
if (!offset)
offset = 1;
template.submit.ud[0] += 3;
template.submit.ud[offset] = SMS_IEI_NATIONAL_LANGUAGE_LOCKING_SHIFT;
template.submit.ud[offset + 1] = 1;
template.submit.ud[offset + 2] = used_locking;
offset += 3;
}
if (offset != 0) if (offset != 0)
template.submit.udhi = FALSE; template.submit.udhi = TRUE;
if (gsm_encoded && (written <= sms_text_capacity_gsm(160, offset))) { if (gsm_encoded && (written <= sms_text_capacity_gsm(160, offset))) {
template.submit.udl = written + (offset * 8 + 6) / 7; template.submit.udl = written + (offset * 8 + 6) / 7;
@ -3678,6 +3708,15 @@ GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
return r; return r;
} }
GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
gboolean use_16bit,
gboolean use_delivery_reports)
{
return sms_text_prepare_with_alphabet(to, utf8, ref, use_16bit,
use_delivery_reports,
SMS_ALPHABET_DEFAULT);
}
gboolean cbs_dcs_decode(guint8 dcs, gboolean *udhi, enum sms_class *cls, gboolean cbs_dcs_decode(guint8 dcs, gboolean *udhi, enum sms_class *cls,
enum sms_charset *charset, gboolean *compressed, enum sms_charset *charset, gboolean *compressed,
enum cbs_language *language, gboolean *iso639) enum cbs_language *language, gboolean *iso639)

View File

@ -154,6 +154,13 @@ enum sms_charset {
SMS_CHARSET_UCS2 = 2, SMS_CHARSET_UCS2 = 2,
}; };
enum sms_alphabet {
SMS_ALPHABET_DEFAULT = 0,
SMS_ALPHABET_TURKISH,
SMS_ALPHABET_SPANISH,
SMS_ALPHABET_PORTUGUESE,
};
enum sms_mwi_type { enum sms_mwi_type {
SMS_MWI_TYPE_VOICE = 0, SMS_MWI_TYPE_VOICE = 0,
SMS_MWI_TYPE_FAX = 1, SMS_MWI_TYPE_FAX = 1,
@ -538,6 +545,11 @@ GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
gboolean use_16bit, gboolean use_16bit,
gboolean use_delivery_reports); gboolean use_delivery_reports);
GSList *sms_text_prepare_with_alphabet(const char *to, const char *utf8,
guint16 ref, gboolean use_16bit,
gboolean use_delivery_reports,
enum sms_alphabet alphabet);
GSList *sms_datagram_prepare(const char *to, GSList *sms_datagram_prepare(const char *to,
const unsigned char *data, unsigned int len, const unsigned char *data, unsigned int len,
guint16 ref, gboolean use_16bit_ref, guint16 ref, gboolean use_16bit_ref,