Added intial cut at fileExists() implement using libcurl. Note, current implement loads the whole file and then discards it so is very in-efficient. This implementation will soon be replaced.

This commit is contained in:
Robert Osfield 2009-05-13 19:47:26 +00:00
parent 122ee0a001
commit 59ddcd08f4
2 changed files with 22 additions and 0 deletions

View File

@ -349,6 +349,8 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType
// return ReadResult::FILE_NOT_HANDLED; // return ReadResult::FILE_NOT_HANDLED;
//} //}
osg::notify(osg::INFO)<<"CURL: Have readerwriter="<<reader<<std::endl;
const char* proxyEnvAddress = getenv("OSG_CURL_PROXY"); const char* proxyEnvAddress = getenv("OSG_CURL_PROXY");
if (proxyEnvAddress) //Env Proxy Settings if (proxyEnvAddress) //Env Proxy Settings
{ {
@ -368,6 +370,8 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType
if (curlResult.status()==ReadResult::FILE_LOADED) if (curlResult.status()==ReadResult::FILE_LOADED)
{ {
osg::notify(osg::INFO)<<"CURL: ReadResult::FILE_LOADED "<<std::endl;
// If we do not already have a ReaderWriter, try to find one based on the // If we do not already have a ReaderWriter, try to find one based on the
// mime-type: // mime-type:
if ( !reader ) if ( !reader )
@ -490,6 +494,22 @@ bool ReaderWriterCURL::read(std::istream& fin, std::string& destination) const
} }
#endif #endif
bool ReaderWriterCURL::fileExists(const std::string& filename, const osgDB::Options* options) const
{
if (osgDB::containsServerAddress(filename))
{
osg::notify(osg::NOTICE)<<"Checking if file exists using curl plugin: "<<filename<<std::endl;
ReadResult result = readFile(OBJECT,filename,options);
return result.status()==osgDB::ReaderWriter::ReadResult::FILE_LOADED;
}
else
{
return ReaderWriter::fileExists(filename, options);
}
}
// now register with Registry to instantiate the above // now register with Registry to instantiate the above
// reader/writer. // reader/writer.
REGISTER_OSGPLUGIN(curl, ReaderWriterCURL) REGISTER_OSGPLUGIN(curl, ReaderWriterCURL)

View File

@ -88,6 +88,8 @@ class ReaderWriterCURL : public osgDB::ReaderWriter
return osgDB::equalCaseInsensitive(extension,"curl"); return osgDB::equalCaseInsensitive(extension,"curl");
} }
virtual bool fileExists(const std::string& filename, const osgDB::Options* options) const;
virtual ReadResult openArchive(const std::string& fileName,ArchiveStatus status, unsigned int , const Options* options) const virtual ReadResult openArchive(const std::string& fileName,ArchiveStatus status, unsigned int , const Options* options) const
{ {
if (status!=READ) return ReadResult(ReadResult::FILE_NOT_HANDLED); if (status!=READ) return ReadResult(ReadResult::FILE_NOT_HANDLED);