Source code formating unification
[platform/framework/web/wrt.git] / src / view / common / view_logic_security_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    view_logic_keys_support.cpp
18  * @author  Pawel Sikorski (p.sikorski@samsung.com)
19  * @brief   Implementation file of SecuritySupport API used by ViewLogic
20  */
21
22 #include "view_logic_security_support.h"
23 #include <string>
24 #include <dpl/string.h>
25 #include <dpl/log/log.h>
26 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28 #include <ace_api_client.h>
29 #include <dpl/utils/warp_iri.h>
30 #include <widget_data_types.h>
31
32 namespace ViewModule {
33 namespace SecuritySupport {
34 namespace {
35 const char *GEOLOCATION_DEV_CAP = "geolocation.position";
36 const char *GEOLOCATION_PARAM_NAME = "param:enableHighAccuracy";
37 const char *GEOLOCATION_PARAM_VALUE = "true";
38
39 bool simpleAceCheck(
40     const DPL::String& tizenId,
41     const char *devCap,
42     const char *paramName,
43     const char *paramValue)
44 {
45     WrtDB::WidgetDAOReadOnly dao(tizenId);
46     ace_request_t aceRequest;
47     aceRequest.widget_handle = dao.getHandle();
48     aceRequest.session_id = const_cast<const ace_string_t>("");
49     aceRequest.feature_list.count = 0;
50     aceRequest.dev_cap_list.count = 1;
51     aceRequest.dev_cap_list.items = new ace_dev_cap_t[1];
52     aceRequest.dev_cap_list.items[0].name =
53         const_cast<ace_string_t>(devCap);
54
55     aceRequest.dev_cap_list.items[0].param_list.count = paramName ? 1 : 0;
56     aceRequest.dev_cap_list.items[0].param_list.items = NULL;
57
58     if (paramName) {
59         aceRequest.dev_cap_list.items[0].param_list.items = new ace_param_t[1];
60         aceRequest.dev_cap_list.items[0].param_list.items[0].name =
61             const_cast<ace_string_t>(paramName);
62         aceRequest.dev_cap_list.items[0].param_list.items[0].value =
63             const_cast<ace_string_t>(paramValue);
64     }
65
66     LogDebug("Making ace check with new C-API");
67     ace_bool_t result = ACE_FALSE;
68     ace_return_t ret = ace_check_access(&aceRequest, &result);
69
70     LogDebug("Result is: " << static_cast<int>(result));
71
72     delete[] aceRequest.dev_cap_list.items[0].param_list.items;
73     delete[] aceRequest.dev_cap_list.items;
74
75     return ACE_OK == ret && ACE_TRUE == result;
76 }
77 } //TODO copied from view_logic.cpp
78
79 bool checkWhitelist(const char *url)
80 {
81     LogInfo("Check WhiteList");
82     // White List should be checked in only case of Tizen widget
83     if (WarpIRI::isIRISchemaIgnored(url)) {
84         // scheme is not supported by WARP
85         return true;
86     }
87
88     WidgetAccessList whiteURIList(WrtDB::GlobalDAOReadOnly::GetWhiteURIList());
89     return whiteURIList.isRequiredIRI(DPL::FromUTF8String(std::string(url)));
90 }
91
92 bool geolocationACECheck(const DPL::String& tizenId, bool highAccuracy)
93 {
94     const char *paramName = NULL;
95     const char *paramValue = NULL;
96     if (highAccuracy) {
97         paramName = GEOLOCATION_PARAM_NAME;
98         paramValue = GEOLOCATION_PARAM_VALUE;
99     }
100     return simpleAceCheck(
101                tizenId,
102                GEOLOCATION_DEV_CAP,
103                paramName,
104                paramValue);
105 }
106 } // namespace SecuritySupport
107 } //namespace ViewModule