From: Jinkun Jang Date: Tue, 12 Mar 2013 16:50:42 +0000 (+0900) Subject: Tizen 2.1 base X-Git-Tag: accepted/tizen_2.1/20130425.034740~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ce7d542afafc3f9f9b38076f1c52096593d4397;p=platform%2Fframework%2Fnative%2Finstaller.git Tizen 2.1 base --- diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..8b88653 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,83 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET (this_target osp-installer) + +SET(CMAKE_EXECUTABLE_SUFFIX "") +SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/output") + +INCLUDE_DIRECTORIES( + inc + src/Context + src/Installer + src/Manager + src/XmlHandler + src/XmlHandler/Parser + src/Step + src/Util + /usr/include/glib-2.0 + /usr/lib/glib-2.0/include + /usr/include/dlog + /usr/include/pkgmgr + /usr/include/appfw + /usr/include/osp + /usr/include/osp/app + /usr/include/osp/base + /usr/include/osp/io + /usr/include/osp/security + /usr/include/osp/system + /usr/include/libxml2 + /usr/include/system + /usr/include/drm-intel +) + +SET (${this_target}_SOURCE_FILES + src/Context/DrmLicense.cpp + src/Context/InstallationContext.cpp + src/Context/InstallationContextData.cpp + src/Installer/DirectoryInstaller.cpp + src/Installer/GuestInstaller.cpp + src/Installer/IDEInstaller.cpp + src/Installer/Installer.cpp + src/Installer/PackageInstaller.cpp + src/Installer/PreloadedInstaller.cpp + src/Installer/RestorationInstaller.cpp + src/Manager/ConfigurationManager.cpp + src/Manager/InstallerManager.cpp + src/Manager/PermissionManager.cpp + src/Manager/SignatureManager.cpp + src/Step/DrmStep.cpp + src/Step/IInstallationStep.cpp + src/Step/LicenseStep.cpp + src/Step/ManifestXmlStep.cpp + src/Step/PackageCheckStep.cpp + src/Step/SignatureStep.cpp + src/Step/SystemCheckStep.cpp + src/Step/UninstallStep.cpp + src/Step/UnpackStep.cpp + src/XmlHandler/ManifestGenerator.cpp + src/XmlHandler/ManifestHandler.cpp + src/XmlHandler/SignatureHandler.cpp + src/XmlHandler/XmlAttribute.cpp + src/XmlHandler/XmlHandler.cpp + src/XmlHandler/XmlWriter.cpp + src/XmlHandler/PrivilegeHandler.cpp + src/XmlHandler/Parser/ManifestParser.cpp + src/XmlHandler/Parser/ManifestAccountsParser.cpp + src/XmlHandler/Parser/ManifestAppControlsParser.cpp + src/XmlHandler/Parser/ManifestLiveboxesParser.cpp + src/backend/backend.cpp + src/Util/InstallerUtil.cpp + ) + +ADD_EXECUTABLE (${this_target} ${${this_target}_SOURCE_FILES}) + +SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") +SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw -lxml2 -lpkgmgr_installer -lpkgmgr_parser -lglib-2.0 -lapp2ext" -Wl,--allow-shlib-undefined) +TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib -ldrm-service-core-intel") + +ADD_SUBDIRECTORY(plugin) + +INSTALL(TARGETS ${this_target} DESTINATION bin) diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100755 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100755 index 0000000..0e0f016 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.APLv2 file for Apache License terms and conditions. diff --git a/data/.readme b/data/.readme new file mode 100644 index 0000000..e69de29 diff --git a/data/configuration b/data/configuration new file mode 100644 index 0000000..e20ce50 --- /dev/null +++ b/data/configuration @@ -0,0 +1 @@ ++/opt/apps/org.tizen.cmtamb4mtv \ No newline at end of file diff --git a/icons/icon.png b/icons/icon.png new file mode 100644 index 0000000..8169106 Binary files /dev/null and b/icons/icon.png differ diff --git a/icons/splash.png b/icons/splash.png new file mode 100644 index 0000000..7474959 Binary files /dev/null and b/icons/splash.png differ diff --git a/inc/InstallerDefs.h b/inc/InstallerDefs.h new file mode 100755 index 0000000..6ee4032 --- /dev/null +++ b/inc/InstallerDefs.h @@ -0,0 +1,260 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallerDefs.h + */ + +#ifndef _INSTALLER_DEFS_H_ +#define _INSTALLER_DEFS_H_ + +#define OSP_INSTALLER_VERSION "osp-installer version = 20130131.2" + +#define DIR_BIN L"/bin" +#define DIR_INFO L"/info" +#define DIR_RES L"/res" +#define DIR_DATA L"/data" +#define DIR_ICONS L"/icons" +#define DIR_SHARED L"/shared" +#define DIR_LIB L"/lib" +#define DIR_SETTING L"/setting" +#define DIR_CONTENTS L"/contents" +#define DIR_SHARED_RES L"/shared/res" + +#define SLP_DIR_BIN L"/bin" +#define SLP_DIR_RES L"/res" +#define SLP_DIR_DATA L"/data" +#define SLP_APP_PATH L"/opt/apps" + +#define PATH_OPT_APPS L"/opt/apps" +#define PATH_USR_APPS L"/usr/apps" +#define PATH_OPT_USR L"/opt/usr" +#define PATH_OPT_USR_APPS L"/opt/usr/apps" + +#define SLP_FONT_PATH L"/opt/share/fonts" + +#define DIR_DESKTOP L"/opt/share/applications/%S.desktop" +#define PACKAGE_NAME_PREFIX_ORG L"org.tizen." +#define PACKAGE_NAME_RULE_ORG L"org.tizen.%ls#%s" + +#define PACKAGE_NAME_RULE L"%ls.%s" + +#define FILE_EXT_INFO L"info" +#define VERSION_INFO_FILE L"/info/version.info" +#define COMPAT_INFO_FILE L"/info/compat.info" +#define UISCALABILITY_INFO_FILE L"/info/uiscalability.info" +#define WEBSERVICE_INFO_FILE L"/info/webservice.info" +#define TYPE_INFO_FILE L"/info/type.info" +#define PACKAGE_XML_FILE L"/info/manifest.xml" + +#define SIGNATURE1_XML_FILE L"/signature1.xml" +#define AUTHOR_SIGNATURE_XML_FILE L"/author-signature.xml" + +#define UISCALABILITY_INFO L"1 %ls %ls %ls" + +#define UIAPP_LOADER_PATH "/usr/lib/osp/osp-ui-app-loader" // UiApp +#define SERVICEAPP_LOADER_PATH "/usr/lib/osp/osp-service-app-loader" // ServiceApp +#define SYSTEMAPP_LOADER_PATH "/usr/lib/osp/osp-system-service-loader" // System Service +#define IME_PATH "/opt/apps/scim/lib/scim-1.0/1.4.0/Helper" + +#define SUB_MODE_APPCONTROL_NAME L"_AppControl" + +#define APP_OWNER_ID 5000 +#define APP_GROUP_ID 5000 + +#define APPID_LENGTH 10 +#define APP_DIR_LENGTH 20 + +#define TEST_ARG_COUNT 1 +#define COMMAND_ARG_COUNT 3 + +#define DIR_OSP_APPLICATIONS_TEMP L"/opt/usr/apps/__@@osp_tmp@@__" + +#define DIR_RO_PACKAGE_SYSTEM_MANIFEST L"/usr/share/packages/%ls.xml" +#define DIR_RW_PACKAGE_SYSTEM_MANIFEST L"/opt/share/packages/%ls.xml" + +#define DIR_MEMORYCARD_OSP_APPLICATIONS L"/opt/storage/sdcard/apps" +#define DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP L"/opt/storage/sdcard/apps/__@@osp_tmp@@__" +#define DIR_MEMORYCARD_INSTALLATION L"/opt/storage/sdcard/installtosdcard" + +#define PERM_BASE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) // 0644 +#define PERM_EXECUTE (S_IXUSR | S_IXGRP | S_IXOTH) +#define PERM_WRITE (S_IWUSR | S_IWGRP | S_IWOTH) + +#define TIZEN_PRIVILEGE_WEB_SERVICE "http://tizen.org/privilege/web.service" +#define TIZEN_CATEGORY_IME "http://tizen.org/category/ime" +#define TIZEN_CATEGORY_HOMESCREEN "http://tizen.org/category/homescreen" +#define TIZEN_CATEGORY_LOCKSCREEN "http://tizen.org/category/lockscreen" +#define TIZEN_CATEGORY_MENUSCREEN "http://tizen.org/category/menuscreen" + +static const int BLOCK_SIZE = 4096; + +#define OSP_INSTALLER "osp-installer" + +#ifdef AppLogTag +#undef AppLogTag +#define AppLogTag(tag, ...) AppLogTagInternal(tag, " |", 0, __VA_ARGS__); \ + fprintf(stderr, " |");fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n"); +#endif + +#ifdef TryCatch +#undef TryCatch +#define TryCatch(condition, expr, ...) \ + if (!(condition)) { \ + AppLogExceptionTag(OSP_INSTALLER, __VA_ARGS__); \ + expr; \ + fprintf(stderr, " |");fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n"); \ + goto CATCH; \ + } \ + else {;} +#endif + +#ifdef TryReturn +#undef TryReturn +#define TryReturn(condition, returnValue, ...) \ + if (!(condition)) { \ + AppLogExceptionTag(OSP_INSTALLER, __VA_ARGS__); \ + fprintf(stderr, " |");fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n"); \ + return returnValue; \ + } \ + else {;} +#endif + +enum InstallationSetStep +{ + INSTALLER_STEP_REMOVE, + INSTALLER_STEP_SET, + +}; + +enum InstallationState +{ + INSTALLER_STATE_READY, + INSTALLER_STATE_RUNNING, + +}; + +enum InstallationStep +{ + INSTALLER_STEP_NONE = 0, + INSTALLER_STEP_INIT, + INSTALLER_STEP_CHECK_SYSTEM, + INSTALLER_STEP_CHECK_PACKAGE, + INSTALLER_STEP_DRM, + INSTALLER_STEP_PARSE_MANIFEST, + INSTALLER_STEP_UNPACK, + INSTALLER_STEP_LICENSE, + INSTALLER_STEP_PARSE_SIGNATURE, + + INSTALLER_STEP_INIT_UNINSTALL, + INSTALLER_STEP_UNINSTALL, + INSTALLER_STEP_END, + + INSTALLER_STEP_MAX, + +}; + +enum InstallerType +{ + INSTALLER_TYPE_INSTALLER, + INSTALLER_TYPE_PACKAGE, + INSTALLER_TYPE_DIRECTORY, + INSTALLER_TYPE_GUEST, + INSTALLER_TYPE_PRELOADED, + INSTALLER_TYPE_IDE, + INSTALLER_TYPE_RESTORATION, + +}; + +enum RequesterType +{ + REQUESTER_TYPE_NORMAL, + REQUESTER_TYPE_IDE, + REQUESTER_TYPE_PRELOADED, + +}; + +enum InstallerError +{ + INSTALLER_ERROR_NONE = 0, + INSTALLER_ERROR_PACKAGE_NOT_FOUND = 1, + INSTALLER_ERROR_PACKAGE_INVALID = 2, + INSTALLER_ERROR_PACKAGE_LOWER_VERSION = 3, + INSTALLER_ERROR_EXECUTABLE_NOT_FOUND = 4, + INSTALLER_ERROR_MANIFEST_NOT_FOUND = 11, + INSTALLER_ERROR_MANIFEST_INVALID = 12, + INSTALLER_ERROR_SIGNATURE_NOT_FOUND = 21, + INSTALLER_ERROR_SIGNATURE_INVALID = 22, + INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED = 23, + INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND = 31, + INSTALLER_ERROR_CERTIFICATE_INVALID = 32, + INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED = 33, + INSTALLER_ERROR_CERTIFICATE_EXPIRED = 34, + INSTALLER_ERROR_PRIVILEGE_INVALID = 41, + INSTALLER_ERROR_MENU_ICON_NOT_FOUND = 51, + INSTALLER_ERROR_FATAL_ERROR = 61, + INSTALLER_ERROR_OUT_OF_STORAGE = 62, + INSTALLER_ERROR_OUT_OF_MEMORY = 63, + + INSTALLER_ERROR_USER_CANCEL = 141, + INSTALLER_ERROR_UNMOUNT_FAILED = 142, + INSTALLER_ERROR_INTERNAL_STATE = 143, + INSTALLER_ERROR_DATABASE = 144, + INSTALLER_ERROR_DRM = 145, +}; + +enum InstallerOperation +{ + INSTALLER_OPERATION_INSTALL, + INSTALLER_OPERATION_UNINSTALL, + +}; + +enum RootCertificateType +{ + ROOT_CERTIFICATE_NONE, + ROOT_CERTIFICATE_DEVELOPER, + ROOT_CERTIFICATE_PUBLIC, + ROOT_CERTIFICATE_PARTNER, + ROOT_CERTIFICATE_PARTNER_OPERATOR, + ROOT_CERTIFICATE_PARTNER_MANUFACTURER, + +}; + +enum +{ + INSTALLER_MODE_INSTALL = 1, + INSTALLER_MODE_UNINSTALL = 2, + INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL = 3, +}; + +enum +{ + INSTALLER_PREFIX_TYPE_NONE, + INSTALLER_PREFIX_TYPE_ORG, + +}; + +enum CategoryType +{ + CATEGORY_TYPE_NONE, + CATEGORY_TYPE_IME, + CATEGORY_TYPE_HOME_SCREEN, + CATEGORY_TYPE_LOCK_SCREEN, + +}; + +#endif // _INSTALLER_DEFS_H_ diff --git a/lib/.readme b/lib/.readme new file mode 100644 index 0000000..e69de29 diff --git a/manifest.xml b/manifest.xml new file mode 100755 index 0000000..18ee478 --- /dev/null +++ b/manifest.xml @@ -0,0 +1,25 @@ + + + cmtamb4mtv + 1.0.0 + C++App + + + + + + 2.1 + + + + + osp-installer + + + + + + + + + diff --git a/osp-installer.manifest b/osp-installer.manifest new file mode 100644 index 0000000..d13ea7f --- /dev/null +++ b/osp-installer.manifest @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/packaging/osp-installer.spec b/packaging/osp-installer.spec new file mode 100755 index 0000000..106e0f8 --- /dev/null +++ b/packaging/osp-installer.spec @@ -0,0 +1,68 @@ +Name: osp-installer +Summary: osp application installer +Version: 1.2.0.0 +Release: 2 +Group: TO_BE/FILLED_IN +License: Apache License, Version 2.0 or Flora +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(capi-system-device) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(appsvc) +BuildRequires: pkgconfig(pkgmgr) +BuildRequires: pkgconfig(pkgmgr-parser) +BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(app2sd) +BuildRequires: pkgconfig(libwbxml2) +BuildRequires: pkgconfig(osp-appfw) +BuildRequires: pkgconfig(drm-service-core-intel) + +BuildRequires: osp-appfw-internal-devel + +# runtime requires +Requires: osp-appfw +Requires: osp-loader + +%description +osp application installer + +%prep +%setup -q + +%build +%ifarch %{ix86} +CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} +%else +CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} +%endif + +# Call make instruction with smp support +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/usr/share/license +cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} + +%make_install + +%post +/bin/rm -f /etc/ld.so.cache +/sbin/ldconfig + +mkdir -p /usr/share/packages +mkdir -p /opt/share/packages +rm -rf /usr/etc/package-manager/backendlib/libtpk.so +ln -s /usr/lib/libosp-installer-plugin.so /usr/etc/package-manager/backendlib/libtpk.so +rm -rf /usr/etc/package-manager/backend/tpk +ln -s /usr/bin/osp-installer /usr/etc/package-manager/backend/tpk + +%postun -p /sbin/ldconfig + +%files +%manifest osp-installer.manifest +/usr/share/license/%{name} +/usr/bin/* +/usr/lib/*.so* + diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt new file mode 100755 index 0000000..fa5d30a --- /dev/null +++ b/plugin/CMakeLists.txt @@ -0,0 +1,23 @@ +SET(this_target osp-installer-plugin) + +INCLUDE_DIRECTORIES( + /usr/include/osp + /usr/include/osp/app + /usr/include/osp/base + ../inc +) + +SET(${this_target}_SOURCE_FILES + osp-installer-plugin.cpp +) + +ADD_LIBRARY(${this_target} SHARED ${${this_target}_SOURCE_FILES}) + +ADD_DEPENDENCIES(${this_target} osp-installer) + +TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw -lpkgmgr_installer" -Wl,--allow-shlib-undefined) + +SET_TARGET_PROPERTIES(${this_target} PROPERTIES LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both -Wl") +SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") + +INSTALL(TARGETS ${this_target} DESTINATION lib) \ No newline at end of file diff --git a/plugin/osp-installer-plugin.cpp b/plugin/osp-installer-plugin.cpp new file mode 100644 index 0000000..14e7130 --- /dev/null +++ b/plugin/osp-installer-plugin.cpp @@ -0,0 +1,266 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file osp-installer-plugin.cpp + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "InstallerDefs.h" + +using namespace Tizen::Base; +using namespace Tizen::Io; +using namespace Tizen::App::Package; + +#ifdef __cplusplus +extern "C" +{ +#endif + +static const int PKG_SUCCESS = 0; +static const int PKG_ERROR = 1; + +static int pkg_get_installed_size(const String& rootPath); +static int pkg_get_data_size(const String& rootPath); + +static void pkg_plugin_unload(void) +{ + AppLogTag(OSP_INSTALLER, "[libtpk] pkg_plugin_unload() is called"); +} + +static int pkg_plugin_pkg_is_installed(const char *pkg_name) +{ + int err = PKG_SUCCESS; + String packageName(pkg_name); + String packageId; + bool installed = true; + + AppLogTag(OSP_INSTALLER, "[libtpk] pkg_plugin_pkg_is_installed() is called"); + AppLogTag(OSP_INSTALLER, "[libtpk] pkg_name=[%s]", pkg_name); + + TryCatch(pkg_name, err = PKG_ERROR, "[osp-installer][libtpk] pkg_name is null"); + + if (packageName.Contains(PACKAGE_NAME_PREFIX_ORG) == true) + { + String prefixPackage(PACKAGE_NAME_PREFIX_ORG); + packageName.SubString(prefixPackage.GetLength(), APPID_LENGTH, packageId); + } + else + { + packageName.SubString(0, APPID_LENGTH, packageId); + } + + installed = _PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId); + TryCatch(installed == true, err = PKG_ERROR, "[osp-installer][libtpk] IsPackageInstalled() is failed"); + + AppLogTag(OSP_INSTALLER, "[libtpk] IsPackageInstalled=[%d]", installed); + err = PKG_SUCCESS; + +CATCH: + return err; +} + +static int pkg_plugin_get_installed_pkg_list(const char *category, + const char *option, package_manager_pkg_info_t **list, int *count) +{ + AppLogTag(OSP_INSTALLER, "[libtpk] pkg_plugin_get_installed_pkg_list() is called"); + + return PKG_ERROR; +} + +static int pkg_plugin_get_pkg_detail_info(const char *pkg_name, + package_manager_pkg_detail_info_t *pkg_detail_info) +{ + bool err = PKG_SUCCESS; + String packageName(pkg_name); + String appId; + char* pVersion = null; + _PackageInfoImpl pkgInfoImpl; + result r = E_SUCCESS; + + AppLogTag(OSP_INSTALLER, "[libtpk] pkg_plugin_get_pkg_detail_info() is called"); + AppLogTag(OSP_INSTALLER, "[libtpk] pkg_name=[%s]", pkg_name); + + TryCatch(pkg_name, err = PKG_ERROR, "[osp-installer][libtpk] pkg_name is null"); + + memset(pkg_detail_info, 0, sizeof(package_manager_pkg_detail_info_t)); + + if (packageName.Contains(PACKAGE_NAME_PREFIX_ORG) == true) + { + String prefixPackage(PACKAGE_NAME_PREFIX_ORG); + packageName.SubString(prefixPackage.GetLength(), APPID_LENGTH, appId); + } + else + { + packageName.SubString(0, APPID_LENGTH, appId); + } + + r = pkgInfoImpl.Construct(appId); + TryCatch(!IsFailed(r), err = PKG_ERROR, "[osp-installer][libtpk] pkgInfoImpl.Construct is failed"); + + strncpy(pkg_detail_info->pkg_type, "tpk", PKG_TYPE_STRING_LEN_MAX); + strncpy(pkg_detail_info->pkg_name, pkg_name, PKG_NAME_STRING_LEN_MAX-1); + + pVersion = _StringConverter::CopyToCharArrayN(pkgInfoImpl.GetVersion()); + TryCatch(pVersion, err = PKG_ERROR, "[osp-installer][libtpk] pVersion is null"); + strncpy(pkg_detail_info->version, pVersion, PKG_VERSION_STRING_LEN_MAX-1); + + delete [] pVersion; + pVersion = null; + + pkg_detail_info->installed_size = pkg_get_installed_size(pkgInfoImpl.GetAppRootPath()); + pkg_detail_info->data_size = pkg_get_data_size(pkgInfoImpl.GetAppRootPath()); + pkg_detail_info->app_size = pkg_detail_info->installed_size - pkg_detail_info->data_size; + + err = PKG_SUCCESS; + +CATCH: + delete [] pVersion; + return err; +} + +static int pkg_plugin_get_pkg_detail_info_from_package(const char *pkg_path, + package_manager_pkg_detail_info_t *pkg_detail_info) +{ + AppLogTag(OSP_INSTALLER, "[libtpk] pkg_plugin_get_pkg_detail_info_from_package() is called"); + + return PKG_ERROR; +} + +long long pkg_get_directory_size(const String& rootPath) +{ + long long total = 0; + long long ret = 0; + int q = 0; + int r = 0; + DIR *dp = NULL; + struct dirent *ep = NULL; + struct stat fileinfo; + char fileName[FILENAME_MAX] = { 0, }; + char *pDirName = null; + + pDirName = _StringConverter::CopyToCharArrayN(rootPath); + TryCatch(pDirName, total = 0, "[osp-installer][libtpk] pDirName is null"); + + dp = opendir(pDirName); + TryCatch(dp, total = 0, "[osp-installer][libtpk] dp is null"); + + while ((ep = readdir(dp)) != NULL) + { + if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, "..")) + { + continue; + } + + snprintf(fileName, FILENAME_MAX, "%s/%s", pDirName, ep->d_name); + + if (lstat(fileName, &fileinfo) < 0) + { + continue; + } + + if (S_ISLNK(fileinfo.st_mode)) + { + AppLogTag(OSP_INSTALLER, "[libtpk] SYMLINK=%s", fileName); + total += BLOCK_SIZE; + continue; + } + else if (S_ISDIR(fileinfo.st_mode)) + { + ret = pkg_get_directory_size(fileName); + ret += fileinfo.st_size; + total += ret; + AppLogTag(OSP_INSTALLER, "[libtpk] DIR=%s, size=%d[%dK],", fileName, (int)ret, (int)(ret/1024)); + } + else + { + /*It is a file. Calculate the actual size occupied (in terms of 4096 blocks)*/ + q = (fileinfo.st_size / BLOCK_SIZE); + r = (fileinfo.st_size % BLOCK_SIZE); + if (r) + { + q++; + } + total += q * BLOCK_SIZE; + + if (q) + { + AppLogTag(OSP_INSTALLER, "[libtpk] File=%s, size=%d[%dK]", fileName, (q * BLOCK_SIZE), (q * BLOCK_SIZE)/1024); + } + } + } + + closedir(dp); + dp = null; + +CATCH: + delete [] pDirName; + + return total; +} + +int pkg_get_installed_size(const String& rootPath) +{ + String destPath; + long long size = 0; + + size = pkg_get_directory_size(rootPath); + + return (int)size; +} + +int pkg_get_data_size(const String& rootPath) +{ + String destPath; + long long size = 0; + + destPath = rootPath + DIR_DATA; + size = pkg_get_directory_size(destPath); + size += BLOCK_SIZE; + + return (int)size; +} + +__attribute__ ((visibility("default"))) +int pkg_plugin_on_load(pkg_plugin_set *set) +{ + memset(set, 0, sizeof(pkg_plugin_set)); + + set->plugin_on_unload = pkg_plugin_unload; + set->pkg_is_installed = pkg_plugin_pkg_is_installed; + set->get_installed_pkg_list = pkg_plugin_get_installed_pkg_list; + set->get_pkg_detail_info = pkg_plugin_get_pkg_detail_info; + set->get_pkg_detail_info_from_package = pkg_plugin_get_pkg_detail_info_from_package; + + return PKG_SUCCESS; +} + +#ifdef __cplusplus +} +#endif + diff --git a/res/0123456789.oap b/res/0123456789.oap new file mode 100644 index 0000000..9fcef08 Binary files /dev/null and b/res/0123456789.oap differ diff --git a/res/0123456789.zip b/res/0123456789.zip new file mode 100644 index 0000000..9fcef08 Binary files /dev/null and b/res/0123456789.zip differ diff --git a/res/etc/.readme b/res/etc/.readme new file mode 100644 index 0000000..e69de29 diff --git a/res/icons/default/small/icon_application.png b/res/icons/default/small/icon_application.png new file mode 100644 index 0000000..f8beeca Binary files /dev/null and b/res/icons/default/small/icon_application.png differ diff --git a/res/images/.readme b/res/images/.readme new file mode 100644 index 0000000..e69de29 diff --git a/res/locale/en_US.po b/res/locale/en_US.po new file mode 100644 index 0000000..432eddb --- /dev/null +++ b/res/locale/en_US.po @@ -0,0 +1,17 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-07-23 16:32+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" diff --git a/src/Context/DrmLicense.cpp b/src/Context/DrmLicense.cpp new file mode 100644 index 0000000..d69ebb9 --- /dev/null +++ b/src/Context/DrmLicense.cpp @@ -0,0 +1,36 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file DrmLicense.cpp + * @brief This is the implementation file for %DrmLicense class. + */ + +#include "DrmLicense.h" + +DrmLicense::DrmLicense(void) +{ +} + +DrmLicense::~DrmLicense(void) +{ +} + +InstallerError +DrmLicense::Construct(void) +{ + return INSTALLER_ERROR_NONE; +} diff --git a/src/Context/DrmLicense.h b/src/Context/DrmLicense.h new file mode 100755 index 0000000..152a40e --- /dev/null +++ b/src/Context/DrmLicense.h @@ -0,0 +1,45 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file DrmLicense.h + * @brief This is the header file for the %DrmLicense class. + * + * This header file contains the declarations of the %DrmLicense class. + */ +#ifndef _DRM_LICENSE_H_ +#define _DRM_LICENSE_H_ + +#include "InstallerDefs.h" + +/** + * @class DrmLicense + * @brief This class represents the class of DrmLicense. + * @since 1.0 + * + * This class represents the class of DrmLicense. + * + */ +class DrmLicense +{ +public: + DrmLicense(void); + InstallerError Construct(void); + virtual ~DrmLicense(void); + +}; // DrmLicense + +#endif // _DRM_LICENSE_H_ diff --git a/src/Context/InstallationContext.cpp b/src/Context/InstallationContext.cpp new file mode 100755 index 0000000..fa4a891 --- /dev/null +++ b/src/Context/InstallationContext.cpp @@ -0,0 +1,530 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallationContext.cpp + * @brief This is the implementation for the InstallerContext class. + */ + +#include "InstallationContext.h" +#include "SystemCheckStep.h" +#include "PackageCheckStep.h" +#include "ManifestXmlStep.h" +#include "LicenseStep.h" +#include "SignatureStep.h" +#include "DrmStep.h" +#include "UninstallStep.h" +#include "UnpackStep.h" + +#include + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; +using namespace Tizen::Security::Cert; +using namespace Tizen::App; +using namespace Tizen::App::Package; + +InstallationContext::InstallationContext(void) +:__pAppDataList(null) +,__isSubMode(false) +,__isOspCompat(false) +,__pStep(null) +,__pDrmLicense(null) +,__error(INSTALLER_ERROR_NONE) +,__step(INSTALLER_STEP_NONE) +,__attributeType(0) +,__state(INSTALLER_STATE_RUNNING) +,__stepChanged(true) +,__continue(true) +,__preloaded(false) +,__hybridService(false) +,__verificationMode(false) +,__operation(INSTALLER_OPERATION_INSTALL) +,__storage(INSTALLATION_STORAGE_INTERNAL) +,__pPrivilegeList(null) +,__pLiveboxDataList(null) +,__pContentDataList(null) +,__pAuthorCertPath(null) +,__pDistributorCertPath(null) +,__rootCertType(ROOT_CERTIFICATE_NONE) +,__packageNameType(INSTALLER_PREFIX_TYPE_NONE) +,__pApp2ExtHandle(null) +,__pPackageInfoImpl(null) +{ +} + +InstallationContext::~InstallationContext(void) +{ + delete __pStep; + __pStep = null; + + delete __pDrmLicense; + __pDrmLicense = null; + + delete __pAuthorCertPath; + __pAuthorCertPath = null; + + delete __pDistributorCertPath; + __pDistributorCertPath = null; + + if (__pPrivilegeList) + { + __pPrivilegeList->RemoveAll(); + delete __pPrivilegeList; + __pPrivilegeList = null; + } + + if (__pLiveboxDataList) + { + __pLiveboxDataList->RemoveAll(); + delete __pLiveboxDataList; + __pLiveboxDataList = null; + } + + if (__pAppDataList) + { + __pAppDataList->RemoveAll(); + delete __pAppDataList; + } +} + +InstallerError +InstallationContext::Construct(void) +{ + __pPackageInfoImpl = new (std::nothrow) _PackageInfoImpl(); + TryReturn(__pPackageInfoImpl, INSTALLER_ERROR_OUT_OF_MEMORY, "[osp-installer] __pPackageInfoImpl is null."); + + __pAppDataList = new (std::nothrow) ArrayListT; + TryReturn(__pAppDataList, INSTALLER_ERROR_OUT_OF_MEMORY, "[osp-installer] __pAppDataList is null"); + + return INSTALLER_ERROR_NONE; +} + +bool +InstallationContext::ChangeStep(InstallationStep step) +{ + delete __pStep; + __pStep = null; + + switch (step) + { + case INSTALLER_STEP_NONE: + break; + + case INSTALLER_STEP_INIT: + break; + + case INSTALLER_STEP_CHECK_SYSTEM: + __pStep = new (std::nothrow) SystemCheckStep(); + TryReturn(__pStep, false, "[osp-installer] SystemCheckStep is failed."); + break; + + case INSTALLER_STEP_CHECK_PACKAGE: + __pStep = new (std::nothrow) PackageCheckStep(); + TryReturn(__pStep, false, "[osp-installer] PackageCheckStep is failed."); + break; + + case INSTALLER_STEP_UNPACK: + __pStep = new (std::nothrow) UnpackStep(); + TryReturn(__pStep, false, "[osp-installer] UnpackStep is failed."); + break; + + case INSTALLER_STEP_PARSE_MANIFEST: + __pStep = new (std::nothrow) ManifestXmlStep(); + TryReturn(__pStep, false, "[osp-installer] ManifestXmlStep is failed."); + break; + + case INSTALLER_STEP_PARSE_SIGNATURE: + __pStep = new (std::nothrow) SignatureStep(); + TryReturn(__pStep, false, "[osp-installer] SignatureStep is failed."); + break; + + case INSTALLER_STEP_UNINSTALL: + __pStep = new (std::nothrow) UninstallStep(); + TryReturn(__pStep, false, "[osp-installer] UninstallStep is failed."); + break; + + case INSTALLER_STEP_LICENSE: + __pStep = new (std::nothrow) LicenseStep(); + TryReturn(__pStep, false, "[osp-installer] LicenseStep is failed."); + break; + + case INSTALLER_STEP_DRM: + __pStep = new (std::nothrow) DrmStep(); + TryReturn(__pStep, false, "[osp-installer] DrmStep is failed."); + break; + + case INSTALLER_STEP_END: + break; + + default: + break; + } + + __step = step; + return true; +} + +InstallerError +InstallationContext::Run(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "InstallationContext::Run()"); + return error; +} + +InstallationStep +InstallationContext::GetCurrentInstallationStep(void) +{ + return __step; +} + +void +InstallationContext::SetCurrentInstallationStep(InstallationStep step) +{ + __step = step; +} + +InstallerError +InstallationContext::GetError(void) +{ + return __error; +} + +void +InstallationContext::SetError(InstallerError installerError) +{ + __error = installerError; +} + +InstallationState +InstallationContext::GetState(void) +{ + return __state; +} + +void +InstallationContext::SetState(InstallationState installationState) +{ + __state = installationState; +} + +IInstallationStep* +InstallationContext::GetStep(void) +{ + return __pStep; +} + +void +InstallationContext::SetInputPath(const Tizen::Base::String& path) +{ + __inputPath = path; +} + +const String& +InstallationContext::GetInputPath(void) const +{ + return __inputPath; +} + +void +InstallationContext::SetInstallerOperation(InstallerOperation op) +{ + __operation = op; +} + +InstallerOperation +InstallationContext::GetInstallerOperation(void) const +{ + return __operation; +} + +bool +InstallationContext::IsContinue(void) +{ + return __continue; +} + +void +InstallationContext::SetContinue(bool cont) +{ + __continue = cont; +} + +bool +InstallationContext::IsPreloaded(void) +{ + return __preloaded; +} + +void +InstallationContext::SetPreloaded(bool preloaded) +{ + __preloaded = preloaded; +} + +bool +InstallationContext::IsHybridService(void) +{ + return __hybridService; +} + +void +InstallationContext::SetHybridService(bool hybridService) +{ + __hybridService = hybridService; +} + +bool +InstallationContext::IsVerificationMode(void) +{ + return __verificationMode; +} + +void +InstallationContext::SetVerificationMode(bool verificationMode) +{ + __verificationMode = verificationMode; +} + +const String& +InstallationContext::GetPackagePath(void) const +{ + return __packagePath; +} + +void +InstallationContext::SetPackagePath(const String& packagePath) +{ + __packagePath = packagePath; +} + +const String& +InstallationContext::GetLicensePath(void) const +{ + return __licensePath; +} + +void +InstallationContext::SetLicensePath(const String& licensePath) +{ + __licensePath = licensePath; +} + +const String& +InstallationContext::GetTemporaryDir(void) const +{ + return __temporaryDir; +} + +void +InstallationContext::SetTemporaryDir(const String& temporaryDir) +{ + __temporaryDir = temporaryDir; +} + +const String& +InstallationContext::GetInstallDir(void) const +{ + return __installDir; +} + +void +InstallationContext::SetInstallDir(const String& installDir) +{ + __installDir = installDir; +} + +const String& +InstallationContext::GetWorkingDir(void) const +{ + return __workingDir; +} + +void +InstallationContext::SetWorkingDir(const String& workingDir) +{ + __workingDir = workingDir; +} + +void +InstallationContext::SetInstallationStorage(InstallationStorage storage) +{ + __storage = storage; +} + +InstallationContext::InstallationStorage +InstallationContext::GetInstallationStorage(void) const +{ + return __storage; +} + +const PackageId& +InstallationContext::GetId(void) const +{ + return __packageId; +} + +void +InstallationContext::SetId(const PackageId& packageId) +{ + __packageId = packageId; +} + +const String& +InstallationContext::GetAppVersion(void) const +{ + return __appVersion; +} + +void +InstallationContext::SetAppVersion(const String& appVersion) +{ + __appVersion = appVersion; +} + +String +InstallationContext::GetManifestXmlPath(void) +{ + String path; + + path = GetInstallDir() + PACKAGE_XML_FILE; + + return path; +} + +String +InstallationContext::GetSignatureXmlPath(void) +{ + String path; + + path = GetInstallDir() + SIGNATURE1_XML_FILE; + + return path; +} + +String +InstallationContext::GetAuthorSignatureXmlPath(void) +{ + String path; + + path = GetInstallDir() + AUTHOR_SIGNATURE_XML_FILE; + + return path; +} + +const ArrayList* +InstallationContext::GetPrivilegeList(void) const +{ + return __pPrivilegeList; +} + +void +InstallationContext::SetPrivilegeList(ArrayList* privilegeList) +{ + __pPrivilegeList = privilegeList; +} + +ArrayList* +InstallationContext::GetLiveboxDataList(void) const +{ + return __pLiveboxDataList; +} + +void +InstallationContext::SetLiveboxDataList(ArrayList* pLiveboxDataList) +{ + __pLiveboxDataList = pLiveboxDataList; +} + +ArrayList* +InstallationContext::GetContentDataList(void) const +{ + return __pContentDataList; +} + +void +InstallationContext::SetContentDataList(ArrayList* pContentDataList) +{ + __pContentDataList = pContentDataList; +} + +X509CertificatePath* +InstallationContext::GetAuthorCertPath(void) const +{ + return __pAuthorCertPath; +} + +void +InstallationContext::SetAuthorCertPath(X509CertificatePath* pAuthorCertPath) +{ + __pAuthorCertPath = pAuthorCertPath; +} + +X509CertificatePath* +InstallationContext::GetDistributorCertPath(void) const +{ + return __pDistributorCertPath; +} + +void +InstallationContext::SetDistributorCertPath(X509CertificatePath* pDistributorCertPath) +{ + __pDistributorCertPath = pDistributorCertPath; +} + +RootCertificateType +InstallationContext::GetRootCertType(void) const +{ + return __rootCertType; +} + +void +InstallationContext::SetRootCertType(RootCertificateType certType) +{ + __rootCertType = certType; +} + +int +InstallationContext::GetPackageNameType(void) const +{ + return __packageNameType; +} + +void +InstallationContext::SetPackageNameType(int type) +{ + __packageNameType = type; +} + +app2ext_handle* +InstallationContext::GetApp2ExtHandle(void) const +{ + return __pApp2ExtHandle; +} + +void +InstallationContext::SetApp2ExtHandle(app2ext_handle* pHandle) +{ + __pApp2ExtHandle = pHandle; +} + +_PackageInfoImpl* +InstallationContext::GetPackageInfoImpl(void) const +{ + return __pPackageInfoImpl; +} diff --git a/src/Context/InstallationContext.h b/src/Context/InstallationContext.h new file mode 100755 index 0000000..97c609f --- /dev/null +++ b/src/Context/InstallationContext.h @@ -0,0 +1,197 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallationContext.h + * @brief This is the header file for the %InstallationContext class. + * + * This header file contains the declarations of the %InstallationContext class. + */ +#ifndef _INSTALLATION_CONTEXT_H_ +#define _INSTALLATION_CONTEXT_H_ + +#include + +#include +#include +#include + +#include "InstallerDefs.h" +#include "IInstallationStep.h" +#include "DrmLicense.h" +#include "InstallationContextData.h" + +class IInstallationStep; + +/** + * @class InstallationContext + * @brief This class represents the class of InstallationContext. + * @since 1.0 + * + * This class represents the class of InstallationContext. + * + */ +class InstallationContext +{ +public: + enum InstallationStorage + { + INSTALLATION_STORAGE_INTERNAL, + INSTALLATION_STORAGE_EXTERNAL, + }; + + InstallationContext(void); + virtual ~InstallationContext(void); + InstallerError Construct(void); + + bool ChangeStep(InstallationStep step); + InstallerError Run(void); + + InstallationStep GetCurrentInstallationStep(void); + void SetCurrentInstallationStep(InstallationStep step); + + InstallerError GetError(void); + void SetError(InstallerError installerError); + + InstallationState GetState(void); + void SetState(InstallationState installationState); + + IInstallationStep* GetStep(void); + + void SetInputPath(const Tizen::Base::String& path); + const Tizen::Base::String& GetInputPath(void) const; + + void SetInstallerOperation(InstallerOperation op); + InstallerOperation GetInstallerOperation(void) const; + + void SetInstallationStorage(InstallationStorage storage); + InstallationStorage GetInstallationStorage(void) const; + + bool IsContinue(void); + void SetContinue(bool cont); + + bool IsPreloaded(void); + void SetPreloaded(bool preloaded); + + bool IsHybridService(void); + void SetHybridService(bool hybridService); + + bool IsVerificationMode(void); + void SetVerificationMode(bool verificationMode); + + const Tizen::Base::String& GetPackagePath(void) const; + void SetPackagePath(const Tizen::Base::String& packagePath); + + const Tizen::Base::String& GetLicensePath(void) const; + void SetLicensePath(const Tizen::Base::String& licensePath); + + const Tizen::Base::String& GetTemporaryDir(void) const; + void SetTemporaryDir(const Tizen::Base::String& temporaryDir); + + const Tizen::Base::String& GetInstallDir(void) const; + void SetInstallDir(const Tizen::Base::String& installDir); + + const Tizen::Base::String& GetWorkingDir(void) const; + void SetWorkingDir(const Tizen::Base::String& workingDir); + + const Tizen::App::PackageId& GetId(void) const; + void SetId(const Tizen::App::PackageId& packageId); + + const Tizen::Base::String& GetAppVersion(void) const; + void SetAppVersion(const Tizen::Base::String& appVersion); + + Tizen::Base::String GetManifestXmlPath(void); + Tizen::Base::String GetSignatureXmlPath(void); + Tizen::Base::String GetAuthorSignatureXmlPath(void); + + const Tizen::Base::Collection::ArrayList* GetPrivilegeList(void) const; + void SetPrivilegeList(Tizen::Base::Collection::ArrayList* privilegeList); + + Tizen::Base::Collection::ArrayList* GetLiveboxDataList(void) const; + void SetLiveboxDataList(Tizen::Base::Collection::ArrayList* pLiveboxDataList); + + Tizen::Base::Collection::ArrayList* GetContentDataList(void) const; + void SetContentDataList(Tizen::Base::Collection::ArrayList* pContentDataList); + + Tizen::Security::Cert::X509CertificatePath* GetAuthorCertPath(void) const; + void SetAuthorCertPath(Tizen::Security::Cert::X509CertificatePath* pAuthorCertPath); + + Tizen::Security::Cert::X509CertificatePath* GetDistributorCertPath(void) const; + void SetDistributorCertPath(Tizen::Security::Cert::X509CertificatePath* pDistributorCertPath); + + RootCertificateType GetRootCertType(void) const; + void SetRootCertType(RootCertificateType certType); + + int GetPackageNameType(void) const; + void SetPackageNameType(int type); + + app2ext_handle* GetApp2ExtHandle(void) const; + void SetApp2ExtHandle(app2ext_handle* pHandle); + + Tizen::App::Package::_PackageInfoImpl* GetPackageInfoImpl(void) const; + + PackageData __packageData; + Tizen::Base::Collection::IListT* __pAppDataList; + + bool __isSubMode; + Tizen::Base::String __subModeAppName; + + bool __isOspCompat; + +private: + InstallationContext(const InstallationContext& value); + InstallationContext& operator =(const InstallationContext& source); + + IInstallationStep* __pStep; + DrmLicense* __pDrmLicense; + InstallerError __error; + InstallationStep __step; + int __attributeType; + InstallationState __state; + bool __stepChanged; + bool __continue; + bool __preloaded; + bool __hybridService; + bool __verificationMode; + + Tizen::Base::String __inputPath; + InstallerOperation __operation; + InstallationStorage __storage; + + Tizen::Base::String __packagePath; + Tizen::Base::String __licensePath; + Tizen::Base::String __temporaryDir; + Tizen::Base::String __installDir; + Tizen::Base::String __workingDir; + Tizen::Base::String __packageId; + Tizen::Base::String __appVersion; + Tizen::Base::String __appRootPath; + + Tizen::Base::Collection::ArrayList* __pPrivilegeList; + Tizen::Base::Collection::ArrayList* __pLiveboxDataList; + Tizen::Base::Collection::ArrayList* __pContentDataList; + Tizen::Security::Cert::X509CertificatePath* __pAuthorCertPath; + Tizen::Security::Cert::X509CertificatePath* __pDistributorCertPath; + RootCertificateType __rootCertType; + + int __packageNameType; + app2ext_handle* __pApp2ExtHandle; + + Tizen::App::Package::_PackageInfoImpl* __pPackageInfoImpl; + +}; // InstallationContext + +#endif // _INSTALLATION_CONTEXT_H_ diff --git a/src/Context/InstallationContextData.cpp b/src/Context/InstallationContextData.cpp new file mode 100755 index 0000000..23b4d1c --- /dev/null +++ b/src/Context/InstallationContextData.cpp @@ -0,0 +1,255 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallationContextData.cpp + * @brief This is the implementation for the InstallationContextData class. + */ + +#include "InstallationContextData.h" + + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; +using namespace Tizen::Security::Cert; +using namespace Tizen::App::Package; + + +AppControlData::AppControlData() +:__pOperationList(null) +,__pMimeTypeList(null) +,__pUriList(null) + +{ + __pOperationList = new (std::nothrow) ArrayListT; + __pMimeTypeList = new (std::nothrow) ArrayListT; + __pUriList = new (std::nothrow) ArrayListT; +} + +AppControlData::~AppControlData() +{ + __pOperationList->RemoveAll(); + delete __pOperationList; + + __pMimeTypeList->RemoveAll(); + delete __pMimeTypeList; + + __pUriList->RemoveAll(); + delete __pUriList; +} + +AccountData::AccountData() +:__pNameList(null) +{ + __pNameList = new (std::nothrow) HashMap; + TryReturn(__pNameList, , "[osp-installer] __pNameList is null."); + __pNameList->Construct(); +} + +AccountData::~AccountData() +{ + __pNameList->RemoveAll(true); + delete __pNameList; +} + + +LiveboxData::LiveboxData(void) +:__updatePeriod(0) +,__pNameList(null) +,__pSizeList(null) +{ + __pNameList = new (std::nothrow) HashMap; + TryReturn(__pNameList, , "[osp-installer] __pNameList is null."); + __pNameList->Construct(); + + __pSizeList = new (std::nothrow) ArrayList; + TryReturn(__pSizeList, , "[osp-installer] __pSizeList is null."); + __pSizeList->Construct(); +} + +LiveboxData::~LiveboxData(void) +{ + __pNameList->RemoveAll(true); + delete __pNameList; + + __pSizeList->RemoveAll(true); + delete __pSizeList; +} + +result +LiveboxData::SetUpdatePeriod(long long period) +{ + __updatePeriod = period; + return E_SUCCESS; +} + +long long +LiveboxData::GetUpdatePeriod(void) const +{ + return __updatePeriod; +} + +result +LiveboxData::SetPopupEnabled(const String& value) +{ + __popupEnabled = value; + return E_SUCCESS; +} + +const String& +LiveboxData::GetPopupEnabled(void) const +{ + return __popupEnabled; +} + +result +LiveboxData::SetIcon(const String& icon) +{ + __icon = icon; + return E_SUCCESS; +} + +const String& +LiveboxData::GetIcon(void) const +{ + return __icon; +} + +result +LiveboxData::SetProviderName(const String& providerName) +{ + __providerName = providerName; + return E_SUCCESS; +} + +const String& +LiveboxData::GetProviderName(void) const +{ + return __providerName; +} + +result +LiveboxData::AddName(const String& language, const String& name) +{ + result r = E_SUCCESS; + + r = __pNameList->Add(language, name); + + return r; +} + +HashMap* +LiveboxData::GetNameList(void) const +{ + return __pNameList; +} + +result +LiveboxData::AddSize(const String& size) +{ + result r = E_SUCCESS; + + r = __pSizeList->Add(size); + + return r; +} + +ArrayList* +LiveboxData::GetSizeList(void) const +{ + return __pSizeList; +} + + +ContentData::ContentData(void) +:__pNameList(null) +{ + __pNameList = new (std::nothrow) HashMap; + TryReturn(__pNameList, , "[osp-installer] __pNameList is null."); + __pNameList->Construct(); +} + +ContentData::~ContentData(void) +{ + __pNameList->RemoveAll(true); + delete __pNameList; +} + +result +ContentData::SetContentId(const String& contentId) +{ + __contentId = contentId; + return E_SUCCESS; +} + +const String& +ContentData::GetContentId(void) const +{ + return __contentId; +} + +result +ContentData::SetIcon(const String& icon) +{ + __icon = icon; + return E_SUCCESS; +} + +const String& +ContentData::GetIcon(void) const +{ + return __icon; +} + +result +ContentData::AddName(const String& language, const String& name) +{ + result r = E_SUCCESS; + + r = __pNameList->Add(language, name); + + return r; +} + +HashMap* +ContentData::GetNameList(void) const +{ + return __pNameList; +} + +AppData::AppData() +:__pCategoryList(null) +,__pAccountDataList(null) +,__pAppControlDataList(null) +,__legacyAppControls(false) +{ + __pCategoryList = new (std::nothrow) ArrayListT; + __pAccountDataList = new (std::nothrow) ArrayListT; + __pAppControlDataList = new (std::nothrow) ArrayListT; +} + +AppData::~AppData() +{ + __pCategoryList->RemoveAll(); + delete __pCategoryList; + + __pAccountDataList->RemoveAll(); + delete __pAccountDataList; + + __pAppControlDataList->RemoveAll(); + delete __pAppControlDataList; +} diff --git a/src/Context/InstallationContextData.h b/src/Context/InstallationContextData.h new file mode 100755 index 0000000..e118ae4 --- /dev/null +++ b/src/Context/InstallationContextData.h @@ -0,0 +1,157 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallerContextData.h + * @brief This is the header file for the context data classes. + * + * This header file contains the declarations of the the context data classes. + */ +#ifndef _INSTALLATION_CONTEXT_DATA_H_ +#define _INSTALLATION_CONTEXT_DATA_H_ + +#include +#include + +#include "InstallerDefs.h" + +class LiveboxData + : public Tizen::Base::Object +{ +public: + LiveboxData(void); + virtual ~LiveboxData(void); + + result SetUpdatePeriod(long long period); + long long GetUpdatePeriod(void) const; + + result SetPopupEnabled(const Tizen::Base::String& value); + const Tizen::Base::String& GetPopupEnabled(void) const; + + result SetIcon(const Tizen::Base::String& icon); + const Tizen::Base::String& GetIcon(void) const; + + result SetProviderName(const Tizen::Base::String& providerName); + const Tizen::Base::String& GetProviderName(void) const; + + result AddName(const Tizen::Base::String& language, const Tizen::Base::String& name); + Tizen::Base::Collection::HashMap* GetNameList(void) const; + + result AddSize(const Tizen::Base::String& size); + Tizen::Base::Collection::ArrayList* GetSizeList(void) const; + + Tizen::Base::String __main; + Tizen::Base::String __configurationAppControlAppId; + +private: + LiveboxData(const LiveboxData& value); + LiveboxData& operator =(const LiveboxData& source); + + long long __updatePeriod; + Tizen::Base::String __popupEnabled; + Tizen::Base::String __icon; + Tizen::Base::String __providerName; + + Tizen::Base::Collection::HashMap* __pNameList; + Tizen::Base::Collection::ArrayList* __pSizeList; + +}; + + +class AccountData + : public Tizen::Base::Object +{ +public: + AccountData(); + virtual ~AccountData(); + + Tizen::Base::String __providerId; + Tizen::Base::String __multipleAccountsSupport; + Tizen::Base::String __accountIcon; + Tizen::Base::String __accountSmallIcon; + Tizen::Base::Collection::HashMap* __pNameList; +}; + + +class AppControlData + : public Tizen::Base::Object +{ +public: + AppControlData(); + virtual ~AppControlData(); + + Tizen::Base::Collection::IListT* __pOperationList; + Tizen::Base::Collection::IListT* __pMimeTypeList; + Tizen::Base::Collection::IListT* __pUriList; +}; + + +class ContentData + : public Tizen::Base::Object +{ +public: + ContentData(void); + virtual ~ContentData(void); + + result SetContentId(const Tizen::Base::String& contentId); + const Tizen::Base::String& GetContentId(void) const; + + result SetIcon(const Tizen::Base::String& icon); + const Tizen::Base::String& GetIcon(void) const; + + result AddName(const Tizen::Base::String& language, const Tizen::Base::String& name); + Tizen::Base::Collection::HashMap* GetNameList(void) const; + +private: + ContentData(const ContentData& value); + ContentData& operator =(const ContentData& source); + + Tizen::Base::String __icon; + Tizen::Base::String __contentId; + + Tizen::Base::Collection::HashMap* __pNameList; + +}; + + +class AppData + : public Tizen::Base::Object +{ +public: + AppData(); + virtual ~AppData(); + + Tizen::Base::String name; + Tizen::Base::Collection::IListT* __pCategoryList; + Tizen::Base::Collection::IListT* __pAccountDataList; + Tizen::Base::Collection::IListT* __pAppControlDataList; + + bool __legacyAppControls; + +private: +}; + + +class PackageData + : public Tizen::Base::Object +{ +public: + PackageData(){}; + virtual ~PackageData(){}; +}; + + +#endif // _INSTALLATION_CONTEXT_DATA_H_ diff --git a/src/Installer/DirectoryInstaller.cpp b/src/Installer/DirectoryInstaller.cpp new file mode 100755 index 0000000..6c3b347 --- /dev/null +++ b/src/Installer/DirectoryInstaller.cpp @@ -0,0 +1,191 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file DirectoryInstaller.cpp + * @brief This is the implementation file for %DirectoryInstaller class. + */ + +#include +#include +#include +#include + +#include "DirectoryInstaller.h" +#include "InstallerUtil.h" + +using namespace Tizen::App::Package; +using namespace Tizen::Base; +using namespace Tizen::Io; + +DirectoryInstaller::DirectoryInstaller(void) +{ +} + +DirectoryInstaller::~DirectoryInstaller(void) +{ +} + +InstallationStep +DirectoryInstaller::GetNext(InstallationStep step) +{ + if (step == INSTALLER_STEP_NONE) + { + return INSTALLER_STEP_INIT; + } + else if (step == INSTALLER_STEP_INIT) + { + return INSTALLER_STEP_CHECK_SYSTEM; + } + else if (step == INSTALLER_STEP_CHECK_SYSTEM) + { + return INSTALLER_STEP_PARSE_MANIFEST; + } + else if (step == INSTALLER_STEP_PARSE_MANIFEST) + { + return INSTALLER_STEP_PARSE_SIGNATURE; + } + else if (step == INSTALLER_STEP_PARSE_SIGNATURE) + { + return INSTALLER_STEP_END; + } + else + { + step = (InstallationStep)(step + 1); + return step; + } +} + +InstallerError +DirectoryInstaller::OnInit(void) +{ + AppLogTag(OSP_INSTALLER, "DirectoryInstaller::OnInit()"); + + InstallationContext* pContext = GetContext(); + String installPath = pContext->GetInstallDir(); + + String newInstallPath; + InstallerUtil::CreateSymlinkForAppDirectory(installPath, newInstallPath); + pContext->SetInstallDir(newInstallPath); + + _PackageInfoImpl *pPackageInfoImpl = null; + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + pPackageInfoImpl->SetAppRootPath(newInstallPath); + + // remove in /info/*.info files + RemoveInfoFiles(); + + AppLogTag(OSP_INSTALLER, "installation path = [%ls]", newInstallPath.GetPointer()); + + return Installer::OnInit(); +} + +InstallerError +DirectoryInstaller::OnRegister(void) +{ + AppLogTag(OSP_INSTALLER, "DirectoryInstaller::OnRegister()"); + return Installer::OnRegister(); +} + +InstallerError +DirectoryInstaller::OnEnd(void) +{ + AppLogTag(OSP_INSTALLER, "DirectoryInstaller::OnEnd()"); + return Installer::OnEnd(); +} + +InstallerError +DirectoryInstaller::OnError(void) +{ + AppLogTag(OSP_INSTALLER, "DirectoryInstaller::OnError()"); + return Installer::OnError(); +} + +InstallerError +DirectoryInstaller::OnRollback(void) +{ + AppLogTag(OSP_INSTALLER, "DirectoryInstaller::OnRollback()"); + return Installer::OnRollback(); +} + +InstallerError +DirectoryInstaller::OnUserCancel(void) +{ + AppLogTag(OSP_INSTALLER, "DirectoryInstaller::OnUserCancel()"); + return Installer::OnUserCancel(); +} + +bool +DirectoryInstaller::RemoveInfoFiles(void) +{ + Directory* pDir = null; + DirEnumerator* pDirEnum = null; + result r = E_SUCCESS; + int res = false; + String appid; + String path; + + _PackageInfoImpl* pPackageInfoImpl = null; + InstallationContext* pContext = null; + + pContext = GetContext(); + TryCatch(pContext, res = false, "[osp-installer] pContext is null"); + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryCatch(pPackageInfoImpl, res = false, "[osp-installer] pPackageInfoImpl is null"); + + path = pPackageInfoImpl->GetAppRootPath() + DIR_INFO; + + pDir = new (std::nothrow) Directory; // Allocate %Directory instance + TryCatch(pDir, res = false, "[osp-installer] pDir is null"); + + r = pDir->Construct(path); + TryCatch(!IsFailed(r), res = false, "[osp-installer] pDir->Construct() failed, path = [%ls]", path.GetPointer()); + + pDirEnum = pDir->ReadN(); + TryCatch(pDirEnum, res = false, "[osp-installer] pDirEnum is null"); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String entryDir = path; + entryDir += L"/"; + entryDir += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + + // check *.info file + if (_FileImpl::GetFileExtension(entryDir) == FILE_EXT_INFO) + { + AppLogTag(OSP_INSTALLER, "Request to delete info file = [%ls]\n", entryDir.GetPointer()); + InstallerUtil::Remove(entryDir); + } + } + + delete pDirEnum; + delete pDir; + return true; + +CATCH: + // delete pDirEnum; + delete pDir; + return false; +} diff --git a/src/Installer/DirectoryInstaller.h b/src/Installer/DirectoryInstaller.h new file mode 100644 index 0000000..6106332 --- /dev/null +++ b/src/Installer/DirectoryInstaller.h @@ -0,0 +1,58 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file DirectoryInstaller.h + * @brief This is the header file for the %DirectoryInstaller class. + * + * This header file contains the declarations of the %DirectoryInstaller class. + */ +#ifndef _DIRECTORY_INSTALLER_H_ +#define _DIRECTORY_INSTALLER_H_ + +#include "Installer.h" + +/** + * @class DirectoryInstaller + * @brief This class represents the class of DirectoryInstaller. + * @since 1.0 + * + * This class represents the class of DirectoryInstaller. + * + */ +class DirectoryInstaller + : public Installer +{ +public: + DirectoryInstaller(void); + virtual ~DirectoryInstaller(void); + + virtual InstallationStep GetNext(InstallationStep step); + + virtual InstallerError OnInit(void); + virtual InstallerError OnRegister(void); + virtual InstallerError OnEnd(void); + + virtual InstallerError OnError(void); + virtual InstallerError OnRollback(void); + virtual InstallerError OnUserCancel(void); + +private: + bool RemoveInfoFiles(void); + +}; // DirectoryInstaller + +#endif //_DIRECTORY_INSTALLER_H_ diff --git a/src/Installer/GuestInstaller.cpp b/src/Installer/GuestInstaller.cpp new file mode 100755 index 0000000..7483f45 --- /dev/null +++ b/src/Installer/GuestInstaller.cpp @@ -0,0 +1,79 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file GuestInstaller.cpp + * @brief This is the implementation for the %GuestInstaller class. + */ + +#include "GuestInstaller.h" + +GuestInstaller::GuestInstaller(void) +{ +} + +GuestInstaller::~GuestInstaller(void) +{ +} + +InstallationStep +GuestInstaller::GetNext(InstallationStep step) +{ + AppLogTag(OSP_INSTALLER, "GuestInstaller::GetNext()"); + return PackageInstaller::GetNext(step); +} + +InstallerError +GuestInstaller::OnInit(void) +{ + AppLogTag(OSP_INSTALLER, "GuestInstaller::OnInit()"); + return PackageInstaller::OnInit(); +} + +InstallerError +GuestInstaller::OnRegister(void) +{ + AppLogTag(OSP_INSTALLER, "GuestInstaller::OnRegister()"); + return PackageInstaller::OnRegister(); +} + +InstallerError +GuestInstaller::OnEnd(void) +{ + AppLogTag(OSP_INSTALLER, "GuestInstaller::OnEnd()"); + return PackageInstaller::OnEnd(); +} + +InstallerError +GuestInstaller::OnError(void) +{ + AppLogTag(OSP_INSTALLER, "GuestInstaller::OnError()"); + return PackageInstaller::OnError(); +} + +InstallerError +GuestInstaller::OnRollback(void) +{ + AppLogTag(OSP_INSTALLER, "GuestInstaller::OnRollback()"); + return PackageInstaller::OnRollback(); +} + +InstallerError +GuestInstaller::OnUserCancel(void) +{ + AppLogTag(OSP_INSTALLER, "GuestInstaller::OnUserCancel()"); + return PackageInstaller::OnUserCancel(); +} diff --git a/src/Installer/GuestInstaller.h b/src/Installer/GuestInstaller.h new file mode 100644 index 0000000..0ebdd42 --- /dev/null +++ b/src/Installer/GuestInstaller.h @@ -0,0 +1,55 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file GuestInstaller.h + * @brief This is the header file for the %GuestInstaller class. + * + * This header file contains the declarations of the %GuestInstaller class. + */ +#ifndef _GUEST_INSTALLER_H_ +#define _GUEST_INSTALLER_H_ + +#include "PackageInstaller.h" + +/** + * @class GuestInstaller + * @brief This class represents the class of GuestInstaller. + * @since 1.0 + * + * This class represents the class of GuestInstaller. + * + */ +class GuestInstaller + : public PackageInstaller +{ +public: + GuestInstaller(void); + virtual ~GuestInstaller(void); + + virtual InstallationStep GetNext(InstallationStep step); + + virtual InstallerError OnInit(void); + virtual InstallerError OnRegister(void); + virtual InstallerError OnEnd(void); + + virtual InstallerError OnError(void); + virtual InstallerError OnRollback(void); + virtual InstallerError OnUserCancel(void); + +}; // GuestInstaller + +#endif //_GUEST_INSTALLER_H_ diff --git a/src/Installer/IDEInstaller.cpp b/src/Installer/IDEInstaller.cpp new file mode 100755 index 0000000..9cbd8fe --- /dev/null +++ b/src/Installer/IDEInstaller.cpp @@ -0,0 +1,79 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file IDEInstaller.cpp + * @brief This is the implementation file for %IDEInstaller class. + */ + +#include "IDEInstaller.h" + +IDEInstaller::IDEInstaller(void) +{ +} + +IDEInstaller::~IDEInstaller(void) +{ +} + +InstallationStep +IDEInstaller::GetNext(InstallationStep step) +{ + AppLogTag(OSP_INSTALLER, "IDEInstaller::GetNext()"); + return DirectoryInstaller::GetNext(step); +} + +InstallerError +IDEInstaller::OnInit(void) +{ + AppLogTag(OSP_INSTALLER, "IDEInstaller::OnInit()"); + return DirectoryInstaller::OnInit(); +} + +InstallerError +IDEInstaller::OnRegister(void) +{ + AppLogTag(OSP_INSTALLER, "IDEInstaller::OnRegister()"); + return DirectoryInstaller::OnRegister(); +} + +InstallerError +IDEInstaller::OnEnd(void) +{ + AppLogTag(OSP_INSTALLER, "IDEInstaller::OnEnd()"); + return DirectoryInstaller::OnEnd(); +} + +InstallerError +IDEInstaller::OnError(void) +{ + AppLogTag(OSP_INSTALLER, "IDEInstaller::OnError()"); + return DirectoryInstaller::OnError(); +} + +InstallerError +IDEInstaller::OnUserCancel(void) +{ + AppLogTag(OSP_INSTALLER, "IDEInstaller::OnUserCancel()"); + return DirectoryInstaller::OnUserCancel(); +} + +InstallerError +IDEInstaller::OnRollback(void) +{ + AppLogTag(OSP_INSTALLER, "IDEInstaller::OnRollback()"); + return DirectoryInstaller::OnRollback(); +} diff --git a/src/Installer/IDEInstaller.h b/src/Installer/IDEInstaller.h new file mode 100644 index 0000000..0218d4d --- /dev/null +++ b/src/Installer/IDEInstaller.h @@ -0,0 +1,55 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file IDEInstaller.h + * @brief This is the header file for the %IDEInstaller class. + * + * This header file contains the declarations of the %IDEInstaller class. + */ +#ifndef _IDE_INSTALLER_H_ +#define _IDE_INSTALLER_H_ + +#include "DirectoryInstaller.h" + +/** + * @class IDEInstaller + * @brief This class represents the class of IDEInstaller. + * @since 1.0 + * + * This class represents the class of IDEInstaller. + * + */ +class IDEInstaller + : public DirectoryInstaller +{ +public: + IDEInstaller(void); + virtual ~IDEInstaller(void); + + virtual InstallationStep GetNext(InstallationStep step); + + virtual InstallerError OnInit(void); + virtual InstallerError OnRegister(void); + virtual InstallerError OnEnd(void); + + virtual InstallerError OnError(void); + virtual InstallerError OnRollback(void); + virtual InstallerError OnUserCancel(void); + +}; // IDEInstaller + +#endif //_IDE_INSTALLER_H_ diff --git a/src/Installer/Installer.cpp b/src/Installer/Installer.cpp new file mode 100755 index 0000000..fb10659 --- /dev/null +++ b/src/Installer/Installer.cpp @@ -0,0 +1,204 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file Installer.cpp + * @brief This is the implementation file for %Installer class. + */ + +#include +#include + +#include +#include +#include +#include + +#include "Installer.h" +#include "PermissionManager.h" +#include "ConfigurationManager.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::App::Package; +using namespace Tizen::Io; + +Installer::Installer(void) +:__pContext(null) +{ +} + +Installer::~Installer(void) +{ +} + +InstallerError +Installer::Construct(InstallationContext* pContext) +{ + __pContext = pContext; + + if (InstallerUtil::IsSymlink(PATH_OPT_APPS) == false) + { + if (File::IsFileExist(PATH_OPT_APPS) == false) + { + Directory::Create(PATH_OPT_APPS, false); + InstallerUtil::ChangeMode(PATH_OPT_APPS, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + } + + if (File::IsFileExist(PATH_OPT_USR) == false) + { + Directory::Create(PATH_OPT_USR, false); + InstallerUtil::ChangeMode(PATH_OPT_USR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + if (File::IsFileExist(PATH_OPT_USR_APPS) == false) + { + Directory::Create(PATH_OPT_USR_APPS, false); + InstallerUtil::ChangeMode(PATH_OPT_USR_APPS, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + return INSTALLER_ERROR_NONE; +} + +InstallationStep +Installer::GetNext(InstallationStep step) +{ + if (step == INSTALLER_STEP_PARSE_SIGNATURE) + { + step = INSTALLER_STEP_END; + } + else + { + step = (InstallationStep)(step + 1); + } + + return step; +} + +InstallerError +Installer::OnInit(void) +{ + AppLogTag(OSP_INSTALLER, "Installer::OnInit()"); + + return INSTALLER_ERROR_NONE; +} + +InstallerError +Installer::OnRegister(void) +{ + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "Installer::OnRegister() - START"); + InstallationContext* pContext = GetContext(); + TryReturn(pContext, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pContext is null"); + + InstallerOperation operation = pContext->GetInstallerOperation(); + + _PackageManagerImpl *pManagerImpl = null; + pManagerImpl = pManagerImpl->GetInstance(); + TryReturn(pManagerImpl, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pManagerImpl is null"); + + if (operation == INSTALLER_OPERATION_INSTALL) + { + pManagerImpl->UnregisterPackageInfo(pContext->GetId()); + pManagerImpl->RegisterPackageInfo(*pContext->GetPackageInfoImpl()); + } + else + { + pManagerImpl->UnregisterPackageInfo(pContext->GetId()); + } + AppLogTag(OSP_INSTALLER, "Installer::OnRegister() - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + return INSTALLER_ERROR_NONE; +} + +InstallerError +Installer::OnEnd(void) +{ + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "Installer::OnEnd() - START"); + InstallationContext* pContext = GetContext(); + TryReturn(pContext, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pContext is null"); + + InstallerOperation operation = pContext->GetInstallerOperation(); + ConfigurationManager configurationManager; + + pContext->SetContinue(false); + + if (operation == INSTALLER_OPERATION_INSTALL) + { + PermissionManager::SetDirectory(pContext); + PermissionManager::SetFile(pContext); + + configurationManager.CreateFile(pContext); + configurationManager.UnregisterCertInfo(pContext); + configurationManager.RegisterCertInfo(pContext); + configurationManager.PostInstall(pContext, false); + } + else if (operation == INSTALLER_OPERATION_UNINSTALL) + { + configurationManager.RemoveFile(pContext); + configurationManager.UnregisterCertInfo(pContext); + configurationManager.PostUninstall(pContext); + } + + AppLogTag(OSP_INSTALLER, "Installer::OnEnd() - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + return INSTALLER_ERROR_NONE; +} + +InstallerError +Installer::OnError(void) +{ + AppLogTag(OSP_INSTALLER, "Installer::OnError()"); + + InstallerOperation operation = __pContext->GetInstallerOperation(); + ConfigurationManager configurationManager; + + if (operation == INSTALLER_OPERATION_INSTALL) + { + configurationManager.PostInstall(__pContext, true); + } + else + { + configurationManager.PostUninstall(__pContext); + } + + return INSTALLER_ERROR_NONE; +} + +InstallerError +Installer::OnRollback(void) +{ + AppLogTag(OSP_INSTALLER, "Installer::OnRollback()"); + return INSTALLER_ERROR_NONE; +} + +InstallerError +Installer::OnUserCancel(void) +{ + AppLogTag(OSP_INSTALLER, "Installer::OnUserCancel()"); + return INSTALLER_ERROR_NONE; +} + +InstallationContext* +Installer::GetContext(void) +{ + return __pContext; +} diff --git a/src/Installer/Installer.h b/src/Installer/Installer.h new file mode 100644 index 0000000..c131e33 --- /dev/null +++ b/src/Installer/Installer.h @@ -0,0 +1,62 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file Installer.h + * @brief This is the header file for the %Installer class. + * + * This header file contains the declarations of the %Installer class. + */ +#ifndef _INSTALLER_H_ +#define _INSTALLER_H_ + +#include "InstallerDefs.h" +#include "InstallationContext.h" + +/** + * @class Installer + * @brief This class represents the class of Installer. + * @since 1.0 + * + * This class represents the class of Installer. + * + */ +class Installer +{ +public: + Installer(void); + virtual InstallerError Construct(InstallationContext* pContext); + virtual ~Installer(void); + + virtual InstallationStep GetNext(InstallationStep step); + + virtual InstallerError OnInit(void); + virtual InstallerError OnRegister(void); + virtual InstallerError OnEnd(void); + + virtual InstallerError OnError(void); + virtual InstallerError OnRollback(void); + virtual InstallerError OnUserCancel(void); + +protected: + InstallationContext* GetContext(void); + +private: + InstallationContext* __pContext; + +}; // Installer + +#endif // _INSTALLER_H_ diff --git a/src/Installer/PackageInstaller.cpp b/src/Installer/PackageInstaller.cpp new file mode 100644 index 0000000..54317c1 --- /dev/null +++ b/src/Installer/PackageInstaller.cpp @@ -0,0 +1,85 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PackageInstaller.cpp + * @brief This is the implementation file for %PackageInstaller class. + */ + +#include + +#include "InstallerDefs.h" +#include "PackageInstaller.h" + +using namespace Tizen::Io; + +PackageInstaller::PackageInstaller(void) +{ +} + +PackageInstaller::~PackageInstaller(void) +{ +} + +InstallationStep +PackageInstaller::GetNext(InstallationStep step) +{ + return Installer::GetNext(step); +} + +InstallerError +PackageInstaller::OnInit(void) +{ + AppLogTag(OSP_INSTALLER, "PackageInstaller::OnInit()"); + return Installer::OnInit(); +} + +InstallerError +PackageInstaller::OnRegister(void) +{ + AppLogTag(OSP_INSTALLER, "PackageInstaller::OnRegister()"); + return Installer::OnRegister(); +} + +InstallerError +PackageInstaller::OnEnd(void) +{ + AppLogTag(OSP_INSTALLER, "PackageInstaller::OnEnd()"); + + return Installer::OnEnd(); +} + +InstallerError +PackageInstaller::OnError(void) +{ + AppLogTag(OSP_INSTALLER, "PackageInstaller::OnError()"); + + return Installer::OnError(); +} + +InstallerError +PackageInstaller::OnRollback(void) +{ + AppLogTag(OSP_INSTALLER, "PackageInstaller::OnRollback()"); + return Installer::OnRollback(); +} + +InstallerError +PackageInstaller::OnUserCancel(void) +{ + AppLogTag(OSP_INSTALLER, "PackageInstaller::OnUserCancel()"); + return Installer::OnUserCancel(); +} diff --git a/src/Installer/PackageInstaller.h b/src/Installer/PackageInstaller.h new file mode 100644 index 0000000..8d6c71f --- /dev/null +++ b/src/Installer/PackageInstaller.h @@ -0,0 +1,55 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PackageInstaller.h + * @brief This is the header file for the %PackageInstaller class. + * + * This header file contains the declarations of the %PackageInstaller class. + */ +#ifndef _PACKAGE_INSTALLER_H_ +#define _PACKAGE_INSTALLER_H_ + +#include "Installer.h" + +/** + * @class PackageInstaller + * @brief This class represents the class of PackageInstaller. + * @since 1.0 + * + * This class represents the class of PackageInstaller. + * + */ +class PackageInstaller + : public Installer +{ +public: + PackageInstaller(void); + virtual ~PackageInstaller(void); + + virtual InstallationStep GetNext(InstallationStep step); + + virtual InstallerError OnInit(void); + virtual InstallerError OnRegister(void); + virtual InstallerError OnEnd(void); + + virtual InstallerError OnError(void); + virtual InstallerError OnRollback(void); + virtual InstallerError OnUserCancel(void); + +}; // PackageInstaller + +#endif // _PACKAGE_INSTALLER_H_ diff --git a/src/Installer/PreloadedInstaller.cpp b/src/Installer/PreloadedInstaller.cpp new file mode 100755 index 0000000..948c8a5 --- /dev/null +++ b/src/Installer/PreloadedInstaller.cpp @@ -0,0 +1,156 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PreloadedInstaller.cpp + * @brief This is the implementation file for %PreloadedInstaller class. + */ + +#include +#include +#include + +#include "PreloadedInstaller.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Io; + +PreloadedInstaller::PreloadedInstaller(void) +{ +} + +PreloadedInstaller::~PreloadedInstaller(void) +{ +} + +InstallationStep +PreloadedInstaller::GetNext(InstallationStep step) +{ + AppLogTag(OSP_INSTALLER, "PreloadedInstaller::GetNext()"); + return DirectoryInstaller::GetNext(step); +} + +InstallerError +PreloadedInstaller::OnInit(void) +{ + AppLogTag(OSP_INSTALLER, "PreloadedInstaller::OnInit()"); + + InstallationContext* pContext = GetContext(); + String path = pContext->GetInputPath(); + + String appId; + String prefix(PATH_USR_APPS); + prefix += L"/"; + + path.SubString(prefix.GetLength(), APPID_LENGTH, appId); + + String destRootPath(PATH_OPT_USR_APPS); + destRootPath += L"/"; + destRootPath += appId; + + InstallerUtil::Remove(destRootPath); + Directory::Create(destRootPath); + + String srcPath; + String destPath; + + // /data + srcPath = path + DIR_DATA; + destPath = destRootPath + DIR_DATA; + InstallerUtil::CopyDirectory(srcPath, destPath); + + // /info + srcPath = path + DIR_INFO; + destPath = destRootPath + DIR_INFO; + InstallerUtil::CopyDirectory(srcPath, destPath); + + // appRoot - signature + + srcPath = path + DIR_BIN; + destPath = destRootPath + DIR_BIN; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_RES; + destPath = destRootPath + DIR_RES; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_LIB; + destPath = destRootPath + DIR_LIB; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_SHARED; + destPath = destRootPath + DIR_SHARED; + if (File::IsFileExist(srcPath) == true) + { + InstallerUtil::CopyDirectory(srcPath, destPath); + } + else + { + Directory::Create(destPath); + } + + srcPath += DIR_RES; + destPath += DIR_RES; + if (File::IsFileExist(destPath) == false) + { + srcPath = path + DIR_ICONS; + InstallerUtil::CreateSymlink(srcPath, destPath); + } + + srcPath = path + DIR_SETTING; + destPath = destRootPath + DIR_SETTING; + InstallerUtil::CreateSymlink(srcPath, destPath); + + pContext->SetInstallDir(destRootPath); + + return DirectoryInstaller::OnInit(); +} + +InstallerError +PreloadedInstaller::OnRegister(void) +{ + AppLogTag(OSP_INSTALLER, "PreloadedInstaller::OnRegister()"); + return DirectoryInstaller::OnRegister(); +} + +InstallerError +PreloadedInstaller::OnEnd(void) +{ + AppLogTag(OSP_INSTALLER, "PreloadedInstaller::OnEnd()"); + return DirectoryInstaller::OnEnd(); +} + +InstallerError +PreloadedInstaller::OnError(void) +{ + AppLogTag(OSP_INSTALLER, "PreloadedInstaller::OnError()"); + return DirectoryInstaller::OnError(); +} + +InstallerError +PreloadedInstaller::OnRollback(void) +{ + AppLogTag(OSP_INSTALLER, "PreloadedInstaller::OnRollback()"); + return DirectoryInstaller::OnRollback(); +} + +InstallerError +PreloadedInstaller::OnUserCancel(void) +{ + AppLogTag(OSP_INSTALLER, "PreloadedInstaller::OnUserCancel()"); + return DirectoryInstaller::OnUserCancel(); +} diff --git a/src/Installer/PreloadedInstaller.h b/src/Installer/PreloadedInstaller.h new file mode 100644 index 0000000..a19eb44 --- /dev/null +++ b/src/Installer/PreloadedInstaller.h @@ -0,0 +1,55 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PreloadedInstaller.h + * @brief This is the header file for the %PreloadedInstaller class. + * + * This header file contains the declarations of the %PreloadedInstaller class. + */ +#ifndef _PRELOADED_INSTALLER_H_ +#define _PRELOADED_INSTALLER_H_ + +#include "DirectoryInstaller.h" + +/** + * @class PreloadedInstaller + * @brief This class represents the class of PreloadedInstaller. + * @since 1.0 + * + * This class represents the class of PreloadedInstaller. + * + */ +class PreloadedInstaller + : public DirectoryInstaller +{ +public: + PreloadedInstaller(void); + virtual ~PreloadedInstaller(void); + + virtual InstallationStep GetNext(InstallationStep step); + + virtual InstallerError OnInit(void); + virtual InstallerError OnRegister(void); + virtual InstallerError OnEnd(void); + + virtual InstallerError OnError(void); + virtual InstallerError OnRollback(void); + virtual InstallerError OnUserCancel(void); + +}; // PreloadedInstaller + +#endif // _PRELOADED_INSTALLER_H_ diff --git a/src/Installer/RestorationInstaller.cpp b/src/Installer/RestorationInstaller.cpp new file mode 100755 index 0000000..26ce8e6 --- /dev/null +++ b/src/Installer/RestorationInstaller.cpp @@ -0,0 +1,79 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file RestorationInstaller.cpp + * @brief This is the implementation file for %RestorationInstaller class. + */ + +#include "RestorationInstaller.h" + +RestorationInstaller::RestorationInstaller(void) +{ +} + +RestorationInstaller::~RestorationInstaller(void) +{ +} + +InstallationStep +RestorationInstaller::GetNext(InstallationStep step) +{ + AppLogTag(OSP_INSTALLER, "RestorationInstaller::GetNext()"); + return DirectoryInstaller::GetNext(step); +} + +InstallerError +RestorationInstaller::OnInit(void) +{ + AppLogTag(OSP_INSTALLER, "RestorationInstaller::OnInit()"); + return DirectoryInstaller::OnInit(); +} + +InstallerError +RestorationInstaller::OnRegister(void) +{ + AppLogTag(OSP_INSTALLER, "RestorationInstaller::OnRegister()"); + return DirectoryInstaller::OnRegister(); +} + +InstallerError +RestorationInstaller::OnEnd(void) +{ + AppLogTag(OSP_INSTALLER, "RestorationInstaller::OnEnd()"); + return DirectoryInstaller::OnEnd(); +} + +InstallerError +RestorationInstaller::OnError(void) +{ + AppLogTag(OSP_INSTALLER, "RestorationInstaller::OnError()"); + return DirectoryInstaller::OnError(); +} + +InstallerError +RestorationInstaller::OnRollback(void) +{ + AppLogTag(OSP_INSTALLER, "RestorationInstaller::OnRollback()"); + return DirectoryInstaller::OnRollback(); +} + +InstallerError +RestorationInstaller::OnUserCancel(void) +{ + AppLogTag(OSP_INSTALLER, "RestorationInstaller::OnUserCancel()"); + return DirectoryInstaller::OnUserCancel(); +} diff --git a/src/Installer/RestorationInstaller.h b/src/Installer/RestorationInstaller.h new file mode 100644 index 0000000..baca42d --- /dev/null +++ b/src/Installer/RestorationInstaller.h @@ -0,0 +1,55 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file RestorationInstaller.h + * @brief This is the header file for the %RestorationInstaller class. + * + * This header file contains the declarations of the %RestorationInstaller class. + */ +#ifndef _RESTORATION_INSTALLER_H_ +#define _RESTORATION_INSTALLER_H_ + +#include "DirectoryInstaller.h" + +/** + * @class RestorationInstaller + * @brief This class represents the class of RestorationInstaller. + * @since 1.0 + * + * This class represents the class of RestorationInstaller. + * + */ +class RestorationInstaller + : public DirectoryInstaller +{ +public: + RestorationInstaller(void); + virtual ~RestorationInstaller(void); + + virtual InstallationStep GetNext(InstallationStep step); + + virtual InstallerError OnInit(void); + virtual InstallerError OnRegister(void); + virtual InstallerError OnEnd(void); + + virtual InstallerError OnError(void); + virtual InstallerError OnRollback(void); + virtual InstallerError OnUserCancel(void); + +}; // RestorationInstaller + +#endif //_RESTORATION_INSTALLER_H_ diff --git a/src/Manager/ConfigurationManager.cpp b/src/Manager/ConfigurationManager.cpp new file mode 100755 index 0000000..b29dd49 --- /dev/null +++ b/src/Manager/ConfigurationManager.cpp @@ -0,0 +1,796 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ConfigurationManager.cpp + * @brief This is the implementation file for %ConfigurationManager class. + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ConfigurationManager.h" +#include "ManifestGenerator.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::Security::Cert; +using namespace Tizen::App; +using namespace Tizen::App::Package; +using namespace Tizen::Io; + +ConfigurationManager::ConfigurationManager(void) +{ +} + +ConfigurationManager::~ConfigurationManager(void) +{ +} + +bool +ConfigurationManager::CreateFile(InstallationContext* pContext) +{ + bool res = false; + const char* pBinaryPath = null; + String xmlPath; + char* pXmlPath = null; + int err = 0; + bool hybridService = pContext->IsHybridService(); + ArrayList* pContentDataList = null; + + _PackageInfoImpl *pPackageInfoImpl = null; + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, false, "[osp-installer] pPackageInfoImpl is null."); + + String rootPath; + rootPath = pPackageInfoImpl->GetAppRootPath(); + + String apiVersion; + apiVersion = pPackageInfoImpl->GetAppApiVersion(); + String versionInfoFile; + versionInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), VERSION_INFO_FILE); + CreateInfoFile(versionInfoFile, &apiVersion); + + if (pContext->__isOspCompat == true) + { + AppLogTag(OSP_INSTALLER, "[OspCompat] is detected"); + + String compatInfoFile; + compatInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), COMPAT_INFO_FILE); + CreateInfoFile(compatInfoFile, null); + } + + String webServicePrivilege(TIZEN_PRIVILEGE_WEB_SERVICE); + if (FindPrivilege(pContext, webServicePrivilege) == true) + { + AppLogTag(OSP_INSTALLER, "WEB_SERVICE privilege is detected. rootPath=[%ls]", rootPath.GetPointer()); + + String webServiceInfoFile; + webServiceInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), WEBSERVICE_INFO_FILE); + CreateInfoFile(webServiceInfoFile, null); + } + + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + pAppList = pPackageInfoImpl->GetAppInfoList(); + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + result r = E_SUCCESS; + + String appName; + appName = pAppInfoImpl->GetName(); + + String appType; + appType = pAppInfoImpl->GetType(); + + String packageName; + packageName = pAppInfoImpl->GetPackageName(); + + String binaryPath; + binaryPath.Format(1024, L"%ls%ls/%ls", rootPath.GetPointer(), DIR_BIN, appName.GetPointer()); + + String tempBinaryPath; + tempBinaryPath.Format(1024, L"%ls%ls/.%ls", rootPath.GetPointer(), DIR_BIN, appName.GetPointer()); + + pBinaryPath = _StringConverter::CopyToCharArrayN(binaryPath); + TryCatch(pBinaryPath, res = false, "[osp-installer] pBinaryPath is null"); + + if (File::IsFileExist(binaryPath) == true) + { + InstallerUtil::Remove(binaryPath); + } + + if (appType == L"UiApp") + { + //err = symlink(UIAPP_LOADER_PATH, pBinaryPath); + + //r = File::Copy(UIAPP_LOADER_PATH, pBinaryPath, false); + //TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed[%s], filePath=[%s]", GetErrorMessage(r), pBinaryPath); + + InstallerUtil::Copy(UIAPP_LOADER_PATH, binaryPath); + InstallerUtil::Copy(UIAPP_LOADER_PATH, tempBinaryPath); + + ArrayList* pFeatureList = pAppInfoImpl->GetAppFeatureList(); + TryCatch(pFeatureList, res = false, "[osp-installer] pFeatureList is null"); + + String coordinateSystem; + String baseScreenSize; + String logicalCoordinate; + + for (int j = 0; j < pFeatureList->GetCount(); j++) + { + _AppFeatureInfoImpl* pAppFeature = dynamic_cast<_AppFeatureInfoImpl*>(pFeatureList->GetAt(j)); + + if (pAppFeature != null) + { + if (pAppFeature->GetName() == L"CoordinateSystem") + { + coordinateSystem = pAppFeature->GetValue(); + } + + if (pAppFeature->GetName() == L"BaseScreenSize") + { + baseScreenSize = pAppFeature->GetValue(); + } + + if (pAppFeature->GetName() == L"LogicalCoordinate") + { + logicalCoordinate = pAppFeature->GetValue(); + } + } + } + + String uiScalability; + uiScalability.Format(1024, UISCALABILITY_INFO, coordinateSystem.GetPointer(), baseScreenSize.GetPointer(), logicalCoordinate.GetPointer()); + + String uiScalabilityInfoFile; + uiScalabilityInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), UISCALABILITY_INFO_FILE); + + CreateInfoFile(uiScalabilityInfoFile, &uiScalability); + + int categoryType = pAppInfoImpl->GetAppFeature(); + if (categoryType != CATEGORY_TYPE_NONE) + { + String category = InstallerUtil::GetCategory(categoryType); + category.ToLowerCase(); + + int type = _Aul::GetAppType(category); + + if (category == L"ime") + { + CreateImeSymlink(binaryPath, packageName); + } + + String typeInfo; + typeInfo.Format(1024, L"%d", type); + + String typeInfoFile; + typeInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), TYPE_INFO_FILE); + + CreateInfoFile(typeInfoFile, &typeInfo); + } + } + else if (appType == L"ServiceApp") + { + if (pContext->IsPreloaded() == false) + { + //err = symlink(SERVICEAPP_LOADER_PATH, pBinaryPath); + + InstallerUtil::Copy(SERVICEAPP_LOADER_PATH, tempBinaryPath); + InstallerUtil::Copy(SERVICEAPP_LOADER_PATH, binaryPath); + + //r = File::Copy(SERVICEAPP_LOADER_PATH, pBinaryPath, false); + //TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed[%s], filePath=[%s]", GetErrorMessage(r), pBinaryPath); + } + else + { + //err = symlink(SYSTEMAPP_LOADER_PATH, pBinaryPath); + + InstallerUtil::Copy(SYSTEMAPP_LOADER_PATH, tempBinaryPath); + InstallerUtil::Copy(SERVICEAPP_LOADER_PATH, binaryPath); + + //r = File::Copy(SYSTEMAPP_LOADER_PATH, pBinaryPath, false); + //TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed[%s], filePath=[%s]", GetErrorMessage(r), pBinaryPath); + } + } + + InstallerUtil::ChangeMode(pBinaryPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + + delete[] pBinaryPath; + pBinaryPath = null; + } + } + + pContentDataList = pContext->GetContentDataList(); + if (pContentDataList) + { + int contentCount = pContentDataList->GetCount(); + for (int i = 0 ; i < contentCount; i++) + { + ContentData* pContentData = static_cast(pContentDataList->GetAt(i)); + if (pContentData) + { + String contentId = pContentData->GetContentId(); + String oldPath = rootPath + DIR_CONTENTS + L"/" + contentId; + + if (File::IsFileExist(SLP_FONT_PATH) == false) + { + Directory::Create(SLP_FONT_PATH, false); + InstallerUtil::ChangeMode(SLP_FONT_PATH, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + String newPath = SLP_FONT_PATH; + newPath += L"/" + pContext->GetId(); + Directory::Create(newPath, false); + InstallerUtil::ChangeMode(newPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + + newPath += L"/"; + newPath += contentId; + InstallerUtil::CreateSymlink(oldPath, newPath); + } + } + } + + //if (pContext->IsPreloaded() == true) + //{ + // xmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, pContext->GetId().GetPointer()); + //} + //else + //{ + xmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, pContext->GetId().GetPointer()); + //} + + pXmlPath = _StringConverter::CopyToCharArrayN(xmlPath); + TryCatch(pXmlPath != null, res = false, "[osp-installer] pXmlPath is null"); + + if (hybridService == true) + { + String webXmlPath = pXmlPath; + webXmlPath += L".wgt"; + InstallerUtil::Copy(pXmlPath, webXmlPath); + + pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath, null); + CreateSystemXmlFile(pContext); + + String serviceXmlPath = pXmlPath; + serviceXmlPath += L".tpk"; + InstallerUtil::Copy(pXmlPath, serviceXmlPath); + InstallerUtil::Remove(pXmlPath); + + MergeToSystemXmlFile(pXmlPath, webXmlPath, serviceXmlPath); + InstallerUtil::Remove(webXmlPath); + InstallerUtil::Remove(serviceXmlPath); + } + else + { + pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath, null); + CreateSystemXmlFile(pContext); + } + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "sync() - START"); + sync(); + AppLogTag(OSP_INSTALLER, "sync() - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() - START"); + err = pkgmgr_parser_parse_manifest_for_installation(pXmlPath, null); + if (err != 0) + { + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() is failed. error = [%d][%s]", err, pXmlPath); + } + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + res = true; + +CATCH: + delete[] pBinaryPath; + delete[] pXmlPath; + + return res; +} + +bool +ConfigurationManager::RemoveFile(InstallationContext* pContext) +{ + String xmlPath; + char* pXmlPath = null; + _PackageInfoImpl *pPackageInfoImpl = null; + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + + //if (pContext->IsPreloaded() == true) + //{ + // xmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, pContext->GetId().GetPointer()); + //} + //else + //{ + xmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, pContext->GetId().GetPointer()); + //} + + pXmlPath = _StringConverter::CopyToCharArrayN(xmlPath); + TryCatch(pXmlPath != null, , "[osp-installer] pXmlPath is null"); + + if (pContext->IsHybridService() == true) + { + AppLogTag(OSP_INSTALLER, "Uninstallation for HybridService - skip"); + + } + else + { + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_uninstallation() START"); + if (pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath, null) != 0) + { + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_uninstallation() is failed.[%s]", pXmlPath); + } + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_uninstallation() END"); + + InstallerUtil::Remove(xmlPath); + } + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryCatch(pPackageInfoImpl, , "[osp-installer] pPackageInfoImpl is null."); + + pAppList = pPackageInfoImpl->GetAppInfoList(); + + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + String packageName = pAppInfoImpl->GetPackageName(); + String destPath; + char dest[772] = {0}; + + destPath.Format(1024, L"%ls/%ls", SLP_APP_PATH, packageName.GetPointer()); + sprintf(dest, "%ls", destPath.GetPointer()); + unlink(dest); + } + } + +CATCH: + delete[] pXmlPath; + + return true; +} + +bool +ConfigurationManager::RegisterCertInfo(InstallationContext* pContext) const +{ + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "RegisterCertInfo - START"); + + int res = 0; + bool result = true; + pkgmgr_instcertinfo_h handle = null; + String appId = pContext->GetId(); + X509CertificatePath* pAuthorCertPath = pContext->GetAuthorCertPath(); + X509CertificatePath* pDistributorCertPath = pContext->GetDistributorCertPath(); + + char* pAppId = _StringConverter::CopyToCharArrayN(appId); + TryCatch(pAppId, result = false, "[osp-installer] pAppId is null"); + + res = pkgmgr_installer_create_certinfo_set_handle(&handle); + TryCatch(res == 0, result = false, "[osp-installer] pkgmgr_installer_create_certinfo_set_handle() failed.[%d]", res); + + if (pAuthorCertPath) + { + AppLogTag(OSP_INSTALLER, "[AuthorCert]"); + result = SetCertHashValue(handle, pAuthorCertPath, PM_SET_AUTHOR_SIGNER_CERT); + TryCatch(result == true, , "[osp-installer] RegisterCertHashValue() failed. [pAuthorCertPath]"); + } + + if (pDistributorCertPath) + { + AppLogTag(OSP_INSTALLER, "[DistributorCert]"); + result = SetCertHashValue(handle, pDistributorCertPath, PM_SET_DISTRIBUTOR_SIGNER_CERT); + TryCatch(result == true, , "[osp-installer] RegisterCertHashValue() failed. [pDistributorCertPath]"); + } + + res = pkgmgr_installer_save_certinfo(pAppId, handle); + TryCatch(res == 0, result = false, "[osp-installer] pkgmgr_installer_save_certinfo(%s) failed.[%d]", pAppId, res); + + AppLogTag(OSP_INSTALLER, "RegisterCertInfo - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + +CATCH: + if (handle) + { + pkgmgr_installer_destroy_certinfo_set_handle(handle); + } + + delete[] pAppId; + return result; +} + +bool +ConfigurationManager::SetCertHashValue(void* pHandle, X509CertificatePath* pCertPath, int certType) const +{ + TryReturn(pCertPath, false, "[osp-installer] pCertPath is null."); + + int res = 0; + bool result = true; + ICertificate* pCert = null; + char* pCertValue = null; + + for (int i = 0; i < pCertPath->GetLength(); i++) + { + pCert = pCertPath->GetCertificateN(i); + TryCatch(pCert, result = false, "[osp-installer] pCert is null.[%i]", i); + + pCertValue = GetCertValueN(pCert); + TryCatch(pCertValue, result = false, "[osp-installer] pCertValue is null.[%i]", i); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "CertValue(%d), certType[%d]", i, certType); + AppLogTag(OSP_INSTALLER, "[%s]", pCertValue); + + res = pkgmgr_installer_set_cert_value(pHandle, (pkgmgr_instcert_type)certType, pCertValue); + TryCatch(res == 0, result = false, "[osp-installer] pkgmgr_installer_set_cert_value(%d) failed.[%d]", i, res); + + delete pCert; + pCert = null; + delete[] pCertValue; + pCertValue = null; + + certType--; + } + +CATCH: + delete pCert; + delete[] pCertValue; + + return result; +} + +char* +ConfigurationManager::GetCertValueN(ICertificate* pCert) const +{ + result r = E_SUCCESS; + ByteBuffer* pEncodedData = null; + String base64Value; + char* pEncodedValue = null; + + pEncodedData = pCert->GetEncodedDataN(); + TryCatch(pEncodedData, , "[osp-installer] pEncodedData is null."); + + r = StringUtil::EncodeToBase64String(*pEncodedData, base64Value); + TryCatch(!IsFailed(r), , "[osp-installer] StringUtil::EncodeToBase64String is failed."); + + pEncodedValue = _StringConverter::CopyToCharArrayN(base64Value); + TryCatch(pEncodedValue, , "[osp-installer] pEncodedValue is null"); + +CATCH: + delete pEncodedData; + + return pEncodedValue; +} + +bool +ConfigurationManager::UnregisterCertInfo(InstallationContext* pContext) const +{ + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "UnregisterCertInfo - START"); + int res = 0; + bool result = true; + String appId = pContext->GetId(); + + char* pAppId = _StringConverter::CopyToCharArrayN(appId); + TryCatch(pAppId, result = false, "[osp-installer] pAppId is null"); + + res = pkgmgr_installer_delete_certinfo(pAppId); + TryCatch(res == 0, result = false, "[osp-installer] pkgmgr_installer_delete_certinfo(%s) failed.[%d]", pAppId, res); + + AppLogTag(OSP_INSTALLER, "UnregisterCertInfo - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + +CATCH: + delete[] pAppId; + return result; +} + +bool +ConfigurationManager::PostInstall(InstallationContext* pContext, bool error) const +{ + app2ext_handle* pHandle = pContext->GetApp2ExtHandle(); + if (pHandle) + { + String appId = pContext->GetId(); + std::unique_ptr pAppId(_StringConverter::CopyToCharArrayN(appId)); + TryReturn(pAppId, false, "[osp-installer] pAppId is null"); + + if (error == true) + { + pHandle->interface.post_install(pAppId.get(), APP2EXT_STATUS_FAILED); + AppLogTag(OSP_INSTALLER, "[app2sd] post_install(%s, APP2EXT_STATUS_FAILED)", pAppId.get()); + } + else + { + pHandle->interface.post_install(pAppId.get(), APP2EXT_STATUS_SUCCESS); + AppLogTag(OSP_INSTALLER, "[app2sd] post_install(%s, APP2EXT_STATUS_SUCCESS)", pAppId.get()); + } + + app2ext_deinit(pHandle); + } + + return true; +} + +bool +ConfigurationManager::PostUninstall(InstallationContext* pContext) const +{ + app2ext_handle* pHandle = pContext->GetApp2ExtHandle(); + if (pHandle) + { + String appId = pContext->GetId(); + std::unique_ptr pAppId(_StringConverter::CopyToCharArrayN(appId)); + TryReturn(pAppId, false, "[osp-installer] pAppId is null"); + + pHandle->interface.post_uninstall(pAppId.get()); + AppLogTag(OSP_INSTALLER, "[app2sd] post_uninstall(%s)", pAppId.get()); + + app2ext_deinit(pHandle); + } + + return true; +} + +bool +ConfigurationManager::CreateSystemXmlFile(InstallationContext* pContext) +{ + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "CreateSystemXmlFile() - START"); + bool ret = false; + + ManifestGenerator manifestGenerator; + manifestGenerator.Construct(pContext); + ret = manifestGenerator.Write(); + + if (ret == false) + { + AppLogTag(OSP_INSTALLER, "manifestGenerator.Write() is failed."); + } + AppLogTag(OSP_INSTALLER, "CreateSystemXmlFile() - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + return ret; +} + +//bool +//ConfigurationManager::CreateHybridServiceDesktopFile(InstallationContext* pContext) +//{ +// AppLogTag(OSP_INSTALLER, "HybridServiceDesktopFile - START"); +// +// bool ret = true; +// _PackageInfoImpl *pPackageInfoImpl = pContext->GetPackageInfoImpl(); +// _PackageAppInfoImpl* pAppInfoImpl = null; +// ArrayList* pAppList = null; +// pAppList = pPackageInfoImpl->GetAppInfoList(); +// +// for (int i = 0 ; i < pAppList->GetCount(); i++) +// { +// pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); +// +// if (pAppInfoImpl) +// { +// String name; +// name.Format(1024, L"%ls", pPackageInfoImpl->GetAppName().GetPointer()); +// +// String binaryPath; +// binaryPath.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_BIN, pAppInfoImpl->GetName().GetPointer()); +// +// String iconPath; +// iconPath.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_ICONS, pAppInfoImpl->GetMainmenuIcon().GetPointer()); +// +// String version; +// version.Format(1024, L"%ls", pPackageInfoImpl->GetAppVersion().GetPointer()); +// +// String desktop; +// desktop.Format(1024, L"[Desktop Entry]\n" +// "Name=%ls\n" +// "Name[en_GB]=%ls\n" +// "Type=Application\n" +// "Exec=%ls\n" +// "Icon=%ls\n" +// "Version=%ls\n" +// "NoDisplay=true\n" +// "X-TIZEN-TaskManage=False\n" +// "X-TIZEN-PackageType=tpk\n", +// name.GetPointer(), name.GetPointer(), binaryPath.GetPointer(), iconPath.GetPointer(), version.GetPointer()); +// +// String desktopPath; +// desktopPath.Format(1024, L"/opt/share/applications/%ls.desktop", pAppInfoImpl->GetPackageName().GetPointer()); +// +// if (File::IsFileExist(desktopPath) == true) +// { +// AppLogTag(OSP_INSTALLER, "removing desktop filePath=[%ls]", desktopPath.GetPointer()); +// InstallerUtil::Remove(desktopPath); +// } +// +// CreateInfoFile(desktopPath, &desktop); +// } +// } +// +// AppLogTag(OSP_INSTALLER, "HybridServiceDesktopFile - END"); +// +// return ret; +//} + +bool +ConfigurationManager::MergeToSystemXmlFile(const String& systemXmlPath, const String& webXmlPath, const String& serviceXmlPath) +{ + result r = E_SUCCESS; + + FileAttributes webXmlAttr; + r = File::GetAttributes(webXmlPath, webXmlAttr); + TryReturn(!IsFailed(r), false, "[osp-installer] File::GetAttributes() failed, webXmlPath=%ls", webXmlPath.GetPointer()); + + FileAttributes serviceAttr; + r = File::GetAttributes(serviceXmlPath, serviceAttr); + TryReturn(!IsFailed(r), false, "[osp-installer] File::GetAttributes() failed, serviceXmlPath=%ls", serviceXmlPath.GetPointer()); + + long long webXmlFileSize = webXmlAttr.GetFileSize(); + long long serviceXmlFileSize = serviceAttr.GetFileSize(); + long long mergedSize = webXmlFileSize + serviceXmlFileSize; + + File webXml; + r = webXml.Construct(webXmlPath, L"r"); + TryReturn(!IsFailed(r), false, "[osp-installer] webXmlPath.Construct is failed"); + + std::unique_ptr pMergedBuf(new (std::nothrow) char[mergedSize + 1]); + TryReturn(pMergedBuf, false, "[osp-installer] pMergedBuf is null"); + memset(pMergedBuf.get(), 0, mergedSize + 1); + + int readBytes = webXml.Read(pMergedBuf.get(), webXmlFileSize); + TryReturn(readBytes >= 0, false, "[osp-installer] webXml.Read is failed"); + + File serviceXml; + r = serviceXml.Construct(serviceXmlPath, L"r"); + TryReturn(!IsFailed(r), false, "[osp-installer] serviceXmlPath.Construct is failed"); + + std::unique_ptr pServiceBuf(new (std::nothrow) char[serviceXmlFileSize + 1]); + TryReturn(pServiceBuf, false, "[osp-installer] pServiceBuf is null"); + memset(pServiceBuf.get(), 0, serviceXmlFileSize + 1); + + readBytes = serviceXml.Read(pServiceBuf.get(), serviceXmlFileSize); + TryReturn(readBytes >= 0, false, "[osp-installer] serviceXml.Read is failed"); + + char* pManifestTag = strcasestr(pMergedBuf.get(), ""); + TryReturn(pManifestTag, false, "[osp-installer] pManifestTag is null"); + + char* pAppTagStart = strcasestr(pServiceBuf.get(), ""); + TryReturn(pAppTagEnd, false, "[osp-installer] pAppTagEnd is null"); + + int serviceAppLen = pAppTagEnd - pAppTagStart + strlen(""); + + memcpy(pManifestTag, pAppTagStart, serviceAppLen); + + char* pManifestEndTag = pManifestTag + serviceAppLen; + strcpy(pManifestEndTag, "\n"); + + int fileSize = pManifestEndTag - pMergedBuf.get() + strlen("\n"); + + File systemXml; + r = systemXml.Construct(systemXmlPath, L"w"); + TryReturn(!IsFailed(r), false, "[osp-installer] systemXmlPath.Construct is failed"); + + systemXml.Write(pMergedBuf.get(), fileSize); + + AppLogTag(OSP_INSTALLER, "pMergedBuf.get()=0x%0x, length=%d", (unsigned int)pMergedBuf.get(), fileSize); + InstallerUtil::DumpLogData(pMergedBuf.get(), fileSize); + + return true; +} + +bool +ConfigurationManager::CreateInfoFile(const String& filePath, const String* pContext) +{ + result r = E_SUCCESS; + File file; + + r = file.Construct(filePath, "w"); + TryReturn(!IsFailed(r), false, "[osp-installer] file.Construct() failed, filePath=[%ls]", filePath.GetPointer()); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "CreateInfoFile(), filePath = [%ls]", filePath.GetPointer()); + + if (pContext) + { + r = file.Write(*pContext); + TryReturn(!IsFailed(r), false, "[osp-installer] file.Write() failed, filePath=[%ls]", filePath.GetPointer()); + AppLogTag(OSP_INSTALLER, "string = [%ls]", pContext->GetPointer()); + } + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + return true; +} + +bool +ConfigurationManager::CreateImeSymlink(const String& binaryPath, const String& packageName) +{ + bool res = true; + int err = 0; + const char* pExePath = null; + const char* pSymlinkPath = null; + + Directory::Create(IME_PATH, true); + + String exePath; + exePath.Format(1024, L"%ls.exe", binaryPath.GetPointer()); + + String symlinkPath; + symlinkPath.Format(1024, L"%s/%ls.so", IME_PATH, packageName.GetPointer()); + + pExePath = _StringConverter::CopyToCharArrayN(exePath); + TryCatch(pExePath, res = false, "[osp-installer] pExePath is null"); + + pSymlinkPath = _StringConverter::CopyToCharArrayN(symlinkPath); + TryCatch(pSymlinkPath, res = false, "[osp-installer] pSymlinkPath is null"); + + err = symlink(pExePath, pSymlinkPath); + + AppLogTag(OSP_INSTALLER, "[%s] -> [%s]", pSymlinkPath, pExePath); + +CATCH: + delete[] pExePath; + delete[] pSymlinkPath; + + return res; +} + +bool +ConfigurationManager::FindPrivilege(InstallationContext* pContext, const String& privilege) const +{ + TryReturn(pContext, false, "[osp-installer] pContext is null."); + + bool ret = false; + const ArrayList* pPrivilegeList = pContext->GetPrivilegeList(); + + if (pPrivilegeList) + { + if (pPrivilegeList->Contains(privilege) == true) + { + AppLogTag(OSP_INSTALLER, "Privilege = [%ls]", privilege.GetPointer()); + ret = true; + } + } + + return ret; +} diff --git a/src/Manager/ConfigurationManager.h b/src/Manager/ConfigurationManager.h new file mode 100755 index 0000000..f17aa4c --- /dev/null +++ b/src/Manager/ConfigurationManager.h @@ -0,0 +1,67 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ConfigurationManager.h + * @brief This is the header file for the %ConfigurationManager class. + * + * This header file contains the declarations of the %ConfigurationManager class. + */ +#ifndef _CONFIGURATION_MANAGER_H_ +#define _CONFIGURATION_MANAGER_H_ + +#include + +#include "InstallationContext.h" + + +/** + * @class ConfigurationManager + * @brief This class represents the class of ConfigurationManager. + * @since 1.0 + * + * This class represents the class of ConfigurationManager. + * + */ +class ConfigurationManager +{ +public: + ConfigurationManager(void); + virtual ~ConfigurationManager(void); + + bool CreateFile(InstallationContext* pContext); + bool RemoveFile(InstallationContext* pContext); + + bool RegisterCertInfo(InstallationContext* pContext) const; + bool UnregisterCertInfo(InstallationContext* pContext) const; + + bool PostInstall(InstallationContext* pContext, bool error) const; + bool PostUninstall(InstallationContext* pContext) const; + +private: + bool CreateSystemXmlFile(InstallationContext* pContext); + // bool CreateHybridServiceDesktopFile(InstallationContext* pContext); + bool MergeToSystemXmlFile(const Tizen::Base::String& systemXmlPath, const Tizen::Base::String& webXmlPath,const Tizen::Base::String& serviceXmlPath); + + bool CreateInfoFile(const Tizen::Base::String& filePath, const Tizen::Base::String* pContext); + bool CreateImeSymlink(const Tizen::Base::String& binaryPath, const Tizen::Base::String& packageName); + bool FindPrivilege(InstallationContext* pContext, const Tizen::Base::String& privilege) const; + bool SetCertHashValue(void* pHandle, Tizen::Security::Cert::X509CertificatePath* pCertPath, int certType) const; + char* GetCertValueN(Tizen::Security::Cert::ICertificate* pCert) const; + +}; // ConfigurationManager + +#endif // _CONFIGURATION_MANAGER_H_ diff --git a/src/Manager/InstallerManager.cpp b/src/Manager/InstallerManager.cpp new file mode 100755 index 0000000..bbad10e --- /dev/null +++ b/src/Manager/InstallerManager.cpp @@ -0,0 +1,1053 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallerManager.cpp + * @brief This is the implementation file for %InstallerManager class. + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "InstallerManager.h" +#include "GuestInstaller.h" +#include "IDEInstaller.h" +#include "PreloadedInstaller.h" +#include "RestorationInstaller.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Utility; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; +using namespace Tizen::App; +using namespace Tizen::App::Package; + +const int BUFSIZE = 512; +InstallerManager* InstallerManager::__pInstallerManager = null; + +InstallerManager::InstallerManager(void) +:__pContext(null) +,__pInstaller(null) +,__errorType(0) +,__operation(INSTALLER_OPERATION_INSTALL) +,__startTick(0) +,__endTick(0) +{ +} + +InstallerManager::~InstallerManager(void) +{ + delete __pContext; + __pContext = null; + + delete __pInstaller; + __pInstaller = null; +} + +InstallerManager* +InstallerManager::GetInstance() +{ + if (__pInstallerManager == null) + { + __pInstallerManager = new InstallerManager(); + TryReturn(__pInstallerManager, null, "[osp-installer] __pInstallerManager is null"); + } + + return __pInstallerManager; +} + +InstallerError +InstallerManager::Construct(const String& path, InstallerOperation operation, RequesterType requesterType, bool hybridService) +{ + InstallerError error = INSTALLER_ERROR_NONE; + InstallerType installerType = INSTALLER_TYPE_INSTALLER; + result r = E_SUCCESS; + + __pContext = new InstallationContext(); + TryReturn(__pContext, INSTALLER_ERROR_OUT_OF_MEMORY, "[osp-installer] __pContext is null."); + + error = __pContext->Construct(); + TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pContext->Construct() failed."); + + // 1. operation + if (operation == INSTALLER_OPERATION_INSTALL) + { + FileAttributes attr; + r = File::GetAttributes(path, attr); + TryReturn(!IsFailed(r), INSTALLER_ERROR_PACKAGE_NOT_FOUND, "[osp-installer] File::GetAttributes() failed"); + + if (attr.IsDirectory()) + { + installerType = INSTALLER_TYPE_DIRECTORY; + if (path.StartsWith(PATH_USR_APPS, 0) == true) + { + installerType = INSTALLER_TYPE_PRELOADED; + } + + __pContext->SetInputPath(path); + __pContext->SetInstallDir(path); + } + else + { + installerType = INSTALLER_TYPE_PACKAGE; + __pContext->SetPackagePath(path); + } + + // org.tizen.* + if (path.Contains(PACKAGE_NAME_PREFIX_ORG) == true) + { + __pContext->SetPackageNameType(INSTALLER_PREFIX_TYPE_ORG); + } + } + else if (operation == INSTALLER_OPERATION_UNINSTALL) + { + installerType = INSTALLER_TYPE_INSTALLER; + + AppLogTag(OSP_INSTALLER, "operation is INSTALLER_OPERATION_UNINSTALL"); + __pContext->SetCurrentInstallationStep(INSTALLER_STEP_INIT_UNINSTALL); + __pContext->SetId(path); + } + + __pContext->SetInstallerOperation(operation); + + // 2. requesterType + if (requesterType == REQUESTER_TYPE_PRELOADED) + { + __pContext->SetPreloaded(true); + } + + // 3. hybridService + if (hybridService == true) + { + AppLogTag(OSP_INSTALLER, "Request to install HybridService app!"); + __pContext->SetHybridService(true); + } + + __pInstaller = CreateInstaller(installerType); + TryReturn(__pInstaller, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller is null."); + + error = __pInstaller->Construct(__pContext); + TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller->Construct() failed"); + + return error; +} + +void +InstallerManager::Release(void) +{ + delete __pInstallerManager; + __pInstallerManager = null; +} + +Installer* +InstallerManager::CreateInstaller(InstallerType installerType) +{ + Installer* pInstaller = null; + + switch (installerType) + { + case INSTALLER_TYPE_INSTALLER: + AppLogTag(OSP_INSTALLER, "InstallerType = [Installer]"); + pInstaller = new (std::nothrow) Installer(); + break; + + case INSTALLER_TYPE_PACKAGE: + AppLogTag(OSP_INSTALLER, "InstallerType = [PackageInstaller]"); + pInstaller = new (std::nothrow) PackageInstaller(); + break; + + case INSTALLER_TYPE_DIRECTORY: + AppLogTag(OSP_INSTALLER, "InstallerType = [DirectoryInstaller]"); + pInstaller = new (std::nothrow) DirectoryInstaller(); + break; + + case INSTALLER_TYPE_GUEST: + AppLogTag(OSP_INSTALLER, "InstallerType = [GuestInstaller]"); + pInstaller = new (std::nothrow) GuestInstaller(); + break; + + case INSTALLER_TYPE_PRELOADED: + AppLogTag(OSP_INSTALLER, "InstallerType = [PreloadedInstaller]"); + pInstaller = new (std::nothrow) PreloadedInstaller(); + break; + + case INSTALLER_TYPE_IDE: + AppLogTag(OSP_INSTALLER, "InstallerType = [IDEInstaller]"); + pInstaller = new (std::nothrow) IDEInstaller(); + break; + + case INSTALLER_TYPE_RESTORATION: + AppLogTag(OSP_INSTALLER, "InstallerType = [RestorationInstaller]"); + pInstaller = new (std::nothrow) RestorationInstaller(); + break; + + default: + AppLogExceptionTag(OSP_INSTALLER, "Installer is not found."); + break; + } + + return pInstaller; +} + +InstallationStep +InstallerManager::GetNext(void) +{ + InstallationStep step = __pContext->GetCurrentInstallationStep(); + return __pInstaller->GetNext(step); +} + +InstallerError +InstallerManager::Init(void) +{ + return __pInstaller->OnInit(); +} + +InstallerError +InstallerManager::Error(void) +{ + return __pInstaller->OnError(); +} + +InstallerError +InstallerManager::Register(void) +{ + return __pInstaller->OnRegister(); +} + +InstallerError +InstallerManager::End(void) +{ + return __pInstaller->OnEnd(); +} + +InstallerError +InstallerManager::Rollback(void) +{ + return __pInstaller->OnRollback(); +} + +InstallerError +InstallerManager::UserCancel(void) +{ + return __pInstaller->OnUserCancel(); +} + +InstallerError +InstallerManager::Activate(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + IInstallationStep* pStep = null; + InstallationStep currentStep; + + while (__pContext->GetState() == INSTALLER_STATE_RUNNING) + { + currentStep = GetNext(); + __pContext->ChangeStep(currentStep); + + pStep = __pContext->GetStep(); + if (pStep) + { + error = pStep->Run(__pContext); + + if (error != INSTALLER_ERROR_NONE) + { + __pContext->SetError(error); + Error(); + return error; + } + } + + if (currentStep == INSTALLER_STEP_INIT) + { + error = Init(); + TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred."); + } + else if (currentStep == INSTALLER_STEP_END) + { + error = Register(); + TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred."); + + error = End(); + TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred."); + } + + if (__pContext->IsContinue() == false) + { + break; + } + + if (__pContext->GetCurrentInstallationStep() >= INSTALLER_STEP_MAX) + { + break; + } + } + + return error; +} + +InstallerError +InstallerManager::Progress(void) +{ + return INSTALLER_ERROR_NONE; +} + +InstallationContext* +InstallerManager::GetContext(void) +{ + return __pContext; +} + +int +InstallerManager::Request(const String& path, InstallerOperation operation, RequesterType requesterType, bool hybridService) +{ + InstallationContext* pContext = null; + InstallerError errorType = INSTALLER_ERROR_NONE; + InstallerManager* pInstallManager = null; + PackageId packageId; + + if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) + { + InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); + } + + Tizen::System::SystemTime::GetTicks(__startTick); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "InstallerManager::Request"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " # operation = [%s]", (operation == INSTALLER_OPERATION_INSTALL)?"Installation":"Uninstallation"); + AppLogTag(OSP_INSTALLER, " # path = [%ls]", path.GetPointer()); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + SetInstallerOperation(operation); + + pInstallManager = InstallerManager::GetInstance(); + TryCatch(pInstallManager, errorType = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pInstallManager is null."); + + errorType = pInstallManager->Construct(path, operation, requesterType, hybridService); + TryCatch(errorType == INSTALLER_ERROR_NONE, , "[osp-installer] pInstallManager->Construct() failed."); + + errorType = pInstallManager->Activate(); + TryCatch(errorType == INSTALLER_ERROR_NONE, , "[osp-installer] pInstallManager->Activate() failed."); + + pContext = pInstallManager->GetContext(); + TryCatch(pContext, errorType = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pContext is null."); + + packageId = pContext->GetId(); + SetId(packageId); + +CATCH: + if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) + { + InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); + } + + SetErrorType(errorType); + return errorType; +} + +int +InstallerManager::RequestRecursiveDirectory(const Tizen::Base::String& path, int& errorType) +{ + Directory* pDir = null; + DirEnumerator* pDirEnum = null; + result r = E_SUCCESS; + int res = false; + String appid; + InstallerError error = INSTALLER_ERROR_NONE; + int totalCount = 0; + int successCount = 0; + int failureCount = 0; + + pDir = new (std::nothrow) Directory; // Allocate %Directory instance + TryCatch(pDir, res = false, "[osp-installer] pDir is null"); + + r = pDir->Construct(path); + TryCatch(!IsFailed(r), res = false, "[osp-installer] pDir->Construct() failed, path = [%ls]", path.GetPointer()); + + pDirEnum = pDir->ReadN(); + TryCatch(pDirEnum, res = false, "[osp-installer] pDirEnum is null"); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String entryDir = path; + entryDir += L"/"; + entryDir += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + + if (entry.IsDirectory() == false) + { + continue; + } + + const int entryLength = entryName.GetLength(); + if (entryLength == APPID_LENGTH) + { + // AppId + } + else if (entryLength == APP_DIR_LENGTH) + { + if (entryName.Contains(PACKAGE_NAME_PREFIX_ORG) == false) + { + AppLogTag(OSP_INSTALLER, " - Not osp = [%ls]: prefix mismatch", entryDir.GetPointer()); + continue; + } + } + else + { + AppLogTag(OSP_INSTALLER, " - Not osp = [%ls]: length(%d) mismatch", entryDir.GetPointer(), entryLength); + continue; + } + + String xmlFile; + xmlFile.Format(1024, L"%ls%ls", entryDir.GetPointer(), PACKAGE_XML_FILE); + + FileAttributes attr; + r = File::GetAttributes(xmlFile, attr); + if (IsFailed(r)) + { + AppLogTag(OSP_INSTALLER, " - Not osp = [%ls]: No manifest.xml", entryDir.GetPointer()); + continue; + } + + totalCount++; + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " # Directory = [%ls]", entryDir.GetPointer()); + + errorType = Request(entryDir, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_PRELOADED); + if (errorType == 0) + { + successCount++; + } + else + { + failureCount++; + } + + PrintResult(); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + } + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "recursive directory installation"); + AppLogTag(OSP_INSTALLER, " # totalCount = [%d]", totalCount); + AppLogTag(OSP_INSTALLER, " # successCount = [%d]", successCount); + AppLogTag(OSP_INSTALLER, " # failureCount = [%d]", failureCount); + +CATCH: + delete pDirEnum; + delete pDir; + return error; +} + +int +InstallerManager::RequestByCommand(int argc, char **argv) +{ + int mode = 0; + char buf[BUFSIZE] = {0}; + // String appId; + int errorType = 0; + bool output = false; + bool hybridService = false; + + AppLogTag(OSP_INSTALLER, " # argc = [%d]", argc); + + for (int i = 0; i < argc; i++) + { + AppLogTag(OSP_INSTALLER, " # argv[%d] = [%s]", i, argv[i]); + } + + ParseCommandArg(argc, argv, &mode, buf, &output); + + if (output == true) + { + AppLogTag(OSP_INSTALLER, "HybridService is detected in ParseCommandArg()"); + hybridService = true; + } + + switch (mode) + { + case INSTALLER_MODE_INSTALL: + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " # Directory = [%s]", buf); + + errorType = Request(buf, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL, hybridService); + if (errorType != 0) + { + // in case of command, garbage directory is not deleted. + // RemoveGarbage(buf); + } + PrintResult(); + } + break; + + case INSTALLER_MODE_UNINSTALL: + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " # Directory = [%s]", buf); + + errorType = Request(buf, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL, hybridService); + PrintResult(); + } + break; + + case INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL: + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + errorType = RequestRecursiveDirectory(buf, errorType); + } + break; + + default: + { + AppLogTag(OSP_INSTALLER, "__install_package_by_cmd, Invalid mode"); + } + break; + } + + AppLogTag(OSP_INSTALLER, "=========================================="); + + if (output == true) + { + AppLogTag(OSP_INSTALLER, "stdout is updated by errorType"); + fprintf(stdout, "%d", errorType); + } + + return errorType; +} + +int +InstallerManager::RequestMove(const PackageId& packageId, int moveType) +{ + result r = E_SUCCESS; + int res = 0; + InstallerError errorType = INSTALLER_ERROR_NONE; + app2ext_handle* pHandle = null; + app2ext_move_type location = APP2EXT_MOVE_TO_EXT; + GList* pDirectoryList = null; + Directory* pDir = null; + DirEnumerator* pDirEnum = null; + PackageInfo* pPackageInfo = null; + _PackageInfoImpl* pPackageInfoImpl = null; + String rootPath; + + std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(packageId)); + TryReturn(pPackageId, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageId is null"); + + if (moveType == PM_MOVE_TO_INTERNAL) + { + location = APP2EXT_MOVE_TO_PHONE; + } + + pPackageInfo = _PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId); + TryCatch(pPackageInfo != null, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetPackageInfoN() failed"); + + pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo); + TryCatch(pPackageInfoImpl, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetInstance() failed"); + + rootPath = pPackageInfoImpl->GetAppRootPath(); + + pHandle = app2ext_init(APP2EXT_SD_CARD); + TryCatch(pHandle, errorType = INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed"); + + if (location == APP2EXT_MOVE_TO_PHONE) + { + res = pHandle->interface.enable(pPackageId.get()); + TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.eable() failed [%d]", res); + } + + pDir = new (std::nothrow) Directory; + TryCatch(pDir, errorType = INSTALLER_ERROR_OUT_OF_MEMORY, "pDir is null"); + + r = pDir->Construct(rootPath); + TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDir->Construct() failed, path = [%ls]", rootPath.GetPointer()); + + pDirEnum = pDir->ReadN(); + TryCatch(pDirEnum, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirEnum is null"); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + //String rootDirectory = rootPath; + //rootDirectory += L"/"; + //rootDirectory += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + + int length = 0; + app2ext_dir_details* pDirDetails = null; + + pDirDetails = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details)); + TryCatch(pDirDetails, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirDetails is null"); + + length = entryName.GetLength(); + pDirDetails->name = (char*) calloc(1, (sizeof(char) * length) + 1); + snprintf(pDirDetails->name, length + 1, "%ls", entryName.GetPointer()); + + String bin(L"bin"); + String res(L"res"); + String icons(L"icons"); + + if (entryName.Contains(bin) || entryName.Contains(res) || entryName.Contains(icons)) + { + pDirDetails->type = APP2EXT_DIR_RO; + } + else + { + pDirDetails->type = APP2EXT_DIR_RW; + } + + AppLog("------------------------------------------"); + AppLog("# Root Directory = [%s], Type = [%d]", pDirDetails->name, pDirDetails->type); + + pDirectoryList = g_list_append(pDirectoryList, pDirDetails); + } + + res = pHandle->interface.move(pPackageId.get(), pDirectoryList, location); + TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.move() failed [%d]", res); + + app2ext_deinit(pHandle); + +CATCH: + if (pDirectoryList) + { + GList* pList = null; + app2ext_dir_details* pDirDetails = null; + + pList = g_list_first(pDirectoryList); + while (pList) + { + pDirDetails = (app2ext_dir_details*)pList->data; + if (pDirDetails && pDirDetails->name) + { + free(pDirDetails->name); + } + pList = g_list_next(pList); + } + g_list_free(pDirectoryList); + } + + delete pDirEnum; + delete pDir; + delete pPackageInfo; + + return errorType; +} + +int +InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output) +{ + const char* pOpts_str = "u:i:r:v"; + int s = 0; + + if (mode == NULL) + { + AppLogTag(OSP_INSTALLER, "mode is null"); + exit(-1); + } + + *mode = 0; + + while (1) + { + s = getopt(argc, argv, pOpts_str); + + if (s == -1) + { + break; + } + + switch (s) + { + case 'i': + if (*mode) + { + break; + } + + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: i"); + *mode = INSTALLER_MODE_INSTALL; + if (optarg[0] == 'v') + { + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v"); + *output = true; + strncpy(buf, argv[optind++], BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: buf = [%s]", buf); + } + else + { + strncpy(buf, optarg, BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg); + } + break; + + case 'u': + if (*mode) + { + break; + } + + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: u"); + *mode = INSTALLER_MODE_UNINSTALL; + if (optarg[0] == 'v') + { + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v"); + *output = true; + strncpy(buf, argv[optind++], BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: buf = [%s]", buf); + } + else + { + strncpy(buf, optarg, BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg); + } + break; + + case 'r': + if (*mode) + { + break; + } + + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: r"); + *mode = INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL; + strncpy(buf, optarg, BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg); + break; + + case 'v': + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v"); + *output = true; + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg); + break; + + default: + AppLogTag(OSP_INSTALLER, "Invalid option"); + exit(-1); + break; + } + } + + if (mode == 0) + { + AppLogTag(OSP_INSTALLER, "Invalid mode"); + exit(-1); + } + + return 0; +} + +bool +InstallerManager::RemoveGarbage(const String& filePath) +{ + AppLogTag(OSP_INSTALLER, "RemoveGarbage Directory = [%ls]", filePath.GetPointer()); + + String realPath; + if (InstallerUtil::IsSymlink(filePath) == true) + { + if (InstallerUtil::GetRealPath(filePath, realPath) == true) + { + InstallerUtil::Remove(realPath); + } + } + + InstallerUtil::Remove(filePath); + + return true; +} + +int +InstallerManager::ReqeustByTest(void) +{ + int errorType = 0; + String appId; + Tizen::Io::File file; + Tizen::Io::FileAttributes attr; + result r = E_SUCCESS; + char readBuf[512] = {0}; + + r = File::GetAttributes(L"/opt/apps/cmtamb4mtv/data/configuration", attr); + TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_PACKAGE_NOT_FOUND, "[osp-installer] file not found"); + + r = file.Construct(L"/opt/apps/cmtamb4mtv/data/configuration", L"r"); + TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_PACKAGE_NOT_FOUND, "[osp-installer] file.Construct failed"); + + if (file.Read(readBuf, sizeof(readBuf)-1) > 1) + { + String path; + path.Format(1024, L"%s", &readBuf[1]); + + if (readBuf[0] == '+') + { + errorType = Request(path, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL); + } + else if (readBuf[0] == '-') + { + errorType = Request(path, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL); + } + else if (readBuf[0] == '*') + { + errorType = RequestRecursiveDirectory(path, errorType); + } + else if (readBuf[0] == '>') + { + errorType = RequestMove(path, PM_MOVE_TO_SDCARD); + } + else if (readBuf[0] == '<') + { + errorType = RequestMove(path, PM_MOVE_TO_INTERNAL); + } + } + +CATCH: + return errorType; +} + +void +InstallerManager::PrintPackageInfo(const char* appId) +{ + _PackageInfoImpl* pPackageInfoImpl = null; + ArrayList* pAppList = null; + int totalCount = 0; + + pPackageInfoImpl = new (std::nothrow) _PackageInfoImpl; + if (pPackageInfoImpl == null) + { + return; + } + + pPackageInfoImpl->Construct(appId); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "PackageInfo"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "# id = [%S]", pPackageInfoImpl->GetId().GetPointer()); + AppLogTag(OSP_INSTALLER, "# version = [%S]", pPackageInfoImpl->GetAppVersion().GetPointer()); + AppLogTag(OSP_INSTALLER, "# name = [%S]", pPackageInfoImpl->GetAppName().GetPointer()); + AppLogTag(OSP_INSTALLER, "# vendor = [%S]", pPackageInfoImpl->GetAppVendor().GetPointer()); + AppLogTag(OSP_INSTALLER, "# description = [%S]", pPackageInfoImpl->GetAppDescription().GetPointer()); + AppLogTag(OSP_INSTALLER, "# mimeType = [%S]", pPackageInfoImpl->GetAppMimeType().GetPointer()); + AppLogTag(OSP_INSTALLER, "# api version = [%S]", pPackageInfoImpl->GetAppApiVersion().GetPointer()); + AppLogTag(OSP_INSTALLER, "# uri = [%S]", pPackageInfoImpl->GetAppUrl().GetPointer()); + AppLogTag(OSP_INSTALLER, "# cid = [%S]", pPackageInfoImpl->GetAppCid().GetPointer()); + AppLogTag(OSP_INSTALLER, "# installationDate = [%S]", pPackageInfoImpl->GetAppInstallationTime().ToString().GetPointer()); + AppLogTag(OSP_INSTALLER, "# rootpath = [%S]", pPackageInfoImpl->GetAppRootPath().GetPointer()); + AppLogTag(OSP_INSTALLER, "# storageType = [%d]", pPackageInfoImpl->GetAppStorageType()); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + pAppList = pPackageInfoImpl->GetAppInfoListN(); + if (pAppList == null) + { + delete pPackageInfoImpl; + return; + } + + totalCount = pAppList->GetCount(); + + for (int i = 0; i < totalCount; i++) + { + _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "AppInfo(%d/%d)", i+1, totalCount); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "# default = [%S]", pAppInfoImpl->GetDefault().GetPointer()); + AppLogTag(OSP_INSTALLER, "# appname = [%S]", pAppInfoImpl->GetName().GetPointer()); + AppLogTag(OSP_INSTALLER, "# packagename = [%S]", pAppInfoImpl->GetPackageName().GetPointer()); + AppLogTag(OSP_INSTALLER, "# mainmenu icon = [%S]", pAppInfoImpl->GetMainmenuIcon().GetPointer()); + AppLogTag(OSP_INSTALLER, "# setting icon = [%S]", pAppInfoImpl->GetSettingIcon().GetPointer()); + AppLogTag(OSP_INSTALLER, "# quickpanel icon = [%S]", pAppInfoImpl->GetQuickpanelIcon().GetPointer()); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + } + + pAppList->RemoveAll(); + delete pAppList; + pAppList = null; + + delete pPackageInfoImpl; +} + +void +InstallerManager::PrintResult(void) +{ + String packageId = GetId(); + int errorType = GetErrorType(); + InstallerOperation operation = GetInstallerOperation(); + + Tizen::System::SystemTime::GetTicks(__endTick); + + AppLogTag(OSP_INSTALLER, "=========================================="); + AppLogTag(OSP_INSTALLER, "%s Result", (operation == INSTALLER_OPERATION_INSTALL)?"Installation":"Uninstallation"); + AppLogTag(OSP_INSTALLER, " # %s", OSP_INSTALLER_VERSION); + AppLogTag(OSP_INSTALLER, " # PackageId = [%ls]", packageId.IsEmpty() ? L"Unknown" : packageId.GetPointer()); + AppLogTag(OSP_INSTALLER, " # Result = [%s]", (errorType == 0)?"Success":"Failure"); + AppLogTag(OSP_INSTALLER, " # Time = [%d]ms (start=%d, end=%d)", (int)(__endTick-__startTick), (int)__startTick, (int)__endTick); + PrintError(errorType); +} + +void +InstallerManager::PrintError(int errorType) +{ + const char* pError = null; + + switch (errorType) + { + case INSTALLER_ERROR_NONE: + pError = "Success"; + break; + + case INSTALLER_ERROR_PACKAGE_NOT_FOUND: + pError = "[PACKAGE_NOT_FOUND] Thrown when package file is not found."; + break; + + case INSTALLER_ERROR_PACKAGE_INVALID: + pError = "[PACKAGE_INVALID] Thrown when package file is not valid due to file operation or directory hierarchy."; + break; + + case INSTALLER_ERROR_PACKAGE_LOWER_VERSION: + pError = "[PACKAGE_LOWER_VERSION] Thrown when the lower version package is tried to install."; + break; + + case INSTALLER_ERROR_EXECUTABLE_NOT_FOUND: + pError = "[EXECUTABLE_NOT_FOUND] Thrown when executable file is not found in the package."; + break; + + case INSTALLER_ERROR_MANIFEST_NOT_FOUND: + pError = "[MANIFEST_NOT_FOUND] Thrown when manifest.xml is not found in the package."; + break; + + case INSTALLER_ERROR_MANIFEST_INVALID: + pError = "[MANIFEST_INVALID] Thrown when manifest.xml is not valid due to schema or parsing failure."; + break; + + case INSTALLER_ERROR_SIGNATURE_NOT_FOUND: + pError = "[SIGNATURE_NOT_FOUND] Thrown when the signature files are not found in the package."; + break; + + case INSTALLER_ERROR_SIGNATURE_INVALID: + pError = "[SIGNATURE_INVALID] Thrown when the signature files are not valid due to schema or parsing failure."; + break; + + case INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED: + pError = "[SIGNATURE_VERIFICATION_FAILED] Thrown when the signature verification has failed due to be modified illegally."; + break; + + case INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND: + pError = "[ROOT_CERTIFICATE_NOT_FOUND] Thrown when the root certificate is not found."; + break; + + case INSTALLER_ERROR_CERTIFICATE_INVALID: + pError = "[CERTIFICATE_INVALID] Thrown when the certificate verification has failed."; + break; + + case INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED: + pError = "[CERTIFICATE_CHAIN_VERIFICATION_FAILED] Thrown when the certificate chain verification has failed."; + break; + + case INSTALLER_ERROR_CERTIFICATE_EXPIRED: + pError = "[CERTIFICATE_EXPIRED] Thrown when the used certificates have expired."; + break; + + case INSTALLER_ERROR_PRIVILEGE_INVALID: + pError = "[PRIVILEGE_INVALID] Thrown when unsupported privilege strings are detected."; + break; + + case INSTALLER_ERROR_MENU_ICON_NOT_FOUND: + pError = "[MENU_ICON_NOT_FOUND] Thrown when an icon for menu is not found. This icon is mandatory."; + break; + + case INSTALLER_ERROR_FATAL_ERROR: + pError = "[FATAL_ERROR] Thrown when an icon for menu is not found. This icon is mandatory."; + break; + + case INSTALLER_ERROR_OUT_OF_STORAGE: + pError = "[OUT_OF_STORAGE] Thrown when the storage is full."; + break; + + case INSTALLER_ERROR_OUT_OF_MEMORY: + pError = "[OUT_OF_MEMORY] Thrown when the memory is not sufficient to perform the requested installation or uninstallation."; + break; + + default: + pError = "fatal error"; + break; + } + + AppLogTag(OSP_INSTALLER, " # Error = %s(%d)", pError, errorType); +} + +const PackageId& +InstallerManager::GetId(void) const +{ + return __packageId; +} + +void +InstallerManager::SetId(const PackageId& packageId) +{ + __packageId = packageId; +} + +int +InstallerManager::GetErrorType(void) const +{ + return __errorType; +} + +void +InstallerManager::SetErrorType(int errorType) +{ + __errorType = errorType; +} + +void +InstallerManager::SetInstallerOperation(InstallerOperation op) +{ + __operation = op; +} + +InstallerOperation +InstallerManager::GetInstallerOperation(void) const +{ + return __operation; +} diff --git a/src/Manager/InstallerManager.h b/src/Manager/InstallerManager.h new file mode 100755 index 0000000..9076d65 --- /dev/null +++ b/src/Manager/InstallerManager.h @@ -0,0 +1,105 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallerManager.h + * @brief This is the header file for the %InstallerManager class. + * + * This header file contains the declarations of the %InstallerManager class. + */ +#ifndef _INSTALLER_MANAGER_H_ +#define _INSTALLER_MANAGER_H_ + +#include "InstallationContext.h" +#include "Installer.h" + +/** + * @class InstallerManager + * @brief This class represents the class of InstallerManager. + * @since 1.0 + * + * This class represents the class of InstallerManager. + * + */ +class InstallerManager +{ +public: + InstallerManager(void); + InstallerError Construct(const Tizen::Base::String& path, InstallerOperation op, RequesterType requesterType, bool hybridService = false); + virtual ~InstallerManager(void); + + static InstallerManager* GetInstance(void); + void Release(void); + + int Request(const Tizen::Base::String& path, InstallerOperation op, RequesterType requesterType, bool hybridService = false); + int RequestRecursiveDirectory(const Tizen::Base::String& path, int& errorType); + + bool RemoveGarbage(const Tizen::Base::String& filePath); + + int RequestByCommand(int argc, char **argv); + int ReqeustByTest(void); + int RequestMove(const Tizen::App::PackageId& packageId, int moveType); + + void PrintPackageInfo(const char* appId); + void PrintResult(void); + void PrintError(int errorType); + + const Tizen::App::PackageId& GetId(void) const; + void SetId(const Tizen::App::PackageId& appId); + + int GetErrorType(void) const; + void SetErrorType(int errorType); + + void SetInstallerOperation(InstallerOperation op); + InstallerOperation GetInstallerOperation(void) const; + +private: + InstallerManager(const InstallerManager& value); + InstallerManager& operator =(const InstallerManager& source); + + InstallationStep GetNext(void); + + InstallerError Init(void); + InstallerError Register(void); + InstallerError End(void); + + InstallerError Error(void); + InstallerError Rollback(void); + InstallerError UserCancel(void); + + InstallerError Activate(void); + InstallerError Progress(void); + + Installer* CreateInstaller(InstallerType installerType); + InstallationContext* GetContext(void); + + int ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output); + +private: + static InstallerManager* __pInstallerManager; + InstallationContext* __pContext; + Installer* __pInstaller; + + Tizen::App::PackageId __packageId; + int __errorType; + InstallerOperation __operation; + + long long __startTick; + long long __endTick; + +}; // InstallerManager + +#endif //_INSTALLER_MANAGER_H_ diff --git a/src/Manager/PermissionManager.cpp b/src/Manager/PermissionManager.cpp new file mode 100755 index 0000000..cf1c9b2 --- /dev/null +++ b/src/Manager/PermissionManager.cpp @@ -0,0 +1,278 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PermissionManager.cpp + * @brief This is the implementation file for %PermissionManager class. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "PermissionManager.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::Io; +using namespace Tizen::App::Package; + +PermissionManager::PermissionManager(void) +{ +} + +PermissionManager::~PermissionManager(void) +{ +} + +bool +PermissionManager::SetDirectory(InstallationContext* pContext) +{ + result r = E_SUCCESS; + + String destPath; + String appRootPath; + _PackageInfoImpl *pPackageInfoImpl = null; + FileAttributes attribute; + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + appRootPath = pPackageInfoImpl->GetAppRootPath(); + + // appRoot + // InstallerUtil::ChangeOwner(appRootPath); + InstallerUtil::ChangeMode(appRootPath, PERM_BASE | PERM_EXECUTE); + + // appRoot/bin + destPath = appRootPath + DIR_BIN; + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE | PERM_EXECUTE, false); + + // appRoot/info + destPath = appRootPath + DIR_INFO; + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false); + + // appRoot/res + destPath = appRootPath + DIR_RES; + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false); + + // appRoot/lib + destPath = appRootPath + DIR_LIB; + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE | PERM_EXECUTE, false); + + // appRoot/shared + destPath = appRootPath + DIR_SHARED; + if (File::IsFileExist(destPath) == false) + { + r = Directory::Create(destPath, false); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed"); + } + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false); + + destPath = appRootPath + DIR_SHARED_RES; + if (File::IsFileExist(destPath) == false) + { + String iconPath = appRootPath + DIR_ICONS; + InstallerUtil::CreateSymlink(iconPath, destPath); + } + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false); + + // appRoot/contents + destPath = appRootPath + DIR_CONTENTS; + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false); + + // appRoot/setting + destPath = appRootPath + DIR_SETTING; + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + String appVersion = pPackageInfoImpl->GetVersion(); + String srcPath; + String settingXmlPath; + + srcPath = destPath + L"/setting." + appVersion + L".xml"; + settingXmlPath = destPath + L"/setting.xml"; + + InstallerUtil::Remove(settingXmlPath); + InstallerUtil::CreateSymlink(srcPath, settingXmlPath); + + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE | PERM_WRITE, false); + } + + // appRoot/data + destPath = appRootPath + DIR_DATA; + if (File::IsFileExist(destPath) == false) + { + r = Directory::Create(destPath, false); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed"); + } + InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, true); + + String appId = pContext->GetId(); + String apiVersion = pPackageInfoImpl->GetAppApiVersion(); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "[Tizen::Io] # path = [%ls]", appRootPath.GetPointer()); + AppLogTag(OSP_INSTALLER, "[Tizen::Io] # appId = [%ls]", appId.GetPointer()); + AppLogTag(OSP_INSTALLER, "[Tizen::Io] # apiVersion = [%ls]", apiVersion.GetPointer()); + + if (pContext->__isOspCompat == true) + { + AppLogTag(OSP_INSTALLER, "[Tizen::Io] OSP 2.0 application"); + + if (_FileImpl::PrepareDataCaging(appRootPath, appId) == false) + { + AppLogTag(OSP_INSTALLER, "[Tizen::Io] _FileImpl::PrepareDataCaging() failed"); + return false; + } + + SetSymLink(pContext); + } + else + { + AppLogTag(OSP_INSTALLER, "[Tizen::Io] apiVersion is equal to or greater than Tizen 2.0"); + + if (_FileImpl::CreateOspApplicationDirectories(appRootPath, appId) == false) + { + AppLogTag(OSP_INSTALLER, "[Tizen::Io] _FileImpl::CreateOspApplicationDirectories() failed"); + return false; + } + } + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + // Create AppId.ExecutableName directory + // This will be removed. + CreateSystemDirectory(pContext, appRootPath); + + return true; +} + +bool +PermissionManager::SetFile(InstallationContext* pContext) +{ + String destPath; + + _PackageInfoImpl *pPackageInfoImpl = null; + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, false, "[osp-installer] pPackageInfoImpl is null."); + + String appRootPath; + appRootPath = pPackageInfoImpl->GetAppRootPath(); + + pAppList = pPackageInfoImpl->GetAppInfoList(); + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + // set permission(755) to bin file. + destPath = appRootPath + DIR_BIN + L"/" + pAppInfoImpl->GetName() + L".exe"; + InstallerUtil::ChangeMode(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + } + + return true; +} + +bool +PermissionManager::CreateSystemDirectory(InstallationContext* pContext, const Tizen::Base::String& rootpath) +{ + _PackageInfoImpl *pPackageInfoImpl = null; + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, false, "[osp-installer] pPackageInfoImpl is null."); + + pAppList = pPackageInfoImpl->GetAppInfoList(); + TryReturn(pAppList, false, "[osp-installer] pAppList is null."); + + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + String destPath = SLP_APP_PATH; + destPath += L"/" + pAppInfoImpl->GetPackageName(); + + InstallerUtil::Remove(destPath); + InstallerUtil::CreateSymlink(pPackageInfoImpl->GetAppRootPath(), destPath); + } + } + + return true; +} + +bool +PermissionManager::SetSymLink(InstallationContext* pContext) +{ + String oldPath; + String newPath; + + _PackageInfoImpl* pPackageInfoImpl = pContext->GetPackageInfoImpl(); + String appRootPath = pPackageInfoImpl->GetAppRootPath(); + +#if 0 + oldPath = appRootPath + DIR_RES; + newPath = appRootPath + L"/Res"; + InstallerUtil::CreateSymlink(oldPath, newPath); +#else + newPath = appRootPath + L"/Res"; + std::unique_ptr< char[] > pResPath(_StringConverter::CopyToCharArrayN(newPath)); + int ret = symlink("./res", pResPath.get()); +#endif + +#if 0 + oldPath = appRootPath + DIR_DATA; + newPath = appRootPath + L"/Home"; + InstallerUtil::CreateSymlink(oldPath, newPath); +#else + newPath = appRootPath + L"/Home"; + std::unique_ptr< char[] > pHomePath(_StringConverter::CopyToCharArrayN(newPath)); + ret = symlink("./data", pHomePath.get()); +#endif + + oldPath = appRootPath + DIR_RES + L"/screen-size-normal"; + newPath = appRootPath + L"/Res/ScreenSize-Normal"; + InstallerUtil::CreateSymlink(oldPath, newPath); + + oldPath = appRootPath + DIR_RES + L"/screen-density-high"; + newPath = appRootPath + L"/Res/ScreenDensity-High"; + InstallerUtil::CreateSymlink(oldPath, newPath); + + oldPath = appRootPath + DIR_RES + L"/screen-density-middle"; + newPath = appRootPath + L"/Res/ScreenDensity-Middle"; + InstallerUtil::CreateSymlink(oldPath, newPath); + + oldPath = appRootPath + DIR_RES + L"/screen-density-low"; + newPath = appRootPath + L"/Res/ScreenDensity-Low"; + InstallerUtil::CreateSymlink(oldPath, newPath); + + return true; +} diff --git a/src/Manager/PermissionManager.h b/src/Manager/PermissionManager.h new file mode 100644 index 0000000..379493d --- /dev/null +++ b/src/Manager/PermissionManager.h @@ -0,0 +1,52 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PermissionManager.h + * @brief This is the header file for the %PermissionManager class. + * + * This header file contains the declarations of the %PermissionManager class. @n + */ +#ifndef _PERMISSION_MANAGER_H_ +#define _PERMISSION_MANAGER_H_ + +#include "InstallationContext.h" + +/** + * @class PermissionManager + * @brief This class represents the class of PermissionManager. + * @since 1.0 + * + * This class represents the class of PermissionManager. + * + */ +class PermissionManager +{ +public: + PermissionManager(void); + virtual ~PermissionManager(void); + + static bool SetDirectory(InstallationContext* pContext); + static bool SetFile(InstallationContext* pContext); + +private: + static bool CreateSystemDirectory(InstallationContext* pContext, const Tizen::Base::String& rootpath); + static bool SetSymLink(InstallationContext* pContext); + static bool PrepareDataCaging(InstallationContext* pContext); + +}; // PermissionManager + +#endif // _PERMISSION_MANAGER_H_ diff --git a/src/Manager/SignatureManager.cpp b/src/Manager/SignatureManager.cpp new file mode 100755 index 0000000..b69ae70 --- /dev/null +++ b/src/Manager/SignatureManager.cpp @@ -0,0 +1,413 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SignatureManager.cpp + * @brief This is the implementation file for %SignatureManager class. + */ + +#include + +#include "SignatureManager.h" + +using namespace Tizen::Base; +using namespace Tizen::Security::Cert; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; + +SignatureManager::SignatureManager(void) +:__pContext(null) +,__pAuthorSignature(null) +,__pDistributorSignature(null) +,__pAuthorCertPath(null) +,__pDistributorCertPath(null) +{ +} + +SignatureManager::~SignatureManager(void) +{ + delete __pAuthorSignature; + delete __pDistributorSignature; + delete __pAuthorCertPath; + delete __pDistributorCertPath; +} + +bool +SignatureManager::Construct(InstallationContext* pContext) +{ + __pContext = pContext; + + return true; +} + +bool +SignatureManager::SetSignature() +{ + TryReturn(__pContext, false, "[osp-installer] __pContext is null."); + + bool ret = true; + char* pSignaturePath = _StringConverter::CopyToCharArrayN(__pContext->GetSignatureXmlPath()); + char* pAuthorSignaturePath = _StringConverter::CopyToCharArrayN(__pContext->GetAuthorSignatureXmlPath()); + + __pDistributorSignature = new (std::nothrow) SignatureHandler; + TryCatch(__pDistributorSignature, ret = false, "[osp-installer] __pDistributorSignature is null"); + + ret = __pDistributorSignature->Construct(__pContext); + TryCatch(ret == true, ret = false, "[osp-installer] __pDistributorSignature->Construct is failed."); + + ret = __pDistributorSignature->Parse(pSignaturePath); + TryCatch(ret == true, ret = false, "[osp-installer] __pDistributorSignature->Parse is failed."); + + __pAuthorSignature = new (std::nothrow) SignatureHandler; + TryCatch(__pAuthorSignature, ret = false, "[osp-installer] __pAuthorSignature is null"); + + ret = __pAuthorSignature->Construct(__pContext); + TryCatch(ret == true, ret = false, "[osp-installer] __pAuthorSignature->Construct is failed."); + + ret = __pAuthorSignature->Parse(pAuthorSignaturePath); + TryCatch(ret == true, ret = false, "[osp-installer] __pAuthorSignature->Parse is failed."); + +CATCH: + delete[] pSignaturePath; + delete[] pAuthorSignaturePath; + return ret; +} + +bool +SignatureManager::AddCert() +{ + TryReturn(__pAuthorSignature, false, "[osp-installer] __pAuthorSignature is null."); + TryReturn(__pDistributorSignature, false, "[osp-installer] __pDistributorSignature is null."); + + bool ret = true; + IList* pAuthorCertChain = __pAuthorSignature->GetAuthorCertChain(); + IList* pDistributorCertChain = __pDistributorSignature->GetDistributorCertChain(); + + if (pAuthorCertChain) + { + AppLogTag(OSP_INSTALLER, "AddCertificate - AuthorCertChain"); + + __pAuthorCertPath = new (std::nothrow) X509CertificatePath(); + TryCatch(__pAuthorCertPath, ret = false, "[osp-installer] __pAuthorCertPath is null."); + + ret = AddCertificate(__pAuthorCertPath, pAuthorCertChain); + TryCatch(ret == true, ret = false, "[osp-installer] AddCertificate(AuthorCert) is failed."); + + ret = AddAuthorRootCert(__pAuthorCertPath); + TryCatch(ret == true, ret = false, "[osp-installer] AddAuthorRootCert(AuthorCertPath) is failed."); + } + + if (pDistributorCertChain) + { + AppLogTag(OSP_INSTALLER, "AddCertificate - DistributorCert"); + + __pDistributorCertPath = new (std::nothrow) X509CertificatePath(); + TryCatch(__pDistributorCertPath, ret = false, "[osp-installer] __pDistributorCertPath is null."); + + ret = AddCertificate(__pDistributorCertPath, pDistributorCertChain); + TryCatch(ret == true, ret = false, "[osp-installer] AddCertificate(DistributorCert) is failed."); + + ret = AddDistributorRootCert(__pDistributorCertPath); + TryCatch(ret == true, ret = false, "[osp-installer] AddDistributorRootCert(DistributorCert) is failed."); + } + +CATCH: + return ret; +} + +bool +SignatureManager::VerifyChain() +{ + TryReturn(__pAuthorCertPath, false, "[osp-installer] __pAuthorCertPath is null."); + TryReturn(__pDistributorCertPath, false, "[osp-installer] __pDistributorCertPath is null."); + + bool ret = true; + + AppLogTag(OSP_INSTALLER, "AuthorCert Validate - START"); + ret = Validate(__pAuthorCertPath); + AppLogTag(OSP_INSTALLER, "AuthorCert Validate - END"); + TryCatch(ret == true, ret = false, "[osp-installer] Validate(AuthorCert) is failed."); + + __pContext->SetAuthorCertPath(__pAuthorCertPath); + __pAuthorCertPath = null; + + AppLogTag(OSP_INSTALLER, "DistributorCert Validate - START"); + ret = Validate(__pDistributorCertPath); + AppLogTag(OSP_INSTALLER, "DistributorCert Validate - END"); + TryCatch(ret == true, ret = false, "[osp-installer] Validate(DistributorCert) is failed."); + + __pContext->SetDistributorCertPath(__pDistributorCertPath); + __pDistributorCertPath = null; + +CATCH: + delete __pAuthorCertPath; + __pAuthorCertPath = null; + delete __pDistributorCertPath; + __pDistributorCertPath = null; + + return ret; +} + +bool +SignatureManager::Validate(X509CertificatePath* pCertPath) +{ + TryReturn(pCertPath, false, "[osp-installer] pCertPath is null."); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "# signature.xml"); + ValidationResult valResult = VALIDATION_SUCCESS; + valResult = pCertPath->Validate(); + + if (valResult != VALIDATION_SUCCESS) + { + AppLogTag(OSP_INSTALLER, "Validate() fail! - ValidationResult = [%d]", valResult); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + return false; + } + else + { + int depth = pCertPath->GetLength(); + if (depth == 0) + { + AppLogTag(OSP_INSTALLER, "depth = 0"); + return false; + } + + AppLogTag(OSP_INSTALLER, "Validate() success!"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + } + + return true; +} + +bool +SignatureManager::AddCertificate(X509CertificatePath* pCertPath, IList* pCertChain) +{ + TryReturn(pCertChain, false, "[osp-installer] pCertChain is null."); + + bool ret = true; + result r = E_SUCCESS; + X509Certificate* pCertificate = null; + + for (int i = 0; i < pCertChain->GetCount(); i++) + { + Tizen::Base::ByteBuffer* pByteBuffer = dynamic_cast (pCertChain->GetAt(i)); + + if (pByteBuffer) + { + AppLogTag(OSP_INSTALLER, "[cert][%d]", i); + + pCertificate = new (std::nothrow) X509Certificate; + TryCatch(pCertificate, ret = false, "[osp-installer] pCertificate is null."); + + r = pCertificate->Construct(*pByteBuffer); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] pCertificate->Construct() is failed."); + + r = pCertPath->AddCertificate(*pCertificate); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] AddCertificate is failed."); + + delete pCertificate; + pCertificate = null; + } + } + +CATCH: + delete pCertificate; + return ret; +} + +bool +SignatureManager::AddDistributorRootCert(X509CertificatePath* pCertPath) +{ + TryReturn(pCertPath, false, "[osp-installer] pCertPath is null."); + + result r = E_SUCCESS; + bool ret = true; + ICertificate* pIntermediateCA = null; + String issuer; + + pIntermediateCA = pCertPath->GetCertificateN(1); + TryCatch(pIntermediateCA, ret = false, "[osp-installer] pIntermediateCA is null."); + + issuer = pIntermediateCA->GetIssuer(); + + for(int certType = ROOT_CERTIFICATE_PUBLIC; certType <= ROOT_CERTIFICATE_PARTNER_MANUFACTURER; certType++) + { + const char* pRootCert = null; + ByteBuffer byteBuffer; + X509Certificate rootCert; + int length = 0; + + if (certType == ROOT_CERTIFICATE_PUBLIC) + { + pRootCert = "MIICozCCAgwCCQD9XW6kNg4bbjANBgkqhkiG9w0BAQUFADCBlTELMAkGA1UEBhMC" + "S1IxDjAMBgNVBAgMBVN1d29uMQ4wDAYDVQQHDAVTdXdvbjEWMBQGA1UECgwNVGl6" + "ZW4gVGVzdCBDQTEjMCEGA1UECwwaVFRpemVuIERpc3RyaWJ1dG9yIFRlc3QgQ0Ex" + "KTAnBgNVBAMMIFRpemVuIFB1YmxpYyBEaXN0cmlidXRvciBSb290IENBMB4XDTEy" + "MTAyNjA4MDAyN1oXDTIyMTAyNDA4MDAyN1owgZUxCzAJBgNVBAYTAktSMQ4wDAYD" + "VQQIDAVTdXdvbjEOMAwGA1UEBwwFU3V3b24xFjAUBgNVBAoMDVRpemVuIFRlc3Qg" + "Q0ExIzAhBgNVBAsMGlRUaXplbiBEaXN0cmlidXRvciBUZXN0IENBMSkwJwYDVQQD" + "DCBUaXplbiBQdWJsaWMgRGlzdHJpYnV0b3IgUm9vdCBDQTCBnzANBgkqhkiG9w0B" + "AQEFAAOBjQAwgYkCgYEA8o0kPY1U9El1BbBUF1k4jCq6mH8a6MmDJdjgsz+hILAY" + "sPWimRTXUcW8GAUWhZWgm1Fbb49xWcasA8b4bIJabC/6hLb8uWiozzpRXyQJbe7k" + "//RocskRqDmFOky8ANFsCCww72/Xbq8BFK1sxlGdmOWQiGwDWBDlS2Lw1XOMqb0C" + "AwEAATANBgkqhkiG9w0BAQUFAAOBgQBUotZqTNFr+SNyqeZqhOToRsg3ojN1VJUa" + "07qdlVo5I1UObSE+UTJPJ0NtSj7OyTY7fF3E4xzUv/w8aUoabQP1erEmztY/AVD+" + "phHaPytkZ/Dx+zDZ1u5e9bKm5zfY4dQs/A53zDQta5a/NkZOEF97Dj3+bzAh2bP7" + "KOszlocFYw=="; + } + else if (certType == ROOT_CERTIFICATE_PARTNER) + { + pRootCert = "MIICozCCAgwCCQD9IBoOxzq2hjANBgkqhkiG9w0BAQUFADCBlTELMAkGA1UEBhMC" + "S1IxDjAMBgNVBAgMBVN1d29uMQ4wDAYDVQQHDAVTdXdvbjEWMBQGA1UECgwNVGl6" + "ZW4gVGVzdCBDQTEiMCAGA1UECwwZVGl6ZW4gRGlzdHJpYnV0b3IgVGVzdCBDQTEq" + "MCgGA1UEAwwhVGl6ZW4gUGFydG5lciBEaXN0cmlidXRvciBSb290IENBMB4XDTEy" + "MTAyNjA4MTIzMVoXDTIyMTAyNDA4MTIzMVowgZUxCzAJBgNVBAYTAktSMQ4wDAYD" + "VQQIDAVTdXdvbjEOMAwGA1UEBwwFU3V3b24xFjAUBgNVBAoMDVRpemVuIFRlc3Qg" + "Q0ExIjAgBgNVBAsMGVRpemVuIERpc3RyaWJ1dG9yIFRlc3QgQ0ExKjAoBgNVBAMM" + "IVRpemVuIFBhcnRuZXIgRGlzdHJpYnV0b3IgUm9vdCBDQTCBnzANBgkqhkiG9w0B" + "AQEFAAOBjQAwgYkCgYEAnIBA2qQEaMzGalP0kzvwUxdCC6ybSC/fb+M9iGvt8QXp" + "ic2yARQB+bIhfbEu1XHwE1jCAGxKd6uT91b4FWr04YwnBPoRX4rBGIYlqo/dg+pS" + "rGyFjy7vfr0BOdWp2+WPlTe7SOS6bVauncrSoHxX0spiLaU5LU686BKr7YaABV0C" + "AwEAATANBgkqhkiG9w0BAQUFAAOBgQAX0Tcfmxcs1TUPBdr1U1dx/W/6Y4PcAF7n" + "DnMrR0ZNRPgeSCiVLax1bkHxcvW74WchdKIb24ZtAsFwyrsmUCRV842YHdfddjo6" + "xgUu7B8n7hQeV3EADh6ft/lE8nalzAl9tALTxAmLtYvEYA7thvDoKi1k7bN48izL" + "gS9G4WEAUg=="; + } + else if (certType == ROOT_CERTIFICATE_PARTNER_OPERATOR) + { + pRootCert = "MIICzDCCAjWgAwIBAgIJAJrv22F9wyp/MA0GCSqGSIb3DQEBBQUAMIGeMQswCQYD" + "VQQGEwJLUjEOMAwGA1UECAwFU3V3b24xDjAMBgNVBAcMBVN1d29uMRYwFAYDVQQK" + "DA1UaXplbiBUZXN0IENBMSIwIAYDVQQLDBlUaXplbiBEaXN0cmlidXRvciBUZXN0" + "IENBMTMwMQYDVQQDDCpUaXplbiBQYXJ0bmVyLU9wZXJhdG9yIERpc3RyaWJ1dG9y" + "IFJvb3QgQ0EwHhcNMTIxMjEzMDUzOTMyWhcNMjIxMjExMDUzOTMyWjCBnjELMAkG" + "A1UEBhMCS1IxDjAMBgNVBAgMBVN1d29uMQ4wDAYDVQQHDAVTdXdvbjEWMBQGA1UE" + "CgwNVGl6ZW4gVGVzdCBDQTEiMCAGA1UECwwZVGl6ZW4gRGlzdHJpYnV0b3IgVGVz" + "dCBDQTEzMDEGA1UEAwwqVGl6ZW4gUGFydG5lci1PcGVyYXRvciBEaXN0cmlidXRv" + "ciBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9X0Hw0EfAuagg" + "De9h6Jtvh8Df4fyVbvLm9VNea/iVP3/qTbG8tNqoQ32lu0SwzAZBnjpvpbxzsWs9" + "pSYo7Ys1fymHlu+gf+kmTGTVscBrAHWkr4O0m33x2FYfy/wmu+IImnRDYDud83rN" + "tjQmMO6BihN9Lb6kLiEtVIa8ITwdQwIDAQABoxAwDjAMBgNVHRMEBTADAQH/MA0G" + "CSqGSIb3DQEBBQUAA4GBAHS2M2UnfEsZf80/sT84xTcfASXgpFL/1M5HiAVpR+1O" + "UwLpLyqHiGQaASuADDeGEfcIqEf8gP1SzvnAZqLx9GchbOrOKRleooVFH7PRxFBS" + "VWJ5Fq46dJ1mCgTWSkrL6dN5j9hWCzzGfv0Wco+NAf61n9kVbCv7AScIJwQNltOy"; + } + else // ROOT_CERTIFICATE_PARTNER_MANUFACTURER + { + pRootCert = "MIIC1DCCAj2gAwIBAgIJAJZH47dCtgPdMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD" + "VQQGEwJLUjEOMAwGA1UECAwFU3V3b24xDjAMBgNVBAcMBVN1d29uMRYwFAYDVQQK" + "DA1UaXplbiBUZXN0IENBMSIwIAYDVQQLDBlUaXplbiBEaXN0cmlidXRvciBUZXN0" + "IENBMTcwNQYDVQQDDC5UaXplbiBQYXJ0bmVyLU1hbnVmYWN0dXJlciBEaXN0cmli" + "dXRvciBSb290IENBMB4XDTEyMTIxMzA1NDQxN1oXDTIyMTIxMTA1NDQxN1owgaIx" + "CzAJBgNVBAYTAktSMQ4wDAYDVQQIDAVTdXdvbjEOMAwGA1UEBwwFU3V3b24xFjAU" + "BgNVBAoMDVRpemVuIFRlc3QgQ0ExIjAgBgNVBAsMGVRpemVuIERpc3RyaWJ1dG9y" + "IFRlc3QgQ0ExNzA1BgNVBAMMLlRpemVuIFBhcnRuZXItTWFudWZhY3R1cmVyIERp" + "c3RyaWJ1dG9yIFJvb3QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMJG" + "0gq3XrDn7W7cIH58w7hSDMVENnXLmXm4Jl5teXXrgL/BgpORracGMgm0Fmxxq/Nq" + "8OEI2RfmtrlN5nWGiphs3XqLHtO+BAPY1BbZS6YVZjrVXrGWdzk12zQxd6sXJMiV" + "B08ECQiQ0qgKFbTDSEbH/p4eyKCMG9lnrBLPHTpJAgMBAAGjEDAOMAwGA1UdEwQF" + "MAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAJTJYCr9GhZ1xXwvxsWLGd9XV9wixo1zk" + "FV2+eJZbCc4xJyOSb0cZds8fYUuzw32oyElLvPhYfAHVTHu/WlkwSshZlKdI2hCT" + "Iy03/Up+JNfuom8JLgF7qc3YtbuJHzoVu1jJ/akXU6y52D/J5CkYy2JSsV0KZuh2" + "ZeRWlV2f1Uo="; + } + + length = strlen(pRootCert); + byteBuffer.Construct(length); + + r = byteBuffer.SetArray((byte*)pRootCert, 0, length); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] SetArray() is failed."); + + byteBuffer.Flip(); + + r = rootCert.Construct(byteBuffer); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] rootCert.Construct() is failed."); + + String subject = rootCert.GetSubject(); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "Issuer = [%ls]", issuer.GetPointer()); + AppLogTag(OSP_INSTALLER, "Subject = [%ls]", subject.GetPointer()); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + if (subject == issuer) + { + AppLogTag(OSP_INSTALLER, "subject, issuer is matched."); + + r = pCertPath->AddCertificate(rootCert); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] AddCertificate(DistributorRootCert) is failed."); + + AppLogTag(OSP_INSTALLER, "AddCertificate() RootCert = [%d]", certType); + __pContext->SetRootCertType((RootCertificateType)certType); + + ret = true; + + break; + } + else + { + AppLogTag(OSP_INSTALLER, "subject, issuer is not matched."); + ret = false; + } + } + +CATCH: + delete pIntermediateCA; + return ret; +} + +bool +SignatureManager::AddAuthorRootCert(X509CertificatePath* pCertPath) +{ + TryReturn(pCertPath, false, "[osp-installer] pCertPath is null."); + + result r = E_SUCCESS; + bool ret = true; + ByteBuffer byteBuffer; + X509Certificate rootCert; + int length = 0; + const char* pAuthorRootCert = "MIICnzCCAggCCQCn+GGT4zh+BjANBgkqhkiG9w0BAQUFADCBkzELMAkGA1UEBhMC" + "S1IxDjAMBgNVBAgMBVN1d29uMQ4wDAYDVQQHDAVTdXdvbjEWMBQGA1UECgwNVGl6" + "ZW4gVGVzdCBDQTElMCMGA1UECwwcVGl6ZW4gVGVzdCBEZXZlbG9wZXIgUm9vdCBD" + "QTElMCMGA1UEAwwcVGl6ZW4gVGVzdCBEZXZlbG9wZXIgUm9vdCBDQTAeFw0xMjEw" + "MjYwOTUwMTNaFw0yMjEwMjQwOTUwMTNaMIGTMQswCQYDVQQGEwJLUjEOMAwGA1UE" + "CAwFU3V3b24xDjAMBgNVBAcMBVN1d29uMRYwFAYDVQQKDA1UaXplbiBUZXN0IENB" + "MSUwIwYDVQQLDBxUaXplbiBUZXN0IERldmVsb3BlciBSb290IENBMSUwIwYDVQQD" + "DBxUaXplbiBUZXN0IERldmVsb3BlciBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUA" + "A4GNADCBiQKBgQDWT6ZH5JyGadTUK1QmNwU8j+py4WtuElJE+4/wPFP8/KBmvvmI" + "rGVjhUbKXToKIo8N6C/0SLxGEWuRAIoZHhg5JVbw1Ay7smgJJHizDUAqMTmV6LI9" + "yTFbBV+OlO2Dir4LVdQ/XDBiqqslr7pqXgsg1V2g7x+tOI/f3dn2kWoVZQIDAQAB" + "MA0GCSqGSIb3DQEBBQUAA4GBADGJYMtzUBDK+KKLZQ6zYmrKb+OWLlmEr/t/c2af" + "KjTKUtommcz8VeTPqrDBOwxlVPdxlbhisCYzzvwnWeZk1aeptxxU3kdW9N3/wocN" + "5nBzgqkkHJnj/ptqjrH2v/m0Z3hBuI4/akHIIfCBF8mUHwqcxYsRdcCIrkgp2Aiv" + "bSaM"; + + length = strlen(pAuthorRootCert); + byteBuffer.Construct(length); + + r = byteBuffer.SetArray((byte*)pAuthorRootCert, 0, length); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] SetArray() is failed."); + + byteBuffer.Flip(); + + r = rootCert.Construct(byteBuffer); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] rootCert.Construct() is failed."); + + r = pCertPath->AddCertificate(rootCert); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] AddCertificate(AuthorRootCert) is failed."); + +CATCH: + return ret; +} diff --git a/src/Manager/SignatureManager.h b/src/Manager/SignatureManager.h new file mode 100644 index 0000000..70fc7c7 --- /dev/null +++ b/src/Manager/SignatureManager.h @@ -0,0 +1,71 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SignatureManager.h + * @brief This is the header file for the %SignatureManager class. + * + * This header file contains the declarations of the %SignatureManager class. + */ +#ifndef _SIGNATURE_MANAGER_H_ +#define _SIGNATURE_MANAGER_H_ + +#include + +#include "InstallationContext.h" +#include "SignatureHandler.h" + +/** + * @class SignatureManager + * @brief This class represents the class of SignatureManager. + * @since 1.0 + * + * This class represents the class of SignatureManager. + * + */ + +class SignatureManager +{ +public: + SignatureManager(void); + virtual ~SignatureManager(void); + + bool Construct(InstallationContext *pConext); + bool SetSignature(); + bool AddCert(); + bool VerifyChain(); + //bool VerifySignature(); + +private: + SignatureManager(const SignatureManager& value); + SignatureManager& operator =(const SignatureManager& source); + + bool Validate(Tizen::Security::Cert::X509CertificatePath* pCertPath); + bool AddCertificate(Tizen::Security::Cert::X509CertificatePath* pCertPath, Tizen::Base::Collection::IList* pCertChain); + bool AddDistributorRootCert(Tizen::Security::Cert::X509CertificatePath* pCertPath); + bool AddAuthorRootCert(Tizen::Security::Cert::X509CertificatePath* pCertPath); + +private: + InstallationContext* __pContext; + SignatureHandler* __pAuthorSignature; + SignatureHandler* __pDistributorSignature; + Tizen::Security::Cert::X509CertificatePath* __pAuthorCertPath; + Tizen::Security::Cert::X509CertificatePath* __pDistributorCertPath; + + +}; // SignatureManager + +#endif // _SIGNATURE_MANAGER_H_ diff --git a/src/Step/DrmStep.cpp b/src/Step/DrmStep.cpp new file mode 100755 index 0000000..9be5f1b --- /dev/null +++ b/src/Step/DrmStep.cpp @@ -0,0 +1,158 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file DrmStep.cpp + * @brief This is the implementation file for %ApplicationXmlStep class. + */ + +#include "InstallationContext.h" +#include "DrmStep.h" + +DrmStep::DrmStep(void) +:__state(STATE_DRM_CHECKING) +,__pContext(null) +{ +} + +DrmStep::~DrmStep(void) +{ +} + +InstallerError +DrmStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " DrmStep - START"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + __pContext = pContext; + + while (true) + { + switch (__state) + { + case STATE_DRM_CHECKING: + AppLogTag(OSP_INSTALLER, "[STATE_DRM_CHECKING]"); + error = OnDrmChecking(); + break; + + case STATE_DRM_PURCHASE_REQUEST: + AppLogTag(OSP_INSTALLER, "[STATE_DRM_PURCHASE_REQUEST]"); + error = OnPurchaseRequest(); + break; + + case STATE_DRM_LICENSE_REQUEST: + AppLogTag(OSP_INSTALLER, "[STATE_DRM_LICENSE_REQUEST]"); + error = OnLicenseRequest(); + break; + + case STATE_DRM_LICENSE_RESPONSE: + AppLogTag(OSP_INSTALLER, "[STATE_DRM_LICENSE_RESPONSE]"); + error = OnLicenseResponse(); + break; + + case STATE_DRM_DECRYPT: + AppLogTag(OSP_INSTALLER, "[STATE_DRM_DECRYPT]"); + error = OnDecryptPackage(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[STATE_DONE]"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " DrmStep - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + break; + } + } + + return error; +} + +void +DrmStep::GoNextState(void) +{ + __state++; +} + +InstallerError +DrmStep::OnDrmChecking(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +DrmStep::OnPurchaseRequest(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +DrmStep::OnLicenseRequest(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +DrmStep::OnLicenseResponse(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +DrmStep::OnDecryptPackage(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +DrmStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} diff --git a/src/Step/DrmStep.h b/src/Step/DrmStep.h new file mode 100644 index 0000000..0de8124 --- /dev/null +++ b/src/Step/DrmStep.h @@ -0,0 +1,70 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file DrmStep.h + * @brief This is the header file for the %DrmStep class. + * + * This header file contains the declarations of the %DrmStep class. + */ +#ifndef _DRM_STEP_H_ +#define _DRM_STEP_H_ + +#include "IInstallationStep.h" + +/** + * @class DrmStep + * @brief This class represents the class of DrmStep. + * @since 1.0 + * + * This class represents the class of DrmStep. + * + */ +class DrmStep + : public IInstallationStep +{ +public: + DrmStep(void); + virtual ~DrmStep(void); + + virtual InstallerError Run(InstallationContext* pContext); + +private: + enum + { + STATE_DRM_CHECKING, + STATE_DRM_PURCHASE_REQUEST, + STATE_DRM_LICENSE_REQUEST, + STATE_DRM_LICENSE_RESPONSE, + STATE_DRM_DECRYPT, + STATE_DONE + }; + + void GoNextState(void); + InstallerError OnDrmChecking(void); + InstallerError OnPurchaseRequest(void); + InstallerError OnLicenseRequest(void); + InstallerError OnLicenseResponse(void); + InstallerError OnDecryptPackage(void); + InstallerError OnStateDone(void); + +private: + int __state; + InstallationContext* __pContext; + +}; // DrmStep + +#endif //_DRM_STEP_H_ diff --git a/src/Step/IInstallationStep.cpp b/src/Step/IInstallationStep.cpp new file mode 100644 index 0000000..e101bfb --- /dev/null +++ b/src/Step/IInstallationStep.cpp @@ -0,0 +1,30 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file IInstallationStep.cpp + * @brief This is the implementation file for %IInstallationStep class. + */ + +#include "IInstallationStep.h" + +IInstallationStep::IInstallationStep(void) +{ +} + +IInstallationStep::~IInstallationStep(void) +{ +} diff --git a/src/Step/IInstallationStep.h b/src/Step/IInstallationStep.h new file mode 100644 index 0000000..a90dd82 --- /dev/null +++ b/src/Step/IInstallationStep.h @@ -0,0 +1,49 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file IInstallationStep.h + * @brief This is the header file for the %IInstallationStep class. + * + * This header file contains the declarations of the %IInstallationStep class. + */ +#ifndef _IINSTALLATION_STEP_H_ +#define _IINSTALLATION_STEP_H_ + +#include "InstallerDefs.h" + +class InstallationContext; + +/** + * @class IInstallationStep + * @brief This class represents the class of IInstallationStep. + * @since 1.0 + * + * This class represents the class of IInstallationStep. + * + */ + +class IInstallationStep +{ +public: + IInstallationStep(void); + virtual ~IInstallationStep(void); + + virtual InstallerError Run(InstallationContext* pContext) = 0; + +}; // IInstallationStep + +#endif // _IINSTALLATION_STEP_H_ diff --git a/src/Step/LicenseStep.cpp b/src/Step/LicenseStep.cpp new file mode 100755 index 0000000..6d76c99 --- /dev/null +++ b/src/Step/LicenseStep.cpp @@ -0,0 +1,102 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file LicenseStep.cpp + * @brief This is the implementation file for %LicenseStep class. + */ + +#include "InstallationContext.h" +#include "LicenseStep.h" + +LicenseStep::LicenseStep(void) +:__state(STATE_LICENSE_VERIFICATION) +,__pContext(null) +{ +} + +LicenseStep::~LicenseStep(void) +{ +} + +InstallerError +LicenseStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " LicenseStep - START"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + __pContext = pContext; + + while (true) + { + switch (__state) + { + case STATE_LICENSE_VERIFICATION: + AppLogTag(OSP_INSTALLER, "[STATE_LICENSE_VERIFICATION]"); + error = OnStateLicenseVerification(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[STATE_DONE]"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " LicenseStep - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + break; + } + } + + return error; +} + +void +LicenseStep::GoNextState(void) +{ + __state++; +} + +InstallerError +LicenseStep::OnStateLicenseVerification(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +LicenseStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} diff --git a/src/Step/LicenseStep.h b/src/Step/LicenseStep.h new file mode 100644 index 0000000..0bb1ee4 --- /dev/null +++ b/src/Step/LicenseStep.h @@ -0,0 +1,62 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file LicenseStep.h + * @brief This is the header file for the %LicenseStep class. + * + * This header file contains the declarations of the %LicenseStep class. + */ +#ifndef _LICENSE_STEP_H_ +#define _LICENSE_STEP_H_ + +#include "IInstallationStep.h" + +/** + * @class LicenseStep + * @brief This class represents the class of LicenseStep. + * @since 1.0 + * + * This class represents the class of LicenseStep. + * + */ +class LicenseStep + : public IInstallationStep +{ +public: + LicenseStep(void); + virtual ~LicenseStep(void); + + virtual InstallerError Run(InstallationContext* pContext); + +private: + enum + { + STATE_LICENSE_VERIFICATION, + STATE_DONE + }; + + void GoNextState(void); + InstallerError OnStateLicenseVerification(void); + InstallerError OnStateDone(void); + +private: + int __state; + InstallationContext* __pContext; + +}; // LicenseStep + +#endif //_LICENSE_STEP_H_ diff --git a/src/Step/ManifestXmlStep.cpp b/src/Step/ManifestXmlStep.cpp new file mode 100755 index 0000000..d055799 --- /dev/null +++ b/src/Step/ManifestXmlStep.cpp @@ -0,0 +1,140 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestStep.cpp + * @brief This is the implementation file for %ManifestStep class. + */ + +#include + +#include + +#include +#include + +#include "InstallationContext.h" +#include "ManifestHandler.h" +#include "ManifestXmlStep.h" + +using namespace Tizen::Base; +using namespace Tizen::App::Package; +using namespace Tizen::Io; + +ManifestXmlStep::ManifestXmlStep(void) +:__state(STATE_MANIFEST_XML) +,__pContext(null) +{ +} + +ManifestXmlStep::~ManifestXmlStep(void) +{ +} + +InstallerError +ManifestXmlStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " ManifestXmlStep - START"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + __pContext = pContext; + + while (true) + { + switch (__state) + { + case STATE_MANIFEST_XML: + AppLogTag(OSP_INSTALLER, "[STATE_MANIFEST]"); + error = OnStateManifestXml(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[STATE_DONE]"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " ManifestXmlStep - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + break; + } + } + + return error; +} + +void +ManifestXmlStep::GoNextState(void) +{ + __state++; +} + +InstallerError +ManifestXmlStep::OnStateManifestXml(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + bool ret = false; + _PackageInfoImpl *pPackageInfoImpl = null; + String manifestXmlPath; + result r = E_SUCCESS; + + manifestXmlPath = __pContext->GetManifestXmlPath(); + + FileAttributes attr; + r = File::GetAttributes(manifestXmlPath, attr); + TryReturn(!IsFailed(r), INSTALLER_ERROR_MANIFEST_NOT_FOUND, "[osp-installer] File::GetAttributes() failed"); + + std::unique_ptr pFilepath(_StringConverter::CopyToCharArrayN(manifestXmlPath)); + TryReturn(pFilepath, INSTALLER_ERROR_OUT_OF_MEMORY, "[osp-installer] pFilepath is null"); + + AppLogTag(OSP_INSTALLER, "manifest file=[%ls]", manifestXmlPath.GetPointer()); + + ManifestHandler manifestHandler; + manifestHandler.Construct(__pContext); + ret = manifestHandler.Parse(pFilepath.get()); + TryReturn(ret == true, INSTALLER_ERROR_MANIFEST_INVALID, "[osp-installer] manifestHandler.Parse() failed"); + + pPackageInfoImpl = __pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, error = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pPackageInfoImpl is null"); + __pContext->SetId(pPackageInfoImpl->GetId()); + + GoNextState(); + + return error; +} + +InstallerError +ManifestXmlStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} diff --git a/src/Step/ManifestXmlStep.h b/src/Step/ManifestXmlStep.h new file mode 100644 index 0000000..08d2975 --- /dev/null +++ b/src/Step/ManifestXmlStep.h @@ -0,0 +1,62 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestXmlStep.h + * @brief This is the header file for the %ManifestXmlStep class. + * + * This header file contains the declarations of the %ManifestXmlStep class. + */ +#ifndef _MANIFEST_XML_STEP_H_ +#define _MANIFEST_XML_STEP_H_ + +#include "IInstallationStep.h" + +/** + * @class ManifestXmlStep + * @brief This class represents the class of ManifestXmlStep. + * @since 1.0 + * + * This class represents the class of ManifestXmlStep. + * + */ +class ManifestXmlStep + : public IInstallationStep +{ +public: + ManifestXmlStep(void); + virtual ~ManifestXmlStep(void); + + virtual InstallerError Run(InstallationContext* pContext); + +private: + enum + { + STATE_MANIFEST_XML, + STATE_DONE + }; + + void GoNextState(void); + InstallerError OnStateManifestXml(void); + InstallerError OnStateDone(void); + +private: + int __state; + InstallationContext* __pContext; + +}; // ManifestXmlStep + +#endif //_MANIFEST_XML_STEP_H_ diff --git a/src/Step/PackageCheckStep.cpp b/src/Step/PackageCheckStep.cpp new file mode 100755 index 0000000..5c5813a --- /dev/null +++ b/src/Step/PackageCheckStep.cpp @@ -0,0 +1,154 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PackageCheckStep.cpp + * @brief This is the implementation file for %PackageCheckStep class. + */ + +#include +#include + +#include "InstallationContext.h" +#include "PackageCheckStep.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Utility; +using namespace Tizen::Io; + +PackageCheckStep::PackageCheckStep(void) +:__state(STATE_PACKAGE_CHECK) +,__pContext(null) +{ +} + +PackageCheckStep::~PackageCheckStep(void) +{ +} + +InstallerError +PackageCheckStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " PackageCheckStep - START"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + __pContext = pContext; + + while (true) + { + switch (__state) + { + case STATE_PACKAGE_CHECK: + AppLogTag(OSP_INSTALLER, "[STATE_PACKAGE_CHECK]"); + error = OnStatePackageCheck(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[STATE_DONE]"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " PackageCheckStep - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + break; + } + } + + return error; +} + +void +PackageCheckStep::GoNextState(void) +{ + __state++; +} + +InstallerError +PackageCheckStep::OnStatePackageCheck(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + String tempDir; + + if (__pContext->GetInstallationStorage() == InstallationContext::INSTALLATION_STORAGE_INTERNAL) + { + tempDir = DIR_OSP_APPLICATIONS_TEMP; + } + else + { + tempDir = DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP; + } + + __pContext->SetTemporaryDir(tempDir); + __pContext->SetInstallDir(tempDir); + + if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == false) + { + result r = E_SUCCESS; + r = Directory::Create(DIR_OSP_APPLICATIONS_TEMP, false); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed"); + } + + String packagePath = __pContext->GetPackagePath(); + if (InstallerUtil::IsDrmFile(packagePath) == true) + { + bool res = false; + res = InstallerUtil::DecryptPackage(packagePath); + TryReturn(res == true, INSTALLER_ERROR_DRM, "[osp-installer] InstallerUtil::DecryptPackage() failed"); + } + + FileUnzipper unzipper; + unzipper.Construct(packagePath); + + AppLogTag(OSP_INSTALLER, "UnzipTo(manifest.xml) - START"); + unzipper.UnzipTo(tempDir, L"info/manifest.xml"); + unzipper.UnzipTo(tempDir, L"signature1.xml"); + unzipper.UnzipTo(tempDir, L"author-signature.xml"); + AppLogTag(OSP_INSTALLER, "UnzipTo(manifest.xml) - END"); + + if ((File::IsFileExist(__pContext->GetSignatureXmlPath()) == true) && + (File::IsFileExist(__pContext->GetAuthorSignatureXmlPath()) == true)) + { + AppLogTag(OSP_INSTALLER, "[VerifySignature] VerificationMode ON"); + __pContext->SetVerificationMode(true); + } + + GoNextState(); + return error; +} + +InstallerError +PackageCheckStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} diff --git a/src/Step/PackageCheckStep.h b/src/Step/PackageCheckStep.h new file mode 100644 index 0000000..b39ef44 --- /dev/null +++ b/src/Step/PackageCheckStep.h @@ -0,0 +1,62 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PackageCheckStep.h + * @brief This is the header file for the %PackageCheckStep class. + * + * This header file contains the declarations of the %PackageCheckStep class. + */ +#ifndef _PACKAGE_CHECK_STEP_H_ +#define _PACKAGE_CHECK_STEP_H_ + +#include "IInstallationStep.h" + +/** + * @class PackageCheckStep + * @brief This class represents the class of PackageCheckStep. + * @since 1.0 + * + * This class represents the class of PackageCheckStep. + * + */ +class PackageCheckStep + : public IInstallationStep +{ +public: + PackageCheckStep(void); + virtual ~PackageCheckStep(void); + + virtual InstallerError Run(InstallationContext* pContext); + +private: + enum + { + STATE_PACKAGE_CHECK, + STATE_DONE + }; + + void GoNextState(void); + InstallerError OnStatePackageCheck(void); + InstallerError OnStateDone(void); + +private: + int __state; + InstallationContext* __pContext; + +}; // PackageCheckStep + +#endif //_PACKAGE_CHECK_STEP_H_ diff --git a/src/Step/SignatureStep.cpp b/src/Step/SignatureStep.cpp new file mode 100755 index 0000000..fab780f --- /dev/null +++ b/src/Step/SignatureStep.cpp @@ -0,0 +1,211 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SignatureStep.cpp + * @brief This is the implementation file for %SignatureStep class. + */ + +#include +#include +#include + +#include "InstallationContext.h" +#include "PrivilegeHandler.h" +#include "SignatureHandler.h" +#include "SignatureStep.h" + +using namespace Tizen::App::Package; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +SignatureStep::SignatureStep(void) +:__state(STATE_SIGNER_CERT) +,__pContext(null) +,__pSignatureManager(null) +{ +} + +SignatureStep::~SignatureStep(void) +{ + delete __pSignatureManager; +} + +InstallerError +SignatureStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " SignatureStep - START"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + __pContext = pContext; + + if (__pContext->IsVerificationMode() == false) + { + AppLogTag(OSP_INSTALLER, "no signature file[%ls]", __pContext->GetSignatureXmlPath().GetPointer()); + return INSTALLER_ERROR_NONE; + } + + while (true) + { + switch (__state) + { + case STATE_SIGNER_CERT: + AppLogTag(OSP_INSTALLER, "[STATE_SIGNER_CERT]"); + error = OnStateSignerCert(); + break; + + case STATE_CERT_CHAIN: + AppLogTag(OSP_INSTALLER, "[STATE_CERT_CHAIN]"); + error = OnStateCertChain(); + break; + + case STATE_ROOT_CERT: + AppLogTag(OSP_INSTALLER, "[STATE_ROOT_CERT]"); + error = OnStateRootCert(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[STATE_DONE]"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " SignatureStep - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + break; + } + } + + return error; +} + +void +SignatureStep::GoNextState(void) +{ + __state++; +} + +InstallerError +SignatureStep::OnStateSignerCert(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + bool ret = true; + + __pSignatureManager = new (std::nothrow) SignatureManager(); + TryCatch(__pSignatureManager, error = INSTALLER_ERROR_OUT_OF_MEMORY, "[osp-installer] __pSignatureManager is null."); + + ret = __pSignatureManager->Construct(__pContext); + TryCatch(ret == true, error = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Construct() failed"); + + ret = __pSignatureManager->SetSignature(); + TryCatch(ret == true, error = INSTALLER_ERROR_SIGNATURE_INVALID, "[osp-installer] SetSignature() failed"); + +CATCH: + GoNextState(); + return error; +} + +InstallerError +SignatureStep::OnStateCertChain(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + bool ret = true; + + ret = __pSignatureManager->AddCert(); + TryCatch(ret == true, error = INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED, "[osp-installer] AddCert(DEVELOPER_ROOT_CERTIFICATE) failed"); + + ret = __pSignatureManager->VerifyChain(); + TryCatch(ret == true, error = INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED, "[osp-installer] VerifyChain() failed"); + +CATCH: + GoNextState(); + return error; +} + +InstallerError +SignatureStep::OnStateRootCert(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + result r = E_SUCCESS; + String privileges; + String hmacPrivileges; + + const ArrayList* pPrivilegeList = __pContext->GetPrivilegeList(); + RootCertificateType certType = __pContext->GetRootCertType(); + _PackageInfoImpl* pPackageInfoImpl = __pContext->GetPackageInfoImpl(); + String appId = pPackageInfoImpl->GetId(); + int apiVisibility = GetApiVisibility(certType); + + AppLogTag(OSP_INSTALLER, "AppId = [%ls], CertType = [%d], ApiVisibility = [%d]", appId.GetPointer(), certType, apiVisibility); + + r = PrivilegeHandler::GenerateCipherPrivilege(appId, *pPrivilegeList, apiVisibility, privileges, hmacPrivileges); + TryCatch(!IsFailed(r), error = INSTALLER_ERROR_PRIVILEGE_INVALID, "[osp-installer] privMgr.GeneratePrivilegeString() failed"); + + pPackageInfoImpl->SetPrivilegesValue(privileges, hmacPrivileges); + pPackageInfoImpl->SetCertType(apiVisibility); + +CATCH: + GoNextState(); + return error; +} + +InstallerError +SignatureStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +int +SignatureStep::GetApiVisibility(RootCertificateType certType) +{ + int apiVisibility = _API_VISIBILITY_NONE; + + if (certType == ROOT_CERTIFICATE_PUBLIC) + { + apiVisibility = _API_VISIBILITY_PUBLIC; + } + else if (certType == ROOT_CERTIFICATE_PARTNER) + { + apiVisibility = _API_VISIBILITY_PARTNER; + } + else if (certType == ROOT_CERTIFICATE_PARTNER_OPERATOR) + { + apiVisibility = _API_VISIBILITY_PARTNER_OPERATOR; + } + else if (certType == ROOT_CERTIFICATE_PARTNER_MANUFACTURER) + { + apiVisibility = _API_VISIBILITY_PARTNER_MANUFACTURER; + } + + return apiVisibility; +} diff --git a/src/Step/SignatureStep.h b/src/Step/SignatureStep.h new file mode 100755 index 0000000..610d888 --- /dev/null +++ b/src/Step/SignatureStep.h @@ -0,0 +1,73 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SignatureStep.h + * @brief This is the header file for the %SignatureStep class. + * + * This header file contains the declarations of the %SignatureStep class. + */ +#ifndef _SIGNATURE_STEP_H_ +#define _SIGNATURE_STEP_H_ + +#include "IInstallationStep.h" +#include "SignatureManager.h" + +/** + * @class SignatureStep + * @brief This class represents the class of SignatureStep. + * @since 1.0 + * + * This class represents the class of SignatureStep. + * + */ +class SignatureStep + : public IInstallationStep +{ +public: + SignatureStep(void); + virtual ~SignatureStep(void); + + virtual InstallerError Run(InstallationContext* pContext); + +private: + enum + { + STATE_SIGNER_CERT, + STATE_CERT_CHAIN, + STATE_ROOT_CERT, + STATE_DONE + }; + + SignatureStep(const SignatureStep& value); + SignatureStep& operator =(const SignatureStep& source); + + void GoNextState(void); + InstallerError OnStateSignerCert(void); + InstallerError OnStateCertChain(void); + InstallerError OnStateRootCert(void); + InstallerError OnStateDone(void); + + int GetApiVisibility(RootCertificateType certType); + +private: + int __state; + InstallationContext* __pContext; + SignatureManager* __pSignatureManager; + +}; // SignatureStep + +#endif //_SIGNATURE_STEP_H_ diff --git a/src/Step/SystemCheckStep.cpp b/src/Step/SystemCheckStep.cpp new file mode 100755 index 0000000..fb9c9be --- /dev/null +++ b/src/Step/SystemCheckStep.cpp @@ -0,0 +1,134 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SystemCheckStep.cpp + * @brief This is the implementation file for %SystemCheckStep class. + */ + +#include "InstallationContext.h" +#include "SystemCheckStep.h" + +SystemCheckStep::SystemCheckStep(void) +:__state(STATE_SYSTEM_CHECK) +,__pContext(null) +{ +} + +SystemCheckStep::~SystemCheckStep(void) +{ +} + +InstallerError +SystemCheckStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " SystemCheckStep - START"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + __pContext = pContext; + + while (true) + { + switch (__state) + { + case STATE_SYSTEM_CHECK: + AppLogTag(OSP_INSTALLER, "[STATE_SYSTEM_CHECK]"); + error = OnStateSystemCheck(); + break; + + case STATE_AGENT_CHECK: + AppLogTag(OSP_INSTALLER, "[STATE_AGENT_CHECK]"); + error = OnStateAgentCheck(); + break; + + case STATE_AGENT_TIMER: + AppLogTag(OSP_INSTALLER, "[STATE_AGENT_TIMER]"); + error = OnStateAgentTimer(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[STATE_DONE]"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " SystemCheckStep - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + break; + } + } + + return error; +} + +void +SystemCheckStep::GoNextState(void) +{ + __state++; +} + +InstallerError +SystemCheckStep::OnStateSystemCheck(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + // Check preferred storage + __pContext->SetInstallationStorage(InstallationContext::INSTALLATION_STORAGE_INTERNAL); + + GoNextState(); + return error; +} + +InstallerError +SystemCheckStep::OnStateAgentCheck(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +SystemCheckStep::OnStateAgentTimer(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +SystemCheckStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} diff --git a/src/Step/SystemCheckStep.h b/src/Step/SystemCheckStep.h new file mode 100644 index 0000000..506f587 --- /dev/null +++ b/src/Step/SystemCheckStep.h @@ -0,0 +1,66 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SystemCheckStep.h + * @brief This is the header file for the %SystemCheckStep class. + * + * This header file contains the declarations of the %SystemCheckStep class. + */ +#ifndef _SYSTEM_CHECK_STEP_H_ +#define _SYSTEM_CHECK_STEP_H_ + +#include "IInstallationStep.h" + +/** + * @class SystemCheckStep + * @brief This class represents the class of SystemCheckStep. + * @since 1.0 + * + * This class represents the class of SystemCheckStep. + * + */ +class SystemCheckStep + : public IInstallationStep +{ +public: + SystemCheckStep(void); + virtual ~SystemCheckStep(void); + + virtual InstallerError Run(InstallationContext* pContext); + +private: + enum + { + STATE_SYSTEM_CHECK, + STATE_AGENT_CHECK, + STATE_AGENT_TIMER, + STATE_DONE + }; + + void GoNextState(void); + InstallerError OnStateSystemCheck(void); + InstallerError OnStateAgentCheck(void); + InstallerError OnStateAgentTimer(void); + InstallerError OnStateDone(void); + +private: + int __state; + InstallationContext* __pContext; + +}; // SystemCheckStep + +#endif //_SYSTEM_CHECK_STEP_H_ diff --git a/src/Step/UninstallStep.cpp b/src/Step/UninstallStep.cpp new file mode 100755 index 0000000..27209e0 --- /dev/null +++ b/src/Step/UninstallStep.cpp @@ -0,0 +1,292 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file UninstallStep.cpp + * @brief This is the implementation file for %UninstallStep class. + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include "InstallationContext.h" +#include "UninstallStep.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::App::Package; +using namespace Tizen::Io; + +UninstallStep::UninstallStep(void) +:__state(STATE_GET_PACKAGEINFO) +,__pContext(null) +{ +} + +UninstallStep::~UninstallStep(void) +{ +} + +InstallerError +UninstallStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " UninstallStep - START"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + __pContext = pContext; + + while (true) + { + switch (__state) + { + case STATE_GET_PACKAGEINFO: + AppLogTag(OSP_INSTALLER, "[STATE_GET_PACKAGEINFO]"); + error = OnStateGetPackageInfo(); + break; + + case STATE_CHECK_APP_RUNNING: + AppLogTag(OSP_INSTALLER, "[STATE_CHECK_APP_RUNNING]"); + error = OnStateCheckAppRunning(); + break; + + case STATE_TERMINATE_APP: + AppLogTag(OSP_INSTALLER, "[STATE_TERMINATE_APP]"); + error = OnStateTerminateApp(); + break; + + case STATE_START_TIMER: + AppLogTag(OSP_INSTALLER, "[STATE_START_TIMER]"); + error = OnStateStartTimer(); + break; + + case STATE_DELETE_DIR: + AppLogTag(OSP_INSTALLER, "[STATE_DELETE_DIR]"); + error = OnStateRemoveDir(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[STATE_DONE]"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " UninstallStep - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + break; + } + } + + return error; +} + +void +UninstallStep::GoNextState(void) +{ + __state++; +} + +InstallerError +UninstallStep::OnStateGetPackageInfo(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + String appId = __pContext->GetId(); + + _PackageInfoImpl* pPackageInfoImpl = __pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pPackageInfoImpl is null"); + + AppLogTag(OSP_INSTALLER, "appId = %S", appId.GetPointer()); + pPackageInfoImpl->Construct(appId); + + if (__pContext->IsHybridService() == true) + { + AppLogTag(OSP_INSTALLER, "Uninstallation for HybridService"); + __state = STATE_DELETE_DIR; + return error; + } + + if (pPackageInfoImpl->IsInstalledInExternalStorage() == true) + { + int res = 0; + app2ext_handle* pHandle = null; + + std::unique_ptr pAppId(_StringConverter::CopyToCharArrayN(appId)); + TryReturn(pAppId, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pAppId is null"); + + pHandle = app2ext_init(APP2EXT_SD_CARD); + TryReturn(pHandle, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] app2ext_init() failed"); + + res = pHandle->interface.pre_uninstall(pAppId.get()); + TryReturn(res == 0, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pHandle->interface.pre_uninstall() failed [%d]", res); + + __pContext->SetApp2ExtHandle(pHandle); + + AppLogTag(OSP_INSTALLER, "[app2sd] pre_uninstall(%s)", pAppId.get()); + } + + ArrayList* pList = pPackageInfoImpl->GetAppInfoListN(); + TryReturn(pList, INSTALLER_ERROR_DATABASE, "[osp-installer] pList is null."); + + for (int i = 0; i < pList->GetCount(); i++) + { + _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pList->GetAt(i)); + if (pAppInfoImpl) + { + pPackageInfoImpl->AddAppInfo(*pAppInfoImpl); + pAppInfoImpl = null; + } + } + + __state = STATE_DELETE_DIR; + + return error; +} + + +InstallerError +UninstallStep::OnStateCheckAppRunning(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +UninstallStep::OnStateTerminateApp(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +UninstallStep::OnStateStartTimer(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +UninstallStep::OnStateRemoveDir(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + _PackageInfoImpl* pPackageInfoImpl = __pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pPackageInfoImpl is null"); + + String rootPath; + rootPath = pPackageInfoImpl->GetAppRootPath(); + AppLogTag(OSP_INSTALLER, "rootPath[%ls]", rootPath.GetPointer()); + + String compatPath(rootPath); + compatPath.Append(L"/info/compat.info"); + bool ospCompat = File::IsFileExist(compatPath); + result r = GetLastResult(); + if (r == E_SUCCESS && ospCompat == true) + { + if (_FileImpl::FinalizeDataCaging(rootPath) == false) + { + AppLogTag(OSP_INSTALLER, "[Tizen::Io] Failed to unmount directories for 2.0 application, appRootPath: %ls", + rootPath.GetPointer()); + return INSTALLER_ERROR_UNMOUNT_FAILED; + } + } + else if (r != E_SUCCESS) + { + AppLogTag(OSP_INSTALLER, "[Tizen::Io] Failed to access %ls", compatPath.GetPointer()); + return INSTALLER_ERROR_UNMOUNT_FAILED; + } + + AppLogTag(OSP_INSTALLER, "Directory::Remove - START"); + + if (__pContext->IsHybridService() == true) + { + AppLogTag(OSP_INSTALLER, "Uninstallation for HybridService - skip Remove"); + + } + else + { + String realPath; + if (InstallerUtil::IsSymlink(rootPath) == true) + { + if (InstallerUtil::GetRealPath(rootPath, realPath) == true) + { + InstallerUtil::Remove(realPath); + } + } + + InstallerUtil::Remove(rootPath); + } + + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + + pAppList = pPackageInfoImpl->GetAppInfoList(); + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + String packageName = pAppInfoImpl->GetPackageName(); + String destPath; + destPath.Format(1024, L"%S/%S", SLP_APP_PATH, packageName.GetPointer()); + InstallerUtil::Remove(destPath); + + if (pAppInfoImpl->GetAppFeature() == CATEGORY_TYPE_IME) + { + String symlinkPath; + symlinkPath.Format(1024, L"%s/%ls.so", IME_PATH, packageName.GetPointer()); + InstallerUtil::Remove(symlinkPath); + } + } + } + AppLogTag(OSP_INSTALLER, "Directory::Remove - END"); + + GoNextState(); + return error; +} + +InstallerError +UninstallStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} diff --git a/src/Step/UninstallStep.h b/src/Step/UninstallStep.h new file mode 100644 index 0000000..ca97334 --- /dev/null +++ b/src/Step/UninstallStep.h @@ -0,0 +1,70 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file UninstallStep.h + * @brief This is the header file for the %UninstallStep class. + * + * This header file contains the declarations of the %UninstallStep class. + */ +#ifndef _UNINSTALL_STEP_H_ +#define _UNINSTALL_STEP_H_ + +#include "IInstallationStep.h" + +/** + * @class UninstallStep + * @brief This class represents the class of UninstallStep. + * @since 1.0 + * + * This class represents the class of UninstallStep. + * + */ +class UninstallStep + : public IInstallationStep +{ +public: + UninstallStep(void); + virtual ~UninstallStep(void); + + virtual InstallerError Run(InstallationContext* pContext); + +private: + enum + { + STATE_GET_PACKAGEINFO, + STATE_CHECK_APP_RUNNING, + STATE_TERMINATE_APP, + STATE_START_TIMER, + STATE_DELETE_DIR, + STATE_DONE + }; + + void GoNextState(void); + InstallerError OnStateGetPackageInfo(void); + InstallerError OnStateCheckAppRunning(void); + InstallerError OnStateTerminateApp(void); + InstallerError OnStateStartTimer(void); + InstallerError OnStateRemoveDir(void); + InstallerError OnStateDone(void); + +private: + int __state; + InstallationContext* __pContext; + +}; // UninstallStep + +#endif //_UNINSTALL_STEP_H_ diff --git a/src/Step/UnpackStep.cpp b/src/Step/UnpackStep.cpp new file mode 100755 index 0000000..2fbfc46 --- /dev/null +++ b/src/Step/UnpackStep.cpp @@ -0,0 +1,358 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file UnpackStep.cpp + * @brief This is the implementation file for %UnpackStep class. + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include "InstallationContext.h" +#include "UnpackStep.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::App::Package; +using namespace Tizen::Io; + +UnpackStep::UnpackStep(void) +:__state(STATE_UNZIP) +,__pContext(null) +,__pDirectoryList(null) +,__uncompressedSize(0) +{ +} + +UnpackStep::~UnpackStep(void) +{ + if (__pDirectoryList) + { + GList* pList = null; + app2ext_dir_details* pDirDetails = null; + + pList = g_list_first(__pDirectoryList); + while (pList) + { + pDirDetails = (app2ext_dir_details*)pList->data; + if (pDirDetails && pDirDetails->name) + { + free(pDirDetails->name); + } + pList = g_list_next(pList); + } + g_list_free(__pDirectoryList); + } +} + +InstallerError +UnpackStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " UnpackStep - START"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + __pContext = pContext; + + while (true) + { + switch (__state) + { + case STATE_UNZIP: + AppLogTag(OSP_INSTALLER, "[STATE_UNZIP]"); + error = OnUnzip(); + break; + + case STATE_VERSION_CHECK: + AppLogTag(OSP_INSTALLER, "[STATE_VERSION_CHECK]"); + error = OnStateVersionCheck(); + break; + + case STATE_FILE_MOVE: + AppLogTag(OSP_INSTALLER, "[STATE_FILE_MOVE]"); + error = OnStateFileMove(); + break; + + case STATE_CREATE_DIR: + AppLogTag(OSP_INSTALLER, "[STATE_CREATE_DIR]"); + error = OnCreateDir(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[STATE_DONE]"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, " UnpackStep - END"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + break; + } + } + + return error; +} + +void +UnpackStep::GoNextState(void) +{ + __state++; +} + +InstallerError +UnpackStep::OnUnzip(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + _PackageInfoImpl *pPackageInfoImpl = null; + String newInstallPath; + app2ext_handle* pHandle = null; + + String installPath; + installPath = PATH_OPT_USR_APPS; + installPath += "/"; + + if (__pContext->GetPackageNameType() == INSTALLER_PREFIX_TYPE_ORG) + { + installPath += PACKAGE_NAME_PREFIX_ORG; + } + + installPath += __pContext->GetId(); + + result r = E_SUCCESS; + FileUnzipper unzipper; + r = unzipper.Construct(__pContext->GetPackagePath()); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] unzipper.Construct() failed"); + + if (__pContext->GetInstallationStorage() == InstallationContext::INSTALLATION_STORAGE_EXTERNAL) + { + int res = 0; + String appId = __pContext->GetId(); + + std::unique_ptr pAppId(_StringConverter::CopyToCharArrayN(appId)); + TryReturn(pAppId, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pAppId is null"); + + GetUncompressedInfo(unzipper); + TryReturn((__pDirectoryList && (__uncompressedSize > 0)), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] GetUncompressedInfo() failed"); + + pHandle = app2ext_init(APP2EXT_SD_CARD); + TryReturn(pHandle, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] app2ext_init() failed"); + + __pContext->SetApp2ExtHandle(pHandle); + + res = pHandle->interface.pre_install(pAppId.get(), __pDirectoryList, __uncompressedSize); + TryReturn(res == 0, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pHandle->interface.pre_install() failed [%d]", res); + + AppLogTag(OSP_INSTALLER, "[app2sd] pre_install(%s)", pAppId.get()); + } + + if (File::IsFileExist(installPath) == false) + { + r = Directory::Create(installPath, false); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed, installPath=%ls", installPath.GetPointer()); + } + + InstallerUtil::CreateSymlinkForAppDirectory(installPath, newInstallPath); + __pContext->SetInstallDir(newInstallPath); + + pPackageInfoImpl = __pContext->GetPackageInfoImpl(); + pPackageInfoImpl->SetAppRootPath(newInstallPath); + + AppLogTag(OSP_INSTALLER, "UnzipTo - START"); + unzipper.UnzipTo(newInstallPath); + AppLogTag(OSP_INSTALLER, "UnzipTo - END"); + + // GoNextState(); + __state = STATE_DONE; + return error; +} + +InstallerError +UnpackStep::OnStateVersionCheck(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +UnpackStep::OnStateFileMove(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +UnpackStep::OnCreateDir(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +InstallerError +UnpackStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + GoNextState(); + return error; +} + +bool +UnpackStep::CreateDefaultDir(void) +{ + // Directory::Create(DIR_OSP_APPLICATION_PHONE, true); + // Directory::Create(DIR_OSP_APPLICATION_MMC, true); + + return true; +} + +bool +UnpackStep::GetUncompressedInfo(const FileUnzipper& unzipper) +{ + result r = E_SUCCESS; + unsigned long totalSize = 0; + String directory; + String entryName; + ArrayList directoryList; + int entryCount = unzipper.GetEntryCount(); + + directoryList.Construct(); + + for(int i = 0; i < entryCount; i++) + { + int indexOf = 0; + int startIndex = 0; + unsigned long uncompressedSize = 0; + ZipEntry zipEntry; + + unzipper.GetEntry(i, zipEntry); + entryName = zipEntry.GetName(); + + while((r = entryName.IndexOf(L'/', startIndex, indexOf)) == E_SUCCESS) + { + String* pCurDirectory = new (std::nothrow) String; + TryReturn(pCurDirectory, false, "[osp-installer] pCurDirectory is null."); + + entryName.SubString(0, indexOf, *pCurDirectory); + + if (directoryList.Contains(*pCurDirectory) == false) + { + if (startIndex == 0) + { + AddDirectory(*pCurDirectory); + } + + AppLogTag(OSP_INSTALLER, "Folder[%ls], Size[%d]", pCurDirectory->GetPointer(), BLOCK_SIZE); + totalSize += BLOCK_SIZE; + + directoryList.Add(*pCurDirectory); + } + + startIndex = indexOf + 1; + } + + if (zipEntry.IsDirectory() == false) + { + uncompressedSize = zipEntry.GetUncompressedSize(); + + int blockCount = uncompressedSize / BLOCK_SIZE; + + if ((blockCount == 0) && (uncompressedSize != 0)) + { + uncompressedSize = BLOCK_SIZE; + } + else + { + int mod = uncompressedSize % BLOCK_SIZE; + if (mod != 0) + { + blockCount++; + } + uncompressedSize = (BLOCK_SIZE * blockCount); + } + + totalSize += uncompressedSize; + AppLogTag(OSP_INSTALLER, " -File[%ls], UncompressedSize[%d]", entryName.GetPointer(), (int)uncompressedSize); + } + } + + directoryList.RemoveAll(true); + __uncompressedSize = (int)(totalSize / (1024 * 1024)) + 1; + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "TotalSize = [%d]B", (int)totalSize); + AppLogTag(OSP_INSTALLER, "TotalSize = [%d]MB", __uncompressedSize); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + + return true; +} + +bool +UnpackStep::AddDirectory(const String& rootDirectory) +{ + int length = 0; + app2ext_dir_details* pDirDetails = null; + + pDirDetails = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details)); + TryReturn(pDirDetails, false, "[osp-installer] pDirDetails is null"); + + length = rootDirectory.GetLength(); + pDirDetails->name = (char*) calloc(1, (sizeof(char) * length) + 1); + snprintf(pDirDetails->name, length + 1, "%ls", rootDirectory.GetPointer()); + + if ((rootDirectory == L"bin") || (rootDirectory == L"res") || (rootDirectory == L"icons")) + { + pDirDetails->type = APP2EXT_DIR_RO; + } + else + { + pDirDetails->type = APP2EXT_DIR_RW; + } + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "# Root Directory = [%s], Type = [%d]", pDirDetails->name, pDirDetails->type); + + __pDirectoryList = g_list_append(__pDirectoryList, pDirDetails); + + return true; +} diff --git a/src/Step/UnpackStep.h b/src/Step/UnpackStep.h new file mode 100644 index 0000000..db7feff --- /dev/null +++ b/src/Step/UnpackStep.h @@ -0,0 +1,78 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file UnpackStep.h + * @brief This is the header file for the %UnpackStep class. + * + * This header file contains the declarations of the %UnpackStep class. + */ +#ifndef _UNPACK_STEP_H_ +#define _UNPACK_STEP_H_ + +#include + +#include + +#include "IInstallationStep.h" + +/** + * @class UnpackStep + * @brief This class represents the class of UnpackStep. + * @since 1.0 + * + * This class represents the class of UnpackStep. + * + */ +class UnpackStep + : public IInstallationStep +{ +public: + UnpackStep(void); + virtual ~UnpackStep(void); + + virtual InstallerError Run(InstallationContext* pContext); + +private: + enum + { + STATE_UNZIP, + STATE_VERSION_CHECK, + STATE_FILE_MOVE, + STATE_CREATE_DIR, + STATE_DONE + }; + + void GoNextState(void); + InstallerError OnUnzip(void); + InstallerError OnStateVersionCheck(void); + InstallerError OnStateFileMove(void); + InstallerError OnCreateDir(void); + InstallerError OnStateDone(void); + + bool CreateDefaultDir(void); + bool GetUncompressedInfo(const Tizen::Base::Utility::FileUnzipper& unzipper); + bool AddDirectory(const Tizen::Base::String& directory); + +private: + int __state; + InstallationContext* __pContext; + GList* __pDirectoryList; + int __uncompressedSize; + +}; // UnpackStep + +#endif //_UNPACK_STEP_H_ diff --git a/src/Util/InstallerUtil.cpp b/src/Util/InstallerUtil.cpp new file mode 100755 index 0000000..b706c0d --- /dev/null +++ b/src/Util/InstallerUtil.cpp @@ -0,0 +1,600 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallerUtil.cpp + * @brief This is the implementation file for %InstallerUtil class. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "InstallerDefs.h" +#include "InstallerUtil.h" + +#include + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::App; +using namespace Tizen::Io; + +InstallerUtil::InstallerUtil(void) +{ +} + +InstallerUtil::~InstallerUtil(void) +{ +} + +bool +InstallerUtil::Remove(const Tizen::Base::String& filePath) +{ + int err = -1; + result r = E_SUCCESS; + struct stat fileinfo; + + AppLogTag(OSP_INSTALLER, "+ Remove(): path=[%ls]", filePath.GetPointer()); + + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + err = lstat(pFilePath.get(), &fileinfo); + if (err < 0) + { + AppLogTag(OSP_INSTALLER, "Remove(): lstat(%s): %s[errno:%d]: skip", pFilePath.get(), strerror(errno), errno); + return true; + } + + if (S_ISLNK(fileinfo.st_mode)) + { + AppLogTag(OSP_INSTALLER, "Remove(): symlink, path=[%s]", pFilePath.get()); + err = unlink(pFilePath.get()); + TryReturn(err >= 0, false, "[osp-installer] unlink() failed(%s), filepath=[%s]", strerror(errno), pFilePath.get()); + } + else if (S_ISDIR(fileinfo.st_mode)) + { + AppLogTag(OSP_INSTALLER, "Remove(): directory, path=[%ls]", filePath.GetPointer()); + r = Directory::Remove(filePath, true); + TryReturn(!IsFailed(r), false, "[osp-installer] Directory::Remove() failed, filePath=%ls", filePath.GetPointer()); + } + else + { + AppLogTag(OSP_INSTALLER, "Remove(): file, path=[%ls]", filePath.GetPointer()); + r = File::Remove(filePath); + TryReturn(!IsFailed(r), false, "[osp-installer] File::Remove() failed, filePath=%ls", filePath.GetPointer()); + } + + return true; +} + +bool +InstallerUtil::Copy(const String& srcFilePath, const String& destFilePath) +{ + int bufSize = 4096; + int readBytes = 0; + result r = E_SUCCESS; + + // AppLogTag(OSP_INSTALLER, "+ Copy(): src=[%ls], dest=[%ls]", srcFilePath.GetPointer(), destFilePath.GetPointer()); + + File srcFile; + File destFile; + + std::unique_ptr pBuf(new (std::nothrow) char[bufSize]); + TryReturn(pBuf, false, "[osp-installer] pBuf is null"); + + r = srcFile.Construct(srcFilePath, L"r"); + TryReturn(!IsFailed(r), false, "[osp-installer] srcFile.Construct is failed"); + + r = destFile.Construct(destFilePath, L"w"); + TryReturn(!IsFailed(r), false, "[osp-installer] destFile.Construct is failed"); + + do + { + readBytes = srcFile.Read(pBuf.get(), bufSize); + if (readBytes > 0) + { + r = destFile.Write(pBuf.get(), readBytes); + TryReturn(!IsFailed(r), false, "[osp-installer] destFile.Write is failed"); + } + } + while (readBytes > 0); + + return true; +} + +bool +InstallerUtil::CopyDirectory(const String& srcFilePath, const String& destFilePath) +{ + result r = E_SUCCESS; + + AppLogTag(OSP_INSTALLER, "+ CopyDirectory(): src=[%ls], dest=[%ls]", srcFilePath.GetPointer(), destFilePath.GetPointer()); + + std::unique_ptr pDir(new (std::nothrow) Directory); + TryReturn(pDir, false, "[osp-installer] pDir is null."); + + r = pDir->Construct(srcFilePath); + TryReturn(!IsFailed(r), false, "[osp-installer] pDir->Construct() failed, srcFilePath=[%ls].", srcFilePath.GetPointer()); + + std::unique_ptr pDirEnum(pDir->ReadN()); + TryReturn(pDirEnum, false, "[osp-installer] pDirEnum is null."); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String srcEntryDir = srcFilePath; + srcEntryDir += L"/"; + srcEntryDir += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + + // if file or directory is symbolic link, skip this. + if (InstallerUtil::IsSymlink(srcEntryDir) == true) + { + continue; + } + + String destEntryDir = destFilePath; + destEntryDir += L"/"; + destEntryDir += entryName; + + if (entry.IsDirectory() == false) + { + // file + Directory::Create(destFilePath, true); + InstallerUtil::Copy(srcEntryDir, destEntryDir); + } + else + { + Directory::Create(destEntryDir, true); + CopyDirectory(srcEntryDir, destEntryDir); + } + } + + return true; +} + +bool +InstallerUtil::IsSymlink(const Tizen::Base::String& filePath) +{ + int err = -1; + struct stat fileinfo; + + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + err = lstat(pFilePath.get(), &fileinfo); + TryReturn(err >= 0, false, "[osp-installer] lstat() failed(%s), filepath=[%s]", strerror(errno), pFilePath.get()); + + if (S_ISLNK(fileinfo.st_mode)) + { + return true; + } + + return false; +} + +bool +InstallerUtil::GetRealPath(const String& filePath, String& realPath) +{ + char* pRealPath = null; + + AppLogTag(OSP_INSTALLER, "+ GetRealPath(): path=[%ls], realPath=[%ls]", filePath.GetPointer(), realPath.GetPointer()); + + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + char tmpPath[PATH_MAX] = {0}; + pRealPath = realpath(pFilePath.get(), tmpPath); + TryReturn(pRealPath, false, "[osp-installer] pRealPath is null"); + + realPath = tmpPath; + + return true; +} + +bool +InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath) +{ + int err = -1; + bool res = false; + + AppLogTag(OSP_INSTALLER, "+ CreateSymlink(): oldPath=[%ls], newPath=[%ls]", oldPath.GetPointer(), newPath.GetPointer()); + + res = File::IsFileExist(oldPath); + TryReturn(res == true, false, "[osp-installer] file not found, oldPath=[%ls]", oldPath.GetPointer()); + + std::unique_ptr pOldPath(_StringConverter::CopyToCharArrayN(oldPath)); + TryReturn(pOldPath, false, "[osp-installer] pOldPath is null"); + + std::unique_ptr pNewPath(_StringConverter::CopyToCharArrayN(newPath)); + TryReturn(pNewPath, false, "[osp-installer] pNewPath is null"); + + err = symlink(pOldPath.get(), pNewPath.get()); + TryReturn(err == 0, false, "[osp-installer] symlink() is failed(%s), oldpath=[%s], newpath=[%s]", strerror(errno), pOldPath.get(), pNewPath.get()); + + AppLogTag(OSP_INSTALLER, "CreateSymlink(): [%ls] -> [%ls]", newPath.GetPointer(), oldPath.GetPointer()); + + return true; +} + +bool +InstallerUtil::ChangeMode(const String& filePath, int mode) +{ + int err = -1; + + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + err = chmod(pFilePath.get(), mode); + TryReturn(err == 0, false, "[osp-installer] chmod() is failed(%s), filepath=[%s], mode=[%o]", strerror(errno), pFilePath.get(), mode); + + return true; +} + +bool +InstallerUtil::ChangeOwner(const String& filePath) +{ + int err = -1; + + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + err = chown(pFilePath.get(), APP_OWNER_ID, APP_GROUP_ID); + TryReturn(err == 0, false, "[osp-installer] chown() is failed(%s), filepath=[%s]", strerror(errno), pFilePath.get()); + + return true; +} + +bool +InstallerUtil::ChangeDirectoryPermission(const String& filePath, int mode, bool appOwner) +{ + result r = E_SUCCESS; + bool res = false; + + AppLogTag(OSP_INSTALLER, "+ ChangeDirectoryPermission(): path=[%ls], mode=[%04o], appOwner=[%s]", + filePath.GetPointer(), mode, appOwner?"true":"false"); + + res = File::IsFileExist(filePath); + if (res == false) + { + AppLogTag(OSP_INSTALLER, "ChangeDirectoryPermission(): path=[%ls]: skip", filePath.GetPointer()); + return true; + } + + std::unique_ptr pDir(new (std::nothrow) Directory); + TryReturn(pDir, false, "[osp-installer] pDir is null."); + + r = pDir->Construct(filePath); + TryReturn(!IsFailed(r), false, "[osp-installer] pDir->Construct() failed, filePath=[%ls]", filePath.GetPointer()); + + std::unique_ptr pDirEnum(pDir->ReadN()); + TryReturn(pDirEnum, false, "[osp-installer] pDirEnum is null."); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String entryDir = filePath; + entryDir += L"/"; + entryDir += entryName; + + if (entryName == L".") + { + if (appOwner == true) + { + InstallerUtil::ChangeOwner(entryDir); + } + InstallerUtil::ChangeMode(entryDir, mode | PERM_EXECUTE); + continue; + } + else if (entryName == L"..") + { + continue; + } + + if (entry.IsDirectory() == false) + { + if (appOwner == true) + { + InstallerUtil::ChangeOwner(entryDir); + } + InstallerUtil::ChangeMode(entryDir, mode); + } + else + { + ChangeDirectoryPermission(entryDir, mode, appOwner); + if (appOwner == true) + { + InstallerUtil::ChangeOwner(entryDir); + } + InstallerUtil::ChangeMode(entryDir, mode | PERM_EXECUTE); + } + } + + return true; +} + +bool +InstallerUtil::IsDrmFile(const Tizen::Base::String& path) +{ + bool res = true; + char* pFilePath = null; + result r = E_SUCCESS; + int isDrm = 0; + + pFilePath = _StringConverter::CopyToCharArrayN(path); + TryCatch(pFilePath, r = GetLastResult(), "[osp-installer] pFilePath is null"); + + isDrm = drm_oem_intel_isDrmFile(pFilePath); + if(isDrm == 1) + { + AppLogTag(OSP_INSTALLER, "IsDrmFile() called, packagePath=%ls is drm file", path.GetPointer()); + } + else + { + res = false; + AppLogTag(OSP_INSTALLER, "IsDrmFile() called, packagePath=%ls isn't drm file", path.GetPointer()); + } + + CATCH: + delete [] pFilePath; + return res; +} + +bool +InstallerUtil::DecryptPackage(const Tizen::Base::String& packagePath) +{ + bool res = true; + char* pFilePath = null; + result r = E_SUCCESS; + int result = 0; + + pFilePath = _StringConverter::CopyToCharArrayN(packagePath); + TryCatch(pFilePath, r = GetLastResult(), "[osp-installer] pFilePath is null"); + + result = drm_oem_intel_decrypt_package(pFilePath, pFilePath); + if(result == 1) + { + AppLogTag(OSP_INSTALLER, "DecryptPackage() called, packagePath=%ls, decrpyt success", packagePath.GetPointer()); + } + else + { + AppLogTag(OSP_INSTALLER, "DecryptPackage() called, packagePath=%ls, decrypt failed", packagePath.GetPointer()); + res = false; + } + +CATCH: + delete [] pFilePath; + return res; +} + +String +InstallerUtil::GetCategory(int categoryType) +{ + String category; + + if (categoryType == CATEGORY_TYPE_IME) + { + category = L"Ime"; + } + else if (categoryType == CATEGORY_TYPE_HOME_SCREEN) + { + category = L"home-screen"; + } + else if (categoryType == CATEGORY_TYPE_LOCK_SCREEN) + { + category = L"lock-screen"; + } + + return category; +} + +CategoryType +InstallerUtil::GetCategoryType(char* pCategory) +{ + CategoryType category = CATEGORY_TYPE_NONE; + + if (strcasecmp(pCategory, "Ime") == 0) + { + category = CATEGORY_TYPE_IME; + } + else if (strcasecmp(pCategory, "home-screen") == 0) + { + category = CATEGORY_TYPE_HOME_SCREEN; + } + else if (strcasecmp(pCategory, "lock-screen") == 0) + { + category = CATEGORY_TYPE_LOCK_SCREEN; + } + + return category; +} + +bool +InstallerUtil::CreateSymlinkForAppDirectory(const String& inPath, String& outPath) +{ + String appId; + + AppLogTag(OSP_INSTALLER, "+ CreateSymlinkForAppDirectory(): path=[%ls]", inPath.GetPointer()); + + int length = inPath.GetLength(); + inPath.SubString(length - APPID_LENGTH, APPID_LENGTH, appId); + + String newPath; + newPath = PATH_OPT_APPS; + newPath += L"/"; + newPath += appId; + + if (inPath != newPath) + { + InstallerUtil::CreateSymlink(inPath, newPath); + } + + outPath = newPath; + AppLogTag(OSP_INSTALLER, "CreateSymlinkForAppDirectory(): output path=[%ls]", outPath.GetPointer()); + + return true; +} + +bool +InstallerUtil::DumpLog(const char* pBuf) +{ + char temp[4096] = {0}; + TryReturn(pBuf, false, "[osp-installer] pBuf is null"); + + int bufLen = strlen(pBuf); + strncpy(temp, pBuf, sizeof(temp)); + + char *pStart = &temp[0]; + + for (int i = 0; i < bufLen; i++) + { + if (temp[i] == '\n') + { + temp[i] = 0; + AppLogTag(OSP_INSTALLER, "%s", pStart); + pStart = temp + i + 1; + } + } + + return true; +} + +#define LOG_PRINT_LINE_MAX 20 +#define LOG_BUFFER_COUNT_MAX 4096 +bool +InstallerUtil::DumpLogData(char *pData, int dataLen) +{ + const char *szData = (const char*)pData; + char ch = 0; + int i = 0, j = 0, idx = 0, idx2 = 0, high = 0, low = 0, temp = 0; + + char buf[LOG_PRINT_LINE_MAX + 2] = {0}; + char buf2[(LOG_PRINT_LINE_MAX + 2) * 3] = {0}; + char buf_out[sizeof(buf) + sizeof(buf2) + 1] = {0}; + + + if (dataLen > LOG_BUFFER_COUNT_MAX) + { + dataLen = LOG_BUFFER_COUNT_MAX; + } + + // 16 characters by 20 line are proper. // too many logs decrease performance. +// if (dataLen > 16*20) +// dataLen = 16*20; + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + while (i < (int)dataLen) + { + ch = szData[i]; + + /* make ascii table */ + if (ch >= 32 && ch <= 128) + { + buf[idx++] = ch; + } + else + buf[idx++] = '.'; + + // make binary table + high = (ch & 0xf0)>>4; + low = ch & 0x0f; + + buf2[idx2++] = LogChangeHexToStr(high); + buf2[idx2++] = LogChangeHexToStr(low); + buf2[idx2++] = ' '; + + if (idx >= LOG_PRINT_LINE_MAX) + { + memcpy(buf_out, buf2, idx2); + + buf_out[idx2++] = ' '; + buf_out[idx2++] = ' '; + + memcpy(buf_out + idx2, buf, idx); + buf_out[idx2+idx] = '\0'; + + idx = 0; + idx2 = 0; + + AppLogTag(OSP_INSTALLER, "%s\n", buf_out); + } + + i++; + } + + // last line + if (idx > 0) + { + memcpy(buf_out, buf2, idx2); + temp = idx2; + + for (j = 0; j < (LOG_PRINT_LINE_MAX * 3) - temp; j++) + { + buf_out[idx2++] = ' '; + } + + buf_out[idx2++] = ' '; + buf_out[idx2++] = ' '; + + memcpy(buf_out+idx2, buf, idx); + buf_out[idx2+idx] = '\0'; + + AppLogTag(OSP_INSTALLER, "%s\n", buf_out); + } + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + return TRUE; +} + +char +InstallerUtil::LogChangeHexToStr(int hex) +{ + char ch = '0'; + + const static char hexValues[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 0}; + + + if (hex >= 0 && hex <= 0x0F) + { + ch = hexValues[hex]; + } + else + { + AppLogTag(OSP_INSTALLER, "LogChangeHexToStr: Error! [Hex Val: %d]\n", hex); + } + + return ch; +} + + diff --git a/src/Util/InstallerUtil.h b/src/Util/InstallerUtil.h new file mode 100755 index 0000000..4fac08a --- /dev/null +++ b/src/Util/InstallerUtil.h @@ -0,0 +1,76 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallerUtil.h + * @brief This is the header file for the %InstallerUtil class. + * + * This header file contains the declarations of the %InstallerUtil class. + */ +#ifndef _INSTALLER_UTIL_H_ +#define _INSTALLER_UTIL_H_ + +namespace Tizen { namespace Base +{ +class String; +}} + +/** + * @class InstallerUtil + * @brief This class represents the class of InstallerUtil. + * @since 1.0 + * + * This class represents the class of InstallerUtil. + * + */ +class InstallerUtil +{ +public: + InstallerUtil(void); + virtual ~InstallerUtil(void); + + static bool Remove(const Tizen::Base::String& filePath); + static bool Copy(const Tizen::Base::String& srcFilePath, const Tizen::Base::String& destFilePath); + static bool CopyDirectory(const Tizen::Base::String& srcFilePath, const Tizen::Base::String& destFilePath); + static bool IsSymlink(const Tizen::Base::String& filePath); + static bool GetRealPath(const Tizen::Base::String& filePath, Tizen::Base::String& realPath); + + static bool CreateSymlink(const Tizen::Base::String& oldPath, const Tizen::Base::String& newPath); + static bool ChangeMode(const Tizen::Base::String& filePath, int mode); + static bool ChangeOwner(const Tizen::Base::String& filePath); + static bool ChangeDirectoryPermission(const Tizen::Base::String& filePath, int mode, bool appOwner); + + static bool IsDrmFile(const Tizen::Base::String& path); + static bool DecryptPackage(const Tizen::Base::String& packagePath); + + static Tizen::Base::String GetCategory(int categoryType); + static CategoryType GetCategoryType(char* pCategory); + + static bool CreateSymlinkForAppDirectory(const Tizen::Base::String& inPath, Tizen::Base::String& outPath); + + static bool DumpLog(const char* pBuf); + static bool DumpLogData(char *pData, int dataLen); + +private: + static char LogChangeHexToStr(int hex); + InstallerUtil(const InstallerUtil& value); + InstallerUtil& operator =(const InstallerUtil& source); + +private: + +}; // InstallerUtil + +#endif // _INSTALLER_UTIL_H_ diff --git a/src/XmlHandler/ManifestGenerator.cpp b/src/XmlHandler/ManifestGenerator.cpp new file mode 100755 index 0000000..1213492 --- /dev/null +++ b/src/XmlHandler/ManifestGenerator.cpp @@ -0,0 +1,857 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestGenerator.cpp + * @brief This is the implementation file for %ManifestGenerator class. + */ + +#include + +#include +#include +#include +#include + +#include "ManifestGenerator.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::App; +using namespace Tizen::App::Package; +using namespace Tizen::Locales; +using namespace Tizen::Io; + +ManifestGenerator::ManifestGenerator(void) +:__pContext(null) +,__pPackageInfoImpl(null) +,__pWriter(null) +{ +} + +ManifestGenerator::~ManifestGenerator(void) +{ + delete __pWriter; + __pWriter = null; +} + +bool +ManifestGenerator::Construct(InstallationContext* pContext) +{ + __pContext = pContext; + __pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryReturn(__pPackageInfoImpl, false, "[osp-installer] __pPackageInfoImpl is null."); + + __pWriter = new (std::nothrow) XmlWriter; + TryReturn(__pWriter, false, "[osp-installer] __pWriter is null."); + + return true; +} + +bool +ManifestGenerator::Write() +{ + //bool preload = false; //__pContext->IsPreloaded(); + String xmlPath; + String package; + String location; + + //if (preload == true) + //{ + // xmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, __pContext->GetId().GetPointer()); + // location = L"internal-only"; + //} + //else + //{ + xmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, __pContext->GetId().GetPointer()); + location = L"auto"; + //} + + package = __pContext->GetId(); + + __pWriter->Construct(xmlPath); + + __pWriter->StartElement("manifest"); + __pWriter->WriteAttribute("xmlns", "http://tizen.org/ns/packages"); + __pWriter->WriteAttribute("package", package); + __pWriter->WriteAttribute("type", "tpk"); + __pWriter->WriteAttribute("version", __pPackageInfoImpl->GetVersion()); + __pWriter->WriteAttribute("install-location", location); + + __pWriter->StartElement("label"); + __pWriter->WriteString(__pPackageInfoImpl->GetDisplayName()); + __pWriter->EndElement(); + + __pWriter->StartElement("author"); + __pWriter->EndElement(); + + __pWriter->StartElement("description"); + __pWriter->WriteString(__pPackageInfoImpl->GetDescription()); + __pWriter->EndElement(); + + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + pAppList = __pPackageInfoImpl->GetAppInfoList(); + int appCount = pAppList->GetCount(); + AppLogTag(OSP_INSTALLER, "Write(): appCount=%d", appCount); + + for (int i = 0 ; i < appCount; i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + WriteApp(i, pAppInfoImpl); + } + } + + if (__pContext->__isSubMode == true) + { + AppLogTag(OSP_INSTALLER, "Write(): __pContext->__isSubMode is detected"); + WriteSubModeApp(appCount); + } + + __pWriter->EndElement(); + + return true; +} + +bool +ManifestGenerator::FindFeatureValue(ArrayList* pFeatureList, const String& feature, const String& value) const +{ + TryReturn(pFeatureList, false, "[osp-installer] pFeatureList is null."); + + _AppFeatureInfoImpl* pFeature = null; + + for (int i = 0 ; i < pFeatureList->GetCount(); i++) + { + pFeature = dynamic_cast<_AppFeatureInfoImpl*>(pFeatureList->GetAt(i)); + if (pFeature) + { + if ((pFeature->GetName() == feature) && (pFeature->GetValue() == value)) + { + AppLogTag(OSP_INSTALLER, "Find - feature=[%ls], value=[%ls]", feature.GetPointer(), value.GetPointer()); + return true; + } + } + } + + return false; +} + +String +ManifestGenerator::GetGlFrameValue(ArrayList* pFeatureList) const +{ + if (pFeatureList == null) + { + return "use-system-setting"; + } + + _AppFeatureInfoImpl* pFeature = null; + for (int i = 0 ; i < pFeatureList->GetCount(); i++) + { + pFeature = dynamic_cast<_AppFeatureInfoImpl*>(pFeatureList->GetAt(i)); + if (pFeature == null) + { + return "use-system-setting"; + } + + if (pFeature->GetName() == L"HwAcceleration" || pFeature->GetName() == L"GlFrame") + { + String value = pFeature->GetValue(); + if (value == L"On") + { + return "use-GL"; + } + else if (value == L"Off") + { + return "not-use-GL"; + } + } + } + + return "use-system-setting"; +} + +bool +ManifestGenerator::WriteLanguageValue(IMap* pList, const String& element) const +{ + TryReturn(pList, false, "[osp-installer] pNameList is null."); + + IMapEnumerator* pMapEnum = pList->GetMapEnumeratorN(); + while (pMapEnum->MoveNext() == E_SUCCESS) + { + String* pLanguage = null; + String* pValue = null; + String threeLetterCode; + String countryCode; + String launguage; + + pLanguage = static_cast (pMapEnum->GetKey()); + pValue = static_cast (pMapEnum->GetValue()); + + pLanguage->SubString(0, 3, threeLetterCode); + pLanguage->SubString(4, 2, countryCode); + + LanguageCode code = Locale::StringToLanguageCode(threeLetterCode); + String twoLetterLanguage = Locale::LanguageCodeToTwoLetterLanguageCodeString(code); + + launguage = twoLetterLanguage + L"-" + countryCode; + launguage.ToLowerCase(); + + if (((*pLanguage) == L"eng-GB") || ((*pLanguage) == L"eng-US")) + { + __pWriter->StartElement(element); + __pWriter->WriteString(*pValue); + __pWriter->EndElement(); + } + + __pWriter->StartElement(element); + __pWriter->WriteAttribute("xml:lang", launguage); + __pWriter->WriteString(*pValue); + __pWriter->EndElement(); + } + + delete pMapEnum; + return true; +} + +bool +ManifestGenerator::WriteLiveboxes(_PackageAppInfoImpl* pAppInfoImpl) const +{ + TryReturn(__pContext, false, "[osp-installer] __pContext is null."); + TryReturn(__pWriter, false, "[osp-installer] __pWriter is null."); + + ArrayList* pLiveboxDataList = __pContext->GetLiveboxDataList(); + String label("label"); + + if (pLiveboxDataList == null) + { + return true; + } + + for (int j = 0 ; j < pLiveboxDataList->GetCount(); j++) + { + LiveboxData* pLiveboxData = dynamic_cast(pLiveboxDataList->GetAt(j)); + if (pLiveboxData == null) + { + AppLogTag(OSP_INSTALLER, "pLiveboxData is null [%d]", j); + continue; + } + + long long updatePeriod = pLiveboxData->GetUpdatePeriod(); + String period = LongLong::ToString(updatePeriod/1000); + IMap* pLiveboxNameList = pLiveboxData->GetNameList(); + ArrayList* pSizeList = pLiveboxData->GetSizeList(); + String popupEnabled = pLiveboxData->GetPopupEnabled(); + String primary = pLiveboxData->__main; + + __pWriter->StartElement("livebox"); + + __pWriter->WriteAttribute("appid", pAppInfoImpl->GetPackageName() + "." + pLiveboxData->GetProviderName()); + __pWriter->WriteAttribute("period", period); + __pWriter->WriteAttribute("pinup", "false"); + + if (primary.IsEmpty() == false) + { + primary.ToLowerCase(); + __pWriter->WriteAttribute("primary", primary); + } + + __pWriter->WriteAttribute("auto_launch", "false"); + __pWriter->WriteAttribute("abi", "osp"); + + WriteLanguageValue(pLiveboxNameList, label); + + String menuIcon = pAppInfoImpl->GetMainmenuIcon(); + if (menuIcon.IsEmpty() == false) + { + String menuIconPath; + menuIconPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, menuIcon.GetPointer()); + + __pWriter->StartElement("icon"); + __pWriter->WriteString(menuIconPath); + __pWriter->EndElement(); + } + + if (pSizeList) + { + __pWriter->StartElement("box"); + __pWriter->WriteAttribute("type", "buffer"); + + for (int k = 0 ; k < pSizeList->GetCount(); k++) + { + String* pSize = dynamic_cast(pSizeList->GetAt(k)); + if (pSize == null) + { + AppLogTag(OSP_INSTALLER, "pSize is null [%d]", k); + continue; + } + + __pWriter->StartElement("size"); + __pWriter->WriteString(*pSize); + __pWriter->EndElement(); + } + __pWriter->EndElement(); + } + + if (pLiveboxData->__configurationAppControlAppId.IsEmpty() == false) + { + __pWriter->StartElement("setup"); + __pWriter->WriteString(pLiveboxData->__configurationAppControlAppId); + __pWriter->EndElement(); + } + + popupEnabled.ToLowerCase(); + if (popupEnabled == L"true") + { + __pWriter->StartElement("pd"); + __pWriter->WriteAttribute("type", "buffer"); + + __pWriter->StartElement("size"); + __pWriter->WriteString("720x250"); + __pWriter->EndElement(); + + __pWriter->EndElement(); + } + __pWriter->EndElement(); + } + + return true; +} + +bool +ManifestGenerator::WriteAppControl(_PackageAppInfoImpl* pAppInfoImpl) const +{ + TryReturn(pAppInfoImpl, false, "[osp-installer] pAppInfoImpl is null."); + + ArrayList* pAppControlImplList = pAppInfoImpl->GetAppControlList(); + TryReturn(pAppControlImplList, false, "[osp-installer] pAppControlImplList is null."); + + _AppControlInfoImpl* pAppControl = dynamic_cast<_AppControlInfoImpl*>(pAppControlImplList->GetAt(0)); + TryReturn(pAppControl, false, "[osp-installer] pAppControl is null."); + + ArrayList* pCapabilityList = pAppControl->GetCapabilityList(); + TryReturn(pCapabilityList, false, "[osp-installer] pCapabilityList is null."); + + int capaCount = pCapabilityList->GetCount(); + for (int capaIndex = 0 ; capaIndex < capaCount; capaIndex++) + { + _AppControlCapabilityInfoImpl* pCapability = dynamic_cast<_AppControlCapabilityInfoImpl*>(pCapabilityList->GetAt(capaIndex)); + if (pCapability == null) continue; + + String operationId = pCapability->GetOperationId(); + + ArrayList* pResolutionList = pCapability->GetResolutionList(); + int resCount = pResolutionList->GetCount(); + + if (resCount == 0) + { + __pWriter->StartElement("application-service"); + __pWriter->StartElement("operation"); + __pWriter->WriteAttribute("name", operationId); + __pWriter->EndElement(); + __pWriter->EndElement(); + continue; + } + + for (int resIndex = 0 ; resIndex < resCount; resIndex++) + { + __pWriter->StartElement("application-service"); + __pWriter->StartElement("operation"); + __pWriter->WriteAttribute("name", operationId); + __pWriter->EndElement(); + + _AppControlResolutionInfoImpl* pResolution = dynamic_cast <_AppControlResolutionInfoImpl*>(pResolutionList->GetAt(resIndex)); + if (pResolution == null) continue; + + String* pUriScheme = pResolution->GetUriScheme(); + if (pUriScheme && pUriScheme->IsEmpty() == false) + { + __pWriter->StartElement("uri"); + __pWriter->WriteAttribute("name", *pUriScheme); + __pWriter->EndElement(); + } + + String* pMimeType = pResolution->GetMimeType(); + if (pMimeType && pMimeType->IsEmpty() == false) + { + __pWriter->StartElement("mime"); + __pWriter->WriteAttribute("name", *pMimeType); + __pWriter->EndElement(); + } + + __pWriter->EndElement(); + } + } + + return true; +} + +bool +ManifestGenerator::WriteCategory(int index) const +{ + IListT* pAppDataList = __pContext->__pAppDataList; + TryReturn(pAppDataList, true, "[osp-installer] pAppDataList is null"); + + AppData* pAppData = null; + pAppDataList->GetAt(index, pAppData); + TryReturn(pAppData, true, "[osp-installer] pAppData is null"); + + IListT* pCategoryList = pAppData->__pCategoryList; + TryReturn(pCategoryList, true, "[osp-installer] pCategoryList is null"); + + for (int i = 0; i < pCategoryList->GetCount(); i++) + { + String *pStr = null; + pCategoryList->GetAt(i, pStr); + TryReturn(pStr, false, "[osp-installer] pStr is null"); + + AppLogTag(OSP_INSTALLER, "WriteCategory(): Category String=[%ls]", pStr->GetPointer()); + + __pWriter->StartElement("category"); + __pWriter->WriteAttribute("name", *pStr); + __pWriter->EndElement(); + } + + return true; +} + +bool +ManifestGenerator::FindCategory(int index, const String& category) const +{ + result r = E_SUCCESS; + + IListT* pAppDataList = __pContext->__pAppDataList; + TryReturn(pAppDataList, false, "[osp-installer] pAppDataList is null"); + + AppData* pAppData = null; + r = pAppDataList->GetAt(index, pAppData); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + IListT* pCategoryList = pAppData->__pCategoryList; + TryReturn(pCategoryList, false, "[osp-installer] pCategoryList is null"); + + for (int i = 0; i < pCategoryList->GetCount(); i++) + { + String *pStr = null; + pCategoryList->GetAt(i, pStr); + TryReturn(pStr, false, "[osp-installer] pStr is null"); + + if (*pStr == category) + { + AppLogTag(OSP_INSTALLER, "FindCategory(): Category is found=[%ls]", pStr->GetPointer()); + return true; + } + + } + + return false; +} + +bool +ManifestGenerator::WriteApp(int index, Tizen::App::Package::_PackageAppInfoImpl* pAppInfoImpl) +{ + IMap* pNameList = pAppInfoImpl->GetNameList(); + String label("label"); + String type("c++app"); + String binaryPath; + binaryPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_BIN, pAppInfoImpl->GetName().GetPointer()); + + if (pAppInfoImpl->GetDefault() == L"True") + { + WriteLanguageValue(pNameList, label); + + if (pAppInfoImpl->GetMainmenuIcon().IsEmpty() == false) + { + String iconPath; + iconPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, pAppInfoImpl->GetMainmenuIcon().GetPointer()); + + __pWriter->StartElement("icon"); + __pWriter->WriteString(iconPath); + __pWriter->EndElement(); + } + } + + String nodisplay("true"); + String taskmanage("false"); + String category; + String mainapp("true"); + + if (pAppInfoImpl->GetType() == L"UiApp") + { + taskmanage = L"true"; + + if (pAppInfoImpl->IsMainmenuVisible() == true) + { + nodisplay = L"false"; + taskmanage = L"true"; + } + else + { + nodisplay = L"true"; + taskmanage = L"false"; + } + + const char* pCategory = null; + pCategory = TIZEN_CATEGORY_IME; + if (FindCategory(index, pCategory) == true) + { + AppLogTag(OSP_INSTALLER, "Write(): [%s] is detected. taskmanage=false, nodisplay=true", pCategory); + taskmanage = L"false"; + nodisplay = L"true"; + } + + pCategory = TIZEN_CATEGORY_HOMESCREEN; + if (FindCategory(index, pCategory) == true) + { + AppLogTag(OSP_INSTALLER, "Write(): [%s] is detected. taskmanage=false", pCategory); + taskmanage = L"false"; + } + + pCategory = TIZEN_CATEGORY_LOCKSCREEN; + if (FindCategory(index, pCategory) == true) + { + AppLogTag(OSP_INSTALLER, "Write(): [%s] is detected. taskmanage=false", pCategory); + taskmanage = L"false"; + } + + pCategory = TIZEN_CATEGORY_MENUSCREEN; + if (FindCategory(index, pCategory) == true) + { + AppLogTag(OSP_INSTALLER, "Write(): [%s] is detected. taskmanage=false", pCategory); + taskmanage = L"false"; + } + } + + if (pAppInfoImpl->GetDefault() != L"True") + { + mainapp = L"false"; + } + + ArrayList* pFeatureList = pAppInfoImpl->GetAppFeatureList(); + String glFrame = GetGlFrameValue(pFeatureList); + + __pWriter->StartElement("ui-application"); + __pWriter->WriteAttribute("appid", pAppInfoImpl->GetPackageName()); + __pWriter->WriteAttribute("exec", binaryPath); + __pWriter->WriteAttribute("nodisplay", nodisplay); + __pWriter->WriteAttribute("taskmanage", taskmanage); + __pWriter->WriteAttribute("multiple", "false"); + __pWriter->WriteAttribute("type", type); + __pWriter->WriteAttribute("hw-acceleration", glFrame); + __pWriter->WriteAttribute("mainapp", mainapp); + + WriteCategory(index); + +#if 0 + if (pAppInfoImpl->GetType() == L"UiApp") + { + String nodisplay; + + if (pAppInfoImpl->IsMainmenuVisible() == true) + { + nodisplay = "false"; + } + else + { + nodisplay = "true"; + } + + __pWriter->StartElement("ui-application"); + __pWriter->WriteAttribute("appid", pAppInfoImpl->GetPackageName()); + __pWriter->WriteAttribute("exec", binaryPath); + __pWriter->WriteAttribute("nodisplay", nodisplay); + __pWriter->WriteAttribute("taskmanage", "true"); + __pWriter->WriteAttribute("multiple", "false"); + __pWriter->WriteAttribute("type", type); + } + else if (pAppInfoImpl->GetType() == L"ServiceApp") + { + ArrayList* pFeatureList = pAppInfoImpl->GetAppFeatureList(); + String onBoot("false"); + String autoRestart("false"); + + if (FindFeatureValue(pFeatureList, "LaunchOnBoot", "True") == true) + { + onBoot = L"true"; + } + + if (FindFeatureValue(pFeatureList, "AutoRestart", "True") == true) + { + autoRestart = L"true"; + } + + __pWriter->StartElement("service-application"); + __pWriter->WriteAttribute("appid", pAppInfoImpl->GetPackageName()); + __pWriter->WriteAttribute("exec", binaryPath); + __pWriter->WriteAttribute("type", type); + __pWriter->WriteAttribute("on-boot", onBoot); + __pWriter->WriteAttribute("auto-restart", autoRestart); + } + else + { + AppLogTag(OSP_INSTALLER, "Type is invalid! [%ls]", pAppInfoImpl->GetType().GetPointer()); + return false; + } + #endif + + WriteLanguageValue(pNameList, label); + + if (pAppInfoImpl->GetMainmenuIcon().IsEmpty() == false) + { + String iconPath; + iconPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, pAppInfoImpl->GetMainmenuIcon().GetPointer()); + + __pWriter->StartElement("icon"); + __pWriter->WriteString(iconPath); + __pWriter->EndElement(); + } + + IListT* pAppDataList = __pContext->__pAppDataList; + TryReturn(pAppDataList, false, "[osp-installer] pAppDataList is null"); + + AppData* pAppData = null; + pAppDataList->GetAt(index, pAppData); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + if (pAppData->__legacyAppControls == true) + { + AppLogTag(OSP_INSTALLER, "Write(): AppControls spec is legacy"); + WriteAppControl(pAppInfoImpl); + } + else + { + WriteAppControl(index); + } + + __pWriter->EndElement(); + + if (pAppInfoImpl->GetType() == L"ServiceApp") + { + WriteLiveboxes(pAppInfoImpl); + } + + WriteAccounts(index); + + return true; +} + +bool +ManifestGenerator::WriteSubModeApp(int index) +{ + // SUB_MODE_APPCONTROL_NAME -> AppName + String subBinaryPath; + subBinaryPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_BIN, SUB_MODE_APPCONTROL_NAME); + + String binaryPath; + binaryPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_BIN, __pContext->__subModeAppName.GetPointer()); + + if (File::IsFileExist(subBinaryPath) == true) + { + InstallerUtil::Remove(subBinaryPath); + } + InstallerUtil::CreateSymlink(binaryPath, subBinaryPath); + + // SUB_MODE_APPCONTROL_NAME.exe -> AppName.exe + String subBinaryExecPath = subBinaryPath + ".exe"; + String binaryExecPath = binaryPath + ".exe"; + + if (File::IsFileExist(subBinaryExecPath) == true) + { + InstallerUtil::Remove(subBinaryExecPath); + } + InstallerUtil::CreateSymlink(binaryExecPath, subBinaryExecPath); + + IListT* pAppDataList = __pContext->__pAppDataList; + TryReturn(pAppDataList, false, "[osp-installer] pAppDataList is null"); + + AppLogTag(OSP_INSTALLER, "WriteSubModeApp(): appCount=%d", pAppDataList->GetCount()); + + AppData* pAppData = null; + pAppDataList->GetAt(index, pAppData); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + PackageId packageId = __pContext->GetId(); + AppId appId = packageId + L"." + SUB_MODE_APPCONTROL_NAME; + + __pWriter->StartElement("ui-application"); + __pWriter->WriteAttribute("appid", appId); + __pWriter->WriteAttribute("exec", subBinaryPath); + __pWriter->WriteAttribute("nodisplay", "true"); + __pWriter->WriteAttribute("taskmanage", "false"); + __pWriter->WriteAttribute("multiple", "true"); + __pWriter->WriteAttribute("type", "c++app"); + + __pWriter->StartElement("label"); + __pWriter->WriteString(__pPackageInfoImpl->GetDisplayName()); + __pWriter->EndElement(); + + ArrayList* pAppList = __pPackageInfoImpl->GetAppInfoList(); + _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(0)); + if (pAppInfoImpl) + { + if (pAppInfoImpl->GetMainmenuIcon().IsEmpty() == false) + { + String iconPath; + iconPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, pAppInfoImpl->GetMainmenuIcon().GetPointer()); + + __pWriter->StartElement("icon"); + __pWriter->WriteString(iconPath); + __pWriter->EndElement(); + } + } + + WriteAppControl(index); + + __pWriter->EndElement(); // end of "ui-application" + + return true; +} + +bool +ManifestGenerator::WriteAppControl(int index) +{ + IListT* pAppDataList = __pContext->__pAppDataList; + TryReturn(pAppDataList, false, "[osp-installer] pAppDataList is null"); + + AppData* pAppData = null; + pAppDataList->GetAt(index, pAppData); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + IListT* pAppControlDataList = pAppData->__pAppControlDataList; + TryReturn(pAppControlDataList, false, "[osp-installer] pAppControlDataList is null"); + + for (int i = 0; i < pAppControlDataList->GetCount(); i++) + { + __pWriter->StartElement("application-service"); + + AppControlData* pAppControlData = null; + pAppControlDataList->GetAt(i, pAppControlData); + TryReturn(pAppControlData, false, "[osp-installer] pAppControlData is null"); + + IListT* pOperationList = pAppControlData->__pOperationList; + TryReturn(pOperationList, false, "[osp-installer] pOperationList is null"); + for (int sub = 0; sub < pOperationList->GetCount(); sub++) + { + String* pOperation = null; + pOperationList->GetAt(sub, pOperation); + TryReturn(pOperation, false, "[osp-installer] pOperation is null"); + + __pWriter->StartElement("operation"); + __pWriter->WriteAttribute("name", *pOperation); + __pWriter->EndElement(); // end of "operation" + } + + IListT* pMimeTypeList = pAppControlData->__pMimeTypeList; + TryReturn(pMimeTypeList, false, "[osp-installer] pMimeTypeList is null"); + for (int sub = 0; sub < pMimeTypeList->GetCount(); sub++) + { + String* pMimeType = null; + pMimeTypeList->GetAt(sub, pMimeType); + TryReturn(pMimeType, false, "[osp-installer] pMimeType is null"); + + if (pMimeType->IsEmpty() == true) continue; + + __pWriter->StartElement("mime"); + __pWriter->WriteAttribute("name", *pMimeType); + __pWriter->EndElement(); // end of "mime" + } + + IListT* pUriList = pAppControlData->__pUriList; + TryReturn(pUriList, false, "[osp-installer] pUriList is null"); + for (int sub = 0; sub < pUriList->GetCount(); sub++) + { + String* pUri = null; + pUriList->GetAt(sub, pUri); + TryReturn(pUri, false, "[osp-installer] pUri is null"); + + if (pUri->IsEmpty() == true) continue; + + __pWriter->StartElement("uri"); + __pWriter->WriteAttribute("name", *pUri); + __pWriter->EndElement(); // end of "uri" + } + + __pWriter->EndElement(); // end of "application-service" + } + + return true; +} + +bool +ManifestGenerator::WriteAccounts(int index) +{ + IListT* pAppDataList = __pContext->__pAppDataList; + TryReturn(pAppDataList, false, "[osp-installer] pAppDataList is null"); + + AppData* pAppData = null; + pAppDataList->GetAt(index, pAppData); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + IListT* pAccountDataList = pAppData->__pAccountDataList; + TryReturn(pAccountDataList, false, "[osp-installer] pAccountDataList is null"); + + int accountCount = pAccountDataList->GetCount(); + if (accountCount == 0) + { + return true; + } + + __pWriter->StartElement("Accounts"); + + for (int i = 0; i < accountCount; i++) + { + __pWriter->StartElement("AccountProvider"); + + AccountData* pAccountData = null; + pAccountDataList->GetAt(i, pAccountData); + TryReturn(pAccountData, false, "[osp-installer] pAccountData is null"); + + __pWriter->WriteAttribute("ProviderId", pAccountData->__providerId); + __pWriter->WriteAttribute("MultipleAccountsSupport", pAccountData->__multipleAccountsSupport); + + String accountIcon = pAccountData->__accountIcon; + if (accountIcon.IsEmpty() == false) + { + String accountIconPath; + accountIconPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, accountIcon.GetPointer()); + + __pWriter->StartElement("account-icon"); + __pWriter->WriteString(accountIconPath); + __pWriter->EndElement(); + } + + String accountSmallIcon = pAccountData->__accountSmallIcon; + if (accountSmallIcon.IsEmpty() == false) + { + String accountSmallIconPath; + accountSmallIconPath.Format(1024, L"%ls%ls/%ls", __pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, accountSmallIcon.GetPointer()); + + __pWriter->StartElement("account-small-icon"); + __pWriter->WriteString(accountSmallIcon); + __pWriter->EndElement(); + } + + WriteLanguageValue(pAccountData->__pNameList, L"label"); + + __pWriter->EndElement(); // end of "AccountProvider" + } + + __pWriter->EndElement(); // end of "Accounts" + + return true; +} diff --git a/src/XmlHandler/ManifestGenerator.h b/src/XmlHandler/ManifestGenerator.h new file mode 100755 index 0000000..7429dfd --- /dev/null +++ b/src/XmlHandler/ManifestGenerator.h @@ -0,0 +1,74 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestGenerator.h + * @brief This is the header file for the %ManifestGenerator class. + * + * This header file contains the declarations of the %ManifestGenerator class. + */ +#ifndef _MANIFEST_GENERATOR_H_ +#define _MANIFEST_GENERATOR_H_ + +#include +#include + +#include "InstallationContext.h" +#include "XmlWriter.h" + +/** + * @class ManifestGenerator + * @brief This class represents the class of ManifestGenerator. + * @since 1.0 + * + * This class represents the class of ManifestGenerator. + * + */ +class ManifestGenerator +{ +public: + ManifestGenerator(void); + virtual ~ManifestGenerator(void); + + bool Construct(InstallationContext *pConext); + bool Write(void); + +private: + ManifestGenerator(const ManifestGenerator& value); + ManifestGenerator& operator =(const ManifestGenerator& source); + + bool FindFeatureValue(Tizen::Base::Collection::ArrayList* pFeatureList, const Tizen::Base::String& feature, const Tizen::Base::String& value) const; + bool WriteLanguageValue(Tizen::Base::Collection::IMap* pList, const Tizen::Base::String& label) const; + bool WriteLiveboxes(Tizen::App::Package::_PackageAppInfoImpl* pAppInfoImpl) const; + bool WriteAppControl(Tizen::App::Package::_PackageAppInfoImpl* pAppInfoImpl) const; + Tizen::Base::String GetGlFrameValue(Tizen::Base::Collection::ArrayList* pFeatureList) const; + + bool WriteCategory(int index) const; + bool FindCategory(int index, const Tizen::Base::String& category) const; + + bool WriteApp(int index, Tizen::App::Package::_PackageAppInfoImpl* pAppInfoImpl); + bool WriteSubModeApp(int index); + bool WriteAppControl(int index); + bool WriteAccounts(int index); + +private: + InstallationContext* __pContext; + Tizen::App::Package::_PackageInfoImpl* __pPackageInfoImpl; + XmlWriter* __pWriter; + +}; // ManifestGenerator + +#endif // _MANIFEST_GENERATOR_H_ diff --git a/src/XmlHandler/ManifestHandler.cpp b/src/XmlHandler/ManifestHandler.cpp new file mode 100755 index 0000000..a887f73 --- /dev/null +++ b/src/XmlHandler/ManifestHandler.cpp @@ -0,0 +1,1403 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestHandler.cpp + * @brief This is the implementation file for %ManifestHandler class. + */ + +#include +#include +#include +#include + +#include "ManifestHandler.h" +#include "PrivilegeHandler.h" +#include "InstallerUtil.h" +#include "ManifestLiveboxesParser.h" +#include "ManifestAccountsParser.h" +#include "ManifestAppControlsParser.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::App::Package; +using namespace Tizen::Io; +using namespace Tizen::System; + +ManifestHandler::ManifestHandler(void) +:__pContext(null) +,__pPrivilegeList(null) +,__pContentDataList(null) +,__pPackageInfoImpl(null) +,__pPackageAppInfoImpl(null) +,__pAppControlInfoImpl(null) +,__pAppControlCapabilityInfoImpl(null) +,__pAppControlResolutionInfoImpl(null) +,__pDataControlInfoImpl(null) +,__pDataControlTypeImpl(null) +,__pLaunchConditionImpl(null) +,__pNotificationImpl(null) +,__pContentData(null) +,__pDefaultIconType(null) +,__isDefaultMainmenu(false) +,__isDefaultSetting(false) +,__isDefaultTicker(false) +,__isDefaultQuickpanel(false) +,__isDefaultLaunchImage(false) +,__isDefaultName(false) +,__isDefaultAppDetected(false) +,__pAppData(null) +,__pSubModeAppControlDataList(null) +,__isParserMode(false) +{ +} + +ManifestHandler::~ManifestHandler(void) +{ + delete[] __pDefaultIconType; + __pDefaultIconType = null; + + if (__pPackageAppInfoImpl) + { + delete __pPackageAppInfoImpl; + __pPackageAppInfoImpl = null; + } +} + +bool +ManifestHandler::Construct(InstallationContext* pContext) +{ + __pContext = pContext; + __pPackageInfoImpl = pContext->GetPackageInfoImpl(); + + return true; +} + +InstallationContext* +ManifestHandler::GetContext(void) +{ + return __pContext; +} + +bool +ManifestHandler::Parse(const char *pFilepath) +{ + return ParseDocument(pFilepath); +} + +bool +ManifestHandler::OnStartElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null."); + + bool status = true; + + if (__isParserMode == true) + { + TryReturn(__pParser, false, "[osp-installer] __pParser is null"); + return __pParser->OnStartElement(pName); + } + + if (strcasecmp(pName, "Manifest") == 0) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "manifest.xml"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "<%s>", pName); + } + else if (strcasecmp(pName, "Apps") == 0) + { + AppLogTag(OSP_INSTALLER, "<%s>", pName); + } + else if (strcasecmp(pName, "UiApp") == 0) + { + status = OnUiAppStartElement(); + } + else if (strcasecmp(pName, "ServiceApp") == 0) + { + status = OnServiceAppStartElement(); + } + else if (strcasecmp(pName, "DataControl") == 0) + { + status = OnDataControlStartElement(); + } + else if (strcasecmp(pName, "Privileges") == 0) + { + status = OnPrivilegesStartElement(); + } + else if (strcasecmp(pName, "UiScalability") == 0) + { + status = OnUiScalabilityStartElement(); + } + else if (strcasecmp(pName, "UiTheme") == 0) + { + status = OnUiThemeStartElement(); + } + else if (strcasecmp(pName, "Icons") == 0) + { + status = OnIconsStartElement(); + } + else if (strcasecmp(pName, "Contents") == 0) + { + status = OnContentsStartElement(); + } + else if (strcasecmp(pName, "Content") == 0) + { + status = OnContentStartElement(); + } + else if (strcasecmp(pName, "Liveboxes") == 0) + { + status = OnLiveboxesStartElement(pName); + } + else if (strcasecmp(pName, "Accounts") == 0) + { + status = OnAccountsStartElement(pName); + } + else if (strcasecmp(pName, "AppControls") == 0) + { + status = OnAppControlsStartElement(pName); + } + + if (!status) + { + __isParserMode = false; + return false; + } + + return true; +} + +bool +ManifestHandler::OnEndElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null."); + + bool status = true; + + if (__isParserMode == true) + { + TryReturn(__pParser, false, "[osp-installer] __pParser is null"); + __pParser->OnEndElement(pName); + + if (strcasecmp(pName, "Liveboxes") == 0) + { + status = OnLiveboxesEndElement(); + } + else if (strcasecmp(pName, "Accounts") == 0) + { + status = OnAccountsEndElement(); + } + else if (strcasecmp(pName, "AppControls") == 0) + { + status = OnAppControlsEndElement(); + } + + return status; + } + + if (strcasecmp(pName, "Privileges") == 0) + { + status = OnPrivilegesEndElement(); + } + else if (strcasecmp(pName, "UiApp") == 0) + { + status = OnUiAppEndElement(); + } + else if (strcasecmp(pName, "ServiceApp") == 0) + { + status = OnServiceAppEndElement(); + } + else if (strcasecmp(pName, "DataControl") == 0) + { + status = OnDataControlEndElement(); + } + else if (strcasecmp(pName, "DataControlType") == 0) + { + status = OnDataControlTypeEndElement(); + } + else if (strcasecmp(pName, "Condition") == 0) + { + status = OnConditionEndElement(); + } + else if (strcasecmp(pName, "Notification") == 0) + { + status = OnNotificationEndElement(); + } + else if (strcasecmp(pName, "Apps") == 0) + { + status = OnAppsEndElement(); + } + else if (strcasecmp(pName, "UiScalability") == 0) + { + AppLogTag(OSP_INSTALLER, "", pName); + } + else if (strcasecmp(pName, "Icons") == 0) + { + status = OnIconsEndElement(); + } + else if (strcasecmp(pName, "Contents") == 0) + { + status = OnContentsEndElement(); + } + else if (strcasecmp(pName, "Content") == 0) + { + status = OnContentEndElement(); + } + else if (strcasecmp(pName, "Manifest") == 0) + { + status = OnManifestEndElement(); + } + + if (!status) + { + return false; + } + + return true; +} + +bool +ManifestHandler::OnCharacters(const char *pCharacters) +{ + bool status = true; + + if (__isParserMode == true) + { + TryReturn(__pParser, false, "[osp-installer] __pParser is null"); + return __pParser->OnCharacters(pCharacters); + } + + char *pName = GetElementName(); + TryReturn(pName, false, "[osp-installer] pName is null."); + + if (strcasecmp(pName, "Id") == 0) + { + status = OnIdValue(pCharacters); + } + else if (strcasecmp(pName, "Version") == 0) + { + status = OnVersionValue(pCharacters); + } + else if (strcasecmp(pName, "Type") == 0) + { + status = OnTypeValue(pCharacters); + } + else if (strcasecmp(pName, "Url") == 0) + { + status = OnUrlValue(pCharacters); + } + else if (strcasecmp(pName, "ApiVersion") == 0) + { + status = OnApiVersionValue(pCharacters); + } + else if (strcasecmp(pName, "Privilege") == 0) + { + status = OnPrivilegeValue(pCharacters); + } + else if (strcasecmp(pName, "Name") == 0) + { + status = OnNameValue(pCharacters); + } + else if (strcasecmp(pName, "DisplayName") == 0) + { + status = OnNameValue(pCharacters); + } + else if (strcasecmp(pName, "Author") == 0) + { + status = OnAuthorValue(pCharacters); + } + else if (strcasecmp(pName, "Description") == 0) + { + status = OnDescriptionValue(pCharacters); + } + else if (strcasecmp(pName, "Icon") == 0) + { + status = OnIconValue(pCharacters); + } + else if (strcasecmp(pName, "DataControlType") == 0) + { + status = OnDataControlTypeValue(pCharacters); + } + else if (strcasecmp(pName, "Condition") == 0) + { + status = OnConditionValue(pCharacters); + } + else if (strcasecmp(pName, "Notification") == 0) + { + status = OnNotificationValue(pCharacters); + } + else if (strcasecmp(pName, "InstallationLocation") == 0) + { + status = OnInstallationLocationValue(pCharacters); + } + else if (strcasecmp(pName, "Category") == 0) + { + status = OnCategoryValue(pCharacters); + } + + if (!status) + { + return false; + } + + return true; +} + +bool +ManifestHandler::OnPrivilegesStartElement(void) +{ + __pPrivilegeList = new (std::nothrow) ArrayList; + TryReturn(__pPrivilegeList, false, "[osp-installer] __pPrivilegeList is null"); + + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnUiAppStartElement(void) +{ + __pPackageAppInfoImpl = new (std::nothrow) _PackageAppInfoImpl; + TryReturn(__pPackageAppInfoImpl, false, "[osp-installer] __pPackageAppInfoImpl is null"); + + __pAppData = new (std::nothrow) AppData; + TryReturn(__pAppData, false, "[osp-installer] __pAppData is null"); + + AppLogTag(OSP_INSTALLER, ""); + + XmlAttribute *pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + ParseAppAttribute(pAttr, true); + + return true; +} + +bool +ManifestHandler::OnServiceAppStartElement(void) +{ + __pPackageAppInfoImpl = new (std::nothrow) _PackageAppInfoImpl; + TryReturn(__pPackageAppInfoImpl, false, "[osp-installer] __pPackageAppInfoImpl is null"); + + __pAppData = new (std::nothrow) AppData; + TryReturn(__pAppData, false, "[osp-installer] __pAppData is null"); + + AppLogTag(OSP_INSTALLER, ""); + + XmlAttribute *pAttr = GetAttribute(); + TryReturn(pAttr, true, "pAttr is null"); + + ParseAppAttribute(pAttr, false); + + return true; +} + +bool +ManifestHandler::OnIconsStartElement(void) +{ + result r = E_SUCCESS; + int width = 0; + String defaultIconType; + + AppLogTag(OSP_INSTALLER, ""); + + r = _SystemInfoImpl::GetSysInfo(L"ScreenWidth", width); + if (IsFailed(r)) + { + defaultIconType = L"Xhigh"; + } + else + { + if (width == 480) + { + defaultIconType = L"High"; + } + else + { + defaultIconType = L"Xhigh"; + } + } + + AppLogTag(OSP_INSTALLER, "ScreenWidth = [%d]", width); + + __pDefaultIconType = _StringConverter::CopyToCharArrayN(defaultIconType); + TryReturn(__pDefaultIconType, false, "[osp-installer] __pDefaultIconType is null."); + + AppLogTag(OSP_INSTALLER, "DefaultIconType = [%s]", __pDefaultIconType); + + return true; +} + +bool +ManifestHandler::OnUiScalabilityStartElement(void) +{ + XmlAttribute *pAttr = null; + char *pCoordinateSystem = null; + char *pBaseScreenSize = null; + char *pLogicalCoordinate = null; + + AppLogTag(OSP_INSTALLER, ""); + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pCoordinateSystem = pAttr->Find("CoordinateSystem"); + if (pCoordinateSystem) + { + _AppFeatureInfoImpl* pAppFeatureInfo = new (std::nothrow) _AppFeatureInfoImpl; + TryReturn(pAppFeatureInfo, false, "[osp-installer] pAppFeatureInfo is null"); + + pAppFeatureInfo->SetName("CoordinateSystem"); + pAppFeatureInfo->SetValue(pCoordinateSystem); + + __pPackageAppInfoImpl->AddAppFeature(*pAppFeatureInfo); + + AppLogTag(OSP_INSTALLER, "", pCoordinateSystem); + } + + pBaseScreenSize = pAttr->Find("BaseScreenSize"); + if (pBaseScreenSize) + { + _AppFeatureInfoImpl* pAppFeatureInfo = new (std::nothrow) _AppFeatureInfoImpl; + TryReturn(pAppFeatureInfo, false, "[osp-installer] pAppFeatureInfo is null"); + + pAppFeatureInfo->SetName("BaseScreenSize"); + pAppFeatureInfo->SetValue(pBaseScreenSize); + + __pPackageAppInfoImpl->AddAppFeature(*pAppFeatureInfo); + + AppLogTag(OSP_INSTALLER, "", pBaseScreenSize); + } + + pLogicalCoordinate = pAttr->Find("LogicalCoordinate"); + if (pLogicalCoordinate) + { + _AppFeatureInfoImpl* pAppFeatureInfo = new (std::nothrow) _AppFeatureInfoImpl; + TryReturn(pAppFeatureInfo, false, "[osp-installer] pAppFeatureInfo is null"); + + pAppFeatureInfo->SetName("LogicalCoordinate"); + pAppFeatureInfo->SetValue(pLogicalCoordinate); + + __pPackageAppInfoImpl->AddAppFeature(*pAppFeatureInfo); + + AppLogTag(OSP_INSTALLER, "", pLogicalCoordinate); + } + + return true; +} + +bool +ManifestHandler::OnUiThemeStartElement(void) +{ + XmlAttribute *pAttr = null; + char *pSystemTheme = null; + char *pUserDefinedTheme = null; + + AppLogTag(OSP_INSTALLER, ""); + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pSystemTheme = pAttr->Find("SystemTheme"); + if (pSystemTheme) + { + _AppFeatureInfoImpl* pAppFeatureInfo = new (std::nothrow) _AppFeatureInfoImpl; + TryReturn(pAppFeatureInfo, false, "[osp-installer] pAppFeatureInfo is null"); + + pAppFeatureInfo->SetName("SystemTheme"); + pAppFeatureInfo->SetValue(pSystemTheme); + + __pPackageAppInfoImpl->AddAppFeature(*pAppFeatureInfo); + + AppLogTag(OSP_INSTALLER, "", pSystemTheme); + } + + pUserDefinedTheme = pAttr->Find("UserDefinedTheme"); + if (pUserDefinedTheme) + { + _AppFeatureInfoImpl* pAppFeatureInfo = new (std::nothrow) _AppFeatureInfoImpl; + TryReturn(pAppFeatureInfo, false, "[osp-installer] pAppFeatureInfo is null"); + + pAppFeatureInfo->SetName("UserDefinedTheme"); + pAppFeatureInfo->SetValue(pUserDefinedTheme); + + __pPackageAppInfoImpl->AddAppFeature(*pAppFeatureInfo); + + AppLogTag(OSP_INSTALLER, "", pUserDefinedTheme); + } + + return true; +} + + +bool +ManifestHandler::OnDataControlStartElement(void) +{ + XmlAttribute *pAttr = null; + char *pProviderId = null; + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pProviderId = pAttr->Find("ProviderId"); + TryReturn(pProviderId, true, "[osp-installer] pProviderId is null"); + + __pDataControlInfoImpl = new (std::nothrow) _DataControlInfoImpl; + TryReturn(__pDataControlInfoImpl, false, "[osp-installer] __pDataControlInfoImpl is null"); + + __pDataControlInfoImpl->SetProviderId(pProviderId); + + AppLogTag(OSP_INSTALLER, "", pProviderId); + + return true; +} + +bool +ManifestHandler::OnContentsStartElement(void) +{ + __pContentDataList = new (std::nothrow) ArrayList; + TryReturn(__pContentDataList, false, "[osp-installer] __pContentDataList is null"); + + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnContentStartElement(void) +{ + TryReturn(__pContentData == null, false, "[osp-installer] __pContentData is not null"); + + XmlAttribute *pAttr = null; + char *pDefault = null; + + __pContentData = new (std::nothrow) ContentData; + TryReturn(__pContentData, false, "[osp-installer] __pContentData is null"); + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + char* pId = pAttr->Find("Id"); + if (pId) + { + __pContentData->SetContentId(pId); + } + + char* pEntryName = pAttr->Find("EntryName"); + if (pEntryName) + { + __pContentData->SetContentId(pEntryName); + } + + pDefault = pAttr->Find("Default"); + if (pDefault) + { + if (strcasecmp(pDefault, "True") == 0) + { + __isDefaultAppDetected = true; + } + } + + AppLogTag(OSP_INSTALLER, "", pId, pEntryName); + + return true; +} + +bool +ManifestHandler::OnLiveboxesStartElement(const char *pName) +{ + __pParser = new (std::nothrow) ManifestLiveboxesParser; + TryReturn(__pParser, false, "[osp-installer] __pParser is null"); + + __isParserMode = true; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + __pParser->Construct(this); + + return __pParser->OnStartElement(pName); +} + +bool +ManifestHandler::OnAccountsStartElement(const char *pName) +{ + __pParser = new (std::nothrow) ManifestAccountsParser; + TryReturn(__pParser, false, "[osp-installer] __pParser is null"); + + __isParserMode = true; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + __pParser->Construct(this); + + return __pParser->OnStartElement(pName); +} + +bool +ManifestHandler::OnAppControlsStartElement(const char *pName) +{ + __pParser = new (std::nothrow) ManifestAppControlsParser; + TryReturn(__pParser, false, "[osp-installer] __pParser is null"); + + __isParserMode = true; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + __pParser->Construct(this); + + return __pParser->OnStartElement(pName); +} + +bool +ManifestHandler::OnPrivilegesEndElement(void) +{ + if (__pContext->IsVerificationMode() == false) + { + AppLogTag(OSP_INSTALLER, "no signature file[%ls]", __pContext->GetSignatureXmlPath().GetPointer()); + + result r = E_SUCCESS; + String privileges; + String hmacPrivileges; + String appId = __pPackageInfoImpl->GetId(); + r = PrivilegeHandler::GenerateCipherPrivilege(appId, *__pPrivilegeList, privileges, hmacPrivileges); + TryReturn(!IsFailed(r), false, "[osp-installer] privMgr.GeneratePrivilegeString() failed"); + + __pPackageInfoImpl->SetPrivilegesValue(privileges, hmacPrivileges); + } + + __pContext->SetPrivilegeList(__pPrivilegeList); + + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnUiAppEndElement(void) +{ + if (__pContext->__isSubMode == true) + { + __pSubModeAppControlDataList = __pAppData->__pAppControlDataList; + __pAppData->__pAppControlDataList = null; + __pContext->__subModeAppName = __pPackageAppInfoImpl->GetName(); + } + + __pPackageInfoImpl->AddAppInfo(*__pPackageAppInfoImpl); + __pPackageAppInfoImpl = null; + + __isDefaultName = false; + + __pContext->__pAppDataList->Add(__pAppData); + __pAppData = null; + + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnServiceAppEndElement(void) +{ + if (__pContext->__isSubMode == true) + { + __pSubModeAppControlDataList = __pAppData->__pAppControlDataList; + __pAppData->__pAppControlDataList = null; + __pContext->__subModeAppName = __pPackageAppInfoImpl->GetName(); + } + + __pPackageInfoImpl->AddAppInfo(*__pPackageAppInfoImpl); + __pPackageAppInfoImpl = null; + + __isDefaultName = false; + + __pContext->__pAppDataList->Add(__pAppData); + __pAppData = null; + + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnAppsEndElement(void) +{ + if (__pContext->__isSubMode == true) + { + __pAppData = new (std::nothrow) AppData; + TryReturn(__pAppData, false, "[osp-installer] __pAppData is null"); + + __pAppData->__pAppControlDataList = __pSubModeAppControlDataList; + __pSubModeAppControlDataList = null; + + __pContext->__pAppDataList->Add(__pAppData); + } + + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnIconsEndElement(void) +{ + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnDataControlEndElement(void) +{ + __pPackageAppInfoImpl->AddDataControl(__pDataControlInfoImpl); + __pDataControlInfoImpl = null; + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnDataControlTypeEndElement(void) +{ + __pDataControlInfoImpl->AddControlType(__pDataControlTypeImpl); + __pDataControlTypeImpl = null; + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnConditionEndElement(void) +{ + __pPackageAppInfoImpl->AddLaunchCondition(*__pLaunchConditionImpl); + __pLaunchConditionImpl = null; + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnNotificationEndElement(void) +{ + __pPackageAppInfoImpl->AddNotification(*__pNotificationImpl); + __pNotificationImpl = null; + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnContentsEndElement(void) +{ + __pContext->SetContentDataList(__pContentDataList); + __pContentDataList = null; + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnContentEndElement(void) +{ + __pContentDataList->Add(*__pContentData); + __pContentData = null; + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnLiveboxesEndElement(void) +{ + delete __pParser; + __isParserMode = false; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + return true; +} + +bool +ManifestHandler::OnAccountsEndElement(void) +{ + delete __pParser; + __isParserMode = false; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + return true; +} + +bool +ManifestHandler::OnAppControlsEndElement(void) +{ + delete __pParser; + __isParserMode = false; + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + return true; +} + +bool +ManifestHandler::OnManifestEndElement(void) +{ + TryReturn(__isDefaultAppDetected, false, "[osp-installer][Error] Main tag is not detected..."); + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnIdValue(const char *pCharacters) +{ + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + __pPackageInfoImpl->SetId(pCharacters); + + return true; +} + +bool +ManifestHandler::OnVersionValue(const char *pCharacters) +{ + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + __pPackageInfoImpl->SetVersion(pCharacters); + + return true; +} + +bool +ManifestHandler::OnTypeValue(const char *pCharacters) +{ + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + //__pPackageInfoImpl->SetAppType(pCharacters); + + if (strcasecmp(pCharacters, "Contents") == 0) + { + __pPackageInfoImpl->SetAppApiVersion("3.0"); + } + + return true; +} + +bool +ManifestHandler::OnAuthorValue(const char *pCharacters) +{ +// XmlAttribute *pAttr = 0; +// char *pAttrValue = 0; +// +// pAttr = GetAttribute(); +// TryReturn(pAttr, true, "[osp-installer] pAttr is null"); +// +// pAttrValue = pAttr->Find("Locale"); +// TryReturn(pAttrValue, true, "[osp-installer] pAttrValue is null"); +// +// if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0) +// { +// // Set default name +// __pPackageInfoImpl->SetAppVendor(pCharacters); +// } + + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + __pPackageInfoImpl->SetAuthor(pCharacters); + + return true; +} + +bool +ManifestHandler::OnUrlValue(const char *pCharacters) +{ + __pPackageInfoImpl->SetUrl(pCharacters); + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + + return true; +} + +bool +ManifestHandler::OnApiVersionValue(const char *pCharacters) +{ + __pPackageInfoImpl->SetAppApiVersion(pCharacters); + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + + XmlAttribute *pAttr = GetAttribute(); + if (pAttr) + { + char* pOspCompat = pAttr->Find("OspCompat"); + if (pOspCompat) + { + AppLogTag(OSP_INSTALLER, " - OspCompat=%s", pOspCompat); + __pContext->__isOspCompat = true; + } + } + + return true; +} + +bool +ManifestHandler::OnPrivilegeValue(const char *pCharacters) +{ + __pPrivilegeList->Add(*new (std::nothrow) String(pCharacters)); + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + + return true; +} + +bool +ManifestHandler::OnIconValue(const char *pCharacters) +{ + XmlAttribute *pAttr = 0; + char *pAttrValue1 = 0; + char *pTypeValue = 0; + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pAttrValue1 = pAttr->Find("Section"); + TryReturn(pAttrValue1, true, "[osp-installer] pAttrValue1 is null"); + + pTypeValue = pAttr->Find("Type"); + TryReturn(pTypeValue, true, "[osp-installer] pTypeValue is null"); + + char icon[1024] = {0,}; + + if (strcasecmp(pTypeValue, "Xhigh") == 0) + { + snprintf(icon, sizeof(icon), "%s/%s", "screen-density-xhigh", pCharacters); + } + else if (strcasecmp(pTypeValue, "High") == 0) + { + snprintf(icon, sizeof(icon), "%s/%s", "screen-density-high", pCharacters); + } + else + { + AppLogTag(OSP_INSTALLER, "Invalid Type [%s]", __pDefaultIconType); + return false; + } + + if (FindElement("Content") == true) + { + TryReturn(__pContentData, false, "[osp-installer] __pContentData is null"); + __pContentData->SetIcon(icon); + } + else + { + if (strcasecmp(pAttrValue1, "MainMenu") == 0) + { + if (__isDefaultMainmenu == false) + { + __pPackageAppInfoImpl->SetMainmenuIcon(icon); + } + + if (strcasecmp(pTypeValue, __pDefaultIconType) == 0) + { + __isDefaultMainmenu = true; + } + } + else if (strcasecmp(pAttrValue1, "Setting") == 0) + { + if (__isDefaultSetting == false) + { + __pPackageAppInfoImpl->SetSettingIcon(icon); + } + + if (strcasecmp(pTypeValue, __pDefaultIconType) == 0) + { + __isDefaultSetting = true; + } + } + else if (strcasecmp(pAttrValue1, "Notification") == 0) + { + if (__isDefaultQuickpanel == false) + { + __pPackageAppInfoImpl->SetQuickpanelIcon(icon); + } + + if (strcasecmp(pTypeValue, __pDefaultIconType) == 0) + { + __isDefaultQuickpanel = true; + } + } + } + + AppLogTag(OSP_INSTALLER, "%s", pAttrValue1, pTypeValue, pCharacters); + + return true; +} + +bool +ManifestHandler::OnNameValue(const char *pCharacters) +{ + XmlAttribute* pAttr = 0; + char* pAttrValue = 0; + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pAttrValue = pAttr->Find("Locale"); + TryReturn(pAttrValue, true, "[osp-installer] pAttrValue is null"); + + if (FindElement("Content") == true) + { + TryReturn(__pContentData, false, "[osp-installer] __pContentData is null"); + + String* pValue = new (std::nothrow) String; + StringUtil::Utf8ToString(pCharacters, *pValue); + __pContentData->AddName(*(new (std::nothrow) String(pAttrValue)), *pValue); + } + else + { + if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0) + { + if (__isDefaultName == true) + { + __pPackageInfoImpl->SetDisplayName(pCharacters); + } + } + + if (__pPackageAppInfoImpl) + { + String* pValue = new (std::nothrow) String; + StringUtil::Utf8ToString(pCharacters, *pValue); + __pPackageAppInfoImpl->AddName(*(new (std::nothrow) String(pAttrValue)), *pValue); + } + } + + AppLogTag(OSP_INSTALLER, "%s", pAttrValue, pCharacters); + + return true; +} + +bool +ManifestHandler::OnDescriptionValue(const char *pCharacters) +{ + XmlAttribute *pAttr = 0; + char *pAttrValue = 0; + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pAttrValue = pAttr->Find("Locale"); + TryReturn(pAttrValue, true, "[osp-installer] pAttrValue is null"); + + if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0) + { + // Set default name + __pPackageInfoImpl->SetDescription(pCharacters); + } + + AppLogTag(OSP_INSTALLER, "%s", pAttrValue, pCharacters); + + return true; +} + +bool +ManifestHandler::OnDataControlTypeValue(const char *pCharacters) +{ + XmlAttribute *pAttr = null; + char *pAccessValue = null; + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pAccessValue = pAttr->Find("Access"); + TryReturn(pAccessValue, true, "[osp-installer] pAccessValue is null"); + + __pDataControlTypeImpl = new (std::nothrow) _DataControlTypeImpl; + TryReturn(__pDataControlTypeImpl, false, "[osp-installer] __pDataControlTypeImpl is null"); + + __pDataControlTypeImpl->SetType(pCharacters); + __pDataControlTypeImpl->SetAccess(pAccessValue); + + AppLogTag(OSP_INSTALLER, "", pAccessValue, pCharacters); + + return true; +} + +bool +ManifestHandler::OnConditionValue(const char *pCharacters) +{ + XmlAttribute *pAttr = null; + char *pName = null; + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pName = pAttr->Find("Name"); + TryReturn(pName, true, "[osp-installer] pName is null"); + + __pLaunchConditionImpl = new (std::nothrow) _LaunchConditionInfoImpl; + TryReturn(__pLaunchConditionImpl, false, "[osp-installer] __pLaunchConditionImpl is null"); + + __pLaunchConditionImpl->SetName(pName); + __pLaunchConditionImpl->SetValue(pCharacters); + + AppLogTag(OSP_INSTALLER, "", pName, pCharacters); + + return true; +} + +bool +ManifestHandler::OnNotificationValue(const char *pCharacters) +{ + XmlAttribute *pAttr = null; + char *pName = null; + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pName = pAttr->Find("Name"); + TryReturn(pName, true, "[osp-installer] pName is null"); + + __pNotificationImpl = new (std::nothrow) _NotificationInfoImpl; + TryReturn(__pNotificationImpl, false, "[osp-installer] __pNotificationImpl is null"); + + __pNotificationImpl->SetName(pName); + __pNotificationImpl->SetValue(pCharacters); + + AppLogTag(OSP_INSTALLER, "", pName, pCharacters); + + return true; +} + +bool +ManifestHandler::OnInstallationLocationValue(const char *pCharacters) +{ + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + + if ((strcasecmp(pCharacters, "UserPreferred") == 0) && + (File::IsFileExist(DIR_MEMORYCARD_INSTALLATION) == true)) + { + AppLogTag(OSP_INSTALLER, "INSTALLATION_STORAGE = [EXTERNAL]"); + __pContext->SetInstallationStorage(InstallationContext::INSTALLATION_STORAGE_EXTERNAL); + __pPackageInfoImpl->SetInstalledInExternalStorage(true); + } + + return true; +} + +bool +ManifestHandler::OnCategoryValue(const char *pCharacters) +{ + TryReturn(__pAppData, false, "[osp-installer] __pAppData is null"); + + __pAppData->__pCategoryList->Add(new (std::nothrow) String(pCharacters)); + + if (strcasecmp(pCharacters, TIZEN_CATEGORY_IME) == 0) + { + __pPackageAppInfoImpl->SetAppFeature(CATEGORY_TYPE_IME); + } + + return true; +} + +bool +ManifestHandler::FindElement(const char *pName) +{ + bool res = false; + Tizen::Base::Collection::IEnumerator* pEnum = GetElementEnumeratorN(); + + if (pEnum) + { + while(pEnum->MoveNext() == E_SUCCESS) + { + String* pStr = static_cast(pEnum->GetCurrent()); + if (pStr) + { + if (pStr->Equals(pName, false) == true) + { + AppLogTag(OSP_INSTALLER, "[%s] is matched.", pName); + res = true; + break; + } + } + } + + delete pEnum; + } + + return res; +} + +bool +ManifestHandler::AddAppFeature(const Tizen::Base::String& name, const Tizen::Base::String& value) +{ + _AppFeatureInfoImpl* pAppFeatureInfo = new (std::nothrow) _AppFeatureInfoImpl; + TryReturn(pAppFeatureInfo, false, "[osp-installer] pAppFeatureInfo is null"); + + pAppFeatureInfo->SetName(name); + pAppFeatureInfo->SetValue(value); + __pPackageAppInfoImpl->AddAppFeature(*pAppFeatureInfo); + + return true; +} + +bool +ManifestHandler::ParseAppAttribute(XmlAttribute* pAttr, bool isUiApp) +{ + char* pName = pAttr->Find("Name"); + if (pName == null) + { + pName = pAttr->Find("ExecutableName"); + } + + if (pName) + { + AppLogTag(OSP_INSTALLER, " - Name=%s", pName); + __pPackageAppInfoImpl->SetName(pName); + } + + char* pMain = pAttr->Find("Main"); + if (pMain == null) + { + pMain = pAttr->Find("Default"); + } + + if (pMain) + { + AppLogTag(OSP_INSTALLER, " - Main=%s", pMain); + + __pPackageAppInfoImpl->SetDefault(pMain); + + if (strcasecmp(pMain, "True") == 0) + { + __isDefaultName = true; + __isDefaultAppDetected = true; + } + } + else + { + __pPackageAppInfoImpl->SetDefault("False"); + } + + char* pHwAcceleration = pAttr->Find("HwAcceleration"); + if (pHwAcceleration) + { + AddAppFeature("HwAcceleration", pHwAcceleration); + AppLogTag(OSP_INSTALLER, " - HwAcceleration=%s", pHwAcceleration); + } + else + { + char* pGlFrame = pAttr->Find("GlFrame"); + if (pGlFrame) + { + AddAppFeature("GlFrame", pGlFrame); + AppLogTag(OSP_INSTALLER, " - GlFrame=%s", pGlFrame); + } + } + + char* pCategory = pAttr->Find("Category"); + if (pCategory) + { + AppLogTag(OSP_INSTALLER, " - Category=%s", pCategory); + + if (strcasecmp(pCategory, "home-screen") == 0) + { + __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_HOMESCREEN)); + } + else if (strcasecmp(pCategory, "lock-screen") == 0) + { + __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_LOCKSCREEN)); + } + else if (strcasecmp(pCategory, "Ime") == 0) + { + __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_IME)); + } + + CategoryType categoryType = InstallerUtil::GetCategoryType(pCategory); + __pPackageAppInfoImpl->SetAppFeature(categoryType); + } + + char* pSubMode = pAttr->Find("SubMode"); + if (pSubMode) + { + if (strcasecmp(pSubMode, "True") == 0) + { + __pContext->__isSubMode = true; + AppLogTag(OSP_INSTALLER, " - SubMode=%s", pSubMode); + } + } + + if (isUiApp == true) + { + __pPackageAppInfoImpl->SetType("UiApp"); + + char* pMenuIconVisible = pAttr->Find("MenuIconVisible"); + if (pMenuIconVisible == null) + { + pMenuIconVisible = pAttr->Find("MainmenuVisible"); + } + + if (pMenuIconVisible) + { + if (strcasecmp(pMenuIconVisible, "True") == 0) + { + __pPackageAppInfoImpl->SetMainmenuVisible(true); + } + else + { + __pPackageAppInfoImpl->SetMainmenuVisible(false); + } + + AddAppFeature("MenuIconVisible", pMenuIconVisible); + AppLogTag(OSP_INSTALLER, " - MenuIconVisible=%s", pMenuIconVisible); + } + } + else + { + __pPackageAppInfoImpl->SetType("ServiceApp"); + __pPackageAppInfoImpl->SetMainmenuVisible(false); + + char *pUseUi = pAttr->Find("UseUi"); + if (pUseUi) + { + AddAppFeature("UseUi", pUseUi); + AppLogTag(OSP_INSTALLER, " - UseUi=%s", pUseUi); + } + + char *pLifeDuration = pAttr->Find("LifeDuration"); + if (pLifeDuration) + { + AddAppFeature("LifeDuration", pLifeDuration); + AppLogTag(OSP_INSTALLER, " - LifeDuration=%s", pLifeDuration); + } + + char *pLaunchOnBoot = pAttr->Find("LaunchOnBoot"); + if (pLaunchOnBoot) + { + AddAppFeature("LaunchOnBoot", pLaunchOnBoot); + AppLogTag(OSP_INSTALLER, " - LaunchOnBoot=%s", pLaunchOnBoot); + } + + char *pAutoRestart = pAttr->Find("AutoRestart"); + if (pAutoRestart) + { + AddAppFeature("AutoRestart", pAutoRestart); + AppLogTag(OSP_INSTALLER, " - AutoRestart=%s", pAutoRestart); + } + } + + String appId; + appId.Format(1024, PACKAGE_NAME_RULE, __pPackageInfoImpl->GetId().GetPointer(), pName); + __pPackageAppInfoImpl->SetPackageName(appId); + + AppLogTag(OSP_INSTALLER, " - appId=%ls", appId.GetPointer()); + + return true; +} + +AppData* +ManifestHandler::GetAppData(void) +{ + return __pAppData; +} + +char* +ManifestHandler::GetDefaultIconType(void) +{ + return __pDefaultIconType; +} + diff --git a/src/XmlHandler/ManifestHandler.h b/src/XmlHandler/ManifestHandler.h new file mode 100755 index 0000000..1a3e0a7 --- /dev/null +++ b/src/XmlHandler/ManifestHandler.h @@ -0,0 +1,173 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestHandler.h + * @brief This is the header file for the %ManifestHandler class. + * + * This header file contains the declarations of the %ManifestHandler class. + */ +#ifndef _MANIFEST_HANDLER_H_ +#define _MANIFEST_HANDLER_H_ + +#include +#include + +#include "XmlHandler.h" +#include "InstallationContext.h" + +class ManifestParser; + +/** + * @class ManifestHandler + * @brief This class represents the class of ManifestHandler. + * @since 1.0 + * + * This class represents the class of ManifestHandler. + * + */ +class ManifestHandler + : public XmlHandler +{ +public: + ManifestHandler(void); + virtual ~ManifestHandler(void); + + bool Construct(InstallationContext *pConext); + InstallationContext* GetContext(void); + bool Parse(const char *pFilepath); + + AppData* GetAppData(void); + char* GetDefaultIconType(void); + +private: + ManifestHandler(const ManifestHandler& value); + ManifestHandler& operator =(const ManifestHandler& source); + + virtual bool OnStartElement(const char *pName); + virtual bool OnEndElement(const char *pName); + virtual bool OnCharacters(const char *pCharacters); + + // StartElement + bool OnPrivilegesStartElement(void); + bool OnUiAppStartElement(void); + bool OnServiceAppStartElement(void); + bool OnIconsStartElement(void); + bool OnUiScalabilityStartElement(void); + bool OnUiThemeStartElement(void); + + bool OnAppControlStartElement(void); + bool OnCapabilityStartElement(void); + bool OnResolutionStartElement(void); + bool OnOperationStartElement(void); + bool OnDataControlStartElement(void); + + bool OnContentsStartElement(void); + bool OnContentStartElement(void); + + // Parsers + bool OnLiveboxesStartElement(const char *pName); + bool OnAccountsStartElement(const char *pName); + bool OnAppControlsStartElement(const char *pName); + + // EndElement + bool OnPrivilegesEndElement(void); + bool OnUiAppEndElement(void); + bool OnServiceAppEndElement(void); + bool OnAppsEndElement(void); + bool OnIconsEndElement(void); + bool OnUiScalabilityEndElement(void); + bool OnUiThemeEndElement(void); + + bool OnDataControlEndElement(void); + bool OnDataControlTypeEndElement(void); + bool OnConditionEndElement(void); + bool OnNotificationEndElement(void); + + bool OnContentsEndElement(void); + bool OnContentEndElement(void); + + // Parsers + bool OnLiveboxesEndElement(void); + bool OnAccountsEndElement(void); + bool OnAppControlsEndElement(void); + + bool OnManifestEndElement(void); + + // OnValue + bool OnIdValue(const char *pCharacters); + bool OnVersionValue(const char *pCharacters); + bool OnTypeValue(const char *pCharacters); + bool OnAuthorValue(const char *pCharacters); + bool OnUrlValue(const char *pCharacters); + bool OnApiVersionValue(const char *pCharacters); + bool OnPrivilegeValue(const char *pCharacters); + bool OnIconValue(const char *pCharacters); + bool OnNameValue(const char *pCharacters); + bool OnDescriptionValue(const char *pCharacters); + bool OnDataControlTypeValue(const char *pCharacters); + bool OnConditionValue(const char *pCharacters); + bool OnNotificationValue(const char *pCharacters); + bool OnSizeValue(const char *pCharacters); + bool OnInstallationLocationValue(const char *pCharacters); + bool OnCategoryValue(const char *pCharacters); + + bool OnMimeTypeValue(const char* pCharacters); + bool OnUriValue(const char* pCharacters); + + bool OnConfigurationAppControlAppIdValue(const char* pCharacters); + + // help functions + bool FindElement(const char *pName); + bool AddAppFeature(const Tizen::Base::String& name, const Tizen::Base::String& value); + bool ParseAppAttribute(XmlAttribute* pAttr, bool isUiApp); + +private: + InstallationContext* __pContext; + Tizen::Base::Collection::ArrayList* __pPrivilegeList; + Tizen::Base::Collection::ArrayList* __pContentDataList; + Tizen::App::Package::_PackageInfoImpl* __pPackageInfoImpl; + Tizen::App::Package::_PackageAppInfoImpl* __pPackageAppInfoImpl; + Tizen::App::Package::_AppControlInfoImpl* __pAppControlInfoImpl; + Tizen::App::Package::_AppControlCapabilityInfoImpl* __pAppControlCapabilityInfoImpl; + Tizen::App::Package::_AppControlResolutionInfoImpl* __pAppControlResolutionInfoImpl; + Tizen::App::Package::_DataControlInfoImpl* __pDataControlInfoImpl; + Tizen::App::Package::_DataControlTypeImpl* __pDataControlTypeImpl; + Tizen::App::Package::_LaunchConditionInfoImpl* __pLaunchConditionImpl; + Tizen::App::Package::_NotificationInfoImpl* __pNotificationImpl; + + ContentData* __pContentData; + char* __pDefaultIconType; + + bool __isDefaultMainmenu; + bool __isDefaultSetting; + bool __isDefaultTicker; + bool __isDefaultQuickpanel; + bool __isDefaultLaunchImage; + bool __isDefaultName; + bool __isDefaultAppDetected; + + AppData* __pAppData; + Tizen::Base::Collection::IListT* __pSubModeAppControlDataList; + + bool __isParserMode; + ManifestParser* __pParser; + + friend class ManifestAppControlsParser; + +}; // ManifestHandler + +#endif // _MANIFEST_HANDLER_H_ diff --git a/src/XmlHandler/Parser/ManifestAccountsParser.cpp b/src/XmlHandler/Parser/ManifestAccountsParser.cpp new file mode 100755 index 0000000..a50d680 --- /dev/null +++ b/src/XmlHandler/Parser/ManifestAccountsParser.cpp @@ -0,0 +1,272 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestAccountsParser.cpp + * @brief This is the implementation file for %ManifestAccountsParser class. + */ + +#include +#include +#include +#include + +#include "ManifestAccountsParser.h" +#include "InstallerUtil.h" +#include "InstallationContext.h" +#include "ManifestHandler.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::App::Package; +using namespace Tizen::Io; +using namespace Tizen::System; + +ManifestAccountsParser::ManifestAccountsParser(void) +:__pContext(null) +,__pAccountData(null) +,__isAccountIconSelected(false) +,__isAccountSmallIconSelected(false) +{ +} + +ManifestAccountsParser::~ManifestAccountsParser(void) +{ + delete __pAccountData; +} + +bool +ManifestAccountsParser::OnStartElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null"); + bool status = true; + + if (strcasecmp(pName, "Accounts") == 0) + { + status = OnAccountsStartElement(); + } + else if (strcasecmp(pName, "AccountProvider") == 0) + { + status = OnAccountProviderStartElement(); + } + + return status; +} + +bool +ManifestAccountsParser::OnEndElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null"); + bool status = true; + + if (strcasecmp(pName, "Accounts") == 0) + { + status = OnAccountsEndElement(); + } + else if (strcasecmp(pName, "AccountProvider") == 0) + { + status = OnAccountProviderEndElement(); + } + + return true; +} + +bool +ManifestAccountsParser::OnCharacters(const char *pCharacters) +{ + TryReturn(pCharacters, true, "[osp-installer] pCharacters is null"); + bool status = true; + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + char *pName = pHandler->GetElementName(); + TryReturn(pName, false, "[osp-installer] pName is null"); + + if (strcasecmp(pName, "DisplayName") == 0) + { + status = OnDisplayNameValue(pCharacters); + } + else if (strcasecmp(pName, "Icon") == 0) + { + status = OnIconValue(pCharacters); + } + + return true; +} + +bool +ManifestAccountsParser::OnAccountsStartElement(void) +{ + ManifestHandler* __pHandler = GetHandler(); + TryReturn(__pHandler, false, "[osp-installer] __pHandler is null"); + + __pContext = __pHandler->GetContext(); + TryReturn(__pContext, false, "[osp-installer] __pContext is null"); + + AppLogTag(OSP_INSTALLER, " "); + + return true; +} + +bool +ManifestAccountsParser::OnAccountProviderStartElement(void) +{ + XmlAttribute *pAttr = null; + + __pAccountData = new (std::nothrow) AccountData; + TryReturn(__pAccountData, false, "[osp-installer] __pAccountData is null"); + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + pAttr = pHandler->GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + AppLogTag(OSP_INSTALLER, " "); + + char *pProviderId = pAttr->Find("ProviderId"); + if (pProviderId) + { + __pAccountData->__providerId = pProviderId; + AppLogTag(OSP_INSTALLER, " - ProviderId=%s", pProviderId); + } + + char *pMultipleAccountsSupport = pAttr->Find("MultipleAccountsSupport"); + if (pMultipleAccountsSupport) + { + __pAccountData->__multipleAccountsSupport = pMultipleAccountsSupport; + AppLogTag(OSP_INSTALLER, " - MultipleAccountsSupport=%s", pMultipleAccountsSupport); + } + + return true; +} + +bool +ManifestAccountsParser::OnAccountsEndElement(void) +{ + AppLogTag(OSP_INSTALLER, " "); + + return true; +} + +bool +ManifestAccountsParser::OnAccountProviderEndElement(void) +{ + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + AppData* pAppData = pHandler->GetAppData(); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + pAppData->__pAccountDataList->Add(__pAccountData); + __pAccountData = null; + AppLogTag(OSP_INSTALLER, " "); + + return true; +} + +bool +ManifestAccountsParser::OnDisplayNameValue(const char *pCharacters) +{ + XmlAttribute* pAttr = 0; + char* pAttrValue = 0; + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + pAttr = pHandler->GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pAttrValue = pAttr->Find("Locale"); + TryReturn(pAttrValue, true, "[osp-installer] pAttrValue is null"); + + String* pValue = new (std::nothrow) String; + StringUtil::Utf8ToString(pCharacters, *pValue); + __pAccountData->__pNameList->Add(new (std::nothrow) String(pAttrValue), pValue); + + AppLogTag(OSP_INSTALLER, " %s", pCharacters); + + return true; +} + +bool +ManifestAccountsParser::OnIconValue(const char *pCharacters) +{ + XmlAttribute* pAttr = 0; + char* pSectionValue = 0; + char* pTypeValue = 0; + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + pAttr = pHandler->GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pSectionValue = pAttr->Find("Section"); + TryReturn(pSectionValue, true, "[osp-installer] pSectionValue is null"); + + pTypeValue = pAttr->Find("Type"); + TryReturn(pTypeValue, true, "[osp-installer] pTypeValue is null"); + + char* pDefaultIconType = pHandler->GetDefaultIconType(); + TryReturn(pDefaultIconType, false, "[osp-installer] pDefaultIconType is null"); + + String icon; + if (strcasecmp(pTypeValue, "Xhigh") == 0) + { + icon.Format(1024, L"%s/%s", "screen-density-xhigh", pCharacters); + } + else if (strcasecmp(pTypeValue, "High") == 0) + { + icon.Format(1024, L"%s/%s", "screen-density-high", pCharacters); + } + else + { + AppLogTag(OSP_INSTALLER, "Invalid Type [%s]", pDefaultIconType); + return false; + } + + if (strcasecmp(pSectionValue, "Account") == 0) + { + if (__isAccountIconSelected == false) + { + __pAccountData->__accountIcon = icon; + } + + if (strcasecmp(pTypeValue, pDefaultIconType) == 0) + { + __isAccountIconSelected = true; + } + } + else if (strcasecmp(pSectionValue, "AccountSmall") == 0) + { + if (__isAccountSmallIconSelected == false) + { + __pAccountData->__accountSmallIcon = icon; + } + + if (strcasecmp(pTypeValue, pDefaultIconType) == 0) + { + __isAccountSmallIconSelected = true; + } + } + + AppLogTag(OSP_INSTALLER, " %s", pSectionValue, pTypeValue, pCharacters); + + return true; +} diff --git a/src/XmlHandler/Parser/ManifestAccountsParser.h b/src/XmlHandler/Parser/ManifestAccountsParser.h new file mode 100755 index 0000000..74e90cb --- /dev/null +++ b/src/XmlHandler/Parser/ManifestAccountsParser.h @@ -0,0 +1,69 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestAccountsParser.h + * @brief This is the header file for the %ManifestAccountsParser class. + * + * This header file contains the declarations of the %ManifestAccountsParser class. + */ +#ifndef _MANIFEST_ACCOUNTS_PARSER_H_ +#define _MANIFEST_ACCOUNTS_PARSER_H_ + +#include + +#include + +#include "ManifestParser.h" +#include "InstallationContext.h" + +/** + * @class ManifestAccountsParser + * @brief This class represents the class of ManifestAccountsParser. + * @since 1.0 + * + * This class represents the class of ManifestAccountsParser. + * + */ +class ManifestAccountsParser + : public ManifestParser +{ +public: + ManifestAccountsParser(void); + virtual ~ManifestAccountsParser(void); + + virtual bool OnStartElement(const char *pName); + virtual bool OnEndElement(const char *pName); + virtual bool OnCharacters(const char *pCharacters); + +private: + bool OnAccountsStartElement(void); + bool OnAccountProviderStartElement(void); + bool OnAccountsEndElement(void); + bool OnAccountProviderEndElement(void); + + bool OnDisplayNameValue(const char *pCharacters); + bool OnIconValue(const char *pCharacters); + +private: + InstallationContext* __pContext; + AccountData* __pAccountData; + bool __isAccountIconSelected; + bool __isAccountSmallIconSelected; + +}; // ManifestAccountsParser + +#endif // _MANIFEST_ACCOUNTS_PARSER_H_ diff --git a/src/XmlHandler/Parser/ManifestAppControlsParser.cpp b/src/XmlHandler/Parser/ManifestAppControlsParser.cpp new file mode 100755 index 0000000..44ab921 --- /dev/null +++ b/src/XmlHandler/Parser/ManifestAppControlsParser.cpp @@ -0,0 +1,398 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestAppControlsParser.cpp + * @brief This is the implementation file for %ManifestAppControlsParser class. + */ + +#include +#include +#include +#include + +#include "ManifestAppControlsParser.h" +#include "InstallerUtil.h" +#include "InstallationContext.h" +#include "ManifestHandler.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::App::Package; +using namespace Tizen::Io; +using namespace Tizen::System; + +ManifestAppControlsParser::ManifestAppControlsParser(void) +:__pContext(null) +,__pAppControlData(null) +,__legacyAppControls(false) +{ +} + +ManifestAppControlsParser::~ManifestAppControlsParser(void) +{ + delete __pAppControlData; +} + +bool +ManifestAppControlsParser::OnStartElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null"); + bool status = true; + + if (strcasecmp(pName, "AppControls") == 0) + { + status = OnAppControlsStartElement(); + } + else if (strcasecmp(pName, "AppControl") == 0) + { + status = OnAppControlStartElement(); + } + else if (strcasecmp(pName, "Capability") == 0) + { + status = OnCapabilityStartElement(); + } + else if (strcasecmp(pName, "Resolution") == 0) + { + status = OnResolutionStartElement(); + } + + return status; +} + +bool +ManifestAppControlsParser::OnEndElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null"); + bool status = true; + + if (strcasecmp(pName, "AppControls") == 0) + { + status = OnAppControlsEndElement(); + } + else if (strcasecmp(pName, "AppControl") == 0) + { + status = OnAppControlEndElement(); + } + else if (strcasecmp(pName, "Capability") == 0) + { + status = OnCapabilityEndElement(); + } + else if (strcasecmp(pName, "Resolution") == 0) + { + status = OnResolutionEndElement(); + } + + return true; +} + +bool +ManifestAppControlsParser::OnCharacters(const char *pCharacters) +{ + TryReturn(pCharacters, true, "[osp-installer] pCharacters is null"); + bool status = true; + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + char *pName = pHandler->GetElementName(); + TryReturn(pName, false, "[osp-installer] pName is null"); + + if (strcasecmp(pName, "Operation") == 0) + { + status = OnOperationValue(pCharacters); + } + else if (strcasecmp(pName, "MimeType") == 0) + { + status = OnMimeTypeValue(pCharacters); + } + else if (strcasecmp(pName, "Uri") == 0) + { + status = OnUriValue(pCharacters); + } + + return true; +} + +bool +ManifestAppControlsParser::OnAppControlsStartElement(void) +{ + ManifestHandler* __pHandler = GetHandler(); + TryReturn(__pHandler, false, "[osp-installer] __pHandler is null"); + + __pContext = __pHandler->GetContext(); + TryReturn(__pContext, false, "[osp-installer] __pContext is null"); + + AppLogTag(OSP_INSTALLER, " "); + return true; +} + +bool +ManifestAppControlsParser::OnAppControlStartElement(void) +{ + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + AppData* pAppData = pHandler->GetAppData(); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + AppLogTag(OSP_INSTALLER, " "); + + XmlAttribute *pAttr = pHandler->GetAttribute(); + if (pAttr == null) + { + __pAppControlData = new (std::nothrow) AppControlData; + TryReturn(__pAppControlData, false, "[osp-installer] __pAppControlData is null"); + __legacyAppControls = false; + + return true; + } + + pHandler->__pAppControlInfoImpl = new (std::nothrow) _AppControlInfoImpl; + TryReturn(pHandler->__pAppControlInfoImpl, false, "[osp-installer] pHandler->__pAppControlInfoImpl is null"); + + char* pProviderId = pAttr->Find("ProviderId"); + if (pProviderId) + { + AppLogTag(OSP_INSTALLER, " - ProviderId=%s", pProviderId); + pHandler->__pAppControlInfoImpl->SetProviderId(pProviderId); + __legacyAppControls = true; + } + + char* pCategory = pAttr->Find("Category"); + if (pCategory) + { + AppLogTag(OSP_INSTALLER, " - Category=%s", pCategory); + pHandler->__pAppControlInfoImpl->SetCategory(pCategory); + } + + return true; +} + +bool +ManifestAppControlsParser::OnCapabilityStartElement(void) +{ + if (__legacyAppControls == false) + { + return true; + } + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + XmlAttribute *pAttr = pHandler->GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + AppLogTag(OSP_INSTALLER, " "); + + char* pOperationId = pAttr->Find("OperationId"); + if (pOperationId) + { + AppLogTag(OSP_INSTALLER, " - OperationId=%s", pOperationId); + + pHandler->__pAppControlCapabilityInfoImpl = new (std::nothrow) _AppControlCapabilityInfoImpl; + TryReturn(pHandler->__pAppControlCapabilityInfoImpl, false, "[osp-installer] pHandler->__pAppControlCapabilityInfoImpl is null"); + + pHandler->__pAppControlCapabilityInfoImpl->SetOperationId(pOperationId); + } + + return true; +} + +bool +ManifestAppControlsParser::OnResolutionStartElement(void) +{ + if (__legacyAppControls == false) + { + return true; + } + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + XmlAttribute *pAttr = pHandler->GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pHandler->__pAppControlResolutionInfoImpl = new (std::nothrow) _AppControlResolutionInfoImpl; + TryReturn(pHandler->__pAppControlResolutionInfoImpl, false, "[osp-installer] pHandler->__pAppControlResolutionInfoImpl is null"); + + AppLogTag(OSP_INSTALLER, " "); + + char* pMimeType = pAttr->Find("MimeType"); + if (pMimeType) + { + AppLogTag(OSP_INSTALLER, " - MimeType=%s", pMimeType); + pHandler->__pAppControlResolutionInfoImpl->SetMimeType(new (std::nothrow) String(pMimeType)); + } + + char* pUriScheme = pAttr->Find("UriScheme"); + if (pUriScheme) + { + AppLogTag(OSP_INSTALLER, " - UriScheme=%s", pUriScheme); + pHandler->__pAppControlResolutionInfoImpl->SetUriScheme(new (std::nothrow) String(pUriScheme)); + } + + return true; +} + +bool +ManifestAppControlsParser::OnAppControlsEndElement(void) +{ + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + AppData* pAppData = pHandler->GetAppData(); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + pAppData->__legacyAppControls = __legacyAppControls; + AppLogTag(OSP_INSTALLER, " "); + + if (pAppData->__legacyAppControls == true) + { + AppLogTag(OSP_INSTALLER, " AppControls spec is legacy"); + } + + return true; +} + +bool +ManifestAppControlsParser::OnAppControlEndElement(void) +{ + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + AppData* pAppData = pHandler->GetAppData(); + TryReturn(pAppData, false, "[osp-installer] pAppData is null"); + + AppLogTag(OSP_INSTALLER, " "); + + if (__legacyAppControls == true) + { + pHandler->__pPackageAppInfoImpl->AddAppControl(pHandler->__pAppControlInfoImpl); + pHandler->__pAppControlInfoImpl = null; + } + else + { + pAppData->__pAppControlDataList->Add(__pAppControlData); + __pAppControlData = null; + } + + return true; +} + +bool +ManifestAppControlsParser::OnCapabilityEndElement(void) +{ + if (__legacyAppControls == false) + { + return true; + } + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + if (pHandler->__pAppControlInfoImpl) + { + pHandler->__pAppControlInfoImpl->AddCapability(pHandler->__pAppControlCapabilityInfoImpl); + pHandler->__pAppControlCapabilityInfoImpl = null; + } + AppLogTag(OSP_INSTALLER, " "); + + return true; +} + +bool +ManifestAppControlsParser::OnResolutionEndElement(void) +{ + if (__legacyAppControls == false) + { + return true; + } + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + pHandler->__pAppControlCapabilityInfoImpl->AddResolution(pHandler->__pAppControlResolutionInfoImpl); + pHandler->__pAppControlResolutionInfoImpl = null; + + AppLogTag(OSP_INSTALLER, " "); + + return true; +} + +bool +ManifestAppControlsParser::OnOperationValue(const char* pCharacters) +{ + if (__legacyAppControls == true) + { + return true; + } + + if (pCharacters && pCharacters[0]) + { + String* pStr = new (std::nothrow) String(pCharacters); + if (__pAppControlData->__pOperationList->Contains(pStr) == false) + { + AppLogTag(OSP_INSTALLER, " %s", pCharacters); + __pAppControlData->__pOperationList->Add(pStr); + } + } + + return true; +} + +bool +ManifestAppControlsParser::OnMimeTypeValue(const char* pCharacters) +{ + if (__legacyAppControls == true) + { + return true; + } + + if (pCharacters && pCharacters[0]) + { + String* pStr = new (std::nothrow) String(pCharacters); + if (__pAppControlData->__pMimeTypeList->Contains(pStr) == false) + { + AppLogTag(OSP_INSTALLER, " %s", pCharacters); + __pAppControlData->__pMimeTypeList->Add(pStr); + } + } + + return true; +} + +bool +ManifestAppControlsParser::OnUriValue(const char* pCharacters) +{ + if (__legacyAppControls == true) + { + return true; + } + + if (pCharacters && pCharacters[0]) + { + String* pStr = new (std::nothrow) String(pCharacters); + if (__pAppControlData->__pUriList->Contains(pStr) == false) + { + AppLogTag(OSP_INSTALLER, " %s", pCharacters); + __pAppControlData->__pUriList->Add(pStr); + } + } + + return true; +} diff --git a/src/XmlHandler/Parser/ManifestAppControlsParser.h b/src/XmlHandler/Parser/ManifestAppControlsParser.h new file mode 100755 index 0000000..52ab0cd --- /dev/null +++ b/src/XmlHandler/Parser/ManifestAppControlsParser.h @@ -0,0 +1,76 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestAppControlsParser.h + * @brief This is the header file for the %ManifestAppControlsParser class. + * + * This header file contains the declarations of the %ManifestAppControlsParser class. + */ +#ifndef _MANIFEST_APPCONTROLS_PARSER_H_ +#define _MANIFEST_APPCONTROLS_PARSER_H_ + +#include + +#include + +#include "ManifestParser.h" +#include "InstallationContext.h" + +/** + * @class ManifestAppControlsParser + * @brief This class represents the class of ManifestAppControlsParser. + * @since 1.0 + * + * This class represents the class of ManifestAppControlsParser. + * + */ +class ManifestAppControlsParser + : public ManifestParser +{ +public: + ManifestAppControlsParser(void); + virtual ~ManifestAppControlsParser(void); + + virtual bool OnStartElement(const char *pName); + virtual bool OnEndElement(const char *pName); + virtual bool OnCharacters(const char *pCharacters); + +private: + bool OnAppControlsStartElement(void); + bool OnAppControlStartElement(void); + bool OnCapabilityStartElement(void); + bool OnResolutionStartElement(void); + + bool OnAppControlsEndElement(void); + bool OnAppControlEndElement(void); + + bool OnCapabilityEndElement(void); + bool OnResolutionEndElement(void); + + bool OnOperationValue(const char* pCharacters); + bool OnMimeTypeValue(const char* pCharacters); + bool OnUriValue(const char* pCharacters); + +private: + InstallationContext* __pContext; + AppControlData* __pAppControlData; + + bool __legacyAppControls; + +}; // ManifestAppControlsParser + +#endif // _MANIFEST_APPCONTROLS_PARSER_H_ diff --git a/src/XmlHandler/Parser/ManifestLiveboxesParser.cpp b/src/XmlHandler/Parser/ManifestLiveboxesParser.cpp new file mode 100755 index 0000000..726c9c3 --- /dev/null +++ b/src/XmlHandler/Parser/ManifestLiveboxesParser.cpp @@ -0,0 +1,243 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestLiveboxesParser.cpp + * @brief This is the implementation file for %ManifestLiveboxesParser class. + */ + +#include +#include +#include +#include + +#include "ManifestLiveboxesParser.h" +#include "InstallerUtil.h" +#include "XmlAttribute.h" +#include "ManifestHandler.h" +#include "InstallationContextData.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::App::Package; +using namespace Tizen::Io; +using namespace Tizen::System; + +ManifestLiveboxesParser::ManifestLiveboxesParser(void) +:__pContext(null) +,__pLiveboxDataList(null) +,__pLiveboxData(null) +{ +} + +ManifestLiveboxesParser::~ManifestLiveboxesParser(void) +{ +} + +bool +ManifestLiveboxesParser::OnStartElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null"); + + bool status = true; + + if (strcasecmp(pName, "Liveboxes") == 0) + { + status = OnLiveboxesStartElement(); + } + else if (strcasecmp(pName, "Livebox") == 0) + { + status = OnLiveboxStartElement(); + } + + return status; +} + +bool +ManifestLiveboxesParser::OnEndElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null"); + + bool status = true; + + if (strcasecmp(pName, "Liveboxes") == 0) + { + status = OnLiveboxesEndElement(); + } + else if (strcasecmp(pName, "Livebox") == 0) + { + status = OnLiveboxEndElement(); + } + + return status; +} + +bool +ManifestLiveboxesParser::OnCharacters(const char *pCharacters) +{ + TryReturn(pCharacters, true, "[osp-installer] pCharacters is null"); + + bool status = true; + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + char *pName = pHandler->GetElementName(); + TryReturn(pName, false, "[osp-installer] pName is null"); + + if (strcasecmp(pName, "DisplayName") == 0) + { + status = OnDisplayNameValue(pCharacters); + } + else if (strcasecmp(pName, "Size") == 0) + { + status = OnSizeValue(pCharacters); + } + else if (strcasecmp(pName, "ConfigurationAppControlAppId") == 0) + { + status = OnConfigurationAppControlAppIdValue(pCharacters); + } + + return status; +} + +bool +ManifestLiveboxesParser::OnLiveboxesStartElement() +{ + ManifestHandler* __pHandler = GetHandler(); + TryReturn(__pHandler, false, "[osp-installer] __pHandler is null"); + + __pContext = __pHandler->GetContext(); + TryReturn(__pContext, false, "[osp-installer] __pContext is null"); + + __pLiveboxDataList = new (std::nothrow) ArrayList; + TryReturn(__pLiveboxDataList, false, "[osp-installer] __pLiveboxDataList is null"); + + AppLogTag(OSP_INSTALLER, " "); + + return true; +} + +bool +ManifestLiveboxesParser::OnLiveboxStartElement(void) +{ + XmlAttribute *pAttr = null; + + __pLiveboxData = new (std::nothrow) LiveboxData; + TryReturn(__pLiveboxData, false, "[osp-installer] __pLiveboxData is null"); + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + pAttr = pHandler->GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + AppLogTag(OSP_INSTALLER, " "); + + char *pProviderName = pAttr->Find("ProviderName"); + if (pProviderName) + { + __pLiveboxData->SetProviderName(pProviderName); + AppLogTag(OSP_INSTALLER, " - ProviderName=%s", pProviderName); + } + + char *pUpdatePeriod = pAttr->Find("UpdatePeriod"); + if (pUpdatePeriod) + { + long long updatePeriod = atoll(pUpdatePeriod); + __pLiveboxData->SetUpdatePeriod(updatePeriod); + AppLogTag(OSP_INSTALLER, " - UpdatePeriod=%lld", updatePeriod); + } + + char *pLiveboxPopupEnabled = pAttr->Find("LiveboxPopupEnabled"); + if (pLiveboxPopupEnabled) + { + __pLiveboxData->SetPopupEnabled(pLiveboxPopupEnabled); + AppLogTag(OSP_INSTALLER, " - LiveboxPopupEnabled=%s", pLiveboxPopupEnabled); + } + + char *pMain = pAttr->Find("Main"); + if (pMain) + { + __pLiveboxData->__main = pMain; + AppLogTag(OSP_INSTALLER, " - Main=%s", pMain); + } + + return true; +} + +bool +ManifestLiveboxesParser::OnLiveboxesEndElement(void) +{ + __pContext->SetLiveboxDataList(__pLiveboxDataList); + __pLiveboxDataList = null; + AppLogTag(OSP_INSTALLER, " "); + + return true; +} + +bool +ManifestLiveboxesParser::OnLiveboxEndElement(void) +{ + __pLiveboxDataList->Add(*__pLiveboxData); + __pLiveboxData = null; + AppLogTag(OSP_INSTALLER, " "); + + return true; +} + +bool +ManifestLiveboxesParser::OnSizeValue(const char *pCharacters) +{ + __pLiveboxData->AddSize(*(new (std::nothrow) String(pCharacters))); + + AppLogTag(OSP_INSTALLER, " %s", pCharacters); + return true; +} + +bool +ManifestLiveboxesParser::OnDisplayNameValue(const char *pCharacters) +{ + XmlAttribute* pAttr = 0; + char* pAttrValue = 0; + + ManifestHandler* pHandler = GetHandler(); + TryReturn(pHandler, false, "[osp-installer] pHandler is null"); + + pAttr = pHandler->GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pAttrValue = pAttr->Find("Locale"); + TryReturn(pAttrValue, true, "[osp-installer] pAttrValue is null"); + + String* pValue = new (std::nothrow) String; + StringUtil::Utf8ToString(pCharacters, *pValue); + __pLiveboxData->AddName(*(new (std::nothrow) String(pAttrValue)), *pValue); + + AppLogTag(OSP_INSTALLER, " %s", pCharacters); + + return true; +} + +bool +ManifestLiveboxesParser::OnConfigurationAppControlAppIdValue(const char* pCharacters) +{ + __pLiveboxData->__configurationAppControlAppId = pCharacters; + AppLogTag(OSP_INSTALLER, " %s", pCharacters); + + return true; +} diff --git a/src/XmlHandler/Parser/ManifestLiveboxesParser.h b/src/XmlHandler/Parser/ManifestLiveboxesParser.h new file mode 100755 index 0000000..ad61c64 --- /dev/null +++ b/src/XmlHandler/Parser/ManifestLiveboxesParser.h @@ -0,0 +1,70 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestLiveboxesParser.h + * @brief This is the header file for the %ManifestLiveboxesParser class. + * + * This header file contains the declarations of the %ManifestLiveboxesParser class. + */ +#ifndef _MANIFEST_LIVEBOXES_PARSER_H_ +#define _MANIFEST_LIVEBOXES_PARSER_H_ + +#include + +#include + +#include "ManifestParser.h" +#include "InstallationContext.h" + +/** + * @class ManifestLiveboxesParser + * @brief This class represents the class of ManifestLiveboxesParser. + * @since 1.0 + * + * This class represents the class of ManifestLiveboxesParser. + * + */ +class ManifestLiveboxesParser + : public ManifestParser +{ +public: + ManifestLiveboxesParser(void); + virtual ~ManifestLiveboxesParser(void); + + virtual bool OnStartElement(const char *pName); + virtual bool OnEndElement(const char *pName); + virtual bool OnCharacters(const char *pCharacters); + +private: + bool OnLiveboxesStartElement(void); + bool OnLiveboxStartElement(void); + + bool OnLiveboxesEndElement(void); + bool OnLiveboxEndElement(void); + + bool OnSizeValue(const char *pCharacters); + bool OnDisplayNameValue(const char *pCharacters); + bool OnConfigurationAppControlAppIdValue(const char* pCharacters); + +private: + InstallationContext* __pContext; + Tizen::Base::Collection::ArrayList* __pLiveboxDataList; + LiveboxData* __pLiveboxData; + +}; // ManifestLiveboxesParser + +#endif // _MANIFEST_LIVEBOXES_PARSER_H_ diff --git a/src/XmlHandler/Parser/ManifestParser.cpp b/src/XmlHandler/Parser/ManifestParser.cpp new file mode 100755 index 0000000..f5be175 --- /dev/null +++ b/src/XmlHandler/Parser/ManifestParser.cpp @@ -0,0 +1,77 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestParser.cpp + * @brief This is the implementation file for %ManifestParser class. + */ + +#include +#include +#include +#include + +#include "ManifestParser.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::App::Package; +using namespace Tizen::Io; +using namespace Tizen::System; + +ManifestParser::ManifestParser(void) +:__pManifestHandler(null) +{ +} + +ManifestParser::~ManifestParser(void) +{ +} + +bool +ManifestParser::Construct(ManifestHandler* pManifestHandler) +{ + __pManifestHandler = pManifestHandler; + + return true; +} + +ManifestHandler* +ManifestParser::GetHandler(void) +{ + return __pManifestHandler; +} + +bool +ManifestParser::OnStartElement(const char *pName) +{ + return true; +} + +bool +ManifestParser::OnEndElement(const char *pName) +{ + return true; +} + +bool +ManifestParser::OnCharacters(const char *pCharacters) +{ + return true; +} + diff --git a/src/XmlHandler/Parser/ManifestParser.h b/src/XmlHandler/Parser/ManifestParser.h new file mode 100755 index 0000000..2033d6f --- /dev/null +++ b/src/XmlHandler/Parser/ManifestParser.h @@ -0,0 +1,60 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ManifestParser.h + * @brief This is the header file for the %ManifestParser class. + * + * This header file contains the declarations of the %ManifestParser class. + */ +#ifndef _MANIFEST_PARSER_H_ +#define _MANIFEST_PARSER_H_ + +#include + +#include + +#include "InstallationContext.h" + +class ManifestHandler; + +/** + * @class ManifestParser + * @brief This class represents the class of ManifestParser. + * @since 1.0 + * + * This class represents the class of ManifestParser. + * + */ +class ManifestParser +{ +public: + ManifestParser(void); + virtual ~ManifestParser(void); + + bool Construct(ManifestHandler* pManifestHandler); + ManifestHandler* GetHandler(void); + + virtual bool OnStartElement(const char *pName); + virtual bool OnEndElement(const char *pName); + virtual bool OnCharacters(const char *pCharacters); + +private: + ManifestHandler* __pManifestHandler; + +}; // ManifestParser + +#endif // _MANIFEST_PARSER_H_ diff --git a/src/XmlHandler/PrivilegeHandler.cpp b/src/XmlHandler/PrivilegeHandler.cpp new file mode 100755 index 0000000..c570742 --- /dev/null +++ b/src/XmlHandler/PrivilegeHandler.cpp @@ -0,0 +1,406 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PrivilegeHandler.cpp + * @brief This is the implementation for the PrivilegeHandler class. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "InstallerDefs.h" +#include "PrivilegeHandler.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::Security; +using namespace Tizen::Security::Crypto; +using namespace Tizen::Text; + +result +PrivilegeHandler::GenerateCipherPrivilege(const AppId& appId, const IList& privilegeList, String& encryptedPrivileges, String& checksum) +{ + result r = E_SUCCESS; + byte* pBitwisePrivilege = null; + int count = 0; + + SysLog(NID_SEC, "Enter."); + + encryptedPrivileges.Clear(); + checksum.Clear(); + + count = privilegeList.GetCount(); + if (count == 0) + { + goto CATCH; + } + + pBitwisePrivilege = PackPrivilegeN(privilegeList); + SysTryReturnResult(NID_SEC, pBitwisePrivilege != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + r = GetEncryptedBitwise(pBitwisePrivilege, encryptedPrivileges); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + r = GetChecksum(appId, pBitwisePrivilege, checksum); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + // fall through + +CATCH: + + if (pBitwisePrivilege) + { + free(pBitwisePrivilege); + } + + SysLog(NID_SEC, "Exit."); + return r; +} + +result +PrivilegeHandler::GenerateCipherPrivilege(const AppId& appId, const IList& privilegeList, int visibilityLevel, String& encryptedPrivileges, String& checksum) +{ + result r = E_SUCCESS; + byte* pBitwisePrivilege = null; + int count = 0; + + SysLog(NID_SEC, "Enter."); + + encryptedPrivileges.Clear(); + checksum.Clear(); + + count = privilegeList.GetCount(); + if (count == 0) + { + goto CATCH; + } + + r = PackPrivilegeN(privilegeList, visibilityLevel, &pBitwisePrivilege); + SysTryReturnResult(NID_SEC, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + r = GetEncryptedBitwise(pBitwisePrivilege, encryptedPrivileges); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + r = GetChecksum(appId, pBitwisePrivilege, checksum); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + // fall through + +CATCH: + + if (pBitwisePrivilege) + { + free(pBitwisePrivilege); + } + + SysLog(NID_SEC, "Exit."); + return r; +} + +byte* +PrivilegeHandler::PackPrivilegeN(const IList& privilegeList) +{ + result r = E_SUCCESS; + int index = 0; + int privilegeEnum = 0; + int position = 0; + bool validStringFlag = false; + bool resultFlag = true; + byte privilegeBit = 0; + byte* pResult = null; + byte* pBitwisePrivilege = null; + IEnumerator* pEnum = null; + + SysLog(NID_SEC, "Enter."); + ClearLastResult(); + + pResult = (byte*) malloc(sizeof(byte) * MAX_BITWISE_PRIV_SIZE); + SysTryReturn(NID_SEC, pResult != null, null, E_OUT_OF_MEMORY, "The memory is insufficient."); + + memset(pResult, 0, MAX_BITWISE_PRIV_SIZE); + + pEnum = privilegeList.GetEnumeratorN(); + SysTryCatch(NID_SEC, pEnum != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + while (pEnum->MoveNext() == E_SUCCESS) + { + validStringFlag = false; + String privilegeURI = L"http://tizen.org/privilege/"; + + String* pTempString = (String*) pEnum->GetCurrent(); + + if ((pTempString->GetLength()) < (privilegeURI.GetLength())) + { + SysLogException(NID_SEC, E_INVALID_ARG, "[E_INVALID_ARG] Invalid privilege string : %ls", pTempString->GetPointer()); + AppLogTag(OSP_INSTALLER, "[Privilege] PackPrivilegeN(1): length error[%ls]", pTempString->GetPointer()); + resultFlag = false; + continue; + } + + String uriString; + pTempString->SubString(0, privilegeURI.GetLength(), uriString); + + if (!(uriString.Equals(privilegeURI, true))) + { + SysLogException(NID_SEC, E_INVALID_ARG, "[E_INVALID_ARG] Invalid privilege string : %ls", pTempString->GetPointer()); + AppLogTag(OSP_INSTALLER, "[Privilege] PackPrivilegeN(1): uri error[%ls]", pTempString->GetPointer()); + resultFlag = false; + continue; + } + + String privilegeString; + pTempString->SubString(privilegeURI.GetLength(), pTempString->GetLength()-privilegeURI.GetLength(), privilegeString); + + for (index = 0; index < _MAX_PRIVILEGE_ENUM; index++) + { + if (wcscmp(privilegeListTable[index].privilegeString, privilegeString.GetPointer()) == 0) + { + validStringFlag = true; + privilegeEnum = static_cast< int >(privilegeListTable[index].privilege); + + position = privilegeEnum / _BITS_IN_BYTE; + privilegeBit = (byte) (privilegeEnum % _BITS_IN_BYTE); + pResult[position] = pResult[position] | (1 << privilegeBit); + break; + } + } + + if (validStringFlag == false) + { + SysLogException(NID_SEC, E_INVALID_ARG, "[E_INVALID_ARG] Invalid privilege string : %ls", pTempString->GetPointer()); + AppLogTag(OSP_INSTALLER, "[Privilege] PackPrivilegeN(1): validStringFlag is false[%ls]", pTempString->GetPointer()); + resultFlag = false; + } + } + + SysTryCatch(NID_SEC, resultFlag == true, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] One of privilege string is invalid."); + + pBitwisePrivilege = pResult; + + delete pEnum; + + SysLog(NID_SEC, "Exit."); + return pBitwisePrivilege; + +CATCH: + + delete pEnum; + free(pResult); + + SysLog(NID_SEC, "Exit."); + return null; +} + +result +PrivilegeHandler::PackPrivilegeN(const IList& privilegeList, int visibilityLevel, byte** ppBitwisePrivilege) +{ + result r = E_SUCCESS; + int index = 0; + int privilegeEnum = 0; + int position = 0; + bool validStringFlag = false; + bool validLevelFlag = true; + bool resultFlag = true; + byte privilegeBit = 0; + byte* pResult = null; + IEnumerator* pEnum = null; + + SysLog(NID_SEC, "Enter."); + ClearLastResult(); + + pResult = (byte*) malloc(sizeof(byte) * MAX_BITWISE_PRIV_SIZE); + SysTryReturn(NID_SEC, pResult != null, null, E_OUT_OF_MEMORY, "The memory is insufficient."); + + memset(pResult, 0, MAX_BITWISE_PRIV_SIZE); + + pEnum = privilegeList.GetEnumeratorN(); + SysTryCatch(NID_SEC, pEnum != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + while (pEnum->MoveNext() == E_SUCCESS) + { + validStringFlag = false; + validLevelFlag = true; + + String privilegeURI = L"http://tizen.org/privilege/"; + + String* pTempString = (String*) pEnum->GetCurrent(); + + if ((pTempString->GetLength()) < (privilegeURI.GetLength())) + { + SysLogException(NID_SEC, E_INVALID_ARG, "[E_INVALID_ARG] Invalid privilege string : %ls", pTempString->GetPointer()); + AppLogTag(OSP_INSTALLER, "[Privilege] PackPrivilegeN(3): length error[%ls]", pTempString->GetPointer()); + resultFlag = false; + continue; + } + + String uriString; + pTempString->SubString(0, privilegeURI.GetLength(), uriString); + + if (!(uriString.Equals(privilegeURI, true))) + { + SysLogException(NID_SEC, E_INVALID_ARG, "[E_INVALID_ARG] Invalid privilege string : %ls", pTempString->GetPointer()); + AppLogTag(OSP_INSTALLER, "[Privilege] PackPrivilegeN(3): uri error[%ls]", pTempString->GetPointer()); + resultFlag = false; + continue; + } + + String privilegeString; + pTempString->SubString(privilegeURI.GetLength(), pTempString->GetLength()-privilegeURI.GetLength(), privilegeString); + + for (index = 0; index < _MAX_PRIVILEGE_ENUM; index++) + { + if (wcscmp(privilegeListTable[index].privilegeString, privilegeString.GetPointer()) == 0) + { + validStringFlag = true; + privilegeEnum = static_cast< int >(privilegeListTable[index].privilege); + + if (visibilityLevel != _API_VISIBILITY_NONE) + { + if (visibilityLevelListTable[privilegeEnum][_PRV_API_VER_2_0] > visibilityLevel) + { + validLevelFlag = false; + break; + } + } + + position = privilegeEnum / _BITS_IN_BYTE; + privilegeBit = (byte) (privilegeEnum % _BITS_IN_BYTE); + pResult[position] = pResult[position] | (1 << privilegeBit); + break; + } + } + + if (validStringFlag == false) + { + SysLogException(NID_SEC, E_INVALID_ARG, "[E_INVALID_ARG] Invalid privilege string : %ls", pTempString->GetPointer()); + AppLogTag(OSP_INSTALLER, "[Privilege] PackPrivilegeN(3): privilege string error[%ls]", pTempString->GetPointer()); + resultFlag = false; + } + + if (validLevelFlag == false) + { + SysLogException(NID_SEC, E_INVALID_ARG, "[E_INVALID_ARG] The application does not have the visibility to register %ls", pTempString->GetPointer()); + AppLogTag(OSP_INSTALLER, "[Privilege] PackPrivilegeN(3): validLevelFlag is false[%ls]", pTempString->GetPointer()); + resultFlag = false; + } + } + + SysTryCatch(NID_SEC, resultFlag == true, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] One of privilege string is invalid."); + + *ppBitwisePrivilege = pResult; + + delete pEnum; + + SysLog(NID_SEC, "Exit.");; + return r; + +CATCH: + + delete pEnum; + free(pResult); + + SysLog(NID_SEC, "Exit."); + return r; +} + + +result +PrivilegeHandler::GetEncryptedBitwise(byte* pBitwisePrivilege, String& encryptedPrivileges) +{ + result r = E_SUCCESS; + ByteBuffer* pTempBitwisePrivilege = null; + + SysLog(NID_SEC, "Enter."); + + pTempBitwisePrivilege = new (std::nothrow) ByteBuffer(); + SysTryReturnResult(NID_SEC, pTempBitwisePrivilege != null, E_OUT_OF_MEMORY, "Memory allocation is failed."); + + r = pTempBitwisePrivilege->Construct(MAX_BITWISE_PRIV_SIZE); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + r = pTempBitwisePrivilege->SetArray(pBitwisePrivilege, 0, MAX_BITWISE_PRIV_SIZE); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + pTempBitwisePrivilege->Flip(); + + r = StringUtil::EncodeToBase64String(*pTempBitwisePrivilege, encryptedPrivileges); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + // fall through + +CATCH: + + delete pTempBitwisePrivilege; + + SysLog(NID_SEC, "Exit."); + return r; +} + +result +PrivilegeHandler::GetChecksum(AppId appId, byte* pBitwisePrivilege, String& checksum) +{ + result r = E_SUCCESS; + byte tempChecksumString[MAX_BITWISE_PRIV_SIZE + MAX_APP_ID_SIZE]; + + ByteBuffer input; + IHash* pHash = null; + ByteBuffer* pChecksumByteBuffer = null; + char* pAppId = null; + + pAppId = (char*) _StringConverter::CopyToCharArrayN(appId); + SysTryCatch(NID_SEC, pAppId != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + memcpy(tempChecksumString, pAppId, MAX_APP_ID_SIZE); + memcpy(tempChecksumString + MAX_APP_ID_SIZE, pBitwisePrivilege, MAX_BITWISE_PRIV_SIZE); + + delete[] pAppId; + pAppId = null; + + r = input.Construct(MAX_APP_ID_SIZE + MAX_BITWISE_PRIV_SIZE); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + r = input.SetArray(tempChecksumString, 0, MAX_APP_ID_SIZE + MAX_BITWISE_PRIV_SIZE); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + input.Flip(); + + pHash = new (std::nothrow) Sha1Hash(); + SysTryCatch(NID_SEC, pHash != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed."); + + pChecksumByteBuffer = pHash->GetHashN(input); + SysTryCatch(NID_SEC, pChecksumByteBuffer != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + r = StringUtil::EncodeToBase64String(*pChecksumByteBuffer, checksum); + SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred."); + + // fall through + +CATCH: + + delete pHash; + delete pChecksumByteBuffer; + + return r; +} diff --git a/src/XmlHandler/PrivilegeHandler.h b/src/XmlHandler/PrivilegeHandler.h new file mode 100644 index 0000000..90373e6 --- /dev/null +++ b/src/XmlHandler/PrivilegeHandler.h @@ -0,0 +1,61 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PrivilegeHandler.h + * @brief This is the header file for the PrivilegeHandler class. + * + * This header file contains the declarations of the PrivilegeHandler class. + */ + +#ifndef _PRIVILEGE_HANDLER_H_ +#define _PRIVILEGE_HANDLER_H_ + +#include + +namespace Tizen { namespace Base { namespace Collection +{ +class IList; +}}} + +namespace Tizen { namespace Base +{ +class String; +}} + +/** + * @class PrivilegeHandler + * @brief This class represents the class of PrivilegeHandler. + * @since 2.1 + * + * This class represents the class of PrivilegeHandler. + * + */ +class PrivilegeHandler +{ + +public: + static result GenerateCipherPrivilege(const Tizen::App::AppId& appId, const Tizen::Base::Collection::IList& privilegeList, Tizen::Base::String& encryptedPrivileges, Tizen::Base::String& checksum); + static result GenerateCipherPrivilege(const Tizen::App::AppId& appId, const Tizen::Base::Collection::IList& privilegeList, int visibilityLevel, Tizen::Base::String& encryptedPrivileges, Tizen::Base::String& checksum); +private: + static byte* PackPrivilegeN(const Tizen::Base::Collection::IList& privilegeList); + static result PackPrivilegeN(const Tizen::Base::Collection::IList& privilegeList, int visibilityLevel, byte** ppBitwisePrivilege); + static result GetEncryptedBitwise(byte* __bitwisePrivilege, Tizen::Base::String& encryptedPrivileges); + static result GetChecksum(Tizen::App::AppId appId, byte* __bitwisePrivilege, Tizen::Base::String& checksum); + +}; // PrivilegeHandler + +#endif // _PRIVILEGE_HANDLER_H_ diff --git a/src/XmlHandler/SignatureHandler.cpp b/src/XmlHandler/SignatureHandler.cpp new file mode 100755 index 0000000..17cc465 --- /dev/null +++ b/src/XmlHandler/SignatureHandler.cpp @@ -0,0 +1,222 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SignatureHandler.cpp + * @brief This is the implementation file for %SignatureHandler class. + */ + +#include "SignatureHandler.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +SignatureHandler::SignatureHandler(void) +:__pContext(null) +,__pAuthorCertChain(null) +,__pDistributorCertChain(null) +,__isAuthorSignature(false) +,__isDistributorSignature(false) +{ +} + +SignatureHandler::~SignatureHandler(void) +{ + if (__pAuthorCertChain) + { + __pAuthorCertChain->RemoveAll(true); + delete __pAuthorCertChain; + } + + if (__pDistributorCertChain) + { + __pDistributorCertChain->RemoveAll(true); + delete __pDistributorCertChain; + } +} + +bool +SignatureHandler::Construct(InstallationContext* pContext) +{ + __pContext = pContext; + + return true; +} + +bool +SignatureHandler::Parse(const char *pFilepath) +{ + return ParseNormalizedDocument(pFilepath); +} + +bool +SignatureHandler::OnStartElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null."); + + bool status = true; + + if (strcasecmp(pName, "Signature") == 0) + { + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "signature.xml"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "<%s>", pName); + status = OnSignatureElement(); + } + + if (!status) + { + return false; + } + + return true; +} + +bool +SignatureHandler::OnEndElement(const char *pName) +{ + TryReturn(pName, true, "[osp-installer] pName is null."); + + if (strcasecmp(pName, "Signature") == 0) + { + __isDistributorSignature = false; + __isAuthorSignature = false; + AppLogTag(OSP_INSTALLER, "", pName); + } + + return true; +} + +bool +SignatureHandler::OnCharacters(const char *pCharacters) +{ + bool status = true; + char *pName = 0; + + pName = GetElementName(); + TryReturn(pName, false, "[osp-installer] pName is null."); + + if (strcasecmp(pName, "X509Certificate") == 0) + { + status = OnCertificateValue(pCharacters); + } + + if (!status) + { + return false; + } + + return true; +} + +bool +SignatureHandler::OnSignatureElement(void) +{ + XmlAttribute *pAttr = null; + char *pId = null; + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + pId = pAttr->Find("Id"); + if (pId) + { + AppLogTag(OSP_INSTALLER, "", pId); + + if (strcasecmp(pId, "AuthorSignature") == 0) + { + __isAuthorSignature = true; + } + else if (strcasecmp(pId, "DistributorSignature") == 0) + { + __isDistributorSignature = true; + } + } + + return true; +} + +bool +SignatureHandler::OnCertificateValue(const char *pCharacters) +{ + AppLogTag(OSP_INSTALLER, "%s", pCharacters); + + result r = E_SUCCESS; + bool res = true; + ByteBuffer* pByteBuffer = null; + + if (__isAuthorSignature == true) + { + if (__pAuthorCertChain == null) + { + __pAuthorCertChain = new (std::nothrow) ArrayList; + TryCatch(__pAuthorCertChain, res = false, "[osp-installer] __pAuthorCertChain is null"); + } + + pByteBuffer = new (std::nothrow) ByteBuffer; + TryCatch(pByteBuffer, res = false, "[osp-installer] pByteBuffer is null"); + + int length = strlen(pCharacters); + pByteBuffer->Construct(length); + + r = pByteBuffer->SetArray((byte*)pCharacters, 0, length); + TryCatch(!IsFailed(r), res = false, "[osp-installer] SetArray() is failed."); + + pByteBuffer->Flip(); + + __pAuthorCertChain->Add(*pByteBuffer); + pByteBuffer = null; + } + else if (__isDistributorSignature == true) + { + if (__pDistributorCertChain == null) + { + __pDistributorCertChain = new (std::nothrow) ArrayList; + TryCatch(__pDistributorCertChain, res = false, "[osp-installer] __pDistributorCertChain is null"); + } + + pByteBuffer = new (std::nothrow) ByteBuffer; + TryCatch(pByteBuffer, res = false, "[osp-installer] pByteBuffer is null"); + + int length = strlen(pCharacters); + pByteBuffer->Construct(length); + + r = pByteBuffer->SetArray((byte*)pCharacters, 0, length); + TryCatch(!IsFailed(r), res = false, "[osp-installer] SetArray() is failed."); + + pByteBuffer->Flip(); + + __pDistributorCertChain->Add(*pByteBuffer); + pByteBuffer = null; + } + +CATCH: + delete pByteBuffer; + return res; +} + +ArrayList* +SignatureHandler::GetAuthorCertChain(void) +{ + return __pAuthorCertChain; +} + +ArrayList* +SignatureHandler::GetDistributorCertChain(void) +{ + return __pDistributorCertChain; +} diff --git a/src/XmlHandler/SignatureHandler.h b/src/XmlHandler/SignatureHandler.h new file mode 100644 index 0000000..6078fba --- /dev/null +++ b/src/XmlHandler/SignatureHandler.h @@ -0,0 +1,72 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SignatureHandler.h + * @brief This is the header file for the %SignatureHandler class. + * + * This header file contains the declarations of the %SignatureHandler class. + */ +#ifndef _SIGNATURE_HANDLER_H_ +#define _SIGNATURE_HANDLER_H_ + +#include "XmlHandler.h" +#include "InstallationContext.h" + +/** + * @class SignatureHandler + * @brief This class represents the class of SignatureHandler. + * @since 1.0 + * + * This class represents the class of SignatureHandler. + * + */ +class SignatureHandler + : public XmlHandler +{ +public: + SignatureHandler(void); + virtual ~SignatureHandler(void); + + bool Construct(InstallationContext *pConext); + bool Parse(const char *pFilepath); + + Tizen::Base::Collection::ArrayList* GetAuthorCertChain(void); + Tizen::Base::Collection::ArrayList* GetDistributorCertChain(void); + +private: + SignatureHandler(const SignatureHandler& value); + SignatureHandler& operator =(const SignatureHandler& source); + + virtual bool OnStartElement(const char *pName); + virtual bool OnEndElement(const char *pName); + virtual bool OnCharacters(const char *pCharacters); + + bool OnSignatureElement(void); + bool OnCertificateValue(const char *pCharacters); + + +private: + InstallationContext* __pContext; + Tizen::Base::Collection::ArrayList* __pAuthorCertChain; + Tizen::Base::Collection::ArrayList* __pDistributorCertChain; + bool __isAuthorSignature; + bool __isDistributorSignature; + + +}; // SignatureHandler + +#endif // _SIGNATURE_HANDLER_H_ diff --git a/src/XmlHandler/XmlAttribute.cpp b/src/XmlHandler/XmlAttribute.cpp new file mode 100755 index 0000000..61e8ee1 --- /dev/null +++ b/src/XmlHandler/XmlAttribute.cpp @@ -0,0 +1,116 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file XmlAttribute.cpp + * @brief This is the implementation file for %XmlAttribute class. + */ + +#include +#include + +#include +#include + +#include "InstallerDefs.h" +#include "XmlAttribute.h" + +XmlAttribute::XmlAttribute(void) +:__pName(null) +,__pValue(null) +,__pNext(null) +{ +} + +XmlAttribute::~XmlAttribute(void) +{ + delete[] __pName; + delete[] __pValue; + delete __pNext; +} + +bool +XmlAttribute::Construct(const char *pName, const char *pValue) +{ + if (pName == 0 || pValue == 0) + { + return true; + } + + __pName = new (std::nothrow) char[strlen(pName)+1]; + TryReturn(__pName, false, "[osp-installer] __pName is null"); + strcpy(__pName, pName); + + __pValue = new (std::nothrow) char[strlen(pValue)+1]; + TryReturn(__pValue, false, "[osp-installer] __pValue is null"); + strcpy(__pValue, pValue); + + return true; +} + +char* +XmlAttribute::Find(const char *pName) +{ + if (pName == 0) + { + return null; + } + + if (__pName == 0 || __pValue == 0) + { + return null; + } + + if (strcasecmp(pName, __pName) == 0) + { + return __pValue; + } + + if (__pNext) + { + return __pNext->Find(pName); + } + + return null; +} + +bool +XmlAttribute::Add(const char *pName, const char *pValue) +{ + if (pName == 0 || pValue == 0) + { + return true; + } + + if (__pNext) + { + XmlAttribute *pNext = __pNext; + while (pNext->__pNext) + { + pNext = pNext->__pNext; + } + return pNext->Add(pName, pValue); + } + else + { + __pNext = new (std::nothrow) XmlAttribute(); + TryReturn(__pNext, false, "[osp-installer] __pNext is null"); + + __pNext->Construct(pName, pValue); + } + + return true; +} diff --git a/src/XmlHandler/XmlAttribute.h b/src/XmlHandler/XmlAttribute.h new file mode 100755 index 0000000..b35daac --- /dev/null +++ b/src/XmlHandler/XmlAttribute.h @@ -0,0 +1,54 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file XmlAttribute.h + * @brief This is the header file for the %XmlAttribute class. + * + * This header file contains the declarations of the %XmlAttribute class. + */ +#ifndef _XML_ATTRIBUTE_H_ +#define _XML_ATTRIBUTE_H_ + +/** + * @class XmlAttribute + * @brief This class represents the class of XmlAttribute. + * @since 1.0 + * + * This class represents the class of XmlAttribute. + * + */ +class XmlAttribute +{ +public: + XmlAttribute(void); + bool Construct(const char *pName, const char *pValue); + virtual ~XmlAttribute(void); + + char* Find(const char *pName); + bool Add(const char *pName, const char *pValue); + +private: + XmlAttribute(const XmlAttribute& value); + XmlAttribute& operator =(const XmlAttribute& source); + + char* __pName; + char* __pValue; + XmlAttribute* __pNext; + +}; // XmlAttribute + +#endif // _XML_ATTRIBUTE_H_ diff --git a/src/XmlHandler/XmlHandler.cpp b/src/XmlHandler/XmlHandler.cpp new file mode 100755 index 0000000..d36ec2e --- /dev/null +++ b/src/XmlHandler/XmlHandler.cpp @@ -0,0 +1,472 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file XmlHandler.cpp + * @brief This is the implementation file for %XmlHandler class. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "InstallerDefs.h" +#include "XmlHandler.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +XmlHandler::XmlHandler(void) +:__pAttr(null) +,__pElementName(null) +,__pCharacters(null) +,__error(false) +{ +} + +XmlHandler::~XmlHandler(void) +{ + delete[] __pElementName; + __pElementName = null; + + delete __pAttr; + __pAttr = null; +} + +bool +XmlHandler::OnStartDocument(void) +{ + AppLogTag(OSP_INSTALLER, "OnStartDocument()"); + return true; +} + +bool +XmlHandler::OnEndDocument(void) +{ + AppLogTag(OSP_INSTALLER, "OnEndDocument()"); + return true; +} + +bool +XmlHandler::OnStartElement(const char *pName) +{ + AppLogTag(OSP_INSTALLER, "OnStartElement()"); + return true; +} + +bool +XmlHandler::OnEndElement(const char *pName) +{ + AppLogTag(OSP_INSTALLER, "OnEndElement()"); + + return true; +} + +bool +XmlHandler::OnCharacters(const char *pCharacters) +{ + AppLogTag(OSP_INSTALLER, "OnCharacters()"); + return true; +} + +void +XmlHandler::StartElement(void *ctx, const xmlChar *name, const xmlChar **atts) +{ + XmlHandler *pHandler = null; + pHandler = (XmlHandler *)ctx; + bool xmlResult = false; + + if (name == 0) + { + return; + } + + pHandler->SetElementName((const char *)name); + // AppLogTag(OSP_INSTALLER, "<%s>", (const char*)name); + + if (atts) + { + XmlAttribute *pAttr = 0; + + if (atts[0] != null && atts[1] != null) + { + pAttr = new (std::nothrow) XmlAttribute(); + TryReturnVoid(pAttr, "pAttr is null"); + pAttr->Construct((const char *)atts[0], (const char *)atts[1]); + + // log + //if (atts[0][0] && atts[1][0]) + //{ + // AppLogTag(OSP_INSTALLER, "%s=\"%s\"", (const char*)atts[0], (const char*)atts[1]); + //} + + atts = &atts[2]; + } + + while (atts != null && atts[0] != null && atts[1] != null) + { + pAttr->Add((const char *)atts[0], (const char *)atts[1]); + + // log + //if (atts[0][0] && atts[1][0]) + //{ + // AppLogTag(OSP_INSTALLER, "%s=\"%s\"", (const char*)atts[0], (const char*)atts[1]); + //} + + atts = &atts[2]; + } + + pHandler->SetAttribute(pAttr); + } + + xmlResult = pHandler->OnStartElement((const char *)name); + if (xmlResult == false) + { + pHandler->SetError(); + } +} + +void +XmlHandler::EndElement(void *ctx, const xmlChar *name) +{ + XmlHandler *pHandler = null; + pHandler = (XmlHandler *)ctx; + bool xmlResult = false; + char* pCharacters = pHandler->GetCharacters(); + + if (pCharacters && (strlen(pCharacters) > 0)) + { + xmlResult = pHandler->OnCharacters(pCharacters); + if (xmlResult == false) + { + pHandler->SetError(); + } + } + + xmlResult = pHandler->OnEndElement((const char *)name); + if (xmlResult == false) + { + pHandler->SetError(); + } + + // AppLogTag(OSP_INSTALLER, "", name); + + pHandler->DeleteElement(); + pHandler->DeleteAttribute(); + pHandler->DeleteCharacters(); +} + +void +XmlHandler::Characters(void *ctx, const xmlChar *ch, int len) +{ + TryReturnVoid(ch, "ch is null."); + + XmlHandler* pHandler = null; + pHandler = (XmlHandler*)ctx; + char* pCharacters = null; + + if (ch[0] == 0x20 || ch[0] == 0x09 || ch[0] == 0x0D || ch[0] == 0x0A) + { + return; + } + + pCharacters = new (std::nothrow) char[len+1]; + TryReturnVoid(pCharacters, "pCharacters is null."); + + strncpy(pCharacters, (const char *)ch, len); + pCharacters[len] = 0; + + pHandler->SetCharacters(pCharacters); + + // AppLogTag(OSP_INSTALLER, "%s", pCharacters); + delete[] pCharacters; +} + +bool +XmlHandler::ParseDocument(const char *pFilepath) +{ + xmlSAXHandler *pSAXHandler = null; + xmlParserCtxtPtr ctxt = 0; + bool ret = true; + File file; + FileAttributes attr; + result r = E_SUCCESS; + char* pBuf = null; + int size = 0; + int readSize = 0; + + r = file.Construct(pFilepath, L"r"); + TryCatch(r == E_SUCCESS, ret = false, "[osp-installer] file.Construct is failed. [%s]", pFilepath); + + r = file.GetAttributes(pFilepath, attr); + TryCatch(IsFailed(r) == false, ret = false, "[osp-installer] file.GetAttributes is failed. [%s]", pFilepath); + + size = (int)attr.GetFileSize(); + TryCatch(size > 0, ret = false, "[osp-installer] size is invalid. [%s]", pFilepath); + + pBuf = new (std::nothrow) char[size+1]; + TryCatch(pBuf, ret = false, "[osp-installer] pBuf is null"); + + memset(pBuf, 0, size+1); + + readSize = file.Read(pBuf, size); + TryCatch(readSize > 0, ret = false, "[osp-installer] file.Read is failed. [%s][%d]", pFilepath, readSize); + + ctxt = xmlCreateMemoryParserCtxt(pBuf, size+1); + TryCatch(ctxt, ret = false, "[osp-installer] invalid xml file, %s", pFilepath); + + pSAXHandler = new (std::nothrow) xmlSAXHandler; + TryCatch(pSAXHandler, ret = false, "[osp-installer] pSAXHandler is null"); + memset(pSAXHandler, 0, sizeof(xmlSAXHandler)); + + ctxt->userData = (void *)this; + + pSAXHandler->startElement = XmlHandler::StartElement; + pSAXHandler->endElement = XmlHandler::EndElement; + pSAXHandler->characters = XmlHandler::Characters; + + ctxt->sax = pSAXHandler; + + xmlParseDocument(ctxt); + xmlFreeParserCtxt(ctxt); + + TryCatch(GetError() != true, ret = false, "[osp-installer] xml parsing error is occurred."); + +CATCH: + delete[] pBuf; + + return ret; +} + +bool +XmlHandler::ParseNormalizedDocument(const char* pFilepath) +{ + xmlSAXHandler *pSAXHandler = null; + xmlParserCtxtPtr ctxt = 0; + bool ret = true; + File file; + FileAttributes attr; + result r = E_SUCCESS; + char* pBuf = null; + char* pNormalizedBuf = null; + int size = 0; + int normalizedSize = 0; + int readSize = 0; + + r = file.Construct(pFilepath, L"r"); + TryCatch(r == E_SUCCESS, ret = false, "[osp-installer] file.Construct is failed. [%s]", pFilepath); + + r = file.GetAttributes(pFilepath, attr); + TryCatch(IsFailed(r) == false, ret = false, "[osp-installer] file.GetAttributes is failed. [%s]", pFilepath); + + size = (int)attr.GetFileSize(); + TryCatch(size > 0, ret = false, "[osp-installer] size is invalid. [%s]", pFilepath); + + pBuf = new (std::nothrow) char[size+1]; + TryCatch(pBuf, ret = false, "[osp-installer] pBuf is null"); + + pNormalizedBuf = new (std::nothrow) char[size+1]; + TryCatch(pNormalizedBuf, ret = false, "[osp-installer] pNormalizedBuf is null"); + + memset(pBuf, 0, size+1); + memset(pNormalizedBuf, 0, size+1); + + readSize = file.Read(pBuf, size); + TryCatch(readSize > 0, ret = false, "[osp-installer] file.Read is failed. [%s][%d]", pFilepath, readSize); + + normalizedSize = Normalize(pBuf, size, pNormalizedBuf); + TryCatch(normalizedSize > 0, ret = false, "[osp-installer] normalizedSize [%d]", readSize); + + ctxt = xmlCreateMemoryParserCtxt(pNormalizedBuf, normalizedSize); + TryCatch(ctxt, ret = false, "[osp-installer] invalid xml file, %s", pFilepath); + + pSAXHandler = new (std::nothrow) xmlSAXHandler; + TryCatch(pSAXHandler, ret = false, "[osp-installer] pSAXHandler is null"); + memset(pSAXHandler, 0, sizeof(xmlSAXHandler)); + + ctxt->userData = (void *)this; + + pSAXHandler->startElement = XmlHandler::StartElement; + pSAXHandler->endElement = XmlHandler::EndElement; + pSAXHandler->characters = XmlHandler::Characters; + + ctxt->sax = pSAXHandler; + + xmlParseDocument(ctxt); + xmlFreeParserCtxt(ctxt); + + TryCatch(GetError() != true, ret = false, "[osp-installer] xml parsing error is occurred."); + +CATCH: + delete[] pBuf; + delete[] pNormalizedBuf; + + return ret; +} + +int +XmlHandler::Normalize(const char* pBuf, int size, char* pNormalizedBuf) +{ + int idx = 0; + int normalizedIdx = 0; + + while (pBuf[idx] && idx < size) + { + if (pBuf[idx] == 0x0D) + { + if (pBuf[idx + 1] == 0x0A) + { + idx++; + } + pNormalizedBuf[normalizedIdx] = 0x0A; + normalizedIdx++; + } + else if((pBuf[idx] == 0X0A) && (pBuf[idx + 1] == 0x4d) && (pBuf[idx - 1] == 0x3E)) + { + //AppLogTag(OSP_INSTALLER, "[pBuf = %s]", pBuf); + idx++; + pNormalizedBuf[normalizedIdx] = pBuf[idx]; + normalizedIdx++; + } + else + { + pNormalizedBuf[normalizedIdx] = pBuf[idx]; + normalizedIdx++; + } + + idx++; + } + + return normalizedIdx; +} + +bool +XmlHandler::SetElementName(const char *pElementName) +{ + TryReturn(pElementName, false, "[osp-installer] pElementName is null"); + + if (__pElementName) + { + delete[] __pElementName; + __pElementName = null; + } + + __pElementName = new (std::nothrow) char[strlen(pElementName)+1]; + TryReturn(__pElementName, false, "[osp-installer] __pElementName is null"); + strcpy(__pElementName, pElementName); + + __elementStack.Push(*new (std::nothrow) String(pElementName)); + + return true; +} + +char* +XmlHandler::GetElementName(void) +{ + return __pElementName; +} + +void +XmlHandler::DeleteElement(void) +{ + delete[]__pElementName; + __pElementName = 0; + + __elementStack.Pop(); +} + +bool +XmlHandler::SetCharacters(const char* pCharacter) +{ + TryReturn(pCharacter, false, "[osp-installer] pCharacter is null"); + + if (__pCharacters == null) + { + __pCharacters = new (std::nothrow) char[4096]; + TryReturn(__pCharacters, false, "[osp-installer] __pCharacters is null"); + + memset(__pCharacters, 0, 4096); + } + + strncat(__pCharacters, pCharacter, strlen(pCharacter)); + + return true; +} + +char* +XmlHandler::GetCharacters(void) +{ + return __pCharacters; +} + +void +XmlHandler::DeleteCharacters(void) +{ + delete[] __pCharacters; + __pCharacters = null; +} + +void +XmlHandler::SetAttribute(XmlAttribute *pAttr) +{ + __pAttr = pAttr; +} + +XmlAttribute* +XmlHandler::GetAttribute(void) +{ + return __pAttr; +} + +void +XmlHandler::DeleteAttribute(void) +{ + delete __pAttr; + __pAttr = null; +} + +IEnumerator* +XmlHandler::GetElementEnumeratorN(void) +{ + return __elementStack.GetEnumeratorN(); +} + +int +XmlHandler::GetElementCount(void) +{ + return __elementStack.GetCount(); +} + +void +XmlHandler::SetError(void) +{ + __error = true; +} + +bool +XmlHandler::GetError(void) +{ + return __error; +} + diff --git a/src/XmlHandler/XmlHandler.h b/src/XmlHandler/XmlHandler.h new file mode 100755 index 0000000..8d3c6bd --- /dev/null +++ b/src/XmlHandler/XmlHandler.h @@ -0,0 +1,106 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file XmlHandler.h + * @brief This is the header file for the %XmlHandler class. + * + * This header file contains the declarations of the %XmlHandler class. + */ +#ifndef _XML_HANDLER_H_ +#define _XML_HANDLER_H_ + +#include + +#include + +#include "XmlAttribute.h" + +namespace Tizen { namespace Base { namespace Collection +{ +class IEnumerator; +}}} + +/** + * @class XmlHandler + * @brief This class represents the class of XmlHandler. + * @since 1.0 + * + * This class represents the class of XmlHandler. + * + */ +class XmlHandler +{ +public: + XmlHandler(void); + bool Construct(void); + virtual ~XmlHandler(void); + + virtual bool OnStartDocument(void); + virtual bool OnEndDocument(void); + virtual bool OnStartElement(const char *pName); + virtual bool OnEndElement(const char *pName); + virtual bool OnCharacters(const char *pCharacters); + // virtual bool OnXmlDecl(char *version, char *encoding, char *standalone, CXmlElement* pElement); + // virtual bool OnPi(char *pi, char *ins, CXmlElement* pElement); + // virtual bool OnDocType(char *name, char *docType, CXmlElement* pElement); + // virtual bool OnComment(char *comment, CXmlElement* pElement); + // virtual bool OnCData(char *data, CXmlElement* pElement); + + void SetError(void); + bool GetError(void); + + char* GetElementName(void); + XmlAttribute* GetAttribute(void); + Tizen::Base::Collection::IEnumerator* GetElementEnumeratorN(void); + int GetElementCount(void); + +protected: + bool ParseDocument(const char *pFilepath); + bool ParseNormalizedDocument(const char* pFilepath); + + int Normalize(const char* pBuf, int size, char* pNormalizedBuf); + + bool SetElementName(const char *pElementName); + void DeleteElement(void); + + bool SetCharacters(const char* pCharacter); + char* GetCharacters(void); + void DeleteCharacters(void); + + void SetAttribute(XmlAttribute *pAttr); + void DeleteAttribute(void); + +private: + XmlHandler(const XmlHandler& value); + XmlHandler& operator =(const XmlHandler& source); + + static void StartDocument(void *ctx); + static void EndDocument(void *ctx); + static void StartElement(void *ctx, const xmlChar *name, const xmlChar **atts); + static void EndElement(void *ctx, const xmlChar *name); + static void Characters(void *ctx, const xmlChar *ch, int len); + + XmlAttribute* __pAttr; + char* __pElementName; + char* __pCharacters; + Tizen::Base::Collection::Stack __elementStack; + + bool __error; + +}; // XmlHandler + +#endif // _XML_HANDLER_H_ diff --git a/src/XmlHandler/XmlWriter.cpp b/src/XmlHandler/XmlWriter.cpp new file mode 100755 index 0000000..0cf3512 --- /dev/null +++ b/src/XmlHandler/XmlWriter.cpp @@ -0,0 +1,200 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file XmlWriter.cpp + * @brief This is the implementation file for %XmlWriter class. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "InstallerDefs.h" +#include "XmlWriter.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::Io; + +XmlWriter::XmlWriter(void) +:__pXmlWriter(null), __pXmlBuffer(null) +{ +} + +XmlWriter::~XmlWriter(void) +{ + result r = E_SUCCESS; + int err = 0; + + err = xmlTextWriterEndDocument(__pXmlWriter); + if (err == -1) + { + AppLogTag(OSP_INSTALLER, "xmlTextWriterEndDocument() is failed(%d)", err); + } + + File file; + r = file.Construct(__xmlFilePath, "w"); + if (IsFailed(r)) + { + AppLogTag(OSP_INSTALLER, "file.Construct() failed, __xmlFilePath=[%ls]", __xmlFilePath.GetPointer()); + } + else + { + r = file.Write((char *)__pXmlBuffer->content, __pXmlBuffer->use); + if (IsFailed(r)) + { + AppLogTag(OSP_INSTALLER, "file.Write() failed, __xmlFilePath=[%ls]", __xmlFilePath.GetPointer()); + } + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "%ls is generated", __xmlFilePath.GetPointer()); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + // AppLogTag(OSP_INSTALLER, "%s", __pXmlBuffer->content); + // InstallerUtil::DumpLog((const char*)__pXmlBuffer->content); + } + + if (__pXmlWriter) + { + xmlFreeTextWriter(__pXmlWriter); + } + + if (__pXmlBuffer) + { + xmlBufferFree(__pXmlBuffer); + } +} + +bool +XmlWriter::Construct(const Tizen::Base::String& filepath) +{ + bool res = false; + int err = 0; + + // __pXmlBuffer = xmlBufferCreate(); + __pXmlBuffer = xmlBufferCreateSize(4096*10); + TryCatch(__pXmlBuffer, res = false, "[osp-installer] __pXmlBuffer is null"); + + __xmlFilePath = filepath; + + __pXmlWriter = xmlNewTextWriterMemory(__pXmlBuffer, 0); + TryCatch(__pXmlWriter, res = false, "[osp-installer] __pXmlWriter is null"); + + xmlTextWriterSetIndent(__pXmlWriter, 1); + + err = xmlTextWriterStartDocument(__pXmlWriter, null, null, null); + TryCatch(err == 0, res = false, "[osp-installer] err is %d", err); + + return true; +CATCH: + + if (__pXmlWriter) + { + xmlFreeTextWriter(__pXmlWriter); + __pXmlWriter = null; + } + + if (__pXmlBuffer) + { + xmlBufferFree(__pXmlBuffer); + __pXmlBuffer = null; + } + + return res; +} + +bool +XmlWriter::StartElement(const Tizen::Base::String& name) +{ + ByteBuffer* pNameBuf = null; + int err = 0; + bool res = true; + + pNameBuf = StringUtil::StringToUtf8N(name); + if (pNameBuf) + { + err = xmlTextWriterStartElement(__pXmlWriter, (xmlChar *)pNameBuf->GetPointer()); + if (err != 0) + { + res = false; + } + } + + delete pNameBuf; + return res; +} + +bool +XmlWriter::WriteAttribute(const Tizen::Base::String& name, const Tizen::Base::String& content) +{ + ByteBuffer* pNameBuf = null; + ByteBuffer* pContentBuf = null; + int err = 0; + bool res = true; + + pNameBuf = StringUtil::StringToUtf8N(name); + pContentBuf = StringUtil::StringToUtf8N(content); + + if (pNameBuf && pContentBuf) + { + err = xmlTextWriterWriteAttribute(__pXmlWriter, (xmlChar *)pNameBuf->GetPointer(), (xmlChar *)pContentBuf->GetPointer()); + if (err != 0) + { + res = false; + } + } + + delete pNameBuf; + delete pContentBuf; + return res; +} + +bool +XmlWriter::WriteString(const Tizen::Base::String& content) +{ + ByteBuffer* pContentBuf = null; + int err = 0; + bool res = true; + + pContentBuf = StringUtil::StringToUtf8N(content); + if (pContentBuf) + { + err = xmlTextWriterWriteString(__pXmlWriter, (xmlChar *)pContentBuf->GetPointer()); + if (err != 0) + { + res = false; + } + } + + delete pContentBuf; + return res; +} + +bool +XmlWriter::EndElement(void) +{ + xmlTextWriterEndElement(__pXmlWriter); + return true; +} + diff --git a/src/XmlHandler/XmlWriter.h b/src/XmlHandler/XmlWriter.h new file mode 100644 index 0000000..5754ffe --- /dev/null +++ b/src/XmlHandler/XmlWriter.h @@ -0,0 +1,62 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file XmlWriter.h + * @brief This is the header file for the %XmlWriter class. + * + * This header file contains the declarations of the %XmlWriter class. + */ +#ifndef _XML_WRITER_H_ +#define _XML_WRITER_H_ + +// #include +#include + +#include "XmlAttribute.h" + +/** + * @class XmlWriter + * @brief This class represents the class of XmlWriter. + * @since 1.0 + * + * This class represents the class of XmlWriter. + * + */ +class XmlWriter +{ +public: + XmlWriter(void); + virtual ~XmlWriter(void); + bool Construct(const Tizen::Base::String& filepath); + + bool StartElement(const Tizen::Base::String& name); + bool WriteAttribute(const Tizen::Base::String& name, const Tizen::Base::String& content); + bool WriteString(const Tizen::Base::String& content); + bool EndElement(void); + +private: + XmlWriter(const XmlWriter& value); + XmlWriter& operator =(const XmlWriter& source); + + // bool __error; + xmlTextWriterPtr __pXmlWriter; + xmlBufferPtr __pXmlBuffer; + Tizen::Base::String __xmlFilePath; + +}; // XmlWriter + +#endif // _XML_WRITER_H_ diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp new file mode 100755 index 0000000..ad38402 --- /dev/null +++ b/src/backend/backend.cpp @@ -0,0 +1,258 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file backend.cpp + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "InstallerManager.h" +#include "InstallerDefs.h" +#include "InstallerUtil.h" + +using namespace Tizen::Base; + +extern "C" void Osp_Initialize(); +static bool __osp_installer_report_result(const String& appId, int errorType); + +static pkgmgr_installer *_pi = null; + +int +main(int argc, char **argv) +{ + int ret = 0; + const char *pkg_info = NULL; + char* pkg_path = NULL; + String path; + String appId; + int errorType = 0; + InstallerManager manager; + pkgmgr_installer *pi = null; + int req_type = 0; + + Osp_Initialize(); + + AppLogTag(OSP_INSTALLER, "--\n\n\n"); + AppLogTag(OSP_INSTALLER, "=========================================="); + AppLogTag(OSP_INSTALLER, " # %s", OSP_INSTALLER_VERSION); + AppLogTag(OSP_INSTALLER, " # argc = %d", argc); + + if (argc == TEST_ARG_COUNT) + { + errorType = manager.ReqeustByTest(); + manager.PrintResult(); + goto CATCH; + } + else if (argc == COMMAND_ARG_COUNT) + { + errorType = manager.RequestByCommand(argc, argv); + goto CATCH; + } + + pi = pkgmgr_installer_new(); + _pi = pi; + + pkgmgr_installer_receive_request(pi, argc, argv); + + req_type = pkgmgr_installer_get_request_type(pi); + if (PKGMGR_REQ_INVALID >= req_type) + { + goto CATCH; + } + + pkg_info = pkgmgr_installer_get_request_info(pi); + pkg_path = (const_cast(pkg_info)); + AppLogTag(OSP_INSTALLER, " # path = [%s]", pkg_path); + + path = pkg_path; + + switch (req_type) + { + case PKGMGR_REQ_INSTALL: + { + errorType = manager.Request(path, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL); + appId = manager.GetId(); + if (_pi != 0) + { + char resultBuf[128] = {0}; + snprintf(resultBuf, sizeof(resultBuf), "%ls", appId.GetPointer()); + pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "install"); + } + else + { + AppLogTag(OSP_INSTALLER, "_pi is null"); + } + +// if (errorType != 0) +// { +// manager.RemoveGarbage(path); +// } + + __osp_installer_report_result(appId, errorType); + manager.PrintResult(); + } + break; + + case PKGMGR_REQ_UNINSTALL: + { + String requestAppId; + + if (path.Contains(PACKAGE_NAME_PREFIX_ORG) == true) + { + String prefixPackage(PACKAGE_NAME_PREFIX_ORG); + path.SubString(prefixPackage.GetLength(), APPID_LENGTH, requestAppId); + } + else + { + path.SubString(0, APPID_LENGTH, requestAppId); + } + + AppLogTag(OSP_INSTALLER, "requestAppId = %ls", requestAppId.GetPointer()); + ret = manager.Request(requestAppId, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL); + appId = manager.GetId(); + + if (_pi != 0) + { + char resultBuf[128] = {0}; + snprintf(resultBuf, sizeof(resultBuf), "%ls", appId.GetPointer()); + pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "uninstall"); + } + else + { + AppLogTag(OSP_INSTALLER, "_pi is null"); + } + + __osp_installer_report_result(appId, errorType); + manager.PrintResult(); + } + break; + + case PKGMGR_REQ_MOVE: + { + if (_pi != 0) + { + int moveType = -1; + moveType = pkgmgr_installer_get_move_type(_pi); + + manager.RequestMove(path, moveType); + } + else + { + AppLog("_pi is null"); + } + + } + break; + + default: + ret = -1; + break; + } + + if (ret == -1) + { + goto CATCH; + } + +CATCH: + return errorType; +} + +bool +__osp_installer_send_error(int errorType) +{ + char errorMsg[11] = {0}; + int error = 0; + + if (errorType >= INSTALLER_ERROR_USER_CANCEL) + { + error = INSTALLER_ERROR_FATAL_ERROR; + } + + snprintf(errorMsg, sizeof(errorMsg) - 1, "%d", error); + pkgmgr_installer_send_signal(_pi, "tpk", "", "error", errorMsg); + + return true; +} + +bool +__osp_installer_report_result(const String& appId, int errorType) +{ + int ret = 0; + char resultBuf[128] = {0}; + InstallerManager manager; + const char* pPkgType = "tpk"; + const char* pKey = "end"; + const char* pValue = null; + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "osp_installer_report_result"); + AppLogTag(OSP_INSTALLER, " # request_type = [%d]", pkgmgr_installer_get_request_type(_pi)); + AppLogTag(OSP_INSTALLER, " # request_info = [%s]", pkgmgr_installer_get_request_info(_pi)); + AppLogTag(OSP_INSTALLER, " # session_id = [%s]", pkgmgr_installer_get_session_id(_pi)); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + if (_pi == 0) + { + AppLogTag(OSP_INSTALLER, "_pi is null"); + return false; + } + + if (errorType == 0) + { + if (appId.IsEmpty() == true) + { + snprintf(resultBuf, sizeof(resultBuf), "0000000000"); + } + else + { + snprintf(resultBuf, sizeof(resultBuf), "%ls", appId.GetPointer()); + } + + pValue = "ok"; + } + else + { + snprintf(resultBuf, sizeof(resultBuf), "0000000000"); + pValue = "fail"; + __osp_installer_send_error(errorType); + } + + ret = pkgmgr_installer_send_signal(_pi, pPkgType, resultBuf, pKey, pValue); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "pkgmgr_installer_send_signal"); + AppLogTag(OSP_INSTALLER, " # type = [%s]", pPkgType); + AppLogTag(OSP_INSTALLER, " # pkg id = [%s]", resultBuf); + AppLogTag(OSP_INSTALLER, " # key = [%s]", pKey); + AppLogTag(OSP_INSTALLER, " # val = [%s]", pValue); + AppLogTag(OSP_INSTALLER, " # ret = [%s]", (ret == 0)?"success":"failure"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + pkgmgr_installer_free(_pi); + _pi = null; + + return true; +}