// limit maximum image down load size to 50 MB
const size_t MAXIMUM_DOWNLOAD_IMAGE_SIZE = 50 * 1024 * 1024;
+std::string ConvertDataReadable(uint8_t* data, const size_t size, const size_t width)
+{
+ std::ostringstream oss;
+
+ for(size_t i = 0u; i < size; ++i)
+ {
+ if(i > 0u && (i % width) == 0u)
+ {
+ oss << '\n';
+ }
+ oss << ((data[i] >= 0x20 && data[i] < 0x80) ? static_cast<char>(data[i]) : '.');
+ }
+
+ return oss.str();
+}
+
} // namespace
Devel::PixelBuffer LoadImageFromFile(const std::string& url, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection)
else
{
DALI_LOG_WARNING("Unable to decode bitmap supplied as in-memory blob.\n");
+
+ auto prefixSize = std::min(static_cast<decltype(blobSize)>(0x200), blobSize); // maximum 512 bytes.
+ auto errorString = ConvertDataReadable(reinterpret_cast<uint8_t*>(dataBuffer.Begin()), prefixSize, 0x40);
+ DALI_LOG_WARNING("URL: %s\n", url.c_str());
+ DALI_LOG_WARNING("Downloaded data (prefix %zu bytes of %zu bytes):\n", prefixSize, blobSize);
+ DALI_LOG_WARNING("%s\n", errorString.c_str());
}
}
else
{
auto verboseModeString = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_CURLOPT_VERBOSE_MODE);
verboseMode = verboseModeString ? (std::strtol(verboseModeString, nullptr, 10) > 0 ? 1 : 0) : 0;
+
+ // TODO : Until resolve some thread issue, let we don't mark it as true.
+ // mean, always ask from environment every time.
+ // verboseModeSetted = true;
}
return verboseMode;
}
+/**
+ * @brief Get the Curlopt Maximum Redirection count value from environment.
+ *
+ * @return 5 if environment not defined. Otherwise, value from environment.
+ */
+long GetCurloptMaximumRedirectionCount()
+{
+ static long maxiumumRedirectionCount = 5L;
+ static bool maxiumumRedirectionCountSetted = false;
+ if(DALI_UNLIKELY(!maxiumumRedirectionCountSetted))
+ {
+ auto maxiumumRedirectionCountString = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_CURLOPT_MAXREDIRS);
+ maxiumumRedirectionCount = maxiumumRedirectionCountString ? (std::strtol(maxiumumRedirectionCountString, nullptr, 10)) : 5L;
+
+ // TODO : Until resolve some thread issue, let we don't mark it as true.
+ // mean, always ask from environment every time.
+ // maxiumumRedirectionCountSetted = true;
+ }
+
+ return maxiumumRedirectionCount;
+}
+
/**
* Curl library environment. Direct initialize ensures it's constructed before adaptor
* or application creates any threads.
void ConfigureCurlOptions(CURL* curlHandle, const std::string& url)
{
- auto verboseMode = GetCurloptVerboseMode(); // 0 : off, 1 : on
+ const auto verboseMode = GetCurloptVerboseMode(); // 0 : off, 1 : on
+
+ const long maximumRedirectionCounts = GetCurloptMaximumRedirectionCount(); // 5 for default
curl_easy_setopt(curlHandle, CURLOPT_URL, url.c_str());
curl_easy_setopt(curlHandle, CURLOPT_VERBOSE, verboseMode);
curl_easy_setopt(curlHandle, CURLOPT_NOBODY, EXCLUDE_BODY);
curl_easy_setopt(curlHandle, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curlHandle, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(curlHandle, CURLOPT_MAXREDIRS, 5L);
+ curl_easy_setopt(curlHandle, CURLOPT_MAXREDIRS, maximumRedirectionCounts);
if(verboseMode != 0)
{