From: Joogab Yun Date: Mon, 16 Sep 2019 06:44:39 +0000 (+0900) Subject: Merge branch 'devel/master' into tizen X-Git-Tag: submit/tizen/20190917.064531~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7957dda0f0b8e19bc3f012bed80d74518c74095f;hp=36a297be6c289ecbda9c2a8db3a9d1052da99d86;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Merge branch 'devel/master' into tizen --- diff --git a/build/tizen/adaptor/Makefile.am b/build/tizen/adaptor/Makefile.am index 3aeb2df..21d8ff2 100644 --- a/build/tizen/adaptor/Makefile.am +++ b/build/tizen/adaptor/Makefile.am @@ -460,6 +460,7 @@ LIBDALI_ADAPTOR_LA_CXXFLAGS = \ $(LIBDRM_CFLAGS) \ $(LIBEXIF_CFLAGS) \ $(LIBCURL_CFLAGS) \ + $(LIBCRYPTO_CFLAGS) \ $(TPKP_CURL_CFLAGS) \ $(UTILX_CFLAGS) @@ -488,6 +489,7 @@ LIBDALI_ADAPTOR_LA_LIBADD = \ $(LIBDRM_LIBS) \ $(LIBEXIF_LIBS) \ $(LIBCURL_LIBS) \ + $(LIBCRYPTO_LIBS) \ $(HARFBUZZ_LIBS) \ $(TPKP_CURL_LIBS) \ $(UTILX_LIBS) \ @@ -601,6 +603,15 @@ LIBDALI_ADAPTOR_LA_LIBADD += -ljpeg CFLAGS += -fPIC endif +if !UBUNTU_PROFILE +if WAYLAND +else +# X11 +LIBDALI_ADAPTOR_LA_CXXFLAGS += $(UTILX_CFLAGS) +LIBDALI_ADAPTOR_LA_LIBADD += $(UTILX_LIBS) +endif +endif + tizenadaptorpublicapidir = $(devincludepath)/dali/public-api tizenadaptorpublicapi_HEADERS = $(public_api_header_files) diff --git a/build/tizen/adaptor/configure.ac b/build/tizen/adaptor/configure.ac index 77ded63..ae20dd2 100644 --- a/build/tizen/adaptor/configure.ac +++ b/build/tizen/adaptor/configure.ac @@ -44,6 +44,7 @@ PKG_CHECK_MODULES(PNG, libpng) PKG_CHECK_MODULES(LIBEXIF, libexif) PKG_CHECK_MODULES(LIBDRM, libdrm) PKG_CHECK_MODULES(LIBCURL, libcurl) +PKG_CHECK_MODULES(LIBCRYPTO, libcrypto) PKG_CHECK_MODULES(HARFBUZZ, harfbuzz) PKG_CHECK_MODULES(FRIBIDI, fribidi) PKG_CHECK_MODULES(CAIRO, cairo) diff --git a/dali/internal/imaging/common/file-download.cpp b/dali/internal/imaging/common/file-download.cpp index 3a5367e..402e3c0 100755 --- a/dali/internal/imaging/common/file-download.cpp +++ b/dali/internal/imaging/common/file-download.cpp @@ -214,18 +214,75 @@ 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, diff --git a/dali/internal/imaging/common/file-download.h b/dali/internal/imaging/common/file-download.h index d53438c..f807b22 100755 --- a/dali/internal/imaging/common/file-download.h +++ b/dali/internal/imaging/common/file-download.h @@ -23,6 +23,7 @@ #include #include //c++11 #include // uint8 +#include namespace Dali { @@ -58,6 +59,24 @@ public: CurlEnvironment& operator=( const CurlEnvironment& ) = delete; CurlEnvironment( CurlEnvironment&& ) = default; CurlEnvironment& operator=( CurlEnvironment&& ) = default; + + /** + * Locking function for libcurl with openssl + */ + static void OnOpenSSLLocking( int mode, int n, const char* file, int line ); + + /** + * Gets thread id for libcurl with openssl + */ + static void GetThreadId( CRYPTO_THREADID* tid ); + +private: + + void SetLockingFunction(); + + void UnsetLockingFunction(); + + static std::mutex* mMutexs; }; diff --git a/dali/internal/imaging/windows/file-download-win.cpp b/dali/internal/imaging/windows/file-download-win.cpp index 198e828..a6ab471 100755 --- a/dali/internal/imaging/windows/file-download-win.cpp +++ b/dali/internal/imaging/windows/file-download-win.cpp @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include #include #include #include <../ExInclude/InternalFileOperation.h> @@ -223,18 +224,70 @@ 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::SetLockingFunction() +{ + if( mMutexs != NULL ) + { + return; + } + + mMutexs = new std::mutex[ CRYPTO_num_locks() ]; + + CRYPTO_set_id_callback( &CurlEnvironment::GetThreadId ); + CRYPTO_set_locking_callback( &CurlEnvironment::OnOpenSSLLocking ); +} + +void CurlEnvironment::UnsetLockingFunction() +{ + if( mMutexs == NULL ) + { + return; + } + + CRYPTO_set_id_callback( NULL ); + CRYPTO_set_locking_callback( NULL ); + + delete [] mMutexs; + mMutexs = NULL; +} + bool DownloadRemoteFileIntoMemory( const std::string& url, Dali::Vector& dataBuffer, size_t& dataSize, diff --git a/packaging/dali-adaptor.spec b/packaging/dali-adaptor.spec index 8e40281..c1e5f7a 100644 --- a/packaging/dali-adaptor.spec +++ b/packaging/dali-adaptor.spec @@ -65,6 +65,7 @@ BuildRequires: fribidi-devel BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(capi-system-sensor) +BuildRequires: pkgconfig(libcrypto) BuildRequires: pkgconfig(cairo) BuildRequires: pkgconfig(wayland-egl)