Return invalid handle ec appropriately on client 76/69376/1
authorKyungwook Tak <k.tak@samsung.com>
Fri, 13 May 2016 03:00:02 +0000 (12:00 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Fri, 13 May 2016 03:00:54 +0000 (12:00 +0900)
Change-Id: Icaf77dcdff29321b97a57242e7d3a11f378c272c
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/framework/client/content-screening.cpp
src/framework/client/web-protection.cpp

index 33257d7..d6fb4fb 100644 (file)
@@ -110,7 +110,7 @@ int csr_cs_context_create(csr_cs_context_h *phandle)
        EXCEPTION_SAFE_START
 
        if (phandle == nullptr)
-               return CSR_ERROR_INVALID_PARAMETER;
+               return CSR_ERROR_INVALID_HANDLE;
 
        *phandle = reinterpret_cast<csr_cs_context_h>(
                                   new Client::HandleExt(SockId::CS, ContextShPtr(new CsContext())));
@@ -126,7 +126,7 @@ int csr_cs_context_destroy(csr_cs_context_h handle)
        EXCEPTION_SAFE_START
 
        if (handle == nullptr)
-               return CSR_ERROR_INVALID_PARAMETER;
+               return CSR_ERROR_INVALID_HANDLE;
 
        delete reinterpret_cast<Client::HandleExt *>(handle);
 
@@ -140,7 +140,9 @@ int csr_cs_set_ask_user(csr_cs_context_h handle, csr_cs_ask_user_e ask_user)
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || !_isValid(ask_user))
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (!_isValid(ask_user))
                return CSR_ERROR_INVALID_PARAMETER;
 
        reinterpret_cast<Client::HandleExt *>(handle)->getContext()->set(
@@ -156,7 +158,9 @@ int csr_cs_set_popup_message(csr_cs_context_h handle, const char *message)
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || message == nullptr || message[0] == '\0')
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (message == nullptr || message[0] == '\0')
                return CSR_ERROR_INVALID_PARAMETER;
 
        reinterpret_cast<Client::HandleExt *>(handle)->getContext()->set(
@@ -172,7 +176,9 @@ int csr_cs_set_core_usage(csr_cs_context_h handle, csr_cs_core_usage_e usage)
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || !_isValid(usage))
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (!_isValid(usage))
                return CSR_ERROR_INVALID_PARAMETER;
 
        reinterpret_cast<Client::HandleExt *>(handle)->getContext()->set(
@@ -190,7 +196,7 @@ int csr_cs_set_scan_on_cloud(csr_cs_context_h handle)
        EXCEPTION_SAFE_START
 
        if (handle == nullptr)
-               return CSR_ERROR_INVALID_PARAMETER;
+               return CSR_ERROR_INVALID_HANDLE;
 
        reinterpret_cast<Client::HandleExt *>(handle)->getContext()->set(
                static_cast<int>(CsContext::Key::ScanOnCloud), true);
@@ -206,7 +212,9 @@ int csr_cs_scan_data(csr_cs_context_h handle, const unsigned char *data,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || pdetected == nullptr || data == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pdetected == nullptr || data == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -242,8 +250,9 @@ int csr_cs_scan_file(csr_cs_context_h handle, const char *file_path,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || pdetected == nullptr
-                       || file_path == nullptr || file_path[0] == '\0')
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pdetected == nullptr || file_path == nullptr || file_path[0] == '\0')
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -279,11 +288,13 @@ int csr_cs_set_callback_on_file_scanned(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
-
-       if (hExt == nullptr || callback == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (callback == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
+       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
+
        hExt->m_cb.onScanned = callback;
 
        return CSR_ERROR_NONE;
@@ -297,11 +308,13 @@ int csr_cs_set_callback_on_detected(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
-
-       if (hExt == nullptr || callback == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (callback == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
+       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
+
        hExt->m_cb.onDetected = callback;
 
        return CSR_ERROR_NONE;
@@ -315,11 +328,13 @@ int csr_cs_set_callback_on_completed(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
-
-       if (hExt == nullptr || callback == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (callback == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
+       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
+
        hExt->m_cb.onCompleted = callback;
 
        return CSR_ERROR_NONE;
@@ -333,11 +348,13 @@ int csr_cs_set_callback_on_cancelled(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
-
-       if (hExt == nullptr || callback == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (callback == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
+       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
+
        hExt->m_cb.onCancelled = callback;
 
        return CSR_ERROR_NONE;
@@ -351,11 +368,13 @@ int csr_cs_set_callback_on_error(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
-
-       if (hExt == nullptr || callback == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (callback == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
+       auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
+
        hExt->m_cb.onError = callback;
 
        return CSR_ERROR_NONE;
@@ -369,7 +388,9 @@ int csr_cs_scan_files_async(csr_cs_context_h handle, const char *file_paths[],
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || file_paths == nullptr || count == 0)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (file_paths == nullptr || count == 0)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -400,7 +421,9 @@ int csr_cs_scan_dir_async(csr_cs_context_h handle, const char *dir_path,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || dir_path == nullptr || dir_path[0] == '\0')
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (dir_path == nullptr || dir_path[0] == '\0')
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -422,7 +445,9 @@ int csr_cs_scan_dirs_async(csr_cs_context_h handle, const char *dir_paths[],
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || dir_paths == nullptr || count == 0)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (dir_paths == nullptr || count == 0)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -453,7 +478,7 @@ int csr_cs_scan_cancel(csr_cs_context_h handle)
        EXCEPTION_SAFE_START
 
        if (handle == nullptr)
-               return CSR_ERROR_INVALID_PARAMETER;
+               return CSR_ERROR_INVALID_HANDLE;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
 
@@ -473,7 +498,9 @@ int csr_cs_detected_get_severity(csr_cs_detected_h detected,
 {
        EXCEPTION_SAFE_START
 
-       if (detected == nullptr || pseverity == nullptr)
+       if (detected == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pseverity == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *pseverity = reinterpret_cast<CsDetected *>(detected)->severity;
@@ -489,7 +516,9 @@ int csr_cs_detected_get_malware_name(csr_cs_detected_h detected,
 {
        EXCEPTION_SAFE_START
 
-       if (detected == nullptr || pmalware_name == nullptr)
+       if (detected == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pmalware_name == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *pmalware_name = reinterpret_cast<CsDetected *>(detected)->malwareName.c_str();
@@ -505,7 +534,9 @@ int csr_cs_detected_get_detailed_url(csr_cs_detected_h detected,
 {
        EXCEPTION_SAFE_START
 
-       if (detected == nullptr || pdetailed_url == nullptr)
+       if (detected == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pdetailed_url == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *pdetailed_url = reinterpret_cast<CsDetected *>(detected)->detailedUrl.c_str();
@@ -516,12 +547,13 @@ int csr_cs_detected_get_detailed_url(csr_cs_detected_h detected,
 }
 
 API
-int csr_cs_detected_get_timestamp(csr_cs_detected_h detected,
-                                                                 time_t *ptimestamp)
+int csr_cs_detected_get_timestamp(csr_cs_detected_h detected, time_t *ptimestamp)
 {
        EXCEPTION_SAFE_START
 
-       if (detected == nullptr || ptimestamp == nullptr)
+       if (detected == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (ptimestamp == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *ptimestamp = reinterpret_cast<CsDetected *>(detected)->ts;
@@ -532,12 +564,13 @@ int csr_cs_detected_get_timestamp(csr_cs_detected_h detected,
 }
 
 API
-int csr_cs_detected_get_file_name(csr_cs_detected_h detected,
-                                                                 const char **pfile_name)
+int csr_cs_detected_get_file_name(csr_cs_detected_h detected, const char **pfile_name)
 {
        EXCEPTION_SAFE_START
 
-       if (detected == nullptr || pfile_name == nullptr)
+       if (detected == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pfile_name == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *pfile_name = reinterpret_cast<CsDetected *>(detected)->targetName.c_str();
@@ -553,7 +586,9 @@ int csr_cs_detected_get_user_response(csr_cs_detected_h detected,
 {
        EXCEPTION_SAFE_START
 
-       if (detected == nullptr || presponse == nullptr)
+       if (detected == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (presponse == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *presponse = reinterpret_cast<CsDetected *>(detected)->response;
@@ -568,7 +603,9 @@ int csr_cs_detected_is_app(csr_cs_detected_h detected, bool *pis_app)
 {
        EXCEPTION_SAFE_START
 
-       if (detected == nullptr || pis_app == nullptr)
+       if (detected == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pis_app == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *pis_app = reinterpret_cast<CsDetected *>(detected)->isApp;
@@ -583,7 +620,9 @@ int csr_cs_detected_get_pkg_id(csr_cs_detected_h detected, const char **ppkg_id)
 {
        EXCEPTION_SAFE_START
 
-       if (detected == nullptr || ppkg_id == nullptr)
+       if (detected == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (ppkg_id == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *ppkg_id = reinterpret_cast<CsDetected *>(detected)->pkgId.c_str();
@@ -599,7 +638,9 @@ int csr_cs_judge_detected_malware(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || detected == nullptr || !_isValid(action))
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (detected == nullptr || !_isValid(action))
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -624,7 +665,9 @@ int csr_cs_get_detected_malware(csr_cs_context_h handle, const char *file_path,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || file_path == nullptr || pdetected == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (file_path == nullptr || pdetected == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -659,8 +702,9 @@ int csr_cs_get_detected_malwares(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || dir_paths == nullptr || count == 0
-                       || plist == nullptr || pcount == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (dir_paths == nullptr || count == 0 || plist == nullptr || pcount == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -714,7 +758,9 @@ int csr_cs_get_ignored_malware(csr_cs_context_h handle, const char *file_path,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || file_path == nullptr || pdetected == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (file_path == nullptr || pdetected == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -749,8 +795,9 @@ int csr_cs_get_ignored_malwares(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || dir_paths == nullptr || count == 0
-                       || plist == nullptr || pcount == nullptr)
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (dir_paths == nullptr || count == 0 || plist == nullptr || pcount == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -804,7 +851,9 @@ int csr_cs_dlist_get_detected(csr_cs_detected_list_h list, size_t index,
 {
        EXCEPTION_SAFE_START
 
-       if (list == nullptr || pdetected == nullptr)
+       if (list == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pdetected == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto dListPtr = reinterpret_cast<ResultList *>(list);
index 4683ee3..82013d6 100644 (file)
@@ -39,7 +39,7 @@ int csr_wp_context_create(csr_wp_context_h *phandle)
        EXCEPTION_SAFE_START
 
        if (phandle == nullptr)
-               return CSR_ERROR_INVALID_PARAMETER;
+               return CSR_ERROR_INVALID_HANDLE;
 
        *phandle = reinterpret_cast<csr_wp_context_h>(
                                   new Client::Handle(SockId::WP, std::make_shared<WpContext>()));
@@ -55,7 +55,7 @@ int csr_wp_context_destroy(csr_wp_context_h handle)
        EXCEPTION_SAFE_START
 
        if (handle == nullptr)
-               return CSR_ERROR_INVALID_PARAMETER;
+               return CSR_ERROR_INVALID_HANDLE;
 
        delete reinterpret_cast<Client::Handle *>(handle);
 
@@ -69,8 +69,9 @@ int csr_wp_set_ask_user(csr_wp_context_h handle, csr_wp_ask_user_e ask_user)
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr
-                       || (ask_user != CSR_WP_NOT_ASK_USER && ask_user != CSR_WP_ASK_USER))
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (ask_user != CSR_WP_NOT_ASK_USER && ask_user != CSR_WP_ASK_USER)
                return CSR_ERROR_INVALID_PARAMETER;
 
        reinterpret_cast<Client::Handle *>(handle)->getContext()->set(
@@ -86,7 +87,9 @@ int csr_wp_set_popup_message(csr_wp_context_h handle, const char *message)
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || message == nullptr || message[0] == '\0')
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (message == nullptr || message[0] == '\0')
                return CSR_ERROR_INVALID_PARAMETER;
 
        reinterpret_cast<Client::Handle *>(handle)->getContext()->set(
@@ -103,8 +106,9 @@ int csr_wp_check_url(csr_wp_context_h handle, const char *url,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || presult == nullptr
-                       || url == nullptr || url[0] == '\0')
+       if (handle == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (presult == nullptr || url == nullptr || url[0] == '\0')
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto h = reinterpret_cast<Client::Handle *>(handle);
@@ -132,7 +136,9 @@ int csr_wp_result_get_risk_level(csr_wp_check_result_h result,
 {
        EXCEPTION_SAFE_START
 
-       if (result == nullptr || plevel == nullptr)
+       if (result == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (plevel == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *plevel = reinterpret_cast<WpResult *>(result)->riskLevel;
@@ -148,7 +154,9 @@ int csr_wp_result_get_detailed_url(csr_wp_check_result_h result,
 {
        EXCEPTION_SAFE_START
 
-       if (result == nullptr || pdetailed_url == nullptr)
+       if (result == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (pdetailed_url == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *pdetailed_url = reinterpret_cast<WpResult *>(result)->detailedUrl.c_str();
@@ -165,7 +173,9 @@ int csr_wp_result_get_user_response(csr_wp_check_result_h result,
 {
        EXCEPTION_SAFE_START
 
-       if (result == nullptr || presponse == nullptr)
+       if (result == nullptr)
+               return CSR_ERROR_INVALID_HANDLE;
+       else if (presponse == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *presponse = reinterpret_cast<WpResult *>(result)->response;