FreeCalypso > hg > freecalypso-tools
changeset 966:ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 01 Sep 2023 15:44:52 +0000 |
parents | 2969032bdfac |
children | 6bf473f77fc4 |
files | uptools/atcmd/smsend_main.c uptools/atcmd/smsend_multmain.c uptools/libcoding/Makefile uptools/libcoding/gsm7_encode.c uptools/libcoding/hexdecode2.c |
diffstat | 5 files changed, 82 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/uptools/atcmd/smsend_main.c Fri Sep 01 07:33:51 2023 +0000 +++ b/uptools/atcmd/smsend_main.c Fri Sep 01 15:44:52 2023 +0000 @@ -13,10 +13,10 @@ #define MAX_MSG_CHARS (153*255) #define MAX_MSG_UNI (67*255) -int sms_write_mode, text_mode, utf8_input, ucs2_mode; +int sms_write_mode, text_mode, utf8_input, ucs2_mode, allow_escape; int concat_enable, concat_refno_set, concat_quiet; u_char dest_addr[12]; -char msgtext[MAX_MSG_CHARS*2+2]; +char msgtext[MAX_MSG_CHARS*3+2]; u_char concat_refno; process_cmdline(argc, argv) @@ -26,7 +26,7 @@ extern int optind; extern char *optarg; - while ((c = getopt(argc, argv, "B:cC:np:qRtuUwWX:")) != EOF) { + while ((c = getopt(argc, argv, "B:cC:enp:qRtuUwWX:")) != EOF) { if (atinterf_cmdline_opt(c)) continue; switch (c) { @@ -38,6 +38,9 @@ concat_refno = strtoul(optarg, 0, 0); concat_refno_set = 1; continue; + case 'e': + allow_escape = 1; + continue; case 'q': concat_quiet = 1; continue; @@ -73,6 +76,17 @@ argv[0]); exit(ERROR_USAGE); } + if (allow_escape && text_mode) { + fprintf(stderr, + "%s error: escapes not supported in text mode\n", + argv[0]); + exit(ERROR_USAGE); + } + if (ucs2_mode && allow_escape) { + fprintf(stderr, "%s error: UCS-2 escapes not supported yet\n", + argv[0]); + exit(ERROR_USAGE); + } if (argc > optind + 2) { fprintf(stderr, "usage: %s [options] dest-addr [message]\n", argv[0]); @@ -94,7 +108,7 @@ } if (argc < optind + 2) return(0); - if (strlen(argv[optind+1]) > MAX_MSG_CHARS*2) { + if (strlen(argv[optind+1]) > MAX_MSG_CHARS*3) { fprintf(stderr, "error: message argument is too long\n"); exit(ERROR_USAGE); } @@ -176,7 +190,7 @@ exit(0); } rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, - &msgtext_gsmlen); + &msgtext_gsmlen, allow_escape); if (rc == -1) { fprintf(stderr, "error: message not valid for GSM7 charset\n"); exit(ERROR_USAGE); @@ -185,6 +199,11 @@ fprintf(stderr, "error: message too long for max concat SMS\n"); exit(ERROR_USAGE); } + if (rc == -3) { + fprintf(stderr, + "error: message contains invalid backslash escape\n"); + exit(ERROR_USAGE); + } if (msgtext_gsmlen <= 160) { common_init(); prep_for_pdu_mode();
--- a/uptools/atcmd/smsend_multmain.c Fri Sep 01 07:33:51 2023 +0000 +++ b/uptools/atcmd/smsend_multmain.c Fri Sep 01 15:44:52 2023 +0000 @@ -141,7 +141,7 @@ send_in_text_mode(dest_addr, msgtext); return(0); } - rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, &msgtext_gsmlen); + rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, &msgtext_gsmlen, 0); if (rc == -1) { fprintf(stderr, "input line %d: message not valid for GSM7 charset\n",
--- a/uptools/libcoding/Makefile Fri Sep 01 07:33:51 2023 +0000 +++ b/uptools/libcoding/Makefile Fri Sep 01 15:44:52 2023 +0000 @@ -3,9 +3,9 @@ OBJS= alpha_addr.o decode_helpers.o grokdcs.o gsm7_decode.o \ gsm7_decode_qstring.o gsm7_decode_tables.o gsm7_encode.o \ gsm7_encode_table.o gsm7_pack.o gsm7_unpack.o gsmtime.o hexdecode.o \ - hexdump.o hexencode.o number_decode.o number_encode.o scaddr.o \ - sms_submit.o sms_submit8.o ucs2_bigend.o ucs2_decode.o utf8_decode.o \ - utf8_decode2.o + hexdecode2.o hexdump.o hexencode.o number_decode.o number_encode.o \ + scaddr.o sms_submit.o sms_submit8.o ucs2_bigend.o ucs2_decode.o \ + utf8_decode.o utf8_decode2.o LIB= libcoding.a all: ${LIB}
--- a/uptools/libcoding/gsm7_encode.c Fri Sep 01 07:33:51 2023 +0000 +++ b/uptools/libcoding/gsm7_encode.c Fri Sep 01 15:44:52 2023 +0000 @@ -4,10 +4,40 @@ */ #include <sys/types.h> +#include <ctype.h> extern u_char gsm7_encode_table[256]; -latin1_to_gsm7(inbuf, outbuf, outmax, outlenp) +static unsigned +handle_escape(ipp) + u_char **ipp; +{ + unsigned c; + + c = *(*ipp)++; + if (c >= '0' && c <= '7' && isxdigit(**ipp)) { + c = ((c - '0') << 4) | decode_hex_digit(*(*ipp)++); + return c; + } + switch (c) { + case 'n': + return '\n'; + case 'r': + return '\r'; + case 'e': + return 0x1B; + case 'E': /* Euro currency symbol */ + return 0xE5; + case '"': + case '\\': + c = gsm7_encode_table[c]; + return c; + default: + return 0xFF; + } +} + +latin1_to_gsm7(inbuf, outbuf, outmax, outlenp, allow_escape) u_char *inbuf, *outbuf; unsigned outmax, *outlenp; { @@ -15,9 +45,15 @@ unsigned outcnt = 0, c, n; while (c = *ip++) { - c = gsm7_encode_table[c]; - if (c == 0xFF) - return(-1); + if (c == '\\' && allow_escape) { + c = handle_escape(&ip); + if (c == 0xFF) + return(-3); + } else { + c = gsm7_encode_table[c]; + if (c == 0xFF) + return(-1); + } if (c & 0x80) n = 2; else
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uptools/libcoding/hexdecode2.c Fri Sep 01 15:44:52 2023 +0000 @@ -0,0 +1,14 @@ +/* + * This module is a subset of hexdigits.c from fc-sim-tools/libutil. + */ + +decode_hex_digit(c) +{ + if (c >= '0' && c <= '9') + return(c - '0'); + if (c >= 'A' && c <= 'F') + return(c - 'A' + 10); + if (c >= 'a' && c <= 'f') + return(c - 'a' + 10); + return(-1); +}