Commit 1c94c0a9 1c94c0a932d228a27b7f08c728c807faa97042ee by Alain Magloire

attachment.c file_stream.c header.c io.c mailbox.c mbx_pop.c

 	mbx_unix.c mbx_unixscan.c message.c mime.c trans_stream.c
 	include/private/io0.h include/public/attribute.h
 	include/public/auth.h include/public/body.h
 	include/public/header.h include/public/io.h
 	include/public/locker.h include/public/mailbox.h
 	include/public/message.h

expunge can be call safely, whithout having to close/destroy the mailbox
it will readjust the message_t pointer.

mailbox_t uses stream to now.
1 parent 8e968a03
...@@ -32,7 +32,7 @@ struct _msg_info { ...@@ -32,7 +32,7 @@ struct _msg_info {
32 char *header_buf; 32 char *header_buf;
33 int header_len; 33 int header_len;
34 int header_size; 34 int header_size;
35 header_t hdr; 35 header_t hdr;
36 message_t msg; 36 message_t msg;
37 int ioffset; 37 int ioffset;
38 int ooffset; 38 int ooffset;
...@@ -51,7 +51,7 @@ int message_create_attachment(const char *content_type, const char *encoding, co ...@@ -51,7 +51,7 @@ int message_create_attachment(const char *content_type, const char *encoding, co
51 int ret; 51 int ret;
52 52
53 if ( ( ret = message_create(newmsg, NULL) ) == 0 ) { 53 if ( ( ret = message_create(newmsg, NULL) ) == 0 ) {
54 if ( content_type == NULL ) 54 if ( content_type == NULL )
55 content_type = "text/plain"; 55 content_type = "text/plain";
56 if ( encoding == NULL ) 56 if ( encoding == NULL )
57 encoding = "7bit"; 57 encoding = "7bit";
...@@ -61,21 +61,23 @@ int message_create_attachment(const char *content_type, const char *encoding, co ...@@ -61,21 +61,23 @@ int message_create_attachment(const char *content_type, const char *encoding, co
61 sprintf(header, MSG_HDR, content_type, encoding); 61 sprintf(header, MSG_HDR, content_type, encoding);
62 if ( ( ret = header_create( &hdr, header, strlen(header), *newmsg ) ) == 0 ) { 62 if ( ( ret = header_create( &hdr, header, strlen(header), *newmsg ) ) == 0 ) {
63 message_get_body(*newmsg, &body); 63 message_get_body(*newmsg, &body);
64 if ( ( ret = file_stream_create(&fstream, filename, MU_STREAM_READ) ) == 0 ) { 64 if ( ( ret = file_stream_create(&fstream) ) == 0 ) {
65 if ( ( ret = stream_open(fstream, filename, 0, MU_STREAM_READ) ) == 0 ) {
65 if ( ( ret = encoder_stream_create(&tstream, fstream, encoding) ) == 0 ) { 66 if ( ( ret = encoder_stream_create(&tstream, fstream, encoding) ) == 0 ) {
66 body_set_stream(body, tstream, *newmsg); 67 body_set_stream(body, tstream, *newmsg);
67 message_set_header(*newmsg, hdr, NULL); 68 message_set_header(*newmsg, hdr, NULL);
68 } 69 }
70 }
69 } 71 }
70 } 72 }
71 } 73 }
72 } 74 }
73 if ( ret ) { 75 if ( ret ) {
74 if ( *newmsg ) 76 if ( *newmsg )
75 message_destroy(newmsg, NULL); 77 message_destroy(newmsg, NULL);
76 if ( hdr ) 78 if ( hdr )
77 header_destroy(&hdr, NULL); 79 header_destroy(&hdr, NULL);
78 if ( fstream ) 80 if ( fstream )
79 stream_destroy(&fstream, NULL); 81 stream_destroy(&fstream, NULL);
80 } 82 }
81 return ret; 83 return ret;
...@@ -87,14 +89,14 @@ static int _attachment_setup(struct _msg_info **info, message_t msg, stream_t *s ...@@ -87,14 +89,14 @@ static int _attachment_setup(struct _msg_info **info, message_t msg, stream_t *s
87 int sfl, ret; 89 int sfl, ret;
88 body_t body; 90 body_t body;
89 91
90 if ( ( ret = message_get_body(msg, &body) ) != 0 || 92 if ( ( ret = message_get_body(msg, &body) ) != 0 ||
91 ( ret = body_get_stream(body, stream) ) != 0 ) 93 ( ret = body_get_stream(body, stream) ) != 0 )
92 return ret; 94 return ret;
93 stream_get_flags(*stream, &sfl); 95 stream_get_flags(*stream, &sfl);
94 if ( data == NULL && (sfl & MU_STREAM_NONBLOCK) ) 96 if ( data == NULL && (sfl & MU_STREAM_NONBLOCK) )
95 return EINVAL; 97 return EINVAL;
96 if ( data ) 98 if ( data )
97 *info = *data; 99 *info = *data;
98 if ( *info == NULL ) { 100 if ( *info == NULL ) {
99 if ( ( *info = calloc(1, sizeof(struct _msg_info)) ) == NULL ) 101 if ( ( *info = calloc(1, sizeof(struct _msg_info)) ) == NULL )
100 return ENOMEM; 102 return ENOMEM;
...@@ -107,14 +109,14 @@ static int _attachment_setup(struct _msg_info **info, message_t msg, stream_t *s ...@@ -107,14 +109,14 @@ static int _attachment_setup(struct _msg_info **info, message_t msg, stream_t *s
107 } 109 }
108 110
109 static void _attachment_free(struct _msg_info *info, int free_message) { 111 static void _attachment_free(struct _msg_info *info, int free_message) {
110 if ( info->buf ) 112 if ( info->buf )
111 free(info->buf); 113 free(info->buf);
112 if ( info->header_buf ) 114 if ( info->header_buf )
113 free(info->header_buf); 115 free(info->header_buf);
114 if ( free_message ) { 116 if ( free_message ) {
115 if ( info->msg ) 117 if ( info->msg )
116 message_destroy(&(info->msg), NULL); 118 message_destroy(&(info->msg), NULL);
117 else if ( info->hdr ) 119 else if ( info->hdr )
118 header_destroy(&(info->hdr), NULL); 120 header_destroy(&(info->hdr), NULL);
119 } 121 }
120 free(info); 122 free(info);
...@@ -128,7 +130,7 @@ int message_save_attachment(message_t msg, const char *filename, void **data) ...@@ -128,7 +130,7 @@ int message_save_attachment(message_t msg, const char *filename, void **data)
128 int ret; 130 int ret;
129 size_t size; 131 size_t size;
130 char *content_encoding; 132 char *content_encoding;
131 133
132 if ( msg == NULL || filename == NULL) 134 if ( msg == NULL || filename == NULL)
133 return EINVAL; 135 return EINVAL;
134 136
...@@ -142,10 +144,10 @@ int message_save_attachment(message_t msg, const char *filename, void **data) ...@@ -142,10 +144,10 @@ int message_save_attachment(message_t msg, const char *filename, void **data)
142 } 144 }
143 if ( ret == 0 && ( ret = _attachment_setup( &info, msg, &stream, data) ) != 0 ) 145 if ( ret == 0 && ( ret = _attachment_setup( &info, msg, &stream, data) ) != 0 )
144 return ret; 146 return ret;
145 147
146 if ( ret != EAGAIN && info ) 148 if ( ret != EAGAIN && info )
147 _attachment_free(info, ret); 149 _attachment_free(info, ret);
148 return ret; 150 return ret;
149 } 151 }
150 152
151 #if 0 153 #if 0
...@@ -158,14 +160,14 @@ int message_encapsulate(message_t msg, message_t *newmsg, void **data) ...@@ -158,14 +160,14 @@ int message_encapsulate(message_t msg, message_t *newmsg, void **data)
158 160
159 if ( msg == NULL || newmsg == NULL) 161 if ( msg == NULL || newmsg == NULL)
160 return EINVAL; 162 return EINVAL;
161 163
162 if ( ( ret = message_create(&(info->msg), NULL) ) == 0 ) { 164 if ( ( ret = message_create(&(info->msg), NULL) ) == 0 ) {
163 header = "Content-Type: message/rfc822\nContent-Transfer-Encoding: 7bit\n\n"; 165 header = "Content-Type: message/rfc822\nContent-Transfer-Encoding: 7bit\n\n";
164 if ( ( ret = header_create( &(info->hdr), header, strlen(header), msg ) ) == 0 ) { 166 if ( ( ret = header_create( &(info->hdr), header, strlen(header), msg ) ) == 0 ) {
165 message_set_header(info->msg, info->hdr, NULL); 167 message_set_header(info->msg, info->hdr, NULL);
166 } 168 }
167 } 169 }
168 return ret; 170 return ret;
169 } 171 }
170 #endif 172 #endif
171 173
...@@ -183,7 +185,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data) ...@@ -183,7 +185,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data)
183 185
184 if ( msg == NULL || newmsg == NULL) 186 if ( msg == NULL || newmsg == NULL)
185 return EINVAL; 187 return EINVAL;
186 188
187 if ( (data == NULL || *data == NULL ) && ( ret = message_get_header(msg, &hdr) ) == 0 ) { 189 if ( (data == NULL || *data == NULL ) && ( ret = message_get_header(msg, &hdr) ) == 0 ) {
188 header_get_value(hdr, "Content-Type", NULL, 0, &size); 190 header_get_value(hdr, "Content-Type", NULL, 0, &size);
189 if ( size ) { 191 if ( size ) {
...@@ -218,7 +220,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data) ...@@ -218,7 +220,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data)
218 info->header_len += info->line_ndx; 220 info->header_len += info->line_ndx;
219 memcpy(info->header_buf, info->line, info->line_ndx); 221 memcpy(info->header_buf, info->line, info->line_ndx);
220 if ( info->line_ndx == 1 ) { 222 if ( info->line_ndx == 1 ) {
221 header_done = 1; 223 header_done = 1;
222 break; 224 break;
223 } 225 }
224 info->line_ndx = 0; 226 info->line_ndx = 0;
...@@ -233,7 +235,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data) ...@@ -233,7 +235,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data)
233 } 235 }
234 if ( ret == 0 && info->msg == NULL ) { 236 if ( ret == 0 && info->msg == NULL ) {
235 if ( ( ret = message_create(&(info->msg), NULL) ) == 0) 237 if ( ( ret = message_create(&(info->msg), NULL) ) == 0)
236 if ( ( ret = header_create(&(info->hdr), info->header_buf, info->header_len, info->msg) ) == 0 ) 238 if ( ( ret = header_create(&(info->hdr), info->header_buf, info->header_len, info->msg) ) == 0 )
237 ret = message_set_header(info->msg, hdr, NULL); 239 ret = message_set_header(info->msg, hdr, NULL);
238 } 240 }
239 if ( ret == 0 ) { 241 if ( ret == 0 ) {
...@@ -253,6 +255,6 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data) ...@@ -253,6 +255,6 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data)
253 } 255 }
254 if ( ret != EAGAIN && info ) 256 if ( ret != EAGAIN && info )
255 _attachment_free(info, ret); 257 _attachment_free(info, ret);
256 return ret; 258 return ret;
257 } 259 }
258 260
......
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
21 #include <stdlib.h> 21 #include <stdlib.h>
22 #include <string.h> 22 #include <string.h>
23 23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <unistd.h>
28
24 #include <io0.h> 29 #include <io0.h>
25 30
26 struct _file_stream 31 struct _file_stream
...@@ -44,35 +49,76 @@ _file_read (stream_t stream, char *optr, size_t osize, ...@@ -44,35 +49,76 @@ _file_read (stream_t stream, char *optr, size_t osize,
44 off_t offset, size_t *nbytes) 49 off_t offset, size_t *nbytes)
45 { 50 {
46 struct _file_stream *fs = stream->owner; 51 struct _file_stream *fs = stream->owner;
52 size_t n;
47 53
48 if (fs->offset != offset) 54 if (fs->offset != offset)
49 { 55 {
50 fseek (fs->file, offset, SEEK_SET); 56 fseek (fs->file, offset, SEEK_SET);
51 fs->offset = offset; 57 fs->offset = offset;
52 } 58 }
53 *nbytes = fread (optr, osize, 1, fs->file); 59
54 if (*nbytes == 0) 60 n = fread (optr, sizeof(char), osize, fs->file);
61
62 if (n == 0)
55 { 63 {
56 if (ferror(fs->file)) 64 if (ferror(fs->file))
57 return errno; 65 return errno;
58 } 66 }
59 else 67 else
60 fs->offset += *nbytes; 68 fs->offset += n;
69
70 if (nbytes)
71 *nbytes = n;
61 return 0; 72 return 0;
62 } 73 }
63 74
64 static int 75 static int
76 _file_readline (stream_t stream, char *optr, size_t osize,
77 off_t offset, size_t *nbytes)
78 {
79 struct _file_stream *fs = stream->owner;
80 size_t n = 0;
81 int err = 0;
82
83 if (fs->offset != offset)
84 {
85 fseek (fs->file, offset, SEEK_SET);
86 fs->offset = offset;
87 }
88
89 if (fgets (optr, osize, fs->file) != NULL)
90 {
91 char *tmp = optr;
92 while (*tmp) tmp++; /* strlen(optr) */
93 n = tmp - optr;
94 fs->offset += n;
95 }
96 else
97 {
98 if (ferror (fs->file))
99 err = errno;
100 }
101
102 if (nbytes)
103 *nbytes = n;
104 return err;
105 }
106
107 static int
65 _file_write (stream_t stream, const char *iptr, size_t isize, 108 _file_write (stream_t stream, const char *iptr, size_t isize,
66 off_t offset, size_t *nbytes) 109 off_t offset, size_t *nbytes)
67 { 110 {
68 struct _file_stream *fs = stream->owner; 111 struct _file_stream *fs = stream->owner;
112 size_t n;
69 113
70 if (fs->offset != offset) 114 if (fs->offset != offset)
71 { 115 {
72 fseek (fs->file, offset, SEEK_SET); 116 fseek (fs->file, offset, SEEK_SET);
73 fs->offset = offset; 117 fs->offset = offset;
74 } 118 }
75 *nbytes = fwrite (iptr, isize, 1, fs->file); 119
120 n = fwrite (iptr, sizeof(char), isize, fs->file);
121
76 if (*nbytes == 0) 122 if (*nbytes == 0)
77 { 123 {
78 if (ferror (fs->file)) 124 if (ferror (fs->file))
...@@ -80,47 +126,181 @@ _file_write (stream_t stream, const char *iptr, size_t isize, ...@@ -80,47 +126,181 @@ _file_write (stream_t stream, const char *iptr, size_t isize,
80 } 126 }
81 else 127 else
82 fs->offset += *nbytes; 128 fs->offset += *nbytes;
129
130 if (nbytes)
131 *nbytes = n;
83 return 0; 132 return 0;
84 } 133 }
85 134
86 int 135 static int
87 file_stream_create (stream_t *stream, const char *filename, int flags) 136 _file_truncate (stream_t stream, off_t len)
88 { 137 {
89 struct _file_stream *fs; 138 struct _file_stream *fs = stream->owner;
139 if (ftruncate (fileno(fs->file), len) == -1)
140 return errno;
141 return 0;
142 }
143
144 static int
145 _file_size (stream_t stream, off_t *psize)
146 {
147 struct _file_stream *fs = stream->owner;
148 struct stat stbuf;
149 if (fstat(fileno(fs->file), &stbuf) == -1)
150 return errno;
151 if (psize)
152 *psize = stbuf.st_size;
153 return 0;
154 }
155
156 static int
157 _file_flush (stream_t stream)
158 {
159 struct _file_stream *fs = stream->owner;
160 return fflush (fs->file);
161 }
162
163 static int
164 _file_get_fd (stream_t stream, int *pfd)
165 {
166 struct _file_stream *fs = stream->owner;
167 if (pfd)
168 *pfd = fileno (fs->file);
169 return 0;
170 }
171
172 static int
173 _file_open (stream_t stream, const char *filename, int port, int flags)
174 {
175 struct _file_stream *fs = stream->owner;
176 int flg;
177 int fd;
90 const char *mode; 178 const char *mode;
91 int ret;
92 179
93 if (stream == NULL || filename == NULL) 180 (void)port; /* shutup gcc */
94 return EINVAL; 181 /* map the flags to the system equivalent */
182 if (flags & MU_STREAM_WRITE)
183 flg = O_WRONLY;
184 else if (flags & MU_STREAM_RDWR)
185 flg = O_RDWR;
186 else /* default */
187 flg = O_RDONLY;
95 188
96 if ((fs = calloc(sizeof(struct _file_stream), 1)) == NULL) 189 /* local folders should not block it is local disk ???
97 return ENOMEM; 190 * We simply ignore the O_NONBLOCK flag
191 * But take care of the APPEND.
192 */
193 if (flags & MU_STREAM_APPEND)
194 flg |= O_APPEND;
195
196 /* handle CREAT with care, not to follow symlinks */
197 if (flags & MU_STREAM_CREAT)
198 {
199 /* first see if the file already exists */
200 fd = open(filename, flg);
201 if (fd == -1)
202 {
203 /* oops bail out */
204 if (errno != ENOENT)
205 return errno;
206 /* Race condition here when creating the file ?? */
207 fd = open(filename, flg|O_CREAT|O_EXCL, 0600);
208 if (fd < 0)
209 return errno;
210 }
211 }
212 else
213 {
214 fd = open (filename, flg);
215 if (fd < 0)
216 return errno;
217 }
218
219 /* we have to make sure that We did not open
220 * a symlink. From Casper D. in bugtraq.
221 */
222 if ((flg & MU_STREAM_CREAT) ||
223 (flg & MU_STREAM_RDWR) ||
224 (flg & MU_STREAM_WRITE))
225 {
226 struct stat fdbuf, filebuf;
98 227
99 if (flags & MU_STREAM_RDWR) 228 /* the next two stats should never fail */
229 if (fstat(fd, &fdbuf) == -1)
230 return errno;
231 if (lstat(filename, &filebuf) == -1)
232 return errno;
233
234 /* Now check that: file and fd reference the same file,
235 file only has one link, file is plain file */
236 if (fdbuf.st_dev != filebuf.st_dev ||
237 fdbuf.st_ino != filebuf.st_ino ||
238 fdbuf.st_nlink != 1 ||
239 filebuf.st_nlink != 1 ||
240 (fdbuf.st_mode & S_IFMT) != S_IFREG) {
241 fprintf(stderr,"%s must be a plain file with one link\n", filename);
242 return EINVAL;
243 }
244 }
245 /* we use FILE * object */
246 if (flags & MU_STREAM_APPEND)
247 mode = "a";
248 else if (flags & MU_STREAM_RDWR)
100 mode = "r+b"; 249 mode = "r+b";
101 else if (flags & MU_STREAM_READ)
102 mode = "rb";
103 else if (flags & MU_STREAM_WRITE) 250 else if (flags & MU_STREAM_WRITE)
104 mode = "wb"; 251 mode = "wb";
105 else 252 else /* default readonly*/
106 return EINVAL; 253 mode = "rb";
107 254
108 if ((fs->file = fopen (filename, mode)) == NULL) 255 fs->file = fopen (filename, mode);
256 if (fs->file == NULL)
109 { 257 {
110 ret = errno; 258 int ret = errno;
111 free (fs); 259 free (fs);
112 return ret; 260 return ret;
113 } 261 }
114 if ((ret = stream_create (stream, flags, fs)) != 0) 262 #if BUFSIZ <= 1024
263 {
264 char *iobuffer;
265 iobuffer = malloc (8192);
266 if (iobuffer != NULL)
267 if (setvbuf (file, iobuffer, _IOFBF, 8192) != 0)
268 free (iobuffer);
269 }
270 #endif
271 stream_set_flags (stream, flags |MU_STREAM_NO_CHECK, fs);
272 return 0;
273 }
274
275 int
276 file_stream_create (stream_t *stream)
277 {
278 struct _file_stream *fs;
279 int ret;
280
281 if (stream == NULL)
282 return EINVAL;
283
284 fs = calloc (1, sizeof (struct _file_stream));
285 if (fs == NULL)
286 return ENOMEM;
287
288 ret = stream_create (stream, MU_STREAM_NO_CHECK, fs);
289 if (ret != 0)
115 { 290 {
116 fclose (fs->file); 291 fclose (fs->file);
117 free (fs); 292 free (fs);
118 return ret; 293 return ret;
119 } 294 }
120 295
121 stream_set_read(*stream, _file_read, fs ); 296 stream_set_open (*stream, _file_open, fs);
122 stream_set_write(*stream, _file_write, fs ); 297 stream_set_fd (*stream, _file_get_fd, fs);
123 stream_set_destroy(*stream, _file_destroy, fs ); 298 stream_set_read (*stream, _file_read, fs);
299 stream_set_readline (*stream, _file_readline, fs);
300 stream_set_write (*stream, _file_write, fs);
301 stream_set_truncate (*stream, _file_truncate, fs);
302 stream_set_size (*stream, _file_size, fs);
303 stream_set_flush (*stream, _file_flush, fs);
304 stream_set_destroy (*stream, _file_destroy, fs);
124 return 0; 305 return 0;
125 } 306 }
126
......
...@@ -273,6 +273,8 @@ header_get_value (header_t header, const char *name, char *buffer, ...@@ -273,6 +273,8 @@ header_get_value (header_t header, const char *name, char *buffer,
273 *buffer = '\0'; /* null terminated */ 273 *buffer = '\0'; /* null terminated */
274 if (pn) 274 if (pn)
275 *pn = total; 275 *pn = total;
276 if (total == 0)
277 return ENOENT;
276 return 0; 278 return 0;
277 } 279 }
278 280
...@@ -386,13 +388,13 @@ header_read (stream_t is, char *buf, size_t buflen, ...@@ -386,13 +388,13 @@ header_read (stream_t is, char *buf, size_t buflen,
386 off_t off, size_t *pnread) 388 off_t off, size_t *pnread)
387 { 389 {
388 header_t header; 390 header_t header;
389 ssize_t len; 391 int len;
390 392
391 if (is == NULL || (header = (header_t)is->owner) == NULL) 393 if (is == NULL || (header = (header_t)is->owner) == NULL)
392 return EINVAL; 394 return EINVAL;
393 395
394 len = header->blurb_len - off; 396 len = header->blurb_len - off;
395 if ((header->blurb_len - off) > 0) 397 if (len > 0)
396 { 398 {
397 if (buf) 399 if (buf)
398 { 400 {
......
...@@ -37,11 +37,15 @@ struct _stream ...@@ -37,11 +37,15 @@ struct _stream
37 void *owner; 37 void *owner;
38 int flags; 38 int flags;
39 void (*_destroy) __P ((stream_t)); 39 void (*_destroy) __P ((stream_t));
40 int (*_open) __P ((stream_t, const char *, int port, int flags)); 40 int (*_open) __P ((stream_t, const char *, int port, int flags));
41 int (*_close) __P ((stream_t)); 41 int (*_close) __P ((stream_t));
42 int (*_get_fd) __P ((stream_t, int *)); 42 int (*_get_fd) __P ((stream_t, int *));
43 int (*_read) __P ((stream_t, char *, size_t, off_t, size_t *)); 43 int (*_read) __P ((stream_t, char *, size_t, off_t, size_t *));
44 int (*_readline) __P ((stream_t, char *, size_t, off_t, size_t *));
44 int (*_write) __P ((stream_t, const char *, size_t, off_t, size_t *)); 45 int (*_write) __P ((stream_t, const char *, size_t, off_t, size_t *));
46 int (*_truncate) __P ((stream_t, off_t));
47 int (*_size) __P ((stream_t, off_t *));
48 int (*_flush) __P ((stream_t));
45 }; 49 };
46 50
47 #ifdef __cplusplus 51 #ifdef __cplusplus
......
...@@ -35,42 +35,42 @@ extern "C" { ...@@ -35,42 +35,42 @@ extern "C" {
35 struct _attribute; 35 struct _attribute;
36 typedef struct _attribute * attribute_t; 36 typedef struct _attribute * attribute_t;
37 37
38 extern int attribute_create __P ((attribute_t *)); 38 extern int attribute_create __P ((attribute_t *));
39 extern void attribute_destroy __P ((attribute_t *)); 39 extern void attribute_destroy __P ((attribute_t *));
40 40
41 extern int attribute_is_seen __P ((attribute_t)); 41 extern int attribute_is_seen __P ((attribute_t));
42 extern int attribute_is_answered __P ((attribute_t)); 42 extern int attribute_is_answered __P ((attribute_t));
43 extern int attribute_is_flagged __P ((attribute_t)); 43 extern int attribute_is_flagged __P ((attribute_t));
44 extern int attribute_is_deleted __P ((attribute_t)); 44 extern int attribute_is_deleted __P ((attribute_t));
45 extern int attribute_is_draft __P ((attribute_t)); 45 extern int attribute_is_draft __P ((attribute_t));
46 extern int attribute_is_recent __P ((attribute_t)); 46 extern int attribute_is_recent __P ((attribute_t));
47 extern int attribute_is_read __P ((attribute_t)); 47 extern int attribute_is_read __P ((attribute_t));
48 48
49 extern int attribute_set_seen __P ((attribute_t)); 49 extern int attribute_set_seen __P ((attribute_t));
50 extern int attribute_set_answered __P ((attribute_t)); 50 extern int attribute_set_answered __P ((attribute_t));
51 extern int attribute_set_flagged __P ((attribute_t)); 51 extern int attribute_set_flagged __P ((attribute_t));
52 extern int attribute_set_deleted __P ((attribute_t)); 52 extern int attribute_set_deleted __P ((attribute_t));
53 extern int attribute_set_draft __P ((attribute_t)); 53 extern int attribute_set_draft __P ((attribute_t));
54 extern int attribute_set_recent __P ((attribute_t)); 54 extern int attribute_set_recent __P ((attribute_t));
55 extern int attribute_set_read __P ((attribute_t)); 55 extern int attribute_set_read __P ((attribute_t));
56 56
57 extern int attribute_unset_seen __P ((attribute_t)); 57 extern int attribute_unset_seen __P ((attribute_t));
58 extern int attribute_unset_answered __P ((attribute_t)); 58 extern int attribute_unset_answered __P ((attribute_t));
59 extern int attribute_unset_flagged __P ((attribute_t)); 59 extern int attribute_unset_flagged __P ((attribute_t));
60 extern int attribute_unset_deleted __P ((attribute_t)); 60 extern int attribute_unset_deleted __P ((attribute_t));
61 extern int attribute_unset_draft __P ((attribute_t)); 61 extern int attribute_unset_draft __P ((attribute_t));
62 extern int attribute_unset_recent __P ((attribute_t)); 62 extern int attribute_unset_recent __P ((attribute_t));
63 extern int attribute_unset_read __P ((attribute_t)); 63 extern int attribute_unset_read __P ((attribute_t));
64 64
65 extern int attribute_is_equal __P ((attribute_t att1, attribute_t att2)); 65 extern int attribute_is_equal __P ((attribute_t att1, attribute_t att2));
66 66
67 extern int attribute_copy __P ((attribute_t dst, 67 extern int attribute_copy __P ((attribute_t dst,
68 attribute_t src)); 68 attribute_t src));
69 69
70 extern int string_to_attribute __P ((const char *buf, 70 extern int string_to_attribute __P ((const char *buf,
71 attribute_t *pattr)); 71 attribute_t *pattr));
72 extern int attribute_to_string __P ((attribute_t attr, char *buf, 72 extern int attribute_to_string __P ((attribute_t attr, char *buf,
73 size_t len, size_t *)); 73 size_t len, size_t *));
74 74
75 #ifdef __cplusplus 75 #ifdef __cplusplus
76 } 76 }
......
...@@ -36,24 +36,24 @@ extern "C" { ...@@ -36,24 +36,24 @@ extern "C" {
36 struct _auth; 36 struct _auth;
37 typedef struct _auth *auth_t; 37 typedef struct _auth *auth_t;
38 38
39 extern int auth_create __P ((auth_t *, void *owner)); 39 extern int auth_create __P ((auth_t *, void *owner));
40 extern void auth_destroy __P ((auth_t *, void *owner)); 40 extern void auth_destroy __P ((auth_t *, void *owner));
41 41
42 extern int auth_prologue __P ((auth_t)); 42 extern int auth_prologue __P ((auth_t));
43 extern int auth_set_prologue __P ((auth_t auth, 43 extern int auth_set_prologue __P ((auth_t auth,
44 int (*_prologue) __P ((auth_t)), 44 int (*_prologue) __P ((auth_t)),
45 void *owner)); 45 void *owner));
46 46
47 extern int auth_authenticate __P ((auth_t, char **, char **)); 47 extern int auth_authenticate __P ((auth_t, char **, char **));
48 extern int auth_set_authenticate __P ((auth_t auth, 48 extern int auth_set_authenticate __P ((auth_t auth,
49 int (*_authenticate) 49 int (*_authenticate)
50 __P ((auth_t, char **, char **)), 50 __P ((auth_t, char **, char **)),
51 void *owner)); 51 void *owner));
52 52
53 extern int auth_epilogue __P ((auth_t)); 53 extern int auth_epilogue __P ((auth_t));
54 extern int auth_set_epilogue __P ((auth_t auth, 54 extern int auth_set_epilogue __P ((auth_t auth,
55 int (*_epilogue) __P ((auth_t)), 55 int (*_epilogue) __P ((auth_t)),
56 void *owner)); 56 void *owner));
57 57
58 #ifdef _cplusplus 58 #ifdef _cplusplus
59 } 59 }
......
...@@ -46,14 +46,14 @@ extern int body_set_stream __P ((body_t, stream_t, void *owner)); ...@@ -46,14 +46,14 @@ extern int body_set_stream __P ((body_t, stream_t, void *owner));
46 extern int body_get_filename __P ((body_t, char *, size_t, size_t *)); 46 extern int body_get_filename __P ((body_t, char *, size_t, size_t *));
47 extern int body_set_filename __P ((body_t, const char*)); 47 extern int body_set_filename __P ((body_t, const char*));
48 48
49 extern int body_size __P ((body_t, size_t*)); 49 extern int body_size __P ((body_t, size_t*));
50 extern int body_set_size __P ((body_t, 50 extern int body_set_size __P ((body_t,
51 int (*_size) __P ((body_t, size_t*)), 51 int (*_size) __P ((body_t, size_t*)),
52 void *owner)); 52 void *owner));
53 extern int body_lines __P ((body_t, size_t *)); 53 extern int body_lines __P ((body_t, size_t *));
54 extern int body_set_lines __P ((body_t, 54 extern int body_set_lines __P ((body_t,
55 int (*_lines) __P ((body_t, size_t*)), 55 int (*_lines) __P ((body_t, size_t*)),
56 void *owner)); 56 void *owner));
57 57
58 #ifdef _cplusplus 58 #ifdef _cplusplus
59 } 59 }
......
...@@ -67,7 +67,7 @@ extern "C" { ...@@ -67,7 +67,7 @@ extern "C" {
67 struct _header; 67 struct _header;
68 typedef struct _header * header_t; 68 typedef struct _header * header_t;
69 69
70 extern int header_create __P ((header_t *, const char *blurb, 70 extern int header_create __P ((header_t *, const char *blurb,
71 size_t ln, void *owner)); 71 size_t ln, void *owner));
72 extern void header_destroy __P ((header_t *, void *owner)); 72 extern void header_destroy __P ((header_t *, void *owner));
73 73
...@@ -80,9 +80,9 @@ extern int header_entry_name __P ((header_t, size_t num, char *buf, ...@@ -80,9 +80,9 @@ extern int header_entry_name __P ((header_t, size_t num, char *buf,
80 size_t buflen, size_t *total)); 80 size_t buflen, size_t *total));
81 extern int header_entry_value __P ((header_t, size_t num, char *buf, 81 extern int header_entry_value __P ((header_t, size_t num, char *buf,
82 size_t buflen, size_t *total)); 82 size_t buflen, size_t *total));
83 extern int header_get_stream __P ((header_t, stream_t *stream)); 83 extern int header_get_stream __P ((header_t, stream_t *stream));
84 extern int header_size __P ((header_t, size_t *size)); 84 extern int header_size __P ((header_t, size_t *size));
85 extern int header_lines __P ((header_t, size_t *lines)); 85 extern int header_lines __P ((header_t, size_t *lines));
86 86
87 #ifdef _cplusplus 87 #ifdef _cplusplus
88 } 88 }
......
...@@ -44,52 +44,68 @@ typedef struct _stream *stream_t; ...@@ -44,52 +44,68 @@ typedef struct _stream *stream_t;
44 #define MU_STREAM_NONBLOCK 0x00000020 44 #define MU_STREAM_NONBLOCK 0x00000020
45 #define MU_STREAM_NO_CHECK 0x00000040 45 #define MU_STREAM_NO_CHECK 0x00000040
46 46
47 extern int stream_create __P ((stream_t *, int flags, void *owner)); 47 extern int stream_create __P ((stream_t *, int flags, void *owner));
48 48
49 extern void stream_destroy __P ((stream_t *, void *owner)); 49 extern void stream_destroy __P ((stream_t *, void *owner));
50 extern int stream_set_destroy __P ((stream_t, void (*_destroy) __P ((stream_t)), 50 extern int stream_set_destroy __P ((stream_t, void (*_destroy)
51 void *owner)); 51 __P ((stream_t)), void *owner));
52 52
53 extern int stream_open __P ((stream_t, const char *, int, int)); 53 extern int stream_open __P ((stream_t, const char *, int, int));
54 extern int stream_set_open __P ((stream_t, 54 extern int stream_set_open __P ((stream_t, int (*_open)
55 int (*_open) __P ((stream_t, const char *, 55 __P ((stream_t, const char *, int, int)),
56 int, int)), 56 void *owner));
57 void *owner)); 57
58 58 extern int stream_close __P ((stream_t));
59 extern int stream_close __P ((stream_t)); 59 extern int stream_set_close __P ((stream_t, int (*_close) __P ((stream_t)),
60 extern int stream_set_close __P ((stream_t, int (*_close) __P ((stream_t)), 60 void *owner));
61 void *owner)); 61
62 62 extern int stream_get_fd __P ((stream_t , int *));
63 extern int stream_get_fd __P ((stream_t , int *)); 63 extern int stream_set_fd __P ((stream_t, int (*_get_fd)(stream_t, int *),
64 extern int stream_set_fd __P ((stream_t, 64 void *owner));
65 int (*_get_fd)(stream_t, int *), 65
66 void *owner)); 66 extern int stream_read __P ((stream_t, char *, size_t,
67 67 off_t, size_t *));
68 extern int stream_read __P ((stream_t, char *, size_t, off_t, size_t *)); 68 extern int stream_set_read __P ((stream_t, int (*_read)
69 extern int stream_set_read __P ((stream_t, 69 __P ((stream_t, char *, size_t,
70 int (*_read) __P ((stream_t, char *, 70 off_t, size_t *)),
71 size_t, off_t, size_t *)), 71 void *owner));
72 void *owner)); 72
73 73 extern int stream_readline __P ((stream_t, char *, size_t,
74 extern int stream_write __P ((stream_t, const char *, size_t, 74 off_t, size_t *));
75 off_t, size_t *)); 75 extern int stream_set_readline __P ((stream_t, int (*_readline)
76 extern int stream_set_write __P ((stream_t, 76 __P ((stream_t, char *, size_t,
77 int (*_write) __P ((stream_t, const char *, 77 off_t, size_t *)),
78 size_t, off_t, 78 void *owner));
79 size_t *)), 79
80 void *owner)); 80 extern int stream_size __P ((stream_t, off_t *));
81 81 extern int stream_set_size __P ((stream_t, int (*_size)
82 extern int stream_get_flags __P ((stream_t, int *pflags)); 82 __P ((stream_t, off_t *)), void *owner));
83 extern int stream_set_flags __P ((stream_t, int flags, void *owner)); 83
84 extern int stream_truncate __P ((stream_t, off_t));
85 extern int stream_set_truncate __P ((stream_t, int (*_truncate)
86 __P ((stream_t, off_t)), void *owner));
87
88 extern int stream_write __P ((stream_t, const char *, size_t,
89 off_t, size_t *));
90 extern int stream_set_write __P ((stream_t, int (*_write)
91 __P ((stream_t, const char *,
92 size_t, off_t, size_t *)),
93 void *owner));
94
95 extern int stream_flush __P ((stream_t));
96 extern int stream_set_flush __P ((stream_t, int (*_flush)
97 __P ((stream_t)), void *owner));
98
99 extern int stream_get_flags __P ((stream_t, int *pflags));
100 extern int stream_set_flags __P ((stream_t, int flags, void *owner));
84 101
85 /* misc */ 102 /* misc */
86 extern int file_stream_create __P ((stream_t *stream, const char *filename, 103 extern int file_stream_create __P ((stream_t *stream));
87 int flags));
88 extern int encoder_stream_create __P ((stream_t *stream, stream_t iostream, 104 extern int encoder_stream_create __P ((stream_t *stream, stream_t iostream,
89 const char *encoding)); 105 const char *encoding));
90 extern int decoder_stream_create __P ((stream_t *stream, stream_t iostream, 106 extern int decoder_stream_create __P ((stream_t *stream, stream_t iostream,
91 const char *encoding)); 107 const char *encoding));
92 extern int tcp_stream_create __P ((stream_t *stream)); 108 extern int tcp_stream_create __P ((stream_t *stream));
93 109
94 #ifdef __cplusplus 110 #ifdef __cplusplus
95 } 111 }
......
...@@ -35,9 +35,9 @@ extern "C" { ...@@ -35,9 +35,9 @@ extern "C" {
35 struct _locker; 35 struct _locker;
36 typedef struct _locker *locker_t; 36 typedef struct _locker *locker_t;
37 37
38 extern int locker_create __P ((locker_t *, char *filename, 38 extern int locker_create __P ((locker_t *, char *filename,
39 size_t len, int flags)); 39 size_t len, int flags));
40 extern void locker_destroy __P ((locker_t *)); 40 extern void locker_destroy __P ((locker_t *));
41 41
42 #define MU_LOCKER_RDLOCK 0 42 #define MU_LOCKER_RDLOCK 0
43 #define MU_LOCKER_WRLOCK 1 43 #define MU_LOCKER_WRLOCK 1
......
...@@ -47,6 +47,8 @@ typedef struct _mailbox *mailbox_t; ...@@ -47,6 +47,8 @@ typedef struct _mailbox *mailbox_t;
47 extern int mailbox_create __P ((mailbox_t *, const char *, int id)); 47 extern int mailbox_create __P ((mailbox_t *, const char *, int id));
48 extern void mailbox_destroy __P ((mailbox_t *)); 48 extern void mailbox_destroy __P ((mailbox_t *));
49 49
50 extern int mailbox_create_default __P ((mailbox_t *, const char *));
51
50 /* flags for mailbox_open () */ 52 /* flags for mailbox_open () */
51 #define MU_MAILBOX_RDONLY MU_STREAM_READ 53 #define MU_MAILBOX_RDONLY MU_STREAM_READ
52 #define MU_MAILBOX_WRONLY MU_STREAM_WRITE 54 #define MU_MAILBOX_WRONLY MU_STREAM_WRITE
...@@ -55,35 +57,35 @@ extern void mailbox_destroy __P ((mailbox_t *)); ...@@ -55,35 +57,35 @@ extern void mailbox_destroy __P ((mailbox_t *));
55 #define MU_MAILBOX_CREAT MU_STREAM_CREAT 57 #define MU_MAILBOX_CREAT MU_STREAM_CREAT
56 #define MU_MAILBOX_NONBLOCK MU_STREAM_NONBLOCK 58 #define MU_MAILBOX_NONBLOCK MU_STREAM_NONBLOCK
57 59
58 extern int mailbox_open __P ((mailbox_t, int flag)); 60 extern int mailbox_open __P ((mailbox_t, int flag));
59 extern int mailbox_close __P ((mailbox_t)); 61 extern int mailbox_close __P ((mailbox_t));
60 62
61 /* messages */ 63 /* messages */
62 extern int mailbox_get_message __P ((mailbox_t, size_t msgno, message_t *msg)); 64 extern int mailbox_get_message __P ((mailbox_t, size_t msgno, message_t *msg));
63 extern int mailbox_append_message __P ((mailbox_t, message_t msg)); 65 extern int mailbox_append_message __P ((mailbox_t, message_t msg));
64 extern int mailbox_messages_count __P ((mailbox_t, size_t *num)); 66 extern int mailbox_messages_count __P ((mailbox_t, size_t *num));
65 extern int mailbox_expunge __P ((mailbox_t)); 67 extern int mailbox_expunge __P ((mailbox_t));
66 68
67 /* stream settings */ 69 /* stream settings */
68 extern int mailbox_get_stream __P ((mailbox_t, stream_t *pstream)); 70 extern int mailbox_get_stream __P ((mailbox_t, stream_t *pstream));
69 extern int mailbox_set_stream __P ((mailbox_t, stream_t stream)); 71 extern int mailbox_set_stream __P ((mailbox_t, stream_t stream));
70 72
71 /* Lock settings */ 73 /* Lock settings */
72 extern int mailbox_get_locker __P ((mailbox_t, locker_t *locker)); 74 extern int mailbox_get_locker __P ((mailbox_t, locker_t *locker));
73 extern int mailbox_set_locker __P ((mailbox_t, locker_t locker)); 75 extern int mailbox_set_locker __P ((mailbox_t, locker_t locker));
74 76
75 /* Authentication */ 77 /* Authentication */
76 extern int mailbox_get_auth __P ((mailbox_t, auth_t *auth)); 78 extern int mailbox_get_auth __P ((mailbox_t, auth_t *auth));
77 extern int mailbox_set_auth __P ((mailbox_t, auth_t auth)); 79 extern int mailbox_set_auth __P ((mailbox_t, auth_t auth));
78 80
79 /* update and scanning*/ 81 /* update and scanning*/
80 extern int mailbox_is_updated __P ((mailbox_t)); 82 extern int mailbox_is_updated __P ((mailbox_t));
81 extern int mailbox_scan __P ((mailbox_t, size_t msgno, size_t *count)); 83 extern int mailbox_scan __P ((mailbox_t, size_t msgno, size_t *count));
82 84
83 /* mailbox size ? */ 85 /* mailbox size ? */
84 extern int mailbox_size __P ((mailbox_t, off_t *size)); 86 extern int mailbox_size __P ((mailbox_t, off_t *size));
85 87
86 extern int mailbox_get_url __P ((mailbox_t, url_t *)); 88 extern int mailbox_get_url __P ((mailbox_t, url_t *));
87 89
88 /* events */ 90 /* events */
89 #define MU_EVT_MBX_DESTROY 1 91 #define MU_EVT_MBX_DESTROY 1
...@@ -96,6 +98,7 @@ extern int mailbox_register __P ((mailbox_t mbox, size_t type, ...@@ -96,6 +98,7 @@ extern int mailbox_register __P ((mailbox_t mbox, size_t type,
96 void *arg)); 98 void *arg));
97 extern int mailbox_deregister __P ((mailbox_t mbox, void *action)); 99 extern int mailbox_deregister __P ((mailbox_t mbox, void *action));
98 100
101
99 #ifdef __cplusplus 102 #ifdef __cplusplus
100 } 103 }
101 #endif 104 #endif
......
...@@ -43,10 +43,6 @@ typedef struct _message *message_t; ...@@ -43,10 +43,6 @@ typedef struct _message *message_t;
43 43
44 /* A message is considered to be a container for: 44 /* A message is considered to be a container for:
45 * header_t, body_t, and its attribute_t. 45 * header_t, body_t, and its attribute_t.
46 * The notion of body_t is not visible/exported, since
47 * they are alway tied to a floating message, there was no
48 * need to create yet another object, getting the {i,o}stream_t
49 * was enough.
50 */ 46 */
51 47
52 extern int message_create __P ((message_t *, void *owner)); 48 extern int message_create __P ((message_t *, void *owner));
...@@ -71,20 +67,26 @@ extern int message_set_from __P ((message_t, ...@@ -71,20 +67,26 @@ extern int message_set_from __P ((message_t,
71 size_t, size_t *)), 67 size_t, size_t *)),
72 void *owner)); 68 void *owner));
73 extern int message_received __P ((message_t, char *, size_t, size_t *)); 69 extern int message_received __P ((message_t, char *, size_t, size_t *));
74 extern int message_set_received __P ((message_t, 70 extern int message_set_received __P ((message_t, int (*_received)
75 int (*_received) __P ((message_t, 71 __P ((message_t, char *, size_t,
76 char *, size_t, 72 size_t *)), void *owner));
77 size_t *)),
78 void *owner));
79 73
80 extern int message_get_attribute __P ((message_t, attribute_t *)); 74 extern int message_get_attribute __P ((message_t, attribute_t *));
81 extern int message_set_attribute __P ((message_t, attribute_t, void *owner)); 75 extern int message_set_attribute __P ((message_t, attribute_t, void *owner));
82 76
77 extern int message_get_num_parts __P ((message_t, size_t *nparts));
78 extern int message_set_get_num_parts __P ((message_t, size_t *nparts));
79
80 extern int message_get_part __P ((message_t, size_t part, message_t *msg));
81 extern int message_set_get_part __P ((message_t, size_t part, message_t *msg));
82
83 extern int message_add_part __P ((message_t, message_t msg));
84 extern int message_set_add_part __P ((message_t, message_t msg));
85
83 /* events */ 86 /* events */
84 #define MU_EVT_MSG_DESTROY 32 87 #define MU_EVT_MSG_DESTROY 32
85 extern int message_register __P ((message_t msg, size_t type, 88 extern int message_register __P ((message_t msg, size_t type, int (*action)
86 int (*action) (size_t typ, void *arg), 89 __P ((size_t typ, void *arg)), void *arg));
87 void *arg));
88 extern int message_deregister __P ((message_t msg, void *action)); 90 extern int message_deregister __P ((message_t msg, void *action));
89 91
90 /* misc functions */ 92 /* misc functions */
......
...@@ -132,9 +132,7 @@ stream_set_read (stream_t stream, int (*_read) ...@@ -132,9 +132,7 @@ stream_set_read (stream_t stream, int (*_read)
132 { 132 {
133 if (stream == NULL) 133 if (stream == NULL)
134 return EINVAL; 134 return EINVAL;
135 if (owner == stream->owner && 135 if (owner == stream->owner)
136 ((stream->flags & MU_STREAM_READ) ||
137 (stream->flags & MU_STREAM_RDWR)))
138 { 136 {
139 stream->_read = _read; 137 stream->_read = _read;
140 return 0; 138 return 0;
...@@ -143,16 +141,28 @@ stream_set_read (stream_t stream, int (*_read) ...@@ -143,16 +141,28 @@ stream_set_read (stream_t stream, int (*_read)
143 } 141 }
144 142
145 int 143 int
144 stream_set_readline (stream_t stream, int (*_readline)
145 (stream_t, char *, size_t, off_t, size_t *),
146 void *owner)
147 {
148 if (stream == NULL)
149 return EINVAL;
150 if (owner == stream->owner)
151 {
152 stream->_readline = _readline;
153 return 0;
154 }
155 return EACCES;
156 }
157
158 int
146 stream_set_write (stream_t stream, int (*_write) 159 stream_set_write (stream_t stream, int (*_write)
147 __P ((stream_t, const char *, size_t, off_t, size_t *)), 160 __P ((stream_t, const char *, size_t, off_t, size_t *)),
148 void *owner) 161 void *owner)
149 { 162 {
150 if (stream == NULL) 163 if (stream == NULL)
151 return EINVAL; 164 return EINVAL;
152 if (stream->owner == owner && 165 if (stream->owner == owner)
153 ((stream->flags & MU_STREAM_WRITE) ||
154 (stream->flags & MU_STREAM_RDWR) ||
155 (stream->flags & MU_STREAM_APPEND)))
156 { 166 {
157 stream->_write = _write; 167 stream->_write = _write;
158 return 0; 168 return 0;
...@@ -170,6 +180,46 @@ stream_read (stream_t is, char *buf, size_t count, ...@@ -170,6 +180,46 @@ stream_read (stream_t is, char *buf, size_t count,
170 } 180 }
171 181
172 int 182 int
183 stream_readline (stream_t is, char *buf, size_t count,
184 off_t offset, size_t *pnread)
185 {
186 size_t n, nr = 0;
187 char c;
188 int status;
189 if (is == NULL)
190 return EINVAL;
191 if (is->_readline != NULL)
192 return is->_readline (is, buf, count, offset, pnread);
193
194 /* grossly inefficient hopefully they override this */
195 for (n = 1; n < count; n++)
196 {
197 status = stream_read (is, &c, 1, offset, &nr);
198 if (status != 0) /* error */
199 return status;
200 else if (nr == 1)
201 {
202 *buf++ = c;
203 offset++;
204 if (c == '\n') /* newline is stored like fgets() */
205 break;
206 }
207 else if (nr == 0)
208 {
209 if (n == 1) /* EOF, no data read */
210 n = 0;
211 break; /* EOF, some data was read */
212 }
213 }
214
215 *buf = '\0';
216 if (pnread)
217 *pnread = n;
218
219 return 0;
220 }
221
222 int
173 stream_write (stream_t os, const char *buf, size_t count, 223 stream_write (stream_t os, const char *buf, size_t count,
174 off_t offset, size_t *pnwrite) 224 off_t offset, size_t *pnwrite)
175 { 225 {
...@@ -205,3 +255,63 @@ stream_set_flags (stream_t stream, int fl, void *owner) ...@@ -205,3 +255,63 @@ stream_set_flags (stream_t stream, int fl, void *owner)
205 stream->flags = fl; 255 stream->flags = fl;
206 return 0; 256 return 0;
207 } 257 }
258
259 int
260 stream_size (stream_t stream, off_t *psize)
261 {
262 if (stream == NULL || stream->_size == NULL)
263 return EINVAL;
264 return stream->_size (stream, psize);
265 }
266
267 int
268 stream_set_size (stream_t stream, int (*_size)(stream_t, off_t *), void *owner)
269 {
270 if (stream == NULL)
271 return EINVAL;
272 if (stream->owner != owner)
273 return EACCES;
274 stream->_size = _size;
275 return 0;
276 }
277
278
279 int
280 stream_truncate (stream_t stream, off_t len)
281 {
282 if (stream == NULL || stream->_truncate == NULL )
283 return EINVAL;
284
285 return stream->_truncate (stream, len);
286 }
287
288 int
289 stream_set_truncate (stream_t stream, int (*_truncate) (stream_t, off_t),
290 void *owner)
291 {
292 if (stream == NULL)
293 return EINVAL;
294 if (stream->owner != owner)
295 return EACCES;
296 stream->_truncate = _truncate;
297 return 0;
298 }
299
300 int
301 stream_flush (stream_t stream)
302 {
303 if (stream == NULL || stream->_flush == NULL)
304 return EINVAL;
305 return stream->_flush (stream);
306 }
307
308 int
309 stream_set_flush (stream_t stream, int (*_flush) (stream_t), void *owner)
310 {
311 if (stream == NULL)
312 return EINVAL;
313 if (stream->owner != owner)
314 return EACCES;
315 stream->_flush = _flush;
316 return 0;
317 }
......
...@@ -256,7 +256,7 @@ mailbox_deregister (mailbox_t mbox, void *action) ...@@ -256,7 +256,7 @@ mailbox_deregister (mailbox_t mbox, void *action)
256 for (i = 0; i < mbox->event_num; i++) 256 for (i = 0; i < mbox->event_num; i++)
257 { 257 {
258 event = &(mbox->event[i]); 258 event = &(mbox->event[i]);
259 if (event->_action == action) 259 if ((int)event->_action == (int)action)
260 { 260 {
261 event->type = 0; 261 event->type = 0;
262 event->_action = NULL; 262 event->_action = NULL;
......
...@@ -322,7 +322,7 @@ mailbox_pop_open (mailbox_t mbox, int flags) ...@@ -322,7 +322,7 @@ mailbox_pop_open (mailbox_t mbox, int flags)
322 mailbox_pop_data_t mpd; 322 mailbox_pop_data_t mpd;
323 int status; 323 int status;
324 bio_t bio; 324 bio_t bio;
325 void *func = mailbox_pop_open; 325 void *func = (void *)mailbox_pop_open;
326 int fd; 326 int fd;
327 char host[256] ; 327 char host[256] ;
328 long port; 328 long port;
...@@ -395,9 +395,7 @@ mailbox_pop_open (mailbox_t mbox, int flags) ...@@ -395,9 +395,7 @@ mailbox_pop_open (mailbox_t mbox, int flags)
395 } 395 }
396 /* Dealing whith Authentication */ 396 /* Dealing whith Authentication */
397 /* so far only normal user/pass supported */ 397 /* so far only normal user/pass supported */
398 if (mbox->auth) 398 if (mbox->auth == NULL)
399 auth_authenticate (mbox->auth, &mpd->user, &mpd->passwd);
400 else
401 { 399 {
402 status = auth_create (&(mbox->auth), mbox); 400 status = auth_create (&(mbox->auth), mbox);
403 if (status != 0) 401 if (status != 0)
...@@ -494,7 +492,7 @@ static int ...@@ -494,7 +492,7 @@ static int
494 mailbox_pop_close (mailbox_t mbox) 492 mailbox_pop_close (mailbox_t mbox)
495 { 493 {
496 mailbox_pop_data_t mpd; 494 mailbox_pop_data_t mpd;
497 void *func = mailbox_pop_close; 495 void *func = (void *)mailbox_pop_close;
498 int status; 496 int status;
499 bio_t bio; 497 bio_t bio;
500 498
...@@ -543,7 +541,7 @@ mailbox_pop_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) ...@@ -543,7 +541,7 @@ mailbox_pop_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
543 bio_t bio; 541 bio_t bio;
544 int status; 542 int status;
545 size_t i; 543 size_t i;
546 void *func = mailbox_pop_get_message; 544 void *func = (void *)mailbox_pop_get_message;
547 545
548 /* sanity */ 546 /* sanity */
549 if (mbox == NULL || pmsg == NULL || (mpd = mbox->data) == NULL) 547 if (mbox == NULL || pmsg == NULL || (mpd = mbox->data) == NULL)
...@@ -829,7 +827,7 @@ mailbox_pop_messages_count (mailbox_t mbox, size_t *pcount) ...@@ -829,7 +827,7 @@ mailbox_pop_messages_count (mailbox_t mbox, size_t *pcount)
829 { 827 {
830 mailbox_pop_data_t mpd; 828 mailbox_pop_data_t mpd;
831 int status; 829 int status;
832 void *func = mailbox_pop_messages_count; 830 void *func = (void *)mailbox_pop_messages_count;
833 bio_t bio; 831 bio_t bio;
834 832
835 if (mbox == NULL || (mpd = (mailbox_pop_data_t)mbox->data) == NULL) 833 if (mbox == NULL || (mpd = (mailbox_pop_data_t)mbox->data) == NULL)
...@@ -939,7 +937,7 @@ mailbox_pop_expunge (mailbox_t mbox) ...@@ -939,7 +937,7 @@ mailbox_pop_expunge (mailbox_t mbox)
939 attribute_t attr; 937 attribute_t attr;
940 bio_t bio; 938 bio_t bio;
941 int status; 939 int status;
942 void *func = mailbox_pop_expunge; 940 void *func = (void *)mailbox_pop_expunge;
943 941
944 if (mbox == NULL || 942 if (mbox == NULL ||
945 (mpd = (mailbox_pop_data_t) mbox->data) == NULL) 943 (mpd = (mailbox_pop_data_t) mbox->data) == NULL)
...@@ -1063,7 +1061,7 @@ mailbox_pop_readstream (stream_t is, char *buffer, size_t buflen, ...@@ -1063,7 +1061,7 @@ mailbox_pop_readstream (stream_t is, char *buffer, size_t buflen,
1063 size_t nread = 0; 1061 size_t nread = 0;
1064 bio_t bio; 1062 bio_t bio;
1065 int status = 0; 1063 int status = 0;
1066 void *func = mailbox_pop_readstream; 1064 void *func = (void *)mailbox_pop_readstream;
1067 1065
1068 (void)offset; 1066 (void)offset;
1069 if (is == NULL || (mpm = is->owner) == NULL) 1067 if (is == NULL || (mpm = is->owner) == NULL)
......
...@@ -202,7 +202,7 @@ do \ ...@@ -202,7 +202,7 @@ do \
202 } while (0) 202 } while (0)
203 203
204 /* notifications ADD_MESG */ 204 /* notifications ADD_MESG */
205 #define DISPATCH_ADD_MSG(mbox,mud,file) \ 205 #define DISPATCH_ADD_MSG(mbox,mud) \
206 do \ 206 do \
207 { \ 207 { \
208 int bailing = 0; \ 208 int bailing = 0; \
...@@ -212,7 +212,6 @@ do \ ...@@ -212,7 +212,6 @@ do \
212 { \ 212 { \
213 if (pcount) \ 213 if (pcount) \
214 *pcount = (mud)->messages_count; \ 214 *pcount = (mud)->messages_count; \
215 fclose (file); \
216 mailbox_unix_unlock (mbox); \ 215 mailbox_unix_unlock (mbox); \
217 return EINTR; \ 216 return EINTR; \
218 } \ 217 } \
...@@ -230,7 +229,7 @@ do \ ...@@ -230,7 +229,7 @@ do \
230 * struct incomplete. So we only tell them about 229 * struct incomplete. So we only tell them about
231 * the complete messages. 230 * the complete messages.
232 */ 231 */
233 #define DISPATCH_PROGRESS(mbox,mud,file) \ 232 #define DISPATCH_PROGRESS(mbox,mud) \
234 do \ 233 do \
235 { \ 234 { \
236 { \ 235 { \
...@@ -243,7 +242,6 @@ do \ ...@@ -243,7 +242,6 @@ do \
243 { \ 242 { \
244 if (pcount) \ 243 if (pcount) \
245 *pcount = (mud)->messages_count; \ 244 *pcount = (mud)->messages_count; \
246 fclose (file); \
247 mailbox_unix_unlock (mbox); \ 245 mailbox_unix_unlock (mbox); \
248 return EINTR; \ 246 return EINTR; \
249 } \ 247 } \
...@@ -260,7 +258,6 @@ do \ ...@@ -260,7 +258,6 @@ do \
260 attr = calloc (1, sizeof(*(attr))); \ 258 attr = calloc (1, sizeof(*(attr))); \
261 if ((attr) == NULL) \ 259 if ((attr) == NULL) \
262 { \ 260 { \
263 fclose (file); \
264 mailbox_unix_iunlock (mbox); \ 261 mailbox_unix_iunlock (mbox); \
265 mailbox_unix_unlock (mbox); \ 262 mailbox_unix_unlock (mbox); \
266 return ENOMEM; \ 263 return ENOMEM; \
...@@ -269,7 +266,7 @@ do \ ...@@ -269,7 +266,7 @@ do \
269 266
270 // size_t num = 2 * ((mud)->messages_count) + 10; 267 // size_t num = 2 * ((mud)->messages_count) + 10;
271 /* allocate slots for the new messages */ 268 /* allocate slots for the new messages */
272 #define ALLOCATE_MSGS(mbox,mud,file) \ 269 #define ALLOCATE_MSGS(mbox,mud) \
273 do \ 270 do \
274 { \ 271 { \
275 if ((mud)->messages_count >= (mud)->umessages_count) \ 272 if ((mud)->messages_count >= (mud)->umessages_count) \
...@@ -279,7 +276,6 @@ do \ ...@@ -279,7 +276,6 @@ do \
279 m = realloc ((mud)->umessages, num * sizeof (*m)); \ 276 m = realloc ((mud)->umessages, num * sizeof (*m)); \
280 if (m == NULL) \ 277 if (m == NULL) \
281 { \ 278 { \
282 fclose (file); \
283 mailbox_unix_iunlock (mbox); \ 279 mailbox_unix_iunlock (mbox); \
284 mailbox_unix_unlock (mbox); \ 280 mailbox_unix_unlock (mbox); \
285 return ENOMEM; \ 281 return ENOMEM; \
...@@ -288,7 +284,6 @@ do \ ...@@ -288,7 +284,6 @@ do \
288 (mud)->umessages[num - 1] = calloc (1, sizeof (*(mum))); \ 284 (mud)->umessages[num - 1] = calloc (1, sizeof (*(mum))); \
289 if ((mud)->umessages[num - 1] == NULL) \ 285 if ((mud)->umessages[num - 1] == NULL) \
290 { \ 286 { \
291 fclose (file); \
292 mailbox_unix_iunlock (mbox); \ 287 mailbox_unix_iunlock (mbox); \
293 mailbox_unix_unlock (mbox); \ 288 mailbox_unix_unlock (mbox); \
294 return ENOMEM; \ 289 return ENOMEM; \
...@@ -299,19 +294,19 @@ do \ ...@@ -299,19 +294,19 @@ do \
299 } while (0) 294 } while (0)
300 295
301 static int 296 static int
302 mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount) 297 mailbox_unix_scan0 (mailbox_t mbox, size_t msgno, size_t *pcount, int do_notif)
303 { 298 {
304 #define MSGLINELEN 1024 299 #define MSGLINELEN 1024
305 char buf[MSGLINELEN]; 300 char buf[MSGLINELEN];
306 int inheader; 301 int inheader;
307 int inbody; 302 int inbody;
308 off_t total; 303 off_t total = 0;
309 mailbox_unix_data_t mud; 304 mailbox_unix_data_t mud;
310 mailbox_unix_message_t mum = NULL; 305 mailbox_unix_message_t mum = NULL;
311 int status = 0; 306 int status = 0;
312 size_t lines; 307 size_t lines;
313 int newline; 308 int newline;
314 FILE *file; 309 size_t n = 0;
315 310
316 int zn, isfrom = 0; 311 int zn, isfrom = 0;
317 char *temp; 312 char *temp;
...@@ -321,69 +316,36 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount) ...@@ -321,69 +316,36 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
321 (mud = (mailbox_unix_data_t)mbox->data) == NULL) 316 (mud = (mailbox_unix_data_t)mbox->data) == NULL)
322 return EINVAL; 317 return EINVAL;
323 318
324 /* the simplest way to deal with reentrancy issues is to 319 /* save the timestamp and size */
325 * duplicate the FILE * pointer instead of the orignal. 320 status = stream_size (mbox->stream, &(mud->size));
326 * 321 if (status != 0)
327 * QnX4(and earlier ?) has a BUFSIZ of about 512 ??? 322 return status;
328 * we use setvbuf () to reset to something sane.
329 * Really something smaller would be counter productive.
330 */
331 {
332 file = fopen (mbox->name, "r");
333 if (file == NULL)
334 return errno;
335 #if BUFSIZ <= 1024
336 {
337 char *iobuffer;
338 iobuffer = malloc (8192);
339 if (iobuffer != NULL)
340 if (setvbuf (file, iobuffer, _IOFBF, 8192) != 0)
341 free (iobuffer);
342 }
343 #endif
344 }
345 323
346 /* grab the locks */ 324 /* grab the locks */
347 mailbox_unix_ilock (mbox, MU_LOCKER_WRLOCK); 325 mailbox_unix_ilock (mbox, MU_LOCKER_WRLOCK);
348 mailbox_unix_lock (mbox, MU_LOCKER_RDLOCK); 326 mailbox_unix_lock (mbox, MU_LOCKER_RDLOCK);
349 327
350 /* save the timestamp and size */
351 {
352 struct stat st;
353 if (fstat (fileno (file), &st) != 0)
354 {
355 status = errno;
356 fclose (file);
357 mailbox_unix_iunlock (mbox);
358 mailbox_unix_unlock (mbox);
359 return status;
360 }
361 mud->mtime = st.st_mtime;
362 mud->size = st.st_size;
363 }
364
365 /* seek to the starting point */ 328 /* seek to the starting point */
366 if (mud->umessages) 329 if (mud->umessages && msgno > 0 && mud->messages_count > 0
330 && msgno <= mud->messages_count)
367 { 331 {
368 if (mud->messages_count > 0 && 332 mum = mud->umessages[msgno - 1];
369 msgno != 0 && 333 if (mum)
370 msgno <= mud->messages_count) 334 total = mum->header_from;
371 { 335 mud->messages_count = msgno - 1;
372 mum = mud->umessages[msgno - 1];
373 if (mum)
374 fseek (file, mum->body_end, SEEK_SET);
375 mud->messages_count = msgno;
376 }
377 } 336 }
337 else
338 mud->messages_count = 0;
378 339
379 newline = 1; 340 newline = 1;
380 errno = total = lines = inheader = inbody = 0; 341 errno = lines = inheader = inbody = 0;
381 342
382 while (fgets (buf, sizeof (buf), file)) 343 while ((status = stream_readline (mbox->stream, buf, sizeof (buf),
344 total, &n)) == 0 && n != 0)
383 { 345 {
384 int over, nl; 346 int nl;
385 STRLEN (buf, over); 347 STRLEN(buf, n);
386 total += over; 348 total += n;
387 349
388 nl = (*buf == '\n') ? 1 : 0; 350 nl = (*buf == '\n') ? 1 : 0;
389 VALID(buf, temp, isfrom, zn); 351 VALID(buf, temp, isfrom, zn);
...@@ -403,22 +365,23 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount) ...@@ -403,22 +365,23 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
403 /* signal the end of the body */ 365 /* signal the end of the body */
404 if (mum && !mum->body_end) 366 if (mum && !mum->body_end)
405 { 367 {
406 mum->body_end = total - over - newline; 368 mum->body_end = total - n - newline;
407 mum->body_lines = --lines - newline; 369 mum->body_lines = --lines - newline;
408 DISPATCH_ADD_MSG(mbox, mud, file); 370 if (do_notif)
371 DISPATCH_ADD_MSG(mbox, mud);
409 } 372 }
410 /* allocate_msgs will initialize mum */ 373 /* allocate_msgs will initialize mum */
411 ALLOCATE_MSGS(mbox, mud, file); 374 ALLOCATE_MSGS(mbox, mud);
412 mud->messages_count++; 375 mud->messages_count++;
413 mum = mud->umessages[mud->messages_count - 1]; 376 mum = mud->umessages[mud->messages_count - 1];
414 mum->file = mud->file; 377 mum->stream = mbox->stream;
415 mum->header_from = total - over; 378 mum->header_from = total - n;
416 mum->header_from_end = total; 379 mum->header_from_end = total;
417 lines = 0; 380 lines = 0;
418 } 381 }
419 else if ((over > 7) && ISSTATUS(buf)) 382 else if ((n > 7) && ISSTATUS(buf))
420 { 383 {
421 mum->header_status = total - over; 384 mum->header_status = total - n;
422 mum->header_status_end = total; 385 mum->header_status_end = total;
423 ATTRIBUTE_SET(buf, mum, 'r', 'R', MU_ATTRIBUTE_READ); 386 ATTRIBUTE_SET(buf, mum, 'r', 'R', MU_ATTRIBUTE_READ);
424 ATTRIBUTE_SET(buf, mum, 'o', 'O', MU_ATTRIBUTE_SEEN); 387 ATTRIBUTE_SET(buf, mum, 'o', 'O', MU_ATTRIBUTE_SEEN);
...@@ -433,7 +396,7 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount) ...@@ -433,7 +396,7 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
433 /* set the body position */ 396 /* set the body position */
434 if (mum && !mum->body) 397 if (mum && !mum->body)
435 { 398 {
436 mum->body = total - over + nl; 399 mum->body = total - n + nl;
437 mum->header_lines = lines; 400 mum->header_lines = lines;
438 lines = 0; 401 lines = 0;
439 } 402 }
...@@ -446,25 +409,19 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount) ...@@ -446,25 +409,19 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
446 mailbox_unix_touchlock (mbox); 409 mailbox_unix_touchlock (mbox);
447 410
448 /* ping them every 1000 lines */ 411 /* ping them every 1000 lines */
449 if (((lines +1) % 1000) == 0) 412 if (do_notif)
450 DISPATCH_PROGRESS(mbox, mud, file); 413 if (((lines +1) % 1000) == 0)
414 DISPATCH_PROGRESS(mbox, mud);
451 415
452 } /* while */ 416 } /* while */
453 417
454 status = errno;
455
456 /* not an error if we reach EOF */
457 if (feof (file))
458 status = 0;
459 clearerr (file);
460
461 if (mum) 418 if (mum)
462 { 419 {
463 mum->body_end = total - newline; 420 mum->body_end = total - newline;
464 mum->body_lines = lines - newline; 421 mum->body_lines = lines - newline;
465 DISPATCH_ADD_MSG(mbox, mud, file); 422 if (do_notif)
423 DISPATCH_ADD_MSG(mbox, mud);
466 } 424 }
467 fclose (file);
468 mailbox_unix_iunlock (mbox); 425 mailbox_unix_iunlock (mbox);
469 mailbox_unix_unlock (mbox); 426 mailbox_unix_unlock (mbox);
470 if (pcount) 427 if (pcount)
......
...@@ -389,7 +389,7 @@ message_deregister (message_t msg, void *action) ...@@ -389,7 +389,7 @@ message_deregister (message_t msg, void *action)
389 for (i = 0; i < msg->event_num; i++) 389 for (i = 0; i < msg->event_num; i++)
390 { 390 {
391 event = &(msg->event[i]); 391 event = &(msg->event[i]);
392 if (event->_action == action) 392 if ((int)event->_action == (int)action)
393 { 393 {
394 event->type = 0; 394 event->type = 0;
395 event->_action = NULL; 395 event->_action = NULL;
......
...@@ -77,7 +77,7 @@ static int _mime_append_part(mime_t mime, message_t msg, int body_offset, int bo ...@@ -77,7 +77,7 @@ static int _mime_append_part(mime_t mime, message_t msg, int body_offset, int bo
77 header_set_value(mime_part->hdr, "Content-Type", "message/rfc822", 0, 0); 77 header_set_value(mime_part->hdr, "Content-Type", "message/rfc822", 0, 0);
78 else 78 else
79 header_set_value(mime_part->hdr, "Content-Type", "text/plain", 0, 0); 79 header_set_value(mime_part->hdr, "Content-Type", "text/plain", 0, 0);
80 } 80 }
81 } 81 }
82 mime_part->body_len = body_len; 82 mime_part->body_len = body_len;
83 mime_part->body_offset = body_offset; 83 mime_part->body_offset = body_offset;
...@@ -122,21 +122,21 @@ static void _mime_munge_content_header(char *field_body ) ...@@ -122,21 +122,21 @@ static void _mime_munge_content_header(char *field_body )
122 _strtrim(field_body); 122 _strtrim(field_body);
123 123
124 if ( ( e = strchr(str, ';') ) == NULL ) 124 if ( ( e = strchr(str, ';') ) == NULL )
125 return; 125 return;
126 while( *e == ';' ) { 126 while( *e == ';' ) {
127 p = e; 127 p = e;
128 e++; 128 e++;
129 while ( *e && isspace(*e) ) /* remove space upto param */ 129 while ( *e && isspace(*e) ) /* remove space upto param */
130 e++; 130 e++;
131 memmove(p+1, e, strlen(e)+1); 131 memmove(p+1, e, strlen(e)+1);
132 e = p+1; 132 e = p+1;
133 133
134 while ( *e && *e != '=' ) /* find end of value */ 134 while ( *e && *e != '=' ) /* find end of value */
135 e++; 135 e++;
136 e = p = e+1; 136 e = p = e+1;
137 while ( *e && (quoted || ( !_ISSPECIAL(*e) && !isspace(*e) ) ) ) { 137 while ( *e && (quoted || ( !_ISSPECIAL(*e) && !isspace(*e) ) ) ) {
138 if ( *e == '\\' ) { /* escaped */ 138 if ( *e == '\\' ) { /* escaped */
139 memmove(e, e+1, strlen(e)+2); 139 memmove(e, e+1, strlen(e)+2);
140 } else if ( *e == '\"' ) 140 } else if ( *e == '\"' )
141 quoted = ~quoted; 141 quoted = ~quoted;
142 e++; 142 e++;
...@@ -282,12 +282,12 @@ static int _mime_parse_mpart_message(mime_t mime) ...@@ -282,12 +282,12 @@ static int _mime_parse_mpart_message(mime_t mime)
282 nbytes--; 282 nbytes--;
283 cp++; 283 cp++;
284 } 284 }
285 if ( mime->flags & MIME_INCREAMENTAL_PARSER ) { 285 if ( mime->flags & MIME_INCREAMENTAL_PARSER ) {
286 /* 286 /*
287 * can't really do this since returning EAGAIN will make the MUA think 287 * can't really do this since returning EAGAIN will make the MUA think
288 * it should select on the messages stream fd. re-think this whole 288 * it should select on the messages stream fd. re-think this whole
289 * non-blocking thing..... 289 * non-blocking thing.....
290 290
291 ret = EAGAIN; 291 ret = EAGAIN;
292 break; 292 break;
293 */ 293 */
...@@ -328,15 +328,6 @@ static int _mime_message_fd(stream_t stream, int *fd) ...@@ -328,15 +328,6 @@ static int _mime_message_fd(stream_t stream, int *fd)
328 return stream_get_fd(mime_part->mime->stream, fd); 328 return stream_get_fd(mime_part->mime->stream, fd);
329 } 329 }
330 330
331 static int _mime_new_message_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t *nbytes)
332 {
333 (void)stream; (void)buf; (void)buflen; (void)off;
334 if ( nbytes == NULL )
335 return(EINVAL);
336
337 return 0;
338 }
339
340 static int _mime_body_size (body_t body, size_t *psize) 331 static int _mime_body_size (body_t body, size_t *psize)
341 { 332 {
342 struct _mime_part *mime_part = body->owner; 333 struct _mime_part *mime_part = body->owner;
......
...@@ -74,8 +74,6 @@ static int _trans_read(stream_t stream, char *optr, size_t osize, off_t offset, ...@@ -74,8 +74,6 @@ static int _trans_read(stream_t stream, char *optr, size_t osize, off_t offset,
74 74
75 *nbytes = 0; 75 *nbytes = 0;
76 76
77 if ( offset && ts->offset != offset )
78 return ESPIPE;
79 if ( offset == 0 ) 77 if ( offset == 0 )
80 ts->cur_offset = 0; 78 ts->cur_offset = 0;
81 if ( ( iptr = alloca(isize) ) == NULL ) 79 if ( ( iptr = alloca(isize) ) == NULL )
...@@ -89,13 +87,13 @@ static int _trans_read(stream_t stream, char *optr, size_t osize, off_t offset, ...@@ -89,13 +87,13 @@ static int _trans_read(stream_t stream, char *optr, size_t osize, off_t offset,
89 if ( ( ret = stream_read(ts->stream, iptr + ts->llen, isize - ts->llen, ts->cur_offset, &osize) ) != 0 ) 87 if ( ( ret = stream_read(ts->stream, iptr + ts->llen, isize - ts->llen, ts->cur_offset, &osize) ) != 0 )
90 return ret; 88 return ret;
91 ts->cur_offset += osize; 89 ts->cur_offset += osize;
92 consumed = ts->transcoder(iptr, isize, optr, nbytes); 90 consumed = ts->transcoder(iptr, osize + ts->llen, optr, nbytes);
93 if ( ts->llen = (isize - consumed ) ) { 91 if ( ( ts->llen = ((osize + ts->llen) - consumed ) ) )
92 {
94 if ( ( ts->leftover = malloc(ts->llen) ) == NULL ) 93 if ( ( ts->leftover = malloc(ts->llen) ) == NULL )
95 return ENOMEM; 94 return ENOMEM;
96 memcpy(ts->leftover, iptr + consumed, ts->llen); 95 memcpy(ts->leftover, iptr + consumed, ts->llen);
97 } 96 }
98 ts->offset = offset;
99 return 0; 97 return 0;
100 } 98 }
101 99
...@@ -112,7 +110,7 @@ static int _trans_write(stream_t stream, const char *iptr, size_t isize, off_t o ...@@ -112,7 +110,7 @@ static int _trans_write(stream_t stream, const char *iptr, size_t isize, off_t o
112 110
113 *nbytes = 0; 111 *nbytes = 0;
114 112
115 if ( offset && ts->offset != offset ) 113 if ( offset && ts->cur_offset != offset )
116 return ESPIPE; 114 return ESPIPE;
117 if ( offset == 0 ) 115 if ( offset == 0 )
118 ts->cur_offset = 0; 116 ts->cur_offset = 0;
...@@ -197,19 +195,19 @@ static int _b64_input(char c) ...@@ -197,19 +195,19 @@ static int _b64_input(char c)
197 return -1; 195 return -1;
198 } 196 }
199 197
200 static int _b64_output(int index) 198 static int _b64_output(int idx)
201 { 199 {
202 const char table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 200 const char table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
203 201
204 if (index < 64) 202 if (idx < 64)
205 return table[index]; 203 return table[idx];
206 return -1; 204 return -1;
207 } 205 }
208 206
209 int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes) 207 int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
210 { 208 {
211 int i, tmp = 0; 209 int i = 0, tmp = 0;
212 int consumed = 0; 210 size_t consumed = 0;
213 char data[4]; 211 char data[4];
214 212
215 while ( consumed < isize ) { 213 while ( consumed < isize ) {
...@@ -227,7 +225,10 @@ int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes) ...@@ -227,7 +225,10 @@ int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
227 (*nbytes) += 3; 225 (*nbytes) += 3;
228 } 226 }
229 else // I did not get all the data 227 else // I did not get all the data
228 {
229 consumed -= i;
230 return consumed; 230 return consumed;
231 }
231 i = 0; 232 i = 0;
232 } 233 }
233 return consumed; 234 return consumed;
...@@ -235,7 +236,7 @@ int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes) ...@@ -235,7 +236,7 @@ int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
235 236
236 int _base64_encode(const char *iptr, size_t isize, char *optr, size_t *nbytes) 237 int _base64_encode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
237 { 238 {
238 int consumed = 0; 239 size_t consumed = 0;
239 240
240 while (consumed < (isize - 3) && (*nbytes + 4) < isize) { 241 while (consumed < (isize - 3) && (*nbytes + 4) < isize) {
241 *optr++ = _b64_output(*iptr >> 2); 242 *optr++ = _b64_output(*iptr >> 2);
...@@ -270,7 +271,8 @@ static int _ishex(int c) ...@@ -270,7 +271,8 @@ static int _ishex(int c)
270 int _qp_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes) 271 int _qp_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
271 { 272 {
272 char c; 273 char c;
273 int last_char = 0, consumed = 0; 274 int last_char = 0;
275 size_t consumed = 0;
274 276
275 while (consumed < isize) { 277 while (consumed < isize) {
276 c = *iptr++; 278 c = *iptr++;
...@@ -332,8 +334,8 @@ int _qp_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes) ...@@ -332,8 +334,8 @@ int _qp_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
332 #define QP_LINE_MAX 76 334 #define QP_LINE_MAX 76
333 int _qp_encode(const char *iptr, size_t isize, char *optr, size_t *nbytes) 335 int _qp_encode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
334 { 336 {
335 int count = 0; 337 int count = 0, c;
336 int consumed = 0, c; 338 size_t consumed = 0;
337 339
338 while (consumed < isize && (*nbytes + 4) < isize) { 340 while (consumed < isize && (*nbytes + 4) < isize) {
339 if (count == QP_LINE_MAX) { 341 if (count == QP_LINE_MAX) {
......