diff uptools/atcmd/smsend_main.c @ 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
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();