[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/URL.cpp libbase/URL.h t...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/URL.cpp libbase/URL.h t... |
Date: |
Sat, 02 Sep 2006 14:28:35 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 06/09/02 14:28:35
Modified files:
. : ChangeLog
libbase : URL.cpp URL.h
testsuite/libbase: URLTest.cpp
Log message:
* libbase/URL.{cpp,h}, testsuite/libbase/URLTest.cpp:
added support for query strings (+tests).
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.806&r2=1.807
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/URL.cpp?cvsroot=gnash&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/URL.h?cvsroot=gnash&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libbase/URLTest.cpp?cvsroot=gnash&r1=1.6&r2=1.7
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.806
retrieving revision 1.807
diff -u -b -r1.806 -r1.807
--- ChangeLog 2 Sep 2006 12:27:14 -0000 1.806
+++ ChangeLog 2 Sep 2006 14:28:35 -0000 1.807
@@ -1,5 +1,7 @@
2006-09-02 Sandro Santilli <address@hidden>
+ * libbase/URL.{cpp,h}, testsuite/libbase/URLTest.cpp:
+ added support for query strings (+tests).
* server/swf/ASHandlers.cpp (ActionGetUrl2): log a warning
when an undefined url parameter is on the stack.
* server/as_value.h: added is_undefined() method.
Index: libbase/URL.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/URL.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- libbase/URL.cpp 1 Sep 2006 10:24:58 -0000 1.20
+++ libbase/URL.cpp 2 Sep 2006 14:28:35 -0000 1.21
@@ -116,6 +116,8 @@
// Extract anchor from path, if any
split_anchor_from_path();
+ split_querystring_from_path();
+
#if ! (defined(_WIN32) || defined(WIN32))
assert ( _path[0] == '/');
normalize_path(_path);
@@ -302,6 +304,8 @@
split_anchor_from_path();
+ split_querystring_from_path();
+
normalize_path(_path);
}
@@ -313,6 +317,14 @@
URL::str() const
{
string ret = _proto + "://" + _host + _path;
+ if ( _querystring != "" )
+ {
+ ret += "?" + _querystring;
+ }
+ if ( _anchor != "" )
+ {
+ ret += "#" + _anchor;
+ }
return ret;
}
@@ -331,6 +343,60 @@
}
}
+/*private*/
+void
+URL::split_querystring_from_path()
+{
+ assert(_querystring == "");
+
+ // extract the parameters from the URL
+
+ size_t qmpos = _path.rfind("?");
+ if (qmpos == string::npos)
+ {
+ // no query string
+ return;
+ }
+
+ _querystring = _path.substr(qmpos+1);
+
+ // update _path
+ _path.erase(qmpos);
+
+}
+
+/* public static */
+void
+URL::parse_querystring(const std::string& query_string,
+ std::map<std::string, std::string>& target_map)
+{
+ size_t start = 0;
+ if ( query_string[0] == '?' ) start = 1;
+
+ size_t end = query_string.size();
+ while ( start < end )
+ {
+ size_t eq = query_string.find("=", start);
+ if ( eq == string::npos )
+ {
+ break; // no point of keepign a var
+ }
+
+ size_t amp=query_string.find("&", start);
+ if ( amp == string::npos ) {
+ amp = end;
+ }
+
+ string name = query_string.substr(start, eq-start);
+ string value = query_string.substr(eq+1, amp-(eq+1));
+
+ target_map[name] = value;
+
+ start = amp+1;
+
+ }
+}
+
ostream& operator<< (ostream& o, const URL& u)
{
return o << u.str();
Index: libbase/URL.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/URL.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- libbase/URL.h 1 Sep 2006 10:24:58 -0000 1.9
+++ libbase/URL.h 2 Sep 2006 14:28:35 -0000 1.10
@@ -46,6 +46,7 @@
#include <iosfwd>
#include <string>
#include <fstream>
+#include <map>
namespace gnash {
@@ -94,13 +95,31 @@
///
std::string anchor() const { return _anchor; }
+ /// Return the 'querystring' member of this URL, as a string
+ //
+ /// The query is the string after the '?' character
+ ///
+ std::string querystring() const { return _querystring; }
+
/// Return the full absolute URL as a string.
//
/// TODO: make output operator and operator+ for strings
std::string str() const;
- // check moved to StreamProvider (AccessManager)
- //bool host_check(std::string host);
+ /// Parse a query string filling the provided map
+ //
+ /// @param query_string
+ /// the url-escaped query string
+ /// (can include or not the starting question mark)
+ ///
+ /// @param target_map
+ /// A standard map to put parsed values into.
+ /// Note: existing elements of the map will be replaced.
+ ///
+ /// @todo url-unescape names and values
+ ///
+ static void parse_querystring(const std::string& query_string,
+ std::map<std::string, std::string>& target_map);
private:
void init_absolute(const std::string& absurl);
@@ -109,6 +128,9 @@
/// Extract anchor from path
void split_anchor_from_path();
+ /// Extract and parse query string from path
+ void split_querystring_from_path();
+
/// Normalize a 'path' component of an url
//
/// Normalization currently include removal
@@ -125,6 +147,7 @@
std::string _anchor;
+ std::string _querystring;
};
std::ostream& operator<< (std::ostream&o, const URL& u);
Index: testsuite/libbase/URLTest.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libbase/URLTest.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- testsuite/libbase/URLTest.cpp 1 Sep 2006 10:24:58 -0000 1.6
+++ testsuite/libbase/URLTest.cpp 2 Sep 2006 14:28:35 -0000 1.7
@@ -147,18 +147,55 @@
URL u9("/the/path#the_anchor");
check_equals (u9.path(), "/the/path");
check_equals (u9.anchor(), "the_anchor");
+ check_equals (u9.str(), "file:///the/path#the_anchor");
URL u10("http://host/the/path#the_anchor");
check_equals (u10.hostname(), "host");
check_equals (u10.path(), "/the/path");
check_equals (u10.anchor(), "the_anchor");
+ check_equals (u10.str(), "http://host/the/path#the_anchor");
URL u11("#another_anchor", u10);
check_equals (u11.hostname(), "host");
check_equals (u11.path(), "/the/path");
check_equals (u11.anchor(), "another_anchor");
+ check_equals (u11.str(), "http://host/the/path#another_anchor");
URL u12("#", u10);
check_equals (u12.hostname(), "host");
check_equals (u12.path(), "/the/path");
check_equals (u12.anchor(), "");
+ check_equals (u12.str(), "http://host/the/path");
+
+ /// Test url with QUERY STRING
+ URL u13("http://localhost/?M=A");
+ check_equals (u13.hostname(), "localhost");
+ check_equals (u13.path(), "/");
+ check_equals (u13.protocol(), "http");
+ check_equals (u13.anchor(), "");
+ check_equals (u13.querystring(), "M=A");
+ check_equals (u13.str(), "http://localhost/?M=A");
+ URL u14("/?M=A&C=D");
+ check_equals (u14.querystring(), "M=A&C=D");
+ check_equals (u14.str(), "file:///?M=A&C=D");
+ URL u15("/?M=A&C=D#anchor");
+ check_equals (u15.querystring(), "M=A&C=D");
+ check_equals (u15.anchor(), "anchor");
+ check_equals (u15.str(), "file:///?M=A&C=D#anchor");
+ URL u16("/my/path/?option1=23&option2=65#anchor");
+ check_equals (u16.querystring(), "option1=23&option2=65");
+ check_equals (u16.anchor(), "anchor");
+ check_equals (u16.str(),
"file:///my/path/?option1=23&option2=65#anchor");
+
+ // Test query_string parsing
+ map<string, string> qs;
+ URL::parse_querystring(u13.querystring(), qs);
+ check_equals (qs["M"], "A");
+ check_equals (qs["C"], "");
+ URL::parse_querystring(u14.querystring(), qs);
+ check_equals (qs["M"], "A");
+ check_equals (qs["C"], "D");
+ URL::parse_querystring(u16.querystring(), qs);
+ check_equals (qs["option1"], "23");
+ check_equals (qs["option2"], "65");
+
// TODO: Samba paths
}