# HG changeset patch # User Mychaela Falconia # Date 1520492646 0 # Node ID 4378d70b146b91e69e4ef0cd7c857205742ca941 # Parent ac311a48630e97cf428b7255db95e47cafd135e0 fcup-smsend: added support for multiline messages in default PDU send mode diff -r ac311a48630e -r 4378d70b146b uptools/atcmd/smsend_basic.c --- a/uptools/atcmd/smsend_basic.c Thu Mar 08 00:20:42 2018 +0000 +++ b/uptools/atcmd/smsend_basic.c Thu Mar 08 07:04:06 2018 +0000 @@ -10,10 +10,12 @@ #include #include "../../rvinterf/include/exitcodes.h" +#define MAX_MSG_CHARS 160 + int sms_write_mode, text_mode, utf8_input; u_char dest_addr[12]; -char msgtext[322]; -u_char msgtext_gsm7[160]; +char msgtext[MAX_MSG_CHARS*2+2]; +u_char msgtext_gsm7[MAX_MSG_CHARS]; unsigned msgtext_gsmlen; process_cmdline(argc, argv) @@ -64,7 +66,7 @@ } if (!argv[optind+1]) return(0); - if (strlen(argv[optind+1]) > 320) { + if (strlen(argv[optind+1]) > MAX_MSG_CHARS*2) { fprintf(stderr, "error: message argument is too long\n"); exit(ERROR_USAGE); } @@ -74,19 +76,38 @@ read_msgtext_from_stdin() { - char *nl; + unsigned pos, remain; + int cc; - if (!fgets(msgtext, sizeof msgtext, stdin)) { - fprintf(stderr, "error reading message from stdin\n"); - exit(ERROR_USAGE); + pos = 0; + remain = sizeof(msgtext); + for (;;) { + if (!remain) { + fprintf(stderr, + "error: message on stdin is too long\n"); + exit(ERROR_USAGE); + } + cc = read(0, msgtext + pos, remain); + if (cc < 0) { + fprintf(stderr, "error reading message from stdin\n"); + exit(ERROR_USAGE); + } + if (cc == 0) + break; + pos += cc; + remain -= cc; } - nl = index(msgtext, '\n'); - if (!nl) { - fprintf(stderr, - "error: message on stdin is too long or unterminated\n"); - exit(ERROR_USAGE); - } - *nl = '\0'; + msgtext[pos] = '\0'; +} + +trim_trailing_newlines() +{ + char *cp; + + cp = index(msgtext, '\0'); + while (cp > msgtext && cp[-1] == '\n') + cp--; + *cp = '\0'; } main(argc, argv) @@ -100,7 +121,13 @@ fprintf(stderr, "error: invalid UTF-8 message\n"); exit(ERROR_USAGE); } + trim_trailing_newlines(); if (text_mode) { + if (index(msgtext, '\n')) { + fprintf(stderr, + "error: multiline messages not supported in text mode\n"); + exit(ERROR_USAGE); + } if (strlen(msgtext) > 160) { toolong: fprintf(stderr, "error: message exceeds 160 chars\n"); exit(ERROR_USAGE);