[Widget-manifest-parser] Remove LocalManifestData
[platform/core/appfw/app-installers.git] / src / wgt / step / step_parse.cc
1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2
3 #include "wgt/step/step_parse.h"
4
5 #include <string.h>
6
7 #include <pkgmgr/pkgmgr_parser.h>
8
9 #include <cstdio>
10 #include <cstdlib>
11 #include <string>
12
13 #include "common/app_installer.h"
14 #include "common/context_installer.h"
15 #include "common/step/step.h"
16
17 namespace wgt {
18 namespace parse {
19
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;
24   }
25
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;
33   }
34
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));
40   context_->set_pkgid(
41       std::string(data->package));
42   fillManifest(data, context_->manifest_data());
43
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];
55   LOG(DEBUG) << "  ]-";
56   LOG(DEBUG) << "]-";
57
58   if (!ReleaseData(data, error)) {
59     LOG(ERROR) << "Release data failed.";
60     return common_installer::Step::Status::ERROR;
61   }
62
63   return common_installer::Step::Status::OK;
64 }
65
66 bool StepParse::Check(const boost::filesystem::path& widget_path) {
67   boost::filesystem::path config = widget_path;
68   config /= "config.xml";
69
70   LOG(DEBUG) << "config.xml path: " << config;
71
72   if (!boost::filesystem::exists(config))
73     return false;
74
75   config_ = config;
76   return true;
77 }
78
79 void StepParse::fillManifest(const ManifestData* data, manifest_x* manifest) {
80   // package data
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;
89
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);
96
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);
102   }
103   // application data
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;
114
115   manifest->uiapplication->appid = strdup(data->id);
116   manifest->uiapplication->type = strdup("webapp");
117
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);
121   else
122     manifest->uiapplication->label->name = strdup(data->name);
123
124   manifest->uiapplication->icon->name = strdup(data->icon);
125   manifest->uiapplication->next = nullptr;
126
127   // context->manifest_data()->?? = strdup (data->api_version);
128 }
129
130
131 }  // namespace parse
132 }  // namespace wgt