diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2004-06-03 21:58:51 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2004-06-03 21:58:51 +0000 |
commit | 6de9251eb6e7ade349609e06ce08b320dfa65e64 (patch) | |
tree | b5d703a5abd59913bd5a4522244550721a0fd5fe | |
parent | aa61bbaaaa24a38eba2ed09a1939600766122e40 (diff) | |
download | mailutils-6de9251eb6e7ade349609e06ce08b320dfa65e64.tar.gz mailutils-6de9251eb6e7ade349609e06ce08b320dfa65e64.tar.bz2 |
Use new stream functions
-rw-r--r-- | examples/http.c | 35 | ||||
-rw-r--r-- | imap4d/auth_gsasl.c | 80 | ||||
-rw-r--r-- | imap4d/idle.c | 2 | ||||
-rw-r--r-- | imap4d/util.c | 47 | ||||
-rw-r--r-- | include/mailutils/sys/pop3.h | 1 | ||||
-rw-r--r-- | libsieve/extensions/spamd.c | 6 | ||||
-rw-r--r-- | mailbox/body.c | 15 | ||||
-rw-r--r-- | mailbox/file_stream.c | 47 | ||||
-rw-r--r-- | mailbox/filter.c | 13 | ||||
-rw-r--r-- | mailbox/imap/mbox.c | 29 | ||||
-rw-r--r-- | mailbox/mapfile_stream.c | 12 | ||||
-rw-r--r-- | mailbox/mbox/mbox.c | 27 | ||||
-rw-r--r-- | mailbox/message.c | 14 | ||||
-rw-r--r-- | mailbox/mime.c | 42 | ||||
-rw-r--r-- | mailbox/mutil.c | 39 | ||||
-rw-r--r-- | mailbox/pop/mbox.c | 43 | ||||
-rw-r--r-- | mailbox/pop/pop3_readline.c | 33 | ||||
-rw-r--r-- | mailbox/pop/pop3_sendline.c | 31 | ||||
-rw-r--r-- | mailbox/tcp.c | 26 | ||||
-rw-r--r-- | mh/mhn.c | 6 |
20 files changed, 240 insertions, 308 deletions
diff --git a/examples/http.c b/examples/http.c index 9090ac598..66c573a4f 100644 --- a/examples/http.c +++ b/examples/http.c @@ -33,11 +33,10 @@ char rbuf[1024]; int main (void) { - int ret, off = 0, fd; + int ret, off = 0; stream_t stream; size_t nb; - fd_set fds; - + ret = tcp_stream_create (&stream, "www.gnu.org", 80, MU_STREAM_NONBLOCK); if (ret != 0) { @@ -51,37 +50,22 @@ connect_again: { if (ret == EAGAIN) { - ret = stream_get_fd (stream, &fd); - if (ret != 0) - { - mu_error ("stream_get_fd: %s", mu_strerror (ret)); - exit (EXIT_FAILURE); - } - FD_ZERO (&fds); - FD_SET (fd, &fds); - select (fd + 1, NULL, &fds, NULL, NULL); + int wflags = MU_STREAM_READY_WR; + stream_wait (stream, &wflags, NULL); goto connect_again; } mu_error ("stream_open: %s", mu_strerror (ret)); exit (EXIT_FAILURE); } - ret = stream_get_fd (stream, &fd); - if (ret != 0) - { - mu_error ("stream_get_fd: %s", mu_strerror (ret)); - exit (EXIT_FAILURE); - } - write_again: ret = stream_write (stream, wbuf + off, strlen (wbuf), 0, &nb); if (ret != 0) { if (ret == EAGAIN) { - FD_ZERO (&fds); - FD_SET (fd, &fds); - select (fd + 1, NULL, &fds, NULL, NULL); + int wflags = MU_STREAM_READY_WR; + stream_wait (stream, &wflags, NULL); off += nb; goto write_again; } @@ -102,9 +86,8 @@ write_again: { if (ret == EAGAIN) { - FD_ZERO (&fds); - FD_SET (fd, &fds); - select (fd + 1, &fds, NULL, NULL, NULL); + int wflags = MU_STREAM_READY_RD; + stream_wait (stream, &wflags, NULL); } else { @@ -112,7 +95,7 @@ write_again: exit (EXIT_FAILURE); } } - write (2, rbuf, nb); + write (1, rbuf, nb); } while (nb || ret == EAGAIN); diff --git a/imap4d/auth_gsasl.c b/imap4d/auth_gsasl.c index 4d27fb704..f9b645974 100644 --- a/imap4d/auth_gsasl.c +++ b/imap4d/auth_gsasl.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2004 Free Software Foundation, Inc. GNU Mailutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,11 +25,11 @@ static Gsasl_session_ctx *sess_ctx; static void auth_gsasl_capa_init __P((int disable)); static int -create_gsasl_stream (stream_t *newstr, int fd, int flags) +create_gsasl_stream (stream_t *newstr, stream_t transport, int flags) { int rc; - rc = gsasl_stream_create (newstr, fd, sess_ctx, flags); + rc = gsasl_stream_create (newstr, transport, sess_ctx, flags); if (rc) { syslog (LOG_ERR, _("cannot create SASL stream: %s"), @@ -62,37 +62,18 @@ gsasl_replace_streams (void *self, void *data) return 0; } -#define AUTHBUFSIZE 512 - -static int -auth_step_base64(Gsasl_session_ctx *sess_ctx, char *input, - char **output, size_t *output_len) +static void +finish_session (void) { - int rc; - - while (1) - { - rc = gsasl_server_step_base64 (sess_ctx, input, *output, *output_len); - - if (rc == GSASL_TOO_SMALL_BUFFER) - { - *output_len += AUTHBUFSIZE; - *output = realloc(*output, *output_len); - if (output) - continue; - } - break; - } - return rc; + gsasl_server_finish (sess_ctx); } static int auth_gsasl (struct imap4d_command *command, - char *auth_type, char *arg, char **username) + char *auth_type, char *arg, char **username) { char *input = NULL; char *output; - size_t output_len; char *s; int rc; @@ -109,15 +90,8 @@ auth_gsasl (struct imap4d_command *command, gsasl_server_application_data_set (sess_ctx, username); - output_len = AUTHBUFSIZE; - output = malloc (output_len); - if (!output) - imap4d_bye (ERR_NO_MEM); - - output[0] = '\0'; - - while ((rc = auth_step_base64 (sess_ctx, input, &output, &output_len)) - == GSASL_NEEDS_MORE) + output = NULL; + while ((rc = gsasl_step64 (sess_ctx, input, &output)) == GSASL_NEEDS_MORE) { util_send ("+ %s\r\n", output); input = imap4d_readline_ex (); @@ -144,18 +118,14 @@ auth_gsasl (struct imap4d_command *command, if (sess_ctx) { - stream_t in, out, new_in, new_out; + stream_t tmp, new_in, new_out; stream_t *s; - int infd, outfd; - - util_get_input (&in); - stream_get_fd (in, &infd); - - util_get_output (&out); - stream_get_fd (out, &outfd); - if (create_gsasl_stream (&new_in, infd, MU_STREAM_READ)) + + util_get_input (&tmp); + if (create_gsasl_stream (&new_in, tmp, MU_STREAM_READ)) return RESP_NO; - if (create_gsasl_stream (&new_out, outfd, MU_STREAM_WRITE)) + util_get_output (&tmp); + if (create_gsasl_stream (&new_out, tmp, MU_STREAM_WRITE)) { stream_destroy (&new_in, stream_get_owner (new_in)); return RESP_NO; @@ -166,8 +136,8 @@ auth_gsasl (struct imap4d_command *command, s[1] = new_out; util_register_event (STATE_NONAUTH, STATE_AUTH, gsasl_replace_streams, s); + util_atexit (finish_session); } - auth_gsasl_capa_init (1); return RESP_OK; @@ -180,15 +150,7 @@ auth_gsasl_capa_init (int disable) char *listmech, *name, *s; size_t size; - rc = gsasl_server_listmech (ctx, NULL, &size); - if (rc != GSASL_OK) - return; - - listmech = malloc (size); - if (!listmech) - imap4d_bye (ERR_NO_MEM); - - rc = gsasl_server_listmech (ctx, listmech, &size); + rc = gsasl_server_mechlist (ctx, &listmech); if (rc != GSASL_OK) return; @@ -300,7 +262,7 @@ void auth_gsasl_init () { int rc; - + rc = gsasl_init (&ctx); if (rc != GSASL_OK) { @@ -321,3 +283,9 @@ auth_gsasl_init () auth_gsasl_capa_init (0); } +wd() +{ + int _st=0; + while (_st==0) + _st=_st; +} diff --git a/imap4d/idle.c b/imap4d/idle.c index ca89e69a3..97c89692b 100644 --- a/imap4d/idle.c +++ b/imap4d/idle.c @@ -25,7 +25,7 @@ imap4d_idle (struct imap4d_command *command, char *arg) if (util_getword (arg, &sp)) return util_finish (command, RESP_BAD, "Too many args"); - + if (util_wait_input (0) == -1) return util_finish (command, RESP_NO, "Cannot idle"); diff --git a/imap4d/util.c b/imap4d/util.c index d3ff704d3..1d47c621f 100644 --- a/imap4d/util.c +++ b/imap4d/util.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. GNU Mailutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1084,16 +1084,12 @@ util_get_output (stream_t *pstr) void util_set_input (stream_t str) { - if (istream) - stream_destroy (&istream, stream_get_owner (istream)); istream = str; } void util_set_output (stream_t str) { - if (ostream) - stream_destroy (&ostream, stream_get_owner (ostream)); ostream = str; } @@ -1104,30 +1100,20 @@ util_set_output (stream_t str) int util_wait_input (int timeout) { - int rc, fd; - fd_set rdset; + int wflags = MU_STREAM_READY_RD; + struct timeval tv; + int status; - if (stream_get_fd (istream, &fd)) + tv.tv_sec = timeout; + tv.tv_usec = 0; + status = stream_wait (istream, &wflags, &tv); + if (status) { - errno = ENOSYS; + syslog (LOG_ERR, _("cannot poll input stream: %s"), + mu_strerror(status)); return -1; } - - FD_ZERO (&rdset); - FD_SET (fd, &rdset); - - do - { - struct timeval tv; - - tv.tv_sec = timeout; - tv.tv_usec = 0; - - rc = select (fd + 1, &rdset, NULL, NULL, &tv); - } - while (rc == -1 && errno == EINTR); - - return rc; + return wflags & MU_STREAM_READY_RD; } void @@ -1147,14 +1133,9 @@ int imap4d_init_tls_server () { stream_t stream; - int in_fd; - int out_fd; int rc; - - if (stream_get_fd (istream, &in_fd) - || stream_get_fd (ostream, &out_fd)) - return 0; - rc = tls_stream_create (&stream, in_fd, out_fd, 0); + + rc = tls_stream_create (&stream, istream, ostream, 0); if (rc) return 0; @@ -1166,8 +1147,6 @@ imap4d_init_tls_server () return 0; } - stream_destroy (&istream, stream_get_owner (istream)); - stream_destroy (&ostream, stream_get_owner (ostream)); istream = ostream = stream; return 1; } diff --git a/include/mailutils/sys/pop3.h b/include/mailutils/sys/pop3.h index c9fa06385..0ba218ce1 100644 --- a/include/mailutils/sys/pop3.h +++ b/include/mailutils/sys/pop3.h @@ -91,6 +91,7 @@ struct _mu_pop3 extern int mu_pop3_debug_cmd (mu_pop3_t); extern int mu_pop3_debug_ack (mu_pop3_t); extern int mu_pop3_stream_create (mu_pop3_t pop3, stream_t *pstream); +extern int mu_pop3_carrier_is_ready (stream_t carrier, int flag, int timeout); /* Check for non recoverable error. The error is consider not recoverable if not part of the signal set: diff --git a/libsieve/extensions/spamd.c b/libsieve/extensions/spamd.c index f06caac49..26fa7f508 100644 --- a/libsieve/extensions/spamd.c +++ b/libsieve/extensions/spamd.c @@ -106,10 +106,10 @@ spamd_destroy (stream_t *stream) static void spamd_shutdown (stream_t stream, int flag) { - int fd; + mu_transport_t trans; stream_flush (stream); - stream_get_fd (stream, &fd); - shutdown (fd, flag); + stream_get_transport (stream, &trans); + shutdown ((int)trans, flag); } static void diff --git a/mailbox/body.c b/mailbox/body.c index 82d632856..f3dfcfbd6 100644 --- a/mailbox/body.c +++ b/mailbox/body.c @@ -36,7 +36,7 @@ #define BODY_MODIFIED 0x10000 static int _body_flush __P ((stream_t)); -static int _body_get_fd __P ((stream_t, int *, int *)); +static int _body_get_transport2 __P ((stream_t, mu_transport_t *, mu_transport_t *)); static int _body_read __P ((stream_t, char *, size_t, off_t, size_t *)); static int _body_readline __P ((stream_t, char *, size_t, off_t, size_t *)); static int _body_truncate __P ((stream_t, off_t)); @@ -162,7 +162,7 @@ body_get_stream (body_t body, stream_t *pstream) status = stream_open (body->fstream); if (status != 0) return status; - stream_set_fd (body->stream, _body_get_fd, body); + stream_set_get_transport2 (body->stream, _body_get_transport2, body); stream_set_read (body->stream, _body_read, body); stream_set_readline (body->stream, _body_readline, body); stream_set_write (body->stream, _body_write, body); @@ -246,15 +246,10 @@ body_set_size (body_t body, int (*_size)(body_t, size_t*) , void *owner) /* Stub function for the body stream. */ static int -_body_get_fd (stream_t stream, int *fd, int *fd2) +_body_get_transport2 (stream_t stream, mu_transport_t *pin, mu_transport_t *pout) { - if (fd2) - return ENOSYS; - else - { - body_t body = stream_get_owner (stream); - return stream_get_fd (body->fstream, fd); - } + body_t body = stream_get_owner (stream); + return stream_get_transport2 (body->fstream, pin, pout); } static int diff --git a/mailbox/file_stream.c b/mailbox/file_stream.c index 2c503bae7..01175fe15 100644 --- a/mailbox/file_stream.c +++ b/mailbox/file_stream.c @@ -39,6 +39,7 @@ #include <mailutils/argcv.h> #include <mailutils/nls.h> #include <mailutils/list.h> +#include <mailutils/mutil.h> struct _file_stream { @@ -319,22 +320,32 @@ _file_flush (stream_t stream) return 0; } +int +_file_wait (stream_t stream, int *pflags, struct timeval *tvp) +{ + struct _file_stream *fs = stream_get_owner (stream); + + if (!fs->file) + return EINVAL; + return mu_fd_wait (fileno (fs->file), pflags, tvp); +} + static int -_file_get_fd (stream_t stream, int *pfd, int *pfd2) +_file_get_transport2 (stream_t stream, + mu_transport_t *pin, mu_transport_t *pout) { struct _file_stream *fs = stream_get_owner (stream); int status = 0; - if (pfd2) - return ENOSYS; - - if (pfd) + if (pin) { if (fs->file) - *pfd = fileno (fs->file); + *pin = (mu_transport_t) fs->file; else status = EINVAL; } + if (pout) + *pout = NULL; return status; } @@ -493,10 +504,10 @@ file_stream_create (stream_t *stream, const char* filename, int flags) return ENOMEM; if ((fs->filename = strdup(filename)) == NULL) - { - free (fs); - return ENOMEM; - } + { + free (fs); + return ENOMEM; + } ret = stream_create (stream, flags|MU_STREAM_NO_CHECK, fs); if (ret != 0) @@ -508,7 +519,7 @@ file_stream_create (stream_t *stream, const char* filename, int flags) stream_set_open (*stream, _file_open, fs); stream_set_close (*stream, _file_close, fs); - stream_set_fd (*stream, _file_get_fd, fs); + stream_set_get_transport2 (*stream, _file_get_transport2, fs); stream_set_read (*stream, _file_read, fs); stream_set_readline (*stream, _file_readline, fs); stream_set_write (*stream, _file_write, fs); @@ -517,6 +528,7 @@ file_stream_create (stream_t *stream, const char* filename, int flags) stream_set_flush (*stream, _file_flush, fs); stream_set_destroy (*stream, _file_destroy, fs); stream_set_strerror (*stream, _file_strerror, fs); + stream_set_wait (*stream, _file_wait, fs); return 0; } @@ -572,10 +584,11 @@ stdio_stream_create (stream_t *stream, FILE *file, int flags) stream_set_open (*stream, NULL, fs); stream_set_close (*stream, _file_close, fs); - stream_set_fd (*stream, _file_get_fd, fs); + stream_set_get_transport2 (*stream, _file_get_transport2, fs); stream_set_flush (*stream, _file_flush, fs); stream_set_destroy (*stream, _file_destroy, fs); - + stream_set_wait (*stream, _file_wait, fs); + return 0; } @@ -936,14 +949,14 @@ _prog_flush (stream_t stream) } static int -_prog_get_fd (stream_t stream, int *pfd, int *pfd2) +_prog_get_transport2 (stream_t stream, mu_transport_t *pin, mu_transport_t *pout) { int rc; struct _prog_stream *fs = stream_get_owner (stream); - if ((rc = stream_get_fd (fs->in, pfd)) != 0) + if ((rc = stream_get_transport (fs->in, pin)) != 0) return rc; - return stream_get_fd (fs->out, pfd2); + return stream_get_transport (fs->out, pout); } int @@ -992,7 +1005,7 @@ _prog_stream_create (struct _prog_stream **pfs, stream_set_open (*stream, _prog_open, fs); stream_set_close (*stream, _prog_close, fs); - stream_set_fd (*stream, _prog_get_fd, fs); + stream_set_get_transport2 (*stream, _prog_get_transport2, fs); stream_set_flush (*stream, _prog_flush, fs); stream_set_destroy (*stream, _prog_destroy, fs); diff --git a/mailbox/filter.c b/mailbox/filter.c index e99c2e77a..5464026d7 100644 --- a/mailbox/filter.c +++ b/mailbox/filter.c @@ -112,15 +112,10 @@ filter_flush (stream_t stream) } static int -filter_get_fd (stream_t stream, int *pfd, int *pfd2) +filter_get_transport2 (stream_t stream, mu_transport_t *pin, mu_transport_t *pout) { - if (pfd2) - return ENOSYS; - else - { - filter_t filter = stream_get_owner (stream); - return stream_get_fd (filter->stream, pfd); - } + filter_t filter = stream_get_owner (stream); + return stream_get_transport2 (filter->stream, pin, pout); } static int @@ -252,7 +247,7 @@ filter_create (stream_t *pstream, stream_t stream, const char *name, stream_set_read (*pstream, filter_read, filter); stream_set_readline (*pstream, filter_readline, filter); stream_set_write (*pstream, filter_write, filter); - stream_set_fd (*pstream, filter_get_fd, filter ); + stream_set_get_transport2 (*pstream, filter_get_transport2, filter ); stream_set_truncate (*pstream, filter_truncate, filter ); stream_set_size (*pstream, filter_size, filter ); stream_set_flush (*pstream, filter_flush, filter ); diff --git a/mailbox/imap/mbox.c b/mailbox/imap/mbox.c index f27d60747..d075d314d 100644 --- a/mailbox/imap/mbox.c +++ b/mailbox/imap/mbox.c @@ -76,7 +76,8 @@ static int imap_copy_message __P ((mailbox_t, message_t)); static int imap_submessage_size __P ((msg_imap_t, size_t *)); static int imap_message_size __P ((message_t, size_t *)); static int imap_message_lines __P ((message_t, size_t *)); -static int imap_message_fd __P ((stream_t, int *, int *)); +static int imap_message_get_transport2 __P ((stream_t, mu_transport_t *pin, + mu_transport_t *pout)); static int imap_message_read __P ((stream_t , char *, size_t, off_t, size_t *)); static int imap_message_uid __P ((message_t, size_t *)); @@ -104,11 +105,12 @@ static int imap_body_read __P ((stream_t, char *, size_t, off_t, size_t *)); static int imap_body_size __P ((body_t, size_t *)); static int imap_body_lines __P ((body_t, size_t *)); -static int imap_body_fd __P ((stream_t, int *, int *)); +static int imap_body_get_transport2 __P ((stream_t, mu_transport_t *pin, mu_transport_t *pout)); /* Helpers. */ -static int imap_get_fd2 __P ((msg_imap_t msg_imap, int *pfd1, - int *pfd2)); +static int imap_get_transport2 __P ((msg_imap_t msg_imap, + mu_transport_t *pin, + mu_transport_t *pout)); static int imap_get_message0 __P ((msg_imap_t, message_t *)); static int fetch_operation __P ((f_imap_t, msg_imap_t, char *, size_t, size_t *)); static void free_subparts __P ((msg_imap_t)); @@ -521,7 +523,7 @@ imap_get_message0 (msg_imap_t msg_imap, message_t *pmsg) } stream_setbufsiz (stream, 128); stream_set_read (stream, imap_message_read, msg); - stream_set_fd (stream, imap_message_fd, msg); + stream_set_get_transport2 (stream, imap_message_get_transport2, msg); message_set_stream (msg, stream, msg_imap); message_set_size (msg, imap_message_size, msg_imap); message_set_lines (msg, imap_message_lines, msg_imap); @@ -570,7 +572,7 @@ imap_get_message0 (msg_imap_t msg_imap, message_t *pmsg) } stream_setbufsiz (stream, 128); stream_set_read (stream, imap_body_read, body); - stream_set_fd (stream, imap_body_fd, body); + stream_set_get_transport2 (stream, imap_body_get_transport2, body); body_set_size (body, imap_body_size, msg); body_set_lines (body, imap_body_lines, msg); body_set_stream (body, stream, msg); @@ -1333,11 +1335,11 @@ imap_message_uid (message_t msg, size_t *puid) } static int -imap_message_fd (stream_t stream, int *pfd, int *pfd2) +imap_message_get_transport2 (stream_t stream, mu_transport_t *pin, mu_transport_t *pout) { message_t msg = stream_get_owner (stream); msg_imap_t msg_imap = message_get_owner (msg); - return imap_get_fd2 (msg_imap, pfd, pfd2); + return imap_get_transport2 (msg_imap, pin, pout); } /* Mime. */ @@ -2005,24 +2007,25 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset, } static int -imap_body_fd (stream_t stream, int *pfd, int *pfd2) +imap_body_get_transport2 (stream_t stream, mu_transport_t *pin, + mu_transport_t *pout) { body_t body = stream_get_owner (stream); message_t msg = body_get_owner (body); msg_imap_t msg_imap = message_get_owner (msg); - return imap_get_fd2 (msg_imap, pfd, pfd2); + return imap_get_transport2 (msg_imap, pin, pout); } static int -imap_get_fd2 (msg_imap_t msg_imap, int *pfd1, int *pfd2) +imap_get_transport2 (msg_imap_t msg_imap, mu_transport_t *pin, mu_transport_t *pout) { if ( msg_imap && msg_imap->m_imap && msg_imap->m_imap->f_imap && msg_imap->m_imap->f_imap->folder) - return stream_get_fd2 (msg_imap->m_imap->f_imap->folder->stream, - pfd1, pfd2); + return stream_get_transport2 (msg_imap->m_imap->f_imap->folder->stream, + pin, pout); return EINVAL; } diff --git a/mailbox/mapfile_stream.c b/mailbox/mapfile_stream.c index bff7e8039..48a92ea31 100644 --- a/mailbox/mapfile_stream.c +++ b/mailbox/mapfile_stream.c @@ -236,15 +236,15 @@ _mapfile_flush (stream_t stream) } static int -_mapfile_get_fd (stream_t stream, int *pfd, int *pfd2) +_mapfile_get_transport2 (stream_t stream, mu_transport_t *pin, mu_transport_t *pout) { struct _mapfile_stream *mfs = stream_get_owner (stream); - if (pfd2) - return ENOSYS; + if (pout) + *pout = NULL; - if (pfd) - *pfd = mfs->fd; + if (pin) + *pin = mfs->fd; return 0; } @@ -377,7 +377,7 @@ mapfile_stream_create (stream_t *stream, const char* filename, int flags) stream_set_open (*stream, _mapfile_open, fs); stream_set_close (*stream, _mapfile_close, fs); - stream_set_fd (*stream, _mapfile_get_fd, fs); + stream_set_get_transport2 (*stream, _mapfile_get_transport2, fs); stream_set_read (*stream, _mapfile_read, fs); stream_set_readline (*stream, _mapfile_readline, fs); stream_set_write (*stream, _mapfile_write, fs); diff --git a/mailbox/mbox/mbox.c b/mailbox/mbox/mbox.c index 16dd7c7ea..bb8dce1dc 100644 --- a/mailbox/mbox/mbox.c +++ b/mailbox/mbox/mbox.c @@ -78,8 +78,8 @@ static int mbox_append_message0 __P ((mailbox_t, message_t, off_t *, static int mbox_message_uid __P ((message_t, size_t *)); static int mbox_header_fill __P ((header_t, char *, size_t, off_t, size_t *)); -static int mbox_get_body_fd __P ((stream_t, int *, int *)); -static int mbox_get_fd __P ((mbox_message_t, int *)); +static int mbox_get_body_transport __P ((stream_t, mu_transport_t *, mu_transport_t *)); +static int mbox_get_transport2 __P ((mbox_message_t, mu_transport_t *, mu_transport_t *)); static int mbox_get_attr_flags __P ((attribute_t, int *)); static int mbox_set_attr_flags __P ((attribute_t, int)); static int mbox_unset_attr_flags __P ((attribute_t, int)); @@ -829,27 +829,20 @@ mbox_message_uid (message_t msg, size_t *puid) } static int -mbox_get_body_fd (stream_t is, int *pfd, int *pfd2) +mbox_get_body_transport (stream_t is, mu_transport_t *pin, mu_transport_t *pout) { - if (pfd2) - return ENOSYS; - else - { - body_t body = stream_get_owner (is); - message_t msg = body_get_owner (body); - mbox_message_t mum = message_get_owner (msg); - return mbox_get_fd (mum, pfd); - } + body_t body = stream_get_owner (is); + message_t msg = body_get_owner (body); + mbox_message_t mum = message_get_owner (msg); + return mbox_get_transport2 (mum, pin, pout); } static int -mbox_get_fd (mbox_message_t mum, int *pfd) +mbox_get_transport2 (mbox_message_t mum, mu_transport_t *pin, mu_transport_t *pout) { - int status; if (mum == NULL) return EINVAL; - status = stream_get_fd (mum->mud->mailbox->stream, pfd); - return status; + return stream_get_transport2 (mum->mud->mailbox->stream, pin, pout); } static int @@ -1252,7 +1245,7 @@ mbox_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) } stream_set_read (stream, mbox_body_read, body); stream_set_readline (stream, mbox_body_readline, body); - stream_set_fd (stream, mbox_get_body_fd, body); + stream_set_get_transport2 (stream, mbox_get_body_transport, body); stream_set_size (stream, mbox_stream_size, body); body_set_stream (body, stream, msg); body_set_size (body, mbox_body_size, msg); diff --git a/mailbox/message.c b/mailbox/message.c index 774800678..2333ef22e 100644 --- a/mailbox/message.c +++ b/mailbox/message.c @@ -56,7 +56,8 @@ static int message_read __P ((stream_t is, char *buf, size_t buflen, off_t off, size_t *pnread )); static int message_write __P ((stream_t os, const char *buf, size_t buflen, off_t off, size_t *pnwrite)); -static int message_get_fd __P ((stream_t stream, int *pfd, int *pfd2)); +static int message_get_transport2 __P ((stream_t stream, mu_transport_t *pin, + mu_transport_t *pout)); static int message_sender __P ((envelope_t envelope, char *buf, size_t len, size_t *pnwrite)); static int message_date __P ((envelope_t envelope, char *buf, size_t len, @@ -404,7 +405,7 @@ message_get_stream (message_t msg, stream_t *pstream) return status; stream_set_read (stream, message_read, msg); stream_set_write (stream, message_write, msg); - stream_set_fd (stream, message_get_fd, msg); + stream_set_get_transport2 (stream, message_get_transport2, msg); stream_set_size (stream, message_stream_size, msg); stream_set_flags (stream, MU_STREAM_RDWR); msg->stream = stream; @@ -893,9 +894,8 @@ message_write (stream_t os, const char *buf, size_t buflen, return status; } -/* Implements the stream_get_fd () on the message stream. */ static int -message_get_fd (stream_t stream, int *pfd, int *pfd2) +message_get_transport2 (stream_t stream, mu_transport_t *pin, mu_transport_t *pout) { message_t msg = stream_get_owner (stream); body_t body; @@ -903,8 +903,8 @@ message_get_fd (stream_t stream, int *pfd, int *pfd2) if (msg == NULL) return EINVAL; - if (pfd2) - return ENOSYS; + if (pout) + *pout = NULL; /* Probably being lazy, then create a body for the stream. */ if (msg->body == NULL) @@ -918,7 +918,7 @@ message_get_fd (stream_t stream, int *pfd, int *pfd2) body = msg->body; body_get_stream (body, &is); - return stream_get_fd (is, pfd); + return stream_get_transport2 (is, pin, pout); } /* Implements the stream_stream_size () on the message stream. */ diff --git a/mailbox/mime.c b/mailbox/mime.c index 3d2040b91..2ff0cd0a3 100644 --- a/mailbox/mime.c +++ b/mailbox/mime.c @@ -433,17 +433,12 @@ _mimepart_body_read (stream_t stream, char *buf, size_t buflen, off_t off, } static int -_mimepart_body_fd (stream_t stream, int *fd, int *fd2) +_mimepart_body_transport (stream_t stream, mu_transport_t *tr1, mu_transport_t *tr2) { - if (fd2) - return ENOSYS; - else - { - body_t body = stream_get_owner (stream); - message_t msg = body_get_owner (body); - struct _mime_part *mime_part = message_get_owner (msg); - return stream_get_fd (mime_part->mime->stream, fd); - } + body_t body = stream_get_owner (stream); + message_t msg = body_get_owner (body); + struct _mime_part *mime_part = message_get_owner (msg); + return stream_get_transport2 (mime_part->mime->stream, tr1, tr2); } static int @@ -662,22 +657,17 @@ _mime_body_read (stream_t stream, char *buf, size_t buflen, off_t off, } static int -_mime_body_fd (stream_t stream, int *fd, int *fd2) +_mime_body_transport (stream_t stream, mu_transport_t *tr1, mu_transport_t *tr2) { - if (fd2) - return ENOSYS; - else - { - body_t body = stream_get_owner (stream); - message_t msg = body_get_owner (body); - mime_t mime = message_get_owner (msg); - stream_t msg_stream = NULL; + body_t body = stream_get_owner (stream); + message_t msg = body_get_owner (body); + mime_t mime = message_get_owner (msg); + stream_t msg_stream = NULL; - if (mime->nmtp_parts == 0 || mime->cur_offset == 0) - return EINVAL; - message_get_stream (mime->mtp_parts[mime->cur_part]->msg, &msg_stream); - return stream_get_fd (msg_stream, fd); - } + if (mime->nmtp_parts == 0 || mime->cur_offset == 0) + return EINVAL; + message_get_stream (mime->mtp_parts[mime->cur_part]->msg, &msg_stream); + return stream_get_transport2 (msg_stream, tr1, tr2); } static int @@ -870,7 +860,7 @@ mime_get_part (mime_t mime, size_t part, message_t * msg) body)) == 0) { stream_set_read (stream, _mimepart_body_read, body); - stream_set_fd (stream, _mimepart_body_fd, body); + stream_set_get_transport2 (stream, _mimepart_body_transport, body); body_set_stream (body, stream, mime_part->msg); message_set_body (mime_part->msg, body, mime_part); mime_part->body_created = 1; @@ -945,7 +935,7 @@ mime_get_message (mime_t mime, message_t * msg) == 0) { stream_set_read (body_stream, _mime_body_read, body); - stream_set_fd (body_stream, _mime_body_fd, body); + stream_set_get_transport2 (body_stream, _mime_body_transport, body); body_set_stream (body, body_stream, mime->msg); *msg = mime->msg; return 0; diff --git a/mailbox/mutil.c b/mailbox/mutil.c index a9d50d4fa..1830f7a9e 100644 --- a/mailbox/mutil.c +++ b/mailbox/mutil.c @@ -50,6 +50,7 @@ #include <mailutils/message.h> #include <mailutils/envelope.h> |