Remove unnecessary use of FILEs in imap4d and pop3d.
* imap4d/imap4d.c (imap4d_mainloop): Take two file descriptor as arguments. All uses updated. * imap4d/imap4d.h (io_setio): Change signature. * imap4d/io.c (io_setio): Take two file descriptor as arguments. All uses updated. * pop3d/extra.c (pop3d_setio): Take two file descriptor as arguments. All uses updated. * pop3d/pop3d.c (pop3d_mainloop): Likewise. * pop3d/pop3d.h (pop3d_setio): Change signature.
Showing
6 changed files
with
25 additions
and
26 deletions
... | @@ -96,7 +96,7 @@ static const char *imap4d_capa[] = { | ... | @@ -96,7 +96,7 @@ static const char *imap4d_capa[] = { |
96 | NULL | 96 | NULL |
97 | }; | 97 | }; |
98 | 98 | ||
99 | static int imap4d_mainloop (int, FILE *, FILE *); | 99 | static int imap4d_mainloop (int, int); |
100 | 100 | ||
101 | static error_t | 101 | static error_t |
102 | imap4d_parse_opt (int key, char *arg, struct argp_state *state) | 102 | imap4d_parse_opt (int key, char *arg, struct argp_state *state) |
... | @@ -397,16 +397,16 @@ imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo)) | ... | @@ -397,16 +397,16 @@ imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo)) |
397 | } | 397 | } |
398 | 398 | ||
399 | static int | 399 | static int |
400 | imap4d_mainloop (int fd, FILE *infile, FILE *outfile) | 400 | imap4d_mainloop (int ifd, int ofd) |
401 | { | 401 | { |
402 | imap4d_tokbuf_t tokp; | 402 | imap4d_tokbuf_t tokp; |
403 | char *text; | 403 | char *text; |
404 | int debug_mode = isatty (fd); | 404 | int debug_mode = isatty (ifd); |
405 | 405 | ||
406 | imap4d_child_signal_setup (imap4d_child_signal); | 406 | imap4d_child_signal_setup (imap4d_child_signal); |
407 | io_setio (infile, outfile); | 407 | io_setio (ifd, ofd); |
408 | 408 | ||
409 | if (imap4d_preauth_setup (fd) == 0) | 409 | if (imap4d_preauth_setup (ifd) == 0) |
410 | { | 410 | { |
411 | if (debug_mode) | 411 | if (debug_mode) |
412 | { | 412 | { |
... | @@ -451,7 +451,7 @@ imap4d_connection (int fd, struct sockaddr *sa, int salen, void *data, | ... | @@ -451,7 +451,7 @@ imap4d_connection (int fd, struct sockaddr *sa, int salen, void *data, |
451 | idle_timeout = timeout; | 451 | idle_timeout = timeout; |
452 | if (imap4d_transcript != transcript) | 452 | if (imap4d_transcript != transcript) |
453 | imap4d_transcript = transcript; | 453 | imap4d_transcript = transcript; |
454 | imap4d_mainloop (fd, fdopen (fd, "r"), fdopen (fd, "w")); | 454 | imap4d_mainloop (fd, fd); |
455 | return 0; | 455 | return 0; |
456 | } | 456 | } |
457 | 457 | ||
... | @@ -612,7 +612,7 @@ main (int argc, char **argv) | ... | @@ -612,7 +612,7 @@ main (int argc, char **argv) |
612 | { | 612 | { |
613 | /* Make sure we are in the root directory. */ | 613 | /* Make sure we are in the root directory. */ |
614 | chdir ("/"); | 614 | chdir ("/"); |
615 | status = imap4d_mainloop (fileno (stdin), stdin, stdout); | 615 | status = imap4d_mainloop (MU_STDIN_FD, MU_STDOUT_FD); |
616 | } | 616 | } |
617 | 617 | ||
618 | if (status) | 618 | if (status) | ... | ... |
... | @@ -224,7 +224,7 @@ extern int io_stream_completion_response (mu_stream_t str, | ... | @@ -224,7 +224,7 @@ extern int io_stream_completion_response (mu_stream_t str, |
224 | const char *format, ...) | 224 | const char *format, ...) |
225 | MU_PRINTFLIKE(4,5); | 225 | MU_PRINTFLIKE(4,5); |
226 | int io_getline (char **pbuf, size_t *psize, size_t *pnbytes); | 226 | int io_getline (char **pbuf, size_t *psize, size_t *pnbytes); |
227 | void io_setio (FILE*, FILE*); | 227 | void io_setio (int, int); |
228 | void io_flush (void); | 228 | void io_flush (void); |
229 | int io_wait_input (int); | 229 | int io_wait_input (int); |
230 | 230 | ... | ... |
... | @@ -22,21 +22,21 @@ | ... | @@ -22,21 +22,21 @@ |
22 | mu_stream_t iostream; | 22 | mu_stream_t iostream; |
23 | 23 | ||
24 | void | 24 | void |
25 | io_setio (FILE *in, FILE *out) | 25 | io_setio (int ifd, int ofd) |
26 | { | 26 | { |
27 | mu_stream_t str, istream, ostream; | 27 | mu_stream_t str, istream, ostream; |
28 | 28 | ||
29 | if (!in) | 29 | if (ifd == -1) |
30 | imap4d_bye (ERR_NO_IFILE); | 30 | imap4d_bye (ERR_NO_IFILE); |
31 | if (!out) | 31 | if (ofd == -1) |
32 | imap4d_bye (ERR_NO_OFILE); | 32 | imap4d_bye (ERR_NO_OFILE); |
33 | 33 | ||
34 | if (mu_stdio_stream_create (&istream, fileno (in), | 34 | if (mu_stdio_stream_create (&istream, ifd, |
35 | MU_STREAM_READ | MU_STREAM_AUTOCLOSE)) | 35 | MU_STREAM_READ | MU_STREAM_AUTOCLOSE)) |
36 | imap4d_bye (ERR_STREAM_CREATE); | 36 | imap4d_bye (ERR_STREAM_CREATE); |
37 | mu_stream_set_buffer (istream, mu_buffer_line, 0); | 37 | mu_stream_set_buffer (istream, mu_buffer_line, 0); |
38 | 38 | ||
39 | if (mu_stdio_stream_create (&ostream, fileno (out), | 39 | if (mu_stdio_stream_create (&ostream, ofd, |
40 | MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE)) | 40 | MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE)) |
41 | imap4d_bye (ERR_STREAM_CREATE); | 41 | imap4d_bye (ERR_STREAM_CREATE); |
42 | mu_stream_set_buffer (ostream, mu_buffer_line, 0); | 42 | mu_stream_set_buffer (ostream, mu_buffer_line, 0); | ... | ... |
... | @@ -127,21 +127,21 @@ pop3d_abquit (int reason) | ... | @@ -127,21 +127,21 @@ pop3d_abquit (int reason) |
127 | } | 127 | } |
128 | 128 | ||
129 | void | 129 | void |
130 | pop3d_setio (FILE *in, FILE *out) | 130 | pop3d_setio (int ifd, int ofd) |
131 | { | 131 | { |
132 | mu_stream_t str, istream, ostream; | 132 | mu_stream_t str, istream, ostream; |
133 | 133 | ||
134 | if (!in) | 134 | if (ifd == -1) |
135 | pop3d_abquit (ERR_NO_IFILE); | 135 | pop3d_abquit (ERR_NO_IFILE); |
136 | if (!out) | 136 | if (ofd == -1) |
137 | pop3d_abquit (ERR_NO_OFILE); | 137 | pop3d_abquit (ERR_NO_OFILE); |
138 | 138 | ||
139 | if (mu_stdio_stream_create (&istream, fileno (in), | 139 | if (mu_stdio_stream_create (&istream, ifd, |
140 | MU_STREAM_READ | MU_STREAM_AUTOCLOSE)) | 140 | MU_STREAM_READ | MU_STREAM_AUTOCLOSE)) |
141 | pop3d_abquit (ERR_NO_IFILE); | 141 | pop3d_abquit (ERR_NO_IFILE); |
142 | mu_stream_set_buffer (istream, mu_buffer_line, 0); | 142 | mu_stream_set_buffer (istream, mu_buffer_line, 0); |
143 | 143 | ||
144 | if (mu_stdio_stream_create (&ostream, fileno (out), | 144 | if (mu_stdio_stream_create (&ostream, ofd, |
145 | MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE)) | 145 | MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE)) |
146 | pop3d_abquit (ERR_NO_OFILE); | 146 | pop3d_abquit (ERR_NO_OFILE); |
147 | 147 | ... | ... |
... | @@ -208,11 +208,10 @@ pop3d_get_client_address (int fd, struct sockaddr_in *pcs) | ... | @@ -208,11 +208,10 @@ pop3d_get_client_address (int fd, struct sockaddr_in *pcs) |
208 | /* The main part of the daemon. This function reads input from the client and | 208 | /* The main part of the daemon. This function reads input from the client and |
209 | executes the proper functions. Also handles the bulk of error reporting. | 209 | executes the proper functions. Also handles the bulk of error reporting. |
210 | Arguments: | 210 | Arguments: |
211 | fd -- socket descriptor (for diagnostics) | 211 | ifd -- input descriptor |
212 | infile -- input stream | 212 | ofd -- output descriptor */ |
213 | outfile -- output stream */ | ||
214 | int | 213 | int |
215 | pop3d_mainloop (int fd, FILE *infile, FILE *outfile) | 214 | pop3d_mainloop (int ifd, int ofd) |
216 | { | 215 | { |
217 | int status = OK; | 216 | int status = OK; |
218 | char buffer[512]; | 217 | char buffer[512]; |
... | @@ -221,7 +220,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) | ... | @@ -221,7 +220,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) |
221 | 220 | ||
222 | mu_set_signals (pop3d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab)); | 221 | mu_set_signals (pop3d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab)); |
223 | 222 | ||
224 | pop3d_setio (infile, outfile); | 223 | pop3d_setio (ifd, ofd); |
225 | 224 | ||
226 | state = initial_state; | 225 | state = initial_state; |
227 | 226 | ||
... | @@ -299,7 +298,7 @@ pop3d_connection (int fd, struct sockaddr *sa, int salen, void *data, | ... | @@ -299,7 +298,7 @@ pop3d_connection (int fd, struct sockaddr *sa, int salen, void *data, |
299 | idle_timeout = timeout; | 298 | idle_timeout = timeout; |
300 | if (pop3d_transcript != transcript) | 299 | if (pop3d_transcript != transcript) |
301 | pop3d_transcript = transcript; | 300 | pop3d_transcript = transcript; |
302 | pop3d_mainloop (fd, fdopen (fd, "r"), fdopen (fd, "w")); | 301 | pop3d_mainloop (fd, fd); |
303 | return 0; | 302 | return 0; |
304 | } | 303 | } |
305 | 304 | ||
... | @@ -430,7 +429,7 @@ main (int argc, char **argv) | ... | @@ -430,7 +429,7 @@ main (int argc, char **argv) |
430 | { | 429 | { |
431 | /* Make sure we are in the root directory. */ | 430 | /* Make sure we are in the root directory. */ |
432 | chdir ("/"); | 431 | chdir ("/"); |
433 | status = pop3d_mainloop (fileno (stdin), stdin, stdout); | 432 | status = pop3d_mainloop (MU_STDIN_FD, MU_STDOUT_FD); |
434 | } | 433 | } |
435 | 434 | ||
436 | if (status) | 435 | if (status) | ... | ... |
... | @@ -241,7 +241,7 @@ extern int pop3d_touchlock (void); | ... | @@ -241,7 +241,7 @@ extern int pop3d_touchlock (void); |
241 | extern int pop3d_unlock (void); | 241 | extern int pop3d_unlock (void); |
242 | extern void pop3d_outf (const char *fmt, ...) MU_PRINTFLIKE(1,2); | 242 | extern void pop3d_outf (const char *fmt, ...) MU_PRINTFLIKE(1,2); |
243 | 243 | ||
244 | extern void pop3d_setio (FILE *in, FILE *out); | 244 | extern void pop3d_setio (int, int); |
245 | extern char *pop3d_readline (char *, size_t); | 245 | extern char *pop3d_readline (char *, size_t); |
246 | extern void pop3d_flush_output (void); | 246 | extern void pop3d_flush_output (void); |
247 | 247 | ... | ... |
-
Please register or sign in to post a comment