FreeCalypso > hg > sms-coding-utils
comparison 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 |
parents | |
children | 265b8103530c |
comparison
equal
deleted
inserted
replaced
1:13518c86b73c | 2:a16b1b9728f6 |
---|---|
1 /* | |
2 * In this module we implement SMS encoding in GSM7. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <unistd.h> | |
11 #include "defs.h" | |
12 | |
13 extern int utf8_input; | |
14 extern int concat_enable, concat_refno_set; | |
15 extern char msgtext[MAX_MSG_CHARS*2+2]; | |
16 extern u_char concat_refno; | |
17 | |
18 gsm7_mode_main() | |
19 { | |
20 u_char msgtext_gsm7[MAX_MSG_CHARS]; | |
21 unsigned msgtext_gsmlen; | |
22 int rc; | |
23 unsigned nparts, n; | |
24 u_char udh[6]; | |
25 unsigned pos, remain, chunk; | |
26 | |
27 if (utf8_input && utf8_to_latin1(msgtext) < 0) { | |
28 fprintf(stderr, "error: invalid UTF-8 message\n"); | |
29 exit(1); | |
30 } | |
31 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, | |
32 &msgtext_gsmlen); | |
33 if (rc == -1) { | |
34 fprintf(stderr, "error: message not valid for GSM7 charset\n"); | |
35 exit(1); | |
36 } | |
37 if (rc == -2) { | |
38 fprintf(stderr, "error: message too long for max concat SMS\n"); | |
39 exit(1); | |
40 } | |
41 if (msgtext_gsmlen <= 160) { | |
42 fputs("dcs 0 septet\nmsg ", stdout); | |
43 if (msgtext_gsmlen) | |
44 emit_hex_out(msgtext_gsm7, msgtext_gsmlen, stdout); | |
45 else | |
46 fputs("empty", stdout); | |
47 putchar('\n'); | |
48 exit(0); | |
49 } | |
50 if (!concat_enable) { | |
51 fprintf(stderr, "error: message exceeds 160 chars\n"); | |
52 exit(1); | |
53 } | |
54 if (!concat_refno_set) | |
55 concat_refno = get_concsms_refno_from_host_fs(); | |
56 puts("dcs 0 septet"); | |
57 nparts = (msgtext_gsmlen + 152) / 153; | |
58 udh[0] = 5; | |
59 udh[1] = 0x00; | |
60 udh[2] = 0x03; | |
61 udh[3] = concat_refno; | |
62 udh[4] = nparts; | |
63 pos = 0; | |
64 remain = msgtext_gsmlen; | |
65 for (n = 1; n <= nparts; n++) { | |
66 udh[5] = n; | |
67 chunk = 153; | |
68 if (chunk > remain) | |
69 chunk = remain; | |
70 fputs("msg-udh ", stdout); | |
71 emit_hex_out(udh, 6, stdout); | |
72 emit_hex_out(msgtext_gsm7 + pos, chunk, stdout); | |
73 putchar('\n'); | |
74 pos += chunk; | |
75 remain -= chunk; | |
76 } | |
77 exit(0); | |
78 } |