camel-session.c \
camel-store.c \
camel-stream.c \
+ camel-stream-fs.c \
gmime-content-field.c \
gmime-utils.c \
gstring-util.c \
camel-session.h \
camel-store.h \
camel-stream.h \
+ camel-stream-fs.h \
gmime-content-field.h \
gmime-utils.h \
gstring-util.h \
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-stream-fs.c : file system based stream */
+
+/* inspired by gnome-stream-fs.c in bonobo by Miguel de Icaza */
+/*
+ *
+ * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "camel-stream-fs.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static CamelStreamClass *parent_class=NULL;
+
+
+/* Returns the class for a CamelMimeMessage */
+#define CS_CLASS(so) CAMEL_STREAM_FS_CLASS (GTK_OBJECT(so)->klass)
+
+static gint _read (CamelStream *stream, gchar *buffer, gint n);
+static gint _write (CamelStream *stream, gchar *buffer, gint n);
+static void _flush (CamelStream *stream);
+static gint _available (CamelStream *stream);
+static gboolean _eos (CamelStream *stream);
+static void _close (CamelStream *stream);
+
+
+static void
+camel_stream_fs_class_init (CamelStreamClass *camel_stream_fs_class)
+{
+ CamelStreamClass *camel_stream_class = CAMEL_STREAM_CLASS (camel_stream_fs_class);
+ parent_class = gtk_type_class (gtk_object_get_type ());
+
+ /* virtual method definition */
+
+ /* virtual method overload */
+ camel_stream_class->read = _read;
+ camel_stream_class->write = _write;
+ camel_stream_class->flush = _flush;
+ camel_stream_class->available = _available;
+ camel_stream_class->eos = _eos;
+ camel_stream_class->close = _close;
+
+}
+
+
+
+GtkType
+camel_stream_fs_get_type (void)
+{
+ static GtkType camel_stream_fs_type = 0;
+
+ if (!camel_stream_fs_type) {
+ GtkTypeInfo camel_stream_fs_info =
+ {
+ "CamelStreamFs",
+ sizeof (CamelStreamFs),
+ sizeof (CamelStreamFsClass),
+ (GtkClassInitFunc) camel_stream_fs_class_init,
+ (GtkObjectInitFunc) NULL,
+ /* reserved_1 */ NULL,
+ /* reserved_2 */ NULL,
+ (GtkClassInitFunc) NULL,
+ };
+
+ camel_stream_fs_type = gtk_type_unique (camel_stream_get_type (), &camel_stream_fs_info);
+ }
+
+ return camel_stream_fs_type;
+}
+
+
+CamelStream *
+camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode)
+{
+ struct stat s;
+ int v, fd;
+ int flags;
+ CamelStreamFs *stream_fs;
+
+ if (!name) return NULL;
+
+ v = stat (name->str, &s);
+
+ if (mode & CAMEL_STREAM_FS_READ)
+ if (mode & CAMEL_STREAM_FS_WRITE) flags = O_RDWR;
+ else flags = O_RDONLY;
+ else
+ if (mode & CAMEL_STREAM_FS_WRITE) flags = O_WRONLY;
+ else return NULL;
+
+ if (mode & CAMEL_STREAM_FS_READ)
+ if (v == -1) return NULL;
+
+ fd = open (name->str, flags);
+
+ stream_fs = CAMEL_STREAM_FS (camel_stream_fs_new_with_fd (fd));
+ stream_fs->name = name;
+
+ return CAMEL_STREAM (stream_fs);
+
+}
+
+CamelStream *
+camel_stream_fs_new_with_fd (int fd)
+{
+ CamelStreamFs *stream_fs;
+
+ stream_fs = gtk_type_new (camel_stream_fs_get_type ());
+ stream_fs->fd = fd;
+ return CAMEL_STREAM (stream_fs);
+}
+
+/**
+ * _read: read bytes from a stream
+ * @stream: stream
+ * @buffer: buffer where bytes are stored
+ * @n: max number of bytes to read
+ *
+ *
+ *
+ * Return value: number of bytes actually read.
+ **/
+static gint
+_read (CamelStream *stream, gchar *buffer, gint n)
+{
+ int v;
+
+ do {
+ v = read ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
+ } while (v == -1 && errno == EINTR);
+
+ return v;
+}
+
+
+/**
+ * _write: read bytes to a stream
+ * @stream: the stream
+ * @buffer: byte buffer
+ * @n: number of bytes to write
+ *
+ *
+ *
+ * Return value: the number of bytes actually written
+ * in the stream.
+ **/
+static gint
+_write (CamelStream *stream, gchar *buffer, gint n)
+{
+ int v;
+
+ do {
+ v = write ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
+ } while (v == -1 && errno == EINTR);
+
+ return v;
+
+}
+
+
+
+/**
+ * _flush: flush pending changes
+ * @stream: the stream
+ *
+ *
+ **/
+static void
+_flush (CamelStream *stream)
+{
+ fsync ((CAMEL_STREAM_FS (stream))->fd);
+}
+
+
+
+/**
+ * _available: return the number of bytes available for reading
+ * @stream: the stream
+ *
+ * Return the number of bytes available without blocking.
+ *
+ * Return value: the number of bytes available
+ **/
+static gint
+_available (CamelStream *stream)
+{
+ g_warning ("Not implemented yet");
+}
+
+
+/**
+ * _eos: test if there are bytes left to read
+ * @stream: the stream
+ *
+ *
+ *
+ * Return value: true if all stream has been read
+ **/
+static gboolean
+_eos (CamelStream *stream)
+{
+ g_warning ("Not implemented yet");
+}
+
+
+/**
+ * _close: close a stream
+ * @stream: the stream
+ *
+ *
+ **/
+static void
+_close (CamelStream *stream)
+{
+ close ((CAMEL_STREAM_FS (stream))->fd);
+}
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-stream-fs.h :stream based on unix filesystem */
+
+/*
+ *
+ * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+
+#ifndef CAMEL_STREAM_FS_H
+#define CAMEL_STREAM_FS_H 1
+
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus }*/
+
+#include <gtk/gtk.h>
+#include <stdio.h>
+#include "camel-stream.h"
+
+#define CAMEL_STREAM_FS_TYPE (camel_stream_fs_get_type ())
+#define CAMEL_STREAM_FS(obj) (GTK_CHECK_CAST((obj), CAMEL_STREAM_FS_TYPE, CamelStreamFs))
+#define CAMEL_STREAM_FS_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_STREAM_FS_TYPE, CamelStreamFsClass))
+#define IS_CAMEL_STREAM_FS(o) (GTK_CHECK_TYPE((o), CAMEL_STREAM_FS_TYPE))
+
+typedef enum
+{
+ CAMEL_STREAM_FS_READ = 1,
+ CAMEL_STREAM_FS_WRITE = 2
+} CamelStreamFsMode;
+
+
+typedef struct
+{
+ CamelStream parent_object;
+ GString *name;
+ int fd;
+
+} CamelStreamFs;
+
+
+
+typedef struct {
+ CamelStreamClass parent_class;
+
+ /* Virtual methods */
+
+} CamelStreamFsClass;
+
+
+
+/* Standard Gtk function */
+GtkType camel_stream_fs_get_type (void);
+
+
+/* public methods */
+CamelStream *camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode);
+CamelStream *camel_stream_fs_new_with_fd (int fd);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CAMEL_STREAM_FS_H */
/* Returns the class for a CamelMimeMessage */
#define CS_CLASS(so) CAMEL_STREAM_CLASS (GTK_OBJECT(so)->klass)
-static gint _read (CamelStream *stream, gchar **buffer, gint n);
+static gint _read (CamelStream *stream, gchar *buffer, gint n);
static gint _write (CamelStream *stream, gchar *buffer, gint n);
static void _flush (CamelStream *stream);
static gint _available (CamelStream *stream);
if (!camel_stream_type) {
GtkTypeInfo camel_stream_info =
{
- "CamelMimeMessage",
+ "CamelStream",
sizeof (CamelStream),
sizeof (CamelStreamClass),
(GtkClassInitFunc) camel_stream_class_init,
* Return value: number of bytes actually read.
**/
static gint
-_read (CamelStream *stream, gchar **buffer, gint n)
+_read (CamelStream *stream, gchar *buffer, gint n)
{
}
+gint
+camel_stream_read (CamelStream *stream, gchar *buffer, gint n)
+{
+ CS_CLASS (stream)->read (stream, buffer, n);
+}
/**
* _write: read bytes to a stream
}
+gint
+camel_stream_write (CamelStream *stream, gchar *buffer, gint n)
+{
+ CS_CLASS (stream)->write (stream, buffer, n);
+}
+
/**
{
}
+
+void
+camel_stream_close (CamelStream *stream)
+{
+ CS_CLASS (stream)->close (stream);
+}
#include <gtk/gtk.h>
#define CAMEL_STREAM_TYPE (camel_stream_get_type ())
-#define CAMEL_STREAM(obj) (GTK_CHECK_CAST((obj), CAMEL_STREAM_TYPE, CamelMimeMessage))
-#define CAMEL_STREAM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_STREAM_TYPE, CamelMimeMessageClass))
+#define CAMEL_STREAM(obj) (GTK_CHECK_CAST((obj), CAMEL_STREAM_TYPE, CamelStream))
+#define CAMEL_STREAM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_STREAM_TYPE, CamelStreamClass))
#define IS_CAMEL_STREAM(o) (GTK_CHECK_TYPE((o), CAMEL_STREAM_TYPE))
GtkObjectClass parent_class;
/* Virtual methods */
-gint (*read) (CamelStream *stream, gchar **buffer, gint n);
+gint (*read) (CamelStream *stream, gchar *buffer, gint n);
gint (*write) (CamelStream *stream, gchar *buffer, gint n);
void (*flush) (CamelStream *stream);
gint (*available) (CamelStream *stream);
/* public methods */
+gint camel_stream_read (CamelStream *stream, gchar *buffer, gint n);
+gint camel_stream_write (CamelStream *stream, gchar *buffer, gint n);
+void camel_stream_close (CamelStream *stream);
#ifdef __cplusplus
}
GHashTable *
-get_header_table_from_stream (GnomeStream *stream)
+get_header_table_from_stream (CamelStream *stream)
{
- int next_char;
+ gchar next_char;
gboolean crlf = FALSE;
gboolean end_of_header_line = FALSE;
GHashTable *header_table;
header_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash);
- //next_char = fgetc (file);
+ camel_stream_read (stream, &next_char, 1);
do {
header_line = g_string_new("");
end_of_header_line = FALSE;
/* read a whole header line */
do {
switch (next_char) {
- case EOF:
+ case -1:
end_of_file=TRUE;
end_of_header_line = TRUE;
break;
/* if we have read a whole header line, we have also read
the first character of the next line to be sure the
crlf was not followed by a space or a tab char */
- //if (!end_of_header_line) next_char = fgetc (file);
+ if (!end_of_header_line) camel_stream_read (stream, &next_char, 1);
} while ( !end_of_header_line );
if ( strlen(header_line->str) )
#include <glib.h>
#include <stdio.h>
-#include <bonobo/gnome-stream.h>
+#include <camel-stream.h>
void gmime_write_header_pair_to_file (FILE* file, gchar* name, GString *value);
void write_header_table_to_file (FILE *file, GHashTable *header_table);
void write_header_with_glist_to_file (FILE *file, gchar *header_name, GList *header_values);
GHashTable *get_header_table_from_file (FILE *file);
-GHashTable *get_header_table_from_stream (GnomeStream *stream);
+GHashTable *get_header_table_from_stream (CamelStream *stream);