[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...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ./ChangeLog libbase/URL.cpp libbase/URL.h... |
Date: |
Mon, 15 May 2006 12:09:53 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch:
Changes by: Sandro Santilli <address@hidden> 06/05/15 12:09:53
Modified files:
. : ChangeLog
libbase : URL.cpp URL.h
testsuite/libbase: URLTest.cpp
Log message:
Removed use of <cstring>, throw std::runtime_error on malformed urls,
changed 'file' urls to always start with 'file:///' (3 slashes, 2 for
proto,
1 for rootdir)
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/ChangeLog.diff?tr1=1.321&tr2=1.322&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/libbase/URL.cpp.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/libbase/URL.h.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/testsuite/libbase/URLTest.cpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: gnash/ChangeLog
diff -u gnash/ChangeLog:1.321 gnash/ChangeLog:1.322
--- gnash/ChangeLog:1.321 Mon May 15 11:16:50 2006
+++ gnash/ChangeLog Mon May 15 12:09:53 2006
@@ -2,9 +2,10 @@
* libbase/URL.{cpp,h}: refactored path normalization procedure
to split path in components, remove unneeded ones and
- resolve back-references.
+ resolve back-references, removed all uses of <cstring>
* testsuite/libbase/URLTest.cpp: added check.as-like macros,
- new tests for path normalization.
+ new tests for path normalization, changed expected paths
+ for 'file' urls to always start with three slashes (file:///)
2006-05-14 Rob Savoye <address@hidden>
Index: gnash/libbase/URL.cpp
diff -u gnash/libbase/URL.cpp:1.6 gnash/libbase/URL.cpp:1.7
--- gnash/libbase/URL.cpp:1.6 Mon May 15 11:16:50 2006
+++ gnash/libbase/URL.cpp Mon May 15 12:09:53 2006
@@ -44,10 +44,11 @@
#include "URL.h"
#include <string>
-#include <cstring>
+//#include <cstring>
#include <vector>
#include <stdexcept>
#include <cassert>
+#include <sstream>
#include <algorithm>
// these are for stat(2)
@@ -63,49 +64,46 @@
/*private*/
void
-URL::init_absolute(const char* in)
+URL::init_absolute(const string& in)
{
- size_t len = strlen(in);
- const char* last = in+len;
-
- assert(*last==0);
-
// Find protocol
- char* ptr = strstr(in, "://");
- if ( ptr )
+ string::size_type pos = in.find("://");
+ if ( pos != string::npos )
{
// copy initial part to protocol
- _proto.assign(in, ptr-in);
+ _proto = in.substr(0, pos);
// advance input pointer to past the :// part
- in = ptr+3;
-
+ pos += 3;
+ if ( pos == in.size() )
+ {
+ std::cerr << "protocol-only url!" << std::endl;
+ throw runtime_error("protocol-only url");
+ }
- // Find host (only if not 'file' protocol
- ptr = strchr(in, '/');
- if ( ! ptr )
+ // Find host
+ string::size_type pos1 = in.find('/', pos);
+ if ( pos1 == string::npos )
{
// no slashes ? all hostname, I presume
- _host.assign(in, last-in);
+ _host = in.substr(pos);
+ _path = "/";
+ return;
}
- else
- {
- // copy hostname
- _host.assign(in, ptr-in);
- // advance input pointer to the path
- in = ptr;
- }
+ // copy hostname
+ _host = in.substr(pos, pos1-pos);
+
+ // next come path
+ _path = in.substr(pos1);
}
else
{
_proto = "file";
+ _path = in;
}
- assert ( *in == '/' );
-
- // What remains now is a path
- _path.assign(in, last-in);
+ assert ( _path[0] == '/' );
normalize_path(_path);
}
@@ -114,19 +112,25 @@
URL::URL(const string& absolute_url)
{
//cerr << "URL(" << absolute_url << ")" << endl;
- if ( absolute_url[0] == '/'
+ if ( ( absolute_url.size() && absolute_url[0] == '/' )
|| absolute_url.find("://") != string::npos )
{
//cerr << "It's absolute" << endl;
- init_absolute(absolute_url.c_str());
+ init_absolute(absolute_url);
}
else
{
//cerr << "It's relative" << endl;
char buf[PATH_MAX+1];
- getcwd(buf, PATH_MAX);
+ if ( ! getcwd(buf, PATH_MAX) )
+ {
+ stringstream err;
+ err << "getcwd failed: " << strerror(errno);
+ throw std::runtime_error(err.str());
+ }
char* ptr = buf+strlen(buf);
- *ptr++ = '/';
+ *ptr = '/';
+ ++ptr;
*ptr = '\0';
URL cwd(buf);
init_relative(absolute_url, cwd);
@@ -197,7 +201,7 @@
// If has a protocol, call absolute_url ctor
if ( relative_url.find("://") != string::npos )
{
- init_absolute(relative_url.c_str());
+ init_absolute(relative_url);
return;
}
@@ -207,7 +211,7 @@
_proto = baseurl._proto;
_host = baseurl._host;
- if ( relative_url[0] == '/' ) // path-absolute
+ if ( relative_url.size() && relative_url[0] == '/' )
{
// get path from here
//_path.assign(in, strlen(in));
@@ -271,16 +275,7 @@
string
URL::str() const
{
- string ret = _proto;
-
- if ( _host != "" ) {
- ret += "://" + _host;
- } else {
- // it's a local filename
- ret += ":/" + _host;
- }
- ret += _path;
-
+ string ret = _proto + "://" + _host + _path;
return ret;
}
Index: gnash/libbase/URL.h
diff -u gnash/libbase/URL.h:1.4 gnash/libbase/URL.h:1.5
--- gnash/libbase/URL.h:1.4 Mon May 15 11:16:50 2006
+++ gnash/libbase/URL.h Mon May 15 12:09:53 2006
@@ -94,7 +94,7 @@
private:
- void init_absolute(const char* absurl);
+ void init_absolute(const std::string& absurl);
void init_relative(const std::string& relurl, const URL& baseurl);
Index: gnash/testsuite/libbase/URLTest.cpp
diff -u gnash/testsuite/libbase/URLTest.cpp:1.4
gnash/testsuite/libbase/URLTest.cpp:1.5
--- gnash/testsuite/libbase/URLTest.cpp:1.4 Mon May 15 11:16:50 2006
+++ gnash/testsuite/libbase/URLTest.cpp Mon May 15 12:09:53 2006
@@ -81,7 +81,7 @@
check_equals_label(label, u.protocol(), "file");
check_equals_label(label, u.hostname(), "");
check_equals_label(label, u.path(), "/etc/hosts");
- check_equals_label(label, u.str(), "file://etc/hosts");
+ check_equals_label(label, u.str(), "file:///etc/hosts");
/// Test relative filename
URL u1("passwd", u);
@@ -89,7 +89,7 @@
check_equals_label(label, u1.protocol(), "file" );
check_equals_label(label, u1.hostname(), "" );
check_equals_label(label, u1.path(), "/etc/passwd" );
- check_equals_label(label, u1.str(), "file://etc/passwd" );
+ check_equals_label(label, u1.str(), "file:///etc/passwd" );
/// Test proto-host relative filename
URL u2("/", u);
@@ -97,7 +97,7 @@
check_equals_label (label, u2.protocol() , "file" );
check_equals_label (label, u2.hostname() , "" );
check_equals_label (label, u2.path() , "/" );
- check_equals_label (label, u2.str() , "file://" );
+ check_equals_label (label, u2.str() , "file:///" );
/// Test https url
URL u3("https://www.fake.it/path.swf");