From: Somin Kim Date: Mon, 15 Feb 2016 11:13:21 +0000 (+0900) Subject: Modified trigger to use package id for rule management X-Git-Tag: submit/tizen/20160314.020719~1^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dffcbb2ff1ceceeb00a57a00ec919346d6a0d5d2;p=platform%2Fcore%2Fcontext%2Fcontext-service.git Modified trigger to use package id for rule management - request get_app_id() removed Change-Id: Iaef20e72b9a13974bc5ec246e461a9db99589e2b Signed-off-by: Somin Kim --- diff --git a/src/access_control/peer_creds.cpp b/src/access_control/peer_creds.cpp index c8641bc..5d42a81 100644 --- a/src/access_control/peer_creds.cpp +++ b/src/access_control/peer_creds.cpp @@ -21,8 +21,7 @@ #include #include "peer_creds.h" -ctx::credentials::credentials(char *_app_id, char *_package_id, char *_client, char *_session, char *_user) : - app_id(_app_id), +ctx::credentials::credentials(char *_package_id, char *_client, char *_session, char *_user) : package_id(_package_id), client(_client), session(_session), @@ -32,7 +31,6 @@ ctx::credentials::credentials(char *_app_id, char *_package_id, char *_client, c ctx::credentials::~credentials() { - g_free(app_id); g_free(package_id); g_free(client); g_free(session); @@ -65,7 +63,7 @@ bool ctx::peer_creds::get(GDBusConnection *connection, const char *unique_name, err = cynara_creds_gdbus_get_user(connection, unique_name, USER_METHOD_DEFAULT, &user); IF_FAIL_CATCH_TAG(err == CYNARA_API_SUCCESS, _E, "Peer credentialing failed"); - *creds = new(std::nothrow) credentials(app_id, package_id, client, session, user); + *creds = new(std::nothrow) credentials(package_id, client, session, user); IF_FAIL_CATCH_TAG(*creds, _E, "Memory allocation failed"); return true; diff --git a/src/access_control/peer_creds.h b/src/access_control/peer_creds.h index 7889987..4be8167 100644 --- a/src/access_control/peer_creds.h +++ b/src/access_control/peer_creds.h @@ -25,12 +25,11 @@ namespace ctx { class credentials { public: - char *app_id; char *package_id; char *client; /* default: smack label */ char *session; char *user; /* default: UID */ - credentials(char *_app_id, char *_package_id, char *_client, char *_session, char *_user); + credentials(char *_package_id, char *_client, char *_session, char *_user); ~credentials(); }; diff --git a/src/client_request.cpp b/src/client_request.cpp index e164d6d..4b218be 100644 --- a/src/client_request.cpp +++ b/src/client_request.cpp @@ -44,14 +44,6 @@ const ctx::credentials* ctx::client_request::get_credentials() return __credentials; } -const char* ctx::client_request::get_app_id() -{ - if (__credentials) - return __credentials->app_id; - - return NULL; -} - const char* ctx::client_request::get_package_id() { if (__credentials) diff --git a/src/client_request.h b/src/client_request.h index 6df5da7..9c13783 100644 --- a/src/client_request.h +++ b/src/client_request.h @@ -29,7 +29,6 @@ namespace ctx { ~client_request(); const credentials* get_credentials(); - const char* get_app_id(); const char* get_package_id(); const char* get_client(); bool reply(int error); diff --git a/src/context_trigger/action_manager.cpp b/src/context_trigger/action_manager.cpp index d035c5a..b839711 100644 --- a/src/context_trigger/action_manager.cpp +++ b/src/context_trigger/action_manager.cpp @@ -28,10 +28,10 @@ #include "action_manager.h" static void trigger_action_app_control(ctx::json& action); -static void trigger_action_notification(ctx::json& action, std::string app_id); // TODO appid? creator? +static void trigger_action_notification(ctx::json& action, std::string pkg_id); static void trigger_action_dbus_call(ctx::json& action); -void ctx::action_manager::trigger_action(ctx::json& action, std::string creator) +void ctx::action_manager::trigger_action(ctx::json& action, std::string pkg_id) { std::string type; action.get(NULL, CT_RULE_ACTION_TYPE, &type); @@ -39,7 +39,7 @@ void ctx::action_manager::trigger_action(ctx::json& action, std::string creator) if (type.compare(CT_RULE_ACTION_TYPE_APP_CONTROL) == 0) { trigger_action_app_control(action); } else if (type.compare(CT_RULE_ACTION_TYPE_NOTIFICATION) == 0) { - trigger_action_notification(action, creator); + trigger_action_notification(action, pkg_id); } else if (type.compare(CT_RULE_ACTION_TYPE_DBUS_CALL) == 0) { trigger_action_dbus_call(action); } @@ -80,7 +80,7 @@ void trigger_action_app_control(ctx::json& action) } } -void trigger_action_notification(ctx::json& action, std::string app_id) // TODO appid? creator? +void trigger_action_notification(ctx::json& action, std::string pkg_id) { int error; notification_h notification = notification_create(NOTIFICATION_TYPE_NOTI); @@ -133,10 +133,10 @@ void trigger_action_notification(ctx::json& action, std::string app_id) // TODO } } - if (!app_id.empty()) { - error = notification_set_pkgname(notification, app_id.c_str()); + if (!pkg_id.empty()) { + error = notification_set_pkgname(notification, pkg_id.c_str()); if (error != NOTIFICATION_ERROR_NONE) { - _E("Set pkgname(%s) failed(%d)", app_id.c_str(), error); + _E("Set package id(%s) failed(%#x)", pkg_id.c_str(), error); } } diff --git a/src/context_trigger/action_manager.h b/src/context_trigger/action_manager.h index cc39c9b..e8bf6df 100644 --- a/src/context_trigger/action_manager.h +++ b/src/context_trigger/action_manager.h @@ -23,7 +23,7 @@ namespace ctx { namespace action_manager { - void trigger_action(ctx::json& action, std::string creator); + void trigger_action(ctx::json& action, std::string pkg_id); } diff --git a/src/context_trigger/rule.cpp b/src/context_trigger/rule.cpp index 5328f42..34270ab 100644 --- a/src/context_trigger/rule.cpp +++ b/src/context_trigger/rule.cpp @@ -24,10 +24,10 @@ ctx::rule_manager *ctx::trigger_rule::rule_mgr = NULL; -ctx::trigger_rule::trigger_rule(int i, ctx::json& d, const char* cr, rule_manager* rm) +ctx::trigger_rule::trigger_rule(int i, ctx::json& d, const char* p, rule_manager* rm) : result(EMPTY_JSON_OBJECT) , id(i) - , creator(cr) + , pkg_id(p) { // Rule manager if (!rule_mgr) { @@ -126,10 +126,10 @@ void ctx::trigger_rule::on_event_received(std::string name, ctx::json option, ct clear_result(); } - // Check if creator is uninstalled - if (ctx::rule_manager::is_uninstalled_package(creator)) { - _D("Creator(%s) of rule%d is uninstalled.", creator.c_str(), id); - g_idle_add(handle_uninstalled_rule, &creator); + // Check if creator package is uninstalled + if (ctx::rule_manager::is_uninstalled_package(pkg_id)) { + _D("Creator(%s) of rule%d is uninstalled.", pkg_id.c_str(), id); + g_idle_add(handle_uninstalled_rule, &pkg_id); return; } @@ -187,15 +187,15 @@ void ctx::trigger_rule::clear_result() void ctx::trigger_rule::on_context_data_prepared(void) { if (ctx::rule_evaluator::evaluate_rule(statement, result)) { - ctx::action_manager::trigger_action(action, creator); + ctx::action_manager::trigger_action(action, pkg_id); } clear_result(); } gboolean ctx::trigger_rule::handle_uninstalled_rule(gpointer data) { - std::string* app_id = static_cast(data); - rule_mgr->handle_rule_of_uninstalled_app(*app_id); + std::string* pkg_id = static_cast(data); + rule_mgr->handle_rule_of_uninstalled_package(*pkg_id); return FALSE; } diff --git a/src/context_trigger/rule.h b/src/context_trigger/rule.h index 3fc3688..b5829e0 100644 --- a/src/context_trigger/rule.h +++ b/src/context_trigger/rule.h @@ -58,9 +58,9 @@ namespace ctx { public: int id; - std::string creator; + std::string pkg_id; - trigger_rule(int i, ctx::json& d, const char* c, rule_manager* rm); + trigger_rule(int i, ctx::json& d, const char* p, rule_manager* rm); ~trigger_rule(); int start(void); diff --git a/src/context_trigger/rule_manager.cpp b/src/context_trigger/rule_manager.cpp index 61b745e..815ed2e 100644 --- a/src/context_trigger/rule_manager.cpp +++ b/src/context_trigger/rule_manager.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include "rule_manager.h" #include "template_manager.h" #include "context_monitor.h" @@ -61,14 +61,14 @@ bool ctx::rule_manager::init() // Create tables into db (rule, template) std::string q1 = std::string("status INTEGER DEFAULT 0 NOT NULL, creator TEXT DEFAULT '' NOT NULL,") - + "creator_app_id TEXT DEFAULT '' NOT NULL, description TEXT DEFAULT ''," + + "package_id TEXT DEFAULT '' NOT NULL, description TEXT DEFAULT ''," + "details TEXT DEFAULT '' NOT NULL"; ret = db_manager::create_table(1, RULE_TABLE, q1.c_str(), NULL, NULL); IF_FAIL_RETURN_TAG(ret, false, _E, "Create rule table failed"); // Before re-enable rules, handle uninstalled app's rules if (get_uninstalled_app() > 0) { - error = clear_rule_of_uninstalled_app(true); + error = clear_rule_of_uninstalled_package(true); IF_FAIL_RETURN_TAG(error == ERR_NONE, false, _E, "Failed to remove uninstalled apps' rules while initialization"); } ret = reenable_rule(); @@ -76,84 +76,84 @@ bool ctx::rule_manager::init() return ret; } -void ctx::rule_manager::handle_rule_of_uninstalled_app(std::string app_id) +void ctx::rule_manager::handle_rule_of_uninstalled_package(std::string pkg_id) { - uninstalled_apps.insert(app_id); - clear_rule_of_uninstalled_app(); + uninstalled_packages.insert(pkg_id); + clear_rule_of_uninstalled_package(); } int ctx::rule_manager::get_uninstalled_app(void) { // Return number of uninstalled apps - std::string q1 = "SELECT DISTINCT creator_app_id FROM context_trigger_rule"; + std::string q1 = "SELECT DISTINCT package_id FROM context_trigger_rule"; std::vector record; bool ret = db_manager::execute_sync(q1.c_str(), &record); - IF_FAIL_RETURN_TAG(ret, -1, _E, "Query creators of registered rules failed"); + IF_FAIL_RETURN_TAG(ret, -1, _E, "Query package ids of registered rules failed"); std::vector::iterator vec_end = record.end(); for (std::vector::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) { ctx::json elem = *vec_pos; - std::string app_id; - elem.get(NULL, "creator_app_id", &app_id); + std::string pkg_id; + elem.get(NULL, "package_id", &pkg_id); - if (is_uninstalled_package(app_id)) { - uninstalled_apps.insert(app_id); + if (is_uninstalled_package(pkg_id)) { + uninstalled_packages.insert(pkg_id); } } - return uninstalled_apps.size(); + return uninstalled_packages.size(); } -bool ctx::rule_manager::is_uninstalled_package(std::string app_id) +bool ctx::rule_manager::is_uninstalled_package(std::string pkg_id) { - IF_FAIL_RETURN_TAG(!app_id.empty(), false, _D, "Empty app id"); + IF_FAIL_RETURN_TAG(!pkg_id.empty(), false, _D, "Empty package id"); - app_info_h app_info; - int error = app_manager_get_app_info(app_id.c_str(), &app_info); + package_info_h pkg_info; + int error = package_manager_get_package_info(pkg_id.c_str(), &pkg_info); - if (error == APP_MANAGER_ERROR_NONE) { - app_info_destroy(app_info); - } else if (error == APP_MANAGER_ERROR_NO_SUCH_APP) { - // Uninstalled app found - _D("Uninstalled app found: %s", app_id.c_str()); + if (error == PACKAGE_MANAGER_ERROR_NONE) { + package_info_destroy(pkg_info); + } else if (error == PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE) { + // Uninstalled package found + _D("Uninstalled package found: %s", pkg_id.c_str()); return true; } else { - _E("Get app info(%s) failed: %d", app_id.c_str(), error); + _E("Failed to get package info(%s): %d", pkg_id.c_str(), error); } return false; } -int ctx::rule_manager::clear_rule_of_uninstalled_app(bool is_init) +int ctx::rule_manager::clear_rule_of_uninstalled_package(bool is_init) { - if (uninstalled_apps.size() <= 0) { + if (uninstalled_packages.size() <= 0) { return ERR_NONE; } int error; bool ret; - _D("Clear uninstalled apps' rule started"); - // creator list - std::string creator_list = "("; - std::set::iterator it = uninstalled_apps.begin(); - creator_list += "creator_app_id = '" + *it + "'"; + _D("Clear uninstalled packages' rule started"); + // Package list + std::string pkg_list = "("; + std::set::iterator it = uninstalled_packages.begin(); + pkg_list += "package_id = '" + *it + "'"; it++; - for (; it != uninstalled_apps.end(); ++it) { - creator_list += " OR creator_app_id = '" + *it + "'"; + for (; it != uninstalled_packages.end(); ++it) { + pkg_list += " OR package_id = '" + *it + "'"; } - creator_list += ")"; + pkg_list += ")"; - // After event received, disable all the enabled rules of uninstalled apps // TODO register uninstalled apps app_id when before trigger + // After event received, disable all the enabled rules of uninstalled apps if (!is_init) { std::string q1 = "SELECT row_id FROM context_trigger_rule WHERE status = 2 and ("; - q1 += creator_list; + q1 += pkg_list; q1 += ")"; std::vector record; ret = db_manager::execute_sync(q1.c_str(), &record); - IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Query enabled rules of uninstalled apps failed"); + IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to query enabled rules of uninstalled packages"); std::vector::iterator vec_end = record.end(); for (std::vector::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) { @@ -163,17 +163,17 @@ int ctx::rule_manager::clear_rule_of_uninstalled_app(bool is_init) error = disable_rule(rule_id); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to disable rule" ); } - _D("Uninstalled apps' rules are disabled"); + _D("Uninstalled packages' rules are disabled"); } - // Delete rules of uninstalled apps from DB - std::string q2 = "DELETE FROM context_trigger_rule WHERE " + creator_list; + // Delete rules of uninstalled packages from DB + std::string q2 = "DELETE FROM context_trigger_rule WHERE " + pkg_list; std::vector dummy; ret = db_manager::execute_sync(q2.c_str(), &dummy); - IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Remove rule from db failed"); - _D("Uninstalled apps's rule are deleted from db"); + IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to remove rules from db"); + _D("Uninstalled packages' rules are deleted from db"); - uninstalled_apps.clear(); + uninstalled_packages.clear(); return ERR_NONE; } @@ -413,15 +413,15 @@ bool ctx::rule_manager::rule_equals(ctx::json& lrule, ctx::json& rrule) return true; } -int64_t ctx::rule_manager::get_duplicated_rule_id(std::string creator, ctx::json& rule) +int64_t ctx::rule_manager::get_duplicated_rule_id(std::string pkg_id, ctx::json& rule) { - std::string q = "SELECT row_id, description, details FROM context_trigger_rule WHERE creator = '"; - q += creator; + std::string q = "SELECT row_id, description, details FROM context_trigger_rule WHERE package_id = '"; + q += pkg_id; q += "'"; std::vector d_record; bool ret = db_manager::execute_sync(q.c_str(), &d_record); - IF_FAIL_RETURN_TAG(ret, false, _E, "Query row_id, details by creator failed"); + IF_FAIL_RETURN_TAG(ret, false, _E, "Query row_id, details by package id failed"); ctx::json r_details; rule.get(NULL, CT_RULE_DETAILS, &r_details); @@ -500,7 +500,7 @@ int ctx::rule_manager::verify_rule(ctx::json& rule, const char* creator) return ERR_NONE; } -int ctx::rule_manager::add_rule(std::string creator, const char* app_id, ctx::json rule, ctx::json* rule_id) +int ctx::rule_manager::add_rule(std::string creator, const char* pkg_id, ctx::json rule, ctx::json* rule_id) { apply_templates(); bool ret; @@ -508,10 +508,10 @@ int ctx::rule_manager::add_rule(std::string creator, const char* app_id, ctx::js // Check if all items are supported && allowed to access int err = verify_rule(rule, creator.c_str()); - IF_FAIL_RETURN(err==ERR_NONE, err); + IF_FAIL_RETURN(err == ERR_NONE, err); // Check if duplicated rule exits - if ((rid = get_duplicated_rule_id(creator, rule)) > 0) { + if ((rid = get_duplicated_rule_id(pkg_id, rule)) > 0) { // Save rule id rule_id->set(NULL, CT_RULE_ID, rid); _D("Duplicated rule found"); @@ -525,8 +525,8 @@ int ctx::rule_manager::add_rule(std::string creator, const char* app_id, ctx::js rule.get(NULL, CT_RULE_DESCRIPTION, &description); rule.get(NULL, CT_RULE_DETAILS, &details); r_record.set(NULL, "creator", creator); - if (app_id) { - r_record.set(NULL, "creator_app_id", app_id); + if (pkg_id) { + r_record.set(NULL, "package_id", pkg_id); } r_record.set(NULL, "description", description); @@ -570,7 +570,7 @@ int ctx::rule_manager::enable_rule(int rule_id) std::string query; std::vector rule_record; std::vector record; - std::string creator_app_id; + std::string pkg_id; ctx::json jrule; std::string tmp; std::string id_str = int_to_string(rule_id); @@ -578,17 +578,17 @@ int ctx::rule_manager::enable_rule(int rule_id) trigger_rule* rule; // Get rule json by rule id; - query = "SELECT details, creator_app_id FROM context_trigger_rule WHERE row_id = "; + query = "SELECT details, package_id FROM context_trigger_rule WHERE row_id = "; query += id_str; error = (db_manager::execute_sync(query.c_str(), &rule_record))? ERR_NONE : ERR_OPERATION_FAILED; IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Query rule by rule id failed"); rule_record[0].get(NULL, "details", &tmp); jrule = tmp; - rule_record[0].get(NULL, "creator_app_id", &creator_app_id); + rule_record[0].get(NULL, "package_id", &pkg_id); // Create a rule instance - rule = new(std::nothrow) trigger_rule(rule_id, jrule, creator_app_id.c_str(), this); + rule = new(std::nothrow) trigger_rule(rule_id, jrule, pkg_id.c_str(), this); IF_FAIL_RETURN_TAG(rule, ERR_OUT_OF_MEMORY, _E, "Failed to create rule instance"); // Start the rule @@ -675,24 +675,24 @@ int ctx::rule_manager::pause_rule(int rule_id) return ERR_NONE; } -int ctx::rule_manager::check_rule(std::string creator, int rule_id) +int ctx::rule_manager::check_rule(std::string pkg_id, int rule_id) { - // Get creator app id - std::string q = "SELECT creator FROM context_trigger_rule WHERE row_id ="; + // Get package id + std::string q = "SELECT package_id FROM context_trigger_rule WHERE row_id ="; q += int_to_string(rule_id); std::vector record; bool ret = db_manager::execute_sync(q.c_str(), &record); - IF_FAIL_RETURN_TAG(ret, false, _E, "Query creator by rule id failed"); + IF_FAIL_RETURN_TAG(ret, false, _E, "Query package id by rule id failed"); if (record.size() == 0) { return ERR_NO_DATA; } - std::string c; - record[0].get(NULL, "creator", &c); + std::string p; + record[0].get(NULL, "package_id", &p); - if (c.compare(creator) == 0){ + if (p.compare(pkg_id) == 0){ return ERR_NONE; } @@ -714,11 +714,11 @@ bool ctx::rule_manager::is_rule_enabled(int rule_id) return (status != 0); } -int ctx::rule_manager::get_rule_by_id(std::string creator, int rule_id, ctx::json* request_result) +int ctx::rule_manager::get_rule_by_id(std::string pkg_id, int rule_id, ctx::json* request_result) { apply_templates(); - std::string q = "SELECT description FROM context_trigger_rule WHERE (creator = '"; - q += creator; + std::string q = "SELECT description FROM context_trigger_rule WHERE (package_id = '"; + q += pkg_id; q += "') and (row_id = "; q += int_to_string(rule_id); q += ")"; @@ -742,12 +742,12 @@ int ctx::rule_manager::get_rule_by_id(std::string creator, int rule_id, ctx::jso return ERR_NONE; } -int ctx::rule_manager::get_rule_ids(std::string creator, ctx::json* request_result) +int ctx::rule_manager::get_rule_ids(std::string pkg_id, ctx::json* request_result) { (*request_result) = "{ \"" CT_RULE_ARRAY_ENABLED "\" : [ ] , \"" CT_RULE_ARRAY_DISABLED "\" : [ ] }"; - std::string q = "SELECT row_id, status FROM context_trigger_rule WHERE (creator = '"; - q += creator; + std::string q = "SELECT row_id, status FROM context_trigger_rule WHERE (package_id = '"; + q += pkg_id; q += "')"; std::vector record; diff --git a/src/context_trigger/rule_manager.h b/src/context_trigger/rule_manager.h index bf054e9..2b0b44e 100644 --- a/src/context_trigger/rule_manager.h +++ b/src/context_trigger/rule_manager.h @@ -32,33 +32,33 @@ namespace ctx { ~rule_manager(); bool init(); - int add_rule(std::string creator, const char* app_id, ctx::json rule, ctx::json* rule_id); + int add_rule(std::string creator, const char* pkg_id, ctx::json rule, ctx::json* rule_id); int remove_rule(int rule_id); int enable_rule(int rule_id); int disable_rule(int rule_id); - int get_rule_by_id(std::string creator, int rule_id, ctx::json* request_result); - int get_rule_ids(std::string creator, ctx::json* request_result); - int check_rule(std::string creator, int rule_id); + int get_rule_by_id(std::string pkg_id, int rule_id, ctx::json* request_result); + int get_rule_ids(std::string pkg_id, ctx::json* request_result); + int check_rule(std::string pkg_id, int rule_id); bool is_rule_enabled(int rule_id); int pause_rule_with_item(std::string& subject); int pause_rule(int rule_id); int resume_rule_with_item(std::string& subject); - void handle_rule_of_uninstalled_app(std::string app_id); + void handle_rule_of_uninstalled_package(std::string pkg_id); - static bool is_uninstalled_package(std::string app_id); + static bool is_uninstalled_package(std::string pkg_id); private: bool reenable_rule(void); - int verify_rule(ctx::json& rule, const char* app_id); - int64_t get_duplicated_rule_id(std::string creator, ctx::json& rule); + int verify_rule(ctx::json& rule, const char* creator); + int64_t get_duplicated_rule_id(std::string pkg_id, ctx::json& rule); bool rule_data_arr_elem_equals(ctx::json& lelem, ctx::json& relem); bool rule_item_equals(ctx::json& litem, ctx::json& ritem); bool rule_equals(ctx::json& lrule, ctx::json& rrule); int get_uninstalled_app(void); - int clear_rule_of_uninstalled_app(bool is_init = false); + int clear_rule_of_uninstalled_package(bool is_init = false); void apply_templates(void); - std::set uninstalled_apps; + std::set uninstalled_packages; typedef std::map rule_map_t; rule_map_t rule_map; diff --git a/src/context_trigger/trigger.cpp b/src/context_trigger/trigger.cpp index 94b3f15..d0b28e4 100644 --- a/src/context_trigger/trigger.cpp +++ b/src/context_trigger/trigger.cpp @@ -132,9 +132,9 @@ void ctx::context_trigger::add_rule(ctx::request_info* request) return; } - const char* app_id = request->get_app_id(); + const char* pkg_id = request->get_package_id(); - int error = rule_mgr->add_rule(client, app_id, request->get_description(), &rule_id); + int error = rule_mgr->add_rule(client, pkg_id, request->get_description(), &rule_id); _I("'%s' adds a rule (Error: %#x)", request->get_client(), error); request->reply(error, rule_id); @@ -145,16 +145,12 @@ void ctx::context_trigger::remove_rule(ctx::request_info* request) int id; int error; - const char* app_id = request->get_client(); - if (app_id == NULL) { - request->reply(ERR_OPERATION_FAILED); - return; - } + const char* pkg_id = request->get_package_id(); ctx::json rule_id = request->get_description(); rule_id.get(NULL, CT_RULE_ID, &id); - error = rule_mgr->check_rule(app_id, id); + error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id); if (error != ERR_NONE) { request->reply(error); return; @@ -176,16 +172,12 @@ void ctx::context_trigger::enable_rule(ctx::request_info* request) int id; int error; - const char* app_id = request->get_client(); - if (app_id == NULL) { - request->reply(ERR_OPERATION_FAILED); - return; - } + const char* pkg_id = request->get_package_id(); ctx::json rule_id = request->get_description(); rule_id.get(NULL, CT_RULE_ID, &id); - error = rule_mgr->check_rule(app_id, id); + error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id); if (error != ERR_NONE) { request->reply(error); return; @@ -207,16 +199,12 @@ void ctx::context_trigger::disable_rule(ctx::request_info* request) int id; int error; - const char* app_id = request->get_client(); - if (app_id == NULL) { - request->reply(ERR_OPERATION_FAILED); - return; - } + const char* pkg_id = request->get_package_id(); ctx::json rule_id = request->get_description(); rule_id.get(NULL, CT_RULE_ID, &id); - error = rule_mgr->check_rule(app_id, id); + error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id); if (error != ERR_NONE) { request->reply(error); return; @@ -241,14 +229,10 @@ 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_client(); - if (app_id == NULL) { - request->reply(ERR_OPERATION_FAILED); - return; - } + const char* pkg_id = request->get_package_id(); ctx::json read_data; - error = rule_mgr->get_rule_by_id(app_id, id, &read_data); + error = rule_mgr->get_rule_by_id((pkg_id)? pkg_id : "", id, &read_data); ctx::json dummy; request->reply(error, dummy, read_data); @@ -258,14 +242,10 @@ void ctx::context_trigger::get_rule_ids(ctx::request_info* request) { int error; - const char* app_id = request->get_client(); - if (app_id == NULL) { - request->reply(ERR_OPERATION_FAILED); - return; - } + const char* pkg_id = request->get_package_id(); ctx::json read_data; - error = rule_mgr->get_rule_ids(app_id, &read_data); + error = rule_mgr->get_rule_ids((pkg_id)? pkg_id : "", &read_data); ctx::json dummy; request->reply(error, dummy, read_data); diff --git a/src/request.cpp b/src/request.cpp index 6bf9f43..61f158d 100644 --- a/src/request.cpp +++ b/src/request.cpp @@ -45,11 +45,6 @@ const ctx::credentials* ctx::request_info::get_credentials() return NULL; } -const char* ctx::request_info::get_app_id() -{ - return NULL; -} - const char* ctx::request_info::get_package_id() { return NULL; diff --git a/src/request.h b/src/request.h index 3faeb78..00de3be 100644 --- a/src/request.h +++ b/src/request.h @@ -36,7 +36,6 @@ namespace ctx { ctx::json& get_description(); virtual const credentials* get_credentials(); - virtual const char* get_app_id(); virtual const char* get_package_id(); /* TODO: remove this get_client() */ virtual const char* get_client();