ac99419deceb7a24355120f5129dd08a2eabbd04
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_widget_config.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    task_widget_config.cpp
18  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for installer task widget config
21  */
22
23 #include <map>
24 #include <sstream>
25 #include <string>
26 #include <sys/stat.h>
27 #include <dirent.h>
28
29 #include <dpl/errno_string.h>
30 #include <dpl/foreach.h>
31 #include <dpl/localization/w3c_file_localization.h>
32 #include <dpl/singleton_impl.h>
33 #include <dpl/utils/mime_type_utils.h>
34 #include <dpl/utils/wrt_global_settings.h>
35 #include <dpl/utils/wrt_utility.h>
36 #include <dpl/wrt-dao-ro/global_config.h>
37 #include <dpl/wrt-dao-rw/feature_dao.h>
38
39 #include <libiriwrapper.h>
40 #include <parser_runner.h>
41 #include <root_parser.h>
42
43 #include <widget_install/job_widget_install.h>
44 #include <widget_install/task_widget_config.h>
45 #include <widget_install/widget_install_context.h>
46 #include <widget_install/widget_install_errors.h>
47 #include <widget_parser.h>
48
49 namespace { // anonymous
50 const DPL::String BR = DPL::FromUTF8String("<br>");
51 const std::string WIDGET_NOT_COMPATIBLE = "This widget is "
52                                           "not compatible with WRT.<br><br>";
53 const std::string QUESTION = "Do you want to install it anyway?";
54
55 const char *const DEFAULT_LANGUAGE = "default";
56
57 const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml";
58
59 const std::string WINDGET_INSTALL_NETWORK_ACCESS = "network access";
60 }
61
62 namespace Jobs {
63 namespace WidgetInstall {
64 void InstallerTaskWidgetPopupData::PopupData::addWidgetInfo(
65     const DPL::String &info)
66 {
67     widgetInfo = info;
68 }
69
70 TaskWidgetConfig::TaskWidgetConfig(InstallerContext& installContext) :
71     DPL::TaskDecl<TaskWidgetConfig>(this),
72     m_installContext(installContext)
73 {
74     AddStep(&TaskWidgetConfig::StepProcessConfigurationFile);
75     AddStep(&TaskWidgetConfig::ReadLocaleFolders);
76     AddStep(&TaskWidgetConfig::ProcessLocalizedStartFiles);
77     AddStep(&TaskWidgetConfig::ProcessBackgroundPageFile);
78     AddStep(&TaskWidgetConfig::ProcessLocalizedIcons);
79     AddStep(&TaskWidgetConfig::ProcessWidgetInstalledPath);
80     AddStep(&TaskWidgetConfig::ProcessAppControlInfo);
81     AddStep(&TaskWidgetConfig::StepVerifyFeatures);
82     AddStep(&TaskWidgetConfig::StepCheckMinVersionInfo);
83 }
84
85 void TaskWidgetConfig::StepProcessConfigurationFile()
86 {
87     Try
88     {
89         std::string path = m_installContext.locations->getConfigurationDir();
90         LogInfo("path: " << path);
91
92         processFile(path, m_installContext.widgetConfig);
93     }
94     Catch(Exception::ConfigParseFailed)
95     {
96         LogError("Parsing failed.");
97         ReThrow(Exceptions::WidgetConfigFileInvalid);
98     }
99
100     m_installContext.job->UpdateProgress(
101         InstallerContext::INSTALL_WIDGET_CONFIG1,
102         "Parse elements of configuration file and save them");
103 }
104
105 void TaskWidgetConfig::ReadLocaleFolders()
106 {
107     LogDebug("Reading locale");
108     //Adding default locale
109     m_localeFolders.insert(L"");
110
111     std::string localePath =
112         m_installContext.locations->getConfigurationDir() + "/locales";
113     DIR* localeDir = opendir(localePath.c_str());
114     if (!localeDir) {
115         LogDebug("No /locales directory in the widget package.");
116         return;
117     }
118
119
120
121     struct stat statStruct;
122     struct dirent dirent;
123     struct dirent *result;
124     int return_code;
125     errno = 0;
126     for (return_code = readdir_r(localeDir, &dirent, &result);
127             result != NULL && return_code == 0;
128             return_code = readdir_r(localeDir, &dirent, &result))
129     {
130         DPL::String dirName = DPL::FromUTF8String(dirent.d_name);
131         std::string absoluteDirName = localePath + "/";
132         absoluteDirName += dirent.d_name;
133
134         if (stat(absoluteDirName.c_str(), &statStruct) != 0) {
135             LogError("stat() failed with " << DPL::GetErrnoString());
136             continue;
137         }
138
139         if (S_ISDIR(statStruct.st_mode)) {
140             //Yes, we ignore current, parent & hidden directories
141             if (dirName[0] != L'.') {
142                 LogDebug("Adding locale directory \"" << dirName << "\"");
143                 m_localeFolders.insert(dirName);
144             }
145         }
146     }
147
148     if (return_code != 0 || errno != 0) {
149         LogError("readdir_r() failed with " << DPL::GetErrnoString());
150     }
151
152     if (-1 == TEMP_FAILURE_RETRY(closedir(localeDir))) {
153         LogError("Failed to close dir: " << localePath << " with error: "
154                                          << DPL::GetErrnoString());
155     }
156 }
157
158 void TaskWidgetConfig::ProcessLocalizedStartFiles()
159 {
160     typedef DPL::String S;
161     ProcessStartFile(
162         m_installContext.widgetConfig.configInfo.startFile,
163         m_installContext.widgetConfig.configInfo.
164             startFileContentType,
165         m_installContext.widgetConfig.configInfo.startFileEncoding,
166         true);
167     ProcessStartFile(S(L"index.htm"), S(L"text/html"));
168     ProcessStartFile(S(L"index.html"), S(L"text/html"));
169     ProcessStartFile(S(L"index.svg"), S(L"image/svg+xml"));
170     ProcessStartFile(S(L"index.xhtml"), S(L"application/xhtml+xml"));
171     ProcessStartFile(S(L"index.xht"), S(L"application/xhtml+xml"));
172     // TODO: we need better check if in current locales widget is valid
173     FOREACH(it, m_installContext.widgetConfig.localizationData.startFiles) {
174         if (it->propertiesForLocales.size() > 0) {
175             return;
176         }
177     }
178     ThrowMsg(Exceptions::WidgetConfigFileInvalid,
179              L"The Widget has no valid start file");
180 }
181
182 void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path,
183                                         const DPL::OptionalString& type,
184                                         const DPL::OptionalString& encoding,
185                                         bool typeForcedInConfig)
186 {
187     using namespace WrtDB;
188
189     if (!!path) {
190         WidgetRegisterInfo::LocalizedStartFile startFileData;
191         startFileData.path = *path;
192
193         FOREACH(i, m_localeFolders) {
194             DPL::String pathPrefix = *i;
195             if (!pathPrefix.empty()) {
196                 pathPrefix = L"locales/" + pathPrefix + L"/";
197             }
198
199             DPL::String relativePath = pathPrefix + *path;
200             DPL::String absolutePath = DPL::FromUTF8String(
201                     m_installContext.locations->getConfigurationDir()) + L"/" +
202                 relativePath;
203
204             // get property data from packaged app
205             if (WrtUtilFileExists(DPL::ToUTF8String(absolutePath))) {
206                 WidgetRegisterInfo::StartFileProperties startFileProperties;
207                 if (!!type) {
208                     startFileProperties.type = *type;
209                 } else {
210                     startFileProperties.type =
211                         MimeTypeUtils::identifyFileMimeType(absolutePath);
212                 }
213
214                 //proceed only if MIME type is supported
215                 if (MimeTypeUtils::isMimeTypeSupportedForStartFile(
216                         startFileProperties.type))
217                 {
218                     if (!!encoding) {
219                         startFileProperties.encoding = *encoding;
220                     } else {
221                         MimeTypeUtils::MimeAttributes attributes =
222                             MimeTypeUtils::getMimeAttributes(
223                                 startFileProperties.type);
224                         if (attributes.count(L"charset") > 0) {
225                             startFileProperties.encoding =
226                                 attributes[L"charset"];
227                         } else {
228                             startFileProperties.encoding = L"UTF-8";
229                         }
230                     }
231
232                     startFileData.propertiesForLocales[*i] =
233                         startFileProperties;
234                 } else {
235                     //9.1.16.5.content.8
236                     //(there seems to be no similar requirement in .6,
237                     //so let's throw only when mime type is
238                     // provided explcitly in config.xml)
239                     if (typeForcedInConfig) {
240                         ThrowMsg(Exceptions::WidgetConfigFileInvalid,
241                                  "Unsupported MIME type for start file.");
242                     }
243                 }
244             } else {
245                 // set property data for hosted start url
246                 // Hosted start url only support TIZEN WebApp
247                 if (m_installContext.widgetConfig.webAppType ==
248                     APP_TYPE_TIZENWEBAPP)
249                 {
250                     std::string startPath = DPL::ToUTF8String(
251                             startFileData.path);
252
253                     if (strstr(startPath.c_str(),
254                                "http") == startPath.c_str())
255                     {
256                         WidgetRegisterInfo::StartFileProperties
257                             startFileProperties;
258                         if (!!type) {
259                             startFileProperties.type = *type;
260                         }
261                         if (!!encoding) {
262                             startFileProperties.encoding = *encoding;
263                         }
264                         startFileData.propertiesForLocales[*i] =
265                             startFileProperties;
266                     }
267                 }
268             }
269         }
270
271         m_installContext.widgetConfig.localizationData.startFiles.push_back(
272             startFileData);
273     }
274 }
275
276 void TaskWidgetConfig::ProcessBackgroundPageFile()
277 {
278     if (!!m_installContext.widgetConfig.configInfo.backgroundPage) {
279         // check whether file exists
280         DPL::String backgroundPagePath = DPL::FromUTF8String(
281                 m_installContext.locations->getConfigurationDir()) + L"/" +
282             *m_installContext.widgetConfig.configInfo.backgroundPage;
283         //if no then cancel installation
284         if (!WrtUtilFileExists(DPL::ToUTF8String(backgroundPagePath))) {
285             ThrowMsg(Exceptions::WidgetConfigFileInvalid,
286                      L"Given background page file not found in archive");
287         }
288     }
289 }
290
291 void TaskWidgetConfig::ProcessLocalizedIcons()
292 {
293     using namespace WrtDB;
294     ProcessIcon(ConfigParserData::Icon(L"icon.svg"));
295     ProcessIcon(ConfigParserData::Icon(L"icon.ico"));
296     ProcessIcon(ConfigParserData::Icon(L"icon.png"));
297     ProcessIcon(ConfigParserData::Icon(L"icon.gif"));
298     ProcessIcon(ConfigParserData::Icon(L"icon.jpg"));
299
300     FOREACH(i, m_installContext.widgetConfig.configInfo.iconsList)
301     {
302         ProcessIcon(*i);
303     }
304 }
305
306 void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
307 {
308     LogInfo("enter");
309     bool isAnyIconValid = false;
310     //In case a default filename is passed as custom filename in config.xml, we
311     //need to keep a set of already processed filenames to avoid icon
312     // duplication
313     //in database.
314
315     using namespace WrtDB;
316
317     if (m_processedIconSet.count(icon.src) > 0) {
318         return;
319     }
320     m_processedIconSet.insert(icon.src);
321
322     LocaleSet localesAvailableForIcon;
323
324     FOREACH(i, m_localeFolders)
325     {
326         DPL::String pathPrefix = *i;
327         if (!pathPrefix.empty()) {
328             pathPrefix = L"locales/" + pathPrefix + L"/";
329         }
330
331         DPL::String relativePath = pathPrefix + icon.src;
332         DPL::String absolutePath = DPL::FromUTF8String(
333                 m_installContext.locations->getConfigurationDir()) + L"/" +
334             relativePath;
335
336         if (WrtUtilFileExists(DPL::ToUTF8String(absolutePath))) {
337             DPL::String type = MimeTypeUtils::identifyFileMimeType(absolutePath);
338
339             if (MimeTypeUtils::isMimeTypeSupportedForIcon(type)) {
340                 isAnyIconValid = true;
341                 localesAvailableForIcon.insert(*i);
342                 LogInfo("Icon absolutePath :" << absolutePath <<
343                         ", assigned locale :" << *i << ", type: " << type);
344             }
345         }
346     }
347
348     if (isAnyIconValid) {
349         WidgetRegisterInfo::LocalizedIcon localizedIcon(icon,
350                                                         localesAvailableForIcon);
351         m_installContext.widgetConfig.localizationData.icons.push_back(
352             localizedIcon);
353     }
354 }
355
356 void TaskWidgetConfig::ProcessWidgetInstalledPath()
357 {
358     LogDebug("ProcessWidgetInstalledPath");
359     m_installContext.widgetConfig.widgetInstalledPath =
360         DPL::FromUTF8String(
361             m_installContext.locations->getPackageInstallationDir());
362 }
363
364 void TaskWidgetConfig::ProcessAppControlInfo()
365 {
366     LogDebug("ProcessAppControlInfo");
367     using namespace WrtDB;
368
369     WrtDB::ConfigParserData::AppControlInfo::Disposition disposition =
370         WrtDB::ConfigParserData::AppControlInfo::Disposition::WINDOW;
371     FOREACH(it, m_installContext.widgetConfig.configInfo.settingsList) {
372         if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), "nodisplay") &&
373             !strcmp(DPL::ToUTF8String(it->m_value).c_str(), "true"))
374         {
375             disposition =
376                 WrtDB::ConfigParserData::AppControlInfo::Disposition::INLINE;
377         }
378     }
379
380     std::map<std::string, int> srcMap;
381     int index = 0;
382     // index = 0 is reserved for start file
383     FOREACH(startFileIt, m_installContext.widgetConfig.localizationData.startFiles)
384     {
385         if (!startFileIt->propertiesForLocales.empty()) {
386             std::string src = DPL::ToUTF8String(startFileIt->path);
387              if (srcMap.find(src) == srcMap.end()) {
388                 LogDebug("Insert [" << src << "," << index << "]");
389                 srcMap.insert(std::pair<std::string, int>(src, index++));
390             }
391         }
392     }
393
394     FOREACH(appControlIt, m_installContext.widgetConfig.configInfo.appControlList)
395     {
396         appControlIt->m_disposition = disposition;
397         std::string src = DPL::ToUTF8String(appControlIt->m_src);
398         LogDebug("src = [" << src << "]");
399         std::map<std::string, int>::iterator findIt = srcMap.find(src);
400         if (findIt == srcMap.end()) {
401             LogDebug("Insert [" << src << "," << index << "]");
402             srcMap.insert(std::pair<std::string, int>(src, index));
403             appControlIt->m_index = index++;
404         } else {
405             LogDebug("Exist  [" << src << "," << findIt->second << "]");
406             appControlIt->m_index = findIt->second;
407         }
408     }
409 }
410
411 void TaskWidgetConfig::StepCheckMinVersionInfo()
412 {
413     if (!isMinVersionCompatible(
414             m_installContext.widgetConfig.webAppType.appType,
415             m_installContext.widgetConfig.minVersion))
416     {
417         LogError(
418             "Platform version lower than required -> cancelling installation");
419         ThrowMsg(Exceptions::NotAllowed,
420                  "Platform version does not meet requirements");
421     }
422
423     m_installContext.job->UpdateProgress(
424         InstallerContext::INSTALL_WIDGET_CONFIG2,
425         "Check MinVersion Finished");
426 }
427
428 void TaskWidgetConfig::StepVerifyFeatures()
429 {
430     using namespace WrtDB;
431     ConfigParserData &data = m_installContext.widgetConfig.configInfo;
432     ConfigParserData::FeaturesList list = data.featuresList;
433     ConfigParserData::FeaturesList newList;
434
435     //in case of tests, this variable is unused
436     std::string featureInfo;
437     FOREACH(it, list)
438     {
439         // check feature vender for permission
440         // WAC, TIZEN WebApp cannot use other feature
441
442         if (!isFeatureAllowed(m_installContext.widgetConfig.webAppType.appType,
443                               it->name))
444         {
445             LogInfo("This application type not allowed to use this feature");
446             ThrowMsg(
447                 Exceptions::WidgetConfigFileInvalid,
448                 "This app type [" <<
449                 m_installContext.widgetConfig.webAppType.getApptypeToString()
450                                   <<
451                 "] cannot be allowed to use [" <<
452                 DPL::ToUTF8String(it->name) + "] feature");
453         } else {
454             newList.insert(*it);
455             featureInfo += DPL::ToUTF8String(it->name);
456             featureInfo += DPL::ToUTF8String(BR);
457         }
458     }
459     if (!data.accessInfoSet.empty()) {
460         featureInfo += WINDGET_INSTALL_NETWORK_ACCESS;
461         featureInfo += DPL::ToUTF8String(BR);
462     }
463     data.featuresList = newList;
464     if (!featureInfo.empty()) {
465         m_popupData.addWidgetInfo(DPL::FromUTF8String(featureInfo));
466     }
467
468     m_installContext.job->UpdateProgress(
469         InstallerContext::INSTALL_WIDGET_CONFIG2,
470         "Widget Config step2 Finished");
471 }
472
473 bool TaskWidgetConfig::isFeatureAllowed(WrtDB::AppType appType,
474                                         DPL::String featureName)
475 {
476     using namespace WrtDB;
477     LogInfo("AppType = [" <<
478             WidgetType(appType).getApptypeToString() << "]");
479     LogInfo("FetureName = [" << featureName << "]");
480
481     AppType featureType = APP_TYPE_UNKNOWN;
482     std::string featureStr = DPL::ToUTF8String(featureName);
483     const char* feature = featureStr.c_str();
484
485     // check prefix of  feature name
486     if (strstr(feature, PluginsPrefix::TIZENPluginsPrefix) == feature) {
487         // Tizen WebApp feature
488         featureType = APP_TYPE_TIZENWEBAPP;
489     } else if (strstr(feature, PluginsPrefix::WACPluginsPrefix) == feature) {
490         // WAC 2.0 feature
491         featureType = APP_TYPE_WAC20;
492     } else if (strstr(feature, PluginsPrefix::W3CPluginsPrefix) == feature) {
493         // W3C standard feature
494         // Both WAC and TIZEN WebApp are possible to use W3C plugins
495         return true;
496     } else {
497         // unknown feature
498         // unknown feature will be checked next step
499         return true;
500     }
501
502     if (appType == featureType) {
503         return true;
504     }
505     return false;
506 }
507
508 bool TaskWidgetConfig::parseVersionString(const std::string &version,
509                                           long &majorVersion,
510                                           long &minorVersion,
511                                           long &microVersion) const
512 {
513     std::istringstream inputString(version);
514     inputString >> majorVersion;
515     if (inputString.bad() || inputString.fail()) {
516         LogWarning("Invalid minVersion format.");
517         return false;
518     }
519     inputString.get(); // skip period
520     inputString >> minorVersion;
521     if (inputString.bad() || inputString.fail()) {
522         LogWarning("Invalid minVersion format");
523         return false;
524     } else {
525         inputString.get(); // skip period
526         if (inputString.bad() || inputString.fail()) {
527             inputString >> microVersion;
528         }
529     }
530     return true;
531 }
532
533 bool TaskWidgetConfig::isMinVersionCompatible(
534     WrtDB::AppType appType,
535     const DPL::OptionalString &
536     widgetVersion) const
537 {
538     if (widgetVersion.IsNull() || (*widgetVersion).empty()) {
539         if (appType == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) {
540             return false;
541         } else {
542             LogWarning("minVersion attribute is empty. WRT assumes platform "
543                     "supports this widget.");
544             return true;
545         }
546     }
547
548     //Parse widget version
549     long majorWidget = 0, minorWidget = 0, microWidget = 0;
550     if (!parseVersionString(DPL::ToUTF8String(*widgetVersion), majorWidget,
551                             minorWidget, microWidget))
552     {
553         LogWarning("Invalid format of widget version string.");
554         return false;
555     }
556
557     //Parse supported version
558     long majorSupported = 0, minorSupported = 0, microSupported = 0;
559     std::string version;
560     if (appType == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) {
561         version = WrtDB::GlobalConfig::GetTizenVersion();
562     } else if (appType == WrtDB::AppType::APP_TYPE_WAC20) {
563         version = WrtDB::GlobalConfig::GetWACVersion();
564     } else {
565         LogWarning("Invaild AppType");
566         return false;
567     }
568
569     if (!parseVersionString(version,
570                             majorSupported, minorSupported, microSupported))
571     {
572         LogWarning("Invalid format of platform version string.");
573         return true;
574     }
575
576     if (majorWidget > majorSupported ||
577         (majorWidget == majorSupported && minorWidget > minorSupported) ||
578         (majorWidget == majorSupported && minorWidget == minorSupported
579          && microWidget > microSupported))
580     {
581         LogInfo("Platform doesn't support this widget.");
582         return false;
583     }
584     return true;
585 }
586
587 bool TaskWidgetConfig::isTizenWebApp() const
588 {
589     bool ret = FALSE;
590     if (m_installContext.widgetConfig.webAppType.appType
591         == WrtDB::AppType::APP_TYPE_TIZENWEBAPP)
592     {
593         ret = TRUE;
594     }
595
596     return ret;
597 }
598
599 bool TaskWidgetConfig::parseConfigurationFileBrowser(
600     WrtDB::ConfigParserData& configInfo,
601     const std::string& _currentPath)
602 {
603     ParserRunner parser;
604     Try
605     {
606         parser.Parse(_currentPath, ElementParserPtr(new
607                                                     RootParser<
608                                                         WidgetParser>(
609                                                         configInfo,
610                                                         DPL::FromUTF32String(
611                                                             L"widget"))));
612     }
613     Catch(ElementParser::Exception::Base)
614     {
615         LogError("Invalid widget configuration file!");
616         return false;
617     }
618     return true;
619 }
620
621 bool TaskWidgetConfig::parseConfigurationFileWidget(
622     WrtDB::ConfigParserData& configInfo,
623     const std::string& _currentPath)
624 {
625     std::string configFilePath;
626     WrtUtilJoinPaths(configFilePath, _currentPath, WRT_WIDGET_CONFIG_FILE_NAME);
627     if (!WrtUtilFileExists(configFilePath))
628     {
629         LogError("Archive does not contain configuration file");
630         return false;
631     }
632
633     LogDebug("Configuration file: " << configFilePath);
634
635     Try
636     {
637         ParserRunner parser;
638         parser.Parse(configFilePath,
639                      ElementParserPtr(new RootParser<WidgetParser>(
640                                           configInfo,
641                                           DPL::FromUTF32String(L"widget"))));
642         return true;
643     }
644     Catch (ElementParser::Exception::Base)
645     {
646         LogError("Invalid configuration file!");
647         return false;
648     }
649 }
650
651 bool TaskWidgetConfig::locateAndParseConfigurationFile(
652     const std::string& _currentPath,
653     WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
654     const std::string& baseFolder)
655 {
656     using namespace WrtDB;
657
658     ConfigParserData& configInfo = pWidgetConfigInfo.configInfo;
659
660     // check if this installation from browser, or not.
661     size_t pos = _currentPath.rfind("/");
662     std::ostringstream infoPath;
663     infoPath << _currentPath.substr(pos + 1);
664
665     if (infoPath.str() != WRT_WIDGET_CONFIG_FILE_NAME) {
666         if (_currentPath.empty() || baseFolder.empty()) {
667             return false;
668         }
669         // in case of general installation using wgt archive
670         if (!parseConfigurationFileWidget(configInfo, _currentPath))
671         {
672             return false;
673         }
674     } else {
675         // in case of browser installation
676         if (!parseConfigurationFileBrowser(configInfo, _currentPath))
677         {
678             return false;
679         }
680     }
681
682     if (!fillWidgetConfig(pWidgetConfigInfo, configInfo)) {
683         return false;
684     }
685     return true;
686 }
687
688 bool TaskWidgetConfig::fillWidgetConfig(
689     WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
690     WrtDB::ConfigParserData& configInfo)
691 {
692     if (!!configInfo.widget_id) {
693         if (!pWidgetConfigInfo.guid) {
694             pWidgetConfigInfo.guid = configInfo.widget_id;
695         } else {
696             if (pWidgetConfigInfo.guid != configInfo.widget_id) {
697                 LogError("Invalid archive");
698                 return false;
699             }
700         }
701     }
702     if (!!configInfo.tizenAppId) {
703         if (DPL::ToUTF8String(pWidgetConfigInfo.tzAppid).compare(
704                 DPL::ToUTF8String(*configInfo.tizenAppId)) < 0)
705         {
706             LogError("Invalid archive - Tizen App ID not same error");
707             return false;
708         }
709     }
710     if (!!configInfo.tizenPkgId) {
711         if (pWidgetConfigInfo.tzPkgid != *configInfo.tizenPkgId) {
712             LogError("Invalid archive - Tizen Pkg ID not same error");
713             return false;
714         }
715     }
716     if (!!configInfo.version) {
717         if (!pWidgetConfigInfo.version) {
718             pWidgetConfigInfo.version = configInfo.version;
719         } else {
720             if (pWidgetConfigInfo.version != configInfo.version) {
721                 LogError("Invalid archive");
722                 return false;
723             }
724         }
725     }
726     if (!!configInfo.minVersionRequired) {
727         pWidgetConfigInfo.minVersion = configInfo.minVersionRequired;
728     } else if (!!configInfo.tizenMinVersionRequired) {
729         pWidgetConfigInfo.minVersion = configInfo.tizenMinVersionRequired;
730     }
731     return true;
732 }
733
734 void TaskWidgetConfig::processFile(
735     const std::string& path,
736     WrtDB::WidgetRegisterInfo &
737     widgetConfiguration)
738 {
739     if (!locateAndParseConfigurationFile(path, widgetConfiguration,
740                                          DEFAULT_LANGUAGE))
741     {
742         LogWarning("Widget archive: Failed while parsing config file");
743         ThrowMsg(Exception::ConfigParseFailed, path);
744     }
745 }
746 } //namespace WidgetInstall
747 } //namespace Jobs