Mercurial > dovecot > core-2.2
comparison src/lib-mail/istream-header-filter.c @ 4327:dbae2347dcdb HEAD
Handle i_stream_stat() better.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 Jun 2006 22:26:53 +0300 |
parents | 928229f8b3e6 |
children | 414c0c45040e |
comparison
equal
deleted
inserted
replaced
4326:e228a9efd35d | 4327:dbae2347dcdb |
---|---|
233 (ret == 0 ? 0 : -1); | 233 (ret == 0 ? 0 : -1); |
234 stream->pos = pos; | 234 stream->pos = pos; |
235 return ret; | 235 return ret; |
236 } | 236 } |
237 | 237 |
238 static void parse_header(struct header_filter_istream *mstream) | |
239 { | |
240 size_t pos; | |
241 | |
242 while (!mstream->header_read) { | |
243 if (_read(&mstream->istream) == -1) | |
244 break; | |
245 | |
246 (void)i_stream_get_data(&mstream->istream.istream, &pos); | |
247 i_stream_skip(&mstream->istream.istream, pos); | |
248 } | |
249 } | |
250 | |
238 static void _seek(struct _istream *stream, uoff_t v_offset, | 251 static void _seek(struct _istream *stream, uoff_t v_offset, |
239 bool mark __attr_unused__) | 252 bool mark __attr_unused__) |
240 { | 253 { |
241 struct header_filter_istream *mstream = | 254 struct header_filter_istream *mstream = |
242 (struct header_filter_istream *)stream; | 255 (struct header_filter_istream *)stream; |
243 size_t pos; | 256 |
244 | 257 parse_header(mstream); |
245 while (!mstream->header_read) { | |
246 if (_read(stream) == -1) | |
247 break; | |
248 | |
249 (void)i_stream_get_data(&stream->istream, &pos); | |
250 i_stream_skip(&stream->istream, pos); | |
251 } | |
252 | |
253 stream->istream.v_offset = v_offset; | 258 stream->istream.v_offset = v_offset; |
254 stream->skip = stream->pos = 0; | 259 stream->skip = stream->pos = 0; |
255 stream->buffer = NULL; | 260 stream->buffer = NULL; |
256 | 261 |
257 if (mstream->hdr_ctx != NULL) { | 262 if (mstream->hdr_ctx != NULL) { |
278 { | 283 { |
279 i_panic("istream-header-filter sync() not implemented"); | 284 i_panic("istream-header-filter sync() not implemented"); |
280 } | 285 } |
281 | 286 |
282 static const struct stat * | 287 static const struct stat * |
283 _stat(struct _istream *stream, bool exact __attr_unused__) | 288 _stat(struct _istream *stream, bool exact) |
284 { | 289 { |
285 /* return size and others as unknown */ | 290 struct header_filter_istream *mstream = |
291 (struct header_filter_istream *)stream; | |
292 const struct stat *st; | |
293 | |
294 st = i_stream_stat(mstream->input, exact); | |
295 if (st == NULL || st->st_size == -1 || !exact) | |
296 return st; | |
297 | |
298 parse_header(mstream); | |
299 | |
300 stream->statbuf = *st; | |
301 stream->statbuf.st_size -= | |
302 (off_t)mstream->header_size.physical_size - | |
303 (off_t)mstream->header_size.virtual_size; | |
286 return &stream->statbuf; | 304 return &stream->statbuf; |
287 } | 305 } |
288 | 306 |
289 struct istream * | 307 struct istream * |
290 i_stream_create_header_filter(struct istream *input, | 308 i_stream_create_header_filter(struct istream *input, |