FreeCalypso > hg > sms-coding-utils
diff enc-text/gsm7.c @ 2:a16b1b9728f6
enc-text: sms-encode-text program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Aug 2023 02:07:22 +0000 (21 months ago) |
parents | |
children | 265b8103530c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/enc-text/gsm7.c Sat Aug 05 02:07:22 2023 +0000 @@ -0,0 +1,78 @@ +/* + * In this module we implement SMS encoding in GSM7. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include "defs.h" + +extern int utf8_input; +extern int concat_enable, concat_refno_set; +extern char msgtext[MAX_MSG_CHARS*2+2]; +extern u_char concat_refno; + +gsm7_mode_main() +{ + u_char msgtext_gsm7[MAX_MSG_CHARS]; + unsigned msgtext_gsmlen; + int rc; + unsigned nparts, n; + u_char udh[6]; + unsigned pos, remain, chunk; + + if (utf8_input && utf8_to_latin1(msgtext) < 0) { + fprintf(stderr, "error: invalid UTF-8 message\n"); + exit(1); + } + rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, + &msgtext_gsmlen); + if (rc == -1) { + fprintf(stderr, "error: message not valid for GSM7 charset\n"); + exit(1); + } + if (rc == -2) { + fprintf(stderr, "error: message too long for max concat SMS\n"); + exit(1); + } + if (msgtext_gsmlen <= 160) { + fputs("dcs 0 septet\nmsg ", stdout); + if (msgtext_gsmlen) + emit_hex_out(msgtext_gsm7, msgtext_gsmlen, stdout); + else + fputs("empty", stdout); + putchar('\n'); + exit(0); + } + if (!concat_enable) { + fprintf(stderr, "error: message exceeds 160 chars\n"); + exit(1); + } + if (!concat_refno_set) + concat_refno = get_concsms_refno_from_host_fs(); + puts("dcs 0 septet"); + nparts = (msgtext_gsmlen + 152) / 153; + udh[0] = 5; + udh[1] = 0x00; + udh[2] = 0x03; + udh[3] = concat_refno; + udh[4] = nparts; + pos = 0; + remain = msgtext_gsmlen; + for (n = 1; n <= nparts; n++) { + udh[5] = n; + chunk = 153; + if (chunk > remain) + chunk = remain; + fputs("msg-udh ", stdout); + emit_hex_out(udh, 6, stdout); + emit_hex_out(msgtext_gsm7 + pos, chunk, stdout); + putchar('\n'); + pos += chunk; + remain -= chunk; + } + exit(0); +}