Fix style
[platform/core/appfw/wgt-backend.git] / src / wgt / step / security / step_check_wgt_ime_privilege.cc
1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include <wgt/step/security/step_check_wgt_ime_privilege.h>
6 #include <wgt/step/common/privileges.h>
7
8 #include <manifest_parser/utils/version_number.h>
9 #include <manifest_parser/utils/logging.h>
10
11 #include <common/utils/glist_range.h>
12
13 #include <string>
14
15 namespace {
16 const char kImeCategoryName[] = "http://tizen.org/category/ime";
17 }
18
19 namespace wgt {
20 namespace security {
21
22 common_installer::Step::Status StepCheckWgtImePrivilege::process() {
23   utils::VersionNumber apiVersion(context_->manifest_data.get()->api_version);
24
25   const auto version23 = apiVersion < utils::VersionNumber("2.4");
26   auto has_ime = false;
27
28   for (const auto app :
29       GListRange<application_x*>(context_->manifest_data.get()->application)) {
30     for (const auto category : GListRange<char *>(app->category)) {
31       if (!strcmp(category, kImeCategoryName)) {
32         has_ime = true;
33
34         const auto result = version23 ? Check23Api() : Check24Api();
35         if (result != Status::OK) {
36           LOG(ERROR) << "Insufficient privileges for IME application.";
37           return result;
38         }
39
40         break;
41       }
42     }
43   }
44
45   if (!has_ime) {
46     // be sure no ime data is present without the category
47     context_->manifest_plugins_data.get().ime_info.get().setUuid(std::string());
48   } else if (version23) {
49     // be sure there's a privilege in manifest
50     context_->manifest_data.get()->privileges
51         = g_list_append(context_->manifest_data.get()->privileges,
52                         strdup(common::privileges::kImePrivilegeName));
53   }
54
55   return Status::OK;
56 }
57
58 common_installer::Step::Status StepCheckWgtImePrivilege::Check23Api() const {
59   const auto &ime = context_->manifest_plugins_data.get().ime_info.get();
60   if (ime.uuid().empty()) {
61     LOG(ERROR) << "Missing IME tag.";
62     return Status::CONFIG_ERROR;
63   }
64
65   // ime priv not supported in 2.3
66   return CheckImePrivilege() != Status::OK ?
67       Status::OK : Status::PRIVILEGE_ERROR;
68 }
69
70 common_installer::Step::Status StepCheckWgtImePrivilege::Check24Api() const {
71   return CheckImePrivilege();
72 }
73
74 common_installer::Step::Status
75 StepCheckWgtImePrivilege::CheckImePrivilege() const {
76   for (const auto privilege :
77       GListRange<char *>(context_->manifest_data.get()->privileges)) {
78     if (!strcmp(privilege, common::privileges::kImePrivilegeName))
79       return Status::OK;
80   }
81
82   LOG(DEBUG) << "Missing IME privilege.";
83   return Status::PRIVILEGE_ERROR;
84 }
85 }  // namespace security
86 }  // namespace wgt