From 61dd843d5341f8e52a3470f97960134ee96cccfb Mon Sep 17 00:00:00 2001 From: Matthew Reid Date: Sat, 6 Apr 2024 12:30:19 +1100 Subject: [PATCH] TileSource now loads images from http tile servers without SSL certificate --- src/Skybolt/SkyboltVis/OsgImageHelpers.cpp | 4 ++-- src/Skybolt/SkyboltVis/OsgImageHelpers.h | 3 ++- .../Planet/Tile/TileSource/XyzTileSource.cpp | 10 +++++++--- .../Renderable/Planet/Tile/TileSource/XyzTileSource.h | 3 +++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Skybolt/SkyboltVis/OsgImageHelpers.cpp b/src/Skybolt/SkyboltVis/OsgImageHelpers.cpp index 8d5672a5..08c89d19 100644 --- a/src/Skybolt/SkyboltVis/OsgImageHelpers.cpp +++ b/src/Skybolt/SkyboltVis/OsgImageHelpers.cpp @@ -112,9 +112,9 @@ osg::Image* readImageWithCorrectOrientation(const std::string& filename) return image; } -osg::ref_ptr readImageWithoutWarnings(const std::string& filename) +osg::ref_ptr readImageWithoutWarnings(const std::string& filename, const osgDB::Options* options) { - osgDB::ReaderWriter::ReadResult rr = osgDB::Registry::instance()->readImage(filename, osgDB::Registry::instance()->getOptions()); + osgDB::ReaderWriter::ReadResult rr = osgDB::Registry::instance()->readImage(filename, options ? options : osgDB::Registry::instance()->getOptions()); if (rr.validImage()) return osg::ref_ptr(rr.getImage()); return nullptr; } diff --git a/src/Skybolt/SkyboltVis/OsgImageHelpers.h b/src/Skybolt/SkyboltVis/OsgImageHelpers.h index ec019861..52e44828 100644 --- a/src/Skybolt/SkyboltVis/OsgImageHelpers.h +++ b/src/Skybolt/SkyboltVis/OsgImageHelpers.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -58,7 +59,7 @@ GLuint toSrgbInternalFormat(GLuint format); osg::Image* readImageWithCorrectOrientation(const std::string& filename); -osg::ref_ptr readImageWithoutWarnings(const std::string& filename); +osg::ref_ptr readImageWithoutWarnings(const std::string& filename, const osgDB::Options* options = osgDB::Registry::instance()->getOptions()); //! Reads an image from stream including the image's user data stored in osg::UserDataContainer osg::ref_ptr readImageWithUserData(std::istream& s, const std::string& extension); diff --git a/src/Skybolt/SkyboltVis/Renderable/Planet/Tile/TileSource/XyzTileSource.cpp b/src/Skybolt/SkyboltVis/Renderable/Planet/Tile/TileSource/XyzTileSource.cpp index 2ad5dad9..3cb61599 100644 --- a/src/Skybolt/SkyboltVis/Renderable/Planet/Tile/TileSource/XyzTileSource.cpp +++ b/src/Skybolt/SkyboltVis/Renderable/Planet/Tile/TileSource/XyzTileSource.cpp @@ -26,14 +26,18 @@ XyzTileSource::XyzTileSource(const XyzTileSourceConfig& config) : mYOrigin(config.yOrigin), mApiKey(config.apiKey), mCacheSha(skybolt::calcSha1(config.urlTemplate)), - mElevationRerange(config.elevationRerange) + mElevationRerange(config.elevationRerange), + mImageReadOptions(new osgDB::Options()) { + // Disable SSL verification CURL requests, so that we can read images from http:// tile servers. + // FIXME: Ideally we would allow the user keep verification on and provide a certificate. + mImageReadOptions->setOptionString("OSG_CURL_SSL_VERIFYPEER=0"); } bool XyzTileSource::validate() const { // Validate the loader by loading level 0 image - osg::ref_ptr image = osgDB::readImageFile(toUrl(QuadTreeTileKey())); + osg::ref_ptr image = osgDB::readImageFile(toUrl(QuadTreeTileKey()), mImageReadOptions); if (!image) { BOOST_LOG_TRIVIAL(error) << "Could not load image from XyzTileSource with URL template '" << mUrlTemplate << "."; @@ -65,7 +69,7 @@ static int flipY(int y, int level) osg::ref_ptr XyzTileSource::createImage(const QuadTreeTileKey& key, std::function cancelSupplier) const { - osg::ref_ptr image = readImageWithoutWarnings(toUrl(key)); + osg::ref_ptr image = readImageWithoutWarnings(toUrl(key), mImageReadOptions); if (image) { if (mElevationRerange) diff --git a/src/Skybolt/SkyboltVis/Renderable/Planet/Tile/TileSource/XyzTileSource.h b/src/Skybolt/SkyboltVis/Renderable/Planet/Tile/TileSource/XyzTileSource.h index a231adda..13154404 100644 --- a/src/Skybolt/SkyboltVis/Renderable/Planet/Tile/TileSource/XyzTileSource.h +++ b/src/Skybolt/SkyboltVis/Renderable/Planet/Tile/TileSource/XyzTileSource.h @@ -7,6 +7,7 @@ #pragma once #include "TileSourceWithMinMaxLevel.h" #include "SkyboltVis/Renderable/Planet/Tile/HeightMapElevationRerange.h" +#include namespace skybolt { namespace vis { @@ -59,6 +60,8 @@ class XyzTileSource : public TileSourceWithMinMaxLevel const std::string mApiKey; const std::string mCacheSha; std::optional mElevationRerange; + + osg::ref_ptr mImageReadOptions; }; } // namespace vis