FreeCalypso > hg > freecalypso-tools
changeset 365:4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 08 Mar 2018 07:04:06 +0000 |
parents | ac311a48630e |
children | 9f856f843620 |
files | uptools/atcmd/smsend_basic.c |
diffstat | 1 files changed, 41 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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 <unistd.h> #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);