diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 067035360..6ee72e716 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -131,7 +131,7 @@ DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUp Object::Ptr object = type->Instantiate(); - Deserialize(object, serializedUpdate, false, FAConfig); + Deserialize(object, serializedUpdate, true, FAConfig); return static_pointer_cast(object); } diff --git a/lib/base/serializer.cpp b/lib/base/serializer.cpp index 057aeedcd..aee604350 100644 --- a/lib/base/serializer.cpp +++ b/lib/base/serializer.cpp @@ -149,6 +149,9 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary { const Type *type; + if (!object && safe_mode) + BOOST_THROW_EXCEPTION(std::runtime_error("Tried to instantiate object while safe mode is enabled.")); + if (object) type = object->GetReflectionType(); else @@ -157,14 +160,12 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary if (!type) return object; - Object::Ptr instance = object; - - if (!instance) { - if (safe_mode && !type->IsSafe()) - BOOST_THROW_EXCEPTION(std::runtime_error("Tried to instantiate type '" + type->GetName() + "' which is not marked as safe.")); - + Object::Ptr instance; + + if (object) + instance = object; + else instance = type->Instantiate(); - } ObjectLock olock(input); BOOST_FOREACH(const Dictionary::Pair& kv, input) { @@ -232,8 +233,8 @@ Value icinga::Deserialize(const Object::Ptr& object, const Value& value, bool sa ASSERT(dict != NULL); - if (!dict->Contains("type")) + if ((safe_mode && !object) || !dict->Contains("type")) return DeserializeDictionary(dict, safe_mode, attributeTypes); - - return DeserializeObject(object, dict, safe_mode, attributeTypes); + else + return DeserializeObject(object, dict, safe_mode, attributeTypes); } diff --git a/lib/base/type.cpp b/lib/base/type.cpp index 7c1c027c3..4e191c5df 100644 --- a/lib/base/type.cpp +++ b/lib/base/type.cpp @@ -57,11 +57,6 @@ bool Type::IsAbstract(void) const return ((GetAttributes() & TAAbstract) != 0); } -bool Type::IsSafe(void) const -{ - return ((GetAttributes() & TASafe) != 0); -} - bool Type::IsAssignableFrom(const Type *other) const { for (const Type *t = other; t; t = t->GetBaseType()) { diff --git a/lib/base/type.hpp b/lib/base/type.hpp index bc3c18b98..da9baac64 100644 --- a/lib/base/type.hpp +++ b/lib/base/type.hpp @@ -43,8 +43,7 @@ struct Field enum TypeAttribute { - TAAbstract = 1, - TASafe = 2 + TAAbstract = 1 }; class I2_BASE_API Type @@ -64,7 +63,6 @@ public: bool IsAssignableFrom(const Type *other) const; bool IsAbstract(void) const; - bool IsSafe(void) const; static void Register(const Type *type); static const Type *GetByName(const String& name); diff --git a/lib/icinga/apievents.cpp b/lib/icinga/apievents.cpp index 4e8b3c6e4..c9aa173f3 100644 --- a/lib/icinga/apievents.cpp +++ b/lib/icinga/apievents.cpp @@ -131,9 +131,8 @@ Value ApiEvents::CheckResultAPIHandler(const MessageOrigin& origin, const Dictio if (!params) return Empty; - Value crv = params->Get("cr"); - - CheckResult::Ptr cr = Deserialize(crv, true); + CheckResult::Ptr cr = make_shared(); + Deserialize(cr, params->Get("cr"), true); Host::Ptr host = FindHostByVirtualName(params->Get("host"), origin); @@ -1105,7 +1104,7 @@ Value ApiEvents::VarsChangedAPIHandler(const MessageOrigin& origin, const Dictio if (origin.FromZone && !origin.FromZone->CanAccessObject(object)) return Empty; - Dictionary::Ptr vars = Deserialize(params->Get("vars"), true); + Dictionary::Ptr vars = params->Get("vars"); if (!vars) return Empty; @@ -1166,7 +1165,8 @@ Value ApiEvents::CommentAddedAPIHandler(const MessageOrigin& origin, const Dicti if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) return Empty; - Comment::Ptr comment = Deserialize(params->Get("comment"), true); + Comment::Ptr comment = make_shared(); + Deserialize(comment, params->Get("comment"), true); checkable->AddComment(comment->GetEntryType(), comment->GetAuthor(), comment->GetText(), comment->GetExpireTime(), comment->GetId(), origin); @@ -1281,7 +1281,8 @@ Value ApiEvents::DowntimeAddedAPIHandler(const MessageOrigin& origin, const Dict if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) return Empty; - Downtime::Ptr downtime = Deserialize(params->Get("downtime"), true); + Downtime::Ptr downtime = make_shared(); + Deserialize(downtime, params->Get("downtime"), true); checkable->AddDowntime(downtime->GetAuthor(), downtime->GetComment(), downtime->GetStartTime(), downtime->GetEndTime(), diff --git a/lib/icinga/checkresult.ti b/lib/icinga/checkresult.ti index 12977a5d4..d709348cd 100644 --- a/lib/icinga/checkresult.ti +++ b/lib/icinga/checkresult.ti @@ -57,7 +57,7 @@ enum StateType }; }}} -safe class CheckResult +class CheckResult { [state] double schedule_start; [state] double schedule_end; diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti index b12b39023..2304d5ea0 100644 --- a/lib/icinga/comment.ti +++ b/lib/icinga/comment.ti @@ -35,7 +35,7 @@ enum CommentType }; }}} -safe class Comment +class Comment { [state] String id; [state] double entry_time; diff --git a/lib/icinga/downtime.ti b/lib/icinga/downtime.ti index e672d98c0..5f18cee0e 100644 --- a/lib/icinga/downtime.ti +++ b/lib/icinga/downtime.ti @@ -20,7 +20,7 @@ namespace icinga { -safe class Downtime +class Downtime { [state] String id; [state] double entry_time; diff --git a/lib/icinga/perfdatavalue.ti b/lib/icinga/perfdatavalue.ti index bd14a08f8..5864710a8 100644 --- a/lib/icinga/perfdatavalue.ti +++ b/lib/icinga/perfdatavalue.ti @@ -22,7 +22,7 @@ namespace icinga { -safe class PerfdataValue +class PerfdataValue { [state] String label; [state] double value; diff --git a/tools/mkclass/class_lexer.ll b/tools/mkclass/class_lexer.ll index 6e37f541f..00d1d89b3 100644 --- a/tools/mkclass/class_lexer.ll +++ b/tools/mkclass/class_lexer.ll @@ -133,7 +133,6 @@ class { return T_CLASS; } namespace { return T_NAMESPACE; } code { return T_CODE; } abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; } -safe { yylval->num = TASafe; return T_CLASS_ATTRIBUTE; } config { yylval->num = FAConfig; return T_FIELD_ATTRIBUTE; } state { yylval->num = FAState; return T_FIELD_ATTRIBUTE; } enum { yylval->num = FAEnum; return T_FIELD_ATTRIBUTE; } diff --git a/tools/mkclass/classcompiler.hpp b/tools/mkclass/classcompiler.hpp index fe653eb3d..f8ec30bf2 100644 --- a/tools/mkclass/classcompiler.hpp +++ b/tools/mkclass/classcompiler.hpp @@ -105,8 +105,7 @@ struct Field enum TypeAttribute { - TAAbstract = 1, - TASafe = 2 + TAAbstract = 1 }; struct Klass