[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso... |
Date: |
Tue, 03 Apr 2007 07:30:17 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/04/03 07:30:17
Modified files:
. : ChangeLog
server/asobj : xml.cpp xml.h
Log message:
* server/asobj/xml.{cpp,h}: allow reading XML from
a network stream (untested).
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2755&r2=1.2756
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.cpp?cvsroot=gnash&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.h?cvsroot=gnash&r1=1.8&r2=1.9
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2755
retrieving revision 1.2756
diff -u -b -r1.2755 -r1.2756
--- ChangeLog 2 Apr 2007 22:45:09 -0000 1.2755
+++ ChangeLog 3 Apr 2007 07:30:17 -0000 1.2756
@@ -1,3 +1,8 @@
+2007-04-03 Sandro Santilli <address@hidden>
+
+ * server/asobj/xml.{cpp,h}: allow reading XML from
+ a network stream (untested).
+
2007-04-03 Markus Gothe <address@hidden>
* server/as_value.h: Include <limits> for NAN.
Index: server/asobj/xml.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xml.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- server/asobj/xml.cpp 22 Mar 2007 22:37:46 -0000 1.24
+++ server/asobj/xml.cpp 3 Apr 2007 07:30:17 -0000 1.25
@@ -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.24 2007/03/22 22:37:46 bjacques Exp $ */
+/* $Id: xml.cpp,v 1.25 2007/04/03 07:30:17 strk Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -31,6 +31,10 @@
#include "xml.h"
#include "builtin_function.h"
#include "debugger.h"
+#include "StreamProvider.h"
+#include "URLAccessManager.h"
+#include "tu_file.h"
+#include "URL.h"
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
@@ -43,6 +47,7 @@
#include <sstream>
#include <vector>
#include <boost/lexical_cast.hpp>
+#include <memory>
using namespace std;
@@ -52,6 +57,11 @@
static as_object* getXMLInterface();
+// Callback function for xmlReadIO
+static int closeTuFile (void * context);
+// Callback function for xmlReadIO
+static int readFromTuFile (void * context, char * buffer, int len);
+
DSOEXPORT as_value xml_new(const fn_call& fn);
static as_value xml_load(const fn_call& fn);
//static as_value xml_set_current(const fn_call& fn); // UNDEFINED
@@ -389,27 +399,33 @@
// This reads in an XML file from disk and parses into into a memory resident
// tree which can be walked through later.
bool
-XML::load(const char *filespec)
+XML::load(const URL& url)
{
// GNASH_REPORT_FUNCTION;
- struct stat stats;
- log_msg("Load disk XML file: %s\n", filespec);
//log_msg("%s: mem is %d\n", __FUNCTION__, mem);
- // See if the file exists
- if (stat(filespec, &stats) == 0) {
- _bytes_total = stats.st_size;
- _bytes_loaded = stats.st_size; // FIXME: this should probably
- // be set later on after the
- // file is loaded
+ std::auto_ptr<tu_file> str (
StreamProvider::getDefaultInstance().getStream(url) );
+ if ( ! str.get() )
+ {
+ log_error("Can't load XML file: %s (security?)", url.str().c_str());
+ return false;
}
+
+ log_msg("Load XML file from url: %s", url.str().c_str());
+
xmlInitParser();
- _doc = xmlParseFile(filespec);
+
+ _doc = xmlReadIO(readFromTuFile, closeTuFile, str.get(),
url.str().c_str(), NULL, 0);
+ _bytes_total = str->get_size();
+
if (_doc == 0) {
- log_error("Can't load XML file: %s!\n", filespec);
+ log_error("Can't read XML file (IO): %s!", url.str().c_str());
return false;
}
+
+ _bytes_loaded = _bytes_total;
+
parseDoc(_doc, false);
xmlCleanupParser();
xmlFreeDoc(_doc);
@@ -763,7 +779,6 @@
as_value val;
as_value rv = false;
bool ret;
- struct stat stats;
//GNASH_REPORT_FUNCTION;
@@ -771,16 +786,11 @@
std::string filespec = fn.arg(0).to_string();
- // If the file doesn't exist, don't try to do anything.
- if (stat(filespec.c_str(), &stats) < 0) {
- fprintf(stderr, "ERROR: doesn't exist.%s\n", filespec.c_str());
- rv = false;
- return rv;
- }
+ URL url(filespec, get_base_url());
// Set the argument to the function event handler based on whether the load
// was successful or failed.
- ret = xml_obj->load(filespec.c_str());
+ ret = xml_obj->load(url);
rv = ret;
if (ret == false) {
@@ -797,35 +807,28 @@
}
xml_obj->setupFrame(xml_obj.get(), xml_obj->firstChild(), false);
-#if 1
- if (fn.this_ptr->get_member("onLoad", &method)) {
+ if (fn.this_ptr->get_member("onLoad", &method))
+ {
// log_msg("FIXME: Found onLoad!\n");
fn.env().set_variable("success", true);
fn.arg(0) = true;
-#if 0
- as_c_function_ptr func = method.to_c_function();
- if (func) {
- // It's a C function. Call it.
- log_msg("Calling C function for onLoad\n");
- (*func)(fn_call(&val, xml_obj, fn.env(), fn.nargs,
fn.first_arg_bottom_index)); // was this_ptr instead of node
- } else
-#endif
- if (as_function* as_func = method.to_as_function()) {
+ if (as_function* as_func = method.to_as_function())
+ {
// It's an ActionScript function. Call it.
- log_msg("Calling ActionScript function for onLoad\n");
+ log_msg("Calling ActionScript function for XML.onLoad");
// XXX other than being assigned into, val appears to be unused.
val = (*as_func)(fn_call(xml_obj, &fn.env(), fn.nargs,
fn.offset())); // was this_ptr instead of node
- } else {
+ }
+ else
+ {
log_error("error in call_method(): method is not a function\n");
}
- } else {
- log_msg("Couldn't find onLoad event handler, setting up callback\n");
+ }
+ else
+ {
+ //log_msg("Couldn't find onLoad event handler, setting up callback");
// ptr->set_event_handler(event_id::XML_LOAD,
(as_c_function_ptr)&xml_onload);
}
-#else
- xml_obj->set_event_handler(event_id::XML_LOAD, &xml_onload);
-
-#endif
rv = true;
return rv;
@@ -1337,6 +1340,26 @@
}
+// Callback function for xmlReadIO
+static int
+readFromTuFile (void * context, char * buffer, int len)
+{
+ tu_file* str = static_cast<tu_file*>(context);
+ size_t read = str->read_bytes(buffer, len);
+ if ( str->get_error() ) return -1;
+ else return read;
+}
+
+// Callback function for xmlReadIO
+static int
+closeTuFile (void * /*context*/)
+{
+ // nothing to do, the tu_file destructor will close
+ //tu_file* str = static_cast<tu_file*>(context);
+ //str->close();
+ return 0; // no error
+}
+
} // end of gnash namespace
// Local Variables:
Index: server/asobj/xml.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xml.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- server/asobj/xml.h 19 Mar 2007 17:11:14 -0000 1.8
+++ server/asobj/xml.h 3 Apr 2007 07:30:17 -0000 1.9
@@ -47,6 +47,7 @@
// Forward declarations
class fn_call;
+class URL;
/// XML class and ActionScript object
class DSOLOCAL XML : public as_object
@@ -63,9 +64,11 @@
bool parseDoc(xmlDocPtr document, bool mem);
// Parses an XML document into the specified XML object tree.
bool parseXML(tu_string xml_in);
+
// Loads a document (specified by
- bool load(const char *filespec);
// the XML object) from a URL.
+ bool load(const URL& url);
+
// An event handler that returns a
bool onLoad();
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso...,
Sandro Santilli <=
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso..., Sandro Santilli, 2007/04/03
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso..., Sandro Santilli, 2007/04/03
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso..., Sandro Santilli, 2007/04/04
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso..., Sandro Santilli, 2007/04/04
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso..., Sandro Santilli, 2007/04/04
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso..., Sandro Santilli, 2007/04/04
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso..., Sandro Santilli, 2007/04/04
- [Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso..., Sandro Santilli, 2007/04/07