X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fimaging%2Fcommon%2Ffile-download.cpp;h=3a5367eaee723bfa3f47754a19b1472acce986c7;hb=a92771e3821fb244fa81d488449aa8b2c6be5e0b;hp=60faf2c75eb78edc884a7adcb98a36952f600a17;hpb=1f5a1427a892da51c83def8dcbc4d43ac6f2131c;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/imaging/common/file-download.cpp b/dali/internal/imaging/common/file-download.cpp index 60faf2c..3a5367e 100755 --- a/dali/internal/imaging/common/file-download.cpp +++ b/dali/internal/imaging/common/file-download.cpp @@ -214,80 +214,25 @@ bool DownloadFile( CURL* curlHandle, namespace Network { -std::mutex* CurlEnvironment::mMutexs = NULL; - CurlEnvironment::CurlEnvironment() { // Must be called before we attempt any loads. e.g. by using curl_easy_init() // and before we start any threads. curl_global_init(CURL_GLOBAL_ALL); - - // libcurl with openssl needs locking_function and thread id for threadsafe - // https://curl.haxx.se/libcurl/c/threadsafe.html - // https://www.openssl.org/docs/man1.0.2/crypto/threads.html#DESCRIPTION - // SetLockingFunction sets locking_function and get thread id by the guide. - SetLockingFunction(); } CurlEnvironment::~CurlEnvironment() { - UnsetLockingFunction(); - curl_global_cleanup(); } -// libcurl with openssl needs locking_function and thread id for threadsafe -// https://curl.haxx.se/libcurl/c/threadsafe.html -// https://www.openssl.org/docs/man1.0.2/crypto/threads.html#DESCRIPTION -void CurlEnvironment::OnOpenSSLLocking( int mode, int n, const char* file, int line ) -{ - if( mode & CRYPTO_LOCK ) - { - mMutexs[n].lock(); - } - else - { - mMutexs[n].unlock(); - } -} - -void CurlEnvironment::GetThreadId( CRYPTO_THREADID* tid ) -{ - // If dali uses c++ thread, we may replace pthread_self() to this_thread::get_id() - CRYPTO_THREADID_set_numeric( tid, static_cast< unsigned long > ( pthread_self() ) ); -} - -void CurlEnvironment::SetLockingFunction() -{ - if( mMutexs != NULL ) - { - return; - } - - mMutexs = new std::mutex[ CRYPTO_num_locks() ]; - - CRYPTO_THREADID_set_callback( &CurlEnvironment::GetThreadId ); - CRYPTO_set_locking_callback( &CurlEnvironment::OnOpenSSLLocking ); -} - -void CurlEnvironment::UnsetLockingFunction() -{ - if( mMutexs == NULL ) - { - return; - } - - CRYPTO_THREADID_set_callback( NULL ); - CRYPTO_set_locking_callback( NULL ); - delete [] mMutexs; - mMutexs = NULL; -} - bool DownloadRemoteFileIntoMemory( const std::string& url, Dali::Vector& dataBuffer, size_t& dataSize, size_t maximumAllowedSizeBytes ) { + bool result = false; + if( url.empty() ) { DALI_LOG_WARNING("empty url requested \n"); @@ -298,17 +243,18 @@ bool DownloadRemoteFileIntoMemory( const std::string& url, // thread we need to explicity call curl_global_init() on startup from a single thread. CURL* curlHandle = curl_easy_init(); + if ( curlHandle ) + { + result = DownloadFile( curlHandle, url, dataBuffer, dataSize, maximumAllowedSizeBytes); - bool result = DownloadFile( curlHandle, url, dataBuffer, dataSize, maximumAllowedSizeBytes); - - // clean up session - curl_easy_cleanup( curlHandle ); + // clean up session + curl_easy_cleanup( curlHandle ); #ifdef TPK_CURL_ENABLED - // Clean up tpkp(the module for certificate pinning) resources on Tizen - tpkp_curl_cleanup(); + // Clean up tpkp(the module for certificate pinning) resources on Tizen + tpkp_curl_cleanup(); #endif // TPK_CURL_ENABLED - + } return result; }