return true;
}
+ManifestConstraints::ManifestConstraints() :
+ max_attr_element_length_(0) {
+}
+
+void ManifestConstraints::set_max_attr_element_length(unsigned int value) {
+ max_attr_element_length_ = value;
+}
+
+unsigned int ManifestConstraints::max_attr_element_length() const {
+ return max_attr_element_length_;
+}
+
} // namespace parser
Manifest& operator=(const Manifest&) = delete;
};
+struct ManifestConstraints {
+ public:
+ ManifestConstraints();
+ unsigned int max_attr_element_length() const;
+ void set_max_attr_element_length(unsigned int value);
+
+ private:
+ unsigned int max_attr_element_length_;
+};
+
} // namespace parser
#endif // MANIFEST_PARSER_MANIFEST_H_
return impl_->GetErrorMessage();
}
-bool ManifestParser::ParseManifest(const boost::filesystem::path& path) {
- return impl_->ParseManifest(path);
+bool ManifestParser::ParseManifest(const boost::filesystem::path& path,
+ std::shared_ptr<ManifestConstraints> constraints) {
+ return impl_->ParseManifest(path, constraints);
}
std::shared_ptr<const ManifestData> ManifestParser::GetManifestData(
virtual const std::string& GetErrorMessage() const;
// Parses manifest file to manfiest_ object
- bool ParseManifest(const boost::filesystem::path& path);
+ bool ParseManifest(const boost::filesystem::path& path,
+ std::shared_ptr<ManifestConstraints> constraints = nullptr);
std::shared_ptr<const ManifestData> GetManifestData(const std::string& key);
std::shared_ptr<ManifestData> GetMutableManifestData(const std::string& key);
return error_;
}
-bool ManifestParserImpl::ParseManifest(const bf::path& manifest_path) {
+bool ManifestParserImpl::ParseManifest(const bf::path& manifest_path,
+ std::shared_ptr<ManifestConstraints> constraints) {
error_.clear();
if (manifest_path.empty()) {
SetError(kErrMsgNoPath, &error_);
return false;
}
- manifest_ = parser::LoadManifest(manifest_path.string(), &error_);
+ manifest_ =
+ parser::LoadManifest(manifest_path.string(), &error_, constraints);
if (!manifest_.get())
return false;
if (!ParseManifestData(&error_))
/**
* @brief ParseManifest
* @param path
+ * @param constraints
* @return true on success
*/
- bool ParseManifest(const boost::filesystem::path& path);
+ bool ParseManifest(const boost::filesystem::path& path,
+ std::shared_ptr<ManifestConstraints> constraints = nullptr);
/**
* @brief GetMutableManifestData gathers manifest data
* @param key
namespace bf = boost::filesystem;
namespace {
+
const char kAttributePrefix[] = "@";
const xmlChar kWidgetNodeKey[] = "widget";
// std::map<std::string*, std::map<std::string*,std::string>>
std::unique_ptr<DictionaryValue> LoadXMLNode(
- xmlNode* root, const std::string& inherit_dir) {
+ xmlNode* root,
+ std::shared_ptr<ManifestConstraints> constraints,
+ const std::string& inherit_dir) {
std::unique_ptr<DictionaryValue> value(new DictionaryValue());
if (root->type != XML_ELEMENT_NODE)
return nullptr;
xmlAttr* prop = nullptr;
for (prop = root->properties; prop; prop = prop->next) {
xmlChar* value_ptr = xmlNodeListGetString(root->doc, prop->children, 1);
- std::string prop_value(reinterpret_cast<char*>(value_ptr));
+ std::string prop_value(reinterpret_cast<const char*>(value_ptr));
+ std::string prop_name(reinterpret_cast<const char*>(prop->name));
xmlFree(value_ptr);
+ if (constraints) {
+ if (prop_value.size() > constraints->max_attr_element_length())
+ prop_value.resize(constraints->max_attr_element_length());
+ }
+
if (IsPropSupportDir(root, prop))
prop_value = utils::GetDirTextUTF8(prop_value, current_dir);
if (IsTrimRequiredForProp(root, prop))
prop_value = utils::CollapseWhitespaceUTF8(prop_value);
- value->SetString(
- std::string(kAttributePrefix)
- + reinterpret_cast<const char*>(prop->name),
- prop_value);
+ value->SetString(std::string(kAttributePrefix) + prop_name, prop_value);
}
if (root->ns)
for (xmlNode* node = root->children; node; node = node->next) {
std::string sub_node_name(reinterpret_cast<const char*>(node->name));
std::unique_ptr<DictionaryValue> sub_value =
- LoadXMLNode(node, current_dir);
+ LoadXMLNode(node, constraints, current_dir);
if (!sub_value)
continue;
}
std::shared_ptr<Manifest> LoadManifest(const std::string& manifest_path,
- std::string* error) {
+ std::string* error, std::shared_ptr<ManifestConstraints> constraints) {
xmlDoc * doc = nullptr;
xmlNode* root_node = nullptr;
doc = xmlReadFile(manifest_path.c_str(), nullptr, XML_PARSE_NOENT);
return nullptr;
}
root_node = xmlDocGetRootElement(doc);
- std::unique_ptr<DictionaryValue> dv = LoadXMLNode(root_node);
+ std::unique_ptr<DictionaryValue> dv = LoadXMLNode(root_node, constraints);
std::unique_ptr<DictionaryValue> result(new DictionaryValue);
if (dv)
result->Set(reinterpret_cast<const char*>(root_node->name), dv.release());
// Loads an application manifest from the specified directory. Returns nullptr
// on failure, with a description of the error in |error|.
std::shared_ptr<Manifest> LoadManifest(
- const std::string& file_path, std::string* error);
+ const std::string& file_path, std::string* error,
+ std::shared_ptr<ManifestConstraints> constraints = nullptr);
std::string GetNodeDir(xmlNode* node, const std::string& inherit_dir);
std::string GetNodeText(xmlNode* root, const std::string& inherit_dir);
bool IsPropSupportDir(xmlNode* root, xmlAttr* prop);
bool IsTrimRequiredForElement(xmlNode* root);
bool IsTrimRequiredForProp(xmlNode* root, xmlAttr* prop);
std::unique_ptr<DictionaryValue> LoadXMLNode(
- xmlNode* root, const std::string& inherit_dir = "");
+ xmlNode* root, std::shared_ptr<ManifestConstraints> constraints = nullptr,
+ const std::string& inherit_dir = "");
bool ValidateTizenApplicationId(const std::string& id);
bool ValidateTizenPackageId(const std::string& id);