Moved AuthenticalMap/AuthenticationDetails out in their own files

This commit is contained in:
Robert Osfield
2008-07-17 12:13:04 +00:00
parent adaf71fa19
commit 969884e6c2
5 changed files with 123 additions and 85 deletions

View File

@@ -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 <osg/Referenced>
#include <osg/ref_ptr>
#include <osgDB/Export>
#include <string>
#include <map>
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<std::string, osg::ref_ptr<AuthenticationDetails> > AuthenticationDetailsMap;
AuthenticationDetailsMap _authenticationMap;
};
}
#endif // OSGDB_AUTHENTICATIONMAP

View File

@@ -14,12 +14,11 @@
#ifndef OSGDB_READERWRITER
#define OSGDB_READERWRITER 1
#include <osg/Referenced>
#include <osg/Image>
#include <osg/Shape>
#include <osg/Node>
#include <osgDB/Export>
#include <osgDB/AuthenticationMap>
#include <deque>
#include <list>
@@ -32,54 +31,6 @@ class Archive;
/** list of directories to search through which searching for files. */
typedef std::deque<std::string> 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<std::string, osg::ref_ptr<AuthenticationDetails> > AuthenticationDetailsMap;
AuthenticationDetailsMap _authenticationMap;
};
/** pure virtual base class for reading and writing of non native formats. */
class OSGDB_EXPORT ReaderWriter : public osg::Object
{

View File

@@ -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 <osgDB/AuthenticationMap>
#include <osgDB/FileNameUtils>
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;
}

View File

@@ -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

View File

@@ -15,43 +15,8 @@
#include <osgDB/FileNameUtils>
#include <osgDB/Archive>
#include <map>
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<osg::Image*>(_object.get()); }
osg::HeightField* ReaderWriter::ReadResult::getHeightField() { return dynamic_cast<osg::HeightField*>(_object.get()); }