std::string error;
Json::CharReaderBuilder builder;
+ builder["collectComments"] = false;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+ bool result;
+ try {
+ result = reader->parse(fact.c_str(), (fact.c_str() + fact.size()), &factJson, &error);
+ } catch (Json::Exception const&) {
+ _E("Template: invalid json(Json::Exception)");
+ return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+ }
+
// Error: Invalid Json
- if (!reader->parse(fact.c_str(), (fact.c_str()+fact.size()), &factJson, &error)) {
+ if (!result) {
_E("Fact: invalid json, error [%s]", error.c_str());
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
}
bool CustomTemplate::isValidFact(const Json::Value& tmplJson, const Json::Value& factJson)
{
- Json::Value::Members keys = factJson.getMemberNames();
+ Json::Value::Members keys;
+
+ try {
+ keys = factJson.getMemberNames();
+ } catch (Json::Exception const&) {
+ _E("Custom fact: Invalid value(Json::Exception)");
+ return false;
+ }
std::string dataType;
for (auto& key : keys) {
bool CustomTemplate::isValidTemplate(const Json::Value& tmplJson)
{
bool success = false;
- Json::Value::Members keys = tmplJson.getMemberNames();
+ Json::Value::Members keys;
+
+ try {
+ keys = tmplJson.getMemberNames();
+ } catch (Json::Exception const&) {
+ _E("Invalid template(Json::Exception)");
+ return false;
+ }
std::string dataType;
for (auto& key : keys) {
int minVal = 0;
int maxVal = 0;
- Json::Value::Members elemKeys = elem.getMemberNames();
+ Json::Value::Members elemKeys;
+
+ try {
+ elemKeys = elem.getMemberNames();
+ } catch (Json::Exception const&) {
+ _E("invalid int(Json::Exception)");
+ return false;
+ }
for (auto& elemKey : elemKeys) {
if (elemKey == CT_KEY_MIN) {
bool CustomTemplate::checkTemplateString(const Json::Value& elem)
{
- Json::Value::Members elemKeys = elem.getMemberNames();
+ Json::Value::Members elemKeys;
+ try {
+ elemKeys = elem.getMemberNames();
+ } catch (Json::Exception const&) {
+ _E("invalid string(Json::Exception)");
+ return false;
+ }
for (auto& elemKey : elemKeys) {
IF_FAIL_RETURN_TAG(elemKey == CT_KEY_TYPE, false, _E, "invalid key");
bool CustomTemplate::checkTemplateEnum(const Json::Value& elem)
{
- Json::Value::Members elemKeys = elem.getMemberNames();
+ Json::Value::Members elemKeys;
+ try {
+ elemKeys = elem.getMemberNames();
+ } catch (Json::Exception const&) {
+ _E("invalid enum(Json::Exception)");
+ return false;
+ }
for (auto& elemKey : elemKeys) {
if (elemKey == CT_TYPE_ENUM) {
std::string error;
Json::CharReaderBuilder builder;
+ builder["collectComments"] = false;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+ bool result;
+ try {
+ result = reader->parse(attrTmpl.c_str(), attrTmpl.c_str() + attrTmpl.size(), &tmplJson, &error);
+ } catch (Json::Exception const&) {
+ _E("Template: invalid json(Json::Exception)");
+ return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+ }
+
// Error: Invalid Json
- if (!reader->parse(attrTmpl.c_str(), \
- (attrTmpl.c_str()+attrTmpl.size()), &tmplJson, &error)) {
+ if (!result) {
_E("Template: invalid json, error [%s]", error.c_str());
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
}
void CustomTemplate::remove(const std::string& name)
{
__instances.remove_if(
- [&name](const CustomTemplate& tmpl)->bool {
- return tmpl.getName() == name;
- });
+ [&name](const CustomTemplate& tmpl)->bool {
+ return tmpl.getName() == name;
+ });
}
CustomTemplate* CustomTemplate::get(const std::string& name)
} while (0)
enum EntryCategory {
- CATEGORY_EVENT = 1,
- CATEGORY_CONDITION = 2
+ CATEGORY_EVENT = 1,
+ CATEGORY_CONDITION = 2
};
enum class OpType {
}
} _context_trigger_rule_h;
-
typedef struct _context_trigger_rule_entry_s {
int category;
int type;
}
} _context_trigger_rule_entry_h;
-
namespace {
- class Scheduler {
- private:
- ctx_sched_h __scheduler;
+class Scheduler {
+private:
+ ctx_sched_h __scheduler;
- public:
- Scheduler() : __scheduler(NULL) {}
+public:
+ Scheduler() : __scheduler(NULL)
+ {
+ }
- ~Scheduler()
- {
- ctx_sched_destroy(__scheduler);
- }
+ ~Scheduler()
+ {
+ ctx_sched_destroy(__scheduler);
+ }
- ctx_sched_h get()
- {
- if (__scheduler == NULL)
- ctx_sched_create(&__scheduler);
+ ctx_sched_h get()
+ {
+ if (__scheduler == NULL)
+ ctx_sched_create(&__scheduler);
- return __scheduler;
- }
- };
+ return __scheduler;
+ }
+};
}
static OpType __getOpType(const char* opStr)
static Scheduler __scheduler;
-
EXPORT_API int context_trigger_add_rule(context_trigger_rule_h rule, int* rule_id)
{
INIT_SCHED;
CHECK_CONTEXT_TRIGGER_SUPPORTED(CONTEXT_TRIGGER_FEATURE);
ASSERT_NOT_NULL(rule && entry);
IF_FAIL_RETURN_TAG(!rule->readOnly, E_PARAM,
- _E, "A rule acquired by context_trigger_get_rule_by_id() is not allowed to be modified.");
+ _E, "A rule acquired by context_trigger_get_rule_by_id() is not allowed to be modified.");
if (entry->category == CATEGORY_EVENT)
return __set_event(rule, entry);
}
if (__is_call_operation(app_control) &&
- !PrivilegeChecker::hasPrivilege("http://tizen.org/privilege/call")) {
+ !PrivilegeChecker::hasPrivilege("http://tizen.org/privilege/call")) {
_E("Privilege denied");
return E_ACCESS;
}
}
EXPORT_API int context_trigger_rule_set_action_notification(context_trigger_rule_h rule,
- const char* title, const char* content, const char* icon_path, app_control_h app_control)
+ const char* title, const char* content, const char* icon_path, app_control_h app_control)
{
CHECK_CONTEXT_TRIGGER_SUPPORTED(CONTEXT_TRIGGER_FEATURE);
INIT_SCHED;
static bool __is_valid_pkg_id(const char* pkgId)
{
- CHECK_CONTEXT_TRIGGER_SUPPORTED(CONTEXT_TRIGGER_FEATURE);
IF_FAIL_RETURN(pkgId, false);
pkgmgrinfo_pkginfo_h pkgInfo;