Commit 6eff29e9 6eff29e930330cfc498c58419b8675c913d62b31 by Sergey Poznyakoff

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.
1 parent d0a2801a
......@@ -96,7 +96,7 @@ static const char *imap4d_capa[] = {
NULL
};
static int imap4d_mainloop (int, FILE *, FILE *);
static int imap4d_mainloop (int, int);
static error_t
imap4d_parse_opt (int key, char *arg, struct argp_state *state)
......@@ -397,16 +397,16 @@ imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo))
}
static int
imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
imap4d_mainloop (int ifd, int ofd)
{
imap4d_tokbuf_t tokp;
char *text;
int debug_mode = isatty (fd);
int debug_mode = isatty (ifd);
imap4d_child_signal_setup (imap4d_child_signal);
io_setio (infile, outfile);
io_setio (ifd, ofd);
if (imap4d_preauth_setup (fd) == 0)
if (imap4d_preauth_setup (ifd) == 0)
{
if (debug_mode)
{
......@@ -451,7 +451,7 @@ imap4d_connection (int fd, struct sockaddr *sa, int salen, void *data,
idle_timeout = timeout;
if (imap4d_transcript != transcript)
imap4d_transcript = transcript;
imap4d_mainloop (fd, fdopen (fd, "r"), fdopen (fd, "w"));
imap4d_mainloop (fd, fd);
return 0;
}
......@@ -612,7 +612,7 @@ main (int argc, char **argv)
{
/* Make sure we are in the root directory. */
chdir ("/");
status = imap4d_mainloop (fileno (stdin), stdin, stdout);
status = imap4d_mainloop (MU_STDIN_FD, MU_STDOUT_FD);
}
if (status)
......
......@@ -224,7 +224,7 @@ extern int io_stream_completion_response (mu_stream_t str,
const char *format, ...)
MU_PRINTFLIKE(4,5);
int io_getline (char **pbuf, size_t *psize, size_t *pnbytes);
void io_setio (FILE*, FILE*);
void io_setio (int, int);
void io_flush (void);
int io_wait_input (int);
......
......@@ -22,21 +22,21 @@
mu_stream_t iostream;
void
io_setio (FILE *in, FILE *out)
io_setio (int ifd, int ofd)
{
mu_stream_t str, istream, ostream;
if (!in)
if (ifd == -1)
imap4d_bye (ERR_NO_IFILE);
if (!out)
if (ofd == -1)
imap4d_bye (ERR_NO_OFILE);
if (mu_stdio_stream_create (&istream, fileno (in),
MU_STREAM_READ | MU_STREAM_AUTOCLOSE))
if (mu_stdio_stream_create (&istream, ifd,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE))
imap4d_bye (ERR_STREAM_CREATE);
mu_stream_set_buffer (istream, mu_buffer_line, 0);
if (mu_stdio_stream_create (&ostream, fileno (out),
if (mu_stdio_stream_create (&ostream, ofd,
MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE))
imap4d_bye (ERR_STREAM_CREATE);
mu_stream_set_buffer (ostream, mu_buffer_line, 0);
......
......@@ -127,21 +127,21 @@ pop3d_abquit (int reason)
}
void
pop3d_setio (FILE *in, FILE *out)
pop3d_setio (int ifd, int ofd)
{
mu_stream_t str, istream, ostream;
if (!in)
if (ifd == -1)
pop3d_abquit (ERR_NO_IFILE);
if (!out)
if (ofd == -1)
pop3d_abquit (ERR_NO_OFILE);
if (mu_stdio_stream_create (&istream, fileno (in),
if (mu_stdio_stream_create (&istream, ifd,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE))
pop3d_abquit (ERR_NO_IFILE);
mu_stream_set_buffer (istream, mu_buffer_line, 0);
if (mu_stdio_stream_create (&ostream, fileno (out),
if (mu_stdio_stream_create (&ostream, ofd,
MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE))
pop3d_abquit (ERR_NO_OFILE);
......
......@@ -208,11 +208,10 @@ pop3d_get_client_address (int fd, struct sockaddr_in *pcs)
/* The main part of the daemon. This function reads input from the client and
executes the proper functions. Also handles the bulk of error reporting.
Arguments:
fd -- socket descriptor (for diagnostics)
infile -- input stream
outfile -- output stream */
ifd -- input descriptor
ofd -- output descriptor */
int
pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
pop3d_mainloop (int ifd, int ofd)
{
int status = OK;
char buffer[512];
......@@ -221,7 +220,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
mu_set_signals (pop3d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab));
pop3d_setio (infile, outfile);
pop3d_setio (ifd, ofd);
state = initial_state;
......@@ -299,7 +298,7 @@ pop3d_connection (int fd, struct sockaddr *sa, int salen, void *data,
idle_timeout = timeout;
if (pop3d_transcript != transcript)
pop3d_transcript = transcript;
pop3d_mainloop (fd, fdopen (fd, "r"), fdopen (fd, "w"));
pop3d_mainloop (fd, fd);
return 0;
}
......@@ -430,7 +429,7 @@ main (int argc, char **argv)
{
/* Make sure we are in the root directory. */
chdir ("/");
status = pop3d_mainloop (fileno (stdin), stdin, stdout);
status = pop3d_mainloop (MU_STDIN_FD, MU_STDOUT_FD);
}
if (status)
......
......@@ -241,7 +241,7 @@ extern int pop3d_touchlock (void);
extern int pop3d_unlock (void);
extern void pop3d_outf (const char *fmt, ...) MU_PRINTFLIKE(1,2);
extern void pop3d_setio (FILE *in, FILE *out);
extern void pop3d_setio (int, int);
extern char *pop3d_readline (char *, size_t);
extern void pop3d_flush_output (void);
......