Show
Ignore:
Timestamp:
03/10/09 13:21:13 (5 years ago)
Author:
robert
Message:

From Stephan Huber,
"Attached you'll find a proposal for using different
protocols. The idea behind the new code is:

1.) plugins/apps register protocols which they can handle. This is done
via osgDB::Registry::registerProtocol(aProtocolName). Plugins register
supported protocols as usual via ReaderWriter::supportsProtocol(..), the
Registry is updated accordingly.

2.) osgDB::containsServerAddress checks first for an appearance of "://"
in the filename and then checks the protocol against the set of
registered protocols via Registry::isProtocolRegistered(aProtocollName)

3.) the other getServer*-functions changed as well, there's even a
getServerProtocol-function

With these changes filenames/Urls get routed to loaded plugins even with
different protocols than 'http'."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgDB/FileNameUtils.cpp

    r8912 r9884  
    180180} 
    181181 
     182 
     183 
    182184bool osgDB::containsServerAddress(const std::string& filename) 
    183185{ 
    184     // need to check for http:// 
    185     if (filename.size()<7) return false; 
    186     if (filename.compare(0,7,"http://")==0) return true; 
    187     return false; 
     186    // need to check for :// 
     187    std::string::size_type pos(filename.find_first_of("://")); 
     188    if (pos == std::string::npos)  
     189        return false; 
     190    std::string proto(filename.substr(0, pos)); 
     191     
     192    return Registry::instance()->isProtocolRegistered(proto); 
     193} 
     194 
     195std::string osgDB::getServerProtocol(const std::string& filename) 
     196{ 
     197    std::string::size_type pos(filename.find_first_of("://")); 
     198    if (pos != std::string::npos) 
     199        return filename.substr(0,pos); 
     200 
     201    return ""; 
    188202} 
    189203 
    190204std::string osgDB::getServerAddress(const std::string& filename) 
    191205{ 
    192     if (filename.size()>=7 && filename.compare(0,7,"http://")==0) 
    193     { 
    194         std::string::size_type pos_slash = filename.find_first_of('/',7); 
     206    std::string::size_type pos(filename.find_first_of("://")); 
     207     
     208    if (pos != std::string::npos) 
     209    { 
     210        std::string::size_type pos_slash = filename.find_first_of('/',pos+3); 
    195211        if (pos_slash!=std::string::npos) 
    196212        { 
    197             return filename.substr(7,pos_slash-7); 
     213            return filename.substr(pos+3,pos_slash-pos-3); 
    198214        } 
    199215        else 
    200216        { 
    201             return filename.substr(7,std::string::npos); 
     217            return filename.substr(pos+3,std::string::npos); 
    202218        } 
    203219    } 
     
    207223std::string osgDB::getServerFileName(const std::string& filename) 
    208224{ 
    209     if (filename.size()>=7 && filename.compare(0,7,"http://")==0) 
    210     { 
    211         std::string::size_type pos_slash = filename.find_first_of('/',7); 
     225    std::string::size_type pos(filename.find_first_of("://")); 
     226 
     227    if (pos != std::string::npos) 
     228    { 
     229        std::string::size_type pos_slash = filename.find_first_of('/',pos+3); 
    212230        if (pos_slash!=std::string::npos) 
    213231        {