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/log/log.h>
25 #include <dpl/foreach.h>
26 #include <ace_api_install.h>
29 char* toAceString(const DPL::OptionalString& os)
32 return strdup(DPL::ToUTF8String(*os).c_str());
38 char* toAceString(const std::string& str)
41 return strdup(str.c_str());
46 } //anonymous namespace
49 bool registerAceWidget(const WrtDB::DbWidgetHandle& widgetHandle,
50 const WrtDB::WidgetRegisterInfo& widgetConfig,
51 const WrtDB::WidgetCertificateDataList& certList)
53 LogDebug("Updating Ace database");
54 struct widget_info wi;
55 DPL::OptionalString os;
57 switch (widgetConfig.webAppType.appType) {
58 case WrtDB::APP_TYPE_WAC20:
61 case WrtDB::APP_TYPE_TIZENWEBAPP:
65 LogError("Unknown application type");
69 wi.id = toAceString(widgetConfig.configInfo.widget_id);
70 wi.version = toAceString(widgetConfig.configInfo.version);
71 wi.author = toAceString(widgetConfig.configInfo.authorName);
72 wi.shareHerf = strdup(widgetConfig.shareHref.c_str());
73 LogDebug("Basic data converted. Certificates begin.");
75 //one more element for NULL termination
76 LogDebug("Found: " << certList.size() << " certificates");
77 ace_certificate_data** certData = new ace_certificate_data *
78 [certList.size() + 1];
79 certData[certList.size()] = NULL; // last element set to NULL
84 certData[i] = new ace_certificate_data;
86 case WrtDB::WidgetCertificateData::AUTHOR:
87 certData[i]->owner = AUTHOR;
89 case WrtDB::WidgetCertificateData::DISTRIBUTOR:
90 certData[i]->owner = DISTRIBUTOR;
93 LogDebug("Unknown owner type of cert");
94 certData[i]->owner = UNKNOWN;
97 case WrtDB::WidgetCertificateData::ENDENTITY:
98 certData[i]->type = ENDENTITY;
100 case WrtDB::WidgetCertificateData::ROOT:
101 certData[i]->type = ROOT;
104 LogError("Unknown type of cert");
105 certData[i]->type = ENDENTITY;
107 certData[i]->chain_id = it->chainId;
109 certData[i]->md5_fp = toAceString(it->strMD5Fingerprint);
110 certData[i]->sha1_fp = toAceString(it->strSHA1Fingerprint);
111 certData[i]->common_name =
112 toAceString(DPL::ToUTF8String(it->strCommonName));
116 LogDebug("Registerign widget in ace");
117 ace_return_t retval = ACE_ACE_UNKNOWN_ERROR;
118 retval = ace_register_widget(
119 static_cast<ace_widget_handle_t>(widgetHandle), &wi, certData);
121 //clean up - WidgetInfo
129 while (certData[i] != NULL) {
130 free(certData[i]->common_name);
131 free(certData[i]->md5_fp);
132 free(certData[i]->sha1_fp);
137 return retval == ACE_OK;