Commit 65ec43cb authored by Dan Winship's avatar Dan Winship

Use CamelException to signal failure. (camel_stream_write_strings):

	* camel-stream.c (camel_stream_read, camel_stream_write,
	camel_stream_flush, camel_stream_reset, camel_stream_printf,
	camel_stream_write_to_stream): Use CamelException to signal
	failure.
	(camel_stream_write_strings): Remove. camel_stream_printf is more
	useful in most of the places that used this.
	(camel_stream_write_string): Change from macro to function to
	prevent problems with double-evaluation.

	* camel-seekable-stream.c (camel_seekable_stream_seek,
	camel_seekable_stream_set_bounds): Use CamelException.
	(reset): Update.

	* camel-seekable-substream.c, camel-stream-buffer.c,
	camel-stream-filter.c, camel-stream-fs.c, camel-stream-mem.c:
	Update.

	* camel-stream-fs.c: Remove the virtual init functions and move
	the code into the creator functions. Add CamelExceptions to
	creation functions that could fail.

	* camel-data-wrapper.c (camel_data_wrapper_write_to_stream): Use
	CamelException.
	* camel-mime-message.c, camel-mime-part.c, camel-multipart.c
	(write_to_stream): Update.

	* camel-mime-parser.c: add an exception to the mime parser private
	data and pass that to stream functions as needed.

	* gmime-content-field.c, md5-utils.c: Update (badly) for stream
	changes.

	* camel-exception.h (camel_exception_is_set): convenience macro.

	* providers/Makefile.am: disable SMTP for now

	* providers/mbox/camel-mbox-folder.c (mbox_append_message): Pass
	CamelException to the functions that now need it. Check the
	exception after calling camel_stream_flush, and fail if it fails.
	(mbox_get_message_by_uid): More updates.

	* providers/pop/camel-pop3-folder.c,
	providers/pop/camel-pop3-store.c,
	providers/sendmail/camel-sendmail/transport.c: Update.

svn path=/trunk/; revision=2924
parent 3050b3ba
2000-05-08 Dan Winship <danw@helixcode.com>
* camel-stream.c (camel_stream_read, camel_stream_write,
camel_stream_flush, camel_stream_reset, camel_stream_printf,
camel_stream_write_to_stream): Use CamelException to signal
failure.
(camel_stream_write_strings): Remove. camel_stream_printf is more
useful in most of the places that used this.
(camel_stream_write_string): Change from macro to function to
prevent problems with double-evaluation.
* camel-seekable-stream.c (camel_seekable_stream_seek,
camel_seekable_stream_set_bounds): Use CamelException.
(reset): Update.
* camel-seekable-substream.c, camel-stream-buffer.c,
camel-stream-filter.c, camel-stream-fs.c, camel-stream-mem.c:
Update.
* camel-stream-fs.c: Remove the virtual init functions and move
the code into the creator functions. Add CamelExceptions to
creation functions that could fail.
* camel-data-wrapper.c (camel_data_wrapper_write_to_stream): Use
CamelException.
* camel-mime-message.c, camel-mime-part.c, camel-multipart.c
(write_to_stream): Update.
* camel-mime-parser.c: add an exception to the mime parser private
data and pass that to stream functions as needed.
* gmime-content-field.c, md5-utils.c: Update (badly) for stream
changes.
* camel-exception.h (camel_exception_is_set): convenience macro.
* providers/Makefile.am: disable SMTP for now
* providers/mbox/camel-mbox-folder.c (mbox_append_message): Pass
CamelException to the functions that now need it. Check the
exception after calling camel_stream_flush, and fail if it fails.
(mbox_get_message_by_uid): More updates.
* providers/pop/camel-pop3-folder.c,
providers/pop/camel-pop3-store.c,
providers/sendmail/camel-sendmail/transport.c: Update.
2000-05-08 NotZed <NotZed@HelixCode.com>
* camel-mime-message.c (process_header): Format From and Reply-To
......
......@@ -24,6 +24,7 @@
*/
#include <config.h>
#include "camel-data-wrapper.h"
#include "camel-exception.h"
#include <errno.h>
......@@ -41,7 +42,7 @@ static CamelStream *get_output_stream (CamelDataWrapper *data_wrapper);
static int construct_from_stream(CamelDataWrapper *, CamelStream *);
static int write_to_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream *stream, CamelException *ex);
static void set_mime_type (CamelDataWrapper *data_wrapper,
const gchar *mime_type);
static gchar *get_mime_type (CamelDataWrapper *data_wrapper);
......@@ -204,44 +205,44 @@ camel_data_wrapper_get_output_stream (CamelDataWrapper *data_wrapper)
static int
write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
CamelException *ex)
{
CamelStream *output_stream;
d(printf("data_wrapper::write_to_stream\n"));
output_stream = camel_data_wrapper_get_output_stream (data_wrapper);
if (!output_stream) {
g_warning("write to stream with no stream");
errno = EBADF;
return -1;
}
g_return_val_if_fail (CAMEL_IS_STREAM (output_stream), -1);
camel_stream_reset (output_stream);
return camel_stream_write_to_stream(output_stream, stream);
camel_stream_reset (output_stream, ex);
if (camel_exception_is_set (ex))
return -1;
return camel_stream_write_to_stream (output_stream, stream, ex);
}
/**
* camel_data_wrapper_write_to_stream:
* @data_wrapper: a data wrapper
* @stream: stream for data to be written to
* @ex: a CamelException
*
* Writes the data content to @stream in a machine-independent format
* appropriate for the data. It should be possible to construct an
* equivalent data wrapper object later by passing this stream to
* camel_data_construct_from_stream().
*
* Returns the number of bytes written, and -1 for error.
* Return value: the number of bytes written, or -1 if an error occurs.
**/
int
camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream)
CamelStream *stream, CamelException *ex)
{
g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1);
g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
return CDW_CLASS (data_wrapper)->write_to_stream (data_wrapper, stream);
return CDW_CLASS (data_wrapper)->write_to_stream (data_wrapper,
stream, ex);
}
static int
......
......@@ -71,7 +71,8 @@ typedef struct {
GMimeContentField *mime_type_field);
int (*write_to_stream) (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream *stream,
CamelException *ex);
int (*construct_from_stream) (CamelDataWrapper *data_wrapper,
CamelStream *);
......@@ -87,7 +88,8 @@ GtkType camel_data_wrapper_get_type (void);
CamelDataWrapper *camel_data_wrapper_new (void);
int camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream *stream,
CamelException *ex);
void camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper,
const gchar *mime_type);
gchar * camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper);
......
......@@ -153,7 +153,8 @@ camel_exception_set (CamelException *ex,
* camel_exception_setv: set an exception
* @ex: exception object
* @id: exception id
* @format: format of the description string. The format string is used as in printf().
* @format: format of the description string. The format string is
* used as in printf().
*
* Set the value of an exception. The exception id is
* a unique number representing the exception. The
......@@ -162,6 +163,9 @@ camel_exception_set (CamelException *ex,
* In this version, the string is created from the format
* string and the variable argument list.
*
* It is safe to say:
* camel_exception_setv (ex, ..., camel_exception_get_description (ex), ...);
*
* When @ex is NULL, nothing is done, this routine
* simply returns.
*
......
......@@ -79,7 +79,7 @@ void camel_exception_xfer (CamelException *ex_dst,
ExceptionId camel_exception_get_id (CamelException *ex);
const gchar * camel_exception_get_description (CamelException *ex);
#define camel_exception_is_set(ex) (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE)
#ifdef __cplusplus
}
......
......@@ -66,7 +66,8 @@ static guint signals[LAST_SIGNAL] = { 0 };
static void set_message_number (CamelMimeMessage *mime_message, guint number);
static guint get_message_number (CamelMimeMessage *mime_message);
static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static int write_to_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream, CamelException *ex);
static void finalize (GtkObject *object);
static void add_header (CamelMedium *medium, const char *header_name, const void *header_value);
static void set_header (CamelMedium *medium, const char *header_name, const void *header_value);
......@@ -536,7 +537,8 @@ construct_from_parser(CamelMimePart *dw, CamelMimeParser *mp)
}
static int
write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
CamelException *ex)
{
CamelMimeMessage *mm = CAMEL_MIME_MESSAGE (data_wrapper);
......@@ -554,11 +556,11 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
camel_mime_message_set_subject(mm, "No Subject");
}
/* FIXME: "To" header needs to be set explcitly as well ... */
/* FIXME: "To" header needs to be set explicitly as well ... */
camel_medium_set_header((CamelMedium *)mm, "Mime-Version", "1.0");
return CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream);
return CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream, ex);
}
static char *
......
......@@ -41,6 +41,7 @@
#include "camel-mime-filter.h"
#include "camel-stream.h"
#include "camel-seekable-stream.h"
#include "camel-exception.h"
#define r(x)
#define h(x)
......@@ -208,6 +209,7 @@ struct _header_scan_state {
int fd; /* input for a fd input */
CamelStream *stream; /* or for a stream */
CamelException *ex; /* exception for the stream */
/* for scanning input buffers */
char *realbuf; /* the real buffer, SCAN_HEAD*2 + SCAN_BUF bytes */
......@@ -824,7 +826,8 @@ folder_read(struct _header_scan_state *s)
memcpy(s->inbuf, s->inptr, inoffset);
}
if (s->stream) {
len = camel_stream_read(s->stream, s->inbuf+inoffset, SCAN_BUF-inoffset);
len = camel_stream_read(s->stream, s->inbuf+inoffset,
SCAN_BUF-inoffset, s->ex);
} else {
len = read(s->fd, s->inbuf+inoffset, SCAN_BUF-inoffset);
}
......@@ -869,7 +872,7 @@ folder_seek(struct _header_scan_state *s, off_t offset, int whence)
if (CAMEL_IS_SEEKABLE_STREAM(s->stream)) {
/* NOTE: assumes whence seekable stream == whence libc, which is probably
the case (or bloody well should've been) */
newoffset = camel_seekable_stream_seek((CamelSeekableStream *)s->stream, offset, whence);
newoffset = camel_seekable_stream_seek((CamelSeekableStream *)s->stream, offset, whence, s->ex);
} else {
newoffset = -1;
errno = EINVAL;
......@@ -886,7 +889,7 @@ folder_seek(struct _header_scan_state *s, off_t offset, int whence)
s->inptr = s->inbuf;
s->inend = s->inbuf;
if (s->stream)
len = camel_stream_read(s->stream, s->inbuf, SCAN_BUF);
len = camel_stream_read(s->stream, s->inbuf, SCAN_BUF, s->ex);
else
len = read(s->fd, s->inbuf, SCAN_BUF);
if (len>=0) {
......@@ -1353,8 +1356,10 @@ folder_scan_close(struct _header_scan_state *s)
folder_pull_part(s);
if (s->fd != -1)
close(s->fd);
if (s->stream)
if (s->stream) {
gtk_object_unref((GtkObject *)s->stream);
camel_exception_free(s->ex);
}
g_free(s);
}
......@@ -1368,6 +1373,7 @@ folder_scan_init(void)
s->fd = -1;
s->stream = NULL;
s->ex = NULL;
s->outbuf = g_malloc(1024);
s->outptr = s->outbuf;
......@@ -1415,6 +1421,8 @@ folder_scan_init_with_fd(struct _header_scan_state *s, int fd)
if (s->stream) {
gtk_object_unref((GtkObject *)s->stream);
s->stream = NULL;
camel_exception_free(s->ex);
s->ex = NULL;
}
return 0;
} else {
......@@ -1426,9 +1434,11 @@ static int
folder_scan_init_with_stream(struct _header_scan_state *s, CamelStream *stream)
{
int len;
CamelException *ex;
len = camel_stream_read(stream, s->inbuf, SCAN_BUF);
if (len>=0) {
ex = camel_exception_new();
len = camel_stream_read(stream, s->inbuf, SCAN_BUF, ex);
if (!camel_exception_is_set (ex)) {
s->inend = s->inbuf+len;
s->inptr = s->inbuf;
s->inend[0] = '\n';
......@@ -1436,12 +1446,16 @@ folder_scan_init_with_stream(struct _header_scan_state *s, CamelStream *stream)
gtk_object_unref((GtkObject *)s->stream);
s->stream = stream;
gtk_object_ref((GtkObject *)stream);
if (s->ex)
camel_exception_free(s->ex);
s->ex = ex;
if (s->fd != -1) {
close(s->fd);
s->fd = -1;
}
return 0;
} else {
camel_exception_free (ex);
return -1;
}
}
......
......@@ -36,6 +36,7 @@
#include "camel-stream-mem.h"
#include "camel-stream-filter.h"
#include "camel-mime-filter-basic.h"
#include "camel-exception.h"
#define d(x)
......@@ -66,7 +67,8 @@ static void finalize (GtkObject *object);
/* from CamelDataWrapper */
static int write_to_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream *stream,
CamelException *ex);
static int construct_from_stream (CamelDataWrapper *dw, CamelStream *s);
/* from CamelMedia */
......@@ -478,12 +480,13 @@ set_content_object (CamelMedium *medium, CamelDataWrapper *content)
/**********************************************************************/
static int
write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
CamelException *ex)
{
CamelMimePart *mp = CAMEL_MIME_PART (data_wrapper);
CamelMedium *medium = CAMEL_MEDIUM (data_wrapper);
CamelDataWrapper *content;
int total = 0, count;
int total = 0;
d(printf("mime_part::write_to_stream\n"));
......@@ -494,16 +497,19 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
if (mp->headers) {
struct _header_raw *h = mp->headers;
while (h) {
if ( (count = camel_stream_write_strings (stream, h->name, isspace(h->value[0])?":":": ", h->value, "\n", NULL) ) == -1 )
total += camel_stream_printf (stream, ex, "%s%s%s\n",
h->name,
isspace(h->value[0]) ? ":" : ": ",
h->value);
if (camel_exception_is_set (ex))
return -1;
total += count;
h = h->next;
}
}
if ( (count = camel_stream_write_string(stream,"\n")) == -1)
total += camel_stream_write (stream, "\n", 1, ex);
if (camel_exception_is_set (ex))
return -1;
total += count;
content = camel_medium_get_content_object (medium);
if (content) {
......@@ -531,13 +537,11 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
}
#endif
if ( (count = camel_data_wrapper_write_to_stream(content, stream)) == -1 )
total = -1;
else
total += count;
total += camel_data_wrapper_write_to_stream (content, stream, ex);
if (filter_stream)
gtk_object_unref((GtkObject *)filter_stream);
if (camel_exception_is_set (ex))
return -1;
} else {
g_warning("No content for medium, nothing to write");
}
......
......@@ -31,6 +31,7 @@
#include "camel-stream-mem.h"
#include "camel-multipart.h"
#include "camel-mime-part.h"
#include "camel-exception.h"
#define d(x)
......@@ -50,7 +51,8 @@ static void set_boundary (CamelMultipart *multipart,
gchar *boundary);
static const gchar * get_boundary (CamelMultipart *multipart);
static int write_to_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream *stream,
CamelException *ex);
static void finalize (GtkObject *object);
static CamelDataWrapperClass *parent_class = NULL;
......@@ -404,18 +406,19 @@ camel_multipart_get_boundary (CamelMultipart *multipart)
/* this is MIME specific, doesn't belong here really */
static int
write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
CamelException *ex)
{
CamelMultipart *multipart = CAMEL_MULTIPART (data_wrapper);
const gchar *boundary;
int total = 0, count;
int total = 0;
GList *node;
/* get the bundary text */
boundary = camel_multipart_get_boundary (multipart);
/* we cannot write a multipart without a boundary string */
g_return_val_if_fail (boundary, -1);
g_return_val_if_fail (boundary && *boundary, -1);
/*
* write the preface text (usually something like
......@@ -423,39 +426,40 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
* your mail client probably doesn't support ...."
*/
if (multipart->preface) {
count = camel_stream_write_strings (stream, multipart->preface, NULL);
if (count == -1)
total += camel_stream_write_string (stream,
multipart->preface, ex);
if (camel_exception_is_set (ex))
return -1;
total += count;
}
/*
* Now, write all the parts, separated by the boundary
* delimiter
*/
if (boundary==NULL || (boundary[0] == '\0'))
g_warning ("Multipart boundary is zero length\n");
node = multipart->parts;
while (node) {
if ( (count = camel_stream_write_strings (stream, "\n--", boundary?boundary:"", "\n", NULL) ) == -1 )
total += camel_stream_printf (stream, ex, "\n--%s\n",
boundary);
if (camel_exception_is_set (ex))
return -1;
total += count;
if ( (count = camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (node->data), stream)) == -1 )
total += camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (node->data), stream, ex);
if (camel_exception_is_set (ex));
return -1;
total += count;
node = node->next;
}
/* write the terminating boudary delimiter */
if ( ( count = camel_stream_write_strings (stream, "\n--", boundary, "--\n", NULL) ) == -1 )
total += camel_stream_printf (stream, ex, "\n--%s--\n", boundary);
if (camel_exception_is_set (ex))
return -1;
total += count;
/* and finally the postface - it is NOT fatal if this fails */
/* and finally the postface */
if (multipart->postface) {
if ( ( count = camel_stream_write_strings (stream, multipart->postface, NULL) ) != -1 )
total += count;
total += camel_stream_write_string (stream,
multipart->postface, ex);
if (camel_exception_is_set (ex))
return -1;
}
return total;
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
*
* Author :
/*
* Author:
* Bertrand Guiheneuf <bertrand@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
......@@ -24,31 +23,31 @@
*/
#include <config.h>
#include "camel-seekable-stream.h"
static CamelStreamClass *parent_class=NULL;
static CamelStreamClass *parent_class = NULL;
/* Returns the class for a CamelSeekableStream */
#define CSS_CLASS(so) CAMEL_SEEKABLE_STREAM_CLASS (GTK_OBJECT(so)->klass)
static off_t seek (CamelSeekableStream *stream,
off_t offset,
CamelStreamSeekPolicy policy);
static off_t stream_tell (CamelSeekableStream *stream);
static void reset (CamelStream *stream);
static void set_bounds (CamelSeekableStream *stream, off_t start, off_t end);
static off_t seek (CamelSeekableStream *stream, off_t offset,
CamelStreamSeekPolicy policy,
CamelException *ex);
static off_t stream_tell (CamelSeekableStream *stream);
static void reset (CamelStream *stream, CamelException *ex);
static void set_bounds (CamelSeekableStream *stream, off_t start, off_t end,
CamelException *ex);
static void
camel_seekable_stream_class_init (CamelSeekableStreamClass *camel_seekable_stream_class)
{
CamelStreamClass *camel_stream_class = CAMEL_STREAM_CLASS (camel_seekable_stream_class);
CamelStreamClass *camel_stream_class =
CAMEL_STREAM_CLASS (camel_seekable_stream_class);
parent_class = gtk_type_class (camel_stream_get_type ());
/* seekable stream methods */
camel_seekable_stream_class->seek = seek;
camel_seekable_stream_class->tell = stream_tell;
......@@ -71,9 +70,9 @@ GtkType
camel_seekable_stream_get_type (void)
{
static GtkType camel_seekable_stream_type = 0;
if (!camel_seekable_stream_type) {
GtkTypeInfo camel_seekable_stream_info =
if (!camel_seekable_stream_type) {
GtkTypeInfo camel_seekable_stream_info =
{
"CamelSeekableStream",
sizeof (CamelSeekableStream),
......@@ -84,19 +83,20 @@ camel_seekable_stream_get_type (void)
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
camel_seekable_stream_type = gtk_type_unique (camel_stream_get_type (), &camel_seekable_stream_info);
}
return camel_seekable_stream_type;
}
static off_t
seek (CamelSeekableStream *stream,
off_t offset,
CamelStreamSeekPolicy policy)
seek (CamelSeekableStream *stream, off_t offset,
CamelStreamSeekPolicy policy, CamelException *ex)
{
g_warning ("CamelSeekableStream::seek called on default implementation \n");
g_warning ("CamelSeekableStream::seek called on default "
"implementation\n");
return -1;
}
......@@ -105,7 +105,8 @@ seek (CamelSeekableStream *stream,
* @stream: a CamelStream object.
* @offset: offset value
* @policy: what to do with the offset
*
* @ex: a CamelException
*
* Seek to the specified position in @stream.
*
* If @policy is CAMEL_STREAM_SET, seeks to @offset.
......@@ -117,78 +118,88 @@ seek (CamelSeekableStream *stream,
* @offset.
*
* Regardless of @policy, the stream's final position will be clamped
* to the range specified by its lower and upper bounds.
*
* to the range specified by its lower and upper bounds, and the
* stream's eos state will be updated.
*
* Return value: new position, -1 if operation failed.
**/
off_t
camel_seekable_stream_seek (CamelSeekableStream *stream,
off_t offset,
CamelStreamSeekPolicy policy)
camel_seekable_stream_seek (CamelSeekableStream *stream, off_t offset,
CamelStreamSeekPolicy policy,
CamelException *ex)
{
return CSS_CLASS (stream)->seek (stream, offset, policy);
g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream), -1);
return CSS_CLASS (stream)->seek (stream, offset, policy, ex);
}
static off_t
stream_tell(CamelSeekableStream *stream)
stream_tell (CamelSeekableStream *stream)
{
return stream->position;
}
/**
* camel_seekable_stream_tell: get the position of a stream
* @stream: seekable stream object
*
* camel_seekable_stream_tell:
* @stream: seekable stream object
*
* Get the current position of a seekable stream.
*
*
* Return value: the position.
**/
off_t
camel_seekable_stream_tell (CamelSeekableStream *stream)
{
g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream), -1);
return CSS_CLASS (stream)->tell (stream);
}
static void
set_bounds (CamelSeekableStream *stream, off_t start, off_t end)
set_bounds (CamelSeekableStream *stream, off_t start, off_t end,
CamelException *ex)
{
/* store the bounds */
stream->bound_start = start;
stream->bound_end = end;
/* FIXME: this is probably to be reset by seek ... */
((CamelStream *)stream)->eos = FALSE;
if (start > stream->position)
camel_seekable_stream_seek(stream, start, CAMEL_STREAM_SET);
camel_seekable_stream_seek (stream, start, CAMEL_STREAM_SET, ex);
}
/**
* camel_seekable_stream_set_bounds:
* @stream:
* @start:
* @end:
*
* @stream: a seekable stream
* @start: the first valid position
* @end: the first invalid position, or CAMEL_STREAM_UNBOUND
*
* Set the range of valid data this stream is allowed to cover. If
* there is to be no @end value, then @end should be set to
* #CAMEL_STREAM_UNBOUND.
**/
void
camel_seekable_stream_set_bounds(CamelSeekableStream *stream, off_t start, off_t end)
camel_seekable_stream_set_bounds (CamelSeekableStream *stream,
off_t start, off_t end, CamelException *ex)
{
CSS_CLASS (stream)->set_bounds (stream, start, end);
g_return_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream));
g_return_if_fail (end == CAMEL_STREAM_UNBOUND || end >= start);
CSS_CLASS (stream)->set_bounds (stream, start, end, ex);
}
/* a default implementation of reset for seekable streams */
static void
reset (CamelStream *stream)
static void
reset (CamelStream *stream, CamelException *ex)
{
CamelSeekableStream *seekable_stream;
g_assert (stream);
seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
camel_seekable_stream_seek (seekable_stream, seekable_stream->bound_start, CAMEL_STREAM_SET);
camel_seekable_stream_seek (seekable_stream,
seekable_stream->bound_start,
CAMEL_STREAM_SET, ex);
}
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* camel-stream-fs.h :stream based on unix filesystem */
/*
*
* Author :
/*
* Author:
* Bertrand Guiheneuf <bertrand@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
......@@ -64,22 +63,28 @@ struct _CamelSeekableStream
typedef struct {
CamelStreamClass parent_class;
/* Virtual methods */
off_t (*seek) (CamelSeekableStream *stream, off_t offset, CamelStreamSeekPolicy policy);
/* Virtual methods */
off_t (*seek) (CamelSeekableStream *stream, off_t offset,
CamelStreamSeekPolicy policy,
CamelException *ex);
off_t (*tell) (CamelSeekableStream *stream);