gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10081: It is possible for the hostn


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10081: It is possible for the hostname to be empty for network connections, and
Date: Fri, 24 Oct 2008 18:46:27 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10081
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2008-10-24 18:46:27 +0200
message:
  It is possible for the hostname to be empty for network connections, and
  we don't want to abort.
modified:
  libbase/URL.cpp
  libcore/URLAccessManager.cpp
=== modified file 'libbase/URL.cpp'
--- a/libbase/URL.cpp   2008-07-23 17:08:27 +0000
+++ b/libbase/URL.cpp   2008-10-24 16:46:27 +0000
@@ -50,8 +50,6 @@
 #include <climits>
 #include <boost/tokenizer.hpp>
 
-using namespace std;
-
 namespace gnash {
 
 /*private*/
@@ -59,8 +57,8 @@
 URL::init_absolute(const std::string& in)
 {
        // Find protocol
-       string::size_type pos = in.find("://");
-       if ( pos != string::npos )
+    std::string::size_type pos = in.find("://");
+       if ( pos != std::string::npos )
        {
                // copy initial part to protocol
                _proto = in.substr(0, pos);
@@ -74,8 +72,8 @@
                }
 
                // Find host 
-               string::size_type pos1 = in.find('/', pos);
-               if ( pos1 == string::npos )
+        std::string::size_type pos1 = in.find('/', pos);
+               if ( pos1 == std::string::npos )
                {
                        // no slashes ? all hostname, I presume
                        _host = in.substr(pos);
@@ -84,7 +82,7 @@
                }
 
                // copy hostname
-                _host = in.substr(pos, pos1-pos);
+        _host = in.substr(pos, pos1-pos);
                 
                // next come path
                _path = in.substr(pos1);
@@ -111,7 +109,7 @@
 {
        //cerr << "URL(" << absolute_url << ")" << endl;
        if ( ( absolute_url.size() && absolute_url[0] == '/' )
-               || absolute_url.find("://") != string::npos 
+               || absolute_url.find("://") != std::string::npos 
                || ( absolute_url.size() > 1 && absolute_url[1] == ':' ))       
//for win32
        {
                //cerr << "It's absolute" << endl;
@@ -124,7 +122,7 @@
                char buf[PATH_MAX+1];
                if ( ! getcwd(buf, PATH_MAX) )
                {
-                       stringstream err;
+            std::stringstream err;
                        err << "getcwd failed: " << strerror(errno);
                        throw gnash::GnashException(err.str());
                }
@@ -158,19 +156,16 @@
 
        assert(path[0] == '/');
 
-
-       //cerr << "path=" << path << endl;
-
-       vector<string> components;
-
-       string::iterator prev=path.begin();
-       for (string::iterator curr=prev+1;
+    std::vector<std::string> components;
+
+    std::string::iterator prev=path.begin();
+       for (std::string::iterator curr = prev + 1;
                        curr != path.end();
                        ++curr )
        {
                if ( *curr == '/')
                {
-                       string comp = string(prev+1, curr);
+            std::string comp = std::string(prev+1, curr);
                        //cerr << "comp:" << comp << endl;
                        prev = curr;
 
@@ -181,19 +176,16 @@
                }
        }
        // add last component 
-       components.push_back(string(prev+1, path.end()));
+       components.push_back(std::string(prev+1, path.end()));
 
-       //cerr << "number of dir components:" << components.size() << endl;
        path = "";
-       for (vector<string>::iterator i=components.begin(),
+       for (std::vector<std::string>::const_iterator i=components.begin(),
                        e=components.end();
                        i!=e; ++i)
        {
                path += "/" + *i;
-               //cerr << "component:" << *i << endl;
        }
 
-       //cerr << "after normalization: path=" << path << endl;
 }
 
 /*public*/
@@ -206,53 +198,44 @@
 void
 URL::init_relative(const std::string& relative_url, const URL& baseurl)
 {
+
        // If relative url starts with an hash, it's just
        // an anchor change
        if ( relative_url[0] == '#' )
        {
                _proto = baseurl._proto;
                _host = baseurl._host;
-                _port= baseurl._port;
+        _port= baseurl._port;
                _path = baseurl._path;
                _anchor = relative_url.substr(1);
                return;
        }
 
        // If has a protocol, call absolute_url ctor
-       if ( relative_url.find("://") != string::npos )
+       if ( relative_url.find("://") != std::string::npos )
        {
                init_absolute(relative_url);
                return;
        }
 
-//fprintf(stderr, " input=%s\n", in.c_str());
-
        // use protocol and host from baseurl
        _proto = baseurl._proto;
        _host = baseurl._host;
 
-        // 
-#if 0 // check moved to StreamProvider
-         if (!host_check(_host)) {
-             return;
-         }
-#endif
-
        if ( relative_url.size() && relative_url[0] == '/' ) 
        {
                // get path from here
-               //_path.assign(in, strlen(in));
                _path = relative_url;
        }
 
        else // path-relative
        {
-               string in = relative_url;
+               std::string in = relative_url;
 
                // see how many dirs we want to take
                // off the baseurl path
                int dirsback=0;
-               string::size_type pos;
+               std::string::size_type pos;
                while ( ( pos = in.find("../") ) == 0 ) 
                {
                        ++dirsback;
@@ -264,11 +247,9 @@
                        in = in.substr(pos);
                }
 
-//fprintf(stderr, "dirsback=%d, in=%s\n", dirsback, in.c_str());
-
                // find dirsback'th slash from end of
                // baseurl path
-               string basedir = baseurl._path.substr(0,
+               std::string basedir = baseurl._path.substr(0,
                        baseurl._path.find_last_of("/")+1);
 
                // for WIN32
@@ -278,8 +259,6 @@
                                baseurl._path.find_last_of("\\")+1);
                }
 
-//fprintf(stderr, "basedir=%s\n", basedir.c_str());
-
                assert(basedir[0] == '/'
                        || basedir[1] == ':');  // for WIN32
 #ifndef __OS2__
@@ -287,14 +266,13 @@
                assert(*(basedir.rbegin()) == '/' 
                        || *(basedir.rbegin()) == '\\');        // for WIN32
 #endif
-               string::size_type lpos =  basedir.size()-1;
+        std::string::size_type lpos =  basedir.size()-1;
                for (int i=0; i<dirsback; ++i)
                {
                        if ( lpos == 0 ) break;
-                       string::size_type pos = basedir.rfind('/', lpos-1);
-//fprintf(stderr, "slash %d at offset %d (rfind from %d)\n", i, pos, lpos-1);
+                       std::string::size_type pos = basedir.rfind('/', lpos-1);
                        // no more slashes found, break and set at 1
-                       if ( pos == string::npos ) lpos = 1;
+                       if ( pos == std::string::npos ) lpos = 1;
                        else lpos = pos;
                }
                basedir.resize(lpos+1);
@@ -316,10 +294,10 @@
 }
 
 /*public*/
-string
+std::string
 URL::str() const
 {
-        string ret = _proto + "://" + _host;
+        std::string ret = _proto + "://" + _host;
        if ( _port != "" )
        {
                ret += ":" + _port;
@@ -344,8 +322,8 @@
        assert(_anchor == "");
 
        // Extract anchor from path, if any
-       string::size_type hashpos = _path.find('#');
-       if ( hashpos != string::npos )
+       std::string::size_type hashpos = _path.find('#');
+       if ( hashpos != std::string::npos )
        {
                _anchor = _path.substr(hashpos+1);
                _path.erase(hashpos);
@@ -359,8 +337,8 @@
        assert(_port == "");
 
        // Extract anchor from path, if any
-       string::size_type hashpos = _host.find(':');
-       if ( hashpos != string::npos )
+       std::string::size_type hashpos = _host.find(':');
+       if ( hashpos != std::string::npos )
        {
                _port = _host.substr(hashpos+1);
                _host.erase(hashpos);
@@ -376,7 +354,7 @@
        // extract the parameters from the URL
 
        size_t qmpos = _path.find("?");
-       if (qmpos == string::npos)
+       if (qmpos == std::string::npos)
        {
                // no query string
                return;
@@ -411,11 +389,11 @@
        {
                const std::string& nameval = *tit;
 
-               string name;
-               string value;
+               std::string name;
+        std::string value;
 
                size_t eq = nameval.find("=");
-               if ( eq == string::npos )
+               if ( eq == std::string::npos )
                {
                        name = nameval;
                }
@@ -437,14 +415,14 @@
 void
 URL::encode(std::string& input)
 {
-       const string escapees = " \"#$%&+,/:;<=>address@hidden|}~";
-       const string hexdigits = "0123456789ABCDEF";
+       const std::string escapees = " \"#$%&+,/:;<=>address@hidden|}~";
+       const std::string hexdigits = "0123456789ABCDEF";
 
        for (unsigned int i=0;i<input.length(); i++)
        {
                unsigned c = input[i] & 0xFF;   // ensure value is 0-255 not -ve
 
-               if (c < 32 || c > 126 || escapees.find((char)c) != string::npos)
+               if (c < 32 || c > 126 || escapees.find((char)c) != 
std::string::npos)
                {
                        input[i] = '%';
                        input.insert(++i, hexdigits.substr(c >> 4, 1));
@@ -498,7 +476,7 @@
        }
 }
 
-ostream& operator<< (ostream& o, const URL& u)
+std::ostream& operator<< (std::ostream& o, const URL& u)
 {
        return o << u.str();
 }

=== modified file 'libcore/URLAccessManager.cpp'
--- a/libcore/URLAccessManager.cpp      2008-05-06 11:14:35 +0000
+++ b/libcore/URLAccessManager.cpp      2008-10-24 16:46:27 +0000
@@ -295,7 +295,11 @@
        // in a directory listed as local sandbox
        if (host.size() == 0)
        {
-               assert(url.protocol() == "file");
+               if (url.protocol() != "file")
+        {
+            log_error(_("Network connection without hostname requested"));
+            return false;
+        }
                return local_check(url.path());
        }
        return host_check(host);


reply via email to

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