Hi Aki,
On 09/02/2010 02:52 AM, Aki Niemi wrote:
> Add a new function allowing preparing a message list using alphabets.
> ---
> src/smsutil.c | 108
> ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
> src/smsutil.h | 14 +++++++
> 2 files changed, 113 insertions(+), 9 deletions(-)
>
> diff --git a/src/smsutil.c b/src/smsutil.c
> index 0de420b..7da7022 100644
> --- a/src/smsutil.c
> +++ b/src/smsutil.c
> @@ -2987,9 +2987,10 @@ static inline GSList *sms_list_append(GSList *l, const
> struct sms *in)
> * @use_delivery_reports: value for the Status-Report-Request field
> * (23.040 3.2.9, 9.2.2.2)
> */
> -GSList *sms_text_prepare(const char *utf8, guint16 ref,
> - gboolean use_16bit, int *ref_offset,
> - gboolean use_delivery_reports)
> +GSList *sms_text_prepare_with_alphabet(const char *utf8, guint16 ref,
> + gboolean use_16bit, int *ref_offset,
> + gboolean use_delivery_reports,
> + enum sms_alphabet alphabet)
> {
> struct sms template;
> int offset = 0;
> @@ -3008,9 +3009,93 @@ GSList *sms_text_prepare(const char *utf8, guint16 ref,
> template.submit.srr = use_delivery_reports;
> template.submit.mr = 0;
> template.submit.vp.relative = 0xA7; /* 24 Hours */
> + template.submit.udhi = FALSE;
> +
> + /* UDHI, UDL, UD and DCS actually depend on what we have in
> + * the text. For the different GSM dialects, we use only
> + * matching locking and single shift tables. For example,
> + * turkish locking shift with spanish single shift is not
> + * supported. */
> + switch (alphabet) {
> +
An empty line is not really needed here
> + case SMS_ALPHABET_REDUCED:
> + gsm_encoded = convert_utf8_to_gsm_with_translit(utf8, -1, NULL,
> + &written, 0);
> + break;
> +
> + case SMS_ALPHABET_TURKISH:
> + gsm_encoded = convert_utf8_to_gsm_with_lang(utf8, -1, NULL,
> + &written, 0,
> + GSM_DIALECT_TURKISH,
> + GSM_DIALECT_TURKISH);
> +
> + if (!gsm_encoded)
> + break;
> +
> + if (offset == 0)
> + offset = 1;
> +
> + template.submit.udhi = TRUE;
> + template.submit.ud[0] += 6;
> + template.submit.ud[offset] =
> SMS_IEI_NATIONAL_LANGUAGE_SINGLE_SHIFT;
> + template.submit.ud[offset + 1] = 1;
> + template.submit.ud[offset + 2] = GSM_DIALECT_TURKISH;
> + template.submit.ud[offset + 3] =
> SMS_IEI_NATIONAL_LANGUAGE_LOCKING_SHIFT;
> + template.submit.ud[offset + 4] = 1;
> + template.submit.ud[offset + 5] = GSM_DIALECT_TURKISH;
> +
> + offset += 6;
> + break;
> +
> + case SMS_ALPHABET_SPANISH:
> + gsm_encoded = convert_utf8_to_gsm_with_lang(utf8, -1, NULL,
> + &written, 0,
> + GSM_DIALECT_DEFAULT,
> + GSM_DIALECT_SPANISH);
> +
> + if (!gsm_encoded)
> + break;
> +
> + if (offset == 0)
> + offset = 1;
> +
> + template.submit.udhi = TRUE;
> + 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] = GSM_DIALECT_SPANISH;
> +
> + offset += 3;
> + break;
>
> - /* 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);
> + case SMS_ALPHABET_PORTUGUESE:
> + gsm_encoded = convert_utf8_to_gsm_with_lang(utf8, -1, NULL,
> + &written, 0,
> + GSM_DIALECT_PORTUGUESE,
> + GSM_DIALECT_PORTUGUESE);
> +
> + if (!gsm_encoded)
> + break;
> +
> + if (offset == 0)
> + offset = 1;
> +
> + template.submit.udhi = TRUE;
> + template.submit.ud[0] += 6;
> + template.submit.ud[offset] =
> SMS_IEI_NATIONAL_LANGUAGE_SINGLE_SHIFT;
> + template.submit.ud[offset + 1] = 1;
> + template.submit.ud[offset + 2] = GSM_DIALECT_PORTUGUESE;
> + template.submit.ud[offset + 3] =
> SMS_IEI_NATIONAL_LANGUAGE_LOCKING_SHIFT;
> + template.submit.ud[offset + 4] = 1;
> + template.submit.ud[offset + 5] = GSM_DIALECT_PORTUGUESE;
> +
> + offset += 6;
> + break;
> +
> + case SMS_ALPHABET_DEFAULT:
> + default:
Marcel likes it when the compiler warns of missing enum handlers. So
the default statement should be removed.
> + gsm_encoded = convert_utf8_to_gsm(utf8, -1, NULL, &written, 0);
> + }
>
> if (!gsm_encoded) {
> gsize converted;
> @@ -3028,9 +3113,6 @@ GSList *sms_text_prepare(const char *utf8, guint16 ref,
> else
> template.submit.dcs = 0x08; /* Class Unspecified, UCS2 */
>
> - if (offset != 0)
> - template.submit.udhi = FALSE;
> -
This part doesn't look right. The check should actually set udhi to
TRUE, since we can be issuing a return in the next if statement...
> if (gsm_encoded && (written <= sms_text_capacity_gsm(160, offset))) {
> if (ref_offset)
> *ref_offset = 0;
> @@ -3056,7 +3138,7 @@ GSList *sms_text_prepare(const char *utf8, guint16 ref,
>
> template.submit.udhi = TRUE;
>
> - if (!offset)
> + if (offset == 0)
> offset = 1;
>
> if (ref_offset)
> @@ -3150,6 +3232,14 @@ GSList *sms_text_prepare(const char *utf8, guint16 ref,
> return r;
> }
>
> +GSList *sms_text_prepare(const char *utf8, guint16 ref,
> + gboolean use_16bit, int *ref_offset,
> + gboolean use_delivery_reports)
> +{
> + return sms_text_prepare_with_alphabet(utf8, ref, use_16bit, ref_offset,
> + use_delivery_reports, SMS_ALPHABET_DEFAULT);
> +}
> +
> gboolean cbs_dcs_decode(guint8 dcs, gboolean *udhi, enum sms_class *cls,
> enum sms_charset *charset, gboolean *compressed,
> enum cbs_language *language, gboolean *iso639)
> diff --git a/src/smsutil.h b/src/smsutil.h
> index 3c6b3ae..e58332c 100644
> --- a/src/smsutil.h
> +++ b/src/smsutil.h
> @@ -153,6 +153,15 @@ enum sms_charset {
> SMS_CHARSET_UCS2 = 2,
> };
>
> +enum sms_alphabet {
> + SMS_ALPHABET_DEFAULT = 0,
> + SMS_ALPHABET_TURKISH,
> + SMS_ALPHABET_SPANISH,
> + SMS_ALPHABET_PORTUGUESE,
> + SMS_ALPHABET_REDUCED,
> + SMS_ALHPABET_INVALID,
Why is the INVALID part needed at all?
> +};
> +
> enum sms_mwi_type {
> SMS_MWI_TYPE_VOICE = 0,
> SMS_MWI_TYPE_FAX = 1,
> @@ -516,6 +525,11 @@ void status_report_assembly_expire(struct
> status_report_assembly *assembly,
> time_t before, GFunc foreach_func,
> gpointer data);
>
> +GSList *sms_text_prepare_with_alphabet(const char *utf8, guint16 ref,
> + gboolean use_16bit, int *ref_offset,
> + gboolean use_delivery_reports,
> + enum sms_alphabet alphabet);
> +
> GSList *sms_text_prepare(const char *utf8, guint16 ref,
> gboolean use_16bit, int *ref_offset,
> gboolean use_delivery_reports);
Do you have time to write unit tests for this as well?
Regards,
-Denis
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono