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>
30 char* toAceString(const DPL::OptionalString& os)
33 return strdup(DPL::ToUTF8String(*os).c_str());
38 char* toAceString(const std::string& str)
41 return strdup(str.c_str());
46 } //anonymous namespace
50 bool registerAceWidget(const WrtDB::DbWidgetHandle& widgetHandle,
51 const WrtDB::WidgetRegisterInfo& widgetConfig,
52 const WrtDB::WidgetCertificateDataList& certList)
54 LogDebug("Updating Ace database");
55 struct widget_info wi;
56 DPL::OptionalString os;
58 switch(widgetConfig.webAppType.appType)
60 case WrtDB::APP_TYPE_WAC20:
63 case WrtDB::APP_TYPE_TIZENWEBAPP:
67 LogError("Unknown application type");
71 wi.id = toAceString(widgetConfig.configInfo.widget_id);
72 wi.version = toAceString(widgetConfig.configInfo.version);
73 wi.author = toAceString(widgetConfig.configInfo.authorName);
74 wi.shareHerf = strdup(widgetConfig.shareHref.c_str());
75 LogDebug("Basic data converted. Certificates begin.");
77 //one more element for NULL termination
78 LogDebug("Found: " << certList.size() << " certificates");
79 ace_certificate_data** certData = new ace_certificate_data*[certList.size() + 1];
80 certData[certList.size()] = NULL; // last element set to NULL
85 certData[i] = new ace_certificate_data;
87 case WrtDB::WidgetCertificateData::AUTHOR :
88 certData[i]->owner = AUTHOR;
90 case WrtDB::WidgetCertificateData::DISTRIBUTOR :
91 certData[i]->owner = DISTRIBUTOR;
94 LogDebug("Unknown owner type of cert");
95 certData[i]->owner = UNKNOWN;
98 case WrtDB::WidgetCertificateData::ENDENTITY :
99 certData[i]->type = ENDENTITY;
101 case WrtDB::WidgetCertificateData::ROOT :
102 certData[i]->type = ROOT;
105 LogError("Unknown type of cert");
106 certData[i]->type = ENDENTITY;
108 certData[i]->chain_id = it->chainId;
110 certData[i]->md5_fp = toAceString(it->strMD5Fingerprint);
111 certData[i]->sha1_fp = toAceString(it->strSHA1Fingerprint);
112 certData[i]->common_name = 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;