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.
This commit is contained in:
Max Kellermann 2008-08-26 08:27:10 +02:00
parent 6120635f06
commit 82ca4cf8ce
5 changed files with 19 additions and 0 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -52,6 +52,8 @@ int inputStream_fileOpen(InputStream * inStream, char *filename)
inStream->atEOFFunc = inputStream_fileAtEOF;
inStream->bufferFunc = inputStream_fileBuffer;
inStream->ready = 1;
return 0;
}

View File

@ -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;
}