common/connection.cpp
common/cs-context.cpp
common/cs-detected.cpp
+ common/wp-context.cpp
+ common/wp-result.cpp
common/kvp-container.cpp
common/types.cpp
common/dispatcher.cpp
return CSR_ERROR_INVALID_PARAMETER;
reinterpret_cast<Result *>(detected)->get(
- static_cast<int>(CsDetected::Key::MalwareName), pdetailed_url);
+ static_cast<int>(CsDetected::Key::DetailedUrl), pdetailed_url);
return CSR_ERROR_NONE;
#include "client/handle.h"
#include "common/types.h"
#include "common/command-id.h"
+#include "common/wp-context.h"
+#include "common/wp-result.h"
#include "common/audit/logger.h"
using namespace Csr;
API
-int csr_wp_context_create(csr_wp_context_h* phandle)
+int csr_wp_context_create(csr_wp_context_h *phandle)
{
EXCEPTION_SAFE_START
return CSR_ERROR_INVALID_PARAMETER;
*phandle = reinterpret_cast<csr_wp_context_h>(
- new Client::Handle(std::make_shared<Context>()));
+ new Client::Handle(std::make_shared<Context>()));
return CSR_ERROR_NONE;
API
int csr_wp_set_ask_user(csr_wp_context_h handle, csr_wp_ask_user_e ask_user)
{
- (void) handle;
- (void) ask_user;
+ EXCEPTION_SAFE_START
+
+ if (handle == nullptr
+ || (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(
+ static_cast<int>(WpContext::Key::AskUser), static_cast<int>(ask_user));
- DEBUG("start");
return CSR_ERROR_NONE;
+
+ EXCEPTION_SAFE_END
}
API
-int csr_wp_set_popup_message(csr_wp_context_h handle, const char* message)
+int csr_wp_set_popup_message(csr_wp_context_h handle, const char *message)
{
- (void) handle;
- (void) message;
+ EXCEPTION_SAFE_START
+
+ if (handle == nullptr || message == nullptr || message[0] == '\0')
+ return CSR_ERROR_INVALID_PARAMETER;
+
+ reinterpret_cast<Client::Handle *>(handle)->getContext()->set(
+ static_cast<int>(WpContext::Key::PopupMessage), message);
- DEBUG("start");
return CSR_ERROR_NONE;
+
+ EXCEPTION_SAFE_END
}
API
EXCEPTION_SAFE_START
if (handle == nullptr || presult == nullptr
- || url == nullptr || url[0] == '\0')
+ || url == nullptr || url[0] == '\0')
return CSR_ERROR_INVALID_PARAMETER;
auto h = reinterpret_cast<Client::Handle *>(handle);
auto ret = h->dispatch<std::pair<int, Result *>>(
- CommandId::CHECK_URL,
- h->getContext(),
- std::string(url));
+ CommandId::CHECK_URL,
+ h->getContext(),
+ std::string(url));
if (ret.first != CSR_ERROR_NONE) {
ERROR("Error! ret: " << ret.first);
}
API
-int csr_wp_result_get_risk_level(csr_wp_check_result_h result, csr_wp_risk_level_e* plevel)
+int csr_wp_result_get_risk_level(csr_wp_check_result_h result, csr_wp_risk_level_e *plevel)
{
- (void) result;
- (void) plevel;
+ EXCEPTION_SAFE_START
+
+ if (result == nullptr || plevel == nullptr)
+ return CSR_ERROR_INVALID_PARAMETER;
+
+ int intRiskLevel;
+ reinterpret_cast<Result *>(result)->get(
+ static_cast<int>(WpResult::Key::RiskLevel), intRiskLevel);
+ *plevel = static_cast<csr_wp_risk_level_e>(intRiskLevel);
- DEBUG("start");
return CSR_ERROR_NONE;
+
+ EXCEPTION_SAFE_END
}
API
-int csr_wp_result_get_user_response(csr_wp_check_result_h result, csr_wp_user_response_e* presponse)
+int csr_wp_result_get_detailed_url(csr_wp_check_result_h result, const char **pdetailed_url)
{
- (void) result;
- (void) presponse;
+ EXCEPTION_SAFE_START
+
+ if (result == nullptr || pdetailed_url == nullptr)
+ return CSR_ERROR_INVALID_PARAMETER;
+
+ reinterpret_cast<Result *>(result)->get(
+ static_cast<int>(WpResult::Key::DetailedUrl), pdetailed_url);
+
+ return CSR_ERROR_NONE;
+
+ EXCEPTION_SAFE_END
+}
+
+
+API
+int csr_wp_result_get_user_response(csr_wp_check_result_h result, csr_wp_user_response_e *presponse)
+{
+ EXCEPTION_SAFE_START
+
+ if (result == nullptr || presponse == nullptr)
+ return CSR_ERROR_INVALID_PARAMETER;
+
+ int intResponse;
+ reinterpret_cast<Result *>(result)->get(
+ static_cast<int>(WpResult::Key::UserResponse), intResponse);
+ *presponse = static_cast<csr_wp_user_response_e>(intResponse);
- DEBUG("start");
return CSR_ERROR_NONE;
+
+ EXCEPTION_SAFE_END
}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 wp-context.cpp
+ * @author Dongsun Lee (ds73.lee@samsung.com)
+ * @version 1.0
+ * @brief Wep protection context with dependent options
+ */
+#include "common/wp-context.h"
+
+#include <stdexcept>
+
+#include "common/audit/logger.h"
+
+namespace Csr {
+
+WpContext::WpContext() :
+ m_popupMessage(),
+ m_askUser(CSR_WP_NOT_ASK_USER)
+{
+}
+
+WpContext::~WpContext()
+{
+}
+
+WpContext::WpContext(IStream &stream) : Context(stream)
+{
+ int intAskUser;
+ Deserializer<std::string, int>::Deserialize(stream,
+ m_popupMessage, intAskUser);
+
+ m_askUser = static_cast<csr_wp_ask_user_e>(intAskUser);
+}
+
+void WpContext::Serialize(IStream &stream) const
+{
+ Serializer<std::string, int>::Serialize(stream, m_popupMessage, static_cast<int>(m_askUser));
+}
+
+WpContext::WpContext(WpContext &&other) :
+ Context(std::move(other)),
+ m_popupMessage(std::move(other.m_popupMessage)),
+ m_askUser(other.m_askUser)
+{
+}
+
+WpContext &WpContext::operator=(WpContext && other)
+{
+ if (this == &other)
+ return *this;
+
+ Context::operator=(std::move(other));
+
+ m_popupMessage = std::move(other.m_popupMessage);
+ m_askUser = other.m_askUser;
+
+ return *this;
+}
+
+WpContext::WpContext(const WpContext &other) :
+ Context(other),
+ m_popupMessage(other.m_popupMessage),
+ m_askUser(other.m_askUser)
+{
+}
+
+WpContext &WpContext::operator=(const WpContext &other)
+{
+ Context::operator=(other);
+
+ m_popupMessage = other.m_popupMessage;
+ m_askUser = other.m_askUser;
+
+ return *this;
+}
+
+void WpContext::set(int key, int value)
+{
+ switch (static_cast<Key>(key)) {
+ case Key::AskUser:
+ m_askUser = static_cast<csr_wp_ask_user_e>(value);
+ break;
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as int. value=" << value));
+ }
+}
+
+void WpContext::set(int key, const std::string &value)
+{
+ switch (static_cast<Key>(key)) {
+ case Key::PopupMessage:
+ m_popupMessage = value;
+ break;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as std::string. value=" << value));
+ }
+}
+
+void WpContext::set(int key, const char *value)
+{
+ switch (static_cast<Key>(key)) {
+ case Key::PopupMessage:
+ m_popupMessage = value;
+ break;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as char*. value=" << value));
+ }
+}
+
+void WpContext::get(int key, int &value) const
+{
+ switch (static_cast<Key>(key)) {
+ case Key::AskUser:
+ value = static_cast<int>(m_askUser);
+ break;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as int. value=" << value));
+ }
+}
+
+void WpContext::get(int key, std::string &value) const
+{
+ switch (static_cast<Key>(key)) {
+ case Key::PopupMessage:
+ value = m_popupMessage;
+ break;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as std::string. value=" << value));
+ }
+}
+
+void WpContext::get(int key, const char **value) const
+{
+ if (value == nullptr)
+ throw std::logic_error("invalud argument. output storage pointer is null.");
+
+ switch (static_cast<Key>(key)) {
+ case Key::PopupMessage:
+ *value = m_popupMessage.c_str();
+ break;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as char*. value=" << value));
+ }
+}
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 wp-context.h
+ * @author Dongsun Lee (ds73.lee@samsung.com)
+ * @version 1.0
+ * @brief Wep protection context with dependent options
+ */
+#pragma once
+
+#include <string>
+
+#include "common/types.h"
+#include "csr/web-protection-types.h"
+
+namespace Csr {
+
+class WpContext : public Context {
+public:
+ enum class Key : int {
+ PopupMessage = 0x01, // string
+ AskUser = 0x10, // int
+ };
+
+ WpContext();
+ virtual ~WpContext();
+
+ WpContext(IStream &);
+ virtual void Serialize(IStream &) const;
+
+ WpContext(WpContext &&);
+ WpContext &operator=(WpContext &&);
+
+ WpContext(const WpContext &);
+ WpContext &operator=(const WpContext &);
+
+ virtual void set(int, int) override;
+ virtual void set(int, const std::string &) override;
+ virtual void set(int, const char *) override;
+
+ virtual void get(int, int &) const override;
+ virtual void get(int, std::string &) const override;
+ virtual void get(int, const char **) const override;
+
+private:
+ std::string m_popupMessage;
+ csr_wp_ask_user_e m_askUser;
+};
+
+} // end of namespace Csr
--- /dev/null
+/*
+ * Copyright (c) 2016 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 wp-result.cpp
+ * @author Dongsun Lee (ds73.lee@samsung.com)
+ * @version 1.0
+ * @brief Web protection result
+ */
+#include "common/wp-result.h"
+
+#include <stdexcept>
+
+#include "common/audit/logger.h"
+
+namespace Csr {
+
+WpResult::WpResult() :
+ m_riskLevel(CSR_WP_RISK_LOW),
+ m_detailedUrl(),
+ m_response(CSR_WP_NO_ASK_USER)
+{
+}
+
+WpResult::~WpResult()
+{
+}
+
+WpResult::WpResult(IStream &stream)
+{
+ int intRiskLevel;
+ int intResponse;
+ Deserializer<int, std::string, int>
+ ::Deserialize(stream, intRiskLevel, m_detailedUrl, intResponse);
+
+ m_riskLevel = static_cast<csr_wp_risk_level_e>(intRiskLevel);
+ m_response = static_cast<csr_wp_user_response_e>(intResponse);
+}
+
+void WpResult::Serialize(IStream &stream) const
+{
+ Serializer<int, std::string, int>
+ ::Serialize(stream, static_cast<int>(m_riskLevel), m_detailedUrl, static_cast<int>(m_response));
+}
+
+WpResult::WpResult(WpResult &&other) :
+ Result(std::move(other)),
+ m_riskLevel(other.m_riskLevel),
+ m_detailedUrl(std::move(other.m_detailedUrl)),
+ m_response(other.m_response)
+{
+}
+
+WpResult &WpResult::operator=(WpResult && other)
+{
+ if (this == &other)
+ return *this;
+
+ Result::operator=(std::move(other));
+
+ m_detailedUrl = std::move(other.m_detailedUrl);
+ m_riskLevel = other.m_riskLevel;
+ m_response = other.m_response;
+
+ return *this;
+}
+
+void WpResult::set(int key, int value)
+{
+ switch (static_cast<Key>(key)) {
+ case Key::RiskLevel:
+ m_riskLevel = static_cast<csr_wp_risk_level_e>(value);
+ break;
+
+ case Key::UserResponse:
+ m_response = static_cast<csr_wp_user_response_e>(value);
+ break;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as int. value=" << value));
+ }
+}
+
+void WpResult::set(int key, const std::string &value)
+{
+ switch (static_cast<Key>(key)) {
+ case Key::DetailedUrl:
+ m_detailedUrl = value;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as std::string. value=" << value));
+ }
+}
+
+void WpResult::set(int key, const char *value)
+{
+ switch (static_cast<Key>(key)) {
+ case Key::DetailedUrl:
+ m_detailedUrl = value;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as char*. value=" << value));
+ }
+}
+
+void WpResult::get(int key, int &value) const
+{
+ switch (static_cast<Key>(key)) {
+ case Key::RiskLevel:
+ value = static_cast<int>(m_riskLevel);
+ break;
+
+ case Key::UserResponse:
+ value = static_cast<int>(m_response);
+ break;
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as int. value=" << value));
+ }
+}
+
+void WpResult::get(int key, const char **value) const
+{
+ if (value == nullptr)
+ throw std::logic_error("invalud argument. output storage pointer is null.");
+
+ switch (static_cast<Key>(key)) {
+ case Key::DetailedUrl:
+ *value = m_detailedUrl.c_str();
+
+ default:
+ throw std::logic_error(FORMAT("Invalid key[" << key
+ << "] comes in to set as char**. value=" << value));
+ }
+}
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 wp-result.h
+ * @author Dongsun Lee (ds73.lee@samsung.com)
+ * @version 1.0
+ * @brief Web protection result
+ */
+#pragma once
+
+#include <string>
+
+#include "common/types.h"
+#include "csr/web-protection-types.h"
+
+namespace Csr {
+
+class WpResult : public Result {
+public:
+ // key for set/get
+ enum class Key : int {
+ DetailedUrl = 0x01, // string
+
+ RiskLevel = 0x10, // int
+ UserResponse = 0x11 // int
+ };
+
+ WpResult();
+ virtual ~WpResult();
+
+ WpResult(IStream &);
+ virtual void Serialize(IStream &) const override;
+
+ WpResult(WpResult &&);
+ WpResult &operator=(WpResult &&);
+
+ virtual void set(int, int) override;
+ virtual void set(int, const std::string &) override;
+ virtual void set(int, const char *) override;
+
+ virtual void get(int, int &) const override;
+ virtual void get(int, const char **) const override;
+
+private:
+ csr_wp_risk_level_e m_riskLevel;
+ std::string m_detailedUrl;
+ csr_wp_user_response_e m_response;
+};
+
+}