SET(TARGET_CSR_SERVER ${SERVICE_NAME}-server)
SET(TARGET_CSR_CLIENT ${SERVICE_NAME}-client)
SET(TARGET_CSR_COMMON ${SERVICE_NAME}-common)
-SET(TARGET_CSR_TEST ${SERVICE_NAME}-test)
+SET(TARGET_CSR_POPUP ${SERVICE_NAME}-popup)
SET(TARGET_CSR_CS_ENGINE_SAMPLE ${SERVICE_NAME}-cs-engine)
SET(TARGET_CSR_WP_ENGINE_SAMPLE ${SERVICE_NAME}-wp-engine)
-SET(TARGET_CSR_ENGINE_TEST ${SERVICE_NAME}-engine-test)
+SET(TARGET_CSR_TEST ${SERVICE_NAME}-test)
+SET(TARGET_CSR_POPUP_TEST ${SERVICE_NAME}-popup-test)
CONFIGURE_FILE(packaging/${SERVICE_NAME}.manifest.in ${SERVICE_NAME}.manifest @ONLY)
CONFIGURE_FILE(packaging/${SERVICE_NAME}-client.manifest.in ${SERVICE_NAME}-client.manifest @ONLY)
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(libsystemd-daemon)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(elementary)
Requires: lib%{name}-common = %{version}-%{release}
%{?systemd_requires}
-DINCLUDE_INSTALL_DIR:PATH=%{_includedir} \
-DBIN_DIR:PATH=%{bin_dir} \
-DSYSTEMD_UNIT_DIR=%{_unitdir} \
+ -DSYSTEMD_UNIT_USER_DIR=%{_unitdir_user} \
-DSAMPLE_ENGINE_WORKING_DIR:PATH=%{sample_engine_working_dir} \
-DSAMPLE_ENGINE_DIR:PATH=%{sample_engine_dir} \
-DTEST_DIR:PATH=%{test_dir}
ln -s ../%{service_name}.service %{buildroot}%{_unitdir}/multi-user.target.wants/%{service_name}.service
ln -s ../%{service_name}.socket %{buildroot}%{_unitdir}/sockets.target.wants/%{service_name}.socket
+mkdir -p %{buildroot}%{_unitdir}/default.target.wants
+mkdir -p %{buildroot}%{_unitdir}/sockets.target.wants
+ln -s ../%{service_name}-popup.service %{buildroot}%{_unitdir}/default.target.wants/%{service_name}-popup.service
+ln -s ../%{service_name}-popup.socket %{buildroot}%{_unitdir}/sockets.target.wants/%{service_name}-popup.socket
+
mkdir -p %{buildroot}%{ro_data_dir}/license
cp LICENSE %{buildroot}%{ro_data_dir}/license/%{name}
cp LICENSE.BSL-1.0 %{buildroot}%{ro_data_dir}/license/%{name}.BSL-1.0
if [ $1 = 1 ]; then
systemctl start %{service_name}.socket
systemctl start %{service_name}.service
+ systemctl start %{service_name}-popup.socket
fi
if [ $1 = 2 ]; then
systemctl restart %{service_name}.socket
systemctl restart %{service_name}.service
+ systemctl restart %{service_name}-popup.socket
fi
%preun
if [ $1 = 0 ]; then
systemctl stop %{service_name}.service
systemctl stop %{service_name}.socket
+ systemctl stop %{service_name}-popup.socket
fi
%postun
%{ro_data_dir}/license/%{name}
%{ro_data_dir}/license/%{name}.BSL-1.0
%{bin_dir}/%{service_name}-server
+%{bin_dir}/%{service_name}-popup
%{_unitdir}/multi-user.target.wants/%{service_name}.service
%{_unitdir}/%{service_name}.service
%{_unitdir}/sockets.target.wants/%{service_name}.socket
%{_unitdir}/%{service_name}.socket
+%{_unitdir}/default.target.wants/%{service_name}-popup.service
+%{_unitdir}/%{service_name}-popup.service
+%{_unitdir}/sockets.target.wants/%{service_name}-popup.socket
+%{_unitdir}/%{service_name}-popup.socket
# sample engine related files
%{sample_engine_dir}/lib%{service_name}-cs-engine.so
%{ro_data_dir}/license/%{name}-test
%{ro_data_dir}/license/%{name}-test.BSL-1.0
%{bin_dir}/%{service_name}-test
+%{bin_dir}/%{service_name}-popup-test
# test resources
%{test_dir}
<smack request="sys-assert::core" type="rwxat" />
<smack request="systemd" type="rx" />
<smack request="csr" type="rwxat" />
+ <smack request="sdbd" type="rx" />
</request>
<permit>
+ <smack permit="_" type="rx" />
</permit>
</define>
<request>
<smack request="device::app_logging" type="rw" />
<smack request="sys-assert::core" type="rwxat" />
<smack request="systemd" type="rx" />
+ <smack request="xorg" type="rwxat" />
+ <smack request="system::homedir" type="rx" />
+ <smack request="tizen::vconf::setting" type="rl" />
+ <smack request="tizen::vconf::setting::admin" type="rl" />
+ <smack request="tizen::vconf::public::r::platform::rw" type="rl" />
+ <smack request="tizen::vconf::camcorder" type="rl" />
+ <smack request="isf" type="rx" />
+ <smack request="dbus" type="w" />
+ <smack request="pulseaudio" type="w" />
+ <smack request="sdbd" type="rx" />
</request>
<permit>
+ <smack permit="_" type="rx" />
+ <smack permit="xorg" type="rx" />
</permit>
</define>
<request>
############### SERVER ###################
PKG_CHECK_MODULES(${TARGET_CSR_SERVER}_DEP
REQUIRED
+ libsystemd-daemon
)
SET(${TARGET_CSR_SERVER}_SRCS
framework/main/csr-main.cpp
- framework/main/mainloop.cpp
framework/service/logic.cpp
- framework/service/service.cpp
+ framework/service/server-service.cpp
+ framework/ui/askuser.cpp
+
+ # question and response codes needed on both of
+ # csr-server and popup-backend service
+ framework/ui/common.cpp
)
INCLUDE_DIRECTORIES(
- framework/common
- framework/main
- framework/service
+ framework
+ ${PROJECT_SOURCE_DIR}/src/include
${${TARGET_CSR_SERVER}_DEP_INCLUDED_DIRS}
)
)
INCLUDE_DIRECTORIES(
- framework/common
- framework/client
+ framework
${PROJECT_SOURCE_DIR}/src/include
${${TARGET_CSR_CLIENT}_DEP_INCLUDE_DIRS}
)
common/connection.cpp
common/message-buffer.cpp
common/socket.cpp
+ common/service.cpp
+ common/mainloop.cpp
common/audit/console-sink.cpp
common/audit/dlog-sink.cpp
common/audit/logger.cpp
)
INSTALL(TARGETS ${TARGET_CSR_COMMON} DESTINATION ${LIB_INSTALL_DIR})
+
+ADD_SUBDIRECTORY(ui)
* @version 1.0
* @brief client common for both of cs / wp
*/
-#include "client-common.h"
+#include "client/client-common.h"
#include <exception>
-#include "audit/logger.h"
-#include "raw-buffer.h"
-#include "connection.h"
-#include "socket.h"
+#include "common/audit/logger.h"
+#include "common/raw-buffer.h"
+#include "common/connection.h"
+#include "common/socket.h"
static void init_lib(void) __attribute__((constructor));
static void init_lib(void)
#include <string>
#include "csr/error.h"
-#include "message-buffer.h"
+#include "common/message-buffer.h"
namespace Csr {
#include <functional>
-#include "message-buffer.h"
-#include "command-id.h"
-#include "audit/logger.h"
-#include "client-common.h"
+#include "common/message-buffer.h"
+#include "common/command-id.h"
+#include "common/audit/logger.h"
+#include "client/client-common.h"
#define API __attribute__((visibility("default")))
*/
#include "csr/engine-manager.h"
-#include "audit/logger.h"
+#include "common/audit/logger.h"
#define API __attribute__((visibility("default")))
*/
#include "csr/error.h"
-#include "audit/logger.h"
+#include "common/audit/logger.h"
#define API __attribute__((visibility("default")))
#include <functional>
-#include "message-buffer.h"
-#include "command-id.h"
-#include "audit/logger.h"
-#include "client-common.h"
+#include "common/message-buffer.h"
+#include "common/command-id.h"
+#include "common/audit/logger.h"
+#include "client/client-common.h"
#define API __attribute__((visibility("default")))
#define ERROR(MESSAGE) LOG(Error, MESSAGE)
#define WARN(MESSAGE) LOG(Warning, MESSAGE)
+#define INFO(MESSAGE) LOG(Info, MESSAGE)
#if !defined(NDEBUG)
-#define INFO(MESSAGE) LOG(Info, MESSAGE)
#define DEBUG(MESSAGE) LOG(Debug, MESSAGE)
#define TRACE(MESSAGE) LOG(Trace, MESSAGE)
#else
-#define INFO(MESSAGE) do {} while (false)
#define DEBUG(MESSAGE) do {} while (false)
#define TRACE(MESSAGE) do {} while (false)
#endif //NDEBUG
* @version 1.0
* @brief
*/
-#include "binary-queue.h"
+#include "common/binary-queue.h"
#include <cstring>
#include <cstddef>
* @version 1.0
* @brief
*/
-#include "connection.h"
+#include "common/connection.h"
#include <utility>
#include <functional>
#include <memory>
-#include "socket.h"
-#include "raw-buffer.h"
+#include "common/socket.h"
+#include "common/raw-buffer.h"
namespace Csr {
* @version 1.0
* @brief Mainloop of csr-server with epoll
*/
-#include "mainloop.h"
+#include "common/mainloop.h"
#include <exception>
#include <stdexcept>
#include <sys/epoll.h>
#include <unistd.h>
-#include "audit/logger.h"
+#include "common/audit/logger.h"
namespace Csr {
Mainloop::Mainloop() :
+ m_isTimedOut(false),
m_pollfd(::epoll_create1(EPOLL_CLOEXEC))
{
if (m_pollfd == -1)
Mainloop::~Mainloop()
{
- if (!m_callbacks.empty())
- throw std::logic_error("m_callbacks shouldn't be empty");
+ if (!m_isTimedOut && !m_callbacks.empty())
+ throw std::logic_error("mainloop registered callbacks should be empty "
+ "except timed out case");
::close(m_pollfd);
}
-void Mainloop::run()
+void Mainloop::run(int timeout)
{
- while (true) {
- dispatch(-1);
+ m_isTimedOut = false;
+
+ while (!m_isTimedOut) {
+ dispatch(timeout);
}
+
+ DEBUG("Mainloop run stopped");
}
void Mainloop::addEventSource(int fd, uint32_t event, Callback &&callback)
std::error_code(errno, std::generic_category()),
"epoll_wait failed!");
+ if (nfds == 0) {
+ DEBUG("Mainloop timed out!");
+ m_isTimedOut = true;
+ return;
+ }
+
for (int i = 0; i < nfds; i++) {
/* TODO: use scoped-lock to thread safe on member variables */
int fd = event[i].data.fd;
Mainloop(Mainloop &&) = delete;
Mainloop &operator=(Mainloop &&) = delete;
- void run(void);
+ void run(int timeout);
void addEventSource(int fd, uint32_t event, Callback &&callback);
void removeEventSource(int fd);
private:
void dispatch(int timeout);
+ bool m_isTimedOut;
int m_pollfd;
std::mutex m_mutex;
std::unordered_map<int, Callback> m_callbacks;
* @version 1.0
* @brief Implementation of MessageBuffer.
*/
-#include "message-buffer.h"
+#include "common/message-buffer.h"
#include <exception>
#include <cstring>
*/
#pragma once
-#include "raw-buffer.h"
-#include "binary-queue.h"
-#include "serialization.h"
+#include "common/raw-buffer.h"
+#include "common/binary-queue.h"
+#include "common/serialization.h"
namespace Csr {
#include <vector>
#include <list>
#include <map>
+#include <unordered_map>
#include <memory>
-#include "command-id.h"
+#include "common/command-id.h"
#include "csr/error.h"
namespace Csr {
// Abstract data stream buffer
class IStream {
- public:
+public:
virtual void read(size_t num, void * bytes) = 0;
virtual void write(size_t num, const void * bytes) = 0;
virtual ~IStream(){}
// Serializable interface
class ISerializable {
- public:
- /* ISerializable(){};
- * ISerializable(IStream&){}; */
+public:
+ ISerializable() {}
+ ISerializable(IStream&) {}
virtual void Serialize(IStream &) const = 0;
- virtual ~ISerializable(){}
+ virtual ~ISerializable() {}
};
struct Serialization {
template <typename T>
static void Serialize(IStream& stream, const std::list<T>& list)
{
- int length = list.size();
+ size_t length = list.size();
stream.write(sizeof(length), &length);
- for (typename std::list<T>::const_iterator list_iter = list.begin();
- list_iter != list.end(); list_iter++)
- Serialize(stream, *list_iter);
+ for (const auto &item : list)
+ Serialize(stream, item);
}
template <typename T>
static void Serialize(IStream& stream, const std::list<T>* const list)
template <typename K, typename T>
static void Serialize(IStream& stream, const std::map<K, T>& map)
{
- int length = map.size();
+ size_t length = map.size();
stream.write(sizeof(length), &length);
- typename std::map<K, T>::const_iterator it;
- for (it = map.begin(); it != map.end(); ++it) {
- Serialize(stream, (*it).first);
- Serialize(stream, (*it).second);
+ for (const auto &item : map) {
+ Serialize(stream, item.first);
+ Serialize(stream, item.second);
}
}
template <typename K, typename T>
Serialize(stream, *map);
}
+ // std::unordered_map
+ template <typename K, typename T>
+ static void Serialize(IStream& stream, const std::unordered_map<K, T>& map)
+ {
+ size_t length = map.size();
+ stream.write(sizeof(length), &length);
+ for (const auto &item : map) {
+ Serialize(stream, item.first);
+ Serialize(stream, item.second);
+ }
+ }
+ template <typename K, typename T>
+ static void Serialize(IStream& stream, const std::unordered_map<K, T>* const map)
+ {
+ Serialize(stream, *map);
+ }
+
// std::unique_ptr
template <typename T>
static void Serialize(IStream& stream, const std::unique_ptr<T>& p)
map = new std::map<K, T>;
Deserialize(stream, *map);
}
+
+ // std::unordered_map
+ template <typename K, typename T>
+ static void Deserialize(IStream& stream, std::unordered_map<K, T>& map)
+ {
+ size_t length;
+ stream.read(sizeof(length), &length);
+ for (size_t i = 0; i < length; ++i) {
+ K key;
+ T obj;
+ Deserialize(stream, key);
+ Deserialize(stream, obj);
+ map[key] = std::move(obj);
+ }
+ }
+ template <typename K, typename T>
+ static void Deserialize(IStream& stream, std::unordered_map<K, T>*& map)
+ {
+ map = new std::map<K, T>;
+ Deserialize(stream, *map);
+ }
+
}; // struct Deserialization
// generic serialization
* @version 1.0
* @brief
*/
-#include "service.h"
+#include "common/service.h"
#include <sys/types.h>
#include <sys/epoll.h>
-#include "audit/logger.h"
+#include "common/audit/logger.h"
namespace Csr {
-Service::Service(const std::string &address) :
- m_loop(),
- m_address(address)
+Service::Service(const std::string &address) : m_address(address)
{
DEBUG("Service constructed with address[" << address << "]");
{
}
-void Service::start()
+void Service::start(int timeout)
{
INFO("Service start!");
Socket socket(m_address);
- DEBUG("Get server socket[" << socket.getFd()
+ DEBUG("Get systemd socket[" << socket.getFd()
<< "] with address[" << m_address << "]");
m_loop.addEventSource(socket.getFd(), EPOLLIN | EPOLLHUP | EPOLLRDHUP,
m_onNewConnection(std::make_shared<Connection>(socket.accept()));
});
- m_loop.run();
+ m_loop.run(timeout);
}
void Service::stop()
/* TODO: scoped-lock */
m_onNewConnection = [&](const ConnShPtr &connection) {
if (!connection)
- throw std::logic_error("onNewCOnnection called but ConnShPtr is nullptr.");
+ throw std::logic_error("onNewConnection called but ConnShPtr is nullptr.");
int fd = connection->getFd();
};
}
-void Service::onMessageProcess(const ConnShPtr &connection)
-{
- DEBUG("let's dispatch it to worker threads.");
-
- auto process = [&]() {
- auto reply = m_logic.dispatch(connection->receive());
-
- connection->send(reply);
- };
-
- /* TODO: submit to workqueue */
- process();
-}
-
}
#pragma once
#include <string>
-#include <memory>
#include <functional>
-#include "connection.h"
-#include "mainloop.h"
-#include "logic.h"
+#include "common/connection.h"
+#include "common/mainloop.h"
namespace Csr {
Service(const std::string &address);
virtual ~Service();
- void start(void);
- void stop(void);
+ Service(const Service &) = delete;
+ Service &operator=(const Service &) = delete;
+ Service(Service &&) = delete;
+ Service &operator=(Service &&) = delete;
+
+ virtual void start(int timeout) final;
+ virtual void stop(void) final;
/* ConnCallback param should throw exception to handle error */
- void setNewConnectionCallback(const ConnCallback &);
- void setCloseConnectionCallback(const ConnCallback &);
+ virtual void setNewConnectionCallback(const ConnCallback &) final;
+ virtual void setCloseConnectionCallback(const ConnCallback &) final;
private:
- void onMessageProcess(const ConnShPtr &);
+ virtual void onMessageProcess(const ConnShPtr &) = 0;
ConnCallback m_onNewConnection;
ConnCallback m_onCloseConnection;
std::unordered_map<int, ConnShPtr> m_connectionRegistry;
Mainloop m_loop;
std::string m_address;
-
- Logic m_logic;
};
}
* @version 1.0
* @brief
*/
-#include "socket.h"
+#include "common/socket.h"
#include <exception>
#include <system_error>
#include <systemd/sd-daemon.h>
-#include "audit/logger.h"
+#include "common/audit/logger.h"
namespace {
#include <string>
-#include "raw-buffer.h"
+#include "common/raw-buffer.h"
namespace Csr {
* @version 1.0
* @brief Main of csr daemon
*/
-#include "service.h"
+#include "service/server-service.h"
-#include "audit/logger.h"
+#include "common/audit/logger.h"
int main(void)
{
try {
INFO("Start csr-server main!");
- Csr::Service service("/tmp/." SERVICE_NAME ".socket");
+ Csr::ServerService service("/tmp/." SERVICE_NAME ".socket");
INFO("Let's start csr-server service!");
- service.start();
+ /* no timeout */
+ service.start(-1);
return 0;
} catch (const std::exception &e) {
* @version 1.0
* @brief
*/
-#include "logic.h"
+#include "service/logic.h"
#include <string>
#include <utility>
#include <stdexcept>
-#include "audit/logger.h"
+#include "common/audit/logger.h"
#include "csr/error.h"
namespace Csr {
RawBuffer Logic::scanFile(const std::string &filepath)
{
- (void) filepath;
+ INFO("Scan file[" << filepath << "] by engine");
- DEBUG("Scan file[" << filepath << "] by engine");
return MessageBuffer::Serialize(CSR_ERROR_NONE).pop();
}
RawBuffer Logic::checkUrl(const std::string &url)
{
- (void) url;
+ INFO("Check url[" << url << "] by engine");
- DEBUG("CHeck url[" << url << "] by engine");
return MessageBuffer::Serialize(CSR_ERROR_NONE).pop();
}
#include <string>
#include <utility>
-#include "command-id.h"
-#include "raw-buffer.h"
-#include "message-buffer.h"
+#include "common/command-id.h"
+#include "common/raw-buffer.h"
+#include "common/message-buffer.h"
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 server-service.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#include "service/server-service.h"
+
+#include "common/audit/logger.h"
+
+namespace Csr {
+
+ServerService::ServerService(const std::string &address) : Service(address)
+{
+}
+
+ServerService::~ServerService()
+{
+}
+
+void ServerService::onMessageProcess(const ConnShPtr &connection)
+{
+ DEBUG("let's dispatch it to worker threads.");
+
+ auto process = [&]() {
+ auto reply = m_logic.dispatch(connection->receive());
+
+ connection->send(reply);
+ };
+
+ /* TODO: submit to workqueue */
+ process();
+}
+
+}
--- /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 server-service.h
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#pragma once
+
+#include "common/service.h"
+#include "service/logic.h"
+
+namespace Csr {
+
+class ServerService : public Service {
+public:
+ ServerService(const std::string &address);
+ virtual ~ServerService();
+
+private:
+ virtual void onMessageProcess(const ConnShPtr &) override;
+
+ Logic m_logic;
+};
+
+}
--- /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 CMakeLists.txt
+# @author Kyungwook Tak (k.tak@samsung.com)
+# @brief
+#
+ADD_SUBDIRECTORY(popup)
--- /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 askuser.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief Ask user and get response to handle screening result
+ */
+#include "ui/askuser.h"
+
+#include "common/raw-buffer.h"
+#include "common/message-buffer.h"
+#include "common/connection.h"
+#include "common/socket.h"
+#include "common/audit/logger.h"
+
+namespace Csr {
+namespace Ui {
+
+namespace {
+
+inline Csr::Connection makeConnection(const std::string &address)
+{
+ DEBUG("Try to make connection to csr-popup service");
+
+ return Csr::Connection(Csr::Socket::connect(address));
+}
+
+inline Csr::Connection makeConnection(void)
+{
+ return makeConnection("/tmp/." SERVICE_NAME "-popup.socket");
+}
+
+inline Csr::RawBuffer dispatch(const Csr::Connection &connection, const Csr::RawBuffer &buf)
+{
+ DEBUG("Try to dispatch to csr-popup service");
+
+ connection.send(buf);
+
+ DEBUG("Wait for response from csr-popup service");
+
+ return connection.receive();
+}
+
+Response ask(const RawBuffer &buf)
+{
+ auto conn = makeConnection();
+
+ auto reply = dispatch(conn, buf);
+
+ Csr::MessageBuffer msg;
+ msg.push(reply);
+
+ int int_response;
+ msg.Deserialize(int_response);
+ return static_cast<Response>(int_response);
+}
+
+ResponseMap askMultiple(const RawBuffer &buf)
+{
+ auto conn = makeConnection();
+
+ auto reply = dispatch(conn, buf);
+
+ Csr::MessageBuffer msg;
+ msg.push(reply);
+
+ ResponseMap responseMap;
+ msg.Deserialize(responseMap);
+
+ return responseMap;
+}
+
+} // namespace Csr::Ui::anonymous
+
+AskUser::AskUser()
+{
+}
+
+AskUser::~AskUser()
+{
+}
+
+
+Response AskUser::fileSingle(const std::string &message, const FileItem &item) const
+{
+ auto inbuf = Csr::MessageBuffer::Serialize(
+ static_cast<int>(CommandId::FILE_SINGLE),
+ message,
+ item).pop();
+
+ return ask(inbuf);
+}
+
+ResponseMap AskUser::fileMultiple(const std::string &message, const FileItems &items) const
+{
+ auto inbuf = Csr::MessageBuffer::Serialize(
+ static_cast<int>(CommandId::FILE_MULTIPLE),
+ message,
+ items).pop();
+
+ return askMultiple(inbuf);
+}
+
+Response AskUser::urlSingle(const std::string &message, const UrlItem &item) const
+{
+ auto inbuf = Csr::MessageBuffer::Serialize(
+ static_cast<int>(CommandId::URL_SINGLE),
+ message,
+ item).pop();
+
+ return ask(inbuf);
+}
+
+ResponseMap AskUser::urlMultiple(const std::string &message, const UrlItems &items) const
+{
+ auto inbuf = Csr::MessageBuffer::Serialize(
+ static_cast<int>(CommandId::URL_MULTIPLE),
+ message,
+ items).pop();
+
+ return askMultiple(inbuf);
+}
+
+} // namespace Ui
+} // 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 askuser.h
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief Ask user and get response to handle screening result
+ */
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "ui/common.h"
+#include "csr/content-screening-types.h"
+#include "csr/web-protection-types.h"
+
+namespace Csr {
+namespace Ui {
+
+class AskUser {
+public:
+ AskUser();
+ virtual ~AskUser();
+
+ AskUser(const AskUser &) = delete;
+ AskUser &operator=(const AskUser &) = delete;
+
+ Response fileSingle(const std::string &message, const FileItem &item) const;
+ ResponseMap fileMultiple(const std::string &message, const FileItems &items) const;
+ Response urlSingle(const std::string &message, const UrlItem &item) const;
+ ResponseMap urlMultiple(const std::string &message, const UrlItems &items) const;
+};
+
+}
+}
--- /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 common.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief Common data structs for popup-service and csr-server
+ */
+#include "ui/common.h"
+
+namespace Csr {
+namespace Ui {
+
+FileItem::FileItem(IStream &stream)
+{
+ int int_severity;
+ Deserializer<int>::Deserialize(stream, int_severity);
+ severity = static_cast<csr_cs_severity_level_e>(int_severity);
+
+ int int_threat;
+ Deserializer<int>::Deserialize(stream, int_threat);
+ threat = static_cast<csr_cs_threat_type_e>(int_threat);
+
+ Deserializer<std::string>::Deserialize(stream, filepath);
+}
+
+void FileItem::Serialize(IStream &stream) const
+{
+ Serializer<int>::Serialize(stream, static_cast<int>(severity));
+ Serializer<int>::Serialize(stream, static_cast<int>(threat));
+ Serializer<std::string>::Serialize(stream, filepath);
+}
+
+UrlItem::UrlItem(IStream &stream)
+{
+ int int_risk;
+ Deserializer<int>::Deserialize(stream, int_risk);
+ risk = static_cast<csr_wp_risk_level_e>(int_risk);
+
+ Deserializer<std::string>::Deserialize(stream, url);
+}
+
+void UrlItem::Serialize(IStream &stream) const
+{
+ Serializer<int>::Serialize(stream, static_cast<int>(risk));
+ Serializer<std::string>::Serialize(stream, url);
+}
+
+}
+}
--- /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 common.h
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief Common data structs for popup-service and csr-server
+ */
+#pragma once
+
+#include <string>
+#include <vector>
+#include <unordered_map>
+
+#include "common/serialization.h"
+
+#include "csr/content-screening-types.h"
+#include "csr/web-protection-types.h"
+
+namespace Csr {
+namespace Ui {
+
+enum class CommandId : int {
+ FILE_SINGLE = 0x01,
+ FILE_MULTIPLE = 0x02,
+ URL_SINGLE = 0x03,
+ URL_MULTIPLE = 0x04
+};
+
+enum class Response : int {
+ /* For url access on web protection */
+ ALLOW = 0x01,
+ DENY = 0x02,
+ CONFIRM = 0x03,
+
+ /* For content screening detected item handling */
+ REMOVE = 0x04,
+ IGNORE = 0x05,
+ SKIP = 0x06
+};
+
+struct FileItem : public ISerializable {
+ FileItem() {}
+ virtual ~FileItem() {}
+ FileItem(IStream &);
+ virtual void Serialize(IStream &) const override;
+
+ csr_cs_severity_level_e severity;
+ csr_cs_threat_type_e threat;
+ std::string filepath;
+};
+
+struct UrlItem : public ISerializable {
+ UrlItem() {}
+ virtual ~UrlItem() {}
+ UrlItem(IStream &);
+ virtual void Serialize(IStream &) const override;
+
+ csr_wp_risk_level_e risk;
+ std::string url;
+};
+
+using FileItems = std::vector<FileItem>;
+using UrlItems = std::vector<UrlItem>;
+using ResponseMap = std::unordered_map<std::string, int>;
+
+}
+}
--- /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 CMakeLists.txt
+# @author Janusz Kozerski (j.kozerski@samsung.com)
+# @version 1.0
+#
+PKG_CHECK_MODULES(${TARGET_CSR_POPUP}_DEP
+ REQUIRED
+ elementary
+ libsystemd-daemon
+ vconf
+)
+
+INCLUDE_DIRECTORIES(
+ ${${TARGET_CSR_POPUP}_DEP_INCLUDE_DIRS}
+ .
+ ${PROJECT_SOURCE_DIR}/src/framework
+)
+
+SET(${TARGET_CSR_POPUP}_SRCS
+ main.cpp
+ logic.cpp
+ popup.cpp
+ popup-service.cpp
+ ${PROJECT_SOURCE_DIR}/src/framework/ui/common.cpp
+)
+
+SET_SOURCE_FILES_PROPERTIES(${${TARGET_CSR_POPUP}_SRCS}
+ PROPERTIES
+ COMPILE_FLAGS "-D_GNU_SOURCE -fPIE"
+ LINK_FLAGS "-pie"
+)
+
+ADD_EXECUTABLE(${TARGET_CSR_POPUP} ${${TARGET_CSR_POPUP}_SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_CSR_POPUP}
+ ${${TARGET_CSR_POPUP}_DEP_LIBRARIES}
+ ${TARGET_CSR_COMMON}
+)
+
+INSTALL(TARGETS ${TARGET_CSR_POPUP} DESTINATION ${BIN_DIR})
--- /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 logic.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief Logic for popup service
+ */
+#include "logic.h"
+
+#include <stdexcept>
+#include <functional>
+#include <unordered_map>
+#include <Elementary.h>
+
+#include "common/message-buffer.h"
+#include "common/raw-buffer.h"
+#include "common/audit/logger.h"
+#include "ui/common.h"
+
+namespace Csr {
+namespace Ui {
+
+namespace {
+
+std::unordered_map<int, std::function<void()>> g_callbackRegistry;
+
+void evasCbWrapper(void *data, Evas_Object *, void *)
+{
+ auto response = reinterpret_cast<int *>(data);
+ g_callbackRegistry[*response]();
+}
+
+void registerCb(Evas_Object *button, int *response, std::function<void()> &&func)
+{
+ evas_object_smart_callback_add(button, "clicked", evasCbWrapper, response);
+ g_callbackRegistry[*response] = std::move(func);
+}
+
+void unregisterCb(int response)
+{
+ g_callbackRegistry.erase(response);
+}
+
+} // namespace anonymous
+
+Logic::Logic()
+{
+}
+
+Logic::~Logic()
+{
+}
+
+RawBuffer Logic::dispatch(const RawBuffer &in)
+{
+ auto info = getRequestInfo(in);
+ INFO("Request dispatch on popup-service. CommandId: " << static_cast<int>(info.first));
+
+ switch (info.first) {
+ case CommandId::FILE_SINGLE: {
+ std::string message;
+ FileItem item;
+ info.second.Deserialize(message, item);
+
+ return fileSingle(message, item);
+ }
+
+ case CommandId::FILE_MULTIPLE: {
+ std::string message;
+ FileItems items;
+ info.second.Deserialize(message, items);
+
+ return fileMultiple(message, items);
+ }
+
+ case CommandId::URL_SINGLE: {
+ std::string message;
+ UrlItem item;
+ info.second.Deserialize(message, item);
+
+ return urlSingle(message, item);
+ }
+
+ case CommandId::URL_MULTIPLE: {
+ std::string message;
+ UrlItems items;
+ info.second.Deserialize(message, items);
+
+ return urlMultiple(message, items);
+ }
+
+ default:
+ throw std::logic_error("Protocol error. unknown popup-service command id.");
+ }
+}
+
+std::pair<CommandId, MessageBuffer> Logic::getRequestInfo(const RawBuffer &data)
+{
+ int int_id;
+ MessageBuffer msg;
+ msg.push(data);
+ msg.Deserialize(int_id);
+
+ return std::make_pair(static_cast<CommandId>(int_id), std::move(msg));
+}
+
+RawBuffer Logic::fileSingle(const std::string &message, const FileItem &item) const
+{
+ INFO("fileSingle start with param.. "
+ "message[" << message << "] "
+ "filepath[" << item.filepath << "] "
+ "severity[" << static_cast<int>(item.severity) << "] "
+ "threat[" << static_cast<int>(item.threat) << "]");
+
+ Popup popup;
+
+ popup.fillText("FileSingle title", message.c_str());
+
+ MessageBuffer msg;
+
+ auto respRemove = static_cast<int>(Response::REMOVE);
+ Evas_Object *remove = popup.addButton("button1");
+ elm_object_text_set(remove, "remove");
+ registerCb(remove, &respRemove, [&msg, &respRemove, &popup]() {
+ DEBUG("Remove button clicked!");
+ msg = MessageBuffer::Serialize(respRemove);
+ popup.stop();
+ });
+
+ auto respIgnore = static_cast<int>(Response::IGNORE);
+ Evas_Object *ignore = popup.addButton("button2");
+ elm_object_text_set(ignore, "ignore");
+ registerCb(ignore, &respIgnore, [&msg, &respIgnore, &popup]() {
+ DEBUG("Ignore button clicked!");
+ msg = MessageBuffer::Serialize(respIgnore);
+ popup.stop();
+ });
+
+ auto respSkip = static_cast<int>(Response::SKIP);
+ Evas_Object *skip = popup.addButton("button3");
+ elm_object_text_set(skip, "skip");
+ registerCb(skip, &respSkip, [&msg, &respSkip, &popup]() {
+ DEBUG("Skip button clicked!");
+ msg = MessageBuffer::Serialize(respSkip);
+ popup.stop();
+ });
+
+ popup.start();
+
+ DEBUG("fileSingle done!");
+
+ unregisterCb(respRemove);
+ unregisterCb(respIgnore);
+ unregisterCb(respSkip);
+
+ return msg.pop();
+}
+
+RawBuffer Logic::fileMultiple(const std::string &message, const FileItems &items) const
+{
+ (void) message;
+ (void) items;
+ return RawBuffer();
+}
+
+RawBuffer Logic::urlSingle(const std::string &message, const UrlItem &item) const
+{
+ INFO("urlSingle start with param.. "
+ "message[" << message << "] "
+ "url[" << item.url << "] "
+ "risk level[" << static_cast<int>(item.risk) << "]");
+
+ Popup popup;
+
+ popup.fillText("FileSingle title", message.c_str());
+
+ MessageBuffer msg;
+
+ auto respAllow = static_cast<int>(Response::ALLOW);
+ Evas_Object *allow = popup.addButton("button1");
+ elm_object_text_set(allow, "allow");
+ registerCb(allow, &respAllow, [&msg, &respAllow, &popup]() {
+ DEBUG("Allow button clicked!");
+ msg = MessageBuffer::Serialize(respAllow);
+ popup.stop();
+ });
+
+ auto respDeny = static_cast<int>(Response::DENY);
+ Evas_Object *deny = popup.addButton("button2");
+ elm_object_text_set(deny, "deny");
+ registerCb(deny, &respDeny, [&msg, &respDeny, &popup]() {
+ DEBUG("Deny button clicked!");
+ msg = MessageBuffer::Serialize(respDeny);
+ popup.stop();
+ });
+
+ popup.start();
+
+ DEBUG("urlSingle done!");
+
+ unregisterCb(respAllow);
+ unregisterCb(respDeny);
+
+ return msg.pop();
+}
+
+RawBuffer Logic::urlMultiple(const std::string &message, const UrlItems &items) const
+{
+ (void) message;
+ (void) items;
+ return RawBuffer();
+}
+
+}
+}
--- /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 logic.h
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief Logic for popup service
+ */
+#pragma once
+
+#include <string>
+#include <functional>
+#include <utility>
+
+#include "common/raw-buffer.h"
+#include "common/message-buffer.h"
+#include "ui/common.h"
+#include "popup.h"
+
+namespace Csr {
+namespace Ui {
+
+class Logic {
+public:
+ Logic();
+ virtual ~Logic();
+
+ RawBuffer dispatch(const RawBuffer &);
+
+private:
+ std::pair<CommandId, MessageBuffer> getRequestInfo(const RawBuffer &);
+
+ RawBuffer fileSingle(const std::string &message, const FileItem &item) const;
+ RawBuffer fileMultiple(const std::string &message, const FileItems &items) const;
+ RawBuffer urlSingle(const std::string &message, const UrlItem &item) const;
+ RawBuffer urlMultiple(const std::string &message, const UrlItems &items) const;
+};
+
+}
+}
--- /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 main.cpp
+ * @author Janusz Kozerski (j.kozerski@samsung.com)
+ * Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief Popup service main
+ */
+#include <stdexcept>
+
+#include <vconf.h>
+#include <Elementary.h>
+#include <Ecore.h>
+
+#include "common/audit/logger.h"
+#include "popup-service.h"
+
+namespace {
+
+struct ElmRaii {
+ ElmRaii(int argc, char **argv)
+ {
+ DEBUG("elm_init()");
+ elm_init(argc, argv);
+ }
+
+ virtual ~ElmRaii()
+ {
+ DEBUG("elm_shutdown()");
+ /* TODO: do shutdown.
+ * shutdown generates segmentation fault by unknown reason.
+ */
+// elm_shutdown();
+ }
+};
+
+} // namespace anonymous
+
+int main(int argc, char **argv)
+{
+ try {
+ Csr::Audit::Logger::setTag("CSR_POPUP");
+
+ INFO("CSR popup service start!");
+
+ /* init/shutdown elm automatically */
+ ElmRaii elmRaii(argc, argv);
+
+ setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
+
+ Csr::Ui::PopupService service("/tmp/." SERVICE_NAME "-popup.socket");
+
+ service.start(0);
+
+ return 0;
+ } catch (const std::exception &e) {
+ ERROR("std exception: " << e.what());
+ return -1;
+ } catch (...) {
+ ERROR("Unhandled exception occured!");
+ return -1;
+ }
+}
--- /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 popup-service.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#include "popup-service.h"
+
+#include "common/audit/logger.h"
+
+namespace Csr {
+namespace Ui {
+
+PopupService::PopupService(const std::string &address) : Service(address)
+{
+}
+
+PopupService::~PopupService()
+{
+}
+
+void PopupService::onMessageProcess(const ConnShPtr &connection)
+{
+ DEBUG("process message on popup service");
+
+ auto reply = m_logic.dispatch(connection->receive());
+
+ connection->send(reply);
+
+ DEBUG("process done on popup service");
+}
+
+} // namespace Ui
+} // 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 popup-service.h
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#pragma once
+
+#include <string>
+
+#include "common/service.h"
+#include "logic.h"
+
+namespace Csr {
+namespace Ui {
+
+class PopupService : public Service {
+public:
+ PopupService(const std::string &address);
+ virtual ~PopupService();
+
+private:
+ virtual void onMessageProcess(const ConnShPtr &) override;
+ Logic m_logic;
+};
+
+} // namespace Ui
+} // 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 popup.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#include "popup.h"
+
+#include <stdexcept>
+
+#include "common/audit/logger.h"
+
+namespace Csr {
+namespace Ui {
+
+Popup::Popup()
+{
+ Evas_Object *win = elm_win_add(nullptr, "CSR popup", ELM_WIN_NOTIFICATION);
+ elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_TRANSLUCENT);
+ elm_win_borderless_set(win, EINA_TRUE);
+ elm_win_alpha_set(win, EINA_TRUE);
+
+ Evas_Object *popup = elm_popup_add(win);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ m_win = win;
+ m_popup = popup;
+}
+
+Popup::~Popup()
+{
+}
+
+void Popup::stop()
+{
+ if (m_popup)
+ evas_object_del(m_popup);
+ if (m_win)
+ evas_object_del(m_win);
+ elm_exit();
+}
+
+void Popup::start()
+{
+ evas_object_show(m_win);
+ evas_object_show(m_popup);
+
+ DEBUG("Popup UI event loop start!");
+
+ elm_run();
+}
+
+void Popup::fillText(const char *title, const char *content)
+{
+ elm_object_part_text_set(m_popup, "title,text", title);
+ elm_object_text_set(m_popup, content);
+}
+
+Evas_Object *Popup::addButton(const char *part)
+{
+ Evas_Object *button = elm_button_add(m_popup);
+ elm_object_style_set(button, "bottom");
+ elm_object_part_content_set(m_popup, part, button);
+ evas_object_show(button);
+
+ return button;
+}
+
+}
+}
--- /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 popup.h
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#pragma once
+
+#include <Elementary.h>
+
+namespace Csr {
+namespace Ui {
+
+class Popup {
+public:
+ Popup();
+ virtual ~Popup();
+
+ /* fill text on popup */
+ void fillText(const char *title, const char *content);
+
+ /* add button to popup on given part of */
+ Evas_Object *addButton(const char *part);
+
+ void start(void);
+ void stop(void);
+
+private:
+ Evas_Object *m_win;
+ Evas_Object *m_popup;
+};
+
+}
+}
CONFIGURE_FILE(${SERVICE_NAME}.service.in ${SERVICE_NAME}.service @ONLY)
CONFIGURE_FILE(${SERVICE_NAME}.socket.in ${SERVICE_NAME}.socket @ONLY)
+CONFIGURE_FILE(${SERVICE_NAME}-popup.service.in ${SERVICE_NAME}-popup.service @ONLY)
+CONFIGURE_FILE(${SERVICE_NAME}-popup.socket.in ${SERVICE_NAME}-popup.socket @ONLY)
INSTALL(
FILES
${SERVICE_NAME}.service
${SERVICE_NAME}.socket
+ ${SERVICE_NAME}-popup.service
+ ${SERVICE_NAME}-popup.socket
DESTINATION ${SYSTEMD_UNIT_DIR}
)
-
--- /dev/null
+[Unit]
+Description=CSR popup service for user session
+
+[Service]
+User=app
+Group=app
+Type=simple
+SmackProcessLabel=@SERVICE_NAME@
+EnvironmentFile=/run/tizen-mobile-env
+ExecStart=@BIN_DIR@/@SERVICE_NAME@-popup
+Sockets=@SERVICE_NAME@-popup.socket
+
+[Install]
+WantedBy=default.target
--- /dev/null
+[Unit]
+Description= Csr popup socket
+Wants=@SERVICE_NAME@-popup.service
+Before=@SERVICE_NAME@-popup.service
+
+[Socket]
+ListenStream=/tmp/.@SERVICE_NAME@-popup.socket
+Service=@SERVICE_NAME@-popup.service
+SocketMode=0777
+SmackLabelIPIn=@SERVICE_NAME@
+SmackLabelIPOut=@SERVICE_NAME@
+
+[Install]
+WantedBy=sockets.target
INSTALL(TARGETS ${TARGET_CSR_TEST} DESTINATION ${BIN_DIR})
INSTALL(DIRECTORY resources/ DESTINATION ${TEST_DIR})
+
+ADD_SUBDIRECTORY(popup)
--- /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 CMakeLists.txt
+# @author Kyungwook Tak (k.tak@samsung.com)
+# @brief build test program of csr-popup
+#
+PKG_CHECK_MODULES(${TARGET_CSR_POPUP_TEST}_DEP
+ REQUIRED
+)
+
+SET(${TARGET_CSR_POPUP_TEST}_SRCS
+ ${PROJECT_SOURCE_DIR}/src/framework/ui/askuser.cpp
+ ${PROJECT_SOURCE_DIR}/src/framework/ui/common.cpp
+ ${PROJECT_SOURCE_DIR}/test/colour_log_formatter.cpp
+ test-main.cpp
+ test-popup.cpp
+)
+
+INCLUDE_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/src/include
+ ${PROJECT_SOURCE_DIR}/src/framework
+ ${PROJECT_SOURCE_DIR}/test
+ .
+ ${${TARGET_CSR_POPUP_TEST}_DEP_INCLUDE_DIRS}
+)
+
+ADD_EXECUTABLE(${TARGET_CSR_POPUP_TEST} ${${TARGET_CSR_POPUP_TEST}_SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_CSR_POPUP_TEST}
+ ${TARGET_CSR_COMMON}
+ boost_unit_test_framework
+ -ldl
+)
+
+INSTALL(TARGETS ${TARGET_CSR_POPUP_TEST} DESTINATION ${BIN_DIR})
--- /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 test-main.cpp
+ * @author Kyungwook Tak(k.tak@samsung.com)
+ * @version 1.0
+ * @brief CSR popup service test main
+ */
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <boost/test/results_reporter.hpp>
+#include <colour_log_formatter.h>
+
+struct TestConfig {
+ TestConfig()
+ {
+ boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_test_units);
+ boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
+ boost::unit_test::unit_test_log.set_formatter(new Csr::Test::colour_log_formatter);
+ }
+};
+
+BOOST_GLOBAL_FIXTURE(TestConfig)
--- /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 test-popup.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief CSR popup service test
+ */
+#define BOOST_TEST_MODULE CSR_POPUP_TEST
+#include "ui/askuser.h"
+#include "ui/common.h"
+
+#include <string>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace Csr::Ui;
+
+namespace {
+
+void printPressed(Response response)
+{
+ std::cout << "###################################################" << std::endl;
+ std::cout << "###################################################" << std::endl;
+ std::cout << "###################################################" << std::endl;
+
+ bool isValid = true;
+ switch (response) {
+ case Response::ALLOW:
+ std::cout << "############## ALLOW BUTTON PRESSED #############" << std::endl;
+ break;
+ case Response::DENY:
+ std::cout << "############## DENY BUTTON PRESSED #############" << std::endl;
+ break;
+ case Response::CONFIRM:
+ std::cout << "############## CONFIRM BUTTON PRESSED #############" << std::endl;
+ break;
+ case Response::REMOVE:
+ std::cout << "############## REMOVE BUTTON PRESSED #############" << std::endl;
+ break;
+ case Response::IGNORE:
+ std::cout << "############## IGNORE BUTTON PRESSED #############" << std::endl;
+ break;
+ case Response::SKIP:
+ std::cout << "############## SKIP BUTTON PRESSED #############" << std::endl;
+ break;
+ default:
+ std::cout << "############## Invalid Response!!! #############" << std::endl;
+ isValid = false;
+ break;
+ }
+
+ std::cout << "###################################################" << std::endl;
+ std::cout << "###################################################" << std::endl;
+ std::cout << "###################################################" << std::endl;
+
+ BOOST_REQUIRE_MESSAGE(isValid, "invalid response from csr-popup!");
+}
+
+}
+
+BOOST_AUTO_TEST_SUITE(POPUP)
+
+BOOST_AUTO_TEST_CASE(file_single)
+{
+ try {
+ AskUser askuser;
+
+ FileItem item;
+ item.severity = CSR_CS_SEVERITY_MEDIUM;
+ item.threat = CSR_CS_THREAT_RISKY;
+ item.filepath = "/opt/apps/csr/test/dummyfile";
+
+ auto response = askuser.fileSingle("Message for file_single tc", item);
+ printPressed(response);
+ } catch (...) {
+ BOOST_REQUIRE_MESSAGE(0, "exception shouldn't be thrown.");
+ }
+}
+
+BOOST_AUTO_TEST_CASE(url_single)
+{
+ try {
+ AskUser askuser;
+
+ UrlItem item;
+ item.risk = CSR_WP_RISK_MEDIUM;
+ item.url = "http://csr.test.dummyurl.com";
+
+ auto response = askuser.urlSingle("Message for url_single tc", item);
+ printPressed(response);
+ } catch (...) {
+ BOOST_REQUIRE_MESSAGE(0, "exception shouldn't be thrown.");
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END()