+++ /dev/null
-<?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
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
%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
%files
%manifest packaging/%{name}.manifest
%config %{_sysconfdir}/dbus-1/system.d/*
-#%defattr(-,root,root,-)
%{_bindir}/*
%{_unitdir}/context-service.service
%{_datadir}/license/%{name}
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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__ */
*/
#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;
}
#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 */
#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();
_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;
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);
}
_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);
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;
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 */
#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()
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;
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;
}
}
}
-bool ctx::context_manager_impl::is_supported(const char* subject)
+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)
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)
{
return it;
}
-ctx::context_provider_iface* ctx::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);
}
// 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;
}
// 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;
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);
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);
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);
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);
#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"
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);
+}
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);
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);
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 */
#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"
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;
}
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;
}
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";
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";
}
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
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 += ")";
{
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;
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;
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;
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;
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;
{
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;
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,
return _subject.c_str();
}
-const char* ctx::request_info::get_app_id()
-{
- return get_client();
-}
-
ctx::json& ctx::request_info::get_description()
{
return _description;
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 */
#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"
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");
if (timer_mgr)
timer_mgr->release();
- _I("Release Access control configuration");
- ctx::privilege_manager::release();
-
#ifdef _USE_ECORE_MAIN_LOOP_
ecore_shutdown();
#else