gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9860: Separate LoadVars properly wi


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9860: Separate LoadVars properly with "&" when converting to string and don't add
Date: Mon, 29 Sep 2008 10:40:24 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9860
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2008-09-29 10:40:24 +0200
message:
  Separate LoadVars properly with "&" when converting to string and don't add
  the "?" there. It's only necessary when actually sending. Allow XML
  to be sent using the GET method, appropriately URL encoded (undocumented).
  
  Add documentation, drop default "post" argument for sendAndLoad, as all users
  now need to specify a method.
modified:
  libcore/asobj/LoadVars_as.cpp
  libcore/asobj/LoadableObject.cpp
  libcore/asobj/LoadableObject.h
  libcore/asobj/XML_as.cpp
  libcore/asobj/XML_as.h
  libcore/asobj/xmlnode.cpp
  libcore/asobj/xmlnode.h
=== modified file 'libcore/asobj/LoadVars_as.cpp'
--- a/libcore/asobj/LoadVars_as.cpp     2008-09-19 09:41:54 +0000
+++ b/libcore/asobj/LoadVars_as.cpp     2008-09-29 08:40:24 +0000
@@ -69,7 +69,13 @@
 
 protected:
 
-    void toString(std::ostream& o) const;
+    /// Convert the LoadVars Object to a string.
+    //
+    /// @param o        The ostream to write the string to.
+    /// @param encode   Whether URL encoding is necessary. This is
+    ///                 ignored because LoadVars objects are always
+    ///                 URL encoded.
+    void toString(std::ostream& o, bool encode) const;
 
 #ifdef GNASH_USE_GC
        /// Mark all reachable resources, for the GC
@@ -105,21 +111,18 @@
 
 
 void
-LoadVars_as::toString(std::ostream& o) const
+LoadVars_as::toString(std::ostream& o, bool /*post*/) const
 {
 
        typedef std::map<std::string, std::string> VarMap;
        VarMap vars;
 
-       // TODO: it seems that calling enumerateProperties(vars) here
-       //       somehow corrupts the stack !
        enumerateProperties(vars);
 
-    if (!vars.empty()) o << "?";
-
        for (VarMap::iterator it=vars.begin(), itEnd=vars.end();
                        it != itEnd; ++it)
        {
+           if (it != vars.begin()) o << "&";
         const std::string& val = it->second;
         o << URL::encode(it->first) << "="
                     << URL::encode(val);
@@ -421,8 +424,6 @@
        bool post = true;
        if ( fn.nargs > 2 && fn.arg(2).to_string() == "GET" ) post = false;
 
-       //log_debug("LoadVars.sendAndLoad(%s, %p) called, and returning TRUE", 
urlstr.c_str(), target.get());
-
        ptr->sendAndLoad(urlstr, *target, post);
        return as_value(true);
 }

=== modified file 'libcore/asobj/LoadableObject.cpp'
--- a/libcore/asobj/LoadableObject.cpp  2008-09-24 15:46:40 +0000
+++ b/libcore/asobj/LoadableObject.cpp  2008-09-29 08:40:24 +0000
@@ -76,9 +76,6 @@
     /// All objects get a loaded member, set to false.
     target.set_member(NSV::PROP_LOADED, false);
 
-    std::ostringstream data;
-    toString(data);
-
        URL url(urlstr, get_base_url());
 
        std::auto_ptr<IOChannel> str;
@@ -133,14 +130,26 @@
                         contentType.to_string()));
         }
 
+        // Convert the object to a string to send. XML should
+        // not be URL encoded for the POST method, LoadVars
+        // is always URL encoded.
+        std::ostringstream data;
+        toString(data, false);
+
         /// It doesn't matter if there are no request headers.
         str = StreamProvider::getDefaultInstance().getStream(url,
                                                     data.str(), headers);
     }
        else
     {
-       std::string url = urlstr + "?" + data.str();
-        str = StreamProvider::getDefaultInstance().getStream(url);
+        // Convert the object to a string to send. XML should
+        // not be URL encoded for the GET method.
+        std::ostringstream data;
+        toString(data, true);
+
+       std::string getURL = urlstr + "?" + data.str();
+        log_debug("Using GET method for sendAndLoad: %s", getURL);
+        str = StreamProvider::getDefaultInstance().getStream(getURL);
     }
 
        if (!str.get()) 

=== modified file 'libcore/asobj/LoadableObject.h'
--- a/libcore/asobj/LoadableObject.h    2008-09-19 09:41:54 +0000
+++ b/libcore/asobj/LoadableObject.h    2008-09-29 08:40:24 +0000
@@ -55,9 +55,8 @@
     ///                 This function checks for permission to load the URL.
     /// @param target   An as_object to load the data into using queueLoad,
     ///                 which only LoadableObjects should have.
-    /// @param post     If true (default), POSTs data, otherwise GET.
-    void sendAndLoad(const std::string& urlstr,
-                     as_object& target, bool post = true);
+    /// @param post     If true, POSTs data, otherwise GET.
+    void sendAndLoad(const std::string& urlstr, as_object& target, bool post);
 
     /// Carry out the AS load operation
     //
@@ -82,7 +81,12 @@
 
 protected:
 
-    virtual void toString(std::ostream& o) const = 0;
+    /// Convert the Loadable Object to a string.
+    //
+    /// @param o        The ostream to write the string to.
+    /// @param encode   Whether URL encoding is necessary. How this
+    ///                 is done depends on the type of object.
+    virtual void toString(std::ostream& o, bool encode) const = 0;
 
     typedef std::list<LoadThread*> LoadThreadList;
 

=== modified file 'libcore/asobj/XML_as.cpp'
--- a/libcore/asobj/XML_as.cpp  2008-09-24 15:46:40 +0000
+++ b/libcore/asobj/XML_as.cpp  2008-09-29 08:40:24 +0000
@@ -648,6 +648,8 @@
 /// success of the connection is irrelevant.
 /// The second argument must be an object, but does not have to 
 /// be an XML object.
+/// An optional third argument specifies the method ("GET", or by default
+/// "POST"). The XML node values are partly URL encoded if using GET.
 static as_value
 xml_sendAndLoad(const fn_call& fn)
 {
@@ -682,7 +684,13 @@
     boost::intrusive_ptr<as_object> targetObj = fn.arg(1).to_object();
     assert(targetObj);
 
-    ptr->sendAndLoad(filespec, *targetObj);
+       // Post by default, override by ActionScript third argument. This isn't
+       // documented, but it is possible to send XML objects by the GET method,
+       // exactly like LoadVars.
+       bool post = true;
+       if ( fn.nargs > 2 && fn.arg(2).to_string() == "GET" ) post = false;
+
+    ptr->sendAndLoad(filespec, *targetObj, post);
 
     return as_value(true);
 }

=== modified file 'libcore/asobj/XML_as.h'
--- a/libcore/asobj/XML_as.h    2008-09-19 09:41:54 +0000
+++ b/libcore/asobj/XML_as.h    2008-09-29 08:40:24 +0000
@@ -80,9 +80,14 @@
     XML_as(const std::string& xml_in);
     ~XML_as() {};
 
-    void toString(std::ostream& o) const
+    /// Convert the XML object to a string
+    //
+    /// This calls XMLNode::toString.
+    /// @param o        The ostream to write the string to.
+    /// @param encode   Whether to URL encode the node values.
+    void toString(std::ostream& o, bool encode) const
     {
-        XMLNode::toString(o);
+        XMLNode::toString(o, encode);
     }
 
     /// This is overridden to provide the 'status' and 'loaded' members,

=== modified file 'libcore/asobj/xmlnode.cpp'
--- a/libcore/asobj/xmlnode.cpp 2008-09-24 15:46:40 +0000
+++ b/libcore/asobj/xmlnode.cpp 2008-09-29 08:40:24 +0000
@@ -265,24 +265,22 @@
 }
 
 void
-XMLNode::toString(std::ostream& xmlout) const
+XMLNode::toString(std::ostream& xmlout, bool encode) const
 {
-//    GNASH_REPORT_FUNCTION;
-    stringify(*this, xmlout);
+    log_debug("XMLNode toString: encode %d");
+    stringify(*this, xmlout, encode);
 }
 
 /* static private */
 void
-XMLNode::stringify(const XMLNode& xml, std::ostream& xmlout) 
+XMLNode::stringify(const XMLNode& xml, std::ostream& xmlout, bool encode) 
 {
-//    GNASH_REPORT_FUNCTION;
+
     const std::string& nodevalue = xml.nodeValue();
     const std::string& nodename = xml.nodeName();
     NodeType type = xml.nodeType();
 
 
-//    log_debug("%s: processing for object %s <%p>", __PRETTY_FUNCTION__, 
nodename, xml);
-
 #ifdef GNASH_DEBUG
     log_debug(_("Stringifying node %p with name %s, value %s, %u attributes 
and %u children"),
                     (void*)&xml, nodename, nodevalue, xml._attributes.size(), 
xml._children.size());
@@ -298,7 +296,6 @@
         for (ita = xml._attributes.begin(); ita != xml._attributes.end(); 
ita++)
         {
             const XMLAttr& xa = *ita;
-            // TODO: replace with XMLAttr::operator<<
             xmlout << " " << xa.name() << "=\"" << xa.value() << "\"";
         }
 
@@ -319,16 +316,14 @@
     // Node value first, then children
     if ( type == tText )
     {
-           xmlout << nodevalue;
+           encode ? xmlout << URL::encode(nodevalue) : xmlout << nodevalue;
     }
 
     // Childs, after node value.
     ChildList::const_iterator itx;
     for (itx = xml._children.begin(); itx != xml._children.end(); itx++)
     {
-//      log_debug(_("Found One XMLNode child.  %s <%p>"), 
(*itx)->nodeName().c_str(), (void*)*itx);
-//      cerr << "<" << (*it)->nodeName() << ">" << endl;
-        (*itx)->toString(xmlout);
+        (*itx)->toString(xmlout, encode);
     }
 
     if ( nodename.size() )

=== modified file 'libcore/asobj/xmlnode.h'
--- a/libcore/asobj/xmlnode.h   2008-09-19 10:24:02 +0000
+++ b/libcore/asobj/xmlnode.h   2008-09-29 08:40:24 +0000
@@ -208,9 +208,13 @@
     ///
     void removeNode();
 
-    void toString(std::ostream& str) const;
-
-    //void  change_stack_frame(int frame, gnash::as_object *xml, 
gnash::as_environment *env);
+    /// Convert the XMLNode to a string
+    //
+    /// @param o        The ostream to write the string to.
+    /// @param encode   Whether to URL encode the node values. This
+    ///                 is false by default, as it is only necessary
+    ///                 for XML.sendAndLoad.
+    void toString(std::ostream& str, bool encode = false) const;
 
     // We might turn this back to a dumb pointer, as long
     // as we'll make sure in the XMLNode destructor and
@@ -244,7 +248,7 @@
 
     NodeType     _type;
 
-    static void stringify(const XMLNode& xml, std::ostream& xmlout);
+    static void stringify(const XMLNode& xml, std::ostream& xmlout, bool 
encode);
 
 };
 


reply via email to

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