42 #include <curl/curl.h>
74 std::string lock_file = cache_id;
75 lock_file.append(
".lock");
85 Log::instance()->
debug(
"Layer %s already present in local cache (%s)\n", str.c_str(), cache_id.c_str() );
96 std::string msg =
"Untrusted source for remote raster. Aborting operation.\n";
101 std::string retries_file = cache_id;
102 retries_file.append(
".tries");
111 fin.open( retries_fullpath.c_str(), ios::in );
113 if ( fin.is_open() ) {
118 getline( fin, line );
122 num_retries = atoi( oss.str().c_str() );
128 throw RasterException(
"Could not determine number of previous download retries." );
131 if ( num_retries > 3 ) {
134 throw RasterException(
"Too many attempts to fetch raster. Aborting." );
148 ostringstream oss (ostringstream::out);
153 p_file = fopen( retries_fullpath.c_str(),
"w" );
155 if ( p_file == NULL ) {
158 throw RasterException(
"Could not store number of download retries." );
164 sprintf( buffer,
"%d", num_retries );
165 fputs( buffer, p_file );
170 Log::instance()->
debug(
"Fetching remote raster %s (%s)...\n", str.c_str(), cache_id.c_str() );
175 file_data.
fileName = cached_ref.c_str();
178 curl_global_init( CURL_GLOBAL_DEFAULT );
180 curl = curl_easy_init();
184 if ( CURLE_OK != curl_easy_setopt( curl, CURLOPT_URL, str.c_str() ) ) {
186 std::string msg =
"Could not configure remote raster fetcher.\n";
192 curl_easy_setopt( curl, CURLOPT_FOLLOWLOCATION, 1 );
193 curl_easy_setopt( curl, CURLOPT_MAXREDIRS, 5 );
196 curl_easy_setopt( curl, CURLOPT_TIMEOUT, 30 );
202 #ifdef CURLOPT_NOSIGNAL
203 curl_easy_setopt( curl, CURLOPT_NOSIGNAL, 1 );
207 curl_easy_setopt( curl, CURLOPT_WRITEDATA, &file_data );
210 CURLcode res = curl_easy_perform( curl );
212 curl_easy_cleanup( curl );
216 fclose( file_data.
stream );
219 curl_global_cleanup();
221 if ( CURLE_OK != res ) {
223 std::string msg =
"Could not fetch remote raster.\n";
230 std::string msg =
"Could not initialize remote raster fetcher.\n";
266 std::string msg =
"Method createRaster() not available to create writable remote rasters.\n";
275 std::string msg =
"Method createRaster() not available to create writable remote rasters.\n";
286 std::string msg =
"Method put() not available for remote rasters.\n";
296 std::string msg =
"Method put() not available for remote rasters.\n";
306 std::string msg =
"Method finish() not available for remote rasters.\n";
316 std::string msg =
"Method deleteRaster() not available for remote rasters.\n";
328 if ( out && !out->
stream ) {
338 return fwrite( buffer, size, nmemb, out->
stream );
#define OM_REMOTE_RASTER_SUBDIR
static size_t _writeData(void *buffer, size_t size, size_t nmemb, void *stream)
bool isFromRejectedSource(const std::string &str)
void warn(const char *format,...)
'Warn' level.
static std::string getContentIdMd5(const std::string id)
static bool isCached(const std::string id, const std::string subdir="")
static void cache(const std::string id, const std::ostringstream &content, const std::string subdir="")
double Scalar
Type of map values.
static Raster * CreateRasterCallback()
static Log * instance()
Returns the instance pointer, creating the object on the first call.
void createRaster(const std::string &str, int categ=0)
A common interface to rasters.
static std::string getContentLocation(const std::string id, const std::string subdir="")
int put(Coord x, Coord y, Scalar val)
static int eraseCache(const std::string id, const std::string subdir="")
void error(const char *format,...)
'Error' level.
static bool isCachedMd5(const std::string id, const std::string subdir="")
void createRaster(const std::string &file, int categ=0)
double Coord
Type of map coordinates.
static std::string getContentLocationMd5(const std::string id, const std::string subdir="")
void debug(const char *format,...)
'Debug' level.