summaryrefslogtreecommitdiff
path: root/include/mailutils/stream.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/mailutils/stream.h')
-rw-r--r--include/mailutils/stream.h122
1 files changed, 100 insertions, 22 deletions
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index aa216167f..5bf48c2ca 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -1,5 +1,5 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 2009-2019 Free Software Foundation, Inc.
+ Copyright (C) 2009-2024 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
@@ -17,8 +17,9 @@
#ifndef _MAILUTILS_STREAM_H
#define _MAILUTILS_STREAM_H
-#include <mailutils/types.h>
+#include <stdlib.h>
#include <stdarg.h>
+#include <mailutils/types.h>
#ifdef __cplusplus
extern "C" {
@@ -79,7 +80,10 @@ enum mu_buffer_type
#define MU_IOCTL_TLSSTREAM 13 /* TLS stream */
#define MU_IOCTL_WORDWRAPSTREAM 14 /* Word-wrapper stream */
#define MU_IOCTL_TCPSTREAM 15 /* TCP stream */
-
+
+#define MU_IOCTL_TIMEOUT 16 /* Get or set the I/O timeout value
+ (struct timeval) */
+
/* Opcodes common for various families */
#define MU_IOCTL_OP_GET 0
#define MU_IOCTL_OP_SET 1
@@ -169,6 +173,16 @@ enum mu_buffer_type
Arg: struct mu_locus_range *
*/
#define MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE 16
+
+ /* Get prefix.
+ Arg: char **
+ */
+#define MU_IOCTL_LOGSTREAM_GET_PREFIX 17
+
+ /* Set prefix.
+ Arg: char *
+ */
+#define MU_IOCTL_LOGSTREAM_SET_PREFIX 18
/* Opcodes for MU_IOCTL_XSCRIPTSTREAM */
/* Swap transcript levels.
@@ -177,7 +191,7 @@ enum mu_buffer_type
New transcript level is set to *X.
If setting separate levels for each channel, use MU_XSCRIPT_LEVEL_PACK
macro to pack them into one integer value. Use
- MU_IOCTL_XSCRIPTSTREAM_CHANNEL to confugure single channel.
+ MU_IOCTL_XSCRIPTSTREAM_CHANNEL to configure single channel.
Upon successful return, previous levels are stored in X. Use the
MU_XSCRIPT_LEVEL_UNPACK macro to retrieve level for a particular
@@ -270,22 +284,32 @@ struct mu_buffer_query
size_t bufsize; /* Buffer size */
};
-/* Statistics */
-#define MU_STREAM_STAT_IN 0
-#define MU_STREAM_STAT_OUT 1
-#define MU_STREAM_STAT_READS 2
-#define MU_STREAM_STAT_WRITES 3
-#define MU_STREAM_STAT_SEEKS 4
-#define _MU_STREAM_STAT_MAX 5
+/* Statistics */
+enum
+ {
+ MU_STREAM_STAT_IN, /* Bytes read */
+ MU_STREAM_STAT_OUT, /* Bytes written */
+ MU_STREAM_STAT_READS, /* Number of reads */
+ MU_STREAM_STAT_WRITES, /* Number of writes */
+ MU_STREAM_STAT_SEEKS, /* Number of seeks */
+ MU_STREAM_STAT_INLN, /* Lines read */
+ MU_STREAM_STAT_OUTLN, /* Lines written */
+ MU_STREAM_STAT_IN8BIT, /* 8-bit octets read */
+ MU_STREAM_STAT_OUT8BIT, /* 8-bit octets written */
+ _MU_STREAM_STAT_MAX
+ };
#define MU_STREAM_STAT_MASK(n) (1U<<(n+1))
+
#define MU_STREAM_STAT_MASK_ALL \
(MU_STREAM_STAT_MASK (MU_STREAM_STAT_IN) | \
MU_STREAM_STAT_MASK (MU_STREAM_STAT_OUT) | \
MU_STREAM_STAT_MASK (MU_STREAM_STAT_READS) | \
MU_STREAM_STAT_MASK (MU_STREAM_STAT_WRITES) | \
- MU_STREAM_STAT_MASK (MU_STREAM_STAT_SEEKS))
-
+ MU_STREAM_STAT_MASK (MU_STREAM_STAT_SEEKS) | \
+ MU_STREAM_STAT_MASK (MU_STREAM_STAT_INLN) | \
+ MU_STREAM_STAT_MASK (MU_STREAM_STAT_OUTLN))
+
typedef mu_off_t mu_stream_stat_buffer[_MU_STREAM_STAT_MAX];
int mu_stream_set_stat (mu_stream_t stream, int statmask,
mu_stream_stat_buffer statbuf);
@@ -317,13 +341,54 @@ int mu_stream_set_buffer (mu_stream_t stream, enum mu_buffer_type type,
int mu_stream_get_buffer (mu_stream_t stream,
struct mu_buffer_query *qry);
int mu_stream_read (mu_stream_t stream, void *buf, size_t size, size_t *pread);
-int mu_stream_readdelim (mu_stream_t stream, char *buf, size_t size,
- int delim, size_t *pread);
-int mu_stream_readline (mu_stream_t stream, char *buf, size_t size, size_t *pread);
-int mu_stream_getdelim (mu_stream_t stream, char **pbuf, size_t *psize,
- int delim, size_t *pread);
-int mu_stream_getline (mu_stream_t stream, char **pbuf, size_t *psize,
- size_t *pread);
+int mu_stream_timed_readdelim (mu_stream_t stream, char *buf, size_t size,
+ int delim, struct timeval *to, size_t *pread);
+static inline int
+mu_stream_readdelim (mu_stream_t stream, char *buf, size_t size,
+ int delim, size_t *pread)
+{
+ return mu_stream_timed_readdelim (stream, buf, size, delim, NULL, pread);
+}
+
+static inline int
+mu_stream_timed_readline (mu_stream_t stream, char *buf, size_t size,
+ struct timeval *tv,
+ size_t *pread)
+{
+ return mu_stream_timed_readdelim (stream, buf, size, '\n', tv, pread);
+}
+
+static inline int
+mu_stream_readline (mu_stream_t stream, char *buf, size_t size, size_t *pread)
+{
+ return mu_stream_timed_readline (stream, buf, size, NULL, pread);
+}
+
+int mu_stream_timed_getdelim (mu_stream_t stream, char **pbuf, size_t *psize,
+ int delim, struct timeval *to, size_t *pread);
+
+static inline int
+mu_stream_getdelim (mu_stream_t stream, char **pbuf, size_t *psize,
+ int delim, size_t *pread)
+{
+ return mu_stream_timed_getdelim (stream, pbuf, psize, delim, NULL, pread);
+}
+
+static inline int
+mu_stream_timed_getline (mu_stream_t stream, char **pbuf, size_t *psize,
+ struct timeval *to,
+ size_t *pread)
+{
+ return mu_stream_timed_getdelim (stream, pbuf, psize, '\n', to, pread);
+}
+
+static inline int
+mu_stream_getline (mu_stream_t stream, char **pbuf, size_t *psize,
+ size_t *pread)
+{
+ return mu_stream_timed_getline (stream, pbuf, psize, NULL, pread);
+}
+
int mu_stream_write (mu_stream_t stream, const void *buf, size_t size,
size_t *pwrite);
int mu_stream_writeline (mu_stream_t stream, const char *buf, size_t size);
@@ -351,14 +416,22 @@ int mu_stream_printf (mu_stream_t stream, const char *fmt, ...)
int mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
mu_off_t *pcsz);
+int mu_stream_copy_wcb (mu_stream_t dst, mu_stream_t src, mu_off_t size,
+ void (*cbf) (char *, size_t, void *), void *cbd,
+ mu_off_t *pcsz);
+int mu_stream_copy_nl (mu_stream_t dst, mu_stream_t src, mu_off_t size,
+ mu_off_t *pcsz);
+
int mu_stream_header_copy (mu_stream_t dst, mu_stream_t src, char **exclude_names);
+int mu_stream_shift (mu_stream_t str, mu_off_t off_a, mu_off_t off_b,
+ size_t bufsize);
int mu_file_stream_create (mu_stream_t *pstream, const char *filename, int flags);
struct mu_tempfile_hints;
int mu_temp_file_stream_create (mu_stream_t *pstream,
struct mu_tempfile_hints *hints, int flags);
-int mu_fd_stream_create (mu_stream_t *pstream, char *filename, int fd,
+int mu_fd_stream_create (mu_stream_t *pstream, char const *filename, int fd,
int flags);
#define MU_STDIN_FD 0
@@ -396,6 +469,8 @@ int mu_tcp_stream_create_with_source_host (mu_stream_t *stream,
int mu_tcp_stream_create (mu_stream_t *stream, const char *host, unsigned port,
int flags);
+int mu_mailbox_stream_create (mu_stream_t *pstream, const char *filename, int flags);
+
/* Transcript log levels */
#define MU_XSCRIPT_NORMAL 0 /* Normal transcript */
#define MU_XSCRIPT_SECURE 1 /* Security-related data filtered out */
@@ -446,7 +521,10 @@ int mu_nullstream_create (mu_stream_t *pref, int flags);
int mu_wordwrap_stream_create (mu_stream_t *pstream, mu_stream_t transport,
size_t left_margin, size_t right_margin);
-
+
+extern size_t mu_temp_file_threshold_size;
+int mu_temp_stream_create (mu_stream_t *pstream, size_t threshold);
+
#ifdef __cplusplus
}
#endif

Return to:

Send suggestions and report system problems to the System administrator.