1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
3 #include "wgt/step/step_parse.h"
7 #include <pkgmgr/pkgmgr_parser.h>
13 #include "common/app_installer.h"
14 #include "common/context_installer.h"
15 #include "common/step/step.h"
20 common_installer::Step::Status StepParse::process() {
21 if (!StepParse::Check(context_->unpacked_dir_path())) {
22 LOG(ERROR) << "No config.xml";
23 return common_installer::Step::Status::ERROR;
26 const ManifestData* data = nullptr;
27 const char* error = nullptr;
28 if (!ParseManifest(config_.c_str(), &data, &error)) {
29 LOG(ERROR) << "Parse failed. " << error;
30 if (!ReleaseData(data, error))
31 LOG(ERROR) << " Release data failed.";
32 return common_installer::Step::Status::ERROR;
35 // Copy data from ManifestData to ContextInstaller
36 context_->config_data()->set_application_name(
37 std::string(data->name));
38 context_->config_data()->set_required_version(
39 std::string(data->api_version));
41 std::string(data->package));
42 fillManifest(data, context_->manifest_data());
44 LOG(DEBUG) << " Read data -[ ";
45 LOG(DEBUG) << " package = " << data->package;
46 LOG(DEBUG) << " id = " << data->id;
47 LOG(DEBUG) << " name = " << data->name;
48 LOG(DEBUG) << " short_name = " << data->short_name;
49 LOG(DEBUG) << " version = " << data->version;
50 LOG(DEBUG) << " icon = " << data->icon;
51 LOG(DEBUG) << " api_version = " << data->api_version;
52 LOG(DEBUG) << " privileges -[";
53 for (unsigned int i = 0; i < data->privilege_count; ++i)
54 LOG(DEBUG) << " " << data->privilege_list[i];
58 if (!ReleaseData(data, error)) {
59 LOG(ERROR) << "Release data failed.";
60 return common_installer::Step::Status::ERROR;
63 return common_installer::Step::Status::OK;
66 bool StepParse::Check(const boost::filesystem::path& widget_path) {
67 boost::filesystem::path config = widget_path;
68 config /= "config.xml";
70 LOG(DEBUG) << "config.xml path: " << config;
72 if (!boost::filesystem::exists(config))
79 void StepParse::fillManifest(const ManifestData* data, manifest_x* manifest) {
81 manifest->label = reinterpret_cast<label_x*>
82 (calloc(1, sizeof(label_x)));
83 manifest->description = reinterpret_cast<description_x*>
84 (calloc(1, sizeof(description_x)));
85 manifest->privileges = reinterpret_cast<privileges_x*>
86 (calloc(1, sizeof(privileges_x)));
87 manifest->privileges->next = nullptr;
88 manifest->privileges->privilege = nullptr;
90 manifest->package = strdup(data->package);
91 manifest->type = strdup("wgt");
92 manifest->version = strdup(data->version);
93 manifest->label->name = strdup(data->name);
94 manifest->description->name = nullptr;
95 manifest->mainapp_id = strdup(data->id);
97 for (unsigned int i = 0; i < data->privilege_count; i++) {
98 privilege_x *privilege = reinterpret_cast<privilege_x*>(
99 malloc(sizeof(privilege_x)));
100 privilege->text = strdup(data->privilege_list[i]);
101 LISTADD(manifest->privileges->privilege, privilege);
104 manifest->serviceapplication = nullptr;
105 manifest->uiapplication = reinterpret_cast<uiapplication_x*>
106 (calloc (1, sizeof(uiapplication_x)));
107 manifest->uiapplication->icon = reinterpret_cast<icon_x*>
108 (calloc(1, sizeof(icon_x)));
109 manifest->uiapplication->label = reinterpret_cast<label_x*>
110 (calloc(1, sizeof(label_x)));
111 manifest->description = reinterpret_cast<description_x*>
112 (calloc(1, sizeof(description_x)));
113 manifest->uiapplication->appcontrol = nullptr;
115 manifest->uiapplication->appid = strdup(data->id);
116 manifest->uiapplication->type = strdup("webapp");
118 // For wgt package use the long name if the short name is emty
119 if ( ( data->short_name ) && ( strlen(data->short_name) ) )
120 manifest->uiapplication->label->name = strdup(data->short_name);
122 manifest->uiapplication->label->name = strdup(data->name);
124 manifest->uiapplication->icon->name = strdup(data->icon);
125 manifest->uiapplication->next = nullptr;
127 // context->manifest_data()->?? = strdup (data->api_version);