Initialize the gmime for upstream
[platform/upstream/gmime.git] / gmime / gmime-stream.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*  GMime
3  *  Copyright (C) 2000-2012 Jeffrey Stedfast
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public License
7  *  as published by the Free Software Foundation; either version 2.1
8  *  of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free
17  *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
18  *  02110-1301, USA.
19  */
20
21
22 #ifndef __GMIME_STREAM_H__
23 #define __GMIME_STREAM_H__
24
25 #include <glib.h>
26 #include <glib-object.h>
27
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <stdarg.h>
31
32 G_BEGIN_DECLS
33
34 #define GMIME_TYPE_STREAM            (g_mime_stream_get_type ())
35 #define GMIME_STREAM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_STREAM, GMimeStream))
36 #define GMIME_STREAM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_STREAM, GMimeStreamClass))
37 #define GMIME_IS_STREAM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_STREAM))
38 #define GMIME_IS_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_STREAM))
39 #define GMIME_STREAM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_STREAM, GMimeStreamClass))
40
41 typedef struct _GMimeStream GMimeStream;
42 typedef struct _GMimeStreamClass GMimeStreamClass;
43
44
45 /**
46  * GMimeSeekWhence:
47  * @GMIME_STREAM_SEEK_SET: Seek relative to the beginning of the stream.
48  * @GMIME_STREAM_SEEK_CUR: Seek relative to the current position in the stream.
49  * @GMIME_STREAM_SEEK_END: Seek relative to the end of the stream.
50  *
51  * Relative seek position.
52  **/
53 typedef enum {
54         GMIME_STREAM_SEEK_SET = SEEK_SET,
55         GMIME_STREAM_SEEK_CUR = SEEK_CUR,
56         GMIME_STREAM_SEEK_END = SEEK_END
57 } GMimeSeekWhence;
58
59
60 /**
61  * GMimeStreamIOVector:
62  * @data: data to pass to the I/O function.
63  * @len: length of the data, in bytes.
64  *
65  * An I/O vector for use with g_mime_stream_writev().
66  **/
67 typedef struct {
68         void *data;
69         size_t len;
70 } GMimeStreamIOVector;
71
72
73 /**
74  * GMimeStream:
75  * @parent_object: parent #GObject
76  * @super_stream: parent stream if this is a substream
77  * @position: the current stream position
78  * @bound_start: start boundary of the stream
79  * @bound_end: end boundary of the stream
80  *
81  * Abstract I/O stream class.
82  **/
83 struct _GMimeStream {
84         GObject parent_object;
85         
86         /* <private> */
87         GMimeStream *super_stream;
88         
89         gint64 position;
90         gint64 bound_start;
91         gint64 bound_end;
92 };
93
94 struct _GMimeStreamClass {
95         GObjectClass parent_class;
96         
97         ssize_t  (* read)   (GMimeStream *stream, char *buf, size_t len);
98         ssize_t  (* write)  (GMimeStream *stream, const char *buf, size_t len);
99         int      (* flush)  (GMimeStream *stream);
100         int      (* close)  (GMimeStream *stream);
101         gboolean (* eos)    (GMimeStream *stream);
102         int      (* reset)  (GMimeStream *stream);
103         gint64   (* seek)   (GMimeStream *stream, gint64 offset, GMimeSeekWhence whence);
104         gint64   (* tell)   (GMimeStream *stream);
105         gint64   (* length) (GMimeStream *stream);
106         GMimeStream * (* substream) (GMimeStream *stream, gint64 start, gint64 end);
107 };
108
109
110 GType g_mime_stream_get_type (void);
111
112 void g_mime_stream_construct (GMimeStream *stream, gint64 start, gint64 end);
113
114
115 /* public methods */
116 ssize_t   g_mime_stream_read    (GMimeStream *stream, char *buf, size_t len);
117 ssize_t   g_mime_stream_write   (GMimeStream *stream, const char *buf, size_t len);
118 int       g_mime_stream_flush   (GMimeStream *stream);
119 int       g_mime_stream_close   (GMimeStream *stream);
120 gboolean  g_mime_stream_eos     (GMimeStream *stream);
121 int       g_mime_stream_reset   (GMimeStream *stream);
122 gint64    g_mime_stream_seek    (GMimeStream *stream, gint64 offset, GMimeSeekWhence whence);
123 gint64    g_mime_stream_tell    (GMimeStream *stream);
124 gint64    g_mime_stream_length  (GMimeStream *stream);
125
126 GMimeStream *g_mime_stream_substream (GMimeStream *stream, gint64 start, gint64 end);
127
128 void      g_mime_stream_set_bounds (GMimeStream *stream, gint64 start, gint64 end);
129
130 ssize_t   g_mime_stream_write_string (GMimeStream *stream, const char *str);
131 ssize_t   g_mime_stream_printf       (GMimeStream *stream, const char *fmt, ...) G_GNUC_PRINTF (2, 3);
132
133 ssize_t   g_mime_stream_write_to_stream (GMimeStream *src, GMimeStream *dest);
134
135 ssize_t   g_mime_stream_writev (GMimeStream *stream, GMimeStreamIOVector *vector, size_t count);
136
137 G_END_DECLS
138
139 #endif /* __GMIME_STREAM_H__ */