It was replaced by tpk manifest handlers.
Change-Id: Ic9d56952b8ed4206eb659ab5ff4c08e658d008bc
step/step_parse_recovery.cc
tpk_app_query_interface.cc
tpk_installer.cc
- xml_parser/xml_parser.cc
)
ADD_LIBRARY(${TARGET_LIBNAME_TPK} STATIC ${SRCS})
ADD_EXECUTABLE(${TARGET_TPK_BACKEND} "tpk_backend.cc")
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/system/error_code.hpp>
+#include <tpk_manifest_handlers/application_manifest_constants.h>
+#include <tpk_manifest_handlers/package_handler.h>
+#include <tpk_manifest_handlers/tpk_config_parser.h>
#include <memory>
#include <string>
#include "common/request.h"
#include "common/utils/file_util.h"
#include "common/utils/logging.h"
-#include "tpk/xml_parser/xml_parser.h"
namespace bf = boost::filesystem;
namespace bs = boost::system;
namespace ci = common_installer;
-namespace xp = xml_parser;
namespace {
bf::remove_all(tmp_path, code);
return {};
}
- xp::XmlParser parser;
- std::unique_ptr<xp::XmlTree> tree(parser.ParseAndGetNewTree(
- manifest_path.c_str()));
- if (!tree) {
- bf::remove_all(tmp_path, code);
+
+ tpk::parse::TPKConfigParser parser;
+ if (!parser.ParseManifest(manifest_path))
return {};
- }
- xp::XmlElement* manifest = tree->GetRootElement();
- if (!manifest) {
- bf::remove_all(tmp_path, code);
+ auto package_info = std::static_pointer_cast<const tpk::parse::PackageInfo>(
+ parser.GetManifestData(tpk::manifest_keys::kManifestKey));
+ if (!package_info)
return {};
- }
- std::string pkg_id = manifest->attr("package");
+ std::string pkg_id = package_info->package();
bf::remove_all(tmp_path, code);
return pkg_id;
}
+++ /dev/null
-/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
-
-#include "tpk/xml_parser/xml_parser.h"
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxml/xmlstring.h>
-#include <iostream>
-#include <map>
-#include <string>
-#include <utility>
-#include <vector>
-
-using std::map;
-using std::string;
-using std::vector;
-
-namespace xml_parser {
-
-namespace { // static namespace
-
-string xmlChar2string(const xmlChar *str) {
- return string(const_cast<char*>(reinterpret_cast<const char*>(str)));
-}
-
-} // namespace
-
-
-// class XmlElement
-XmlElement::XmlElement(xmlNode *node) {
- name_ = xmlChar2string(node->name);
- xmlChar* content = xmlNodeGetContent(node); // NOTE: Needs to be freed
- content_ = xmlChar2string(content);
- xmlFree(content);
- SetAttrMap(node);
- node_ = node;
-}
-
-XmlElement::~XmlElement() {
- attr_map_.clear();
-}
-
-const string& XmlElement::attr(const string& attrName) {
- map<string, string>::iterator it = attr_map_.find(attrName);
- if (it != attr_map_.end()) {
- return it->second;
- }
- return XmlElement::null_string();
-}
-
-void XmlElement::SetAttrMap(xmlNode* node) {
- xmlAttr* attr;
-
- for (attr=node->properties; attr != nullptr; attr=attr->next) {
- const xmlChar* name = attr->name;
- xmlChar* value = xmlGetProp(node, name); // NOTE: Needs to be freed
-
- attr_map_.insert(map<string, string>::value_type(
- xmlChar2string(name), xmlChar2string(value)));
-
- xmlFree(value);
- }
-}
-
-const string& XmlElement::null_string() {
- // NOTE: check-coding-rule says that const/static string is to be changed to
- // const char[], but here we need a string object reference, instead of
- // C-style const char.
- static const string nullstr = string("");
- return nullstr;
-}
-
-
-// class XmlTree
-XmlTree::XmlTree(xmlDoc* doc) : root_(nullptr), doc_(doc) {
-}
-
-XmlTree::~XmlTree() {
- xmlFreeDoc(doc_);
-
- // Clear element_map_
- for (auto& it : elements_map_) {
- delete it.second;
- }
- elements_map_.clear();
-}
-
-void XmlTree::StoreElement(xmlNode* node, XmlElement *el) {
- elements_map_.insert(std::pair<xmlNode*, XmlElement*>(node, el));
-}
-
-XmlElement* XmlTree::FindElement(xmlNode* node) {
- map<xmlNode*, XmlElement*>::iterator it = elements_map_.find(node);
- if (it != elements_map_.end()) {
- return it->second;
- }
- return nullptr;
-}
-
-XmlElement* XmlTree::GetRootElement() {
- if (root_) return root_;
-
- xmlNode* root_node = xmlDocGetRootElement(doc_);
- if (root_node == nullptr) {
- return nullptr;
- }
-
- // Get information of the node
- XmlElement* root = new XmlElement(root_node);
- StoreElement(root_node, root);
- root_ = root;
-
- return root_;
-}
-
-vector<XmlElement*> XmlTree::Children(
- XmlElement* parent,
- const std::string& name) {
- xmlNode* child;
- XmlElement *el;
- vector<XmlElement*> children;
-
- for (child = xmlFirstElementChild(parent->node());
- nullptr != child;
- child = xmlNextElementSibling(child)) {
- if (name == xmlChar2string(child->name)) {
- // Found a matched node
- // Search map
- el = FindElement(child);
- if (!el) { // Not in elements_map_
- el = new XmlElement(child);
- StoreElement(child, el);
- }
- // Add to children
- children.push_back(el);
- }
- }
- return children;
-}
-
-
-
-// class XmlParser
-XmlParser::XmlParser() {
-}
-
-XmlParser::~XmlParser() {
- // NOTE: These libxml2 cleanup funcs must be called after all libxml2 funcs
- // are compelte.
-
- // xmlCleanupParser();
- // xmlMemoryDump();
-}
-
-XmlTree* XmlParser::ParseAndGetNewTree(const char* xmlFilePath) {
- LIBXML_TEST_VERSION
-
- XmlTree* t = nullptr;
- xmlDocPtr doc = xmlReadFile(xmlFilePath, nullptr, 0);
- if (doc) {
- t = new XmlTree(doc);
- } else {
- // TODO(youmin.ha@samsung.com): Error log
- }
- return t;
- // NOTE: doc will be freed by XmlTree.
-}
-
-} // namespace xml_parser
+++ /dev/null
-/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
-#ifndef TPK_XML_PARSER_XML_PARSER_H_
-#define TPK_XML_PARSER_XML_PARSER_H_
-
-#include <libxml/tree.h>
-#include <map>
-#include <string>
-#include <vector>
-
-namespace xml_parser {
-
-class XmlElement {
- public:
- static const std::string& null_string();
-
- explicit XmlElement(xmlNode *node);
- ~XmlElement();
- const std::string& name() { return name_; }
- const std::string& content() { return content_; }
- const std::string& attr(const std::string& attrName);
- xmlNode* node() { return node_; }
-
- private:
- void SetAttrMap(xmlNode* node);
-
- std::string name_;
- std::string content_;
- std::map<std::string, std::string> attr_map_;
- xmlNode* node_;
-};
-
-class XmlTree {
- public:
- explicit XmlTree(xmlDoc* doc);
- ~XmlTree();
-
- // Note: Each XmlElement* is available when the XmlTree object is valid.
- XmlElement* GetRootElement();
- std::vector<XmlElement*> Children(XmlElement* parent,
- const std::string& name = "");
-
- private:
- void StoreElement(xmlNode* node, XmlElement *el);
- XmlElement* FindElement(xmlNode* node);
-
- std::map<xmlNode*, XmlElement*> elements_map_;
- XmlElement* root_;
- xmlDoc* doc_;
-};
-
-
-class XmlParser {
- public:
- XmlParser();
- ~XmlParser();
- XmlTree* ParseAndGetNewTree(const char* xmlFilePath = "");
-};
-
-} // namespace xml_parser
-
-#endif // TPK_XML_PARSER_XML_PARSER_H_
SET(TESTS
signature_unittest
- xml_parser_unittest
smoke_test
)
SET(DESTINATION_DIR app-installers-ut)
ADD_EXECUTABLE(signature_unittest
signature_unittest.cc
)
-ADD_EXECUTABLE(xml_parser_unittest
- xml_parser_unittest.cc
- ../tpk/xml_parser/xml_parser.cc
-)
ADD_EXECUTABLE(smoke_test
smoke_test.cc
)
FOREACH(test ${TESTS})
APPLY_PKG_CONFIG(${test} PUBLIC
- LIBXML_DEPS
Boost
GTEST
)
# GTest main libraries is still missing, so additional linking of
# GTEST_MAIN_LIBRARIES is needed.
target_link_libraries(signature_unittest PUBLIC ${TARGET_LIBNAME_COMMON} ${GTEST_MAIN_LIBRARIES})
-target_link_libraries(xml_parser_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${GTEST_MAIN_LIBRARIES})
target_link_libraries(smoke_test PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_TPK})
FOREACH(test ${TESTS})
+++ /dev/null
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include <gtest/gtest.h>
-#include <boost/filesystem/path.hpp>
-#include <iostream>
-#include <memory>
-#include "tpk/xml_parser/xml_parser.h"
-
-namespace {
-
-using std::cout;
-using std::cerr;
-using std::endl;
-using std::unique_ptr;
-using xml_parser::XmlElement;
-using xml_parser::XmlTree;
-using xml_parser::XmlParser;
-
-namespace bf = boost::filesystem;
-
-class TestXmlParser : public testing::Test {
-};
-
-// Tests manifest parser with proper manifest
-TEST_F(TestXmlParser, ReadManifestXml) {
- const char* filename =
- "/usr/share/app-installers-ut/test_samples/tpk-sample-manifest.xml";
- XmlParser p;
-
- unique_ptr<XmlTree> t(p.ParseAndGetNewTree(filename));
- ASSERT_NE(t, nullptr);
-
- XmlElement* root = t->GetRootElement();
- ASSERT_EQ(root->name(), "manifest");
- ASSERT_EQ(root->attr("api-version"), "2.3");
-
- XmlElement* ui_application = t->Children(root, "ui-application")[0];
- ASSERT_EQ(ui_application->attr("appid"), "org.tizen.testapp");
-
- XmlElement* app_control0 = t->Children(ui_application, "app-control")[0];
- XmlElement* operation = t->Children(app_control0, "operation")[0];
- ASSERT_EQ(operation->attr("name"),
- "http://tizen.org/appcontrol/operation/edit");
-
- XmlElement* privileges = t->Children(root, "privileges")[0];
- XmlElement* privilege1 = t->Children(privileges, "privilege")[1];
- ASSERT_EQ(privilege1->content(),
- "http://tizen.org/privilege/packagemanager.info");
-
- XmlElement* feature3 = t->Children(root, "feature")[3];
- ASSERT_EQ(feature3->attr("name"),
- "http://tizen.org/feature/camera.front");
- ASSERT_EQ(feature3->content(), "true");
-
- // null_string equality test(should be true)
- ASSERT_EQ(feature3->attr("nonexist_attr"), XmlElement::null_string());
-}
-
-} // namespace