Merge changes from Tizen 2.4 73/44773/1
authorMu-Woong <muwoong.lee@samsung.com>
Mon, 27 Jul 2015 12:49:08 +0000 (21:49 +0900)
committerMu-Woong <muwoong.lee@samsung.com>
Mon, 27 Jul 2015 12:49:08 +0000 (21:49 +0900)
- Replace conf-file-based privilege checker with runtime-registration-based
- Remove ambiguity of app_id and client in request classes
- Update context-manager to support the on-demand provider object creation routine
- Modified script generator to assign null when some attributes of a condition is missing

Change-Id: I0943e6df4ac631fd6dd01550e13578ea7740c22e
Signed-off-by: Mu-Woong <muwoong.lee@samsung.com>
21 files changed:
data/access-config.xml [deleted file]
packaging/context-service.spec
src/access_control/config_loader.cpp [deleted file]
src/access_control/config_loader.h [deleted file]
src/access_control/privilege.cpp
src/access_control/privilege.h
src/client_request.cpp
src/client_request.h
src/context_mgr_impl.cpp
src/context_mgr_impl.h
src/context_trigger/context_monitor.cpp
src/context_trigger/context_monitor.h
src/context_trigger/fact_reader.cpp
src/context_trigger/fact_reader.h
src/context_trigger/rule_manager.cpp
src/context_trigger/script_generator.cpp
src/context_trigger/trigger.cpp
src/dbus_server_impl.cpp
src/request.cpp
src/request.h
src/server.cpp

diff --git a/data/access-config.xml b/data/access-config.xml
deleted file mode 100644 (file)
index 5471300..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>\r
-\r
-<ContextAccessConfig>\r
-\r
-       <Privilege name="alarm.set">\r
-               <Allow subject="timer/event/on_time"/>\r
-       </Privilege>\r
-\r
-       <Privilege name="network.get">\r
-               <Allow subject="system/state/wifi"/>\r
-       </Privilege>\r
-\r
-       <Privilege name="telephony">\r
-               <Allow subject="social/state/call"/>\r
-       </Privilege>\r
-\r
-       <Privilege name="message.read">\r
-               <Allow subject="social/event/message"/>\r
-       </Privilege>\r
-\r
-       <Privilege name="location">\r
-               <Allow subject="place/event/geofence"/>\r
-       </Privilege>\r
-\r
-       <Privilege name="apphistory.read">\r
-               <Allow subject="app/history/recently_used"/>\r
-               <Allow subject="app/history/frequently_used"/>\r
-               <Allow subject="app/history/rarely_used"/>\r
-               <Allow subject="app/history/peak_time"/>\r
-               <Allow subject="app/history/common_setting"/>\r
-               <Allow subject="app/history/use_freq"/>\r
-       </Privilege>\r
-\r
-       <Privilege name="mediahistory.read">\r
-               <Allow subject="music/history/peak_time"/>\r
-               <Allow subject="video/history/peak_time"/>\r
-               <Allow subject="music/history/common_setting"/>\r
-               <Allow subject="video/history/common_setting"/>\r
-               <Allow subject="music/history/play_freq"/>\r
-               <Allow subject="video/history/play_freq"/>\r
-       </Privilege>\r
-\r
-       <Privilege name="callhistory.read">\r
-               <Allow subject="contact/history/comm_freq"/>\r
-       </Privilege>\r
-\r
-</ContextAccessConfig>\r
index ed4f119db154c3e010b1755651f3b679a6fa524d..61ef9fdf38d9b9dd4db01d2de986f63dfc198a57 100644 (file)
@@ -84,7 +84,6 @@ install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}
 cp LICENSE %{buildroot}%{_datadir}/license/%{name}
 #sed -i "s/^\tversion=\".*\"/\tversion=\"%{version}\"/g" packaging/context-service.xml
 #cp packaging/context-service.xml %{buildroot}%{_datadir}/packages/
-cp data/access-config.xml %{buildroot}/opt/data/context-service/
 cp data/trigger-template.json %{buildroot}/opt/data/context-service/
 sh data/template-json-to-sql.sh data/trigger-template.json > %{buildroot}/opt/data/context-service/trigger-template.sql
 
@@ -93,7 +92,6 @@ install -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/dbus-1/system.d/
 
 %post
 sqlite3 -echo /opt/dbspace/.context-service.db < /opt/data/context-service/trigger-template.sql
-#chsmack -a "context-service" /opt/dbspace/.context-service.db*
 mkdir -p %{_unitdir}/graphical.target.wants
 ln -s ../context-service.service %{_unitdir}/graphical.target.wants/
 /sbin/ldconfig
@@ -112,7 +110,6 @@ systemctl daemon-reload
 %files
 %manifest packaging/%{name}.manifest
 %config %{_sysconfdir}/dbus-1/system.d/*
-#%defattr(-,root,root,-)
 %{_bindir}/*
 %{_unitdir}/context-service.service
 %{_datadir}/license/%{name}
diff --git a/src/access_control/config_loader.cpp b/src/access_control/config_loader.cpp
deleted file mode 100644 (file)
index 07ba3b4..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
-
-#include <types_internal.h>
-
-#include "privilege.h"
-#include "config_loader.h"
-
-#define CONFIG_PATH "/opt/data/context-service/access-config.xml"
-#define ELM_ROOT "ContextAccessConfig"
-#define ELM_PRIV "Privilege"
-#define ELM_LINK "Link"
-#define ELM_ALLOW "Allow"
-#define ATTR_NAME "name"
-#define ATTR_SUBJ "subject"
-#define IS_NODE_OF(node, element) (xmlStrcmp((node)->name, (const xmlChar *)(element)) == 0)
-
-static void parse_priv_node(xmlNodePtr cursor)
-{
-       char *prop = (char*)(xmlGetProp(cursor, (const xmlChar*)ATTR_NAME));
-       IF_FAIL_VOID_TAG(prop, _E, "Failed to get '%s'", ATTR_NAME);
-
-       std::string name = prop;
-       free(prop);
-
-       cursor = cursor->xmlChildrenNode;
-       IF_FAIL_VOID_TAG(cursor, _E, "No child node exists");
-
-       while (cursor) {
-               if (!IS_NODE_OF(cursor, ELM_ALLOW)) {
-                       _D("Skipping a node '%s'", (const char*)cursor->name);
-                       cursor = cursor->next;
-                       continue;
-               }
-
-               prop = (char*)(xmlGetProp(cursor, (const xmlChar*)ATTR_SUBJ));
-               if (prop == NULL) {
-                       _E("Failed to get '%s'", ATTR_SUBJ);
-                       cursor = cursor->next;
-                       continue;
-               }
-
-               _SI("Set Privilege: %s <- %s", prop, name.c_str());
-               ctx::privilege_manager::set(prop, name.c_str());
-
-               free(prop);
-               cursor = cursor->next;
-       }
-}
-
-static void parse_link_node(xmlNodePtr cursor)
-{
-       //TODO: Not supported yet
-       _D("Skipping a link node\n");
-}
-
-bool ctx::access_config_loader::load()
-{
-       xmlDocPtr doc = xmlParseFile(CONFIG_PATH);
-       IF_FAIL_RETURN_TAG(doc, false, _E, "XML parsing failed");
-
-       xmlNodePtr cursor = xmlDocGetRootElement(doc);
-       IF_FAIL_CATCH_TAG(cursor, _E, "No root node");
-       IF_FAIL_CATCH_TAG(IS_NODE_OF(cursor, ELM_ROOT), _E, "Invalid root node");
-
-       cursor = cursor->xmlChildrenNode;
-
-       while (cursor) {
-               if (IS_NODE_OF(cursor, ELM_PRIV)) {
-                       parse_priv_node(cursor);
-               } else if (IS_NODE_OF(cursor, ELM_LINK)) {
-                       parse_link_node(cursor);
-               }
-
-               cursor = cursor->next;
-       }
-
-       xmlFreeDoc(doc);
-       return true;
-
-CATCH:
-       xmlFreeDoc(doc);
-       return false;
-}
diff --git a/src/access_control/config_loader.h b/src/access_control/config_loader.h
deleted file mode 100644 (file)
index d74e51e..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * 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 __CONTEXT_ACCESS_CONFIG_LOADER_H__
-#define __CONTEXT_ACCESS_CONFIG_LOADER_H__
-
-namespace ctx {
-       namespace access_config_loader {
-
-               bool load();
-
-       }
-}      /* namespace ctx */
-
-#endif /* End of __CONTEXT_ACCESS_CONFIG_LOADER_H__ */
index 43e2a9b681810b117a476cf72ec38f0c2815a99a..2ab975a4bbac617fbb9739e297c9ca25fda31efa 100644 (file)
  */
 
 #include <string>
-#include <map>
 #include <types_internal.h>
-#include "config_loader.h"
 #include "privilege.h"
 
-typedef std::map<std::string, std::string> string_map_t;
-
-static string_map_t *privilege_map = NULL;
-
-bool ctx::privilege_manager::init()
-{
-       IF_FAIL_RETURN(privilege_map == NULL, true);
-
-       privilege_map = new(std::nothrow) string_map_t;
-
-       if (!ctx::access_config_loader::load()) {
-               _E("Loading failed");
-               delete privilege_map;
-               return false;
-       }
-
-       return true;
-}
-
-void ctx::privilege_manager::release()
-{
-       delete privilege_map;
-       privilege_map = NULL;
-}
-
-void ctx::privilege_manager::set(const char* subject, const char* priv)
-{
-       (*privilege_map)[subject] = priv;
-}
-
-bool ctx::privilege_manager::is_allowed(const char* pkg_id, const char* subject)
+bool ctx::privilege_manager::is_allowed(const char *client, const char *privilege)
 {
        /* TODO: need to be implemented using Cynara */
 #if 0
-       IF_FAIL_RETURN_TAG(pkg_id && subject, true, _E, "Invalid parameter");
-       IF_FAIL_RETURN_TAG(pkg_id[0]!='\0' && subject[0]!='\0', true, _E, "Invalid parameter");
-
-       string_map_t::iterator it = privilege_map->find(subject);
-       if (it == privilege_map->end()) {
-               // Non-Privileged Subject
-               return true;
-       }
+       IF_FAIL_RETURN(privilege, true);
 
-       std::string priv = "org.tizen.privilege.";
-       priv += (it->second).c_str();
-       int result = 0;
-       int err = security_server_app_has_privilege(pkg_id, PERM_APP_TYPE_EFL, priv.c_str(), &result);
+       std::string priv = "privilege::tizen::";
+       priv += privilege;
 
-       _D("PkgId: %s, PrivName: %s, Enabled: %d", pkg_id, (it->second).c_str(), result);
-       IF_FAIL_RETURN_TAG(err == SECURITY_SERVER_API_SUCCESS, false, _E, "Privilege checking failed");
+       int ret = smack_have_access(client, priv.c_str(), "rw");
+       _D("Client: %s, Priv: %s, Enabled: %d", client, privilege, ret);
 
-       return (result == 1);
+       return (ret == 1);
 #endif
        return true;
 }
index a77a640380fbb961290d4e69b83afdbadf2bf83e..8f9c8c731d6391ed187e39988282e4dd6b88e862 100644 (file)
 
 #include <string>
 
+#define PRIV_ALARM_SET "alarm.set"
+
 namespace ctx {
        namespace privilege_manager {
-
-               bool init();
-               void release();
-
-               void set(const char* subject, const char* priv);
-               bool is_allowed(const char* pkg_id, const char* subject);
-
+               bool is_allowed(const char *client, const char *privilege);
        }       /* namespace ctx::privilege_manager */
 }      /* namespace ctx */
 
index f7205caa4cfce9e2fb436d2e7f106cd257303b20..54a4ea22bf8a32095b69f6d2bfed7c1941ee3f4a 100644 (file)
 #include "dbus_server_impl.h"
 #include "client_request.h"
 
-ctx::client_request::client_request(int type, const char* client, int req_id, const char* subj, const char* desc, GDBusMethodInvocation *inv)
+ctx::client_request::client_request(int type,
+               const char *client, int req_id, const char *subj, const char *desc,
+               const char *sender, GDBusMethodInvocation *inv)
        : request_info(type, client, req_id, subj, desc)
-       , invocation(inv)
+       , __sender(sender)
+       , __invocation(inv)
 {
 }
 
 ctx::client_request::~client_request()
 {
-       if (invocation)
-               g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", ERR_OPERATION_FAILED, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
-}
-
-bool ctx::client_request::set_peer_creds(const char *smack_label)
-{
-       IF_FAIL_RETURN_TAG(smack_label, false, _E, "Invalid parameter");
-       client_app_id = smack_label;
-       return true;
-}
-
-const char* ctx::client_request::get_app_id()
-{
-       if (!client_app_id.empty())
-               return client_app_id.c_str();
-
-       return NULL;
+       if (__invocation)
+               g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", ERR_OPERATION_FAILED, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
 }
 
 bool ctx::client_request::reply(int error)
 {
-       IF_FAIL_RETURN(invocation, true);
+       IF_FAIL_RETURN(__invocation, true);
 
        _I("Reply %#x", error);
 
-       g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", error, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
-       invocation = NULL;
+       g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
+       __invocation = NULL;
        return true;
 }
 
 bool ctx::client_request::reply(int error, ctx::json& request_result)
 {
-       IF_FAIL_RETURN(invocation, true);
+       IF_FAIL_RETURN(__invocation, true);
        IF_FAIL_RETURN(_type != REQ_READ_SYNC, true);
 
        char *result = request_result.dup_cstr();
@@ -71,8 +59,8 @@ bool ctx::client_request::reply(int error, ctx::json& request_result)
        _I("Reply %#x", error);
        _SD("Result: %s", result);
 
-       g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", error, result, EMPTY_JSON_OBJECT));
-       invocation = NULL;
+       g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, result, EMPTY_JSON_OBJECT));
+       __invocation = NULL;
 
        g_free(result);
        return true;
@@ -80,7 +68,7 @@ bool ctx::client_request::reply(int error, ctx::json& request_result)
 
 bool ctx::client_request::reply(int error, ctx::json& request_result, ctx::json& data_read)
 {
-       if (invocation == NULL) {
+       if (__invocation == NULL) {
                return publish(error, data_read);
        }
 
@@ -97,8 +85,8 @@ bool ctx::client_request::reply(int error, ctx::json& request_result, ctx::json&
        _SD("Result: %s", result);
        _SD("Data: %s", data);
 
-       g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", error, result, data));
-       invocation = NULL;
+       g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, result, data));
+       __invocation = NULL;
 
        g_free(result);
        g_free(data);
@@ -115,7 +103,7 @@ bool ctx::client_request::publish(int error, ctx::json& data)
        char *data_str = data.dup_cstr();
        IF_FAIL_RETURN_TAG(data_str, false, _E, "Memory allocation failed");
 
-       dbus_server::publish(_client.c_str(), _req_id, _subject.c_str(), error, data_str);
+       dbus_server::publish(__sender.c_str(), _req_id, _subject.c_str(), error, data_str);
        g_free(data_str);
 
        return true;
index ae1628200e09e99d0d890e2ad3bad6f9079bf004..30181f0420bdc67588fb63a36e01a7c72c88ff6d 100644 (file)
 namespace ctx {
 
        class client_request : public request_info {
-               public:
-                       client_request(int type, const char* client, int req_id, const char* subj, const char* desc, GDBusMethodInvocation *inv);
-                       ~client_request();
-
-                       bool set_peer_creds(const char *smack_label);
-                       const char* get_app_id();
-
-                       bool reply(int error);
-                       bool reply(int error, ctx::json& request_result);
-                       bool reply(int error, ctx::json& request_result, ctx::json& data_read);
-                       bool publish(int error, ctx::json& data);
-
-               private:
-                       GDBusMethodInvocation *invocation;
-                       std::string client_app_id;
+       public:
+               client_request(int type,
+                               const char *client, int req_id, const char *subj, const char *desc,
+                               const char *sender, GDBusMethodInvocation *inv);
+               ~client_request();
+
+               bool reply(int error);
+               bool reply(int error, ctx::json &request_result);
+               bool reply(int error, ctx::json &request_result, ctx::json &data_read);
+               bool publish(int error, ctx::json &data);
+
+       private:
+               std::string __sender;
+               GDBusMethodInvocation *__invocation;
        };
 
 }      /* namespace ctx */
index 18cec7b74417aaddfdc92b65fece456bf9188df0..0f443817f69a5c90efac075ee5aaa8b5859d8431 100644 (file)
 #include "context_mgr_impl.h"
 #include "access_control/privilege.h"
 
-/* Analyzer Headers */
+/* Context Providers */
 #include <internal/device_context_provider.h>
-#include <internal/app_statistics_provider.h>
-#include <internal/social_statistics_provider.h>
-#include <internal/media_statistics_provider.h>
+#include <internal/statistics_context_provider.h>
 #include <internal/place_context_provider.h>
 
 ctx::context_manager_impl::context_manager_impl()
@@ -42,35 +40,26 @@ ctx::context_manager_impl::~context_manager_impl()
 
 bool ctx::context_manager_impl::init()
 {
-       IF_FAIL_RETURN_TAG(provider_list.size()==0, false, _W, "Re-initialization");
-
-       try {
-               /* List of all providers */
-               load_provider(new ctx::device_context_provider());
-               load_provider(new ctx::app_statistics_provider());
-               load_provider(new ctx::social_statistics_provider());
-               load_provider(new ctx::media_statistics_provider());
-               load_provider(new ctx::place_context_provider());
-
-       } catch (std::bad_alloc& ba) {
-               _E("Analyzer loading failed (bad alloc)");
-               return false;
-       } catch (int e) {
-               _E("Analyzer loading failed (%#x)", e);
-               return false;
-       }
+       bool ret;
+
+       ret = init_device_context_provider();
+       IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: device-context-provider");
+
+       ret = init_statistics_context_provider();
+       IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: statistics-context-provider");
+
+       ret = init_place_context_provider();
+       IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: place-context-provider");
 
        return true;
 }
 
 void ctx::context_manager_impl::release()
 {
-       subject_provider_map.clear();
-
-       for (provider_list_t::iterator it = provider_list.begin(); it != provider_list.end(); ++it) {
-               delete *it;
+       for (provider_map_t::iterator it = provider_map.begin(); it != provider_map.end(); ++it) {
+               it->second.destroy(it->second.data);
        }
-       provider_list.clear();
+       provider_map.clear();
 
        for (request_list_t::iterator it = subscribe_request_list.begin(); it != subscribe_request_list.end(); ++it) {
                delete *it;
@@ -83,32 +72,15 @@ void ctx::context_manager_impl::release()
        read_request_list.clear();
 }
 
-void ctx::context_manager_impl::load_provider(context_provider_iface* provider)
+bool ctx::context_manager_impl::register_provider(const char *subject, ctx::context_provider_info &provider_info)
 {
-       if (!provider) {
-               _E("Analyzer NULL");
-               throw static_cast<int>(ERR_INVALID_PARAMETER);
-       }
-
-       provider_list.push_back(provider);
-
-       if (!provider->init()) {
-               _E("Analyzer initialization failed");
-               throw ERR_OPERATION_FAILED;
-       }
-}
-
-bool ctx::context_manager_impl::register_provider(const char* subject, ctx::context_provider_iface* cp)
-{
-       IF_FAIL_RETURN_TAG(subject && cp, false, _E, "Invalid parameter");
-
-       if (subject_provider_map.find(subject) != subject_provider_map.end()) {
+       if (provider_map.find(subject) != provider_map.end()) {
                _E("The provider for the subject '%s' is already registered.", subject);
                return false;
        }
 
-       _I("Registering provider for '%s'", subject);
-       subject_provider_map[subject] = cp;
+       _SI("Subj: %s, Priv: %s", subject, provider_info.privilege);
+       provider_map[subject] = provider_info;
 
        return true;
 }
@@ -138,12 +110,10 @@ void ctx::context_manager_impl::assign_request(ctx::request_info* request)
        }
 }
 
-bool ctx::context_manager_impl::is_supported(const charsubject)
+bool ctx::context_manager_impl::is_supported(const char *subject)
 {
-       subject_provider_map_t::iterator it = subject_provider_map.find(subject);
-       IF_FAIL_RETURN(it != subject_provider_map.end(), false);
-
-       return it->second->is_supported(subject);
+       provider_map_t::iterator it = provider_map.find(subject);
+       return (it != provider_map.end());
 }
 
 void ctx::context_manager_impl::is_supported(request_info *request)
@@ -156,6 +126,14 @@ void ctx::context_manager_impl::is_supported(request_info *request)
        delete request;
 }
 
+bool ctx::context_manager_impl::is_allowed(const char *client, const char *subject)
+{
+       provider_map_t::iterator it = provider_map.find(subject);
+       IF_FAIL_RETURN(it != provider_map.end(), false);
+       IF_FAIL_RETURN(ctx::privilege_manager::is_allowed(client, it->second.privilege), false);
+       return true;
+}
+
 ctx::context_manager_impl::request_list_t::iterator
 ctx::context_manager_impl::find_request(request_list_t& r_list, std::string subject, json& option)
 {
@@ -187,47 +165,30 @@ ctx::context_manager_impl::find_request(request_list_t::iterator begin, request_
        return it;
 }
 
-ctx::context_provider_ifacectx::context_manager_impl::get_provider(ctx::request_info *request)
+ctx::context_provider_iface *ctx::context_manager_impl::get_provider(ctx::request_info *request)
 {
-       subject_provider_map_t::iterator it = subject_provider_map.find(request->get_subject());
-       if (it == subject_provider_map.end()) {
-               _E("Unknown subject '%s'", request->get_subject());
+       provider_map_t::iterator it = provider_map.find(request->get_subject());
+
+       if (it == provider_map.end()) {
+               _W("Unsupported subject");
                request->reply(ERR_NOT_SUPPORTED);
                delete request;
                return NULL;
        }
-       return it->second;
-}
-
-bool ctx::context_manager_impl::check_permission(ctx::request_info* request)
-{
-       const char* app_id = request->get_app_id();
-       _D("Peer AppID: %s", app_id);
 
-       if (app_id == NULL) {
-               _E("AppID NULL");
-               request->reply(ERR_PERMISSION_DENIED);
-               delete request;
-               return false;
-       }
-
-       IF_FAIL_RETURN_TAG(!STR_EQ(app_id, TRIGGER_CLIENT_NAME), true, _D, "Skipping permission check for Trigger");
-
-       bool allowed = ctx::privilege_manager::is_allowed(app_id, request->get_subject());
-       if (!allowed) {
+       if (!ctx::privilege_manager::is_allowed(request->get_client(), it->second.privilege)) {
                _W("Permission denied");
                request->reply(ERR_PERMISSION_DENIED);
                delete request;
-               return false;
+               return NULL;
        }
 
-       return true;
+       return it->second.create(it->second.data);
 }
 
 void ctx::context_manager_impl::subscribe(ctx::request_info *request)
 {
        _I(CYAN("'%s' subscribes '%s' (RID-%d)"), request->get_client(), request->get_subject(), request->get_id());
-       IF_FAIL_VOID(check_permission(request));
 
        context_provider_iface *provider = get_provider(request);
        IF_FAIL_VOID(provider);
@@ -274,8 +235,8 @@ void ctx::context_manager_impl::unsubscribe(ctx::request_info *request)
        }
 
        // Find the proper provider
-       subject_provider_map_t::iterator ca = subject_provider_map.find(req_found->get_subject());
-       if (ca == subject_provider_map.end()) {
+       provider_map_t::iterator ca = provider_map.find(req_found->get_subject());
+       if (ca == provider_map.end()) {
                _E("Invalid subject '%s'", req_found->get_subject());
                delete request;
                delete req_found;
@@ -283,7 +244,7 @@ void ctx::context_manager_impl::unsubscribe(ctx::request_info *request)
        }
 
        // Stop detecting the subject
-       int error = ca->second->unsubscribe(req_found->get_subject(), req_found->get_description());
+       int error = ca->second.create(ca->second.data)->unsubscribe(req_found->get_subject(), req_found->get_description());
        request->reply(error);
        delete request;
        delete req_found;
@@ -292,7 +253,6 @@ void ctx::context_manager_impl::unsubscribe(ctx::request_info *request)
 void ctx::context_manager_impl::read(ctx::request_info *request)
 {
        _I(CYAN("'%s' reads '%s' (RID-%d)"), request->get_client(), request->get_subject(), request->get_id());
-       IF_FAIL_VOID(check_permission(request));
 
        context_provider_iface *provider = get_provider(request);
        IF_FAIL_VOID(provider);
@@ -313,7 +273,6 @@ void ctx::context_manager_impl::read(ctx::request_info *request)
 void ctx::context_manager_impl::write(ctx::request_info *request)
 {
        _I(CYAN("'%s' writes '%s' (RID-%d)"), request->get_client(), request->get_subject(), request->get_id());
-       IF_FAIL_VOID(check_permission(request));
 
        context_provider_iface *provider = get_provider(request);
        IF_FAIL_VOID(provider);
index c6026d39530bb6c39a12067007dcd7beb4e9472e..76bdae19a30feedd0945cb2866b2ae4288302607 100644 (file)
@@ -39,22 +39,19 @@ namespace ctx {
 
                void assign_request(ctx::request_info *request);
                bool is_supported(const char *subject);
+               bool is_allowed(const char *client, const char *subject);
 
                /* From the interface class */
-               bool register_provider(const char *subject, ctx::context_provider_iface *cp);
-               bool publish(const char *subject, ctx::json& option, int error, ctx::json& data_updated);
-               bool reply_to_read(const char *subject, ctx::json& option, int error, ctx::json& data_read);
+               bool register_provider(const char *subject, context_provider_info &provider_info);
+               bool publish(const char *subject, ctx::json &option, int error, ctx::json &data_updated);
+               bool reply_to_read(const char *subject, ctx::json &option, int error, ctx::json &data_read);
 
        private:
-               typedef std::vector<context_provider_iface*> provider_list_t;
-               typedef std::map<std::string, context_provider_iface*> subject_provider_map_t;
+               typedef std::map<std::string, context_provider_info> provider_map_t;
 
-               provider_list_t provider_list;
                request_list_t subscribe_request_list;
                request_list_t read_request_list;
-               subject_provider_map_t subject_provider_map;
-
-               void load_provider(ctx::context_provider_iface *provider);
+               provider_map_t provider_map;
 
                void subscribe(request_info *request);
                void unsubscribe(request_info *request);
@@ -63,7 +60,6 @@ namespace ctx {
                void is_supported(request_info *request);
 
                context_provider_iface *get_provider(request_info *request);
-               bool check_permission(request_info *request);
 
                static gboolean thread_switcher(gpointer data);
                bool _publish(const char *subject, ctx::json option, int error, ctx::json data_updated);
index ed9d6a7ab4cbf17beba4970165a88b431f6ae412..239f55dcc80ef156a8ec364f24d1fdd2a735f430 100644 (file)
@@ -17,6 +17,7 @@
 #include <types_internal.h>
 #include <json.h>
 #include <context_trigger_types_internal.h>
+#include "../access_control/privilege.h"
 #include "context_monitor.h"
 #include "fact_reader.h"
 #include "timer_types.h"
@@ -212,3 +213,14 @@ bool ctx::context_monitor::is_supported(std::string subject)
 
        return reader->is_supported(subject.c_str());
 }
+
+bool ctx::context_monitor::is_allowed(const char *client, const char *subject)
+{
+       if (STR_EQ(subject, TIMER_EVENT_SUBJECT))
+               return privilege_manager::is_allowed(client, PRIV_ALARM_SET);
+
+       if (STR_EQ(subject, TIMER_CONDITION_SUBJECT))
+               return true;
+
+       return reader->is_allowed(client, subject);
+}
index 678107a9f48584f449dedb91582f6f675cfe2e3a..b34dadc227aae6c03dfb43488c7c1cf6f061e39e 100644 (file)
@@ -36,6 +36,7 @@ namespace ctx {
                int unsubscribe(int rule_id, std::string subject, ctx::json option);
                int read(std::string subject, json option, ctx::json* result);
                bool is_supported(std::string subject);
+               bool is_allowed(const char *client, const char *subject);
 
        private:
                int subscribe_timer(ctx::json option);
index f8935eae7c8c66e477ac8e7b964beb08f51a83ec..cd09a00abda320ded03cff87f51c707e743db8b5 100644 (file)
@@ -123,6 +123,11 @@ bool ctx::fact_reader::is_supported(const char* subject)
        return _context_mgr->is_supported(subject);
 }
 
+bool ctx::fact_reader::is_allowed(const char *client, const char *subject)
+{
+       return _context_mgr->is_allowed(client, subject);
+}
+
 int ctx::fact_reader::subscribe(const char* subject, json* option, bool wait_response)
 {
        IF_FAIL_RETURN(subject, ERR_INVALID_PARAMETER);
index e52b86e963de8506ab2057166b6dfa1e4f580308..d0a0dfdba47658193d8acb4520749cb68b0129c1 100644 (file)
@@ -27,45 +27,46 @@ namespace ctx {
        class context_trigger;
 
        class fact_reader {
-               public:
-                       fact_reader(context_manager_impl* mgr, context_trigger* trigger);
-                       ~fact_reader();
+       public:
+               fact_reader(context_manager_impl *mgr, context_trigger *trigger);
+               ~fact_reader();
 
-                       bool is_supported(const char* subject);
+               bool is_supported(const char *subject);
+               bool is_allowed(const char *client, const char *subject);
 
-                       int subscribe(const char* subject, json* option, bool wait_response = false);
-                       void unsubscribe(const char* subject, json* option);
-                       void unsubscribe(int subscription_id);
-                       bool read(const char* subject, json* option, context_fact& fact);
+               int subscribe(const char *subject, json *option, bool wait_response = false);
+               void unsubscribe(const char *subject, json *option);
+               void unsubscribe(int subscription_id);
+               bool read(const char *subject, json *option, context_fact& fact);
 
-                       void reply_result(int req_id, int error, json* request_result = NULL, json* fact = NULL);
-                       void publish_fact(int req_id, int error, const char* subject, json* option, json* fact);
+               void reply_result(int req_id, int error, json *request_result = NULL, json *fact = NULL);
+               void publish_fact(int req_id, int error, const char *subject, json *option, json *fact);
 
-               private:
-                       static context_manager_impl* _context_mgr;
-                       static context_trigger* _trigger;
+       private:
+               static context_manager_impl *_context_mgr;
+               static context_trigger *_trigger;
 
-                       struct subscr_info_s {
-                               int sid;
-                               std::string subject;
-                               ctx::json option;
-                               subscr_info_s(int id, const char* subj, ctx::json* opt)
-                                       : sid(id), subject(subj)
-                               {
-                                       if (opt)
-                                               option = *opt;
-                               }
-                       };
+               struct subscr_info_s {
+                       int sid;
+                       std::string subject;
+                       ctx::json option;
+                       subscr_info_s(int id, const char *subj, ctx::json *opt)
+                               : sid(id), subject(subj)
+                       {
+                               if (opt)
+                                       option = *opt;
+                       }
+               };
 
-                       typedef std::list<subscr_info_s*> subscr_list_t;
-                       subscr_list_t subscr_list;
+               typedef std::list<subscr_info_s*> subscr_list_t;
+               subscr_list_t subscr_list;
 
-                       int find_sub(const char* subject, json* option);
-                       bool add_sub(int sid, const char* subject, json* option);
-                       void remove_sub(const char* subject, json* option);
-                       void remove_sub(int sid);
+               int find_sub(const char *subject, json *option);
+               bool add_sub(int sid, const char *subject, json *option);
+               void remove_sub(const char *subject, json *option);
+               void remove_sub(int sid);
 
-                       static gboolean send_request(gpointer data);
+               static gboolean send_request(gpointer data);
        };
 
 }      /* namespace ctx */
index 4fd214fe1c5780a07bcbee60766dccea8e331aa0..b13122775227c50d708418f9a2b69aee6bf69d05 100644 (file)
@@ -29,7 +29,6 @@
 #include <context_trigger_types_internal.h>
 #include <context_trigger.h>
 #include <db_mgr.h>
-#include "../access_control/privilege.h"
 #include "rule_manager.h"
 #include "script_generator.h"
 #include "trigger.h"
@@ -389,7 +388,7 @@ int ctx::rule_manager::verify_rule(ctx::json& rule, const char* app_id)
        IF_FAIL_RETURN_TAG(c_monitor.is_supported(e_name), ERR_NOT_SUPPORTED, _I, "Event(%s) is not supported", e_name.c_str());
 
        if (app_id) {
-               if (!ctx::privilege_manager::is_allowed(app_id, e_name.c_str())) {
+               if (!c_monitor.is_allowed(app_id, e_name.c_str())) {
                        _W("Permission denied for '%s'", e_name.c_str());
                        return ERR_PERMISSION_DENIED;
                }
@@ -402,7 +401,7 @@ int ctx::rule_manager::verify_rule(ctx::json& rule, const char* app_id)
 
                IF_FAIL_RETURN_TAG(c_monitor.is_supported(c_name), ERR_NOT_SUPPORTED, _I, "Condition(%s) is not supported", c_name.c_str());
 
-               if (!ctx::privilege_manager::is_allowed(app_id, c_name.c_str())) {
+               if (!c_monitor.is_allowed(app_id, c_name.c_str())) {
                        _W("Permission denied for '%s'", c_name.c_str());
                        return ERR_PERMISSION_DENIED;
                }
index 3c8653bff1eef206bf26f545602cd9cf72439624..7480d188a23a9097b6fe9e5aea00059121928b1f 100644 (file)
@@ -81,7 +81,7 @@ std::string ctx::script_generator::generate_deftemplate(ctx::json* item)
        for (std::set<std::string>::iterator it = slot.begin(); it != slot.end(); ++it){
                script += "(slot ";
                script += *it;
-               script += " (default null))";
+               script += " (default nil))";
        }
        script += ")\n";
 
@@ -104,7 +104,7 @@ std::string ctx::script_generator::generate_defclass(ctx::json* item)
        for (int i = 0; item->get_array_elem(NULL, "attributes", i, &attr_name); i++) {
                script += "(slot ";
                script += attr_name;
-               script += " (create-accessor read-write))";
+               script += " (default nil)(create-accessor read-write))";
        }
        script += ")\n";
 
@@ -449,9 +449,7 @@ std::string ctx::script_generator::generate_fact(std::string item_name, ctx::jso
        }
 
        for (int i = 0; event_template.get_array_elem(NULL, "attributes", i, &key); i++) {
-               script += "(";
-               script += key;
-               script += " ";
+               script += "(" + key + " ";
                if (data.get(NULL, key.c_str(), &val_str)) {    // string type data
                        script += "\"" + val_str + "\"";
                } else if (data.get(NULL, key.c_str(), &value)) {       // integer type data
@@ -476,11 +474,15 @@ std::string ctx::script_generator::generate_modifyinstance(std::string instance_
        std::string val_str;
        int value;
        for (int i = 0; condition_template.get_array_elem(NULL, "attributes", i, &key); i++) {
+               script += "(" + key + " ";
                if (data.get(NULL, key.c_str(), &val_str)) {    // string type data
-                       script += "(" + key + " \"" + val_str + "\")";
+                       script += "\"" + val_str + "\"";
                } else  if (data.get(NULL, key.c_str(), &value)) {      // integer type data
-                       script += "(" + key + " " + int_to_string(value) + ")";
+                       script += int_to_string(value);
+               } else {
+                       script += "nil";
                }
+               script += ")";
        }
        script += ")";
 
index 32eb2f4d85b0f1b26b8ad35158f7b693c8ed007e..c85c4f13d66de0267e6aed79add5bde3321f3b07 100644 (file)
@@ -171,7 +171,7 @@ void ctx::context_trigger::add_rule(ctx::request_info* request)
 {
        ctx::json rule_id;
 
-       const char* app_id = request->get_app_id();
+       const char* app_id = request->get_client();
        if (app_id == NULL) {
                request->reply(ERR_OPERATION_FAILED);
                return;
@@ -188,7 +188,7 @@ void ctx::context_trigger::remove_rule(ctx::request_info* request)
        int id;
        int error;
 
-       const char* app_id = request->get_app_id();
+       const char* app_id = request->get_client();
        if (app_id == NULL) {
                request->reply(ERR_OPERATION_FAILED);
                return;
@@ -219,7 +219,7 @@ void ctx::context_trigger::enable_rule(ctx::request_info* request)
        int id;
        int error;
 
-       const char* app_id = request->get_app_id();
+       const char* app_id = request->get_client();
        if (app_id == NULL) {
                request->reply(ERR_OPERATION_FAILED);
                return;
@@ -250,7 +250,7 @@ void ctx::context_trigger::disable_rule(ctx::request_info* request)
        int id;
        int error;
 
-       const char* app_id = request->get_app_id();
+       const char* app_id = request->get_client();
        if (app_id == NULL) {
                request->reply(ERR_OPERATION_FAILED);
                return;
@@ -284,7 +284,7 @@ void ctx::context_trigger::get_rule_by_id(ctx::request_info* request)
        int id;
        option.get(NULL, CT_RULE_ID, &id);
 
-       const char* app_id = request->get_app_id();
+       const char* app_id = request->get_client();
        if (app_id == NULL) {
                request->reply(ERR_OPERATION_FAILED);
                return;
@@ -301,7 +301,7 @@ void ctx::context_trigger::get_rule_ids(ctx::request_info* request)
 {
        int error;
 
-       const char* app_id = request->get_app_id();
+       const char* app_id = request->get_client();
        if (app_id == NULL) {
                request->reply(ERR_OPERATION_FAILED);
                return;
index 23f20e45e8f696fd855dafa18d9f37aec04ebf7f..ac464ea02b0023d6a79b099dd2463b5735868fbb 100644 (file)
@@ -77,28 +77,26 @@ static void handle_request(const char *sender, GVariant *param, GDBusMethodInvoc
        g_variant_get(param, "(i&si&s&s)", &req_type, &cookie, &req_id, &subject, &input);
        IF_FAIL_VOID_TAG(req_type > 0 && req_id > 0 && cookie && subject && input, _E, "Invalid request");
 
-       _SD("Cookie: %s", cookie);
        _I("[%s] ReqId: %d, Subject: %s", req_type_to_str(req_type), req_id, subject);
        _SI("Input: %s", input);
 
-       ctx::client_request *request = NULL;
-       try {
-               request = new ctx::client_request(req_type, sender, req_id, subject, input, invocation);
-       } catch (std::bad_alloc& ba) {
-               _E("Memory allocation failed");
+       std::string smack_label;
+       pid_t pid;
+
+       if (!ctx::peer_creds::get(dbus_connection, sender, smack_label, pid)) {
+               _E("Peer credential failed");
                g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", ERR_OPERATION_FAILED, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
                return;
        }
 
-       std::string smack_label;
-       pid_t pid;
-
-       if (ctx::peer_creds::get(dbus_connection, sender, smack_label, pid) && request->set_peer_creds(smack_label.c_str())) {
-               ctx::server::send_request(request);
+       ctx::client_request *request = new(std::nothrow) ctx::client_request(req_type, smack_label.c_str(), req_id, subject, input, sender, invocation);
+       if (!request) {
+               _E("Memory allocation failed");
+               g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", ERR_OPERATION_FAILED, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
                return;
        }
 
-       delete request;
+       ctx::server::send_request(request);
 }
 
 static void handle_method_call(GDBusConnection *conn, const gchar *sender,
index 6b9e51c66acf58d61cde7d490797e0d20d0c7365..26e9b3eb6ef90626c3f1acffb5da42c91334c3a3 100644 (file)
@@ -51,11 +51,6 @@ const char* ctx::request_info::get_subject()
        return _subject.c_str();
 }
 
-const char* ctx::request_info::get_app_id()
-{
-       return get_client();
-}
-
 ctx::json& ctx::request_info::get_description()
 {
        return _description;
index a11487fdb94e7382e97f5fbe06a5544741eb59d3..2a3e45b9418298653208b41eb3ea5f65a6668876 100644 (file)
 namespace ctx {
 
        class request_info {
-               public:
-                       request_info(int type, const char* client, int req_id, const char* subj, const char* desc);
-                       virtual ~request_info();
-
-                       int get_type();
-                       int get_id();
-                       const char* get_client();
-                       const char* get_subject();
-                       ctx::json& get_description();
-                       virtual const char* get_app_id();
-
-                       virtual bool reply(int error) = 0;
-                       virtual bool reply(int error, ctx::json& request_result) = 0;
-                       virtual bool reply(int error, ctx::json& request_result, ctx::json& data_read) = 0;
-                       virtual bool publish(int error, ctx::json& data) = 0;
-
-               protected:
-                       int _type;
-                       int _req_id;
-                       std::string _client;
-                       std::string _subject;
-                       ctx::json _description;
+       public:
+               request_info(int type, const char *client, int req_id, const char *subj, const char *desc);
+               virtual ~request_info();
+
+               int get_type();
+               int get_id();
+               const char *get_client();
+               const char *get_subject();
+               ctx::json& get_description();
+
+               virtual bool reply(int error) = 0;
+               virtual bool reply(int error, ctx::json &request_result) = 0;
+               virtual bool reply(int error, ctx::json &request_result, ctx::json &data_read) = 0;
+               virtual bool publish(int error, ctx::json &data) = 0;
+
+       protected:
+               int _type;
+               int _req_id;
+               std::string _client;
+               std::string _subject;
+               ctx::json _description;
        };
 
 }      /* namespace ctx */
index 82432fec4748a6397ffdc59aa0612748a68a21a2..3dab603034b592afb2dcb4c717e95756fefa8028 100644 (file)
@@ -24,7 +24,6 @@
 #include "db_mgr_impl.h"
 #include "timer_mgr_impl.h"
 #include "context_mgr_impl.h"
-#include "access_control/privilege.h"
 #include "context_trigger/trigger.h"
 #include "server.h"
 
@@ -74,10 +73,6 @@ void ctx::server::activate()
 
        bool result = false;
 
-       _I("Init access control configuration");
-       result = ctx::privilege_manager::init();
-       IF_FAIL_CATCH_TAG(result, _E, "Access controller initialization failed");
-
        _I("Init Timer Manager");
        timer_mgr = new(std::nothrow) ctx::timer_manager_impl();
        IF_FAIL_CATCH_TAG(timer_mgr, _E, "Memory allocation failed");
@@ -143,9 +138,6 @@ void ctx::server::release()
        if (timer_mgr)
                timer_mgr->release();
 
-       _I("Release Access control configuration");
-       ctx::privilege_manager::release();
-
 #ifdef _USE_ECORE_MAIN_LOOP_
        ecore_shutdown();
 #else