diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-09-03 17:47:14 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-09-03 17:50:54 +0300 |
commit | 016c4a978a69cc8990b5aab6c88cbac6fda57203 (patch) | |
tree | f451622ce35a0b64e52522aeef82bd3064faef06 | |
parent | ddfa689bff19d877170add6fed3381f3d5b79a8e (diff) | |
download | mailutils-016c4a978a69cc8990b5aab6c88cbac6fda57203.tar.gz mailutils-016c4a978a69cc8990b5aab6c88cbac6fda57203.tar.bz2 |
comsatd: optional argument to the --test option supplies the name of the tty to use
* NEWS: Document changes.
* comsat/action.c (open_default_tty): Remove.
(open_tty): Examine the tty device (or file) and construct a suitable
filter chain.
Use append mode when opening it.
* comsat/comsat.c: The --test option takes optional argument.
* comsat/tests/testsuite.at: Use local file instead of the tty.
* doc/texinfo/programs/comsatd.texi: Document changes.
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | comsat/action.c | 156 | ||||
-rw-r--r-- | comsat/comsat.c | 32 | ||||
-rw-r--r-- | comsat/tests/testsuite.at | 62 | ||||
-rw-r--r-- | doc/texinfo/programs/comsatd.texi | 28 |
5 files changed, 153 insertions, 132 deletions
@@ -1,4 +1,4 @@ | |||
1 | GNU mailutils NEWS -- history of user-visible changes. 2019-08-29 | 1 | GNU mailutils NEWS -- history of user-visible changes. 2019-09-03 |
2 | Copyright (C) 2002-2019 Free Software Foundation, Inc. | 2 | Copyright (C) 2002-2019 Free Software Foundation, Inc. |
3 | See the end of file for copying conditions. | 3 | See the end of file for copying conditions. |
4 | 4 | ||
@@ -23,6 +23,11 @@ Example configuration (pop3s server): | |||
23 | ssl-certificate-file /etc/ssl/cert.pem; | 23 | ssl-certificate-file /etc/ssl/cert.pem; |
24 | } | 24 | } |
25 | 25 | ||
26 | * comsatd --test | ||
27 | |||
28 | The --test option takes optional argument: name of the tty or file to | ||
29 | use for reporting. | ||
30 | |||
26 | 31 | ||
27 | Version 3.7 - 2019-06-21 | 32 | Version 3.7 - 2019-06-21 |
28 | 33 | ||
diff --git a/comsat/action.c b/comsat/action.c index c9703f28e..b6799c481 100644 --- a/comsat/action.c +++ b/comsat/action.c | |||
@@ -176,32 +176,78 @@ const char *default_action = | |||
176 | #include "biff.rc.h" | 176 | #include "biff.rc.h" |
177 | ; | 177 | ; |
178 | 178 | ||
179 | /* Examine the tty to determine which filters to apply when printing | ||
180 | to it. On entry, STR is the opened stream, FLT points to an array | ||
181 | of char* with at least 3 slots, and NFLT to an integer number. | ||
182 | On success, populates FLT with the necessary filter chain, and stores | ||
183 | to *NFLT the number of used slots. On error, issues error message and | ||
184 | returns -1. | ||
185 | FLT and NFLT can be used as input to mu_filter_chain_create. | ||
186 | */ | ||
179 | static int | 187 | static int |
180 | need_crlf (mu_stream_t str) | 188 | study_tty (mu_stream_t str, char *flt[], int *nflt) |
181 | { | 189 | { |
182 | #if defined(OPOST) && defined(ONLCR) | ||
183 | mu_transport_t trans[2]; | 190 | mu_transport_t trans[2]; |
184 | struct termios tbuf; | 191 | int fd; |
192 | struct stat st; | ||
193 | int rc; | ||
185 | 194 | ||
186 | if (mu_stream_ioctl (str, MU_IOCTL_TRANSPORT, MU_IOCTL_OP_GET, trans)) | 195 | rc = mu_stream_ioctl (str, MU_IOCTL_TRANSPORT, MU_IOCTL_OP_GET, trans); |
187 | return 1; /* suppose we do need it */ | 196 | if (rc) |
188 | if (tcgetattr ((int) (intptr_t) trans[0], &tbuf) == 0 && | 197 | { |
189 | (tbuf.c_oflag & OPOST) && (tbuf.c_oflag & ONLCR)) | 198 | mu_diag_funcall (MU_DIAG_ERROR, "mu_stream_ioctl", NULL, rc); |
190 | return 0; | 199 | return rc; |
191 | else | 200 | } |
192 | return 1; | 201 | |
202 | *nflt = 0; | ||
203 | fd = (int) (intptr_t) trans[0]; | ||
204 | if (fstat (fd, &st) == 0) | ||
205 | { | ||
206 | switch (st.st_mode & S_IFMT) | ||
207 | { | ||
208 | case S_IFREG: | ||
209 | return 0; | ||
210 | |||
211 | case S_IFCHR: | ||
212 | flt[(*nflt)++] = "7BIT"; | ||
213 | #if defined(OPOST) && defined(ONLCR) | ||
214 | { | ||
215 | struct termios tbuf; | ||
216 | |||
217 | if (!(tcgetattr (fd, &tbuf) == 0 | ||
218 | && (tbuf.c_oflag & OPOST) && (tbuf.c_oflag & ONLCR))) | ||
219 | { | ||
220 | flt[(*nflt)++] = "+"; | ||
221 | flt[(*nflt)++] = "CRLF"; | ||
222 | } | ||
223 | } | ||
193 | #else | 224 | #else |
194 | return 1; /* Just in case */ | 225 | /* Just in case */ |
226 | flt[(*nflt)++] = "+"; | ||
227 | flt[(*nflt)++] = "CRLF"; | ||
195 | #endif | 228 | #endif |
229 | break; | ||
230 | |||
231 | case S_IFSOCK: | ||
232 | return 0; | ||
233 | |||
234 | default: | ||
235 | /* FIXME: Perhaps an error? */ | ||
236 | return 0; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | return 0; | ||
196 | } | 241 | } |
197 | 242 | ||
198 | static mu_stream_t | 243 | static mu_stream_t |
199 | _open_tty (const char *device, int argc, char **argv) | 244 | _open_tty (const char *device, int argc, char **argv) |
200 | { | 245 | { |
201 | mu_stream_t dev, base_dev, prev_stream; | 246 | mu_stream_t dev; |
202 | int status; | 247 | int status; |
248 | char *dfl_argv[4]; | ||
203 | 249 | ||
204 | status = mu_file_stream_create (&dev, device, MU_STREAM_WRITE); | 250 | status = mu_file_stream_create (&dev, device, MU_STREAM_APPEND|MU_STREAM_CREAT); |
205 | if (status) | 251 | if (status) |
206 | { | 252 | { |
207 | mu_error (_("cannot open device %s: %s"), | 253 | mu_error (_("cannot open device %s: %s"), |
@@ -210,58 +256,28 @@ _open_tty (const char *device, int argc, char **argv) | |||
210 | } | 256 | } |
211 | mu_stream_set_buffer (dev, mu_buffer_line, 0); | 257 | mu_stream_set_buffer (dev, mu_buffer_line, 0); |
212 | 258 | ||
213 | prev_stream = base_dev = dev; | 259 | if (argc == 0) |
214 | while (argc) | ||
215 | { | 260 | { |
216 | int i; | 261 | status = study_tty (dev, dfl_argv, &argc); |
217 | int mode; | 262 | if (status) |
218 | int qmark; | 263 | return NULL; |
219 | char *fltname; | 264 | argv = dfl_argv; |
220 | 265 | } | |
221 | fltname = argv[0]; | 266 | |
222 | if (fltname[0] == '?') | 267 | if (argc) |
223 | { | 268 | { |
224 | qmark = 1; | 269 | mu_stream_t str; |
225 | fltname++; | 270 | status = mu_filter_chain_create (&str, dev, |
226 | } | 271 | MU_FILTER_ENCODE, MU_STREAM_WRITE, |
227 | else | 272 | argc, argv); |
228 | qmark = 0; | 273 | mu_stream_unref (dev); |
229 | 274 | if (status) | |
230 | if (fltname[0] == '~') | ||
231 | { | ||
232 | mode = MU_FILTER_DECODE; | ||
233 | fltname++; | ||
234 | } | ||
235 | else | ||
236 | { | ||
237 | mode = MU_FILTER_ENCODE; | ||
238 | } | ||
239 | |||
240 | for (i = 1; i < argc; i++) | ||
241 | if (strcmp (argv[i], "+") == 0) | ||
242 | break; | ||
243 | |||
244 | if (qmark == 0 || need_crlf (base_dev)) | ||
245 | { | ||
246 | status = mu_filter_create_args (&dev, prev_stream, fltname, | ||
247 | i, (const char **)argv, | ||
248 | mode, MU_STREAM_WRITE); | ||
249 | mu_stream_unref (prev_stream); | ||
250 | if (status) | ||
251 | { | ||
252 | mu_error (_("cannot open filter stream: %s"), | ||
253 | mu_strerror (status)); | ||
254 | return NULL; | ||
255 | } | ||
256 | prev_stream = dev; | ||
257 | } | ||
258 | argc -= i; | ||
259 | argv += i; | ||
260 | if (argc) | ||
261 | { | 275 | { |
262 | argc--; | 276 | mu_diag_funcall (MU_DIAG_ERROR, "mu_filter_chain_create", device, |
263 | argv++; | 277 | status); |
278 | return NULL; | ||
264 | } | 279 | } |
280 | dev = str; | ||
265 | } | 281 | } |
266 | return dev; | 282 | return dev; |
267 | } | 283 | } |
@@ -275,21 +291,15 @@ open_tty (const char *device, int argc, char **argv) | |||
275 | { | 291 | { |
276 | int rc = mu_nullstream_create (&dev, MU_STREAM_WRITE); | 292 | int rc = mu_nullstream_create (&dev, MU_STREAM_WRITE); |
277 | if (rc) | 293 | if (rc) |
278 | mu_error (_("cannot open null stream: %s"), mu_strerror (rc)); | 294 | { |
295 | mu_error (_("cannot open null stream: %s"), mu_strerror (rc)); | ||
296 | dev = NULL; | ||
297 | } | ||
279 | } | 298 | } |
280 | else | 299 | else |
281 | dev = _open_tty (device, argc, argv); | 300 | dev = _open_tty (device, argc, argv); |
282 | return dev; | 301 | return dev; |
283 | } | 302 | } |
284 | |||
285 | static mu_stream_t | ||
286 | open_default_tty (const char *device) | ||
287 | { | ||
288 | static char *default_filters[] = { "7bit", "+", "?CRLF", NULL }; | ||
289 | return open_tty (device, MU_ARRAY_SIZE (default_filters) - 1, | ||
290 | default_filters); | ||
291 | } | ||
292 | |||
293 | 303 | ||
294 | struct biffrc_environ | 304 | struct biffrc_environ |
295 | { | 305 | { |
@@ -611,7 +621,7 @@ run_user_action (const char *device, mu_message_t msg) | |||
611 | mu_stream_t stream; | 621 | mu_stream_t stream; |
612 | struct biffrc_environ env; | 622 | struct biffrc_environ env; |
613 | 623 | ||
614 | env.tty = open_default_tty (device); | 624 | env.tty = open_tty (device, 0, NULL); |