Changeset 8619
- Timestamp:
- 07/17/08 13:55:55
- Files:
-
- OpenSceneGraph/trunk/include/osgDB/ReaderWriter (modified) (4 diffs)
- OpenSceneGraph/trunk/include/osgDB/Registry (modified) (2 diffs)
- OpenSceneGraph/trunk/src/osgDB/ReaderWriter.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/src/osgPlugins/curl/ReaderWriterCURL.cpp (modified) (3 diffs)
- OpenSceneGraph/trunk/src/osgPlugins/curl/ReaderWriterCURL.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph/trunk/include/osgDB/ReaderWriter
r8582 r8619 33 33 typedef std::deque<std::string> FilePathList; 34 34 35 class AuthenticationDetails : public osg::Referenced 36 { 37 public: 38 39 /** Http authentication techniques, see libcurl docs for details on names and associated functionality.*/ 40 enum HttpAuthentication 41 { 42 BASIC = 1<<0, 43 DIGEST = 1<<1, 44 NTLM = 1<<2, 45 GSSNegotiate = 1<<2, 46 ANY = ~0, 47 ANYSAFE = ~BASIC 48 }; 49 50 AuthenticationDetails(const std::string& u, const std::string& p, HttpAuthentication auth=BASIC): 51 username(u), 52 password(p), 53 httpAuthentication(auth) {} 54 55 std::string username; 56 std::string password; 57 HttpAuthentication httpAuthentication; 58 59 protected: 60 virtual ~AuthenticationDetails() {} 61 }; 62 63 class OSGDB_EXPORT AuthenticationMap : public osg::Referenced 64 { 65 public: 66 67 AuthenticationMap() {} 68 69 70 virtual void addAuthenticationDetails(const std::string& path, AuthenticationDetails* details); 71 72 virtual const AuthenticationDetails* getAuthenticationDetails(const std::string& path) const; 73 74 protected: 75 76 virtual ~AuthenticationMap() {} 77 78 typedef std::map<std::string, osg::ref_ptr<AuthenticationDetails> > AuthenticationDetailsMap; 79 AuthenticationDetailsMap _authenticationMap; 80 81 }; 82 35 83 /** pure virtual base class for reading and writing of non native formats. */ 36 84 class OSGDB_EXPORT ReaderWriter : public osg::Object … … 160 208 161 209 210 /** Set the password map to be used by plugins when access files from secure locations.*/ 211 void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; } 212 213 /** Get the password map to be used by plugins when access files from secure locations.*/ 214 const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); } 215 162 216 163 217 /** Sets a plugindata value PluginData with a string */ … … 181 235 virtual ~Options() {} 182 236 183 std::string _str; 184 FilePathList _databasePaths; 185 CacheHintOptions _objectCacheHint; 186 BuildKdTreesHint _buildKdTreesHint; 237 std::string _str; 238 FilePathList _databasePaths; 239 CacheHintOptions _objectCacheHint; 240 BuildKdTreesHint _buildKdTreesHint; 241 osg::ref_ptr<AuthenticationMap> _authenticationMap; 187 242 188 243 typedef std::map<std::string,void*> PluginDataMap; … … 248 303 std::string _message; 249 304 osg::ref_ptr<osg::Object> _object; 305 250 306 }; 251 307 OpenSceneGraph/trunk/include/osgDB/Registry
r8582 r8619 335 335 336 336 337 /** Set whether the KdTrees should be built for geometry in the loader model. */ 337 338 void setBuildKdTreesHint(ReaderWriter::Options::BuildKdTreesHint hint) { _buildKdTreesHint = hint; } 339 340 /** Get whether the KdTrees should be built for geometry in the loader model. */ 338 341 ReaderWriter::Options::BuildKdTreesHint getBuildKdTreesHint() const { return _buildKdTreesHint; } 339 342 343 /** Set the KdTreeBuilder visitor that is used to build KdTree on loaded models.*/ 340 344 void setKdTreeBuilder(osg::KdTreeBuilder* builder) { _kdTreeBuilder = builder; } 345 346 /** Get the KdTreeBuilder visitor that is used to build KdTree on loaded models.*/ 341 347 osg::KdTreeBuilder* getKdTreeBuilder() { return _kdTreeBuilder.get(); } 348 349 350 /** Set the password map to be used by plugins when access files from secure locations.*/ 351 void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; } 352 353 /** Get the password map to be used by plugins when access files from secure locations.*/ 354 const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); } 342 355 343 356 344 357 void setCreateNodeFromImage(bool flag) { _createNodeFromImage = flag; } 345 358 bool getCreateNodeFromImage() const { return _createNodeFromImage; } 346 359 347 360 348 361 void setOptions(ReaderWriter::Options* opt) { _options = opt; } … … 478 491 ReaderWriter::Options::BuildKdTreesHint _buildKdTreesHint; 479 492 osg::ref_ptr<osg::KdTreeBuilder> _kdTreeBuilder; 493 494 osg::ref_ptr<AuthenticationMap> _authenticationMap; 480 495 481 496 bool _createNodeFromImage; OpenSceneGraph/trunk/src/osgDB/ReaderWriter.cpp
r8578 r8619 16 16 #include <osgDB/Archive> 17 17 18 #include <map> 19 18 20 using namespace osgDB; 21 22 /////////////////////////////////////////////////////////////////////////////////////////////////////// 23 // 24 // PasswordMap 25 // 26 27 void AuthenticationMap::addAuthenticationDetails(const std::string& path, AuthenticationDetails* details) 28 { 29 _authenticationMap[path] = details; 30 } 31 32 const AuthenticationDetails* AuthenticationMap::getAuthenticationDetails(const std::string& path) const 33 { 34 // see if the full filename has its own authentication details 35 AuthenticationDetailsMap::const_iterator itr = _authenticationMap.find(path); 36 if (itr != _authenticationMap.end()) return itr->second.get(); 37 38 // now look to see if the paths to the file have their own authentication details 39 std::string basePath = osgDB::getFilePath(path); 40 while(!basePath.empty()) 41 { 42 itr = _authenticationMap.find(basePath); 43 if (itr != _authenticationMap.end()) return itr->second.get(); 44 45 basePath = osgDB::getFilePath(basePath); 46 } 47 return 0; 48 } 49 50 /////////////////////////////////////////////////////////////////////////////////////////////////////// 51 // 52 // ReaderWriter 53 // 19 54 20 55 osg::Object* ReaderWriter::ReadResult::getObject() { return _object.get(); } OpenSceneGraph/trunk/src/osgPlugins/curl/ReaderWriterCURL.cpp
r8578 r8619 76 76 { 77 77 osg::notify(osg::INFO)<<"EasyCurl::EasyCurl()"<<std::endl; 78 79 _previousHttpAuthentication = 0; 78 80 79 81 _curl = curl_easy_init(); … … 93 95 94 96 95 osgDB::ReaderWriter::ReadResult EasyCurl::read(const std::string& proxyAddress, const std::string& fileName, StreamObject& sp) 96 { 97 osgDB::ReaderWriter::ReadResult EasyCurl::read(const std::string& proxyAddress, const std::string& fileName, StreamObject& sp, const osgDB::ReaderWriter::Options *options) 98 { 99 const osgDB::AuthenticationMap* authenticationMap = (options && options->getAuthenticationMap()) ? 100 options->getAuthenticationMap() : 101 osgDB::Registry::instance()->getAuthenticationMap(); 102 97 103 if(!proxyAddress.empty()) 98 104 { 99 osg::notify(osg:: NOTICE)<<"Setting proxy: "<<proxyAddress<<std::endl;105 osg::notify(osg::INFO)<<"Setting proxy: "<<proxyAddress<<std::endl; 100 106 curl_easy_setopt(_curl, CURLOPT_PROXY, proxyAddress.c_str()); //Sets proxy address and port on libcurl 107 } 108 109 const osgDB::AuthenticationDetails* details = authenticationMap ? 110 authenticationMap->getAuthenticationDetails(fileName) : 111 0; 112 113 // configure/reset authentication if required. 114 if (details) 115 { 116 const std::string colon(":"); 117 std::string password(details->username + colon + details->password); 118 curl_easy_setopt(_curl, CURLOPT_USERPWD, password.c_str()); 119 _previousPassword = password; 120 121 // use for https. 122 // curl_easy_setopt(_curl, CURLOPT_KEYPASSWD, password.c_str()); 123 124 if (details->httpAuthentication != _previousHttpAuthentication) 125 { 126 curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, details->httpAuthentication); 127 _previousHttpAuthentication = details->httpAuthentication; 128 } 129 } 130 else 131 { 132 if (!_previousPassword.empty()) 133 { 134 curl_easy_setopt(_curl, CURLOPT_USERPWD, 0); 135 _previousPassword.clear(); 136 } 137 138 // need to reset if previously set. 139 if (_previousHttpAuthentication!=0) 140 { 141 curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, 0); 142 _previousHttpAuthentication = 0; 143 } 101 144 } 102 145 … … 249 292 EasyCurl::StreamObject sp(&buffer, std::string()); 250 293 251 ReadResult curlResult = getEasyCurl().read(proxyAddress, fileName, sp );294 ReadResult curlResult = getEasyCurl().read(proxyAddress, fileName, sp, options); 252 295 253 296 if (curlResult.status()==ReadResult::FILE_LOADED) 254 297 { 255 osg::ref_ptr<Options> local_opt = const_cast<Options*>(options); 256 if (!local_opt) local_opt = new Options; 298 osg::ref_ptr<Options> local_opt = options ? 299 static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : 300 new Options; 257 301 258 302 local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); OpenSceneGraph/trunk/src/osgPlugins/curl/ReaderWriterCURL.h
r8326 r8619 51 51 EasyCurl(); 52 52 53 osgDB::ReaderWriter::ReadResult read(const std::string& proxyAddress, const std::string& fileName, StreamObject& sp );53 osgDB::ReaderWriter::ReadResult read(const std::string& proxyAddress, const std::string& fileName, StreamObject& sp, const osgDB::ReaderWriter::Options *options); 54 54 55 55 protected: … … 63 63 64 64 CURL* _curl; 65 66 std::string _previousPassword; 67 long _previousHttpAuthentication; 65 68 }; 66 69
