annotate enc-text/gsm7.c @ 33:a91fb88a57b2 default tip

add INSTALL document
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 14 Jun 2024 20:29:17 +0000
parents e56bb9f09ff1
children
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 GSM7.
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
23
e56bb9f09ff1 sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
13 extern int utf8_input, allow_escape;
2
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int concat_enable, concat_refno_set;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern char msgtext[MAX_MSG_CHARS*2+2];
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern u_char concat_refno;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 gsm7_mode_main()
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char msgtext_gsm7[MAX_MSG_CHARS];
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 unsigned msgtext_gsmlen;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int rc;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 unsigned nparts, n;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 u_char udh[6];
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 unsigned pos, remain, chunk;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (utf8_input && utf8_to_latin1(msgtext) < 0) {
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 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS,
23
e56bb9f09ff1 sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
32 &msgtext_gsmlen, allow_escape);
2
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (rc == -1) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 fprintf(stderr, "error: message not valid for GSM7 charset\n");
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 exit(1);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (rc == -2) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 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
39 exit(1);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
23
e56bb9f09ff1 sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
41 if (rc == -3) {
e56bb9f09ff1 sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
42 fprintf(stderr,
e56bb9f09ff1 sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
43 "error: message contains invalid backslash escape\n");
e56bb9f09ff1 sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
44 exit(1);
e56bb9f09ff1 sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
45 }
2
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (msgtext_gsmlen <= 160) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 fputs("dcs 0 septet\nmsg ", stdout);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (msgtext_gsmlen)
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 emit_hex_out(msgtext_gsm7, msgtext_gsmlen, stdout);
8
265b8103530c sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
50 else {
265b8103530c sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
51 putchar('"');
265b8103530c sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
52 putchar('"');
265b8103530c sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
53 }
2
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 putchar('\n');
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 exit(0);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (!concat_enable) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fprintf(stderr, "error: message exceeds 160 chars\n");
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 exit(1);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (!concat_refno_set)
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 concat_refno = get_concsms_refno_from_host_fs();
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 puts("dcs 0 septet");
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 nparts = (msgtext_gsmlen + 152) / 153;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 udh[0] = 5;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 udh[1] = 0x00;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 udh[2] = 0x03;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 udh[3] = concat_refno;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 udh[4] = nparts;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 pos = 0;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 remain = msgtext_gsmlen;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 for (n = 1; n <= nparts; n++) {
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 udh[5] = n;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 chunk = 153;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (chunk > remain)
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 chunk = remain;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fputs("msg-udh ", stdout);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 emit_hex_out(udh, 6, stdout);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 emit_hex_out(msgtext_gsm7 + pos, chunk, stdout);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 putchar('\n');
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 pos += chunk;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 remain -= chunk;
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 exit(0);
a16b1b9728f6 enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }