From 82ca4cf8ce421cbec87667f6c22b3e7165443016 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: added InputStream.ready The flag "ready" indicates whether the input stream is ready and it has parsed all meta data. Previously, it was impossible for decodeStart() to see the content type of HTTP input streams, because at that time, the HTTP response wasn't parsed yet. --- src/decode.c | 12 ++++++++++++ src/inputStream.c | 1 + src/inputStream.h | 2 ++ src/inputStream_file.c | 2 ++ src/inputStream_http.c | 2 ++ 5 files changed, 19 insertions(+) diff --git a/src/decode.c b/src/decode.c index 92f01a393..97896f67d 100644 --- a/src/decode.c +++ b/src/decode.c @@ -53,6 +53,18 @@ static void decodeStart(void) dc.state = DECODE_STATE_START; dc.command = DECODE_COMMAND_NONE; + /* wait for the input stream to become ready; its metadata + will be available then */ + + while (!inStream.ready) { + if (dc.command != DECODE_COMMAND_NONE) + goto stop; + + ret = bufferInputStream(&inStream); + if (ret < 0) + goto stop; + } + /* for http streams, seekable is determined in bufferInputStream */ dc.seekable = inStream.seekable; diff --git a/src/inputStream.c b/src/inputStream.c index 9495beb8a..7686fed48 100644 --- a/src/inputStream.c +++ b/src/inputStream.c @@ -31,6 +31,7 @@ void initInputStream(void) int openInputStream(InputStream * inStream, char *url) { + inStream->ready = 0; inStream->offset = 0; inStream->size = 0; inStream->error = 0; diff --git a/src/inputStream.h b/src/inputStream.h index c1e2e4f83..2e32c2a13 100644 --- a/src/inputStream.h +++ b/src/inputStream.h @@ -32,6 +32,8 @@ typedef int (*InputStreamAtEOFFunc) (InputStream * inStream); typedef int (*InputStreamBufferFunc) (InputStream * inStream); struct _InputStream { + int ready; + int error; long offset; size_t size; diff --git a/src/inputStream_file.c b/src/inputStream_file.c index 2e51e3f6c..7110eb2e8 100644 --- a/src/inputStream_file.c +++ b/src/inputStream_file.c @@ -52,6 +52,8 @@ int inputStream_fileOpen(InputStream * inStream, char *filename) inStream->atEOFFunc = inputStream_fileAtEOF; inStream->bufferFunc = inputStream_fileBuffer; + inStream->ready = 1; + return 0; } diff --git a/src/inputStream_http.c b/src/inputStream_http.c index 3e99b0475..ace6da4ce 100644 --- a/src/inputStream_http.c +++ b/src/inputStream_http.c @@ -598,6 +598,7 @@ found: xclose(data->fd); data->fd = -1; data->state = CONN_STATE_REDIRECT; + is->ready = 1; return 0; /* success */ } return -1; @@ -696,6 +697,7 @@ static int recv_response(InputStream * is) ringbuf_writer_reset(data->rb); data->state = CONN_STATE_PREBUFFER; + is->ready = 1; return 0; } -- cgit v1.2.3