2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file ace_registration.cpp
18 * @author Andrzej Surdej (a.surdej@gmail.com)
20 * @brief Translate structures to ace api - implementation file
23 #include <ace_registration.h>
24 #include <dpl/foreach.h>
25 #include <ace_api_install.h>
27 #include <installer_log.h>
30 char* toAceString(const DPL::OptionalString& os)
33 return strdup(DPL::ToUTF8String(*os).c_str());
39 char* toAceString(const std::string& str)
42 return strdup(str.c_str());
47 } //anonymous namespace
50 bool registerAceWidget(const WrtDB::DbWidgetHandle& widgetHandle,
51 const WrtDB::WidgetRegisterInfo& widgetConfig,
52 const WrtDB::WidgetCertificateDataList& certList)
54 _D("Updating Ace database");
55 struct widget_info wi;
57 switch (widgetConfig.webAppType.appType) {
58 case WrtDB::APP_TYPE_TIZENWEBAPP:
62 _E("Unknown application type");
66 wi.id = toAceString(widgetConfig.configInfo.widget_id);
67 wi.version = toAceString(widgetConfig.configInfo.version);
68 wi.author = toAceString(widgetConfig.configInfo.authorName);
69 wi.shareHerf = strdup(widgetConfig.shareHref.c_str());
70 _D("Basic data converted. Certificates begin.");
72 //one more element for NULL termination
73 _D("Found: %d certificates", certList.size());
74 ace_certificate_data** certData = new ace_certificate_data *
75 [certList.size() + 1];
76 certData[certList.size()] = NULL; // last element set to NULL
81 certData[i] = new ace_certificate_data;
83 case WrtDB::WidgetCertificateData::AUTHOR:
84 certData[i]->owner = AUTHOR;
86 case WrtDB::WidgetCertificateData::DISTRIBUTOR:
87 certData[i]->owner = DISTRIBUTOR;
90 _D("Unknown owner type of cert");
91 certData[i]->owner = UNKNOWN;
95 case WrtDB::WidgetCertificateData::ENDENTITY:
96 certData[i]->type = ENDENTITY;
98 case WrtDB::WidgetCertificateData::ROOT:
99 certData[i]->type = ROOT;
102 _E("Unknown type of cert");
103 certData[i]->type = ENDENTITY;
106 certData[i]->chain_id = it->chainId;
108 certData[i]->md5_fp = toAceString(it->strMD5Fingerprint);
109 certData[i]->sha1_fp = toAceString(it->strSHA1Fingerprint);
110 certData[i]->common_name =
111 toAceString(DPL::ToUTF8String(it->strCommonName));
115 _D("Registerign widget in ace");
116 ace_return_t retval = ace_register_widget(
117 static_cast<ace_widget_handle_t>(widgetHandle), &wi, certData);
119 //clean up - WidgetInfo
127 while (certData[i] != NULL) {
128 free(certData[i]->common_name);
129 free(certData[i]->md5_fp);
130 free(certData[i]->sha1_fp);
135 return retval == ACE_OK;
137 bool registerAceWidgetFromDB(const WrtDB::DbWidgetHandle& widgetHandle)
139 using namespace WrtDB;
140 _D("Updating Ace database from Widget DB");
141 struct widget_info wi;
142 DPL::OptionalString os;
143 WrtDB::WidgetCertificateDataList certList;
146 WidgetDAOReadOnly dao(widgetHandle);
148 WidgetType type = dao.getWidgetType();
149 if (type == WrtDB::APP_TYPE_TIZENWEBAPP) {
152 _E("Unknown application type");
156 wi.id = toAceString(dao.getGUID());
157 wi.version = toAceString(dao.getVersion());
158 wi.author = toAceString(dao.getAuthorName());
159 wi.shareHerf = strdup(dao.getShareHref().c_str());
160 _D("Basic data converted. Certificates begin.");
161 certList = dao.getCertificateDataList();
163 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
164 _E("Widget does not exist");
168 //one more element for NULL termination
169 _D("Found: %d certificates", certList.size());
170 ace_certificate_data** certData = new ace_certificate_data *
171 [certList.size() + 1];
172 certData[certList.size()] = NULL; // last element set to NULL
175 FOREACH(it, certList)
177 certData[i] = new ace_certificate_data;
179 case WrtDB::WidgetCertificateData::AUTHOR:
180 certData[i]->owner = AUTHOR;
182 case WrtDB::WidgetCertificateData::DISTRIBUTOR:
183 certData[i]->owner = DISTRIBUTOR;
186 _D("Unknown owner type of cert");
187 certData[i]->owner = UNKNOWN;
191 case WrtDB::WidgetCertificateData::ENDENTITY:
192 certData[i]->type = ENDENTITY;
194 case WrtDB::WidgetCertificateData::ROOT:
195 certData[i]->type = ROOT;
198 _E("Unknown type of cert");
199 certData[i]->type = ENDENTITY;
202 certData[i]->chain_id = it->chainId;
204 certData[i]->md5_fp = toAceString(it->strMD5Fingerprint);
205 certData[i]->sha1_fp = toAceString(it->strSHA1Fingerprint);
206 certData[i]->common_name =
207 toAceString(DPL::ToUTF8String(it->strCommonName));
211 _D("Registerign widget in ace");
212 ace_return_t retval = ace_register_widget(
213 static_cast<ace_widget_handle_t>(widgetHandle), &wi, certData);
215 //clean up - WidgetInfo
223 while (certData[i] != NULL) {
224 free(certData[i]->common_name);
225 free(certData[i]->md5_fp);
226 free(certData[i]->sha1_fp);
231 return retval == ACE_OK;