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(+), 0 deletions(-)

diff --git a/src/decode.c b/src/decode.c
index 92f01a3..97896f6 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 9495beb..7686fed 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 c1e2e4f..2e32c2a 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 2e51e3f..7110eb2 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 3e99b04..ace6da4 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;
 }


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to