annotate enc-text/ucs2.c @ 8:265b8103530c

sms-encode-text: emit empty messages as ""
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 06:40:50 +0000
parents a16b1b9728f6
children e56bb9f09ff1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement SMS encoding in UCS-2.
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "defs.h"
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int concat_enable, concat_refno_set;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern char msgtext[MAX_MSG_CHARS*2+2];
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern u_char concat_refno;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ucs2_mode_main()
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 u_short msgtext_uni[MAX_MSG_UNI];
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 unsigned msgtext_unilen;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int rc;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 unsigned nparts, n;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 u_char udh[6], ucs2_be[140];
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 unsigned pos, remain, chunk;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 rc = utf8_to_ucs2(msgtext, msgtext_uni, MAX_MSG_UNI, &msgtext_unilen);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (rc == -1) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 fprintf(stderr, "error: invalid UTF-8 message\n");
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (rc == -2) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 fprintf(stderr, "error: message too long for max concat SMS\n");
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 exit(1);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (msgtext_unilen <= 70) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 fputs("dcs 8 octet\nmsg ", stdout);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (msgtext_unilen) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 ucs2_out_bigend(msgtext_uni, ucs2_be, msgtext_unilen);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 emit_hex_out(ucs2_be, msgtext_unilen * 2, stdout);
8
265b8103530c sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
40 } else {
265b8103530c sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
41 putchar('"');
265b8103530c sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
42 putchar('"');
265b8103530c sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
43 }
2
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 putchar('\n');
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(0);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!concat_enable) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 fprintf(stderr, "error: message exceeds 70 UCS-2 chars\n");
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (!concat_refno_set)
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 concat_refno = get_concsms_refno_from_host_fs();
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 puts("dcs 8 octet");
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 nparts = (msgtext_unilen + 66) / 67;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 udh[0] = 5;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 udh[1] = 0x00;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 udh[2] = 0x03;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 udh[3] = concat_refno;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 udh[4] = nparts;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 pos = 0;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 remain = msgtext_unilen;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 for (n = 1; n <= nparts; n++) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 udh[5] = n;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 chunk = 67;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (chunk > remain)
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 chunk = remain;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fputs("msg-udh ", stdout);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 emit_hex_out(udh, 6, stdout);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 ucs2_out_bigend(msgtext_uni + pos, ucs2_be, chunk);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 emit_hex_out(ucs2_be, chunk * 2, stdout);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 putchar('\n');
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 pos += chunk;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 remain -= chunk;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 exit(0);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }