FreeCalypso > hg > freecalypso-tools
comparison uptools/atcmd/smsend_multmain.c @ 373:1fa4dcbb1c87
fcup-smsendmult program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 08 Mar 2018 19:47:40 +0000 |
parents | |
children | 88131632ce48 |
comparison
equal
deleted
inserted
replaced
372:1e7c6fcb9abe | 373:1fa4dcbb1c87 |
---|---|
1 /* | |
2 * This is the main module for the fcup-smsendmult utility. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <ctype.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <unistd.h> | |
12 #include "../../rvinterf/include/exitcodes.h" | |
13 | |
14 int sms_write_mode, text_mode, utf8_input; | |
15 u_char dest_addr[12]; | |
16 int dest_addr_global; | |
17 char input_line[21+5+1+320+2], *msgtext; | |
18 int lineno; | |
19 u_char msgtext_gsm7[160]; | |
20 unsigned msgtext_gsmlen; | |
21 | |
22 process_cmdline(argc, argv) | |
23 char **argv; | |
24 { | |
25 int c; | |
26 extern int optind; | |
27 | |
28 while ((c = getopt(argc, argv, "B:np:RtuwWX:")) != EOF) { | |
29 if (atinterf_cmdline_opt(c)) | |
30 continue; | |
31 switch (c) { | |
32 case 't': | |
33 text_mode = 1; | |
34 continue; | |
35 case 'u': | |
36 utf8_input = 1; | |
37 continue; | |
38 case 'w': | |
39 sms_write_mode = 1; | |
40 continue; | |
41 case 'W': | |
42 sms_write_mode = 2; | |
43 continue; | |
44 default: | |
45 /* error msg already printed */ | |
46 exit(ERROR_USAGE); | |
47 } | |
48 } | |
49 if (argc > optind + 1) { | |
50 fprintf(stderr, "usage: %s [options] [dest-addr]\n", | |
51 argv[0]); | |
52 exit(ERROR_USAGE); | |
53 } | |
54 if (argv[optind]) { | |
55 dest_addr_global = 1; | |
56 if (parse_and_encode_dest_addr(argv[optind], dest_addr) < 0) { | |
57 fprintf(stderr, | |
58 "error: destination address argument is invalid\n"); | |
59 exit(ERROR_USAGE); | |
60 } | |
61 } else | |
62 dest_addr_global = 0; | |
63 return(0); | |
64 } | |
65 | |
66 preen_input_line() | |
67 { | |
68 char *cp; | |
69 | |
70 cp = index(input_line, '\n'); | |
71 if (!cp) { | |
72 fprintf(stderr, "input line %d: too long or unterminated\n", | |
73 lineno); | |
74 exit(ERROR_USAGE); | |
75 } | |
76 *cp = '\0'; | |
77 if (dest_addr_global) { | |
78 msgtext = input_line; | |
79 return(0); | |
80 } | |
81 if (!input_line[0] || isspace(input_line[0])) { | |
82 inv: fprintf(stderr, "input line %d: invalid syntax\n", lineno); | |
83 exit(ERROR_USAGE); | |
84 } | |
85 for (cp = input_line; *cp && !isspace(*cp); cp++) | |
86 ; | |
87 if (!*cp) | |
88 goto inv; | |
89 *cp++ = '\0'; | |
90 if (parse_and_encode_dest_addr(input_line, dest_addr) < 0) | |
91 goto inv; | |
92 while (isspace(*cp)) | |
93 cp++; | |
94 msgtext = cp; | |
95 return(1); | |
96 } | |
97 | |
98 preen_message() | |
99 { | |
100 int rc; | |
101 | |
102 if (utf8_input && utf8_to_latin1(msgtext) < 0) { | |
103 fprintf(stderr, "input line %d: invalid UTF-8 message\n", | |
104 lineno); | |
105 exit(ERROR_USAGE); | |
106 } | |
107 if (text_mode) { | |
108 if (strlen(msgtext) > 160) { | |
109 toolong: fprintf(stderr, | |
110 "input line %d: message exceeds 160 chars\n", | |
111 lineno); | |
112 exit(ERROR_USAGE); | |
113 } | |
114 return(0); | |
115 } | |
116 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, &msgtext_gsmlen); | |
117 if (rc == -1) { | |
118 fprintf(stderr, | |
119 "input line %d: message not valid for GSM7 charset\n", | |
120 lineno); | |
121 exit(ERROR_USAGE); | |
122 } | |
123 if (rc == -2) | |
124 goto toolong; | |
125 return(0); | |
126 } | |
127 | |
128 init_send_process() | |
129 { | |
130 atinterf_init(); | |
131 /* enable verbose error messages */ | |
132 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); | |
133 if (text_mode) | |
134 prep_for_text_mode(); | |
135 else | |
136 prep_for_pdu_mode(); | |
137 if (sms_write_mode == 0) | |
138 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0); | |
139 } | |
140 | |
141 main(argc, argv) | |
142 char **argv; | |
143 { | |
144 int initdone = 0; | |
145 | |
146 process_cmdline(argc, argv); | |
147 for (lineno = 1; fgets(input_line, sizeof input_line, stdin); lineno++){ | |
148 preen_input_line(); | |
149 preen_message(); | |
150 if (!initdone) { | |
151 init_send_process(); | |
152 initdone = 1; | |
153 } | |
154 if (text_mode) | |
155 send_in_text_mode(dest_addr, msgtext); | |
156 else | |
157 send_in_pdu_mode(dest_addr, msgtext_gsm7, | |
158 msgtext_gsmlen, 0, 0); | |
159 } | |
160 if (!initdone) | |
161 exit(0); | |
162 if (sms_write_mode == 0) | |
163 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0); | |
164 if (sms_write_mode == 1) | |
165 sendafterwr_process(); | |
166 exit(0); | |
167 } |