From 3ef62a29afa645761e303dce21eaabee35907796 Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Tue, 14 Jul 2015 11:52:18 +0900 Subject: [PATCH] Refactor log system * use only dpl/log/log.h * add journald provider Change-Id: I4bf999861d4b0452c7a4a1d41f22eedea7198f85 Signed-off-by: Kyungwook Tak --- packaging/cert-svc.spec | 1 + vcore/src/CMakeLists.txt | 3 + vcore/src/dpl/core/include/dpl/scoped_fclose.h | 15 +- vcore/src/dpl/core/include/dpl/singleton.h | 6 - vcore/src/dpl/core/include/dpl/singleton_impl.h | 6 +- vcore/src/dpl/core/src/assert.cpp | 12 +- vcore/src/dpl/core/src/exception.cpp | 12 +- vcore/src/dpl/core/src/singleton.cpp | 2 +- vcore/src/dpl/core/src/string.cpp | 4 +- vcore/src/dpl/core/src/thread.cpp | 62 +-- .../dpl/core/src/waitable_handle_watch_support.cpp | 45 +- vcore/src/dpl/db/include/dpl/db/orm.h | 8 +- .../db/include/dpl/db/thread_database_support.h | 20 +- vcore/src/dpl/db/src/sql_connection.cpp | 186 +++---- .../log/include/dpl/log/abstract_log_provider.h | 40 +- .../dpl/log/include/dpl/log/dlog_log_provider.h | 47 +- .../dpl/log/include/dpl/log/journal_log_provider.h | 43 ++ vcore/src/dpl/log/include/dpl/log/log.h | 155 +++--- .../log/include/dpl/log/old_style_log_provider.h | 56 +- vcore/src/dpl/log/include/dpl/log/vcore_log.h | 48 -- vcore/src/dpl/log/include/dpl/log/wrt_log.h | 48 -- vcore/src/dpl/log/src/abstract_log_provider.cpp | 3 + vcore/src/dpl/log/src/dlog_log_provider.cpp | 119 ++-- vcore/src/dpl/log/src/journal_log_provider.cpp | 74 +++ vcore/src/dpl/log/src/log.cpp | 215 +++----- vcore/src/dpl/log/src/old_style_log_provider.cpp | 163 ++---- vcore/src/dpl/test/src/process_pipe.cpp | 7 +- vcore/src/vcore/Base64.cpp | 28 +- vcore/src/vcore/CRLImpl.cpp | 64 +-- vcore/src/vcore/CachedCRL.cpp | 25 +- vcore/src/vcore/CachedOCSP.cpp | 15 +- vcore/src/vcore/Certificate.cpp | 16 +- vcore/src/vcore/CertificateCacheDAO.cpp | 14 +- vcore/src/vcore/CertificateCollection.cpp | 10 +- vcore/src/vcore/CertificateLoader.cpp | 607 +-------------------- vcore/src/vcore/CertificateVerifier.cpp | 22 +- vcore/src/vcore/OCSPCertMgrUtil.cpp | 28 +- vcore/src/vcore/OCSPImpl.cpp | 62 +-- vcore/src/vcore/ReferenceValidator.cpp | 18 +- vcore/src/vcore/SaxReader.cpp | 4 +- vcore/src/vcore/SignatureFinder.cpp | 6 +- vcore/src/vcore/SignatureValidator.cpp | 219 ++++---- vcore/src/vcore/SoupMessageSendBase.cpp | 6 +- vcore/src/vcore/SoupMessageSendSync.cpp | 10 +- vcore/src/vcore/TimeConversion.cpp | 8 +- vcore/src/vcore/VCore.cpp | 4 +- vcore/src/vcore/ValidatorFactories.cpp | 6 +- vcore/src/vcore/WacOrigin.cpp | 6 +- vcore/src/vcore/WrtSignatureValidator.cpp | 163 +++--- vcore/src/vcore/XmlsecAdapter.cpp | 67 ++- vcore/src/vcore/api.cpp | 104 ++-- vcore/src/vcore/exception.cpp | 8 +- 52 files changed, 1020 insertions(+), 1900 deletions(-) create mode 100644 vcore/src/dpl/log/include/dpl/log/journal_log_provider.h delete mode 100644 vcore/src/dpl/log/include/dpl/log/vcore_log.h delete mode 100644 vcore/src/dpl/log/include/dpl/log/wrt_log.h create mode 100644 vcore/src/dpl/log/src/journal_log_provider.cpp diff --git a/packaging/cert-svc.spec b/packaging/cert-svc.spec index 12e8d6f..6875468 100644 --- a/packaging/cert-svc.spec +++ b/packaging/cert-svc.spec @@ -25,6 +25,7 @@ BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(key-manager) BuildRequires: pkgconfig(secure-storage) BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(libsystemd-journal) BuildRequires: boost-devel %if 0%{?certsvc_feature_ocsp_crl} BuildRequires: pkgconfig(vconf) diff --git a/vcore/src/CMakeLists.txt b/vcore/src/CMakeLists.txt index c982724..a29981b 100644 --- a/vcore/src/CMakeLists.txt +++ b/vcore/src/CMakeLists.txt @@ -16,6 +16,7 @@ PKG_CHECK_MODULES(VCORE_DEPS icu-uc libsoup-2.4 db-util + libsystemd-journal sqlite3 vconf @@ -33,6 +34,7 @@ PKG_CHECK_MODULES(VCORE_DEPS icu-uc libsoup-2.4 db-util + libsystemd-journal ) ENDIF(DEFINED TIZEN_FEAT_CERTSVC_OCSP_CRL) @@ -90,6 +92,7 @@ SET(VCORE_DPL_LOG_SOURCES ${VCORE_DPL_LOG_SRC_DIR}/abstract_log_provider.cpp ${VCORE_DPL_LOG_SRC_DIR}/old_style_log_provider.cpp ${VCORE_DPL_LOG_SRC_DIR}/dlog_log_provider.cpp + ${VCORE_DPL_LOG_SRC_DIR}/journal_log_provider.cpp ${VCORE_DPL_LOG_SRC_DIR}/log.cpp ) ########### DPL SOURCES ########## diff --git a/vcore/src/dpl/core/include/dpl/scoped_fclose.h b/vcore/src/dpl/core/include/dpl/scoped_fclose.h index 8813497..b69fcbd 100644 --- a/vcore/src/dpl/core/include/dpl/scoped_fclose.h +++ b/vcore/src/dpl/core/include/dpl/scoped_fclose.h @@ -26,9 +26,7 @@ #include #include #include -#include #include -#include namespace VcoreDPL { struct ScopedFClosePolicy @@ -42,17 +40,12 @@ struct ScopedFClosePolicy { if (file != NULL) { // Try to flush first - if (TEMP_FAILURE_RETRY(fflush(file)) != 0) { - std::string errString = GetErrnoString(); - VcoreLogD("Failed to fflush scoped fclose error: %s", - errString.c_str()); - } + if (TEMP_FAILURE_RETRY(fflush(file)) != 0) + return; // fclose cannot be retried, try to close once - if (fclose(file) != 0) { - std::string errString = GetErrnoString(); - VcoreLogD("Failed scoped fclose error: %s", errString.c_str()); - } + if (fclose(file) != 0) + return; } } }; diff --git a/vcore/src/dpl/core/include/dpl/singleton.h b/vcore/src/dpl/core/include/dpl/singleton.h index 4371f32..57bbe33 100644 --- a/vcore/src/dpl/core/include/dpl/singleton.h +++ b/vcore/src/dpl/core/include/dpl/singleton.h @@ -22,10 +22,6 @@ #ifndef DPL_SINGLETON_H #define DPL_SINGLETON_H -#include -#include -#include - namespace VcoreDPL { template class Singleton : @@ -42,8 +38,6 @@ class Singleton : Singleton() {} - typedef boost::optional OptionalThreadPtr; - static Singleton &InternalInstance(); public: diff --git a/vcore/src/dpl/core/include/dpl/singleton_impl.h b/vcore/src/dpl/core/include/dpl/singleton_impl.h index fd70741..f8f9fd9 100644 --- a/vcore/src/dpl/core/include/dpl/singleton_impl.h +++ b/vcore/src/dpl/core/include/dpl/singleton_impl.h @@ -22,6 +22,8 @@ #ifndef DPL_SINGLETON_IMPL_H #define DPL_SINGLETON_IMPL_H +#include + /* * WARNING! * @@ -46,8 +48,8 @@ Class &Singleton::Instance() } } // namespace VcoreDPL -#define IMPLEMENT_SINGLETON(Type) \ - template VcoreDPL::Singleton&VcoreDPL::Singleton::InternalInstance(); \ +#define IMPLEMENT_SINGLETON(Type) \ + template VcoreDPL::Singleton&VcoreDPL::Singleton::InternalInstance(); \ template Type & VcoreDPL::Singleton::Instance(); \ #endif // DPL_SINGLETON_IMPL_H diff --git a/vcore/src/dpl/core/src/assert.cpp b/vcore/src/dpl/core/src/assert.cpp index 2e55877..22761a4 100644 --- a/vcore/src/dpl/core/src/assert.cpp +++ b/vcore/src/dpl/core/src/assert.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace VcoreDPL { void AssertProc(const char *condition, @@ -34,11 +34,11 @@ void AssertProc(const char *condition, const char *function) { -#define INTERNAL_LOG(message) \ -do { \ - std::ostringstream platformLog; \ - platformLog << message; \ - VcoreLogD("%s", platformLog.str().c_str()); \ +#define INTERNAL_LOG(message) \ +do { \ + std::ostringstream platformLog; \ + platformLog << message; \ + LogDebug("" << platformLog.str()); \ } while (0) // Try to log failed assertion to log system diff --git a/vcore/src/dpl/core/src/exception.cpp b/vcore/src/dpl/core/src/exception.cpp index 16a3c25..1fb3d94 100644 --- a/vcore/src/dpl/core/src/exception.cpp +++ b/vcore/src/dpl/core/src/exception.cpp @@ -21,7 +21,7 @@ */ #include #include -#include +#include #include namespace VcoreDPL { @@ -31,8 +31,7 @@ void (*Exception::m_terminateHandler)() = NULL; void LogUnhandledException(const std::string &str) { - // Logging to dlog - VcoreLogD("%s", str.c_str()); + LogDebug("" << str); } void LogUnhandledException(const std::string &str, @@ -40,8 +39,9 @@ void LogUnhandledException(const std::string &str, int line, const char *function) { - // Logging to dlog - VcoreLogE("Exception occured on file[%s] line[%d] function[%s] msg[%s]", - filename, line, function, str.c_str()); + LogError("Exception occured on file[" << filename + << "] line[" << line + << "] function[" << function + << "] msg[" << str << "]"); } } // namespace VcoreDPL diff --git a/vcore/src/dpl/core/src/singleton.cpp b/vcore/src/dpl/core/src/singleton.cpp index a76e8ac..54abd52 100644 --- a/vcore/src/dpl/core/src/singleton.cpp +++ b/vcore/src/dpl/core/src/singleton.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ /* - * @file generic_event.cpp + * @file singleton.cpp * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) * @version 1.0 * @brief This file is the implementation file of singleton diff --git a/vcore/src/dpl/core/src/string.cpp b/vcore/src/dpl/core/src/string.cpp index fb2f79c..5679633 100644 --- a/vcore/src/dpl/core/src/string.cpp +++ b/vcore/src/dpl/core/src/string.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -198,7 +198,7 @@ static UChar *ConvertToICU(const String &inputString) error == U_BUFFER_OVERFLOW_ERROR) { // What buffer size is ok ? - VcoreLogD("ICU: Output buffer size: %i", size); + LogDebug("ICU: Output buffer size: " << size); } else { ThrowMsg(StringException::ICUInvalidCharacterFound, "ICU: Failed to retrieve output string size. Error: " diff --git a/vcore/src/dpl/core/src/thread.cpp b/vcore/src/dpl/core/src/thread.cpp index 98fdd48..045880c 100644 --- a/vcore/src/dpl/core/src/thread.cpp +++ b/vcore/src/dpl/core/src/thread.cpp @@ -21,7 +21,7 @@ */ #include #include -#include +#include #include #include #include @@ -116,7 +116,7 @@ Thread *Thread::GetCurrentThread() void *Thread::StaticThreadEntry(void *param) { - VcoreLogD("Entered static thread entry"); + LogDebug("Entered static thread entry"); // Retrieve context Thread *This = static_cast(param); @@ -126,7 +126,7 @@ void *Thread::StaticThreadEntry(void *param) int result = pthread_setspecific(g_threadSpecific.threadSpecific, This); if (result) - VcoreLogE("Failed to set threadSpecific."); + LogError("Failed to set threadSpecific."); // Enter thread proc // Do not allow exceptions to hit pthread core @@ -145,10 +145,10 @@ void *Thread::StaticThreadEntry(void *param) // Abandon thread if (This->m_abandon) { - VcoreLogD("Thread was abandoned"); + LogDebug("Thread was abandoned"); This->m_thread.detach(); } else { - VcoreLogD("Thread is joinable"); + LogDebug("Thread is joinable"); } } @@ -157,13 +157,13 @@ void *Thread::StaticThreadEntry(void *param) int Thread::ThreadEntry() { - VcoreLogD("Entered default thread entry"); + LogDebug("Entered default thread entry"); return Exec(); } void Thread::ProcessEvents() { - VcoreLogD("Processing events"); + LogDebug("Processing events"); // Steal current event list InternalEventList stolenEvents; @@ -176,7 +176,7 @@ void Thread::ProcessEvents() } // Process event list - VcoreLogD("Stolen %u internal events", stolenEvents.size()); + LogDebug("Stolen " << stolenEvents.size() << " internal events"); for (InternalEventList::iterator iterator = stolenEvents.begin(); iterator != stolenEvents.end(); @@ -200,7 +200,7 @@ void Thread::ProcessTimedEvents() unsigned long currentTimeMiliseconds = GetCurrentTimeMiliseconds(); // Info - VcoreLogD("Processing timed events. Time now: %lu ms", currentTimeMiliseconds); + LogDebug("Processing timed events. Time now: " << currentTimeMiliseconds << " ms"); // All timed events are sorted chronologically // Emit timed out events @@ -210,9 +210,9 @@ void Thread::ProcessTimedEvents() m_timedEventVector.begin()->dueTimeMiliseconds) { // Info - VcoreLogD("Transforming timed event into immediate event. Absolute due time: %lu ms", + LogDebug("Transforming timed event into immediate event. Absolute due time: " << (m_timedEventVector.begin()->registerTimeMiliseconds + - m_timedEventVector.begin()->dueTimeMiliseconds)); + m_timedEventVector.begin()->dueTimeMiliseconds) << " ms"); // Emit immediate event PushEvent(m_timedEventVector.begin()->event, @@ -237,7 +237,7 @@ unsigned long Thread::GetCurrentTimeMiliseconds() const int Thread::Exec() { - VcoreLogD("Executing thread event processing"); + LogDebug("Executing thread event processing"); const std::size_t MIN_HANDLE_LIST_SIZE = 4; @@ -303,7 +303,7 @@ int Thread::Exec() } // Info - VcoreLogD("Thread loop minimum wait time: %lu ms", minimumWaitTime); + LogDebug("Thread loop minimum wait time: " << minimumWaitTime << " ms"); // Do thread waiting WaitableHandleIndexList waitableHandleIndexList = @@ -311,7 +311,7 @@ int Thread::Exec() if (waitableHandleIndexList.empty()) { // Timeout occurred. Process timed events. - VcoreLogD("Timed event list elapsed invoker"); + LogDebug("Timed event list elapsed invoker"); ProcessTimedEvents(); continue; } @@ -324,7 +324,7 @@ int Thread::Exec() { size_t index = *waitableHandleIndexIterator; - VcoreLogD("Event loop triggered with index: %u", index); + LogDebug("Event loop triggered with index: " << index); switch (index) { case 0: @@ -340,7 +340,7 @@ int Thread::Exec() if (m_directInvoke) { m_directInvoke = false; - VcoreLogD("Handling direct invoker"); + LogDebug("Handling direct invoker"); // Update list while (handleList.size() > MIN_HANDLE_LIST_SIZE) { @@ -363,7 +363,7 @@ int Thread::Exec() case 2: // Timed event list changed - VcoreLogD("Timed event list changed invoker"); + LogDebug("Timed event list changed invoker"); ProcessTimedEvents(); // Reset timed event invoker @@ -374,7 +374,7 @@ int Thread::Exec() case 3: // Waitable handle watch support invoker - VcoreLogD("Waitable handle watch invoker event occurred"); + LogDebug("Waitable handle watch invoker event occurred"); // First, remove all previous handles while (handleList.size() > MIN_HANDLE_LIST_SIZE) { @@ -394,14 +394,14 @@ int Thread::Exec() // Handle invoker in waitable watch support WaitableHandleWatchSupport::InvokerFinished(); - VcoreLogD("Waitable handle watch invoker event handled"); + LogDebug("Waitable handle watch invoker event handled"); // Done break; default: // Waitable event watch list - VcoreLogD("Waitable handle watch event occurred"); + LogDebug("Waitable handle watch event occurred"); // Handle event in waitable handle watch { @@ -414,7 +414,7 @@ int Thread::Exec() if (m_directInvoke) { m_directInvoke = false; - VcoreLogD("Handling direct invoker"); + LogDebug("Handling direct invoker"); // Update list while (handleList.size() > MIN_HANDLE_LIST_SIZE) { @@ -432,7 +432,7 @@ int Thread::Exec() } } - VcoreLogD("Waitable handle watch event handled"); + LogDebug("Waitable handle watch event handled"); // Done break; @@ -440,13 +440,13 @@ int Thread::Exec() } } - VcoreLogD("Leaving thread event processing"); + LogDebug("Leaving thread event processing"); return 0; } void Thread::Run() { - VcoreLogD("Running thread"); + LogDebug("Running thread"); // Critical section { @@ -469,7 +469,7 @@ void Thread::Run() m_running = true; } - VcoreLogD("Thread run"); + LogDebug("Thread run"); } void Thread::Quit() @@ -483,7 +483,7 @@ void Thread::Quit() return; } - VcoreLogD("Quitting thread..."); + LogDebug("Quitting thread..."); // Do not abandon thread, we will join m_abandon = false; @@ -498,7 +498,7 @@ void Thread::Quit() Throw(Exception::QuitFailed); } - VcoreLogD("Thread quit"); + LogDebug("Thread quit"); } void Thread::PushEvent(void *event, @@ -516,7 +516,7 @@ void Thread::PushEvent(void *event, // Trigger invoker m_eventInvoker.Signal(); - VcoreLogD("Event pushed and invoker signaled"); + LogDebug("Event pushed and invoker signaled"); } void Thread::PushTimedEvent(void *event, @@ -551,9 +551,9 @@ void Thread::PushTimedEvent(void *event, // Trigger invoker m_timedEventInvoker.Signal(); - VcoreLogD("Timed event pushed and invoker signaled: " - "due time: %lu ms, absolute due time: %lu ms", - dueTimeMiliseconds, currentTimeMiliseconds + dueTimeMiliseconds); + LogDebug("Timed event pushed and invoker signaled: " + "due time: " << dueTimeMiliseconds << " ms, absolute due time: " << + (currentTimeMiliseconds + dueTimeMiliseconds) << " ms"); } Thread *Thread::GetInvokerThread() diff --git a/vcore/src/dpl/core/src/waitable_handle_watch_support.cpp b/vcore/src/dpl/core/src/waitable_handle_watch_support.cpp index fb46539..b7b2644 100644 --- a/vcore/src/dpl/core/src/waitable_handle_watch_support.cpp +++ b/vcore/src/dpl/core/src/waitable_handle_watch_support.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -35,25 +35,25 @@ WaitableHandleWatchSupport::~WaitableHandleWatchSupport() { // Developer assertions if (!m_watchersMap.empty()) { - VcoreLogW("### Leaked watchers map dump ###"); + LogWarning("### Leaked watchers map dump ###"); for (WaitableHandleWatchersMap::const_iterator iterator = m_watchersMap.begin(); iterator != m_watchersMap.end(); ++iterator) { - VcoreLogW("### Waitable handle: %i", iterator->first); + LogWarning("### Waitable handle: " << iterator->first); - VcoreLogW("### Read listeners: %u", iterator->second.readListenersCount); - VcoreLogW("### Write listeners: %u", iterator->second.writeListenersCount); + LogWarning("### Read listeners: " << iterator->second.readListenersCount); + LogWarning("### Write listeners: " << iterator->second.writeListenersCount); for (WaitableHandleListenerList::const_iterator listenersIterator = iterator->second.listeners.begin(); listenersIterator != iterator->second.listeners.end(); ++listenersIterator) { - VcoreLogW("### Mode: %i. Listener: %p", - listenersIterator->mode, listenersIterator->listener); + LogWarning("### Mode: " << listenersIterator->mode + << ". Listener: " << listenersIterator->listener); } } } @@ -97,7 +97,7 @@ WaitableHandleListEx WaitableHandleWatchSupport::WaitableWatcherHandles() const void WaitableHandleWatchSupport::InvokerFinished() { - VcoreLogD("Invoker finished called"); + LogDebug("Invoker finished called"); // Reset invoker m_watchersInvoker.Reset(); @@ -116,7 +116,7 @@ void WaitableHandleWatchSupport::HandleWatcher(WaitableHandle waitableHandle, // Warning: Listeners and/or watcher may also disappear during dispatching // handlers! // - VcoreLogD("Waitable event occurred"); + LogDebug("Waitable event occurred"); // Critical section for other threads { @@ -139,7 +139,7 @@ void WaitableHandleWatchSupport::HandleWatcher(WaitableHandle waitableHandle, if (m_watchersMap.find(trackedWatchersIterator->first) == m_watchersMap.end()) { - VcoreLogD("Watcher disappeared during watcher handler"); + LogDebug("Watcher disappeared during watcher handler"); continue; } @@ -152,8 +152,7 @@ void WaitableHandleWatchSupport::HandleWatcher(WaitableHandle waitableHandle, WaitableHandleListenerList trackedListeners = trackedWatchersIterator->second.listeners; - VcoreLogD("Calling waitable event listeners (%u)...", - trackedListeners.size()); + LogDebug("Calling waitable event listeners (" << trackedListeners.size() << ")..."); // Notice: We must carefully call listeners here as they may // disappear or be created during each of handler call @@ -174,7 +173,7 @@ void WaitableHandleWatchSupport::HandleWatcher(WaitableHandle waitableHandle, if (m_watchersMap.find(trackedWatchersIterator->first) == m_watchersMap.end()) { - VcoreLogD("Watcher disappeared during watcher handler"); + LogDebug("Watcher disappeared during watcher handler"); break; } @@ -200,7 +199,7 @@ void WaitableHandleWatchSupport::HandleWatcher(WaitableHandle waitableHandle, } if (!listenerStillExists) { - VcoreLogD("Watcher listener disappeared during watcher handler"); + LogDebug("Watcher listener disappeared during watcher handler"); break; } @@ -210,17 +209,17 @@ void WaitableHandleWatchSupport::HandleWatcher(WaitableHandle waitableHandle, } // Call waitable event watch listener - VcoreLogD("Before tracker listener call..."); + LogDebug("Before tracker listener call..."); trackedListenersIterator->listener->OnWaitableHandleEvent( trackedWatchersIterator->first, trackedListenersIterator->mode); - VcoreLogD("After tracker listener call..."); + LogDebug("After tracker listener call..."); } // Now call all those listeners who registered during listener calls // FIXME: Implement! Notice, that scenario may be recursive! - VcoreLogD("Waitable event listeners called"); + LogDebug("Waitable event listeners called"); // No more waitable events possible - consistency check break; @@ -255,7 +254,7 @@ void WaitableHandleWatchSupport::AddWaitableHandleWatch( } } - VcoreLogD("Adding waitable handle watch: %i", waitableHandle); + LogDebug("Adding waitable handle watch : " << waitableHandle); // Push new waitable event watch if (mapIterator != m_watchersMap.end()) { @@ -283,7 +282,7 @@ void WaitableHandleWatchSupport::AddWaitableHandleWatch( // Trigger waitable event invoker to commit changes CommitInvoker(); - VcoreLogD("Waitable event watch added and invoker signaled"); + LogDebug("Waitable event watch added and invoker signaled"); } void WaitableHandleWatchSupport::RemoveWaitableHandleWatch( @@ -321,7 +320,7 @@ void WaitableHandleWatchSupport::RemoveWaitableHandleWatch( // Same pair listener-mode must exist Assert(listIterator != mapIterator->second.listeners.end()); - VcoreLogD("Removing waitable handle watch: %i", waitableHandle); + LogDebug("Removing waitable handle watch : " << waitableHandle); // Remove waitable event watch mapIterator->second.listeners.erase(listIterator); @@ -348,19 +347,19 @@ void WaitableHandleWatchSupport::RemoveWaitableHandleWatch( // Trigger waitable event invoker to commit changes CommitInvoker(); - VcoreLogD("Waitable event watch removed and invoker signaled"); + LogDebug("Waitable event watch removed and invoker signaled"); } void WaitableHandleWatchSupport::CommitInvoker() { // Check calling context and execute invoker if (Thread::GetCurrentThread() == GetInvokerThread()) { - VcoreLogD("Calling direct invoker"); + LogDebug("Calling direct invoker"); // Direct invoker call HandleDirectInvoker(); } else { - VcoreLogD("Calling indirect invoker"); + LogDebug("Calling indirect invoker"); // Indirect invoker call m_watchersInvoker.Signal(); diff --git a/vcore/src/dpl/db/include/dpl/db/orm.h b/vcore/src/dpl/db/include/dpl/db/orm.h index 39d0503..11df75f 100644 --- a/vcore/src/dpl/db/include/dpl/db/orm.h +++ b/vcore/src/dpl/db/include/dpl/db/orm.h @@ -664,7 +664,7 @@ protected: this->m_command = TableDefinition::AllocTableDataCommand( this->m_commandString.c_str(), Query::m_interface); - VcoreLogD("Prepared SQL command %s", this->m_commandString.c_str()); + LogDebug("Prepared SQL command " << this->m_commandString); } } @@ -762,7 +762,7 @@ protected: this->m_commandString += " ( " + visitor.m_columnNames + " ) "; this->m_commandString += "VALUES ( " + visitor.m_values + " )"; - VcoreLogD("Prepared SQL command %s", this->m_commandString.c_str()); + LogDebug("Prepared SQL command " << this->m_commandString); this->m_command = TableDefinition::AllocTableDataCommand( this->m_commandString.c_str(), Query::m_interface); @@ -849,7 +849,7 @@ protected: this->m_commandString.c_str(), Query::m_interface); - VcoreLogD("Prepared SQL command %s", this->m_commandString.c_str()); + LogDebug("Prepared SQL command " << this->m_commandString); } } @@ -1065,7 +1065,7 @@ protected: this->m_command = TableDefinition::AllocTableDataCommand( this->m_commandString.c_str(), Query::m_interface); - VcoreLogD("Prepared SQL command %s", this->m_commandString.c_str()); + LogDebug("Prepared SQL command " << this->m_commandString); } } diff --git a/vcore/src/dpl/db/include/dpl/db/thread_database_support.h b/vcore/src/dpl/db/include/dpl/db/thread_database_support.h index 5c82ae5..ce8a11a 100644 --- a/vcore/src/dpl/db/include/dpl/db/thread_database_support.h +++ b/vcore/src/dpl/db/include/dpl/db/thread_database_support.h @@ -97,7 +97,7 @@ class ThreadDatabaseSupport : } // Destroy connection - VcoreLogD("Destroying thread database connection: %s", m_address.c_str()); + LogDebug("Destroying thread database connection: " << m_address); delete *Connection(); @@ -119,16 +119,16 @@ class ThreadDatabaseSupport : void TransactionUnref() { - VcoreLogD("Unref transaction"); + LogDebug("Unref transaction"); if (--(*TransactionDepth()) == 0) { - VcoreLogD("Transaction is finalized"); + LogDebug("Transaction is finalized"); if (*TransactionCancel()) { - VcoreLogD("Transaction will be rolled back"); + LogDebug("Transaction will be rolled back"); (*Connection())->RollbackTransaction(); } else { - VcoreLogD("Transaction will be commited"); + LogDebug("Transaction will be commited"); (*Connection())->CommitTransaction(); } } @@ -157,7 +157,7 @@ class ThreadDatabaseSupport : } // Initialize SQL connection described in traits - VcoreLogD("Attaching thread database connection: %s", m_address.c_str()); + LogDebug("Attaching thread database connection: " << m_address); Connection() = new VcoreDPL::DB::SqlConnection( m_address.c_str(), m_flags, options); @@ -194,7 +194,7 @@ class ThreadDatabaseSupport : // It must not be in linger state yet Assert(*Linger() == false); - VcoreLogD("Detaching thread database connection: %s", m_address.c_str()); + LogDebug("Detaching thread database connection: " << m_address); // Enter linger state *Linger() = true; @@ -246,11 +246,11 @@ class ThreadDatabaseSupport : // Calling thread must support thread database connections Assert(!Connection().IsNull()); - VcoreLogD("Begin transaction"); + LogDebug("Begin transaction"); // Addref transaction if (++(*TransactionDepth()) == 1) { - VcoreLogD("Transaction is initialized"); + LogDebug("Transaction is initialized"); TransactionCancel() = false; (*Connection())->BeginTransaction(); @@ -262,7 +262,7 @@ class ThreadDatabaseSupport : // Calling thread must support thread database connections Assert(!Connection().IsNull()); - VcoreLogD("Commit transaction"); + LogDebug("Commit transaction"); // Unref transation TransactionUnref(); diff --git a/vcore/src/dpl/db/src/sql_connection.cpp b/vcore/src/dpl/db/src/sql_connection.cpp index 9da8266..fa238cd 100644 --- a/vcore/src/dpl/db/src/sql_connection.cpp +++ b/vcore/src/dpl/db/src/sql_connection.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ class ScopedNotifyAll : return; } - VcoreLogD("Notifying after successful synchronize"); + LogDebug("Notifying after successful synchronize"); m_synchronizationObject->NotifyAll(); } }; @@ -74,14 +75,14 @@ SqlConnection::DataCommand::DataCommand(SqlConnection *connection, &m_stmt, NULL); if (ret == SQLITE_OK) { - VcoreLogD("Data command prepared successfuly"); + LogDebug("Data command prepared successfuly"); break; } else if (ret == SQLITE_BUSY) { - VcoreLogD("Collision occurred while preparing SQL command"); + LogDebug("Collision occurred while preparing SQL command"); // Synchronize if synchronization object is available if (connection->m_synchronizationObject) { - VcoreLogD("Performing synchronization"); + LogDebug("Performing synchronization"); connection->m_synchronizationObject->Synchronize(); continue; } @@ -92,14 +93,14 @@ SqlConnection::DataCommand::DataCommand(SqlConnection *connection, // Fatal error const char *error = sqlite3_errmsg(m_masterConnection->m_connection); - VcoreLogD("SQL prepare data command failed"); - VcoreLogD(" Statement: %s", buffer); - VcoreLogD(" Error: %s", error); + LogDebug("SQL prepare data command failed"); + LogDebug(" Statement : " << buffer); + LogDebug(" Error : " << error); ThrowMsg(Exception::SyntaxError, error); } - VcoreLogD("Prepared data command: %s", buffer); + LogDebug("Prepared data command : " << buffer); // Increment stored data command count ++m_masterConnection->m_dataCommandsCount; @@ -107,10 +108,10 @@ SqlConnection::DataCommand::DataCommand(SqlConnection *connection, SqlConnection::DataCommand::~DataCommand() { - VcoreLogD("SQL data command finalizing"); + LogDebug("SQL data command finalizing"); if (sqlite3_finalize(m_stmt) != SQLITE_OK) { - VcoreLogD("Failed to finalize data command"); + LogDebug("Failed to finalize data command"); } // Decrement stored data command count @@ -123,8 +124,8 @@ void SqlConnection::DataCommand::CheckBindResult(int result) const char *error = sqlite3_errmsg( m_masterConnection->m_connection); - VcoreLogD("Failed to bind SQL statement parameter"); - VcoreLogD(" Error: %s", error); + LogDebug("Failed to bind SQL statement parameter"); + LogDebug(" Error : " << error); ThrowMsg(Exception::SyntaxError, error); } @@ -134,7 +135,7 @@ void SqlConnection::DataCommand::BindNull( SqlConnection::ArgumentIndex position) { CheckBindResult(sqlite3_bind_null(m_stmt, position)); - VcoreLogD("SQL data command bind null: [%i]", position); + LogDebug("SQL data command bind null: [" << position << "]"); } void SqlConnection::DataCommand::BindInteger( @@ -142,7 +143,7 @@ void SqlConnection::DataCommand::BindInteger( int value) { CheckBindResult(sqlite3_bind_int(m_stmt, position, value)); - VcoreLogD("SQL data command bind integer: [%i] -> %i", position, value); + LogDebug("SQL data command bind integer: [" << position << "] -> " << value); } void SqlConnection::DataCommand::BindInt8( @@ -151,7 +152,7 @@ void SqlConnection::DataCommand::BindInt8( { CheckBindResult(sqlite3_bind_int(m_stmt, position, static_cast(value))); - VcoreLogD("SQL data command bind int8: [%i] -> %i", position, value); + LogDebug("SQL data command bind int8: [" << position << "] -> " << value); } void SqlConnection::DataCommand::BindInt16( @@ -160,8 +161,7 @@ void SqlConnection::DataCommand::BindInt16( { CheckBindResult(sqlite3_bind_int(m_stmt, position, static_cast(value))); - VcoreLogD("SQL data command bind int16: [%i] -> %i", position, value); -} + LogDebug("SQL data command bind int16: [" << position << "] -> " << value);} void SqlConnection::DataCommand::BindInt32( SqlConnection::ArgumentIndex position, @@ -169,7 +169,7 @@ void SqlConnection::DataCommand::BindInt32( { CheckBindResult(sqlite3_bind_int(m_stmt, position, static_cast(value))); - VcoreLogD("SQL data command bind int32: [%i] -> %i", position, value); + LogDebug("SQL data command bind int32: [" << position << "] -> " << value); } void SqlConnection::DataCommand::BindInt64( @@ -178,7 +178,7 @@ void SqlConnection::DataCommand::BindInt64( { CheckBindResult(sqlite3_bind_int64(m_stmt, position, static_cast(value))); - VcoreLogD("SQL data command bind int64: [%i] -> %lli", position, value); + LogDebug("SQL data command bind int64: [" << position << "] -> " << value); } void SqlConnection::DataCommand::BindFloat( @@ -187,7 +187,7 @@ void SqlConnection::DataCommand::BindFloat( { CheckBindResult(sqlite3_bind_double(m_stmt, position, static_cast(value))); - VcoreLogD("SQL data command bind float: [%i] -> %f", position, value); + LogDebug("SQL data command bind float: [" << position << "] -> " << value); } void SqlConnection::DataCommand::BindDouble( @@ -195,7 +195,7 @@ void SqlConnection::DataCommand::BindDouble( double value) { CheckBindResult(sqlite3_bind_double(m_stmt, position, value)); - VcoreLogD("SQL data command bind double: [%i] -> %f", position, value); + LogDebug("SQL data command bind double: [" << position << "] -> " << value); } void SqlConnection::DataCommand::BindString( @@ -212,7 +212,7 @@ void SqlConnection::DataCommand::BindString( value, strlen(value), SQLITE_TRANSIENT)); - VcoreLogD("SQL data command bind string: [%i] -> %s", position, value); + LogDebug("SQL data command bind string: [" << position << "] -> " << value); } void SqlConnection::DataCommand::BindString( @@ -320,17 +320,17 @@ bool SqlConnection::DataCommand::Step() int ret = sqlite3_step(m_stmt); if (ret == SQLITE_ROW) { - VcoreLogD("SQL data command step ROW"); + LogDebug("SQL data command step ROW"); return true; } else if (ret == SQLITE_DONE) { - VcoreLogD("SQL data command step DONE"); + LogDebug("SQL data command step DONE"); return false; } else if (ret == SQLITE_BUSY) { - VcoreLogD("Collision occurred while executing SQL command"); + LogDebug("Collision occurred while executing SQL command"); // Synchronize if synchronization object is available if (m_masterConnection->m_synchronizationObject) { - VcoreLogD("Performing synchronization"); + LogDebug("Performing synchronization"); m_masterConnection-> m_synchronizationObject->Synchronize(); @@ -344,8 +344,8 @@ bool SqlConnection::DataCommand::Step() // Fatal error const char *error = sqlite3_errmsg(m_masterConnection->m_connection); - VcoreLogD("SQL step data command failed"); - VcoreLogD(" Error: %s", error); + LogDebug("SQL step data command failed"); + LogDebug(" Error : " << error); ThrowMsg(Exception::InternalError, error); } @@ -363,7 +363,7 @@ void SqlConnection::DataCommand::Reset() */ sqlite3_reset(m_stmt); - VcoreLogD("SQL data command reset"); + LogDebug("SQL data command reset"); } void SqlConnection::DataCommand::CheckColumnIndex( @@ -377,7 +377,7 @@ void SqlConnection::DataCommand::CheckColumnIndex( bool SqlConnection::DataCommand::IsColumnNull( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column type: [%i]", column); + LogDebug("SQL data command get column type: [" << column << "]"); CheckColumnIndex(column); return sqlite3_column_type(m_stmt, column) == SQLITE_NULL; } @@ -385,83 +385,83 @@ bool SqlConnection::DataCommand::IsColumnNull( int SqlConnection::DataCommand::GetColumnInteger( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column integer: [%i]", column); + LogDebug("SQL data command get column integer: [" << column << "]"); CheckColumnIndex(column); int value = sqlite3_column_int(m_stmt, column); - VcoreLogD(" Value: %i", value); + LogDebug(" Value : " << value); return value; } int8_t SqlConnection::DataCommand::GetColumnInt8( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column int8: [%i]", column); + LogDebug("SQL data command get column int8: [" << column << "]"); CheckColumnIndex(column); int8_t value = static_cast(sqlite3_column_int(m_stmt, column)); - VcoreLogD(" Value: %i", value); + LogDebug(" Value : " << value); return value; } int16_t SqlConnection::DataCommand::GetColumnInt16( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column int16: [%i]", column); + LgDebug("SQL data command get column int16: [" << column << "]"); CheckColumnIndex(column); int16_t value = static_cast(sqlite3_column_int(m_stmt, column)); - VcoreLogD(" Value: %i", value); + LogDebug(" Value : " << value); return value; } int32_t SqlConnection::DataCommand::GetColumnInt32( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column int32: [%i]", column); + LogDebug("SQL data command get column int32: [" << column << "]"); CheckColumnIndex(column); int32_t value = static_cast(sqlite3_column_int(m_stmt, column)); - VcoreLogD(" Value: %i", value); + LogDebug(" Value : " << value); return value; } int64_t SqlConnection::DataCommand::GetColumnInt64( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column int64: [%i]", column); + LogDebug("SQL data command get column int64: [" << column << "]"); CheckColumnIndex(column); int64_t value = static_cast(sqlite3_column_int64(m_stmt, column)); - VcoreLogD(" Value: %lli", value); + LogDebug(" Value : " << value); return value; } float SqlConnection::DataCommand::GetColumnFloat( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column float: [%i]", column); + LogDebug("SQL data command get column float: [" << column << "]"); CheckColumnIndex(column); float value = static_cast(sqlite3_column_double(m_stmt, column)); - VcoreLogD(" Value: %f", value); + LogDebug(" Value : " << value); return value; } double SqlConnection::DataCommand::GetColumnDouble( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column double: [%i]", column); + LogDebug("SQL data command get column double: [" << column << "]"); CheckColumnIndex(column); double value = sqlite3_column_double(m_stmt, column); - VcoreLogD(" Value: %f", value); + LogDebug(" Value : " << value); return value; } std::string SqlConnection::DataCommand::GetColumnString( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column string: [%i]", column); + LogDebug("SQL data command get column string: [" << column << "]"); CheckColumnIndex(column); const char *value = reinterpret_cast( sqlite3_column_text(m_stmt, column)); - VcoreLogD(" Value: %s", value); + LogDebug(" Value : " << value); if (value == NULL) { return std::string(); @@ -473,105 +473,105 @@ std::string SqlConnection::DataCommand::GetColumnString( boost::optional SqlConnection::DataCommand::GetColumnOptionalInteger( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column optional integer: [%i]", column); + LogDebug("SQL data command get column optional integer: [" << column << "]"); CheckColumnIndex(column); if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { return boost::optional(); } int value = sqlite3_column_int(m_stmt, column); - VcoreLogD(" Value: %i", value); + LogDebug(" Value : " << value); return boost::optional(value); } boost::optional SqlConnection::DataCommand::GetColumnOptionalInt8( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column optional int8: [%i]", column); + LogDebug("SQL data command get column optional int8: [" << column << "]"); CheckColumnIndex(column); if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { return boost::optional(); } int8_t value = static_cast(sqlite3_column_int(m_stmt, column)); - VcoreLogD(" Value: %i", value); + LogDebug(" Value: " << value); return boost::optional(value); } boost::optional SqlConnection::DataCommand::GetColumnOptionalInt16( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column optional int16: [%i]", column); + LogDebug("SQL data command get column optional int16: [" << column << "]"); CheckColumnIndex(column); if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { return boost::optional(); } int16_t value = static_cast(sqlite3_column_int(m_stmt, column)); - VcoreLogD(" Value: %i", value); + LogDebug(" Value : " << value); return boost::optional(value); } boost::optional SqlConnection::DataCommand::GetColumnOptionalInt32( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column optional int32: [%i]", column); + LogDebug("SQL data command get column optional int32: [" << column << "]"); CheckColumnIndex(column); if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { return boost::optional(); } int32_t value = static_cast(sqlite3_column_int(m_stmt, column)); - VcoreLogD(" Value: %i", value); + LogDebug(" Value : " << value); return boost::optional(value); } boost::optional SqlConnection::DataCommand::GetColumnOptionalInt64( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column optional int64: [%i]", column); + LogDebug("SQL data command get column optional int64: [" << column << "]"); CheckColumnIndex(column); if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { return boost::optional(); } int64_t value = static_cast(sqlite3_column_int64(m_stmt, column)); - VcoreLogD(" Value: %lli", value); + LogDebug(" Value : " << value); return boost::optional(value); } boost::optional SqlConnection::DataCommand::GetColumnOptionalFloat( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column optional float: [%i]", column); + LogDebug("SQL data command get column optional float: [" << column << "]"); CheckColumnIndex(column); if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { return boost::optional(); } float value = static_cast(sqlite3_column_double(m_stmt, column)); - VcoreLogD(" Value: %f", value); + LogDebug(" Value : " << value); return boost::optional(value); } boost::optional SqlConnection::DataCommand::GetColumnOptionalDouble( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column optional double: [%i]", column); + LogDebug("SQL data command get column optional double: [" << column << "]"); CheckColumnIndex(column); if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { return boost::optional(); } double value = sqlite3_column_double(m_stmt, column); - VcoreLogD(" Value: %f", value); + LogDebug(" Value : " << value); return boost::optional(value); } boost::optional SqlConnection::DataCommand::GetColumnOptionalString( SqlConnection::ColumnIndex column) { - VcoreLogD("SQL data command get column optional string: [%i]", column); + LogDebug("SQL data command get column optional string: [" << column << "]"); CheckColumnIndex(column); if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { return boost::optional(); } const char *value = reinterpret_cast( sqlite3_column_text(m_stmt, column)); - VcoreLogD(" Value: %s", value); + LogDebug(" Value : " << value); String s = FromUTF8String(value); return boost::optional(s); } @@ -581,10 +581,10 @@ void SqlConnection::Connect(const std::string &address, Flag::Option flag) { if (m_connection != NULL) { - VcoreLogD("Already connected."); + LogDebug("Already connected."); return; } - VcoreLogD("Connecting to DB: %s...", address.c_str()); + LogDebug("Connecting to DB: " << address << "..."); // Connect to database int result; @@ -596,7 +596,7 @@ void SqlConnection::Connect(const std::string &address, NULL); m_usingLucene = true; - VcoreLogD("Lucene index enabled"); + LogDebug("Lucene index enabled"); } else { result = sqlite3_open_v2( address.c_str(), @@ -605,13 +605,13 @@ void SqlConnection::Connect(const std::string &address, NULL); m_usingLucene = false; - VcoreLogD("Lucene index disabled"); + LogDebug("Lucene index disabled"); } if (result == SQLITE_OK) { - VcoreLogD("Connected to DB"); + LogDebug("Connected to DB"); } else { - VcoreLogD("Failed to connect to DB!"); + LogDebug("Failed to connect to DB!"); ThrowMsg(Exception::ConnectionBroken, address); } @@ -622,11 +622,11 @@ void SqlConnection::Connect(const std::string &address, void SqlConnection::Disconnect() { if (m_connection == NULL) { - VcoreLogD("Already disconnected."); + LogDebug("Already disconnected."); return; } - VcoreLogD("Disconnecting from DB..."); + LogDebug("Disconnecting from DB..."); // All stored data commands must be deleted before disconnect AssertMsg(m_dataCommandsCount == 0, @@ -643,20 +643,20 @@ void SqlConnection::Disconnect() if (result != SQLITE_OK) { const char *error = sqlite3_errmsg(m_connection); - VcoreLogD("SQL close failed"); - VcoreLogD(" Error: %s", error); + LogDebug("SQL close failed"); + LogDebug(" Error : " << error); Throw(Exception::InternalError); } m_connection = NULL; - VcoreLogD("Disconnected from DB"); + LogDebug("Disconnected from DB"); } bool SqlConnection::CheckTableExist(const char *tableName) { if (m_connection == NULL) { - VcoreLogD("Cannot execute command. Not connected to DB!"); + LogDebug("Cannot execute command. Not connected to DB!"); return false; } @@ -666,7 +666,7 @@ bool SqlConnection::CheckTableExist(const char *tableName) command->BindString(1, tableName); if (!command->Step()) { - VcoreLogD("No matching records in table"); + LogDebug("No matching records in table"); return false; } @@ -682,19 +682,19 @@ SqlConnection::SqlConnection(const std::string &address, m_dataCommandsCount(0), m_synchronizationObject(synchronizationObject) { - VcoreLogD("Opening database connection to: %s", address.c_str()); + LogDebug("Opening database connection to : " << address); // Connect to DB SqlConnection::Connect(address, flag, option); if (!m_synchronizationObject) { - VcoreLogD("No synchronization object defined"); + LogDebug("No synchronization object defined"); } } SqlConnection::~SqlConnection() { - VcoreLogD("Closing database connection"); + LogDebug("Closing database connection"); // Disconnect from DB Try @@ -703,19 +703,19 @@ SqlConnection::~SqlConnection() } Catch(Exception::Base) { - VcoreLogD("Failed to disconnect from database"); + LogDebug("Failed to disconnect from database"); } } void SqlConnection::ExecCommand(const char *format, ...) { if (m_connection == NULL) { - VcoreLogD("Cannot execute command. Not connected to DB!"); + LogDebug("Cannot execute command. Not connected to DB!"); return; } if (format == NULL) { - VcoreLogD("Null query!"); + LogDebug("Null query!"); ThrowMsg(Exception::SyntaxError, "Null statement"); } @@ -733,11 +733,11 @@ void SqlConnection::ExecCommand(const char *format, ...) std::unique_ptr buffer(rawBuffer); if (!buffer) { - VcoreLogD("Failed to allocate statement string"); + LogDebug("Failed to allocate statement string"); return; } - VcoreLogD("Executing SQL command: %s", buffer.get()); + LogDebug("Executing SQL command : " << buffer.get()); // Notify all after potentially synchronized database connection access ScopedNotifyAll notifyAll(m_synchronizationObject.get()); @@ -764,11 +764,11 @@ void SqlConnection::ExecCommand(const char *format, ...) } if (ret == SQLITE_BUSY) { - VcoreLogD("Collision occurred while executing SQL command"); + LogDebug("Collision occurred while executing SQL command"); // Synchronize if synchronization object is available if (m_synchronizationObject) { - VcoreLogD("Performing synchronization"); + LogDebug("Performing synchronization"); m_synchronizationObject->Synchronize(); continue; } @@ -777,7 +777,7 @@ void SqlConnection::ExecCommand(const char *format, ...) } // Fatal error - VcoreLogD("Failed to execute SQL command. Error: %s", errorMsg.c_str()); + LogDebug("Failed to execute SQL command. Error : " << errorMsg); ThrowMsg(Exception::SyntaxError, errorMsg); } } @@ -787,7 +787,7 @@ SqlConnection::DataCommandAutoPtr SqlConnection::PrepareDataCommand( ...) { if (m_connection == NULL) { - VcoreLogD("Cannot execute data command. Not connected to DB!"); + LogDebug("Cannot execute data command. Not connected to DB!"); return DataCommandAutoPtr(); } @@ -805,11 +805,11 @@ SqlConnection::DataCommandAutoPtr SqlConnection::PrepareDataCommand( std::unique_ptr buffer(rawBuffer); if (!buffer) { - VcoreLogD("Failed to allocate statement string"); + LogDebug("Failed to allocate statement string"); return DataCommandAutoPtr(); } - VcoreLogD("Executing SQL data command: %s", buffer.get()); + LogDebug("Executing SQL data command : " << buffer.get()); return DataCommandAutoPtr(new DataCommand(this, buffer.get())); } @@ -851,7 +851,7 @@ int SqlConnection::db_util_open_with_options(const char *pszFilePath, sqlite3 ** int mode; if((pszFilePath == NULL) || (ppDB == NULL)) { - VcoreLogW("sqlite3 handle null error"); + LogWarning("sqlite3 handle null error"); return SQLITE_ERROR; } @@ -859,7 +859,7 @@ int SqlConnection::db_util_open_with_options(const char *pszFilePath, sqlite3 ** if((geteuid() != 0) && (access(pszFilePath, mode))) { if(errno == EACCES) { - VcoreLogD("file access permission error"); + LogDebug("file access permission error"); return SQLITE_PERM; } } @@ -867,7 +867,7 @@ int SqlConnection::db_util_open_with_options(const char *pszFilePath, sqlite3 ** /* Open DB */ int rc = sqlite3_open_v2(pszFilePath, ppDB, flags, zVfs); if (SQLITE_OK != rc) { - VcoreLogE("sqlite3_open_v2 error(%d)",rc); + LogError("sqlite3_open_v2 error(" << rc << ")"); return rc; } @@ -884,7 +884,7 @@ int SqlConnection::db_util_close(sqlite3 *pDB) /* Close DB */ int rc = sqlite3_close(pDB); if (SQLITE_OK != rc) { - VcoreLogW("Fail to change journal mode: %s\n", pszErrorMsg); + LogWarning("Fail to change journal mode : " << pszErrorMsg); sqlite3_free(pszErrorMsg); return rc; } diff --git a/vcore/src/dpl/log/include/dpl/log/abstract_log_provider.h b/vcore/src/dpl/log/include/dpl/log/abstract_log_provider.h index 9061156..f2f7730 100644 --- a/vcore/src/dpl/log/include/dpl/log/abstract_log_provider.h +++ b/vcore/src/dpl/log/include/dpl/log/abstract_log_provider.h @@ -26,31 +26,27 @@ namespace VcoreDPL { namespace Log { class AbstractLogProvider { - public: +public: + enum class LogLevel { + None, + Error, + Warning, + Info, + Debug, + Pedantic + }; + virtual ~AbstractLogProvider() {} - virtual void Debug(const char *message, - const char *fileName, - int line, - const char *function) = 0; - virtual void Info(const char *message, - const char *fileName, - int line, - const char *function) = 0; - virtual void Warning(const char *message, - const char *fileName, - int line, - const char *function) = 0; - virtual void Error(const char *message, - const char *fileName, - int line, - const char *function) = 0; - virtual void Pedantic(const char *message, - const char *fileName, - int line, - const char *function) = 0; + virtual void SetTag(const char *tag); + + virtual void Log(LogLevel level, + const char *message, + const char *fileName, + int line, + const char *function) const = 0; - protected: +protected: static const char *LocateSourceFileName(const char *filename); }; } diff --git a/vcore/src/dpl/log/include/dpl/log/dlog_log_provider.h b/vcore/src/dpl/log/include/dpl/log/dlog_log_provider.h index 263d1e3..5f96eb5 100644 --- a/vcore/src/dpl/log/include/dpl/log/dlog_log_provider.h +++ b/vcore/src/dpl/log/include/dpl/log/dlog_log_provider.h @@ -23,49 +23,28 @@ #define DPL_DLOG_LOG_PROVIDER_H #include -#include -#include +#include namespace VcoreDPL { namespace Log { -class DLOGLogProvider : - public AbstractLogProvider +class DLOGLogProvider : public AbstractLogProvider { - private: - VcoreDPL::ScopedFree m_tag; - - static std::string FormatMessage(const char *message, - const char *filename, - int line, - const char *function); - - public: +public: DLOGLogProvider(); virtual ~DLOGLogProvider(); - virtual void Debug(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Info(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Warning(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Error(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Pedantic(const char *message, - const char *fileName, - int line, - const char *function); + virtual void Log(AbstractLogProvider::LogLevel level, + const char *message, + const char *fileName, + int line, + const char *function) const; // Set global Tag according to DLOG - void SetTag(const char *tag); + virtual void SetTag(const char *tag); + +private: + std::unique_ptr m_tag; + }; } } // namespace VcoreDPL diff --git a/vcore/src/dpl/log/include/dpl/log/journal_log_provider.h b/vcore/src/dpl/log/include/dpl/log/journal_log_provider.h new file mode 100644 index 0000000..b20e880 --- /dev/null +++ b/vcore/src/dpl/log/include/dpl/log/journal_log_provider.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +/* + * @file journal_log_provider.h + * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com) + * @version 1.0 + */ + +#pragma once + +#include + +namespace VcoreDPL { +namespace Log { + +class JournalLogProvider: public AbstractLogProvider +{ +public: + JournalLogProvider(); + virtual ~JournalLogProvider(); + + virtual void Log(AbstractLogProvider::LogLevel level, + const char *message, + const char *fileName, + int line, + const char *function) const; +}; + +} /* namespace Log */ +} /* namespace VcoreDPL */ diff --git a/vcore/src/dpl/log/include/dpl/log/log.h b/vcore/src/dpl/log/include/dpl/log/log.h index 43f4844..33ab7d5 100644 --- a/vcore/src/dpl/log/include/dpl/log/log.h +++ b/vcore/src/dpl/log/include/dpl/log/log.h @@ -22,13 +22,15 @@ #ifndef DPL_LOG_H #define DPL_LOG_H +#include +#include +#include +#include + #include #include + #include -#include -#include -#include -#include namespace VcoreDPL { namespace Log { @@ -38,62 +40,20 @@ namespace Log { * To switch logs into old style, export * DPL_USE_OLD_STYLE_LOGS before application start */ -class LogSystem : - private Noncopyable +class LogSystem : private Noncopyable { - private: - typedef std::list AbstractLogProviderPtrList; - AbstractLogProviderPtrList m_providers; - - DLOGLogProvider *m_dlogProvider; - OldStyleLogProvider *m_oldStyleProvider; - - bool m_isLoggingEnabled; - - public: - bool IsLoggingEnabled() const; +public: LogSystem(); virtual ~LogSystem(); - /** - * Log debug message - */ - void Debug(const char *message, - const char *filename, - int line, - const char *function); - - /** - * Log info message - */ - void Info(const char *message, - const char *filename, - int line, - const char *function); + AbstractLogProvider::LogLevel GetLogLevel() const { return m_level; } - /** - * Log warning message - */ - void Warning(const char *message, - const char *filename, - int line, - const char *function); + void Log(AbstractLogProvider::LogLevel level, + const char *message, + const char *filename, + int line, + const char *function) const; - /** - * Log error message - */ - void Error(const char *message, - const char *filename, - int line, - const char *function); - - /** - * Log pedantic message - */ - void Pedantic(const char *message, - const char *filename, - int line, - const char *function); /** * Set default's DLOG provider Tag @@ -111,6 +71,32 @@ class LogSystem : * Remove abstract provider from providers list */ void RemoveProvider(AbstractLogProvider *provider); + + /** + * Selects given provider by name (overwrites environment setting) + * + * Throws std::out_of_range exception if not found. + */ + void SelectProvider(const std::string& name); + + /** + * Sets log level (overwrites environment settings) + */ + void SetLogLevel(const char* level); + +private: + void RemoveProviders(); + + typedef std::list AbstractLogProviderPtrList; + AbstractLogProviderPtrList m_providers; + AbstractLogProvider::LogLevel m_level; + + typedef AbstractLogProvider *(*ProviderFn)(); + /* + * It cannot be global as it is used in library constructor and we can't be sure which + * constructor is called first: library's or new_provider's. + */ + std::unordered_map m_providerCtor; }; /* @@ -135,37 +121,42 @@ typedef Singleton LogSystemSingleton; } } // namespace VcoreDPL -// -// Log support -// -// - -#ifdef DPL_LOGS_ENABLED - #define DPL_MACRO_FOR_LOGGING(message, function) \ - do \ - { \ - if (VcoreDPL::Log::LogSystemSingleton::Instance().IsLoggingEnabled()) \ - { \ - std::ostringstream platformLog; \ - platformLog << message; \ - VcoreDPL::Log::LogSystemSingleton::Instance().function( \ - platformLog.str().c_str(), \ - __FILE__, __LINE__, __FUNCTION__); \ - } \ - } while (0) -#else + /* avoid warnings about unused variables */ - #define DPL_MACRO_FOR_LOGGING(message, function) \ - do { \ +#define DPL_MACRO_DUMMY_LOGGING(message, level) \ + do { \ VcoreDPL::Log::NullStream ns; \ - ns << message; \ + ns << message; \ } while (0) -#endif -#define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, Debug) -#define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, Info) -#define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, Warning) -#define LogError(message) DPL_MACRO_FOR_LOGGING(message, Error) -#define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, Pedantic) +#define DPL_MACRO_FOR_LOGGING(message, level) \ +do \ +{ \ + if (level > VcoreDPL::Log::AbstractLogProvider::LogLevel::None && \ + VcoreDPL::Log::LogSystemSingleton::Instance().GetLogLevel() >= level) \ + { \ + std::ostringstream platformLog; \ + platformLog << message; \ + VcoreDPL::Log::LogSystemSingleton::Instance().Log(level, \ + platformLog.str().c_str(), \ + __FILE__, \ + __LINE__, \ + __FUNCTION__); \ + } \ +} while (0) + +#define LogError(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Error) + +#ifdef BUILD_TYPE_DEBUG + #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Debug) + #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Info) + #define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Warning) + #define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Pedantic) +#else + #define LogDebug(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Debug) + #define LogInfo(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Info) + #define LogWarning(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Warning) + #define LogPedantic(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Pedantic) +#endif // BUILD_TYPE_DEBUG #endif // DPL_LOG_H diff --git a/vcore/src/dpl/log/include/dpl/log/old_style_log_provider.h b/vcore/src/dpl/log/include/dpl/log/old_style_log_provider.h index fc14c7f..836a683 100644 --- a/vcore/src/dpl/log/include/dpl/log/old_style_log_provider.h +++ b/vcore/src/dpl/log/include/dpl/log/old_style_log_provider.h @@ -23,60 +23,20 @@ #define DPL_OLD_STYLE_LOG_PROVIDER_H #include -#include namespace VcoreDPL { namespace Log { -class OldStyleLogProvider : - public AbstractLogProvider +class OldStyleLogProvider : public AbstractLogProvider { - private: - bool m_showDebug; - bool m_showInfo; - bool m_showWarning; - bool m_showError; - bool m_showPedantic; - bool m_printStdErr; - - static std::string FormatMessage(const char *message, - const char *filename, - int line, - const char *function); - - public: - OldStyleLogProvider(bool showDebug, - bool showInfo, - bool showWarning, - bool showError, - bool showPedantic); - OldStyleLogProvider(bool showDebug, - bool showInfo, - bool showWarning, - bool showError, - bool showPedantic, - bool printStdErr); +public: + OldStyleLogProvider(); virtual ~OldStyleLogProvider() {} - virtual void Debug(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Info(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Warning(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Error(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Pedantic(const char *message, - const char *fileName, - int line, - const char *function); + virtual void Log(AbstractLogProvider::LogLevel level, + const char *message, + const char *fileName, + int line, + const char *function) const; }; } } // namespace VcoreDPL diff --git a/vcore/src/dpl/log/include/dpl/log/vcore_log.h b/vcore/src/dpl/log/include/dpl/log/vcore_log.h deleted file mode 100644 index 01116bf..0000000 --- a/vcore/src/dpl/log/include/dpl/log/vcore_log.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VCORE_LOG_H -#define VCORE_LOG_H - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CERT_SVC_VCORE" - -#include - -#define COLOR_ERROR "\033[38;5;160;1m" // bold red -#define COLOR_WARNING "\033[38;5;202;1m" // bold orange -#define COLOR_INFO "\033[38;5;243;1m" // bold light gray -#define COLOR_DEBUG "\033[38;5;243;0m" // normal light gray -#define COLOR_END "\033[0m" - -#define INTERNAL_SECURE_LOG __extension__ SECURE_SLOG -#define VCORE_LOG(priority, color, format, ...) \ -do { \ - INTERNAL_SECURE_LOG(priority, LOG_TAG, color format "%s", __VA_ARGS__); \ -} while(0) - - -/* - * Please use following macros - */ -#define VcoreLogD(...) VCORE_LOG(LOG_DEBUG, COLOR_DEBUG, __VA_ARGS__, COLOR_END) -#define VcoreLogI(...) VCORE_LOG(LOG_INFO, COLOR_INFO, __VA_ARGS__, COLOR_END) -#define VcoreLogW(...) VCORE_LOG(LOG_WARN, COLOR_WARNING, __VA_ARGS__, COLOR_END) -#define VcoreLogE(...) VCORE_LOG(LOG_ERROR, COLOR_ERROR, __VA_ARGS__, COLOR_END) - -#endif diff --git a/vcore/src/dpl/log/include/dpl/log/wrt_log.h b/vcore/src/dpl/log/include/dpl/log/wrt_log.h deleted file mode 100644 index b0a3d2e..0000000 --- a/vcore/src/dpl/log/include/dpl/log/wrt_log.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VCORE_WRT_LOG_H -#define VCORE_WRT_LOG_H - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CERT_SVC_VCORE" - -#include - -#define COLOR_ERROR "\033[38;5;160;1m" // bold red -#define COLOR_WARNING "\033[38;5;202;1m" // bold orange -#define COLOR_INFO "\033[38;5;243;1m" // bold light gray -#define COLOR_DEBUG "\033[38;5;243;0m" // normal light gray -#define COLOR_END "\033[0m" - -#define INTERNAL_SECURE_LOG __extension__ SECURE_SLOG -#define WRT_LOG(priority, color, format, ...) \ -do { \ - INTERNAL_SECURE_LOG(priority, LOG_TAG, color format "%s", __VA_ARGS__); \ -} while(0) - - -/* - * Please use following macros - */ -#define WrtLogD(...) WRT_LOG(LOG_DEBUG, COLOR_DEBUG, __VA_ARGS__, COLOR_END) -#define WrtLogI(...) WRT_LOG(LOG_INFO, COLOR_INFO, __VA_ARGS__, COLOR_END) -#define WrtLogW(...) WRT_LOG(LOG_WARN, COLOR_WARNING, __VA_ARGS__, COLOR_END) -#define WrtLogE(...) WRT_LOG(LOG_ERROR, COLOR_ERROR, __VA_ARGS__, COLOR_END) - -#endif diff --git a/vcore/src/dpl/log/src/abstract_log_provider.cpp b/vcore/src/dpl/log/src/abstract_log_provider.cpp index 05a80f7..56bc9a0 100644 --- a/vcore/src/dpl/log/src/abstract_log_provider.cpp +++ b/vcore/src/dpl/log/src/abstract_log_provider.cpp @@ -25,6 +25,9 @@ namespace VcoreDPL { namespace Log { + +void AbstractLogProvider::SetTag(const char *) {} + const char *AbstractLogProvider::LocateSourceFileName(const char *filename) { const char *ptr = strrchr(filename, '/'); diff --git a/vcore/src/dpl/log/src/dlog_log_provider.cpp b/vcore/src/dpl/log/src/dlog_log_provider.cpp index 8958fe0..29729e7 100644 --- a/vcore/src/dpl/log/src/dlog_log_provider.cpp +++ b/vcore/src/dpl/log/src/dlog_log_provider.cpp @@ -20,98 +20,87 @@ * @brief This file is the implementation file of DLOG log provider */ #include -#include #include #include -#include +#include +#include -#ifdef SECURE_LOG - #define INTERNAL_DLP_LOG_ SECURE_LOG -#else - #define INTERNAL_DLP_LOG_ LOG -#endif +#include -/* - * The __extension__ keyword in the following define is required because - * macros used here from dlog.h use non-standard extension that cause - * gcc to show unwanted warnings when compiling with -pedantic switch. - */ -#define INTERNAL_DLP_LOG __extension__ INTERNAL_DLP_LOG_ +#include namespace VcoreDPL { namespace Log { -std::string DLOGLogProvider::FormatMessage(const char *message, - const char *filename, - int line, - const char *function) -{ - std::ostringstream val; - val << std::string("[") << - LocateSourceFileName(filename) << std::string(":") << line << - std::string("] ") << function << std::string("(): ") << message; +namespace { +typedef void (*dlogMacro)(const char *, const char *); - return val.str(); +void error(const char *tag, const char *msg) +{ + SLOG(LOG_ERROR, tag, "%s", msg); } -DLOGLogProvider::DLOGLogProvider() -{} - -DLOGLogProvider::~DLOGLogProvider() -{} - -void DLOGLogProvider::SetTag(const char *tag) +void warning(const char *tag, const char *msg) { - m_tag.Reset(strdup(tag)); + SLOG(LOG_WARN, tag, "%s", msg); } -void DLOGLogProvider::Debug(const char *message, - const char *filename, - int line, - const char *function) +void info(const char *tag, const char *msg) { - INTERNAL_DLP_LOG(LOG_DEBUG, m_tag.Get(), "%s", - FormatMessage(message, filename, line, function).c_str()); + SLOG(LOG_INFO, tag, "%s", msg); } -void DLOGLogProvider::Info(const char *message, - const char *filename, - int line, - const char *function) +void debug(const char *tag, const char *msg) { - INTERNAL_DLP_LOG(LOG_INFO, m_tag.Get(), "%s", - FormatMessage(message, filename, line, function).c_str()); + SLOG(LOG_DEBUG, tag, "%s", msg); } -void DLOGLogProvider::Warning(const char *message, - const char *filename, - int line, - const char *function) +void pedantic(const char *tag, const char *msg) { - INTERNAL_DLP_LOG(LOG_WARN, m_tag.Get(), "%s", - FormatMessage(message, filename, line, function).c_str()); + SLOG(LOG_VERBOSE, tag, "%s", msg); } -void DLOGLogProvider::Error(const char *message, - const char *filename, - int line, - const char *function) +std::map dlogMacros = { + // [](const char* tag, const char* msg) { SLOG(LOG_ERROR, tag, "%s", msg); } won't compile + { AbstractLogProvider::LogLevel::Error, error }, + { AbstractLogProvider::LogLevel::Warning, warning }, + { AbstractLogProvider::LogLevel::Info, info }, + { AbstractLogProvider::LogLevel::Debug, debug}, + { AbstractLogProvider::LogLevel::Pedantic, pedantic} +}; + +} // namespace anonymous + +DLOGLogProvider::DLOGLogProvider() +{} + +DLOGLogProvider::~DLOGLogProvider() +{} + +void DLOGLogProvider::SetTag(const char *tag) { - INTERNAL_DLP_LOG(LOG_ERROR, m_tag.Get(), "%s", - FormatMessage(message, filename, line, function).c_str()); + size_t size = strlen(tag)+1; + char *buff = new (std::nothrow) char[size]; + if (buff) + memcpy(buff, tag, size); + m_tag.reset(buff); } -void DLOGLogProvider::Pedantic(const char *message, - const char *filename, - int line, - const char *function) +void DLOGLogProvider::Log(AbstractLogProvider::LogLevel level, + const char *message, + const char *filename, + int line, + const char *function) const { - INTERNAL_DLP_LOG(LOG_DEBUG, "DPL", "%s", - FormatMessage(message, filename, line, function).c_str()); + std::ostringstream val; + val << std::string("[") << LocateSourceFileName(filename) << std::string(":") << line << + std::string("] ") << function << std::string("(): ") << message; + + try { + dlogMacros.at(level)(m_tag.get(), val.str().c_str()); + } catch (const std::out_of_range&) { + SLOG(LOG_ERROR, m_tag.get(), "Unsupported log level: %d", level); + } } } } // namespace VcoreDPL - -#undef INTERNAL_DLP_LOG -#undef INTERNAL_DLP_LOG_ - diff --git a/vcore/src/dpl/log/src/journal_log_provider.cpp b/vcore/src/dpl/log/src/journal_log_provider.cpp new file mode 100644 index 0000000..71ec2fe --- /dev/null +++ b/vcore/src/dpl/log/src/journal_log_provider.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +/* + * @file journal_log_provider.cpp + * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com) + * @version 1.0 + */ + +#include +#include +#include +#include + +namespace VcoreDPL { +namespace Log { + +namespace { +std::map journalLevel = { + { AbstractLogProvider::LogLevel::Error, LOG_ERR }, + { AbstractLogProvider::LogLevel::Warning, LOG_WARNING }, + { AbstractLogProvider::LogLevel::Info, LOG_INFO }, + { AbstractLogProvider::LogLevel::Debug, LOG_DEBUG }, + { AbstractLogProvider::LogLevel::Pedantic, LOG_DEBUG } +}; + +} // namespace anonymous + +JournalLogProvider::JournalLogProvider() +{} + +JournalLogProvider::~JournalLogProvider() +{} + +void JournalLogProvider::Log(AbstractLogProvider::LogLevel level, + const char *message, + const char *fileName, + int line, + const char *function) const +{ + try { + sd_journal_send("PRIORITY=%d", journalLevel.at(level), + "CODE_FILE=%s", fileName, + "CODE_FUNC=%s", function, + "CODE_LINE=%d", line, + // add file, line & function info to log message + "MESSAGE=[%s:%d] %s(): %s", fileName, line, function, message, + NULL); + } catch (const std::out_of_range&) { + sd_journal_send( + "PRIORITY=%d", LOG_ERR, + "CODE_FILE=%s", fileName, + "CODE_FUNC=%s", function, + "CODE_LINE=%d", line, + // add file, line & function info to log message + "MESSAGE=[%s:%d] %s(): Unsupported log level %d", fileName, line, function, level, + NULL); + } +} + +} /* namespace Log */ +} /* namespace VcoreDPL */ diff --git a/vcore/src/dpl/log/src/log.cpp b/vcore/src/dpl/log/src/log.cpp index 283b849..c2acbf1 100644 --- a/vcore/src/dpl/log/src/log.cpp +++ b/vcore/src/dpl/log/src/log.cpp @@ -20,8 +20,16 @@ * @brief This file is the implementation file of log system */ #include -#include +#include +#include +#include + #include +#include +#include +#include + +#include IMPLEMENT_SINGLETON(VcoreDPL::Log::LogSystem) @@ -29,119 +37,44 @@ namespace VcoreDPL { namespace Log { namespace // anonymous { -const char *OLD_STYLE_LOGS_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS"; -const char *OLD_STYLE_PEDANTIC_LOGS_ENV_NAME = - "DPL_USE_OLD_STYLE_PEDANTIC_LOGS"; -const char *OLD_STYLE_LOGS_MASK_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS_MASK"; -const char *DPL_LOG_OFF = "DPL_LOG_OFF"; -} // namespace anonymous +const char *const CERTSVC_LOG_LEVEL = "CERTSVC_LOG_LEVEL"; +const char *const CERTSVC_LOG_PROVIDER = "CERTSVC_LOG_PROVIDER"; -bool LogSystem::IsLoggingEnabled() const -{ - return m_isLoggingEnabled; -} +const char *const CONSOLE = "CONSOLE"; +const char *const DLOG = "DLOG"; +const char *const JOURNALD = "JOURNALD"; +} // namespace anonymous -LogSystem::LogSystem() : - m_dlogProvider(NULL), - m_oldStyleProvider(NULL), - m_isLoggingEnabled(!getenv(DPL_LOG_OFF)) +LogSystem::LogSystem() + : m_providerCtor({ +#ifdef BUILD_TYPE_DEBUG + { CONSOLE, []{ return static_cast(new OldStyleLogProvider()); }}, +#endif + { DLOG, []{ return static_cast(new DLOGLogProvider()); }}, + { JOURNALD, []{ return static_cast(new JournalLogProvider()); }} + }) { - bool oldStyleLogs = false; - bool oldStyleDebugLogs = true; - bool oldStyleInfoLogs = true; - bool oldStyleWarningLogs = true; - bool oldStyleErrorLogs = true; - bool oldStylePedanticLogs = false; - - // Check environment settings about pedantic logs - const char *value = getenv(OLD_STYLE_LOGS_ENV_NAME); - - if (value != NULL && !strcmp(value, "1")) { - oldStyleLogs = true; - } + SetLogLevel(getenv(CERTSVC_LOG_LEVEL)); - value = getenv(OLD_STYLE_PEDANTIC_LOGS_ENV_NAME); - - if (value != NULL && !strcmp(value, "1")) { - oldStylePedanticLogs = true; + AbstractLogProvider *prv = NULL; + try { + prv = m_providerCtor.at(getenv(CERTSVC_LOG_PROVIDER))(); + } catch (const std::exception &) { + prv = m_providerCtor[JOURNALD](); } - value = getenv(OLD_STYLE_LOGS_MASK_ENV_NAME); - - if (value != NULL) { - size_t len = strlen(value); - - if (len >= 1) { - if (value[0] == '0') { - oldStyleDebugLogs = false; - } else if (value[0] == '1') { - oldStyleDebugLogs = true; - } - } - - if (len >= 2) { - if (value[1] == '0') { - oldStyleInfoLogs = false; - } else if (value[1] == '1') { - oldStyleInfoLogs = true; - } - } - - if (len >= 3) { - if (value[2] == '0') { - oldStyleWarningLogs = false; - } else if (value[2] == '1') { - oldStyleWarningLogs = true; - } - } - - if (len >= 4) { - if (value[3] == '0') { - oldStyleErrorLogs = false; - } else if (value[3] == '1') { - oldStyleErrorLogs = true; - } - } - } - - // Setup default DLOG and old style logging - if (oldStyleLogs) { - // Old style - m_oldStyleProvider = new OldStyleLogProvider(oldStyleDebugLogs, - oldStyleInfoLogs, - oldStyleWarningLogs, - oldStyleErrorLogs, - oldStylePedanticLogs); - AddProvider(m_oldStyleProvider); - } else { - // DLOG - m_dlogProvider = new DLOGLogProvider(); - AddProvider(m_dlogProvider); - } + AddProvider(prv); } LogSystem::~LogSystem() { - // Delete all providers - for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); - iterator != m_providers.end(); - ++iterator) - { - delete *iterator; - } - - m_providers.clear(); - - // And even default providers - m_dlogProvider = NULL; - m_oldStyleProvider = NULL; + RemoveProviders(); } void LogSystem::SetTag(const char* tag) { - if (m_dlogProvider != NULL) { - m_dlogProvider->SetTag(tag); - } + for (auto &it : m_providers) + it->SetTag(tag); } void LogSystem::AddProvider(AbstractLogProvider *provider) @@ -154,69 +87,49 @@ void LogSystem::RemoveProvider(AbstractLogProvider *provider) m_providers.remove(provider); } -void LogSystem::Debug(const char *message, - const char *filename, - int line, - const char *function) +void LogSystem::SelectProvider(const std::string &name) { - for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); - iterator != m_providers.end(); - ++iterator) - { - (*iterator)->Debug(message, filename, line, function); - } -} + ProviderFn& prv = m_providerCtor.at(name); -void LogSystem::Info(const char *message, - const char *filename, - int line, - const char *function) -{ - for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); - iterator != m_providers.end(); - ++iterator) - { - (*iterator)->Info(message, filename, line, function); - } + RemoveProviders(); + AddProvider(prv()); } -void LogSystem::Warning(const char *message, - const char *filename, - int line, - const char *function) +void LogSystem::SetLogLevel(const char *level) { - for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); - iterator != m_providers.end(); - ++iterator) - { - (*iterator)->Warning(message, filename, line, function); + try { + m_level = static_cast(std::stoi(level)); + } catch(const std::exception&) { + m_level = AbstractLogProvider::LogLevel::Debug; } + + if (m_level < AbstractLogProvider::LogLevel::None) + m_level = AbstractLogProvider::LogLevel::None; + else if (m_level > AbstractLogProvider::LogLevel::Pedantic) + m_level = AbstractLogProvider::LogLevel::Pedantic; + +#ifndef BUILD_TYPE_DEBUG + if (m_level > AbstractLogProvider::LogLevel::Error) + m_level = AbstractLogProvider::LogLevel::Error; +#endif // BUILD_TYPE_DEBUG } -void LogSystem::Error(const char *message, - const char *filename, - int line, - const char *function) +void LogSystem::Log(AbstractLogProvider::LogLevel level, + const char *message, + const char *filename, + int line, + const char *function) const { - for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); - iterator != m_providers.end(); - ++iterator) - { - (*iterator)->Error(message, filename, line, function); - } + for (const auto &it : m_providers) + it->Log(level, message, filename, line, function); } -void LogSystem::Pedantic(const char *message, - const char *filename, - int line, - const char *function) +void LogSystem::RemoveProviders() { - for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); - iterator != m_providers.end(); - ++iterator) - { - (*iterator)->Pedantic(message, filename, line, function); - } + for (auto &it : m_providers) + delete it; + + m_providers.clear(); } } } // namespace VcoreDPL diff --git a/vcore/src/dpl/log/src/old_style_log_provider.cpp b/vcore/src/dpl/log/src/old_style_log_provider.cpp index d13c66e..419c07f 100644 --- a/vcore/src/dpl/log/src/old_style_log_provider.cpp +++ b/vcore/src/dpl/log/src/old_style_log_provider.cpp @@ -20,13 +20,16 @@ * @brief This file is the implementation file of old style log provider */ #include -#include -#include +#include +#include #include #include #include -#include -#include +#include +#include + +#include +#include namespace VcoreDPL { namespace Log { @@ -62,139 +65,43 @@ std::string GetFormattedTime() static_cast(tv.tv_usec / 1000)); return format; } -} // namespace anonymous - -std::string OldStyleLogProvider::FormatMessage(const char *message, - const char *filename, - int line, - const char *function) -{ - std::ostringstream val; - - val << std::string("[") << GetFormattedTime() << std::string("] [") << - static_cast(pthread_self()) << "/" << - static_cast(getpid()) << std::string("] [") << - LocateSourceFileName(filename) << std::string(":") << line << - std::string("] ") << function << std::string("(): ") << message; - - return val.str(); -} -OldStyleLogProvider::OldStyleLogProvider(bool showDebug, - bool showInfo, - bool showWarning, - bool showError, - bool showPedantic) : - m_showDebug(showDebug), - m_showInfo(showInfo), - m_showWarning(showWarning), - m_showError(showError), - m_showPedantic(showPedantic), - m_printStdErr(false) -{} +struct ColorMark { + const char *const begin; + const char *const end; +}; -OldStyleLogProvider::OldStyleLogProvider(bool showDebug, - bool showInfo, - bool showWarning, - bool showError, - bool showPedantic, - bool printStdErr) : - m_showDebug(showDebug), - m_showInfo(showInfo), - m_showWarning(showWarning), - m_showError(showError), - m_showPedantic(showPedantic), - m_printStdErr(printStdErr) -{} +std::map consoleLevel = { + { AbstractLogProvider::LogLevel::Error, {ERROR_BEGIN, ERROR_END} }, + { AbstractLogProvider::LogLevel::Warning, {WARNING_BEGIN, WARNING_END} }, + { AbstractLogProvider::LogLevel::Info, {INFO_BEGIN, INFO_END} }, + { AbstractLogProvider::LogLevel::Debug, {DEBUG_BEGIN, DEBUG_END} }, + { AbstractLogProvider::LogLevel::Pedantic, {PEDANTIC_BEGIN, PEDANTIC_END} } +}; -void OldStyleLogProvider::Debug(const char *message, - const char *filename, - int line, - const char *function) -{ - if (m_showDebug) { - if (m_printStdErr) { - fprintf(stderr, "%s%s%s\n", DEBUG_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), DEBUG_END); - } else { - fprintf(stdout, "%s%s%s\n", DEBUG_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), DEBUG_END); - } - } -} +} // namespace anonymous -void OldStyleLogProvider::Info(const char *message, - const char *filename, - int line, - const char *function) -{ - if (m_showInfo) { - if (m_printStdErr) { - fprintf(stderr, "%s%s%s\n", INFO_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), INFO_END); - } else { - fprintf(stdout, "%s%s%s\n", INFO_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), INFO_END); - } - } -} +OldStyleLogProvider::OldStyleLogProvider() {} -void OldStyleLogProvider::Warning(const char *message, - const char *filename, - int line, - const char *function) +void OldStyleLogProvider::Log(AbstractLogProvider::LogLevel level, + const char *message, + const char *filename, + int line, + const char *function) const { - if (m_showWarning) { - if (m_printStdErr) { - fprintf(stderr, "%s%s%s\n", WARNING_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), WARNING_END); - } else { - fprintf(stdout, "%s%s%s\n", WARNING_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), WARNING_END); - } - } -} + try { + const struct ColorMark& mark = consoleLevel.at(level); -void OldStyleLogProvider::Error(const char *message, - const char *filename, - int line, - const char *function) -{ - if (m_showError) { - if (m_printStdErr) { - fprintf(stderr, "%s%s%s\n", ERROR_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), ERROR_END); - } else { - fprintf(stdout, "%s%s%s\n", ERROR_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), ERROR_END); - } + std::ostringstream val; + val << mark.begin << std::string("[") << GetFormattedTime() << std::string("] [") << + static_cast(pthread_self()) << "/" << static_cast(getpid()) << + std::string("] [") << LocateSourceFileName(filename) << std::string(":") << line << + std::string("] ") << function << std::string("(): ") << message << mark.end; + fprintf(stdout, "%s\n", val.str().c_str()); + } catch (const std::out_of_range&) { + fprintf(stdout, "Unsupported log level: %d\n", level); } } -void OldStyleLogProvider::Pedantic(const char *message, - const char *filename, - int line, - const char *function) -{ - if (m_showPedantic) { - if (m_printStdErr) { - fprintf(stderr, "%s%s%s\n", PEDANTIC_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), PEDANTIC_END); - } else { - fprintf(stdout, "%s%s%s\n", PEDANTIC_BEGIN, - FormatMessage(message, filename, line, - function).c_str(), PEDANTIC_END); - } - } -} } } // namespace VcoreDPL diff --git a/vcore/src/dpl/test/src/process_pipe.cpp b/vcore/src/dpl/test/src/process_pipe.cpp index 11023f7..6e4fb74 100644 --- a/vcore/src/dpl/test/src/process_pipe.cpp +++ b/vcore/src/dpl/test/src/process_pipe.cpp @@ -20,8 +20,7 @@ * @brief This file is the implementation pipe from process */ -#include -#include +#include namespace VcoreDPL { @@ -60,8 +59,6 @@ void ProcessPipe::Open(const std::string & command) // Save new descriptor m_file = file; m_fd = fileno(m_file); - - VcoreLogD("Opened pipe: %s", fcommand.c_str()); } void ProcessPipe::Close() @@ -76,8 +73,6 @@ void ProcessPipe::Close() m_fd = -1; m_file = NULL; - - VcoreLogD("Closed pipe"); } } diff --git a/vcore/src/vcore/Base64.cpp b/vcore/src/vcore/Base64.cpp index e3a1abe..85edcae 100644 --- a/vcore/src/vcore/Base64.cpp +++ b/vcore/src/vcore/Base64.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include @@ -37,7 +37,7 @@ Base64Encoder::Base64Encoder() : void Base64Encoder::append(const std::string &data) { if (m_finalized) { - WrtLogW("Already finalized."); + LogWarning("Already finalized."); VcoreThrowMsg(Exception::AlreadyFinalized, "Already finalized"); } @@ -50,7 +50,7 @@ void Base64Encoder::append(const std::string &data) void Base64Encoder::finalize() { if (m_finalized) { - WrtLogW("Already finalized."); + LogWarning("Already finalized."); VcoreThrowMsg(Exception::AlreadyFinalized, "Already finalized."); } m_finalized = true; @@ -62,13 +62,13 @@ void Base64Encoder::finalize() std::string Base64Encoder::get() { if (!m_finalized) { - WrtLogW("Not finalized"); + LogWarning("Not finalized"); VcoreThrowMsg(Exception::NotFinalized, "Not finalized"); } BUF_MEM *bptr = 0; BIO_get_mem_ptr(m_b64, &bptr); if (bptr == 0) { - WrtLogE("Bio internal error"); + LogError("Bio internal error"); VcoreThrowMsg(Exception::InternalError, "Bio internal error"); } @@ -85,7 +85,7 @@ void Base64Encoder::reset() m_b64 = BIO_new(BIO_f_base64()); m_bmem = BIO_new(BIO_s_mem()); if (!m_b64 || !m_bmem) { - WrtLogE("Error during allocation memory in BIO"); + LogError("Error during allocation memory in BIO"); VcoreThrowMsg(Exception::InternalError, "Error during allocation memory in BIO"); } @@ -106,7 +106,7 @@ Base64Decoder::Base64Decoder() : void Base64Decoder::append(const std::string &data) { if (m_finalized) { - WrtLogW("Already finalized."); + LogWarning("Already finalized."); VcoreThrowMsg(Exception::AlreadyFinalized, "Already finalized."); } m_input.append(data); @@ -121,7 +121,7 @@ static bool whiteCharacter(char a) bool Base64Decoder::finalize() { if (m_finalized) { - WrtLogW("Already finalized."); + LogWarning("Already finalized."); VcoreThrowMsg(Exception::AlreadyFinalized, "Already finalized."); } @@ -140,7 +140,7 @@ bool Base64Decoder::finalize() { continue; } - WrtLogE("Base64 input contains illegal chars: %c", m_input[i]); + LogError("Base64 input contains illegal chars: " << m_input[i]); return false; } @@ -150,14 +150,14 @@ bool Base64Decoder::finalize() VcoreDPL::ScopedFree buffer(static_cast(malloc(len))); if (!buffer) { - WrtLogE("Error in malloc."); + LogError("Error in malloc."); VcoreThrowMsg(Exception::InternalError, "Error in malloc."); } memset(buffer.Get(), 0, len); b64 = BIO_new(BIO_f_base64()); if (!b64) { - WrtLogE("Couldn't create BIO object."); + LogError("Couldn't create BIO object."); VcoreThrowMsg(Exception::InternalError, "Couldn't create BIO object."); } BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); @@ -168,7 +168,7 @@ bool Base64Decoder::finalize() if (!bmem) { BIO_free(b64); - WrtLogE("Internal error in BIO"); + LogError("Internal error in BIO"); VcoreThrowMsg(Exception::InternalError, "Internal error in BIO"); } @@ -176,7 +176,7 @@ bool Base64Decoder::finalize() if (!bmem) { BIO_free(b64); - WrtLogE("Internal error in BIO"); + LogError("Internal error in BIO"); VcoreThrowMsg(Exception::InternalError, "Internal error in BIO"); } @@ -198,7 +198,7 @@ bool Base64Decoder::finalize() std::string Base64Decoder::get() const { if (!m_finalized) { - WrtLogW("Not finalized."); + LogWarning("Not finalized."); VcoreThrowMsg(Exception::NotFinalized, "Not finalized"); } return m_output; diff --git a/vcore/src/vcore/CRLImpl.cpp b/vcore/src/vcore/CRLImpl.cpp index 6602e17..1912a5d 100644 --- a/vcore/src/vcore/CRLImpl.cpp +++ b/vcore/src/vcore/CRLImpl.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include #include @@ -52,10 +52,10 @@ CRL::StringList CRLImpl::getCrlUris(const CertificatePtr &argCert) { CRL::StringList result = argCert->getCrlUris(); - if (!result.empty()) { + if (!result.empty()) return result; - } - WrtLogI("No distribution points found. Getting from CA cert."); + + LogInfo("No distribution points found. Getting from CA cert."); X509_STORE_CTX *ctx = createContext(argCert); X509_OBJECT obj; @@ -66,7 +66,7 @@ CRL::StringList CRLImpl::getCrlUris(const CertificatePtr &argCert) &obj); X509_STORE_CTX_free(ctx); if (0 >= retVal) { - WrtLogE("No dedicated CA certificate available"); + LogError("No dedicated CA certificate available"); return result; } CertificatePtr caCert(new Certificate(obj.data.x509)); @@ -79,7 +79,7 @@ CRLImpl::CRLImpl(CRLCacheInterface *ptr) { Assert(m_crlCache != NULL); - WrtLogI("CRL storage initialization."); + LogInfo("CRL storage initialization."); m_store = X509_STORE_new(); if (!m_store) VcoreThrowMsg(CRLException::StorageError, @@ -99,7 +99,7 @@ CRLImpl::CRLImpl(CRLCacheInterface *ptr) VcoreThrowMsg(CRLException::StorageError, "Failed to add lookup dir for PEM files"); } - WrtLogI("CRL storage initialization complete."); + LogInfo("CRL storage initialization complete."); } CRLImpl::~CRLImpl() @@ -110,7 +110,7 @@ CRLImpl::~CRLImpl() void CRLImpl::cleanup() { - WrtLogI("Free CRL storage"); + LogInfo("Free CRL storage"); // STORE is responsible for LOOKUP release // X509_LOOKUP_free(m_lookup); X509_STORE_free(m_store); @@ -124,7 +124,7 @@ CRL::RevocationStatus CRLImpl::checkCertificate(const CertificatePtr &argCert) FOREACH(it, crlUris) { CRLDataPtr crl = getCRL(*it); if (!crl) { - WrtLogD("CRL not found for URI: %s", (*it).c_str()); + LogDebug("CRL not found for URI: " << *it); continue; } X509_CRL *crlInternal = convertToInternal(crl); @@ -138,17 +138,17 @@ CRL::RevocationStatus CRLImpl::checkCertificate(const CertificatePtr &argCert) // If nextUpdate is not set assume it is actual. retStatus.isCRLValid = true; } - WrtLogI("CRL valid: %d", retStatus.isCRLValid); + LogInfo("CRL valid: " << retStatus.isCRLValid); X509_REVOKED rev; rev.serialNumber = X509_get_serialNumber(argCert->getX509()); // sk_X509_REVOKED_find returns index if serial number is found on list retVal = sk_X509_REVOKED_find(crlInternal->crl->revoked, &rev); X509_CRL_free(crlInternal); retStatus.isRevoked = retVal != -1; - WrtLogI("CRL revoked: %d", retStatus.isRevoked); + LogInfo("CRL revoked: " << retStatus.isRevoked); if (!retStatus.isRevoked && isOutOfDate(crl)) { - WrtLogD("Certificate is not Revoked, but CRL is outOfDate."); + LogDebug("Certificate is not Revoked, but CRL is outOfDate."); continue; } @@ -171,7 +171,7 @@ CRL::RevocationStatus CRLImpl::checkCertificateChain(CertificateCollection certC const CertificateList &certList = certChain.getChain(); FOREACH(it, certList) { if (!(*it)->isRootCert()) { - WrtLogI("Certificate common name: %s", (*it)->getCommonName().c_str()); + LogInfo("Certificate common name: " << (*it)->getCommonName()); CRL::RevocationStatus certResult = checkCertificate(*it); ret.isCRLValid &= certResult.isCRLValid; ret.isRevoked |= certResult.isRevoked; @@ -191,7 +191,7 @@ CRL::RevocationStatus CRLImpl::checkCertificateChain(CertificateCollection certC VerificationStatus CRLImpl::checkEndEntity(CertificateCollection &chain) { if (!chain.sort() && !chain.empty()) { - WrtLogI("Could not find End Entity certificate. " + LogInfo("Could not find End Entity certificate. " "Collection does not form chain."); return VERIFICATION_STATUS_ERROR; } @@ -231,13 +231,13 @@ bool CRLImpl::isOutOfDate(const CRLDataPtr &crl) const { bool CRLImpl::updateList(const CertificatePtr &argCert, const CRL::UpdatePolicy updatePolicy) { - WrtLogI("Update CRL for certificate"); + LogInfo("Update CRL for certificate"); // Retrieve distribution points CRL::StringList crlUris = getCrlUris(argCert); FOREACH(it, crlUris) { // Try to get CRL from database - WrtLogI("Getting CRL for URI: %s", (*it).c_str()); + LogInfo("Getting CRL for URI: " << *it); bool downloaded = false; @@ -250,24 +250,24 @@ bool CRLImpl::updateList(const CertificatePtr &argCert, } if (!!crl && isOutOfDate(crl)) { - WrtLogD("Crl out of date - downloading."); + LogDebug("Crl out of date - downloading."); crl = downloadCRL(*it); downloaded = true; } if (!crl) { - WrtLogD("Crl not found in cache - downloading."); + LogDebug("Crl not found in cache - downloading."); crl = downloadCRL(*it); downloaded = true; } if (!crl) { - WrtLogD("Failed to obtain CRL. URL: %s", (*it).c_str()); + LogDebug("Failed to obtain CRL. URL: " << *it); continue; } if (!!crl && isOutOfDate(crl)) { - WrtLogE("CRL out of date. Broken URL: %s", (*it).c_str()); + LogError("CRL out of date. Broken URL: " << *it); } // Make X509 internal structure @@ -275,7 +275,7 @@ bool CRLImpl::updateList(const CertificatePtr &argCert, //Check if CRL is signed if (!verifyCRL(crlInternal, argCert)) { - WrtLogE("Failed to verify CRL. URI: %s", (crl->uri).c_str()); + LogError("Failed to verify CRL. URI: " << (crl->uri).c_str()); X509_CRL_free(crlInternal); return false; } @@ -320,7 +320,7 @@ bool CRLImpl::verifyCRL(X509_CRL *crl, X509_CRL_get_issuer(crl), &obj); X509_STORE_CTX_free(ctx); if (0 >= retVal) { - WrtLogE("Unknown CRL issuer certificate!"); + LogError("Unknown CRL issuer certificate!"); return false; } @@ -328,19 +328,19 @@ bool CRLImpl::verifyCRL(X509_CRL *crl, EVP_PKEY *pkey = X509_get_pubkey(obj.data.x509); X509_OBJECT_free_contents(&obj); if (!pkey) { - WrtLogE("Failed to get issuer's public key."); + LogError("Failed to get issuer's public key."); return false; } retVal = X509_CRL_verify(crl, pkey); EVP_PKEY_free(pkey); if (0 > retVal) { - WrtLogE("Failed to verify CRL."); + LogError("Failed to verify CRL."); return false; } else if (0 == retVal) { - WrtLogE("CRL is invalid"); + LogError("CRL is invalid"); return false; } - WrtLogI("CRL is valid."); + LogInfo("CRL is valid."); return true; } @@ -349,10 +349,10 @@ bool CRLImpl::isPEMFormat(const CRLDataPtr &crl) const const char *pattern = "-----BEGIN X509 CRL-----"; std::string content(crl->buffer, crl->length); if (content.find(pattern) != std::string::npos) { - WrtLogI("CRL is in PEM format."); + LogInfo("CRL is in PEM format."); return true; } - WrtLogI("CRL is in DER format."); + LogInfo("CRL is in DER format."); return false; } @@ -406,7 +406,7 @@ CRLImpl::CRLDataPtr CRLImpl::downloadCRL(const std::string &uri) &cpath, &use_ssl)) { - WrtLogW("Error in OCSP_parse_url"); + LogWarning("Error in OCSP_parse_url"); return CRLDataPtr(); } @@ -425,7 +425,7 @@ CRLImpl::CRLDataPtr CRLImpl::downloadCRL(const std::string &uri) message.setHeader("Host", host); if (SoupMessageSendSync::REQUEST_STATUS_OK != message.sendSync()) { - WrtLogW("Error in sending network request."); + LogWarning("Error in sending network request."); return CRLDataPtr(); } @@ -438,13 +438,13 @@ CRLImpl::CRLDataPtr CRLImpl::getCRL(const std::string &uri) const CRLCachedData cachedCrl; cachedCrl.distribution_point = uri; if (!(m_crlCache->getCRLResponse(&cachedCrl))) { - WrtLogI("CRL not present in database. URI: %s", uri.c_str()); + LogInfo("CRL not present in database. URI: " << uri); return CRLDataPtr(); } std::string body = cachedCrl.crl_body; - WrtLogI("CRL found in database."); + LogInfo("CRL found in database."); //TODO: remove when ORM::blob available //Encode buffer to base64 format to store in database diff --git a/vcore/src/vcore/CachedCRL.cpp b/vcore/src/vcore/CachedCRL.cpp index bdc5123..ff9afe1 100644 --- a/vcore/src/vcore/CachedCRL.cpp +++ b/vcore/src/vcore/CachedCRL.cpp @@ -23,8 +23,7 @@ #include #include -#include -#include +#include #include #include @@ -86,7 +85,7 @@ VerificationStatus CachedCRL::check(const CertificateCollection &certs) } if (!allValid) { // problems with CRL validity - WrtLogD("Some CRLs not valid"); + LogDebug("Some CRLs not valid"); } CRL::RevocationStatus stat; Try { @@ -96,24 +95,22 @@ VerificationStatus CachedCRL::check(const CertificateCollection &certs) return VERIFICATION_STATUS_ERROR; } if (stat.isRevoked) { - WrtLogD("Status REVOKED"); + LogDebug("Status REVOKED"); return VERIFICATION_STATUS_REVOKED; } - WrtLogD("Status GOOD"); + LogDebug("Status GOOD"); return VERIFICATION_STATUS_GOOD; } VerificationStatus CachedCRL::checkEndEntity(CertificateCollection &certs) { if (certs.empty()) { - WrtLogE("Collection empty. This should never happen."); - WrtLogD("Status ERROR"); + LogError("Collection empty. This should never happen."); return VERIFICATION_STATUS_ERROR; } if (!certs.sort()) { - WrtLogE("Could not find End Entity certificate. " + LogError("Could not find End Entity certificate. " "Collection does not form chain."); - WrtLogD("Status ERROR"); return VERIFICATION_STATUS_ERROR; } CRLImpl crl(new CRLCacheDAO); @@ -131,15 +128,15 @@ VerificationStatus CachedCRL::checkEndEntity(CertificateCollection &certs) } if (!allValid) { // problems with CRL validity - WrtLogD("Some CRLs not valid"); + LogDebug("Some CRLs not valid"); } CertificateList::const_iterator iter = certs.begin(); CRL::RevocationStatus stat = crl.checkCertificate(*iter); if (stat.isRevoked) { - WrtLogD("Status REVOKED"); + LogDebug("Status REVOKED"); return VERIFICATION_STATUS_REVOKED; } - WrtLogD("Status GOOD"); + LogDebug("Status GOOD"); return VERIFICATION_STATUS_GOOD; } @@ -164,7 +161,7 @@ bool CachedCRL::updateCRLForUri(const std::string &uri, bool useExpiredShift) } if (CertificateCacheDAO::getCRLResponse(&cachedCRL)) { if (now < cachedCRL.next_update_time) { - WrtLogD("Cached CRL still valid for: %s", uri.c_str()); + LogDebug("Cached CRL still valid for : " << uri); return true; } } @@ -172,7 +169,7 @@ bool CachedCRL::updateCRLForUri(const std::string &uri, bool useExpiredShift) CRLImpl crl(new CRLCacheDAO); CRLImpl::CRLDataPtr list = crl.downloadCRL(uri); if (!list) { - WrtLogW("Could not retreive CRL from %s", uri.c_str()); + LogWarning("Could not retreive CRL from " << uri); return false; } crl.updateCRL(list); diff --git a/vcore/src/vcore/CachedOCSP.cpp b/vcore/src/vcore/CachedOCSP.cpp index 48c613f..bdf29a8 100644 --- a/vcore/src/vcore/CachedOCSP.cpp +++ b/vcore/src/vcore/CachedOCSP.cpp @@ -25,8 +25,7 @@ #include #include -#include -#include +#include #include #include @@ -75,9 +74,9 @@ VerificationStatus CachedOCSP::check(const CertificateCollection &certs) db_status.end_entity_check = false; if (CertificateCacheDAO::getOCSPStatus(&db_status)) { - WrtLogD("Found cache entry for OCSP"); + LogDebug("Found cache entry for OCSP"); if (now < db_status.next_update_time) { - WrtLogD("Cache response valid"); + LogDebug("Cache response valid"); return db_status.ocsp_status; } } @@ -109,9 +108,9 @@ VerificationStatus CachedOCSP::checkEndEntity(CertificateCollection &certs) db_status.end_entity_check = true; if (CertificateCacheDAO::getOCSPStatus(&db_status)) { - WrtLogD("Found cache entry for OCSP"); + LogDebug("Found cache entry for OCSP"); if (now < db_status.next_update_time) { - WrtLogD("Cache response valid"); + LogDebug("Cache response valid"); return db_status.ocsp_status; } } @@ -150,7 +149,7 @@ void CachedOCSP::updateCache() CertificateCollection col; col.load(db_status->cert_chain); if (!col.sort()) { - WrtLogE("Certificate collection does not create chain."); + LogError("Certificate collection does not create chain."); continue; } @@ -183,7 +182,7 @@ void CachedOCSP::getCertsForEndEntity( const CertificateCollection &certs, CertificateList* clst) { if (NULL == clst) { - WrtLogE("NULL pointer"); + LogError("NULL pointer"); return; } diff --git a/vcore/src/vcore/Certificate.cpp b/vcore/src/vcore/Certificate.cpp index 55bcd3a..e332880 100644 --- a/vcore/src/vcore/Certificate.cpp +++ b/vcore/src/vcore/Certificate.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include @@ -69,7 +69,7 @@ Certificate::Certificate(const std::string &der, base64.reset(); base64.append(der); if (!base64.finalize()) { - WrtLogW("Error during decoding"); + LogWarning("Error during decoding"); } tmp = base64.get(); ptr = reinterpret_cast(tmp.c_str()); @@ -120,7 +120,7 @@ std::string Certificate::getBase64(void) const bool Certificate::isSignedBy(const CertificatePtr &parent) const { if (!parent) { - WrtLogD("Invalid certificate parameter."); + LogDebug("Invalid certificate parameter."); return false; } return 0 == X509_NAME_cmp(X509_get_subject_name(parent->m_x509), @@ -318,10 +318,10 @@ Certificate::AltNameSet Certificate::getAlternativeNameDNS() const } else { set.insert(std::string(temp)); - WrtLogD("FOUND GEN_DNS: %s", temp); + LogDebug("FOUND GEN_DNS: " << temp); } } else { - WrtLogD("FOUND GEN TYPE ID: %d", namePart->type); + LogDebug("FOUND GEN TYPE ID: " << namePart->type); } } return set; @@ -397,7 +397,7 @@ Certificate::getCrlUris() const NULL, NULL)); if (!distPoints) { - WrtLogD("No distribution points in certificate."); + LogDebug("No distribution points in certificate."); return result; } @@ -405,7 +405,7 @@ Certificate::getCrlUris() const for (int i = 0; i < count; ++i) { DIST_POINT* point = sk_DIST_POINT_value(distPoints, i); if (!point) { - WrtLogE("Failed to get distribution point."); + LogError("Failed to get distribution point."); continue; } if (point->distpoint != NULL && @@ -420,7 +420,7 @@ Certificate::getCrlUris() const char *crlUri = reinterpret_cast(name->d.ia5->data); if (!crlUri) { - WrtLogE("Failed to get URI."); + LogError("Failed to get URI."); continue; } result.push_back(crlUri); diff --git a/vcore/src/vcore/CertificateCacheDAO.cpp b/vcore/src/vcore/CertificateCacheDAO.cpp index c01fa7a..79863c2 100644 --- a/vcore/src/vcore/CertificateCacheDAO.cpp +++ b/vcore/src/vcore/CertificateCacheDAO.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -84,7 +84,7 @@ void CertificateCacheDAO::setOCSPStatus(const std::string& cert_chain, bool CertificateCacheDAO::getOCSPStatus(OCSPCachedStatus* cached_status) { if (NULL == cached_status) { - WrtLogE("NULL pointer"); + LogError("NULL pointer"); return false; } Try { @@ -105,7 +105,7 @@ bool CertificateCacheDAO::getOCSPStatus(OCSPCachedStatus* cached_status) return true; } - WrtLogD("Cached OCSP status not found"); + LogDebug("Cached OCSP status not found"); return false; } Catch(VcoreDPL::DB::SqlConnection::Exception::Base) { @@ -117,7 +117,7 @@ void CertificateCacheDAO::getOCSPStatusList( OCSPCachedStatusList* cached_status_list) { if (NULL == cached_status_list) { - WrtLogE("NULL pointer"); + LogError("NULL pointer"); return; } Try { @@ -183,7 +183,7 @@ void CertificateCacheDAO::setCRLResponse(const std::string& distribution_point, bool CertificateCacheDAO::getCRLResponse(CRLCachedData* cached_data) { if (NULL == cached_data) { - WrtLogE("NULL pointer"); + LogError("NULL pointer"); return false; } Try { @@ -200,7 +200,7 @@ bool CertificateCacheDAO::getCRLResponse(CRLCachedData* cached_data) return true; } - WrtLogD("Cached CRL not found"); + LogDebug("Cached CRL not found"); return false; } Catch(VcoreDPL::DB::SqlConnection::Exception::Base) { @@ -212,7 +212,7 @@ void CertificateCacheDAO::getCRLResponseList( CRLCachedDataList* cached_data_list) { if (NULL == cached_data_list) { - WrtLogE("NULL pointer"); + LogError("NULL pointer"); return; } Try { diff --git a/vcore/src/vcore/CertificateCollection.cpp b/vcore/src/vcore/CertificateCollection.cpp index 2f20146..8fe8953 100644 --- a/vcore/src/vcore/CertificateCollection.cpp +++ b/vcore/src/vcore/CertificateCollection.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include @@ -67,7 +67,7 @@ bool CertificateCollection::load(const std::string &buffer) base64.reset(); base64.append(buffer); if (!base64.finalize()) { - WrtLogW("Error during chain decoding"); + LogWarning("Error during chain decoding"); return false; } std::string binaryData = base64.get(); @@ -92,11 +92,11 @@ bool CertificateCollection::load(const std::string &buffer) rawDERCert.begin(), rawDERCert.end())))); } VcoreCatch (Certificate::Exception::Base) { - WrtLogW("Error during certificate creation."); + LogWarning("Error during certificate creation."); return false; } - WrtLogD("Loading certificate. Certificate common name: %s", list.back()->getCommonName().c_str()); + LogDebug("Loading certificate. Certificate common name: " << list.back()->getCommonName()); } load(list); return true; @@ -199,7 +199,7 @@ void CertificateCollection::sortCollection() } if (!issTransl.empty()) { - WrtLogW("Certificates don't form a valid chain."); + LogWarning("Certificates don't form a valid chain."); m_collectionStatus = COLLECTION_CHAIN_BROKEN; return; } diff --git a/vcore/src/vcore/CertificateLoader.cpp b/vcore/src/vcore/CertificateLoader.cpp index a934f67..1fc800f 100644 --- a/vcore/src/vcore/CertificateLoader.cpp +++ b/vcore/src/vcore/CertificateLoader.cpp @@ -15,171 +15,31 @@ */ #include #include -#include +#include #include #include #include #include #include + #ifdef TIZEN_FEATURE_CERT_SVC_OCSP_CRL #include #endif namespace { const int MIN_RSA_KEY_LENGTH = 1024; -//const char *OID_CURVE_SECP256R1 = "urn:oid:1.2.840.10045.3.1.7"; } // namespace anonymous namespace ValidationCore { -//// COMPARATOR CLASS START //// - -//class CertificateLoaderECDSA : public CertificateLoader::CertificateLoaderComparator, VcoreDPL::Noncopyable { -//public: -// CertificateLoaderECDSA(const std::string &publicKey) -// : m_ecPublicKey(NULL) -// , m_searchKey(NULL) -// { -// m_bnCtx = BN_CTX_new(); // if fails we can continue anyway -// m_tmpPoint = BN_new(); // if fails we can continue anyway -// m_initialized = CertificateLoader::convertBase64NodeToBigNum(publicKey, &m_searchKey); -// -// if(!m_initialized) -// WrtLogE("Init failed!"); -// } -// -// virtual bool compare(X509 *x509cert){ -// if(!m_initialized) -// return false; -// -// EVP_PKEY_free(m_ecPublicKey); -// -// m_ecPublicKey = X509_get_pubkey(x509cert); -// -// if(m_ecPublicKey == NULL) -// return false; -// -// if(m_ecPublicKey->type != EVP_PKEY_EC){ -// WrtLogE("ecPublicKey has wrong type!"); -// return false; -// } -// -// // Pointer to internal data of ecPublicKey. Do not free! -// EC_KEY *eckey = m_ecPublicKey->pkey.ec; -// -// const EC_POINT *ecpoint = EC_KEY_get0_public_key(eckey); -// const EC_GROUP *ecgroup = EC_KEY_get0_group(eckey); -// -// m_tmpPoint = EC_POINT_point2bn(ecgroup, ecpoint, POINT_CONVERSION_UNCOMPRESSED, m_tmpPoint, m_bnCtx); -// -// if(BN_cmp(m_tmpPoint, m_searchKey) == 0) -// return true; -// -// return false; -// } -// -// ~CertificateLoaderECDSA(){ -// BN_CTX_free(m_bnCtx); -// EVP_PKEY_free(m_ecPublicKey); -// BN_free(m_searchKey); -// BN_free(m_tmpPoint); -// } -// -//private: -// bool m_initialized; -// EVP_PKEY *m_ecPublicKey; -// BN_CTX *m_bnCtx; -// BIGNUM *m_searchKey; -// BIGNUM *m_tmpPoint; -//}; - -///// COMPARETORS CLASS END ///// - -//// COMPARATOR RSA CLASS START //// - -//class CertificateLoaderRSA : public CertificateLoader::CertificateLoaderComparator, VcoreDPL::Noncopyable { -//public: -// CertificateLoaderRSA(const std::string &m_modulus,const std::string &m_exponent ) -// : m_rsaPublicKey(NULL) -// , m_modulus_bn(NULL) -// , m_exponent_bn(NULL) -// { -// -// m_initialized_modulus = CertificateLoader::convertBase64NodeToBigNum(m_modulus, &m_modulus_bn); -// m_initialized_exponent = CertificateLoader::convertBase64NodeToBigNum(m_exponent, &m_exponent_bn); -// -// if(!m_initialized_modulus || !m_initialized_exponent) -// WrtLogE("Init failed!"); -// } -// -// virtual bool compare(X509 *x509cert){ -// -// if(!m_initialized_modulus || !m_initialized_exponent) -// return false; -// -// EVP_PKEY_free(m_rsaPublicKey); -// m_rsaPublicKey = X509_get_pubkey(x509cert); -// -// if(m_rsaPublicKey == NULL) -// return false; -// -// if(m_rsaPublicKey->type != EVP_PKEY_RSA){ -// WrtLogI("rsaPublicKey has wrong type!"); -// return false; -// } -// -// RSA *rsa = NULL; -// rsa = m_rsaPublicKey->pkey.rsa; -// -// if (BN_cmp(m_modulus_bn, rsa->n) == 0 && -// BN_cmp(m_exponent_bn, rsa->e) == 0 ){ -// WrtLogE ("Compare TRUE"); -// return true; -// } -// return false; -// } -// -// ~CertificateLoaderRSA(){ -// EVP_PKEY_free(m_rsaPublicKey); -// BN_free(m_modulus_bn); -// BN_free(m_exponent_bn); -// -// } -// -//private: -// bool m_initialized_modulus; -// bool m_initialized_exponent; -// EVP_PKEY *m_rsaPublicKey; -// BIGNUM *m_modulus_bn; -// BIGNUM *m_exponent_bn; -//}; - -///// COMPARETORS RSA CLASS END ///// - CertificateLoader::CertificateLoaderResult CertificateLoader:: loadCertificateBasedOnExponentAndModulus(const std::string &m_modulus, const std::string &m_exponent) { (void) m_modulus; (void) m_exponent; - WrtLogE("Not implemented."); + LogError("Not implemented."); return UNKNOWN_ERROR; - // if (m_exponent.empty() || m_modulus.empty()) - // return WRONG_ARGUMENTS; - // - // CertificateLoaderRSA comparator(m_modulus,m_exponent); - // - // CertificateLoaderResult result = NO_ERROR; - // for(int i=0; storeId[i]; ++i){ - // result = loadCertificate(std::string(storeId[i]), &comparator); - // - // if(result == ERR_NO_MORE_CERTIFICATES) - // continue; - // - // return result; - // } - // - // return result; } CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificate( @@ -188,248 +48,26 @@ CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificate( { (void) storageName; (void) cmp; - WrtLogE("Not Implemented"); + LogError("Not Implemented"); return UNKNOWN_ERROR; - // long int result = OPERATION_SUCCESS; - // - // char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE]; - // char type[CERTMGR_MAX_CERT_TYPE_SIZE]; - // certmgr_cert_id certId; - // certmgr_ctx context; - // certmgr_mem_buff certRetrieved; - // unsigned char buffer[CERTMGR_MAX_BUFFER_SIZE]; - // - // certmgr_cert_descriptor descriptor; - // - // certRetrieved.data = buffer; - // certRetrieved.firstFree = 0; - // certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE; - // certId.storeId = storeId; - // certId.type = type; - // - // CERTMGR_INIT_CONTEXT((&context), (sizeof(context))) - // - // strncpy(context.storeId, storageName.c_str(), storageName.size()); - // - // for(certRetrieved.firstFree = 0; - // OPERATION_SUCCESS == (result = certmgr_retrieve_certificate_from_store(&context, &certRetrieved, &certId)); - // certRetrieved.firstFree = 0) - // { - // - // if(OPERATION_SUCCESS!=certmgr_extract_certificate_data(&certRetrieved, &descriptor)){ - // WrtLogE("Extracting Certificate Data failed "); - // continue; - // } - // - // const unsigned char *ptr = certRetrieved.data; - // - // X509 *x509cert = d2i_X509(NULL, &ptr, certRetrieved.size); - // if(x509cert == NULL){ - // certmgr_release_certificate_data(&descriptor); - // WrtLogE("Error extracting certificate (d2i_X509)."); - // return UNKNOWN_ERROR; - // } - // - // WrtLogD("The subject of this certificate is %s", (descriptor.mandatory.subject)); - // if(cmp->compare(x509cert)){ - // WrtLogD("Found match. Coping bytes: %d", certRetrieved.size); - // m_certificatePtr = CertificatePtr(new Certificate(certRetrieved)); - // certmgr_release_certificate_data(&descriptor); - // X509_free(x509cert); - // break; - // } - // - // WrtLogD("Release"); - // X509_free(x509cert); - // certmgr_release_certificate_data(&descriptor); - // } - // - // if(ERR_NO_MORE_CERTIFICATES == result){ - // WrtLogE("Certificates for given DN not found"); - // return CERTIFICATE_NOT_FOUND; - // } - // - // if(result!= OPERATION_SUCCESS){ - // WrtLogE("Certificate Manager Error"); - // return UNKNOWN_ERROR; - // } - // - // WrtLogD("Exit"); - // return NO_ERROR; } -// TODO CertificateLoader::CertificateLoaderResult CertificateLoader:: loadCertificateBasedOnSubjectName(const std::string &subjectName) { (void) subjectName; - WrtLogE("Not implemented."); + LogError("Not implemented."); return UNKNOWN_ERROR; - // if(subjectName.empty()) - // { - // return WRONG_ARGUMENTS; - // } - // - // long int result = OPERATION_SUCCESS; - // - // char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE]; - // char type[CERTMGR_MAX_CERT_TYPE_SIZE]; - // certmgr_cert_id certId; - // certmgr_ctx context; - // certmgr_mem_buff certRetrieved; - // unsigned char buffer[CERTMGR_MAX_BUFFER_SIZE]; - // - // certmgr_cert_descriptor descriptor; - // - // certRetrieved.data = buffer; - // certRetrieved.firstFree = 0; - // certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE; - // certId.storeId = storeId; - // certId.type = type; - // - // CERTMGR_INIT_CONTEXT((&context), (sizeof(context))) - // - // for(certRetrieved.firstFree = 0; - // OPERATION_SUCCESS == (result = certmgr_retrieve_certificate_from_store(&context, &certRetrieved, &certId)); - // certRetrieved.firstFree = 0) - // { - // - // if(OPERATION_SUCCESS!=certmgr_extract_certificate_data(&certRetrieved, &descriptor)){ - // WrtLogE("Extracting Certificate Data failed "); - // continue; - // } - // - // if(!strcmp(subjectName.c_str(), descriptor.mandatory.subject)){ - // WrtLogD("The subject of this certificate is %s", descriptor.mandatory.subject); - // m_certificatePtr = CertificatePtr(new Certificate(certRetrieved)); - // certmgr_release_certificate_data(&descriptor); - // break; - // } - // WrtLogD("Release"); - // certmgr_release_certificate_data(&descriptor); - // } - // - // if(ERR_NO_MORE_CERTIFICATES == result) { - // WrtLogE("Certificates for given DN not found"); - // return CERTIFICATE_NOT_FOUND; - // } - // if(result!= OPERATION_SUCCESS){ - // WrtLogE("Certificate Manager Error"); - // return UNKNOWN_ERROR; - // } - // WrtLogD("Exit"); - // return NO_ERROR; } -// KW CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateBasedOnIssuerName(const std::string &issuerName, const std::string &serialNumber) -// KW { -// KW if(issuerName.empty() || serialNumber.empty()) -// KW { -// KW return WRONG_ARGUMENTS; -// KW } -// KW -// KW if(m_cmBuff.data){ -// KW delete[] m_cmBuff.data; -// KW memset(&m_cmBuff, 0, sizeof(certmgr_mem_buff)); -// KW } -// KW -// KW WrtLogD("IssuerName: %s , serialNumber: %s", issuerName.c_str(), serialNumber.c_str()); -// KW -// KW //used to check status of retrieved certificate -// KW long int result = OPERATION_SUCCESS; -// KW char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE]; -// KW char type[CERTMGR_MAX_CERT_TYPE_SIZE]; -// KW certmgr_cert_id certId; -// KW certmgr_ctx context; -// KW certmgr_mem_buff certRetrieved; -// KW unsigned char buffer[CERTMGR_MAX_BUFFER_SIZE]; -// KW -// KW certmgr_cert_descriptor descriptor; -// KW -// KW certRetrieved.data = buffer; -// KW certRetrieved.firstFree = 0; -// KW certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE; -// KW certId.storeId = storeId; -// KW certId.type = type; -// KW -// KW CERTMGR_INIT_CONTEXT((&context), (sizeof(context))) -// KW -// KW for(certRetrieved.firstFree = 0; -// KW OPERATION_SUCCESS == (result = certmgr_retrieve_certificate_from_store(&context, &certRetrieved, &certId)); -// KW certRetrieved.firstFree = 0) -// KW { -// KW -// KW WrtLogD("Extracting certificate from CertMgr"); -// KW -// KW if( OPERATION_SUCCESS != certmgr_extract_certificate_data(&certRetrieved, &descriptor) ){ -// KW WrtLogE("Extracting Certificate Data failed "); -// KW continue; -// KW } -// KW -// KW WrtLogD("Issuer: %s", (descriptor.mandatory.issuer).c_str()); -// KW -// KW const unsigned char *ptr = certRetrieved.data; -// KW char *tmp; -// KW -// KW X509 *x509cert = d2i_X509(NULL, &ptr, certRetrieved.size); -// KW std::string serialNO = std::string(tmp = i2s_ASN1_INTEGER(NULL, X509_get_serialNumber(x509cert))); -// KW OPENSSL_free(tmp); -// KW X509_free(x509cert); -// KW -// KW WrtLogI("Certificate number found: %d", serialNO); -// KW WrtLogI("Certificate number looking for: %d", serialNumber); -// KW -// KW if(!strcmp(issuerName.c_str(), descriptor.mandatory.issuer) -// KW && serialNumber == serialNO) -// KW { -// KW WrtLogE("The issuer of this certificate is %s", (descriptor.mandatory.issuer).c_str()); -// KW -// KW m_cmBuff.data = new unsigned char[certRetrieved.size]; -// KW m_cmBuff.firstFree = m_cmBuff.size = certRetrieved.size; -// KW memcpy(m_cmBuff.data, certRetrieved.data, certRetrieved.size); -// KW certmgr_release_certificate_data(&descriptor); -// KW break; -// KW } -// KW certmgr_release_certificate_data(&descriptor); -// KW } -// KW -// KW if(ERR_NO_MORE_CERTIFICATES == result) { -// KW WrtLogE("Certificates not found"); -// KW return CERTIFICATE_NOT_FOUND; -// KW } -// KW if(result != OPERATION_SUCCESS){ -// KW WrtLogE("Certificate Manager Error"); -// KW return UNKNOWN_ERROR; -// KW } -// KW return NO_ERROR; -// KW } - CertificateLoader::CertificateLoaderResult CertificateLoader:: loadCertificateWithECKEY(const std::string &curveName, const std::string &publicKey) { (void) curveName; (void) publicKey; - WrtLogE("Not implemented."); + LogError("Not implemented."); return UNKNOWN_ERROR; - // if(curveName != OID_CURVE_SECP256R1){ - // WrtLogE("Found field id: %s Expected:", curveName.c_str(), OID_CURVE_SECP256R1.c_str()); - // return UNSUPPORTED_CERTIFICATE_FIELD; - // } - // - // CertificateLoaderECDSA comparator(publicKey); - // - // CertificateLoaderResult result = NO_ERROR; - // for(int i=0; storeId[i]; ++i){ - // result = loadCertificate(std::string(storeId[i]), &comparator); - // - // if(result == ERR_NO_MORE_CERTIFICATES) - // continue; - // - // return result; - // } - // - // return result; } CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateFromRawData(const std::string &rawData) @@ -437,7 +75,7 @@ CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateFro VcoreTry { m_certificatePtr = CertificatePtr(new Certificate(rawData, Certificate::FORM_BASE64)); } VcoreCatch(Certificate::Exception::Base) { - WrtLogW("Error reading certificate by openssl."); + LogWarning("Error reading certificate by openssl."); return UNKNOWN_ERROR; } @@ -453,12 +91,11 @@ CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateFro // key Length (modulus) is in bytes keyLength <<= 3; - WrtLogD("RSA key length: %d bits", keyLength); + LogDebug("RSA key length: " << keyLength << " bits"); if (keyLength < MIN_RSA_KEY_LENGTH) { - WrtLogE( - "RSA key too short! Has only %d bits", keyLength); - return CERTIFICATE_SECURITY_ERROR; + LogError("RSA key too short! Has only " << keyLength << " bits"); + return CERTIFICATE_SECURITY_ERROR; } } } @@ -467,65 +104,6 @@ CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateFro return NO_ERROR; } -// DEPRACETED FUNCTION -//CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateFromRawData(const std::string &rawData) -//{ -// certmgr_mem_buff cmBuff = {0,0,0}; -// -// long int size; -// cmBuff.data = certmgr_util_base64_decode(const_cast(static_cast(rawData.c_str())), rawData.size(), &size); -// -// cmBuff.firstFree = cmBuff.size = size; -// -// certmgr_cert_descriptor descriptor; -// -// long int result = certmgr_extract_certificate_data(&cmBuff, &descriptor); -// -// if (result != OPERATION_SUCCESS) -// { -// WrtLogE("Unable to load certificate"); -// return UNKNOWN_ERROR; -// } -// -// certmgr_release_certificate_data(&descriptor); -// -// m_certificatePtr = CertificatePtr(new Certificate(cmBuff)); -// -// // we have to use temp pointer cause d2i_x509 modifies its input -// const unsigned char* tmpPtr = cmBuff.data; -// X509* pCertificate = d2i_X509(NULL, &tmpPtr, cmBuff.size); -// -// if (pCertificate) -// { -// SSLSmartContainer pX509(pCertificate); -// -// // Check the key length if sig algorithm is RSA -// EVP_PKEY *pKey = X509_get_pubkey(pX509); -// -// if (pKey->type == EVP_PKEY_RSA) -// { -// RSA* pRSA = pKey->pkey.rsa; -// -// if (pRSA) -// { -// int keyLength = RSA_size(pRSA); -// -// // key Length (modulus) is in bytes -// keyLength <<= 3; -// WrtLogD("RSA key length: %d bits", keyLength); -// -// if (keyLength < MIN_RSA_KEY_LENGTH) -// { -// WrtLogE("RSA key too short! Has only %d bits.", keyLength); -// return CERTIFICATE_SECURITY_ERROR; -// } -// } -// } -// } -// -// return NO_ERROR; -//} - CertificateLoader::CertificateLoaderResult CertificateLoader:: loadCertificateBasedOnDSAComponents(const std::string& strP, const std::string& strQ, @@ -542,111 +120,8 @@ CertificateLoader::CertificateLoaderResult CertificateLoader:: (void) strJ; (void) strSeed; (void) strPGenCounter; - WrtLogE("Not implemented."); + LogError("Not implemented."); return UNKNOWN_ERROR; - // (void)strY; - // (void)strJ; - // (void)strSeed; - // (void)strPGenCounter; - // - // long int result = UNKNOWN_ERROR; - // - // char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE]; - // char type[CERTMGR_MAX_CERT_TYPE_SIZE]; - // certmgr_cert_id certId; - // certmgr_ctx context; - // certmgr_mem_buff certRetrieved; - // - // unsigned char buffer[CERTMGR_MAX_BUFFER_SIZE]; - // - // certmgr_cert_descriptor descriptor; - // - // certRetrieved.data = buffer; - // certRetrieved.firstFree = 0; - // certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE; - // certId.storeId = storeId; - // certId.type = type; - // - // CERTMGR_INIT_CONTEXT((&context), (sizeof(context))) - // std::string strStoreType("Operator"); - // strncpy(context.storeId, strStoreType.c_str(), strStoreType.length()); - // - // for (certRetrieved.firstFree = 0; - // OPERATION_SUCCESS == (result = certmgr_retrieve_certificate_from_store(&context, &certRetrieved, &certId)); - // certRetrieved.firstFree = 0) - // { - // - // if (OPERATION_SUCCESS != certmgr_extract_certificate_data(&certRetrieved, &descriptor)) - // { - // WrtLogD("unable to retrieve cert from storage"); - // continue; - // } - // - // X509* pCertificate = d2i_X509(NULL, (const unsigned char**) &(certRetrieved.data), certRetrieved.size); - // - // if (pCertificate) - // { - // EVP_PKEY *pKey = X509_get_pubkey(pCertificate); - // - // if (pKey->type == EVP_PKEY_DSA) - // { - // DSA* pDSA = pKey->pkey.dsa; - // - // if (pDSA) - // { - // BIGNUM *pDSApBigNum = NULL, *pDSAqBigNum = NULL, *pDSAgBigNum = NULL; - // - // convertBase64NodeToBigNum(strP, &pDSApBigNum); - // convertBase64NodeToBigNum(strQ, &pDSAqBigNum); - // convertBase64NodeToBigNum(strG, &pDSAgBigNum); - // - // if (pDSApBigNum && pDSAqBigNum && pDSAgBigNum && - // BN_cmp(pDSApBigNum, pDSA->p) == 0 && - // BN_cmp(pDSAqBigNum, pDSA->q) == 0 && - // BN_cmp(pDSAgBigNum, pDSA->g) == 0) - // { - // WrtLogI("DSA Certificate found"); - // /* TODO load this certificate to m_cmBuff value */ - // WrtLogE("Not implemented!"); - // - // EVP_PKEY_free(pKey); - // X509_free(pCertificate); - // - // BN_free(pDSApBigNum); - // BN_free(pDSAqBigNum); - // BN_free(pDSAgBigNum); - // - // certmgr_release_certificate_data(&descriptor); - // return NO_ERROR; - // } - // - // if (pDSApBigNum) - // { - // BN_free(pDSApBigNum); - // } - // if (pDSAqBigNum) - // { - // BN_free(pDSAqBigNum); - // } - // if (pDSAgBigNum) - // { - // BN_free(pDSAgBigNum); - // } - // - // } - // EVP_PKEY_free(pKey); - // } - // X509_free(pCertificate); - // } - // else - // WrtLogE("Unable to load certificate"); - // - // certmgr_release_certificate_data(&descriptor); - // } - // - // WrtLogE("No DSA certificate with given parameters"); - // - // return CERTIFICATE_NOT_FOUND; } bool CertificateLoader::convertBase64NodeToBigNum(const std::string& strNode, @@ -654,67 +129,9 @@ bool CertificateLoader::convertBase64NodeToBigNum(const std::string& strNode, { (void) strNode; (void) ppBigNum; - WrtLogE("Not implemented."); + LogError("Not implemented."); return false; - // if (!ppBigNum || *ppBigNum != NULL) - // { - // WrtLogE("Ptr variable not initialized properly!"); - // return false; - // } - // - // // decode base64 to binary - // long int binBuffLength = 0; - // unsigned char* binBuff = NULL; - // - // binBuff = certmgr_util_base64_decode(const_cast (strNode.c_str()), strNode.length(), &binBuffLength); - // - // if (!binBuff) - // { - // WrtLogE("base64 decode failed"); - // return false; - // } - // - // // convert binary to bignum - // *ppBigNum = BN_bin2bn(binBuff, binBuffLength, *ppBigNum); - // - // free(binBuff); - // - // if (!(*ppBigNum)) - // { - // WrtLogE("Conversion from node to bignum failed"); - // return false; - // } - // - // return true; } -// KW bool CertificateLoader::convertBigNumToBase64Node(const BIGNUM* pBigNum, std::string& strNode) -// KW { -// KW if (!pBigNum) -// KW { -// KW WrtLogE("null ptr"); -// KW return false; -// KW } -// KW -// KW int nNumLength = BN_num_bytes(pBigNum); -// KW unsigned char* buffer = new unsigned char[nNumLength + 1]; -// KW -// KW // convert bignum to binary format -// KW if (BN_bn2bin(pBigNum, buffer) < 0) -// KW { -// KW WrtLogE("Conversion from bignum to binary failed"); -// KW delete []buffer; -// KW return false; -// KW } -// KW -// KW char* pBase64Node = NULL; -// KW unsigned long int buffLen = 0; -// KW certmgr_util_base64_encode(buffer, (unsigned long int) nNumLength, &pBase64Node, &buffLen); -// KW -// KW strNode.assign(pBase64Node, buffLen); -// KW -// KW delete []buffer; -// KW return true; -// KW } } // namespace ValidationCore diff --git a/vcore/src/vcore/CertificateVerifier.cpp b/vcore/src/vcore/CertificateVerifier.cpp index d683883..ffc0dcc 100644 --- a/vcore/src/vcore/CertificateVerifier.cpp +++ b/vcore/src/vcore/CertificateVerifier.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include namespace ValidationCore { @@ -35,7 +35,7 @@ CertificateVerifier::CertificateVerifier(bool enableOcsp, bool enableCrl) VerificationStatus CertificateVerifier::check( CertificateCollection &certCollection) const { - WrtLogD("== Certificate collection validation start =="); + LogDebug("== Certificate collection validation start =="); Assert(certCollection.isChain() && "Collection must form chain."); VerificationStatus statusOcsp; @@ -52,14 +52,14 @@ VerificationStatus CertificateVerifier::check( } else { statusCrl = VERIFICATION_STATUS_GOOD; } - WrtLogD("== Certificate collection validation end =="); + LogDebug("== Certificate collection validation end =="); return getStatus(statusOcsp, statusCrl); } VerificationStatus CertificateVerifier::obtainOcspStatus( const CertificateCollection &chain) const { - WrtLogD("== Obtain ocsp status =="); + LogDebug("== Obtain ocsp status =="); CachedOCSP ocsp; return ocsp.check(chain); } @@ -67,7 +67,7 @@ VerificationStatus CertificateVerifier::obtainOcspStatus( VerificationStatus CertificateVerifier::obtainCrlStatus( const CertificateCollection &chain) const { - WrtLogD("== Obtain crl status =="); + LogDebug("== Obtain crl status =="); CachedCRL crl; return crl.check(chain); } @@ -79,26 +79,26 @@ VerificationStatus CertificateVerifier::getStatus( if (ocsp == VERIFICATION_STATUS_REVOKED || crl == VERIFICATION_STATUS_REVOKED) { - WrtLogD("Return status: REVOKED"); + LogDebug("Return status: REVOKED"); return VERIFICATION_STATUS_REVOKED; } if (ocsp == VERIFICATION_STATUS_GOOD) { - WrtLogD("Return status: GOOD"); + LogDebug("Return status: GOOD"); return VERIFICATION_STATUS_GOOD; } if (ocsp == VERIFICATION_STATUS_UNKNOWN) { - WrtLogD("Return status: UNKNOWN"); + LogDebug("Return status: UNKNOWN"); return VERIFICATION_STATUS_UNKNOWN; } if (ocsp == VERIFICATION_STATUS_NOT_SUPPORT) { - WrtLogD("Return status: NOT_SUPPORT"); + LogDebug("Return status: NOT_SUPPORT"); return VERIFICATION_STATUS_GOOD; } - WrtLogD("Return status: ERROR"); + LogDebug("Return status: ERROR"); return VERIFICATION_STATUS_ERROR; } @@ -125,7 +125,7 @@ VerificationStatus CertificateVerifier::checkEndEntity( } else { statusCrl.add(VERIFICATION_STATUS_GOOD); } - WrtLogD("== Certificate collection validateion end =="); + LogDebug("== Certificate collection validateion end =="); return getStatus(statusOcsp.convertToStatus(), statusCrl.convertToStatus()); } diff --git a/vcore/src/vcore/OCSPCertMgrUtil.cpp b/vcore/src/vcore/OCSPCertMgrUtil.cpp index 019cd1f..44d4bf6 100644 --- a/vcore/src/vcore/OCSPCertMgrUtil.cpp +++ b/vcore/src/vcore/OCSPCertMgrUtil.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -69,7 +69,7 @@ void getCertFromStore(X509_NAME *subject, X509 **xcert) { if (!xcert || *xcert || !subject) { - WrtLogE("Invalid input!"); + LogError("Invalid input!"); return; } @@ -85,43 +85,43 @@ void getCertFromStore(X509_NAME *subject, ScopedContext ctx(cert_svc_cert_context_init()); if (ctx.Get() == NULL) { - WrtLogW("Error in cert_svc_cert_context_init."); + LogWarning("Error in cert_svc_cert_context_init."); return; } - WrtLogD("Search certificate with subject: %s", buffer); + LogDebug("Search certificate with subject: " << buffer); result = cert_svc_search_certificate(ctx.Get(), SUBJECT_STR, buffer); - WrtLogD("Search finished!"); + LogDebug("Search finished!"); if (CERT_SVC_ERR_NO_ERROR != result) { - WrtLogW("Error during certificate search"); + LogWarning("Error during certificate search"); return; } fileList = ctx.Get()->fileNames; if (fileList == NULL) { - WrtLogD("No certificate found"); + LogDebug("No certificate found"); return; } if (fileList->filename == NULL) { - WrtLogW("Empty filename"); + LogWarning("Empty filename"); return; } - WrtLogD("Found cert file: %s", fileList->filename); + LogDebug("Found cert file: " << fileList->filename); ScopedContext ctx2(cert_svc_cert_context_init()); if (ctx2.Get() == NULL) { - WrtLogW("Error in cert_svc_cert_context_init."); + LogWarning("Error in cert_svc_cert_context_init."); return; } // TODO add read_certifcate_from_file function to Certificate.h if (CERT_SVC_ERR_NO_ERROR != cert_svc_load_file_to_context(ctx2.Get(), fileList->filename)) { - WrtLogW("Error in cert_svc_load_file_to_context"); + LogWarning("Error in cert_svc_load_file_to_context"); return; } @@ -130,18 +130,18 @@ void getCertFromStore(X509_NAME *subject, pCertificate = d2i_X509(NULL, &ptr, ctx2.Get()->certBuf->size); if (pCertificate == NULL) { - WrtLogW("Error during certificate conversion in d2i_X509"); + LogWarning("Error during certificate conversion in d2i_X509"); return; } *xcert = pCertificate; if (fileList->next != NULL) { - WrtLogE("There is more then one certificate with same subject :/"); + LogError("There is more then one certificate with same subject :/"); // TODO Implement me. for (fileList = fileList->next; fileList != NULL; fileList = fileList->next) { - WrtLogE("Additional certificate with same subject: %s", fileList->filename); + LogError("Additional certificate with same subject: " << fileList->filename); } } } diff --git a/vcore/src/vcore/OCSPImpl.cpp b/vcore/src/vcore/OCSPImpl.cpp index 98fc030..27bb250 100644 --- a/vcore/src/vcore/OCSPImpl.cpp +++ b/vcore/src/vcore/OCSPImpl.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include #include @@ -130,7 +130,7 @@ SoupWrapper::SoupMessageSendBase::RequestStatus OCSPImpl::sendOcspRequest( &cpath, &use_ssl)) { - WrtLogW("Error in OCSP_parse_url"); + LogWarning("Error in OCSP_parse_url"); return SoupMessageSendBase::REQUEST_STATUS_CONNECTION_ERROR; } @@ -160,8 +160,8 @@ ValidationCore::VerificationStatusSet OCSPImpl::validateCertificateList( if (certs.size() < 2) { // no certificates to verify, just return a error - WrtLogW("No validation will be proceed. OCSP require at" - " least 2 certificates in chain. Found only %d", certs.size()); + LogWarning("No validation will be proceed. OCSP require at" + " least 2 certificates in chain. Found only " << certs.size()); statusSet.add(VERIFICATION_STATUS_ERROR); return statusSet; } @@ -181,8 +181,8 @@ ValidationCore::VerificationStatusSet OCSPImpl::validateCertificateList( time_t minValidity = 0; for (++parent; parent != certs.end(); ++iter, ++parent) { - WrtLogD("Certificate validation (CN:%s)", (*iter)->getOneLine().c_str()); - WrtLogD("Parent certificate (CN:%s)", (*parent)->getOneLine().c_str()); + LogDebug("Certificate validation (CN:" << (*iter)->getOneLine() << ")"); + LogDebug("Parent certificate (CN:" << (*parent)->getOneLine() << ")"); statusSet.add(validateCertificate(*iter, *parent)); if ((0 == minValidity || minValidity > m_responseValidity) && m_responseValidity > 0) @@ -234,7 +234,7 @@ VerificationStatus OCSPImpl::validateCertificate(CertificatePtr argCert, VcoreThrowMsg(OCSPImpl::Exception::VerificationError, "Default responder is not set"); } - WrtLogW("Default responder will be used"); + LogWarning("Default responder will be used"); uri = m_strResponderURI; } @@ -272,22 +272,22 @@ VerificationStatus OCSPImpl::validateCertificate(CertificatePtr argCert, responseCont, newRequest.ocspCertId); } VcoreCatch(OCSPImpl::Exception::ConnectionError) { - WrtLogW("OCSP: ConnectionError"); + LogWarning("OCSP: ConnectionError"); return VERIFICATION_STATUS_CONNECTION_FAILED; } VcoreCatch(OCSPImpl::Exception::CertificateRevoked) { - WrtLogW("OCSP: Revoked"); + LogWarning("OCSP: Revoked"); return VERIFICATION_STATUS_REVOKED; } VcoreCatch(OCSPImpl::Exception::CertificateUnknown) { - WrtLogW("OCSP: Unknown"); + LogWarning("OCSP: Unknown"); return VERIFICATION_STATUS_UNKNOWN; } VcoreCatch(OCSPImpl::Exception::VerificationError) { - WrtLogW("OCSP: Verification error"); + LogWarning("OCSP: Verification error"); return VERIFICATION_STATUS_VERIFICATION_ERROR; } VcoreCatch(OCSPImpl::Exception::Base) { - WrtLogW("OCSP: Error"); + LogWarning("OCSP: Error"); return VERIFICATION_STATUS_ERROR; } - WrtLogW("OCSP: Good"); + LogWarning("OCSP: Good"); return VERIFICATION_STATUS_GOOD; } @@ -313,7 +313,7 @@ OCSPImpl::CreateRequestResult OCSPImpl::createRequest(CertificatePtr argCert, OCSP_REQUEST* newRequest = OCSP_REQUEST_new(); if (!newRequest) { - WrtLogW("OCSP: Failed to create a request"); + LogWarning("OCSP: Failed to create a request"); return CreateRequestResult(); } @@ -322,14 +322,14 @@ OCSPImpl::CreateRequestResult OCSPImpl::createRequest(CertificatePtr argCert, OCSP_CERTID* certId = addSerial(argCert, argIssuer); if (!certId) { - WrtLogW("OCSP: Unable to create a serial id"); + LogWarning("OCSP: Unable to create a serial id"); return CreateRequestResult(); } SSLSmartContainer certIdCont(certId); // Inserting certificate ID to request if (!OCSP_request_add0_id(requestCont, certIdCont)) { - WrtLogW("OCSP: Unable to create a certificate id"); + LogWarning("OCSP: Unable to create a certificate id"); return CreateRequestResult(); } @@ -339,7 +339,7 @@ OCSPImpl::CreateRequestResult OCSPImpl::createRequest(CertificatePtr argCert, if (m_bSignRequest) { if (!m_pSignCert || !m_pSignKey) { - WrtLogW("OCSP: Unable to sign request if " + LogWarning("OCSP: Unable to sign request if " "SignCert or SignKey was not set"); return CreateRequestResult(); } @@ -351,7 +351,7 @@ OCSPImpl::CreateRequestResult OCSPImpl::createRequest(CertificatePtr argCert, 0, 0)) { - WrtLogW("OCSP: Unable to sign request"); + LogWarning("OCSP: Unable to sign request"); return CreateRequestResult(); } } @@ -377,8 +377,7 @@ void OCSPImpl::setDigestAlgorithmForCertId(OCSP::DigestAlgorithm alg) if (NULL != foundAlg) { m_pCertIdDigestAlg = foundAlg; } else { - WrtLogD("Request for unsupported CertId digest algorithm" - "ignored!"); + LogDebug("Request for unsupported CertId digest algorithm ignored!"); } } @@ -389,8 +388,7 @@ void OCSPImpl::setDigestAlgorithmForRequest(OCSP::DigestAlgorithm alg) if (NULL != foundAlg) { m_pRequestDigestAlg = foundAlg; } else { - WrtLogD("Request for unsupported OCSP request digest algorithm" - "ignored!"); + LogDebug("Request for unsupported OCSP request digest algorithm ignored!"); } } @@ -441,7 +439,7 @@ bool OCSPImpl::verifyResponse(OCSP_BASICRESP* basic) // verify ocsp response int response = OCSP_basic_verify(basic, NULL, m_pTrustedStore, 0); if (response <= 0) { - WrtLogW("OCSP verification failed"); + LogWarning("OCSP verification failed"); } return response > 0; @@ -483,9 +481,9 @@ void OCSPImpl::checkRevocationStatus(OCSP_BASICRESP* basic, asn1GeneralizedTimeToTimeT(nextUpdate,&m_responseValidity); time_t now; time(&now); - WrtLogD("Time of next OCSP update got from server: %d", m_responseValidity); - WrtLogD("Expires in: %d", (m_responseValidity - now)); - WrtLogD("Original: %d", nextUpdate->data); + LogDebug("Time of next OCSP update got from server: " << m_responseValidity); + LogDebug("Expires in: " << (m_responseValidity - now)); + LogDebug("Original: " << nextUpdate->data); } switch (status) { @@ -521,7 +519,7 @@ OCSPImpl::OcspResponse OCSPImpl::convertToResponse() BIO_free_all(res_mem_bio); if (!response) { - WrtLogW("OCSP: Failed to convert OCSP Response to DER format"); + LogWarning("OCSP: Failed to convert OCSP Response to DER format"); return std::make_pair(false, static_cast(NULL)); } @@ -532,23 +530,23 @@ void OCSPImpl::handleInvalidResponse(int result) { switch (result) { case OCSP_RESPONSE_STATUS_MALFORMEDREQUEST: - WrtLogW("OCSP: Server returns " + LogWarning("OCSP: Server returns " "OCSP_RESPONSE_STATUS_MALFORMEDREQUEST status"); break; case OCSP_RESPONSE_STATUS_INTERNALERROR: - WrtLogW("OCSP: Server returns " + LogWarning("OCSP: Server returns " "OCSP_RESPONSE_STATUS_INTERNALERROR status"); break; case OCSP_RESPONSE_STATUS_TRYLATER: - WrtLogW("OCSP: Server returns " + LogWarning("OCSP: Server returns " "OCSP_RESPONSE_STATUS_TRYLATER status"); break; case OCSP_RESPONSE_STATUS_SIGREQUIRED: - WrtLogW("OCSP: Server returns " + LogWarning("OCSP: Server returns " "OCSP_RESPONSE_STATUS_SIGREQUIRED status"); break; case OCSP_RESPONSE_STATUS_UNAUTHORIZED: - WrtLogW("OCSP: Server returns " + LogWarning("OCSP: Server returns " "OCSP_RESPONSE_STATUS_UNAUTHORIZED status"); break; default: diff --git a/vcore/src/vcore/ReferenceValidator.cpp b/vcore/src/vcore/ReferenceValidator.cpp index 188a24e..e8b810a 100644 --- a/vcore/src/vcore/ReferenceValidator.cpp +++ b/vcore/src/vcore/ReferenceValidator.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include namespace { @@ -97,7 +97,7 @@ int ReferenceValidator::Impl::hexToInt(char a) { if (a >= '0' && a <= '9') return a-'0'; if (a >= 'A' && a <= 'F') return a-'A' + 10; if (a >= 'a' && a <= 'f') return a-'a' + 10; - WrtLogE("Symbol '%c' is out of scope.", a); + LogError("Symbol '" << a << "' is out of scope."); throw ERROR_DECODING_URL; } @@ -125,7 +125,7 @@ std::string ReferenceValidator::Impl::decodeProcent(const std::string &path) { } } } catch (Result &) { - WrtLogE("Error while decoding url path: %s", path.c_str()); + LogError("Error while decoding url path : " << path); throw ERROR_DECODING_URL; } return std::string(output.begin(), output.end()); @@ -141,7 +141,7 @@ ReferenceValidator::Result ReferenceValidator::Impl::dfsCheckDirectories( std::string currentDir = m_dirpath + directory; if ((dp = opendir(currentDir.c_str())) == NULL) { - WrtLogE("Error opening directory: %s", currentDir.c_str()); + LogError("Error opening directory : " << currentDir); m_errorDescription = currentDir; return ERROR_OPENING_DIR; } @@ -168,7 +168,7 @@ ReferenceValidator::Result ReferenceValidator::Impl::dfsCheckDirectories( } if (dirp->d_type == DT_DIR) { - WrtLogD("Open directory: %s", (directory + dirp->d_name).c_str()); + LogDebug("Open directory : " << (directory + dirp->d_name)); std::string tmp_directory = directory + dirp->d_name + "/"; Result result = dfsCheckDirectories(referenceSet, tmp_directory, @@ -181,14 +181,14 @@ ReferenceValidator::Result ReferenceValidator::Impl::dfsCheckDirectories( if (referenceSet.end() == referenceSet.find(directory + dirp->d_name)) { - WrtLogD("Found file: %s", (directory + dirp->d_name).c_str()); - WrtLogE("Unknown ERROR_REFERENCE_NOT_FOUND."); + LogDebug("Found file : " << (directory + dirp->d_name)); + LogError("Unknown ERROR_REFERENCE_NOT_FOUND."); closedir(dp); m_errorDescription = directory + dirp->d_name; return ERROR_REFERENCE_NOT_FOUND; } } else { - WrtLogE("Unknown file type."); + LogError("Unknown file type."); closedir(dp); m_errorDescription = directory + dirp->d_name; return ERROR_UNSUPPORTED_FILE_TYPE; @@ -197,7 +197,7 @@ ReferenceValidator::Result ReferenceValidator::Impl::dfsCheckDirectories( if (errno != 0) { m_errorDescription = VcoreDPL::GetErrnoString(); - WrtLogE("readdir failed. Errno code: %d, Description: ", errno, m_errorDescription.c_str()); + LogError("readdir failed. Errno code : " << errno << ", Description : " << m_errorDescription); closedir(dp); return ERROR_READING_DIR; } diff --git a/vcore/src/vcore/SaxReader.cpp b/vcore/src/vcore/SaxReader.cpp index 5c49ece..d1ae2bd 100644 --- a/vcore/src/vcore/SaxReader.cpp +++ b/vcore/src/vcore/SaxReader.cpp @@ -20,7 +20,7 @@ * @brief Simple c++ interface for libxml2. */ #include -#include +#include #include @@ -47,7 +47,7 @@ void SaxReader::initialize( { Assert(m_reader == 0 && "Double initialization of SaxReader"); - WrtLogD("SaxReader opening file: %s", filename.c_str()); + LogDebug("SaxReader opening file: " << filename); m_reader = xmlNewTextReaderFilename(filename.c_str()); diff --git a/vcore/src/vcore/SignatureFinder.cpp b/vcore/src/vcore/SignatureFinder.cpp index 0c864b7..0c9e60f 100644 --- a/vcore/src/vcore/SignatureFinder.cpp +++ b/vcore/src/vcore/SignatureFinder.cpp @@ -20,7 +20,7 @@ * @brief Search for author-signature.xml and signatureN.xml files. */ #include -#include +#include #include #include @@ -60,7 +60,7 @@ SignatureFinder::Result SignatureFinder::Impl::find(SignatureFileInfoSet &set) * find a dir */ if ((dp = opendir(m_dir.c_str())) == NULL) { - WrtLogE("Error opening directory: %s", m_dir.c_str()); + LogError("Error opening directory: " << m_dir); return ERROR_OPENING_DIR; } @@ -89,7 +89,7 @@ SignatureFinder::Result SignatureFinder::Impl::find(SignatureFileInfoSet &set) } if (errno != 0) { - WrtLogE("Error in readdir"); + LogError("Error in readdir"); closedir(dp); return ERROR_READING_DIR; } diff --git a/vcore/src/vcore/SignatureValidator.cpp b/vcore/src/vcore/SignatureValidator.cpp index 2a51402..3ceebd7 100644 --- a/vcore/src/vcore/SignatureValidator.cpp +++ b/vcore/src/vcore/SignatureValidator.cpp @@ -30,7 +30,7 @@ #include #endif -#include +#include namespace { const time_t TIMET_DAY = 60 * 60 * 24; @@ -114,18 +114,18 @@ public: std::string roleURI = data.getRoleURI(); if (roleURI.empty()) { - WrtLogW("URI attribute in Role tag couldn't be empty."); + LogWarning("URI attribute in Role tag couldn't be empty."); return false; } if (roleURI != TOKEN_ROLE_AUTHOR_URI && data.isAuthorSignature()) { - WrtLogW("URI attribute in Role tag does not " + LogWarning("URI attribute in Role tag does not " "match with signature filename."); return false; } if (roleURI != TOKEN_ROLE_DISTRIBUTOR_URI && !data.isAuthorSignature()) { - WrtLogW("URI attribute in Role tag does not " + LogWarning("URI attribute in Role tag does not " "match with signature filename."); return false; } @@ -134,8 +134,8 @@ public: bool checkProfileURI(const SignatureData &data) { if (TOKEN_PROFILE_URI != data.getProfileURI()) { - WrtLogW( - "Profile tag contains unsupported value in URI attribute( %s ).", (data.getProfileURI()).c_str()); + LogWarning( + "Profile tag contains unsupported value in URI attribute " << data.getProfileURI()); return false; } return true; @@ -146,7 +146,7 @@ public: ObjectList::const_iterator iter; for (iter = objectList.begin(); iter != objectList.end(); ++iter) { if (!data.containObjectReference(*iter)) { - WrtLogW("Signature does not contain reference for object %s", (*iter).c_str()); + LogWarning("Signature does not contain reference for object " << *iter); return false; } } @@ -199,13 +199,13 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( // First step - sort certificate if (!collection.sort()) { - WrtLogW("Certificates do not form valid chain."); + LogWarning("Certificates do not form valid chain."); return SignatureValidator::SIGNATURE_INVALID_CERT_CHAIN;//SIGNATURE_INVALID; } // Check for error if (collection.empty()) { - WrtLogW("Certificate list in signature is empty."); + LogWarning("Certificate list in signature is empty."); return SignatureValidator::SIGNATURE_INVALID_CERT_CHAIN;//SIGNATURE_INVALID; } @@ -221,33 +221,33 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( // Is Root CA certificate trusted? CertStoreId::Set storeIdSet = createCertificateIdentifier().find(root); - WrtLogD("Is root certificate from TIZEN_DEVELOPER domain: %d", storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); - WrtLogD("Is root certificate from TIZEN_TEST domain: %d", storeIdSet.contains(CertStoreId::TIZEN_TEST)); - WrtLogD("Is root certificate from TIZEN_VERIFY domain: %d", storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); - WrtLogD("Is root certificate from TIZEN_STORE domain: %d", storeIdSet.contains(CertStoreId::TIZEN_STORE)); - WrtLogD("Is root certificate from TIZEN_PUBLIC domain: %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Is root certificate from TIZEN_PARTNER domain: %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Is root certificate from TIZEN_PLATFORM domain: %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Is root certificate from TIZEN_DEVELOPER domain : " << storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); + LogDebug("Is root certificate from TIZEN_TEST domain : " << storeIdSet.contains(CertStoreId::TIZEN_TEST)); + LogDebug("Is root certificate from TIZEN_VERIFY domain : " << storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); + LogDebug("Is root certificate from TIZEN_STORE domain : " << storeIdSet.contains(CertStoreId::TIZEN_STORE)); + LogDebug("Is root certificate from TIZEN_PUBLIC domain : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Is root certificate from TIZEN_PARTNER domain : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Is root certificate from TIZEN_PLATFORM domain : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); - WrtLogD("Visibility level is public : %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Visibility level is partner : %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Visibility level is platform : %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Visibility level is public : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Visibility level is partner : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Visibility level is platform : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); if (data.isAuthorSignature()) { if (!storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogW("author-signature.xml has got unrecognized Root CA " + LogWarning("author-signature.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } } else { - WrtLogD("signaturefile name = %s", data.getSignatureFileName().c_str()); + LogDebug("signaturefile name = " << data.getSignatureFileName()); if (storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogE("distributor has author level siganture! Signature will be disregarded."); + LogError("distributor has author level siganture! Signature will be disregarded."); return SignatureValidator::SIGNATURE_IN_DISTRIBUTOR_CASE_AUTHOR_CERT;//SIGNATURE_INVALID; } @@ -256,11 +256,11 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( { if (storeIdSet.contains(CertStoreId::VIS_PUBLIC) || storeIdSet.contains(CertStoreId::VIS_PARTNER) || storeIdSet.contains(CertStoreId::VIS_PLATFORM)) { - WrtLogD("Root CA for signature1.xml is correct."); + LogDebug("Root CA for signature1.xml is correct."); } else { - WrtLogW("signature1.xml has got unrecognized Root CA " + LogWarning("signature1.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } @@ -280,7 +280,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( // If the end certificate is not ROOT CA we should disregard signature // but still signature must be valid... Aaaaaa it's so stupid... if (!(root->isSignedBy(root))) { - WrtLogW("Root CA certificate not found. Chain is incomplete."); + LogWarning("Root CA certificate not found. Chain is incomplete."); // context.allowBrokenChain = true; } @@ -305,22 +305,22 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( memset(&tc, 0, sizeof(tc)); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", t->tm_year + 1900, t->tm_mon + 1,t->tm_mday ); - WrtLogD("## System's currentTime : %s", msg); + LogDebug("## System's currentTime : " << msg); fprintf(stderr, "## System's currentTime : %s\n", msg); tb = _ASN1_GetTimeT(notBeforeTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tb.tm_year + 1900, tb.tm_mon + 1,tb.tm_mday ); - WrtLogD("## certificate's notBeforeTime : %s", msg); + LogDebug("## certificate's notBeforeTime : " << msg); fprintf(stderr, "## certificate's notBeforeTime : %s\n", msg); ta = _ASN1_GetTimeT(notAfterTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", ta.tm_year + 1900, ta.tm_mon + 1,ta.tm_mday ); - WrtLogD("## certificate's notAfterTime : %s", msg); + LogDebug("## certificate's notAfterTime : " << msg); fprintf(stderr, "## certificate's notAfterTime : %s\n", msg); if (storeIdSet.contains(CertStoreId::TIZEN_TEST) || storeIdSet.contains(CertStoreId::TIZEN_VERIFY)) { - WrtLogD("## TIZEN_VERIFY : check certificate Time : FALSE"); + LogDebug("## TIZEN_VERIFY : check certificate Time : FALSE"); fprintf(stderr, "## TIZEN_VERIFY : check certificate Time : FALSE\n"); return SignatureValidator::SIGNATURE_INVALID_CERT_TIME;//SIGNATURE_INVALID; } @@ -361,7 +361,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( } snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tc.tm_year + 1900, tc.tm_mon + 1,tc.tm_mday ); - WrtLogD("## cmp cert with validation time : %s", msg); + LogDebug("## cmp cert with validation time : " << msg); fprintf(stderr, "## cmp cert with validation time : %s\n", msg); time_t outCurrent = mktime(&tc); @@ -386,30 +386,21 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( if (notAfter < nowTime) { context.validationTime = notAfter - TIMET_DAY; - WrtLogW("Author certificate is expired. notAfter..."); + LogWarning("Author certificate is expired. notAfter..."); } */ if (notBefore > nowTime) { - WrtLogW("Author certificate is expired. notBefore time is greater than system-time."); + LogWarning("Author certificate is expired. notBefore time is greater than system-time."); t = localtime(&nowTime); - WrtLogD("System's current Year : %d", (t->tm_year + 1900)); - WrtLogD("System's current month : %d", (t->tm_mon + 1)); - WrtLogD("System's current day : %d", (t->tm_mday)); t = localtime(¬Before); - WrtLogD("Author certificate's notBefore Year : %d", (t->tm_year + 1900)); - WrtLogD("Author certificate's notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Author certificate's notBefore day : %d", (t->tm_mday)); context.validationTime = notBefore + TIMET_DAY; t = localtime(&context.validationTime); - WrtLogD("Modified current Year : %d", (t->tm_year + 1900)); - WrtLogD("Modified current notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Modified current notBefore day : %d", (t->tm_mday)); } } #endif @@ -421,13 +412,13 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( if (!data.isAuthorSignature()) { if (XmlSec::NO_ERROR != XmlSecSingleton::Instance().validate(&context)) { - WrtLogW("Installation break - invalid package!"); + LogWarning("Installation break - invalid package!"); return SignatureValidator::SIGNATURE_INVALID_HASH_SIGNATURE;//SIGNATURE_INVALID; } data.setReference(context.referenceSet); if (!checkObjectReferences(data)) { - WrtLogW("Failed to check Object References"); + LogWarning("Failed to check Object References"); return SignatureValidator::SIGNATURE_INVALID_HASH_SIGNATURE;//SIGNATURE_INVALID; } @@ -435,7 +426,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( /* ReferenceValidator fileValidator(widgetContentPath); if (ReferenceValidator::NO_ERROR != fileValidator.checkReferences(data)) { - WrtLogW("Invalid package - file references broken"); + LogWarning("Invalid package - file references broken"); return SignatureValidator::SIGNATURE_INVALID_NO_HASH_FILE;//SIGNATURE_INVALID; } */ @@ -451,7 +442,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( coll.load(sortedCertificateList); if (!coll.sort()) { - WrtLogD("Collection does not contain chain!"); + LogDebug("Collection does not contain chain!"); return SignatureValidator::SIGNATURE_INVALID_CERT_CHAIN;//SIGNATURE_INVALID; } @@ -473,7 +464,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::check( #endif if (disregard) { - WrtLogW("Signature is disregard. RootCA is not a member of Tizen"); + LogWarning("Signature is disregard. RootCA is not a member of Tizen"); return SignatureValidator::SIGNATURE_INVALID_DISTRIBUTOR_CERT;//SIGNATURE_DISREGARD; } return SignatureValidator::SIGNATURE_VERIFIED; @@ -484,7 +475,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData const std::list& uriList) { if(uriList.size() == 0 ) - WrtLogW("checkList >> no hash"); + LogWarning("checkList >> no hash"); bool disregard = false; @@ -503,13 +494,13 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData // First step - sort certificate if (!collection.sort()) { - WrtLogW("Certificates do not form valid chain."); + LogWarning("Certificates do not form valid chain."); return SignatureValidator::SIGNATURE_INVALID; } // Check for error if (collection.empty()) { - WrtLogW("Certificate list in signature is empty."); + LogWarning("Certificate list in signature is empty."); return SignatureValidator::SIGNATURE_INVALID; } @@ -525,40 +516,40 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData // Is Root CA certificate trusted? CertStoreId::Set storeIdSet = createCertificateIdentifier().find(root); - WrtLogD("Is root certificate from TIZEN_DEVELOPER domain: %d", storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); - WrtLogD("Is root certificate from TIZEN_TEST domain: %d", storeIdSet.contains(CertStoreId::TIZEN_TEST)); - WrtLogD("Is root certificate from TIZEN_VERIFY domain: %d", storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); - WrtLogD("Is root certificate from TIZEN_PUBLIC domain: %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Is root certificate from TIZEN_PARTNER domain: %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Is root certificate from TIZEN_PLATFORM domain: %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Is root certificate from TIZEN_DEVELOPER domain : " << storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); + LogDebug("Is root certificate from TIZEN_TEST domain : " << storeIdSet.contains(CertStoreId::TIZEN_TEST)); + LogDebug("Is root certificate from TIZEN_VERIFY domain : " << storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); + LogDebug("Is root certificate from TIZEN_PUBLIC domain : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Is root certificate from TIZEN_PARTNER domain : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Is root certificate from TIZEN_PLATFORM domain : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); - WrtLogD("Visibility level is public : %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Visibility level is partner : %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Visibility level is platform : %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Visibility level is public : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Visibility level is partner : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Visibility level is platform : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); if (data.isAuthorSignature()) { if (!storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogW("author-signature.xml has got unrecognized Root CA " + LogWarning("author-signature.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } - WrtLogD("Root CA for author signature is correct."); + LogDebug("Root CA for author signature is correct."); } else { - WrtLogD("signaturefile name = %s", data.getSignatureFileName().c_str()); + LogDebug("signaturefile name = " << data.getSignatureFileName()); if (data.getSignatureNumber() == 1) { if (storeIdSet.contains(CertStoreId::VIS_PUBLIC) || storeIdSet.contains(CertStoreId::VIS_PARTNER) || storeIdSet.contains(CertStoreId::VIS_PLATFORM)) { - WrtLogD("Root CA for signature1.xml is correct."); + LogDebug("Root CA for signature1.xml is correct."); } else { - WrtLogW("signature1.xml has got unrecognized Root CA " + LogWarning("signature1.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } @@ -578,7 +569,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData // If the end certificate is not ROOT CA we should disregard signature // but still signature must be valid... Aaaaaa it's so stupid... if (!(root->isSignedBy(root))) { - WrtLogW("Root CA certificate not found. Chain is incomplete."); + LogWarning("Root CA certificate not found. Chain is incomplete."); // context.allowBrokenChain = true; } @@ -606,22 +597,22 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData memset(&tc, 0, sizeof(tc)); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", t->tm_year + 1900, t->tm_mon + 1,t->tm_mday ); - WrtLogD("## System's currentTime : %s", msg); + LogDebug("## System's currentTime : " << msg); fprintf(stderr, "## System's currentTime : %s\n", msg); tb = _ASN1_GetTimeT(notBeforeTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tb.tm_year + 1900, tb.tm_mon + 1,tb.tm_mday ); - WrtLogD("## certificate's notBeforeTime : %s", msg); + LogDebug("## certificate's notBeforeTime : " << msg); fprintf(stderr, "## certificate's notBeforeTime : %s\n", msg); ta = _ASN1_GetTimeT(notAfterTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", ta.tm_year + 1900, ta.tm_mon + 1,ta.tm_mday ); - WrtLogD("## certificate's notAfterTime : %s", msg); + LogDebug("## certificate's notAfterTime : " << msg); fprintf(stderr, "## certificate's notAfterTime : %s\n", msg); if (storeIdSet.contains(CertStoreId::TIZEN_VERIFY)) { - WrtLogD("## TIZEN_VERIFY : check certificate Time : FALSE"); + LogDebug("## TIZEN_VERIFY : check certificate Time : FALSE"); fprintf(stderr, "## TIZEN_VERIFY : check certificate Time : FALSE\n"); return SignatureValidator::SIGNATURE_INVALID; } @@ -632,7 +623,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData tc.tm_mday = (tb.tm_mday + ta.tm_mday)/2; snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tc.tm_year + 1900, tc.tm_mon + 1,tc.tm_mday ); - WrtLogD("## cmp cert with validation time : %s", msg); + LogDebug("## cmp cert with validation time : " << msg); fprintf(stderr, "## cmp cert with validation time : %s\n", msg); time_t outCurrent = mktime(&tc); @@ -655,30 +646,21 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData if (notAfter < nowTime) { context.validationTime = notAfter - TIMET_DAY; - WrtLogW("Author certificate is expired. notAfter..."); + LogWarning("Author certificate is expired. notAfter..."); } */ if (notBefore > nowTime) { - WrtLogW("Author certificate is expired. notBefore time is greater than system-time."); + LogWarning("Author certificate is expired. notBefore time is greater than system-time."); t = localtime(&nowTime); - WrtLogD("System's current Year : %d", (t->tm_year + 1900)); - WrtLogD("System's current month : %d", (t->tm_mon + 1)); - WrtLogD("System's current day : %d", (t->tm_mday)); t = localtime(¬Before); - WrtLogD("Author certificate's notBefore Year : %d", (t->tm_year + 1900)); - WrtLogD("Author certificate's notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Author certificate's notBefore day : %d", (t->tm_mday)); context.validationTime = notBefore + TIMET_DAY; t = localtime(&context.validationTime); - WrtLogD("Modified current Year : %d", (t->tm_year + 1900)); - WrtLogD("Modified current notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Modified current notBefore day : %d", (t->tm_mday)); } } #endif @@ -689,7 +671,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData if(uriList.size() == 0) { if (XmlSec::NO_ERROR != XmlSecSingleton::Instance().validateNoHash(&context)) { - WrtLogW("Installation break - invalid package! >> validateNoHash"); + LogWarning("Installation break - invalid package! >> validateNoHash"); return SignatureValidator::SIGNATURE_INVALID; } } @@ -697,7 +679,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData { XmlSecSingleton::Instance().setPartialHashList(uriList); if (XmlSec::NO_ERROR != XmlSecSingleton::Instance().validatePartialHash(&context)) { - WrtLogW("Installation break - invalid package! >> validatePartialHash"); + LogWarning("Installation break - invalid package! >> validatePartialHash"); return SignatureValidator::SIGNATURE_INVALID; } } @@ -711,7 +693,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData /* ReferenceValidator fileValidator(widgetContentPath); if (ReferenceValidator::NO_ERROR != fileValidator.checkReferences(data)) { - WrtLogW("Invalid package - file references broken"); + LogWarning("Invalid package - file references broken"); return SignatureValidator::SIGNATURE_INVALID; } */ @@ -726,7 +708,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData coll.load(sortedCertificateList); if (!coll.sort()) { - WrtLogD("Collection does not contain chain!"); + LogDebug("Collection does not contain chain!"); return SignatureValidator::SIGNATURE_INVALID; } @@ -748,7 +730,7 @@ SignatureValidator::Result ImplTizenSignatureValidator::checkList(SignatureData #endif if (disregard) { - WrtLogW("Signature is disregard. RootCA is not a member of Tizen."); + LogWarning("Signature is disregard. RootCA is not a member of Tizen."); return SignatureValidator::SIGNATURE_DISREGARD; } return SignatureValidator::SIGNATURE_VERIFIED; @@ -803,13 +785,13 @@ SignatureValidator::Result ImplWacSignatureValidator::check( // First step - sort certificate if (!collection.sort()) { - WrtLogW("Certificates do not form valid chain."); + LogWarning("Certificates do not form valid chain."); return SignatureValidator::SIGNATURE_INVALID; } // Check for error if (collection.empty()) { - WrtLogW("Certificate list in signature is empty."); + LogWarning("Certificate list in signature is empty."); return SignatureValidator::SIGNATURE_INVALID; } @@ -825,30 +807,30 @@ SignatureValidator::Result ImplWacSignatureValidator::check( // Is Root CA certificate trusted? CertStoreId::Set storeIdSet = createCertificateIdentifier().find(root); - WrtLogD("Is root certificate from TIZEN_DEVELOPER domain: %d", storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); - WrtLogD("Is root certificate from TIZEN_TEST domain: %d", storeIdSet.contains(CertStoreId::TIZEN_TEST)); - WrtLogD("Is root certificate from TIZEN_VERIFY domain: %d", storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); - WrtLogD("Is root certificate from TIZEN_PUBLIC domain: %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Is root certificate from TIZEN_PARTNER domain: %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Is root certificate from TIZEN_PLATFORM domain: %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Is root certificate from TIZEN_DEVELOPER domain : " << storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); + LogDebug("Is root certificate from TIZEN_TEST domain : " << storeIdSet.contains(CertStoreId::TIZEN_TEST)); + LogDebug("Is root certificate from TIZEN_VERIFY domain : " << storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); + LogDebug("Is root certificate from TIZEN_PUBLIC domain : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Is root certificate from TIZEN_PARTNER domain : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Is root certificate from TIZEN_PLATFORM domain : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); - WrtLogD("Visibility level is public : %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Visibility level is partner : %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Visibility level is platform : %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Visibility level is public : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Visibility level is partner : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Visibility level is platform : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); if (data.isAuthorSignature()) { if (!storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogW("author-signature.xml has got unrecognized Root CA " + LogWarning("author-signature.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } } else { - WrtLogD("signaturefile name = %s", data.getSignatureFileName().c_str()); + LogDebug("signaturefile name = " << data.getSignatureFileName()); if (storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogE("distributor has author level siganture! Signature will be disregarded."); + LogError("distributor has author level siganture! Signature will be disregarded."); return SignatureValidator::SIGNATURE_INVALID; } @@ -857,11 +839,11 @@ SignatureValidator::Result ImplWacSignatureValidator::check( { if (storeIdSet.contains(CertStoreId::VIS_PUBLIC) || storeIdSet.contains(CertStoreId::VIS_PARTNER) || storeIdSet.contains(CertStoreId::VIS_PLATFORM)) { - WrtLogD("Root CA for signature1.xml is correct."); + LogDebug("Root CA for signature1.xml is correct."); } else { - WrtLogW("signature1.xml has got unrecognized Root CA " + LogWarning("signature1.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } @@ -881,7 +863,7 @@ SignatureValidator::Result ImplWacSignatureValidator::check( // If the end certificate is not ROOT CA we should disregard signature // but still signature must be valid... Aaaaaa it's so stupid... if (!(root->isSignedBy(root))) { - WrtLogW("Root CA certificate not found. Chain is incomplete."); + LogWarning("Root CA certificate not found. Chain is incomplete."); // context.allowBrokenChain = true; } @@ -907,22 +889,22 @@ SignatureValidator::Result ImplWacSignatureValidator::check( memset(&tc, 0, sizeof(tc)); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", t->tm_year + 1900, t->tm_mon + 1,t->tm_mday ); - WrtLogD("## System's currentTime : %s", msg); + LogDebug("## System's currentTime : " << msg); fprintf(stderr, "## System's currentTime : %s\n", msg); tb = _ASN1_GetTimeT(notBeforeTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tb.tm_year + 1900, tb.tm_mon + 1,tb.tm_mday ); - WrtLogD("## certificate's notBeforeTime : %s", msg); + LogDebug("## certificate's notBeforeTime : " << msg); fprintf(stderr, "## certificate's notBeforeTime : %s\n", msg); ta = _ASN1_GetTimeT(notAfterTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", ta.tm_year + 1900, ta.tm_mon + 1,ta.tm_mday ); - WrtLogD("## certificate's notAfterTime : %s", msg); + LogDebug("## certificate's notAfterTime : " << msg); fprintf(stderr, "## certificate's notAfterTime : %s\n", msg); if (storeIdSet.contains(CertStoreId::TIZEN_VERIFY)) { - WrtLogD("## TIZEN_VERIFY : check certificate Time : FALSE"); + LogDebug("## TIZEN_VERIFY : check certificate Time : FALSE"); fprintf(stderr, "## TIZEN_VERIFY : check certificate Time : FALSE\n"); return SignatureValidator::SIGNATURE_INVALID; } @@ -933,7 +915,7 @@ SignatureValidator::Result ImplWacSignatureValidator::check( tc.tm_mday = (tb.tm_mday + ta.tm_mday)/2; snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tc.tm_year + 1900, tc.tm_mon + 1,tc.tm_mday ); - WrtLogD("## cmp cert with validation time : %s", msg); + LogDebug("## cmp cert with validation time : " << msg); fprintf(stderr, "## cmp cert with validation time : %s\n", msg); time_t outCurrent = mktime(&tc); @@ -956,37 +938,28 @@ SignatureValidator::Result ImplWacSignatureValidator::check( if (notAfter < nowTime) { context.validationTime = notAfter - TIMET_DAY; - WrtLogW("Author certificate is expired. notAfter..."); + LogWarning("Author certificate is expired. notAfter..."); } */ if (notBefore > nowTime) { - WrtLogW("Author certificate is expired. notBefore time is greater than system-time."); + LogWarning("Author certificate is expired. notBefore time is greater than system-time."); t = localtime(&nowTime); - WrtLogD("System's current Year : %d", (t->tm_year + 1900)); - WrtLogD("System's current month : %d", (t->tm_mon + 1)); - WrtLogD("System's current day : %d", (t->tm_mday)); t = localtime(¬Before); - WrtLogD("Author certificate's notBefore Year : %d", (t->tm_year + 1900)); - WrtLogD("Author certificate's notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Author certificate's notBefore day : %d", (t->tm_mday)); context.validationTime = notBefore + TIMET_DAY; t = localtime(&context.validationTime); - WrtLogD("Modified current Year : %d", (t->tm_year + 1900)); - WrtLogD("Modified current notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Modified current notBefore day : %d", (t->tm_mday)); } } #endif if (!data.isAuthorSignature()) { if (XmlSec::NO_ERROR != XmlSecSingleton::Instance().validate(&context)) { - WrtLogW("Installation break - invalid package!"); + LogWarning("Installation break - invalid package!"); return SignatureValidator::SIGNATURE_INVALID; } @@ -998,7 +971,7 @@ SignatureValidator::Result ImplWacSignatureValidator::check( ReferenceValidator fileValidator(widgetContentPath); if (ReferenceValidator::NO_ERROR != fileValidator.checkReferences(data)) { - WrtLogW("Invalid package - file references broken"); + LogWarning("Invalid package - file references broken"); return SignatureValidator::SIGNATURE_INVALID; } } @@ -1013,7 +986,7 @@ SignatureValidator::Result ImplWacSignatureValidator::check( coll.load(sortedCertificateList); if (!coll.sort()) { - WrtLogD("Collection does not contain chain!"); + LogDebug("Collection does not contain chain!"); return SignatureValidator::SIGNATURE_INVALID; } @@ -1035,7 +1008,7 @@ SignatureValidator::Result ImplWacSignatureValidator::check( #endif if (disregard) { - WrtLogW("Signature is disregard. RootCA is not a member of Tizen."); + LogWarning("Signature is disregard. RootCA is not a member of Tizen."); return SignatureValidator::SIGNATURE_DISREGARD; } return SignatureValidator::SIGNATURE_VERIFIED; @@ -1050,7 +1023,7 @@ SignatureValidator::SignatureValidator( bool complianceMode) : m_impl(0) { - WrtLogD( "appType :%d", appType ); + LogDebug( "appType : " << appType ); if(appType == TIZEN) { diff --git a/vcore/src/vcore/SoupMessageSendBase.cpp b/vcore/src/vcore/SoupMessageSendBase.cpp index a361c18..0a29653 100644 --- a/vcore/src/vcore/SoupMessageSendBase.cpp +++ b/vcore/src/vcore/SoupMessageSendBase.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include namespace SoupWrapper { @@ -74,7 +74,7 @@ void SoupMessageSendBase::setRetry(int retry) { SoupMessage* SoupMessageSendBase::createRequest(){ SoupMessage *message; - WrtLogI("Soup message will be send to: %s", m_host.c_str()); + LogInfo("Soup message will be send to : " << m_host); if (!m_requestBuffer.empty()) { message = soup_message_new("POST", m_host.c_str()); @@ -83,7 +83,7 @@ SoupMessage* SoupMessageSendBase::createRequest(){ } if (!message) { - WrtLogE("Error creating request!"); + LogError("Error creating request!"); return 0; } diff --git a/vcore/src/vcore/SoupMessageSendSync.cpp b/vcore/src/vcore/SoupMessageSendSync.cpp index 8c7343c..9e36731 100644 --- a/vcore/src/vcore/SoupMessageSendSync.cpp +++ b/vcore/src/vcore/SoupMessageSendSync.cpp @@ -26,7 +26,7 @@ #include -#include +#include namespace SoupWrapper { @@ -43,10 +43,8 @@ SoupMessageSendBase::RequestStatus SoupMessageSendSync::sendSync() std::unique_ptr > proxyURI(soup_uri_new (proxy.get()), soup_uri_free); - WrtLogD("Proxy ptr: %s Proxy addr: %s", (void*)proxy.get(), proxy.get()); - for(int tryCount = 0; tryCount < m_tryCount; ++ tryCount){ - WrtLogD("Try(%d) to download %s", tryCount, m_host.c_str()); + LogDebug("Try(" << tryCount << ") to download " << m_host); ScopedSoupSession session(soup_session_async_new_with_options( SOUP_SESSION_ASYNC_CONTEXT, @@ -62,7 +60,7 @@ SoupMessageSendBase::RequestStatus SoupMessageSendSync::sendSync() msg.Reset(createRequest()); if (!msg) { - WrtLogE("Unable to send HTTP request."); + LogError("Unable to send HTTP request."); m_status = STATUS_IDLE; return REQUEST_STATUS_CONNECTION_ERROR; } @@ -79,7 +77,7 @@ SoupMessageSendBase::RequestStatus SoupMessageSendSync::sendSync() m_status = STATUS_IDLE; return REQUEST_STATUS_OK; } else { - WrtLogW("Soup failed with code [%d] message [%s]", msg->status_code, msg->response_body->data); + LogWarning("Soup failed with code [" << msg->status_code << "] message [" << msg->response_body->data << "]"); } } diff --git a/vcore/src/vcore/TimeConversion.cpp b/vcore/src/vcore/TimeConversion.cpp index 803f582..98c80f3 100644 --- a/vcore/src/vcore/TimeConversion.cpp +++ b/vcore/src/vcore/TimeConversion.cpp @@ -17,7 +17,7 @@ #include -#include +#include #include namespace ValidationCore { @@ -97,12 +97,12 @@ int asn1GeneralizedTimeToTimeT(ASN1_GENERALIZEDTIME *tm, time_t *res) const int DATE_BUFFER_LENGTH = 15; // YYYYMMDDHHMMSSZ if (NULL == res || NULL == tm) { - WrtLogE("NULL pointer"); + LogError("NULL pointer"); return -1; } if (DATE_BUFFER_LENGTH != tm->length || NULL == tm->data) { - WrtLogE("Invalid ASN1_GENERALIZEDTIME"); + LogError("Invalid ASN1_GENERALIZEDTIME"); return -1; } @@ -116,7 +116,7 @@ int asn1GeneralizedTimeToTimeT(ASN1_GENERALIZEDTIME *tm, time_t *res) &time_s.tm_min, &time_s.tm_sec) < 6) { - WrtLogE("Could not extract time data from ASN1_GENERALIZEDTIME"); + LogError("Could not extract time data from ASN1_GENERALIZEDTIME"); return -1; } diff --git a/vcore/src/vcore/VCore.cpp b/vcore/src/vcore/VCore.cpp index 7788584..5f1e381 100644 --- a/vcore/src/vcore/VCore.cpp +++ b/vcore/src/vcore/VCore.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #ifdef TIZEN_FEATURE_CERT_SVC_OCSP_CRL namespace { @@ -91,7 +91,7 @@ void VCoreInit() { #ifdef TIZEN_FEATURE_CERT_SVC_OCSP_CRL if (threadInterface) { - WrtLogD("Already Initialized"); + LogDebug("Already Initialized"); return true; } diff --git a/vcore/src/vcore/ValidatorFactories.cpp b/vcore/src/vcore/ValidatorFactories.cpp index 93238c6..d82bada 100644 --- a/vcore/src/vcore/ValidatorFactories.cpp +++ b/vcore/src/vcore/ValidatorFactories.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include @@ -38,10 +38,10 @@ const CertificateIdentifier& createCertificateIdentifier() CertificateConfigReader reader; std::string file = ConfigSingleton::Instance().getXMLConfigPath(); - WrtLogD("File with fingerprint list is: %s", file.c_str()); + LogDebug("File with fingerprint list is : " << file); std::string schema = ConfigSingleton::Instance().getXMLSchemaPath(); - WrtLogD("File with fingerprint list schema is: %s", schema.c_str()); + LogDebug("File with fingerprint list schema is : " << schema); reader.initialize(file, schema); reader.read(certificateIdentifier); diff --git a/vcore/src/vcore/WacOrigin.cpp b/vcore/src/vcore/WacOrigin.cpp index 304f0e8..74ccd7c 100644 --- a/vcore/src/vcore/WacOrigin.cpp +++ b/vcore/src/vcore/WacOrigin.cpp @@ -25,7 +25,7 @@ #include #include -#include <> +#include #include #include "ValidatorCommon.h" @@ -113,7 +113,7 @@ void WacOrigin::parse(const char *url) char *output = NULL; if (IDNA_SUCCESS != idna_to_ascii_lz(m_host.c_str(), &output, IDNA_USE_STD3_ASCII_RULES)) { - WrtLogE("libidn error"); + LogError("libidn error"); m_parseFailed = true; free(output); return; @@ -144,7 +144,7 @@ void WacOrigin::setPort() m_port = PORT_HTTPS; return; } else { - WrtLogD("Scheme %s is not support by WAC2.0 ", m_scheme.c_str()); + LogDebug("Scheme %s is not support by WAC2.0 " << m_scheme); m_parseFailed = true; } } diff --git a/vcore/src/vcore/WrtSignatureValidator.cpp b/vcore/src/vcore/WrtSignatureValidator.cpp index 81fc201..1db950e 100644 --- a/vcore/src/vcore/WrtSignatureValidator.cpp +++ b/vcore/src/vcore/WrtSignatureValidator.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include namespace { const time_t TIMET_DAY = 60 * 60 * 24; @@ -106,18 +106,18 @@ public: std::string roleURI = data.getRoleURI(); if (roleURI.empty()) { - WrtLogW("URI attribute in Role tag couldn't be empty."); + LogWarning("URI attribute in Role tag couldn't be empty."); return false; } if (roleURI != TOKEN_ROLE_AUTHOR_URI && data.isAuthorSignature()) { - WrtLogW("URI attribute in Role tag does not " + LogWarning("URI attribute in Role tag does not " "match with signature filename."); return false; } if (roleURI != TOKEN_ROLE_DISTRIBUTOR_URI && !data.isAuthorSignature()) { - WrtLogW("URI attribute in Role tag does not " + LogWarning("URI attribute in Role tag does not " "match with signature filename."); return false; } @@ -126,7 +126,7 @@ public: bool checkProfileURI(const SignatureData &data) { if (TOKEN_PROFILE_URI != data.getProfileURI()) { - WrtLogW("Profile tag contains unsupported value in URI attribute (%s).", (data.getProfileURI()).c_str()); + LogWarning("Profile tag contains unsupported value in URI attribute " << data.getProfileURI()); return false; } return true; @@ -137,7 +137,7 @@ public: ObjectList::const_iterator iter; for (iter = objectList.begin(); iter != objectList.end(); ++iter) { if (!data.containObjectReference(*iter)) { - WrtLogW("Signature does not contain reference for object %s", (*iter).c_str()); + LogWarning("Signature does not contain reference for object " << *iter); return false; } } @@ -187,13 +187,13 @@ WrtSignatureValidator::Result ImplTizen::check( // First step - sort certificate if (!collection.sort()) { - WrtLogW("Certificates do not form valid chain."); + LogWarning("Certificates do not form valid chain."); return WrtSignatureValidator::SIGNATURE_INVALID_CERT_CHAIN;//SIGNATURE_INVALID; } // Check for error if (collection.empty()) { - WrtLogW("Certificate list in signature is empty."); + LogWarning("Certificate list in signature is empty."); return WrtSignatureValidator::SIGNATURE_INVALID_CERT_CHAIN;//SIGNATURE_INVALID; } @@ -209,21 +209,21 @@ WrtSignatureValidator::Result ImplTizen::check( // Is Root CA certificate trusted? CertStoreId::Set storeIdSet = createCertificateIdentifier().find(root); - WrtLogD("Is root certificate from TIZEN_DEVELOPER domain: %d", storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); - WrtLogD("Is root certificate from TIZEN_TEST domain: %d", storeIdSet.contains(CertStoreId::TIZEN_TEST)); - WrtLogD("Is root certificate from TIZEN_VERIFY domain: %d", storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); - WrtLogD("Is root certificate from TIZEN_PUBLIC domain: %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Is root certificate from TIZEN_PARTNER domain: %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Is root certificate from TIZEN_PLATFORM domain: %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); - WrtLogD("Visibility level is public : %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Visibility level is partner : %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Visibility level is platform : %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Is root certificate from TIZEN_DEVELOPER domain : " << storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); + LogDebug("Is root certificate from TIZEN_TEST domain : " << storeIdSet.contains(CertStoreId::TIZEN_TEST)); + LogDebug("Is root certificate from TIZEN_VERIFY domain : " << storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); + LogDebug("Is root certificate from TIZEN_PUBLIC domain : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Is root certificate from TIZEN_PARTNER domain : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Is root certificate from TIZEN_PLATFORM domain : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Visibility level is public : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Visibility level is partner : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Visibility level is platform : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); if (data.isAuthorSignature()) { if (!storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogW("author-signature.xml has got unrecognized Root CA " + LogWarning("author-signature.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } @@ -232,21 +232,21 @@ WrtSignatureValidator::Result ImplTizen::check( { if (storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogW("distributor has author level siganture! Signature will be disregarded."); + LogWarning("distributor has author level siganture! Signature will be disregarded."); return WrtSignatureValidator::SIGNATURE_IN_DISTRIBUTOR_CASE_AUTHOR_CERT;//SIGNATURE_INVALID; } - WrtLogD("signaturefile name = %s", data.getSignatureFileName().c_str()); + LogDebug("signaturefile name = " << data.getSignatureFileName()); if (data.getSignatureNumber() == 1) { if (storeIdSet.contains(CertStoreId::VIS_PUBLIC) || storeIdSet.contains(CertStoreId::VIS_PARTNER) || storeIdSet.contains(CertStoreId::VIS_PLATFORM)) { - WrtLogD("Root CA for signature1.xml is correct."); + LogDebug("Root CA for signature1.xml is correct."); } else { - WrtLogW("signature1.xml has got unrecognized Root CA " + LogWarning("signature1.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } @@ -266,7 +266,7 @@ WrtSignatureValidator::Result ImplTizen::check( // If the end certificate is not ROOT CA we should disregard signature // but still signature must be valid... Aaaaaa it's so stupid... if (!(root->isSignedBy(root))) { - WrtLogW("Root CA certificate not found. Chain is incomplete."); + LogWarning("Root CA certificate not found. Chain is incomplete."); //context.allowBrokenChain = true; } @@ -292,22 +292,22 @@ WrtSignatureValidator::Result ImplTizen::check( memset(&tc, 0, sizeof(tc)); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", t->tm_year + 1900, t->tm_mon + 1,t->tm_mday ); - WrtLogD("## System's currentTime : %s", msg); + LogDebug("## System's currentTime : " << msg); fprintf(stderr, "## System's currentTime : %s\n", msg); tb = _ASN1_GetTimeT(notBeforeTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tb.tm_year + 1900, tb.tm_mon + 1,tb.tm_mday ); - WrtLogD("## certificate's notBeforeTime : %s", msg); + LogDebug("## certificate's notBeforeTime : " << msg); fprintf(stderr, "## certificate's notBeforeTime : %s\n", msg); ta = _ASN1_GetTimeT(notAfterTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", ta.tm_year + 1900, ta.tm_mon + 1,ta.tm_mday ); - WrtLogD("## certificate's notAfterTime : %s", msg); + LogDebug("## certificate's notAfterTime : " << msg); fprintf(stderr, "## certificate's notAfterTime : %s\n", msg); if (storeIdSet.contains(CertStoreId::TIZEN_TEST) || storeIdSet.contains(CertStoreId::TIZEN_VERIFY)) { - WrtLogD("## TIZEN_VERIFY : check certificate Time : FALSE"); + LogDebug("## TIZEN_VERIFY : check certificate Time : FALSE"); fprintf(stderr, "## TIZEN_VERIFY : check certificate Time : FALSE\n"); return WrtSignatureValidator::SIGNATURE_INVALID_CERT_TIME;//SIGNATURE_INVALID; } @@ -348,7 +348,7 @@ WrtSignatureValidator::Result ImplTizen::check( } snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tc.tm_year + 1900, tc.tm_mon + 1,tc.tm_mday ); - WrtLogD("## cmp cert with validation time : %s", msg); + LogDebug("## cmp cert with validation time : " << msg); fprintf(stderr, "## cmp cert with validation time : %s\n", msg); time_t outCurrent = mktime(&tc); @@ -374,30 +374,30 @@ WrtSignatureValidator::Result ImplTizen::check( if (notAfter < nowTime) { context.validationTime = notAfter - TIMET_DAY; - WrtLogW("Author certificate is expired. notAfter..."); + LogWarning("Author certificate is expired. notAfter..."); } */ if (notBefore > nowTime) { - WrtLogW("Author certificate is expired. notBefore time is greater than system-time."); + LogWarning("Author certificate is expired. notBefore time is greater than system-time."); t = localtime(&nowTime); - WrtLogD("System's current Year : %d", (t->tm_year + 1900)); - WrtLogD("System's current month : %d", (t->tm_mon + 1)); - WrtLogD("System's current day : %d", (t->tm_mday)); + LogDebug("System's current Year : " << (t->tm_year + 1900)); + LogDebug("System's current month : " << (t->tm_mon + 1)); + LogDebug("System's current day : " << (t->tm_mday)); t = localtime(¬Before); - WrtLogD("Author certificate's notBefore Year : %d", (t->tm_year + 1900)); - WrtLogD("Author certificate's notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Author certificate's notBefore day : %d", (t->tm_mday)); + LogDebug("Author certificate's notBefore Year : " << (t->tm_year + 1900)); + LogDebug("Author certificate's notBefore month : " << (t->tm_mon + 1)); + LogDebug("Author certificate's notBefore day : " << (t->tm_mday)); context.validationTime = notBefore + TIMET_DAY; t = localtime(&context.validationTime); - WrtLogD("Modified current Year : %d", (t->tm_year + 1900)); - WrtLogD("Modified current notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Modified current notBefore day : %d", (t->tm_mday)); + LogDebug("Modified current Year : " << (t->tm_year + 1900)); + LogDebug("Modified current notBefore month : " << (t->tm_mon + 1)); + LogDebug("Modified current notBefore day : " << (t->tm_mday)); } } #endif @@ -408,20 +408,20 @@ WrtSignatureValidator::Result ImplTizen::check( if (!data.isAuthorSignature()) { if (XmlSec::NO_ERROR != XmlSecSingleton::Instance().validate(&context)) { - WrtLogW("Installation break - invalid package!"); + LogWarning("Installation break - invalid package!"); return WrtSignatureValidator::SIGNATURE_INVALID_HASH_SIGNATURE;//SIGNATURE_INVALID; } data.setReference(context.referenceSet); if (!checkObjectReferences(data)) { - WrtLogW("Failed to check Object References"); + LogWarning("Failed to check Object References"); return WrtSignatureValidator::SIGNATURE_INVALID_HASH_SIGNATURE;//SIGNATURE_INVALID; } ReferenceValidator fileValidator(widgetContentPath); if (ReferenceValidator::NO_ERROR != fileValidator.checkReferences(data)) { - WrtLogW("Invalid package - file references broken"); + LogWarning("Invalid package - file references broken"); return WrtSignatureValidator::SIGNATURE_INVALID_NO_HASH_FILE;//SIGNATURE_INVALID; } } @@ -436,7 +436,7 @@ WrtSignatureValidator::Result ImplTizen::check( coll.load(sortedCertificateList); if (!coll.sort()) { - WrtLogD("Collection does not contain chain!"); + LogDebug("Collection does not contain chain!"); return WrtSignatureValidator::SIGNATURE_INVALID_CERT_CHAIN;//SIGNATURE_INVALID; } @@ -458,7 +458,7 @@ WrtSignatureValidator::Result ImplTizen::check( #endif if (disregard) { - WrtLogW("Signature is disregard. RootCA is not a member of Tizen"); + LogWarning("Signature is disregard. RootCA is not a member of Tizen"); return WrtSignatureValidator::SIGNATURE_INVALID_DISTRIBUTOR_CERT;//SIGNATURE_DISREGARD; } return WrtSignatureValidator::SIGNATURE_VERIFIED; @@ -500,13 +500,13 @@ WrtSignatureValidator::Result ImplWac::check( // First step - sort certificate if (!collection.sort()) { - WrtLogW("Certificates do not form valid chain."); + LogWarning("Certificates do not form valid chain."); return WrtSignatureValidator::SIGNATURE_INVALID; } // Check for error if (collection.empty()) { - WrtLogW("Certificate list in signature is empty."); + LogWarning("Certificate list in signature is empty."); return WrtSignatureValidator::SIGNATURE_INVALID; } @@ -522,22 +522,21 @@ WrtSignatureValidator::Result ImplWac::check( // Is Root CA certificate trusted? CertStoreId::Set storeIdSet = createCertificateIdentifier().find(root); - WrtLogD("Is root certificate from TIZEN_DEVELOPER domain: %d", storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); - WrtLogD("Is root certificate from TIZEN_TEST domain: %d", storeIdSet.contains(CertStoreId::TIZEN_TEST)); - WrtLogD("Is root certificate from TIZEN_VERIFY domain: %d", storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); - WrtLogD("Is root certificate from TIZEN_PUBLIC domain: %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Is root certificate from TIZEN_PARTNER domain: %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Is root certificate from TIZEN_PLATFORM domain: %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); - - WrtLogD("Visibility level is public : %d", storeIdSet.contains(CertStoreId::VIS_PUBLIC)); - WrtLogD("Visibility level is partner : %d", storeIdSet.contains(CertStoreId::VIS_PARTNER)); - WrtLogD("Visibility level is platform : %d", storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Is root certificate from TIZEN_DEVELOPER domain : " << storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)); + LogDebug("Is root certificate from TIZEN_TEST domain : " << storeIdSet.contains(CertStoreId::TIZEN_TEST)); + LogDebug("Is root certificate from TIZEN_VERIFY domain : " << storeIdSet.contains(CertStoreId::TIZEN_VERIFY)); + LogDebug("Is root certificate from TIZEN_PUBLIC domain : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Is root certificate from TIZEN_PARTNER domain : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Is root certificate from TIZEN_PLATFORM domain : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); + LogDebug("Visibility level is public : " << storeIdSet.contains(CertStoreId::VIS_PUBLIC)); + LogDebug("Visibility level is partner : " << storeIdSet.contains(CertStoreId::VIS_PARTNER)); + LogDebug("Visibility level is platform : " << storeIdSet.contains(CertStoreId::VIS_PLATFORM)); if (data.isAuthorSignature()) { if (!storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogW("author-signature.xml has got unrecognized Root CA " + LogWarning("author-signature.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } @@ -546,20 +545,20 @@ WrtSignatureValidator::Result ImplWac::check( { if (storeIdSet.contains(CertStoreId::TIZEN_DEVELOPER)) { - WrtLogW("distributor has author level siganture! Signature will be disregarded."); + LogWarning("distributor has author level siganture! Signature will be disregarded."); return WrtSignatureValidator::SIGNATURE_INVALID; } - WrtLogD("signaturefile name = %s", data.getSignatureFileName().c_str()); + LogDebug("signaturefile name = " << data.getSignatureFileName()); if (data.getSignatureNumber() == 1) { if (storeIdSet.contains(CertStoreId::VIS_PUBLIC) || storeIdSet.contains(CertStoreId::VIS_PARTNER) || storeIdSet.contains(CertStoreId::VIS_PLATFORM)) { - WrtLogD("Root CA for signature1.xml is correct."); + LogDebug("Root CA for signature1.xml is correct."); } else { - WrtLogW("signature1.xml has got unrecognized Root CA " + LogWarning("signature1.xml has got unrecognized Root CA " "certificate. Signature will be disregarded."); disregard = true; } @@ -579,7 +578,7 @@ WrtSignatureValidator::Result ImplWac::check( // If the end certificate is not ROOT CA we should disregard signature // but still signature must be valid... Aaaaaa it's so stupid... if (!(root->isSignedBy(root))) { - WrtLogW("Root CA certificate not found. Chain is incomplete."); + LogWarning("Root CA certificate not found. Chain is incomplete."); // context.allowBrokenChain = true; } @@ -605,22 +604,22 @@ WrtSignatureValidator::Result ImplWac::check( memset(&tc, 0, sizeof(tc)); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", t->tm_year + 1900, t->tm_mon + 1,t->tm_mday ); - WrtLogD("## System's currentTime : %s", msg); + LogDebug("## System's currentTime : " << msg); fprintf(stderr, "## System's currentTime : %s\n", msg); tb = _ASN1_GetTimeT(notBeforeTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tb.tm_year + 1900, tb.tm_mon + 1,tb.tm_mday ); - WrtLogD("## certificate's notBeforeTime : %s", msg); + LogDebug("## certificate's notBeforeTime : " << msg); fprintf(stderr, "## certificate's notBeforeTime : %s\n", msg); ta = _ASN1_GetTimeT(notAfterTime); snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", ta.tm_year + 1900, ta.tm_mon + 1,ta.tm_mday ); - WrtLogD("## certificate's notAfterTime : %s", msg); + LogDebug("## certificate's notAfterTime : " << msg); fprintf(stderr, "## certificate's notAfterTime : %s\n", msg); if (storeIdSet.contains(CertStoreId::TIZEN_VERIFY)) { - WrtLogD("## TIZEN_VERIFY : check certificate Time : FALSE"); + LogDebug("## TIZEN_VERIFY : check certificate Time : FALSE"); fprintf(stderr, "## TIZEN_VERIFY : check certificate Time : FALSE\n"); return WrtSignatureValidator::SIGNATURE_INVALID; } @@ -661,7 +660,7 @@ WrtSignatureValidator::Result ImplWac::check( } snprintf(msg, sizeof(msg), "Year: %d, month: %d, day : %d", tc.tm_year + 1900, tc.tm_mon + 1,tc.tm_mday ); - WrtLogD("## cmp cert with validation time : %s", msg); + LogDebug("## cmp cert with validation time : " << msg); fprintf(stderr, "## cmp cert with validation time : %s\n", msg); time_t outCurrent = mktime(&tc); @@ -687,30 +686,30 @@ WrtSignatureValidator::Result ImplWac::check( if (notAfter < nowTime) { context.validationTime = notAfter - TIMET_DAY; - WrtLogW("Author certificate is expired. notAfter..."); + LogWarning("Author certificate is expired. notAfter..."); } */ if (notBefore > nowTime) { - WrtLogW("Author certificate is expired. notBefore time is greater than system-time."); + LogWarning("Author certificate is expired. notBefore time is greater than system-time."); t = localtime(&nowTime); - WrtLogD("System's current Year : %d", (t->tm_year + 1900)); - WrtLogD("System's current month : %d", (t->tm_mon + 1)); - WrtLogD("System's current day : %d", (t->tm_mday)); + LogDebug("System's current Year : " << (t->tm_year + 1900)); + LogDebug("System's current month : " << (t->tm_mon + 1)); + LogDebug("System's current day : " << (t->tm_mday)); t = localtime(¬Before); - WrtLogD("Author certificate's notBefore Year : %d", (t->tm_year + 1900)); - WrtLogD("Author certificate's notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Author certificate's notBefore day : %d", (t->tm_mday)); + LogDebug("Author certificate's notBefore Year : " << (t->tm_year + 1900)); + LogDebug("Author certificate's notBefore month : " << (t->tm_mon + 1)); + LogDebug("Author certificate's notBefore day : " << (t->tm_mday)); context.validationTime = notBefore + TIMET_DAY; t = localtime(&context.validationTime); - WrtLogD("Modified current Year : %d", (t->tm_year + 1900)); - WrtLogD("Modified current notBefore month : %d", (t->tm_mon + 1)); - WrtLogD("Modified current notBefore day : %d", (t->tm_mday)); + LogDebug("Modified current Year : " << (t->tm_year + 1900)); + LogDebug("Modified current notBefore month : " << (t->tm_mon + 1)); + LogDebug("Modified current notBefore day : " << (t->tm_mday)); } } #endif @@ -718,7 +717,7 @@ WrtSignatureValidator::Result ImplWac::check( if (!data.isAuthorSignature()) { if (XmlSec::NO_ERROR != XmlSecSingleton::Instance().validate(&context)) { - WrtLogW("Installation break - invalid package!"); + LogWarning("Installation break - invalid package!"); return WrtSignatureValidator::SIGNATURE_INVALID; } @@ -730,7 +729,7 @@ WrtSignatureValidator::Result ImplWac::check( ReferenceValidator fileValidator(widgetContentPath); if (ReferenceValidator::NO_ERROR != fileValidator.checkReferences(data)) { - WrtLogW("Invalid package - file references broken"); + LogWarning("Invalid package - file references broken"); return WrtSignatureValidator::SIGNATURE_INVALID; } } @@ -745,7 +744,7 @@ WrtSignatureValidator::Result ImplWac::check( coll.load(sortedCertificateList); if (!coll.sort()) { - WrtLogD("Collection does not contain chain!"); + LogDebug("Collection does not contain chain!"); return WrtSignatureValidator::SIGNATURE_INVALID; } @@ -767,7 +766,7 @@ WrtSignatureValidator::Result ImplWac::check( #endif if (disregard) { - WrtLogW("Signature is disregard. RootCA is not a member of Tizen."); + LogWarning("Signature is disregard. RootCA is not a member of Tizen."); return WrtSignatureValidator::SIGNATURE_DISREGARD; } return WrtSignatureValidator::SIGNATURE_VERIFIED; diff --git a/vcore/src/vcore/XmlsecAdapter.cpp b/vcore/src/vcore/XmlsecAdapter.cpp index 93fc498..6f3c8e7 100644 --- a/vcore/src/vcore/XmlsecAdapter.cpp +++ b/vcore/src/vcore/XmlsecAdapter.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include @@ -78,7 +78,7 @@ void* XmlSec::fileOpenCallback(const char *filename) { std::string path = s_prefixPath + filename; - // WrtLogD("Xmlsec opening: %s", path); + // LogDebug("Xmlsec opening : " << path); return new FileWrapper(xmlFileOpen(path.c_str()),false); } @@ -100,7 +100,6 @@ int XmlSec::fileReadCallback(void *context, int XmlSec::fileCloseCallback(void *context) { - //WrtLogD("Xmlsec closing: "); FileWrapper *fw = static_cast(context); int output = 0; if (!(fw->released)) { @@ -136,11 +135,11 @@ void LogDebugPrint(const char* file, int line, const char* func, if(reason != 256) { fprintf(stderr, "## [validate error]: %s\n", total); - WrtLogE(" %s", total); + LogError(" " << total); } else { - WrtLogD(" %s", total); + LogDebug(" " << total); } } @@ -158,13 +157,13 @@ XmlSec::XmlSec() : #endif if (xmlSecInit() < 0) { - WrtLogE("Xmlsec initialization failed."); + LogError("Xmlsec initialization failed."); ThrowMsg(Exception::InternalError, "Xmlsec initialization failed."); } if (xmlSecCheckVersion() != 1) { xmlSecShutdown(); - WrtLogE("Loaded xmlsec library version is not compatible."); + LogError("Loaded xmlsec library version is not compatible."); ThrowMsg(Exception::InternalError, "Loaded xmlsec library version is not compatible."); } @@ -172,7 +171,7 @@ XmlSec::XmlSec() : #ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING if (xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) < 0) { xmlSecShutdown(); - WrtLogE( + LogError( "Error: unable to load default xmlsec-crypto library. Make sure " "that you have it installed and check shared libraries path " "(LD_LIBRARY_PATH) envornment variable."); @@ -183,14 +182,14 @@ XmlSec::XmlSec() : if (xmlSecCryptoAppInit(NULL) < 0) { xmlSecShutdown(); - WrtLogE("Crypto initialization failed."); + LogError("Crypto initialization failed."); ThrowMsg(Exception::InternalError, "Crypto initialization failed."); } if (xmlSecCryptoInit() < 0) { xmlSecCryptoAppShutdown(); xmlSecShutdown(); - WrtLogE("Xmlsec-crypto initialization failed."); + LogError("Xmlsec-crypto initialization failed."); ThrowMsg(Exception::InternalError, "Xmlsec-crypto initialization failed."); } @@ -238,7 +237,7 @@ XmlSec::Result XmlSec::validateFile(XmlSecContext *context, int size, res = -1; fileExtractPrefix(context); - WrtLogD("Prefix path: %s", s_prefixPath.c_str()); + LogDebug("Prefix path : " << s_prefixPath); xmlSecIOCleanupCallbacks(); @@ -251,7 +250,7 @@ XmlSec::Result XmlSec::validateFile(XmlSecContext *context, /* load file */ doc = xmlParseFile(context->signatureFile.c_str()); if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)) { - WrtLogW("Unable to parse file %s", (context->signatureFile).c_str()); + LogWarning("Unable to parse file " << context->signatureFile); goto done; } @@ -259,14 +258,14 @@ XmlSec::Result XmlSec::validateFile(XmlSecContext *context, node = xmlSecFindNode(xmlDocGetRootElement( doc), xmlSecNodeSignature, xmlSecDSigNs); if (node == NULL) { - WrtLogW("Start node not found in %s", (context->signatureFile).c_str()); + LogWarning("Start node not found in " << context->signatureFile); goto done; } /* create signature context */ dsigCtx = xmlSecDSigCtxCreate(mngr); if (dsigCtx == NULL) { - WrtLogE("Failed to create signature context."); + LogError("Failed to create signature context."); goto done; } @@ -276,14 +275,14 @@ XmlSec::Result XmlSec::validateFile(XmlSecContext *context, } if (context->validationTime) { - WrtLogD("Setting validation time."); + LogDebug("Setting validation time."); dsigCtx->keyInfoReadCtx.certsVerificationTime = context->validationTime; } if( m_noHash == true || m_partialHash == true ) { - WrtLogD("SignatureEx start >> "); + LogDebug("SignatureEx start >> "); if( m_pList == NULL ) { - WrtLogW("## [validate]: uriList does not exist" ); + LogWarning("## [validate]: uriList does not exist" ); fprintf(stderr, "## [validate]: uriList does not exist\n"); res = xmlSecDSigCtxVerifyEx(dsigCtx, node, 1, NULL); } else { @@ -292,7 +291,7 @@ XmlSec::Result XmlSec::validateFile(XmlSecContext *context, if(m_pList == NULL) { - WrtLogW("## [validate]: uriList does not exist" ); + LogWarning("## [validate]: uriList does not exist" ); fprintf(stderr, "## [validate]: uriList does not exist\n"); res = -1; goto done; @@ -327,17 +326,17 @@ XmlSec::Result XmlSec::validateFile(XmlSecContext *context, } if(res < 0) { - WrtLogE("SignatureEx verify error."); + LogError("SignatureEx verify error."); fprintf(stderr, "## [validate error]: SignatureEx verify error\n"); res = -1; goto done; } } else { - WrtLogD("Signature start >> "); + LogDebug("Signature start >> "); /* Verify signature */ if (xmlSecDSigCtxVerify(dsigCtx, node) < 0) { - WrtLogE("Signature verify error."); + LogError("Signature verify error."); fprintf(stderr, "## [validate error]: Signature verify error\n"); res = -1; goto done; @@ -346,24 +345,24 @@ XmlSec::Result XmlSec::validateFile(XmlSecContext *context, if (dsigCtx->keyInfoReadCtx.flags2 & XMLSEC_KEYINFO_ERROR_FLAGS_BROKEN_CHAIN) { - WrtLogW("XMLSEC_KEYINFO_FLAGS_ALLOW_BROKEN_CHAIN was set to true!"); - WrtLogW("Signature contains broken chain!"); + LogWarning("XMLSEC_KEYINFO_FLAGS_ALLOW_BROKEN_CHAIN was set to true!"); + LogWarning("Signature contains broken chain!"); context->errorBrokenChain = true; } /* print verification result to stdout */ if (dsigCtx->status == xmlSecDSigStatusSucceeded) { - WrtLogD("Signature is OK"); + LogDebug("Signature is OK"); res = 0; } else { - WrtLogD("Signature is INVALID"); + LogDebug("Signature is INVALID"); res = -1; goto done; } if (dsigCtx->c14nMethod && dsigCtx->c14nMethod->id && dsigCtx->c14nMethod->id->name) { - // WrtLogI("Canonicalization method: %s", (reinterpret_cast(dsigCtx->c14nMethod->id->name)).c_str()); + // LogInfo("Canonicalization method: " << (reinterpret_cast(dsigCtx->c14nMethod->id->name)).c_str()); } size = xmlSecPtrListGetSize(&(dsigCtx->signedInfoReferences)); @@ -379,9 +378,9 @@ XmlSec::Result XmlSec::validateFile(XmlSecContext *context, reinterpret_cast(dsigRefCtx->digestMethod->id ->name); std::string strDigest(pDigest); - /*WrtLogI("reference digest method: %s" (reinterpret_cast(dsigRefCtx->digestMethod->id->name)).c_str());*/ + /*LogInfo("reference digest method: " << (reinterpret_cast(dsigRefCtx->digestMethod->id->name)).c_str());*/ if (strDigest == DIGEST_MD5) { - WrtLogW("MD5 digest method used! Please use sha"); + LogWarning("MD5 digest method used! Please use sha"); res = -1; break; } @@ -418,7 +417,7 @@ void XmlSec::loadDERCertificateMemory(XmlSecContext *context, int size = i2d_X509(context->certificatePtr->getX509(), &derCertificate); if (!derCertificate) { - WrtLogE("Failed during x509 conversion to der format."); + LogError("Failed during x509 conversion to der format."); ThrowMsg(Exception::InternalError, "Failed during x509 conversion to der format."); } @@ -429,7 +428,7 @@ void XmlSec::loadDERCertificateMemory(XmlSecContext *context, xmlSecKeyDataFormatDer, xmlSecKeyDataTypeTrusted) < 0) { OPENSSL_free(derCertificate); - WrtLogE("Failed to load der certificate from memory."); + LogError("Failed to load der certificate from memory."); ThrowMsg(Exception::InternalError, "Failed to load der certificate from memory."); } @@ -444,7 +443,7 @@ void XmlSec::loadPEMCertificateFile(XmlSecContext *context, context->certificatePath.c_str(), xmlSecKeyDataFormatPem, xmlSecKeyDataTypeTrusted) < 0) { - WrtLogE("Failed to load PEM certificate from file."); + LogError("Failed to load PEM certificate from file."); ThrowMsg(Exception::InternalError, "Failed to load PEM certificate from file."); } @@ -459,19 +458,19 @@ XmlSec::Result XmlSec::validate(XmlSecContext *context) xmlSecErrorsSetCallback(LogDebugPrint); if (!m_initialized) { - WrtLogE("XmlSec is not initialized."); + LogError("XmlSec is not initialized."); ThrowMsg(Exception::InternalError, "XmlSec is not initialized"); } AutoPtr mngr(xmlSecKeysMngrCreate()); if (!mngr.get()) { - WrtLogE("Failed to create keys manager."); + LogError("Failed to create keys manager."); ThrowMsg(Exception::InternalError, "Failed to create keys manager."); } if (xmlSecCryptoAppDefaultKeysMngrInit(mngr.get()) < 0) { - WrtLogE("Failed to initialize keys manager."); + LogError("Failed to initialize keys manager."); ThrowMsg(Exception::InternalError, "Failed to initialize keys manager."); } context->referenceSet.clear(); diff --git a/vcore/src/vcore/api.cpp b/vcore/src/vcore/api.cpp index cb6797f..a093b21 100644 --- a/vcore/src/vcore/api.cpp +++ b/vcore/src/vcore/api.cpp @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include @@ -74,10 +74,6 @@ #define START_TRUSTED "-----BEGIN TRUSTED CERTIFICATE-----" #define END_TRUSTED "-----END TRUSTED CERTIFICATE-----" -#ifndef LOG_TAG -#define LOG_TAG "CERT_SVC" -#endif - using namespace ValidationCore; namespace { @@ -469,7 +465,7 @@ public: fieldId = SUBJECT_COMMONNAME; break; default: - WrtLogE("Not implemented!"); + LogError("Not implemented!"); return CERTSVC_WRONG_ARGUMENT; } @@ -477,16 +473,16 @@ public: cert_svc_cert_context_final); if (ctx.get() == NULL) { - WrtLogW("Error in cert_svc_cert_context_init."); + LogWarning("Error in cert_svc_cert_context_init."); return CERTSVC_FAIL; } - WrtLogD("Match string: %s", value); + LogDebug("Match string : " << value); result = cert_svc_search_certificate(ctx.get(), fieldId, const_cast(value)); - WrtLogD("Search finished!"); + LogDebug("Search finished!"); if (CERT_SVC_ERR_NO_ERROR != result) { - WrtLogW("Error during certificate search"); + LogWarning("Error during certificate search"); return CERTSVC_FAIL; } @@ -501,7 +497,7 @@ public: ScopedCertCtx ctx2(cert_svc_cert_context_init(), cert_svc_cert_context_final); if (ctx2.get() == NULL) { - WrtLogW("Error in cert_svc_cert_context_init."); + LogWarning("Error in cert_svc_cert_context_init."); return CERTSVC_FAIL; } @@ -509,7 +505,7 @@ public: if (CERT_SVC_ERR_NO_ERROR != cert_svc_load_file_to_context(ctx2.get(), fileList->filename)) { - WrtLogW("Error in cert_svc_load_file_to_context"); + LogWarning("Error in cert_svc_load_file_to_context"); return CERTSVC_FAIL; } int certId = addCert(CertificatePtr(new Certificate(*(ctx2.get()->certBuf)))); @@ -1003,14 +999,14 @@ public: xmlDocPtr doc = xmlParseFile(FINGERPRINT_LIST_PATH); if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)) { - WrtLogE("Failed to prase fingerprint_list.xml"); + LogError("Failed to prase fingerprint_list.xml"); return CERTSVC_IO_ERROR; } xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(doc)); if(curPtr == NULL) { - WrtLogE("Can not find root"); + LogError("Can not find root"); ret = CERTSVC_IO_ERROR; goto out; } @@ -1020,7 +1016,7 @@ public: xmlAttr* attr = curPtr->properties; if(!attr->children || !attr->children->content) { - WrtLogE("Failed to get fingerprints from list"); + LogError("Failed to get fingerprints from list"); ret = CERTSVC_FAIL; goto out; } @@ -1029,18 +1025,18 @@ public: xmlNodePtr FpPtr = xmlFirstElementChild(curPtr); if(FpPtr == NULL) { - WrtLogE("Could not find fingerprint"); + LogError("Could not find fingerprint"); ret = CERTSVC_FAIL; goto out; } - WrtLogD("Retrieve level : %s", strLevel); + LogDebug("Retrieve level : " << strLevel); while(FpPtr) { xmlChar *content = xmlNodeGetContent(FpPtr); if(xmlStrcmp(content, (xmlChar*)fingerprint.c_str()) == 0) { - WrtLogD("fingerprint : %s are %s", content, strLevel); + LogDebug("fingerprint : " << content << " are " << strLevel); if(!xmlStrcmp(strLevel, xmlPathDomainPlatform)) { *visibility = CERTSVC_VISIBILITY_PLATFORM; @@ -1305,7 +1301,7 @@ out: result = c_certsvc_pkcs12_load_certificates_from_store(storeType, pfxIdString.privateHandler, &certs, &ncerts); if (result != CERTSVC_SUCCESS) { - WrtLogE("Unable to load certificates from store."); + LogError("Unable to load certificates from store."); return result; } @@ -1314,7 +1310,7 @@ out: Alias.privateLength = strlen(certs[i]); result = certsvc_pkcs12_get_certificate_info_from_store(instance, storeType, Alias, &certBuffer, &certLength); if (result != CERTSVC_SUCCESS || !certBuffer) { - WrtLogE("Failed to get certificate buffer."); + LogError("Failed to get certificate buffer."); return CERTSVC_FAIL; } @@ -1339,7 +1335,7 @@ out: } if (!trailer) { - WrtLogE("Failed the get the certificate."); + LogError("Failed the get the certificate."); return CERTSVC_FAIL; } @@ -1689,14 +1685,14 @@ int certsvc_pkcs12_dup_evp_pkey( &size); if (result != CERTSVC_SUCCESS) { - WrtLogE("Error in certsvc_pkcs12_private_key_dup"); + LogError("Error in certsvc_pkcs12_private_key_dup"); return result; } BIO *b = BIO_new(BIO_s_mem()); if ((int)size != BIO_write(b, buffer, size)) { - WrtLogE("Error in BIO_write"); + LogError("Error in BIO_write"); BIO_free_all(b); certsvc_pkcs12_private_key_free(buffer); return CERTSVC_FAIL; @@ -1712,7 +1708,7 @@ int certsvc_pkcs12_dup_evp_pkey( return CERTSVC_SUCCESS; } - WrtLogE("Result is null. Openssl REASON code is: %d", ERR_GET_REASON(ERR_peek_last_error())); + LogError("Result is null. Openssl REASON code is : " << ERR_GET_REASON(ERR_peek_last_error())); return CERTSVC_FAIL; } @@ -1891,7 +1887,7 @@ int certsvc_certificate_get_visibility(CertSvcCertificate certificate, int* visi return impl(certificate.privateInstance)->getVisibility(certificate, visibility); } catch (...) { - WrtLogE("exception occur"); + LogError("exception occur"); } return CERTSVC_FAIL; } @@ -1933,19 +1929,19 @@ int certsvc_get_certificate(CertSvcInstance instance, try { result = c_certsvc_pkcs12_get_certificate_buffer_from_store(storeType, gname, &certBuffer, &length); if (result != CERTSVC_SUCCESS) { - WrtLogE("Failed to get certificate buffer from store."); + LogError("Failed to get certificate buffer from store."); return result; } pBio = BIO_new(BIO_s_mem()); if (pBio == NULL) { - WrtLogE("Failed to allocate memory."); + LogError("Failed to allocate memory."); result = CERTSVC_BAD_ALLOC; } length = BIO_write(pBio, (const void*) certBuffer, length); if (length < 1) { - WrtLogE("Failed to load cert into bio."); + LogError("Failed to load cert into bio."); result = CERTSVC_BAD_ALLOC; } @@ -1960,13 +1956,13 @@ int certsvc_get_certificate(CertSvcInstance instance, fileName.append(CERTSVC_PKCS12_STORAGE_DIR); fileName.append(gname); if (!(fp_write = fopen(fileName.c_str(), "w"))) { - WrtLogE("Failed to open the file for writing, [%s].", fileName.c_str()); + LogError("Failed to open the file for writing, [" << fileName << "]."); result = CERTSVC_FAIL; goto error; } if (fwrite(certBuffer, sizeof(char), (size_t)length, fp_write) != (size_t)length) { - WrtLogE("Fail to write certificate."); + LogError("Fail to write certificate."); result = CERTSVC_FAIL; goto error; } @@ -1974,7 +1970,7 @@ int certsvc_get_certificate(CertSvcInstance instance, fclose(fp_write); result = certsvc_certificate_new_from_file(instance, fileName.c_str(), certificate); if (result != CERTSVC_SUCCESS) { - WrtLogE("Failed to construct certificate from buffer."); + LogError("Failed to construct certificate from buffer."); goto error; } unlink(fileName.c_str()); @@ -1996,13 +1992,13 @@ int certsvc_pkcs12_check_alias_exists_in_store(CertSvcInstance instance, int *is_unique) { if (pfxIdString.privateHandler == NULL || pfxIdString.privateLength<=0) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_WRONG_ARGUMENT; } try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } @@ -2015,7 +2011,7 @@ int certsvc_pkcs12_free_certificate_list_loaded_from_store(CertSvcInstance insta CertSvcStoreCertList** certList) { if (*certList == NULL) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_WRONG_ARGUMENT; } @@ -2032,13 +2028,13 @@ int certsvc_pkcs12_get_certificate_list_from_store(CertSvcInstance instance, int* length) { if (*certList != NULL) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_WRONG_ARGUMENT; } try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } @@ -2054,13 +2050,13 @@ int certsvc_pkcs12_get_end_user_certificate_list_from_store(CertSvcInstance inst int* length) { if (*certList != NULL) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_WRONG_ARGUMENT; } try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } @@ -2075,13 +2071,13 @@ int certsvc_pkcs12_get_root_certificate_list_from_store(CertSvcInstance instance int* length) { if (*certList != NULL) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_WRONG_ARGUMENT; } try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } @@ -2097,13 +2093,13 @@ int certsvc_pkcs12_get_certificate_info_from_store(CertSvcInstance instance, size_t* certSize) { if (*certBuffer != NULL) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_WRONG_ARGUMENT; } try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } @@ -2118,7 +2114,7 @@ int certsvc_pkcs12_delete_certificate_from_store(CertSvcInstance instance, { try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } return impl(instance)->pkcsDeleteCertFromStore(storeType, gname); @@ -2135,7 +2131,7 @@ int certsvc_pkcs12_import_from_file_to_store(CertSvcInstance instance, try { if (path.privateHandler != NULL) { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } return impl(instance)->pkcsImportToStore(storeType, path, password, pfxIdString); @@ -2152,13 +2148,13 @@ int certsvc_pkcs12_get_alias_name_for_certificate_in_store(CertSvcInstance insta char **alias) { if (gname.privateHandler == NULL || gname.privateLength<=0) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_WRONG_ARGUMENT; } try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } return impl(instance)->pkcsGetAliasNameForCertInStore(storeType, gname, alias); @@ -2174,7 +2170,7 @@ int certsvc_pkcs12_set_certificate_status_to_store(CertSvcInstance instance, { try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } return impl(instance)->pkcsSetCertStatusToStore(storeType, is_root_app, gname, status); @@ -2190,7 +2186,7 @@ int certsvc_pkcs12_get_certificate_status_from_store( { try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } return impl(instance)->pkcsGetCertStatusFromStore(storeType, gname, status); @@ -2205,7 +2201,7 @@ int certsvc_pkcs12_get_certificate_from_store(CertSvcInstance instance, { try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } return impl(instance)->getCertFromStore(instance, storeType, gname, certificate); @@ -2221,7 +2217,7 @@ int certsvc_pkcs12_load_certificate_list_from_store( { try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } return impl(instance)->getPkcsCertificateListFromStore(instance, storeType, pfxIdString, certificateList); @@ -2238,7 +2234,7 @@ int certsvc_pkcs12_private_key_dup_from_store( { try { if (!impl(instance)->checkValidStoreType(storeType)) { - WrtLogE("Invalid input parameter."); + LogError("Invalid input parameter."); return CERTSVC_INVALID_STORE_TYPE; } return impl(instance)->getPkcsPrivateKeyFromStore(storeType, gname, certBuffer, certSize); @@ -2257,13 +2253,13 @@ int certsvc_pkcs12_dup_evp_pkey_from_store( int result = certsvc_pkcs12_private_key_dup_from_store(instance, storeType, gname, &buffer, &size); if (result != CERTSVC_SUCCESS) { - WrtLogE("Error in certsvc_pkcs12_private_key_dup"); + LogError("Error in certsvc_pkcs12_private_key_dup"); return result; } BIO *b = BIO_new(BIO_s_mem()); if ((int)size != BIO_write(b, buffer, size)) { - WrtLogE("Error in BIO_write"); + LogError("Error in BIO_write"); BIO_free_all(b); certsvc_pkcs12_private_key_free(buffer); return CERTSVC_FAIL; @@ -2275,7 +2271,7 @@ int certsvc_pkcs12_dup_evp_pkey_from_store( if (*pkey) return CERTSVC_SUCCESS; - WrtLogE("Result is null. Openssl REASON code is: %d", ERR_GET_REASON(ERR_peek_last_error())); + LogError("Result is null. Openssl REASON code is : " << ERR_GET_REASON(ERR_peek_last_error())); return CERTSVC_FAIL; } diff --git a/vcore/src/vcore/exception.cpp b/vcore/src/vcore/exception.cpp index 20d359f..fc3e734 100644 --- a/vcore/src/vcore/exception.cpp +++ b/vcore/src/vcore/exception.cpp @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include @@ -33,8 +33,7 @@ void (*Exception::m_terminateHandler)() = NULL; void LogUnhandledException(const std::string &str) { - // Logging to dlog - VcoreLogD("%s", str.c_str()); + LogDebug("" << str); } void LogUnhandledException(const std::string &str, @@ -42,7 +41,6 @@ void LogUnhandledException(const std::string &str, int line, const char *function) { - // Logging to dlog - VcoreLogE("[%s:%d][%s]%s", filename, line, function, str.c_str()); + LogError("[" << filename << ":" << line << "][" << function << "]" << str); } } // namespace ValidationCore -- 2.7.4