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,2 +1,2 @@ | |||
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. |
@@ -25,2 +25,7 @@ Example configuration (pop3s server): | |||
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 | ||
diff --git a/comsat/action.c b/comsat/action.c index c9703f28e..b6799c481 100644 --- a/comsat/action.c +++ b/comsat/action.c | |||
@@ -178,19 +178,64 @@ const char *default_action = | |||
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 | } |
@@ -200,6 +245,7 @@ _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) |
@@ -212,54 +258,24 @@ _open_tty (const char *device, int argc, char **argv) | |||
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 | } |
@@ -277,3 +293,6 @@ open_tty (const char *device, int argc, char **argv) | |||
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 | } |
@@ -283,11 +302,2 @@ open_tty (const char *device, int argc, char **argv) | |||
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 | ||
@@ -613,3 +623,3 @@ run_user_action (const char *device, mu_message_t msg) | |||
613 | 623 | ||
614 | env.tty = open_default_tty (device); | 624 | env.tty = open_tty (device, 0, NULL); |
615 | if (!env.tty) | 625 | if (!env.tty) |
diff --git a/comsat/comsat.c b/comsat/comsat.c index f317fa698..cee474572 100644 --- a/comsat/comsat.c +++ b/comsat/comsat.c | |||
@@ -20,2 +20,3 @@ | |||
20 | #include "mailutils/sockaddr.h" | 20 | #include "mailutils/sockaddr.h" |
21 | #include "mailutils/alloc.h" | ||
21 | 22 | ||
@@ -61,3 +62,3 @@ const char *program_version = "comsatd (" PACKAGE_STRING ")"; | |||
61 | 62 | ||
62 | int test_mode; | 63 | char *test_mode; |
63 | char *biffrc = BIFF_RC; | 64 | char *biffrc = BIFF_RC; |
@@ -71,3 +72,22 @@ set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt, | |||
71 | } | 72 | } |
72 | 73 | ||
74 | static void | ||
75 | set_test_mode (struct mu_parseopt *po, struct mu_option *opt, | ||
76 | char const *arg) | ||
77 | { | ||
78 | if (arg) | ||
79 | { | ||
80 | if (arg[0] != '/') | ||
81 | { | ||
82 | test_mode = mu_make_file_name (mu_getcwd (), arg); | ||
83 | if (!test_mode) | ||
84 | mu_alloc_die (); | ||
85 | } | ||
86 | else | ||
87 | test_mode = mu_strdup (arg); | ||
88 | } | ||
89 | else | ||
90 | test_mode = mu_strdup ("/dev/tty"); | ||
91 | } | ||
92 | |||
73 | static void | 93 | static void |
@@ -99,5 +119,5 @@ set_foreground (struct mu_parseopt *po, struct mu_option *opt, | |||