gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog libbase/curl_adapter.cpp libbas...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libbase/curl_adapter.cpp libbas...
Date: Tue, 17 Apr 2007 10:38:16 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/04/17 10:38:16

Modified files:
        .              : ChangeLog 
        libbase        : curl_adapter.cpp noseek_fd_adapter.cpp 
                         tu_file.cpp tu_file.h zlib_adapter.cpp 
        server/asobj   : xml.cpp 

Log message:
                * libbase/: tu_file.{cpp,h}, curl_adapter.cpp, zlib_adapter.cpp,
                  noseek_fd_adapter.cpp:
                  Add another callback for getting stream error. First pass at
                  documenting the tu_file interfaces (needs more work).
                  Updated implementations to provide the new error getter.
                * server/asobj/xml.cpp (XML::load): check stream status after
                  call to xmlReadIO. The libxml2 function seems immune to
                  stream errors, but we can handle them and avoid parsing
                  anything if a stream error occurs (404 will be a stream 
error).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2894&r2=1.2895
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/curl_adapter.cpp?cvsroot=gnash&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/noseek_fd_adapter.cpp?cvsroot=gnash&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_file.cpp?cvsroot=gnash&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_file.h?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/zlib_adapter.cpp?cvsroot=gnash&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.cpp?cvsroot=gnash&r1=1.38&r2=1.39

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2894
retrieving revision 1.2895
diff -u -b -r1.2894 -r1.2895
--- ChangeLog   17 Apr 2007 09:18:37 -0000      1.2894
+++ ChangeLog   17 Apr 2007 10:38:16 -0000      1.2895
@@ -1,3 +1,15 @@
+2007-04-17 Sandro Santilli <address@hidden>
+
+       * libbase/: tu_file.{cpp,h}, curl_adapter.cpp, zlib_adapter.cpp,
+         noseek_fd_adapter.cpp:
+         Add another callback for getting stream error. First pass at
+         documenting the tu_file interfaces (needs more work).
+         Updated implementations to provide the new error getter.
+       * server/asobj/xml.cpp (XML::load): check stream status after
+         call to xmlReadIO. The libxml2 function seems immune to 
+         stream errors, but we can handle them and avoid parsing
+         anything if a stream error occurs (404 will be a stream error).
+
 2007-04-17 Udo Giacomozzi <address@hidden>
 
        * backend/render_handler_agg: Replaced drawVideoFrame() to use AGG

Index: libbase/curl_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/curl_adapter.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- libbase/curl_adapter.cpp    8 Apr 2007 23:06:17 -0000       1.25
+++ libbase/curl_adapter.cpp    17 Apr 2007 10:38:16 -0000      1.26
@@ -16,7 +16,7 @@
 
 // 
 
-/* $Id: curl_adapter.cpp,v 1.25 2007/04/08 23:06:17 rsavoye Exp $ */
+/* $Id: curl_adapter.cpp,v 1.26 2007/04/17 10:38:16 strk Exp $ */
 
 #if defined(_WIN32) || defined(WIN32)
 #define snprintf _snprintf
@@ -112,6 +112,11 @@
        /// Return true if EOF has been reached
        bool eof();
 
+       /// Return the error condition of current stream
+       int err() const {
+               return _error;
+       }
+
        /// Report global position within the file
        size_t tell();
 
@@ -148,6 +153,13 @@
        // transfer in progress
        int _running;
 
+       // stream error 
+       // 0 on no error.
+       // Example of errors would be:
+       //      404 - file not found
+       //      timeout occurred
+       int _error;
+
        // Post data. Empty if no POST has been requested
        std::string _postdata;
 
@@ -257,6 +269,16 @@
                        throw gnash::GnashException(curl_multi_strerror(mcode));
                }
 
+                long code;
+                curl_easy_getinfo(_handle, CURLINFO_RESPONSE_CODE, &code);
+                if ( code == 404 ) // file not found!
+                {
+                        gnash::log_warning("404 response from url %s", 
_url.c_str());
+                        _error = TU_FILE_OPEN_ERROR;
+                       _running = false;
+                        return;
+                }
+
                // we already have that much data
                fstat(_cachefd, &statbuf);
                if ( statbuf.st_size >= size ) 
@@ -289,6 +311,7 @@
 
        _url = url;
        _running = 1;
+       _error = 0;
 
        _cached = -1;
 
@@ -413,13 +436,14 @@
 size_t
 CurlStreamFile::read(void *dst, size_t bytes)
 {
-       if ( eof() ) return 0;
+       if ( eof() || _error ) return 0;
 
 #ifdef GNASH_CURL_VERBOSE
        fprintf(stderr, "read(%d) called\n", bytes);
 #endif
 
        fill_cache(tell()+bytes);
+       if ( _error ) return 0; // error can be set by fill_cache
 
 #ifdef GNASH_CURL_VERBOSE
        printInfo();
@@ -469,6 +493,7 @@
 #endif
 
        fill_cache(pos);
+       if ( _error ) return false; // error can be set by fill_cache
 
        if ( fseek(_cache, pos, SEEK_SET) == -1 ) {
                fprintf(stderr, "Warning: fseek failed\n");
@@ -495,6 +520,16 @@
                {
                        throw gnash::GnashException(curl_multi_strerror(mcode));
                }
+
+                long code;
+                curl_easy_getinfo(_handle, CURLINFO_RESPONSE_CODE, &code);
+                if ( code == 404 ) // file not found!
+                {
+                        gnash::log_warning("404 response from url %s", 
_url.c_str());
+                        _error = TU_FILE_OPEN_ERROR;
+                       _running = false;
+                        return false;
+                }
        }
 
        if ( fseek(_cache, 0, SEEK_END) == -1 ) {
@@ -538,6 +573,13 @@
        return stream->read(dst, bytes);
 }
 
+static int
+err(void* appdata)
+{
+       CurlStreamFile* stream = (CurlStreamFile*) appdata;
+       return stream->err();
+}
+
 static bool
 eof(void* appdata)
 {
@@ -625,6 +667,7 @@
                seek_to_end, // seek_to_end
                tell, // tell
                eof, // get eof
+               err, // get error
                get_stream_size, // size of stream 
                close);
 }
@@ -656,6 +699,7 @@
                seek_to_end, // seek_to_end
                tell, // tell
                eof, // get eof
+               err, // get error
                get_stream_size, // size of stream 
                close);
 }

Index: libbase/noseek_fd_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/noseek_fd_adapter.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- libbase/noseek_fd_adapter.cpp       8 Apr 2007 23:06:17 -0000       1.15
+++ libbase/noseek_fd_adapter.cpp       17 Apr 2007 10:38:16 -0000      1.16
@@ -16,7 +16,7 @@
 
 // 
 
-/* $Id: noseek_fd_adapter.cpp,v 1.15 2007/04/08 23:06:17 rsavoye Exp $ */
+/* $Id: noseek_fd_adapter.cpp,v 1.16 2007/04/17 10:38:16 strk Exp $ */
 
 #if defined(_WIN32) || defined(WIN32)
 #define snprintf _snprintf
@@ -93,6 +93,9 @@
        /// Return true if EOF has been reached
        bool eof();
 
+       /// Return zero if everything is fine (?)
+       int err() { return 0; }
+
        /// Report global position within the file
        size_t tell();
 
@@ -420,6 +423,14 @@
 }
 
 static int
+err(void* appdata)
+{
+       NoSeekFile* stream = (NoSeekFile*) appdata;
+       if ( ! stream ) return TU_FILE_OPEN_ERROR;
+       return stream->err();
+}
+
+static int
 write(const void* /*src*/, int /*bytes*/, void* /*appdata*/)
 {
        assert(0); // not supported
@@ -485,6 +496,7 @@
                seek_to_end, // seek_to_end
                tell, // tell
                eof, // get eof
+               err, // get error
                NULL, // get stream size
                close);
 }

Index: libbase/tu_file.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/tu_file.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- libbase/tu_file.cpp 29 Mar 2007 10:32:04 -0000      1.14
+++ libbase/tu_file.cpp 17 Apr 2007 10:38:16 -0000      1.15
@@ -87,6 +87,14 @@
     }
 }
 
+static int
+std_get_err_func(void *appdata)
+// Return true if we're at EOF.
+{
+    if ( ! appdata ) return TU_FILE_OPEN_ERROR;
+    return (ferror((FILE*) appdata));
+}
+
 static long
 std_get_stream_size_func(void *appdata)
 // Return -1 on failure, or the size
@@ -286,6 +294,14 @@
     return buf->m_position >= buf->m_.size();
 }
 
+static int
+mem_get_err_func(void* appdata)
+// Return true if we're positioned at the end of the buffer.
+{
+    filebuf* buf = (filebuf*) appdata;
+    return buf->is_valid();
+}
+
 static long
 mem_get_stream_size(void* appdata)
 // Return the file size, or -1 on failure.
@@ -319,7 +335,7 @@
 // Create a file using the custom callbacks.
 tu_file::tu_file(void * appdata, read_func rf, write_func wf,
                 seek_func sf, seek_to_end_func ef, tell_func tf,
-                get_eof_func gef, get_stream_size_func gss, close_func cf)
+                get_eof_func gef, get_err_func ger, get_stream_size_func gss, 
close_func cf)
 {
     m_data = appdata;
     m_read = rf;
@@ -328,9 +344,9 @@
     m_seek_to_end = ef;
     m_tell = tf;
     m_get_eof = gef;
+    m_get_err = ger;
     m_get_stream_size = gss;
     m_close = cf;
-    m_error = TU_FILE_NO_ERROR;
 }
 
 // Create a file from a standard file pointer.
@@ -345,9 +361,9 @@
     m_seek_to_end = std_seek_to_end_func;
     m_tell = std_tell_func;
     m_get_eof = std_get_eof_func;
+    m_get_err = std_get_err_func;
     m_get_stream_size = std_get_stream_size_func;
     m_close = autoclose ? std_close_func : NULL;
-    m_error = TU_FILE_NO_ERROR;
 }
 
 // Create a file from the given name and the given mode.
@@ -357,27 +373,15 @@
 
     m_data = fopen(name, mode);
     
-    if (m_data) {
        m_read = std_read_func;
        m_write = std_write_func;
        m_seek = std_seek_func;
        m_seek_to_end = std_seek_to_end_func;
        m_tell = std_tell_func;
        m_get_eof = std_get_eof_func;
+       m_get_err = std_get_err_func;
     m_get_stream_size = std_get_stream_size_func;
        m_close = std_close_func;
-       m_error = TU_FILE_NO_ERROR;
-    } else {
-       m_read = NULL;
-       m_write = NULL;
-       m_seek = NULL;
-       m_seek_to_end = NULL;
-       m_tell = NULL;
-       m_get_eof = NULL;
-    m_get_stream_size = NULL;
-       m_close = NULL;
-       m_error = TU_FILE_OPEN_ERROR;
-    }
 }
 
 tu_file::tu_file(memory_buffer_enum /* m */)
@@ -391,9 +395,9 @@
     m_seek_to_end = mem_seek_to_end_func;
     m_tell = mem_tell_func;
     m_get_eof = mem_get_eof_func;
+    m_get_err = mem_get_err_func;
     m_get_stream_size = mem_get_stream_size;
     m_close = mem_close_func;
-    m_error = TU_FILE_NO_ERROR;
 }
 
 
@@ -408,9 +412,9 @@
     m_seek_to_end = mem_seek_to_end_func;
     m_tell = mem_tell_func;
     m_get_eof = mem_get_eof_func;
+    m_get_err = mem_get_err_func;
     m_get_stream_size = mem_get_stream_size;
     m_close = mem_close_func;
-    m_error = TU_FILE_NO_ERROR;
 }
 
 tu_file::~tu_file()
@@ -423,7 +427,7 @@
 tu_file::close() 
 // Close this file.
 { 
-    if (m_close) {
+    if (m_close && m_data) {
        m_close(m_data);
     }
     m_data = NULL; 

Index: libbase/tu_file.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/tu_file.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- libbase/tu_file.h   11 Apr 2007 17:54:21 -0000      1.12
+++ libbase/tu_file.h   17 Apr 2007 10:38:16 -0000      1.13
@@ -43,6 +43,7 @@
     typedef int (* seek_to_end_func)(void* appdata);
     typedef int (* tell_func)(void* appdata);
     typedef bool (* get_eof_func)(void* appdata);
+    typedef int (* get_err_func)(void* appdata);
     typedef long (* get_stream_size_func)(void* appdata);
     typedef int (* close_func)(void* appdata);
     
@@ -55,6 +56,7 @@
        seek_to_end_func ef,
        tell_func tf,
        get_eof_func gef,
+       get_err_func ger,
        get_stream_size_func gss,
        close_func cf=NULL);
     
@@ -78,61 +80,209 @@
     
     ~tu_file();
     
-    // Copy remaining contents of *in into *this.
+    /// Copy remaining contents of *in into *this.
+    //
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void copy_from(tu_file* in);
-    // Copy remaining contents of *this into *out.
+
+    /// Copy remaining contents of *this into *out.
+    //
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void copy_to(membuf* out);
     
-    // Copy a fixed number of bytes from *in to *this.
-    // Returns number of bytes copied.
+    /// Copy a fixed number of bytes from *in to *this.
+    //
+    /// Returns number of bytes copied.
+    ///
+    /// TODO: define what happens when either one of the streams
+    ///       is in error condition, see get_error().
+    ///
     int        copy_bytes(tu_file* in, int bytes);
     
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     uint64_t   read_le64();
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     uint32_t   read_le32();
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     uint16_t   read_le16();
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     uint64_t   read_be64();
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     uint32_t   read_be32();
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     uint16_t   read_be16();
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void       write_le64(uint64_t u);
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void       write_le32(uint32_t u);
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void       write_le16(uint16_t u);
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void       write_be64(uint64_t u);
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void       write_be32(uint32_t u);
+
+    /// \brief
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void       write_be16(uint16_t u);
     
-    // read/write a single byte
+    /// Read a single byte from the stream
+    //
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     uint8_t    read_byte() { return read8(); }
+
+    /// write a single byte to the stream
+    //
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     void       write_byte(uint8_t u) { write8(u); }
     
-    // Read/write a byte buffer.
-    // Returns number of bytes read/written.
+    /// Read the given number of bytes from the stream
+    //
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     int        read_bytes(void* dst, int num) { return m_read(dst, num, 
m_data); }
+
+    /// Write the given number of bytes to the stream
+    //
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
     int        write_bytes(const void* src, int num) { return m_write(src, 
num, m_data); }
     
-    // write a 0-terminated string.
+    /// Write a 0-terminated string.
+    //
+    /// TODO: define what happens when the stream
+    ///       is in error condition, see get_error().
+    ///
        void    write_string(const char* src);
     
-    // Read up to max_length characters, returns the number of characters 
-    // read, or -1 if the string length is longer than max_length.
+    /// \brief
+    /// Read up to max_length characters, returns the number of characters 
+    /// read, or -1 if the string length is longer than max_length.
     //
-    // Stops at the first \0 character if it comes before max_length.
-    //
-    // Guarantees termination of the string.
+    /// Stops at the first \0 character if it comes before max_length.
+    ///
+    /// Guarantees termination of the string.
+    ///
+    /// @return ??
+    ///
+    /// TODO: define what to return when the stream
+    ///       is in error condition, see get_error().
+    ///
     int        read_string(char* dst, int max_length);
     
-    // float/double IO
+    /// \brief
+    /// TODO: define what to return when the stream
+    ///       is in error condition, see get_error().
     void       write_float32(float value);
+
+    /// \brief
+    /// TODO: define what to return when the stream
+    ///       is in error condition, see get_error().
     void       write_double64(double value);
+
+    /// \brief
+    /// TODO: define what to return when the stream
+    ///       is in error condition, see get_error().
     float      read_float32();
+
+    /// \brief
+    /// TODO: define what to return when the stream
+    ///       is in error condition, see get_error().
     double     read_double64();
     
-    // get/set pos
+    /// Return current stream position
+    //
+    /// TODO: define what to return when the stream
+    ///       is in error condition, see get_error().
+    ///
     int        get_position() const { return m_tell(m_data); }
+
+    /// Seek to the specified position
+    //
+    /// 
+    /// TODO: define what happens when an error occurs, or
+    ///       when we're already in an error condition
+    ///
     void       set_position(int p) { m_seek(p, m_data); }
+
+    /// Seek to the end of the stream
+    //
+    /// TODO: define what happens when an error occurs
+    ///
     void       go_to_end() { m_seek_to_end(m_data); }
+
+    /// Return true if the end of the stream has been reached.
+    //
+    /// TODO: define what to return when in error condition
+    /// see get_error().
+    ///
     bool       get_eof() { return m_get_eof(m_data); }
     
-    int        get_error() { return m_error; }
+    /// Return non-zero if the stream is in an error state
+    //
+    /// When the stream is in an error state there's nothing
+    /// you can do about it, just delete it and log the error.
+    ///
+    /// There are some rough meaning for possible returned values
+    /// but I don't think they make much sense currently.
+    ///
+    int        get_error() { return m_get_err(m_data); }
     
 
        // get the size of the stream
@@ -189,9 +339,9 @@
     seek_to_end_func   m_seek_to_end;
     tell_func          m_tell;
     get_eof_func       m_get_eof;
+    get_err_func       m_get_err;
     get_stream_size_func       m_get_stream_size;
     close_func         m_close;
-    int                m_error;
 };
 
 

Index: libbase/zlib_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/zlib_adapter.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- libbase/zlib_adapter.cpp    9 Mar 2007 14:38:29 -0000       1.13
+++ libbase/zlib_adapter.cpp    17 Apr 2007 10:38:16 -0000      1.14
@@ -290,6 +290,12 @@
                return inf->m_at_eof;
        }
 
+       inline int inflate_get_err(void* appdata)
+       {
+               inflater_impl*  inf = (inflater_impl*) appdata;
+               return inf->m_error;
+       }
+
        inline int inflate_close(void* appdata)
        {
                inflater_impl*  inf = (inflater_impl*) appdata;
@@ -322,6 +328,7 @@
                                inflate_seek_to_end,
                                inflate_tell,
                                inflate_get_eof,
+                               inflate_get_err,
                                NULL, // get stream size
                                inflate_close)
                        );

Index: server/asobj/xml.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xml.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- server/asobj/xml.cpp        16 Apr 2007 18:23:06 -0000      1.38
+++ server/asobj/xml.cpp        17 Apr 2007 10:38:16 -0000      1.39
@@ -14,7 +14,7 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-/* $Id: xml.cpp,v 1.38 2007/04/16 18:23:06 strk Exp $ */
+/* $Id: xml.cpp,v 1.39 2007/04/17 10:38:16 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -380,13 +380,23 @@
         return false;
     }
 
-    log_msg("Load XML file from url: %s", url.str().c_str());
+    log_msg("Loading XML file from url: '%s'", url.str().c_str());
 
     initParser();
 
     /// see: http://xmlsoft.org/html/libxml-parser.html#xmlParserOption
     int options = XML_PARSE_RECOVER | XML_PARSE_NOWARNING | XML_PARSE_NOERROR;
     _doc = xmlReadIO(readFromTuFile, closeTuFile, str.get(), 
url.str().c_str(), NULL, options);
+    if ( str->get_error() )
+    {
+       xmlFreeDoc(_doc);
+        _doc = 0;
+        log_error("Can't read XML file %s (stream error %d)!", 
url.str().c_str(), str->get_error());
+        _loaded = 0;
+        onLoadEvent(false);
+        return false;
+    }
+
     _bytes_total = str->get_size();
 
     if (_doc == 0)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]