diff --git a/include/osgDB/AuthenticationMap b/include/osgDB/AuthenticationMap new file mode 100644 index 000000000..4392cfbeb --- /dev/null +++ b/include/osgDB/AuthenticationMap @@ -0,0 +1,79 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGDB_AUTHENTICATIONMAP +#define OSGDB_AUTHENTICATIONMAP 1 + +#include +#include + +#include + +#include +#include + +namespace osgDB { + +class Archive; + +class AuthenticationDetails : public osg::Referenced +{ +public: + + /** Http authentication techniques, see libcurl docs for details on names and associated functionality.*/ + enum HttpAuthentication + { + BASIC = 1<<0, + DIGEST = 1<<1, + NTLM = 1<<2, + GSSNegotiate = 1<<2, + ANY = ~0, + ANYSAFE = ~BASIC + }; + + AuthenticationDetails(const std::string& u, const std::string& p, HttpAuthentication auth=BASIC): + username(u), + password(p), + httpAuthentication(auth) {} + + std::string username; + std::string password; + HttpAuthentication httpAuthentication; + +protected: + virtual ~AuthenticationDetails() {} +}; + +class OSGDB_EXPORT AuthenticationMap : public osg::Referenced +{ + public: + + AuthenticationMap() {} + + + virtual void addAuthenticationDetails(const std::string& path, AuthenticationDetails* details); + + virtual const AuthenticationDetails* getAuthenticationDetails(const std::string& path) const; + + protected: + + virtual ~AuthenticationMap() {} + + typedef std::map > AuthenticationDetailsMap; + AuthenticationDetailsMap _authenticationMap; + +}; + +} + +#endif // OSGDB_AUTHENTICATIONMAP diff --git a/include/osgDB/ReaderWriter b/include/osgDB/ReaderWriter index f20e10110..8f8d8f7e4 100644 --- a/include/osgDB/ReaderWriter +++ b/include/osgDB/ReaderWriter @@ -14,12 +14,11 @@ #ifndef OSGDB_READERWRITER #define OSGDB_READERWRITER 1 -#include #include #include #include -#include +#include #include #include @@ -32,54 +31,6 @@ class Archive; /** list of directories to search through which searching for files. */ typedef std::deque FilePathList; -class AuthenticationDetails : public osg::Referenced -{ -public: - - /** Http authentication techniques, see libcurl docs for details on names and associated functionality.*/ - enum HttpAuthentication - { - BASIC = 1<<0, - DIGEST = 1<<1, - NTLM = 1<<2, - GSSNegotiate = 1<<2, - ANY = ~0, - ANYSAFE = ~BASIC - }; - - AuthenticationDetails(const std::string& u, const std::string& p, HttpAuthentication auth=BASIC): - username(u), - password(p), - httpAuthentication(auth) {} - - std::string username; - std::string password; - HttpAuthentication httpAuthentication; - -protected: - virtual ~AuthenticationDetails() {} -}; - -class OSGDB_EXPORT AuthenticationMap : public osg::Referenced -{ - public: - - AuthenticationMap() {} - - - virtual void addAuthenticationDetails(const std::string& path, AuthenticationDetails* details); - - virtual const AuthenticationDetails* getAuthenticationDetails(const std::string& path) const; - - protected: - - virtual ~AuthenticationMap() {} - - typedef std::map > AuthenticationDetailsMap; - AuthenticationDetailsMap _authenticationMap; - -}; - /** pure virtual base class for reading and writing of non native formats. */ class OSGDB_EXPORT ReaderWriter : public osg::Object { diff --git a/src/osgDB/AuthenticationMap.cpp b/src/osgDB/AuthenticationMap.cpp new file mode 100644 index 000000000..5f3d46d52 --- /dev/null +++ b/src/osgDB/AuthenticationMap.cpp @@ -0,0 +1,41 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include +#include + +using namespace osgDB; + +void AuthenticationMap::addAuthenticationDetails(const std::string& path, AuthenticationDetails* details) +{ + _authenticationMap[path] = details; +} + +const AuthenticationDetails* AuthenticationMap::getAuthenticationDetails(const std::string& path) const +{ + // see if the full filename has its own authentication details + AuthenticationDetailsMap::const_iterator itr = _authenticationMap.find(path); + if (itr != _authenticationMap.end()) return itr->second.get(); + + // now look to see if the paths to the file have their own authentication details + std::string basePath = osgDB::getFilePath(path); + while(!basePath.empty()) + { + itr = _authenticationMap.find(basePath); + if (itr != _authenticationMap.end()) return itr->second.get(); + + basePath = osgDB::getFilePath(basePath); + } + return 0; +} + diff --git a/src/osgDB/CMakeLists.txt b/src/osgDB/CMakeLists.txt index 7b7c1f0aa..c82aa8039 100644 --- a/src/osgDB/CMakeLists.txt +++ b/src/osgDB/CMakeLists.txt @@ -9,6 +9,7 @@ SET(LIB_NAME osgDB) SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME}) SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/Archive + ${HEADER_PATH}/AuthenticationMap ${HEADER_PATH}/DatabasePager ${HEADER_PATH}/DotOsgWrapper ${HEADER_PATH}/DynamicLibrary @@ -35,6 +36,7 @@ ADD_LIBRARY(${LIB_NAME} ${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC} ${LIB_PUBLIC_HEADERS} Archive.cpp + AuthenticationMap.cpp DatabasePager.cpp DotOsgWrapper.cpp DynamicLibrary.cpp diff --git a/src/osgDB/ReaderWriter.cpp b/src/osgDB/ReaderWriter.cpp index 0df3e1033..105e955f8 100644 --- a/src/osgDB/ReaderWriter.cpp +++ b/src/osgDB/ReaderWriter.cpp @@ -15,43 +15,8 @@ #include #include -#include - using namespace osgDB; -/////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// PasswordMap -// - -void AuthenticationMap::addAuthenticationDetails(const std::string& path, AuthenticationDetails* details) -{ - _authenticationMap[path] = details; -} - -const AuthenticationDetails* AuthenticationMap::getAuthenticationDetails(const std::string& path) const -{ - // see if the full filename has its own authentication details - AuthenticationDetailsMap::const_iterator itr = _authenticationMap.find(path); - if (itr != _authenticationMap.end()) return itr->second.get(); - - // now look to see if the paths to the file have their own authentication details - std::string basePath = osgDB::getFilePath(path); - while(!basePath.empty()) - { - itr = _authenticationMap.find(basePath); - if (itr != _authenticationMap.end()) return itr->second.get(); - - basePath = osgDB::getFilePath(basePath); - } - return 0; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// ReaderWriter -// - osg::Object* ReaderWriter::ReadResult::getObject() { return _object.get(); } osg::Image* ReaderWriter::ReadResult::getImage() { return dynamic_cast(_object.get()); } osg::HeightField* ReaderWriter::ReadResult::getHeightField() { return dynamic_cast(_object.get()); }