Initialize the gmime for upstream
[platform/upstream/gmime.git] / gmime / gmime-filter-yenc.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_FILTER_YENC_H__
23 #define __GMIME_FILTER_YENC_H__
24
25 #include <gmime/gmime-filter.h>
26
27 G_BEGIN_DECLS
28
29 #define GMIME_TYPE_FILTER_YENC            (g_mime_filter_yenc_get_type ())
30 #define GMIME_FILTER_YENC(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_FILTER_YENC, GMimeFilterYenc))
31 #define GMIME_FILTER_YENC_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_FILTER_YENC, GMimeFilterYencClass))
32 #define GMIME_IS_FILTER_YENC(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_FILTER_YENC))
33 #define GMIME_IS_FILTER_YENC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_FILTER_YENC))
34 #define GMIME_FILTER_YENC_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_FILTER_YENC, GMimeFilterYencClass))
35
36 typedef struct _GMimeFilterYenc GMimeFilterYenc;
37 typedef struct _GMimeFilterYencClass GMimeFilterYencClass;
38
39
40 /**
41  * GMIME_YDECODE_STATE_INIT:
42  *
43  * Initial state for the g_mime_ydecode_step() function.
44  **/
45 #define GMIME_YDECODE_STATE_INIT     (0)
46
47 /**
48  * GMIME_YENCODE_STATE_INIT:
49  *
50  * Initial state for the g_mime_ydecode_step() function.
51  **/
52 #define GMIME_YENCODE_STATE_INIT     (0)
53
54 /* first 8 bits are reserved for saving a byte */
55
56 /**
57  * GMIME_YDECODE_STATE_EOLN:
58  *
59  * State bit that denotes the yEnc filter has reached an end-of-line.
60  *
61  * This state is for internal use only.
62  **/
63 #define GMIME_YDECODE_STATE_EOLN     (1 << 8)
64
65 /**
66  * GMIME_YDECODE_STATE_ESCAPE:
67  *
68  * State bit that denotes the yEnc filter has reached an escape
69  * sequence.
70  *
71  * This state is for internal use only.
72  **/
73 #define GMIME_YDECODE_STATE_ESCAPE   (1 << 9)
74
75 /* bits 10 and 11 reserved for later uses? */
76
77 /**
78  * GMIME_YDECODE_STATE_BEGIN:
79  *
80  * State bit that denotes the yEnc filter has found the =ybegin line.
81  **/
82 #define GMIME_YDECODE_STATE_BEGIN    (1 << 12)
83
84 /**
85  * GMIME_YDECODE_STATE_PART:
86  *
87  * State bit that denotes the yEnc filter has found the =ypart
88  * line. (Note: not all yencoded blocks have one)
89  **/
90 #define GMIME_YDECODE_STATE_PART     (1 << 13)
91
92 /**
93  * GMIME_YDECODE_STATE_DECODE:
94  *
95  * State bit that denotes yEnc filter has begun decoding the actual
96  * yencoded content and will continue to do so until an =yend line is
97  * found (or until there is nothing left to decode).
98  **/
99 #define GMIME_YDECODE_STATE_DECODE   (1 << 14)
100
101 /**
102  * GMIME_YDECODE_STATE_END:
103  *
104  * State bit that denoates that g_mime_ydecode_step() has finished
105  * decoding.
106  **/
107 #define GMIME_YDECODE_STATE_END      (1 << 15)
108
109 /**
110  * GMIME_YENCODE_CRC_INIT:
111  *
112  * Initial state for the crc and pcrc state variables.
113  **/
114 #define GMIME_YENCODE_CRC_INIT       (~0)
115
116 /**
117  * GMIME_YENCODE_CRC_FINAL:
118  * @crc: crc or pcrc state variable
119  *
120  * Gets the final crc value from @crc.
121  **/
122 #define GMIME_YENCODE_CRC_FINAL(crc) (~crc)
123
124 /**
125  * GMimeFilterYenc:
126  * @parent_object: parent #GMimeFilter
127  * @encode: encode vs decode
128  * @part: part id
129  * @state: encode/decode state
130  * @pcrc: part crc
131  * @crc: full crc
132  *
133  * A filter for yEncoding or yDecoding a stream.
134  **/
135 struct _GMimeFilterYenc {
136         GMimeFilter parent_object;
137         
138         gboolean encode;
139         
140         int part;
141         
142         int state;
143         guint32 pcrc;
144         guint32 crc;
145 };
146
147 struct _GMimeFilterYencClass {
148         GMimeFilterClass parent_class;
149         
150 };
151
152
153 GType g_mime_filter_yenc_get_type (void);
154
155 GMimeFilter *g_mime_filter_yenc_new (gboolean encode);
156
157 void g_mime_filter_yenc_set_state (GMimeFilterYenc *yenc, int state);
158 void g_mime_filter_yenc_set_crc (GMimeFilterYenc *yenc, guint32 crc);
159
160 /*int     g_mime_filter_yenc_get_part (GMimeFilterYenc *yenc);*/
161 guint32 g_mime_filter_yenc_get_pcrc (GMimeFilterYenc *yenc);
162 guint32 g_mime_filter_yenc_get_crc (GMimeFilterYenc *yenc);
163
164
165 size_t g_mime_ydecode_step  (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf,
166                              int *state, guint32 *pcrc, guint32 *crc);
167 size_t g_mime_yencode_step  (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf,
168                              int *state, guint32 *pcrc, guint32 *crc);
169 size_t g_mime_yencode_close (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf,
170                              int *state, guint32 *pcrc, guint32 *crc);
171
172 G_END_DECLS
173
174 #endif /* __GMIME_FILTER_YENC_H__ */