Support CURLOPT_MAXREDIRS as environment + Print downloaded buffer if image load... 27/316827/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 18 Dec 2024 08:38:12 +0000 (17:38 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 19 Dec 2024 01:25:06 +0000 (10:25 +0900)
Let we add environment value to control CURLOPT_MAXREDIRS.
Sometimes the redirection count 5 might too small to some applications.
Let we allow to them use more deep depth.

+

Sometimes, we failed to get valid image buffer from given url.

To check whether that url download real-image or not,
let we print prefix of buffers.

Change-Id: I5053ff539da684357d0c5e73d7d57c36423aa976
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/devel-api/adaptor-framework/image-loading.cpp
dali/internal/imaging/common/file-download.cpp
dali/internal/system/common/environment-variables.h

index 2c345346a6a156061b7e7d6f59e119c9c8f5d190..bef7d78915f5bc62db6424420be22d222772652c 100644 (file)
@@ -31,6 +31,22 @@ namespace
 // 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)
@@ -180,6 +196,12 @@ Devel::PixelBuffer DownloadImageSynchronously(const std::string& url, ImageDimen
         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
index de90305a5e0f64f3dcf7d3561efc839104cf6595..4015bc07f0de0c2462adf003c5fdc8ae1e471613 100644 (file)
@@ -154,11 +154,37 @@ long GetCurloptVerboseMode()
   {
     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.
@@ -167,7 +193,9 @@ static Dali::TizenPlatform::Network::CurlEnvironment gCurlEnvironment;
 
 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);
@@ -180,7 +208,7 @@ void ConfigureCurlOptions(CURL* curlHandle, const std::string& url)
   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)
   {
index b657601c7ffb9ea4adb5c923605db06cc42b07bb..2bcef9352d1ac8b59c7db4e49f767ccd464dbd4a 100644 (file)
@@ -175,9 +175,12 @@ namespace Adaptor
 
 #define DALI_ENV_RENDERED_GLYPH_COMPRESS_POLICY "DALI_RENDERED_GLYPH_COMPRESS_POLICY"
 
-// Debug relative environments
+// Curl relative environments
 #define DALI_ENV_CURLOPT_VERBOSE_MODE "DALI_CURLOPT_VERBOSE_MODE"
 
+#define DALI_ENV_CURLOPT_MAXREDIRS "DALI_CURLOPT_MAXREDIRS"
+
+// Debug relative environments
 #define DALI_ENV_PRINT_LOG_LEVEL "DALI_PRINT_LOG_LEVEL"
 
 #define DALI_ENV_TRACE_ENABLE_PRINT_LOG "DALI_TRACE_ENABLE_PRINT_LOG"