upload tizen1.0 source
authorKim Kibum <kb0929.kim@samsung.com>
Sun, 29 Apr 2012 08:01:39 +0000 (17:01 +0900)
committerKim Kibum <kb0929.kim@samsung.com>
Sun, 29 Apr 2012 08:01:39 +0000 (17:01 +0900)
58 files changed:
CMakeLists.txt [new file with mode: 0644]
LICENSE [new file with mode: 0644]
backend-lib/CMakeLists.txt [new file with mode: 0755]
backend-lib/inc/libdebinternals.h [new file with mode: 0755]
backend-lib/src/Makefile [new file with mode: 0755]
backend-lib/src/libdeb.c [new file with mode: 0755]
backend-lib/src/libdebinternals.c [new file with mode: 0755]
backend/CMakeLists.txt [new file with mode: 0755]
backend/inc/nativeinstaller.h [new file with mode: 0755]
backend/scripts/audit_spk.sh.in [new file with mode: 0755]
backend/scripts/extract_manifest.sh.in [new file with mode: 0755]
backend/scripts/find_package.sh.in [new file with mode: 0755]
backend/scripts/install_spk.sh.in [new file with mode: 0755]
backend/scripts/uninstall_spk.sh.in [new file with mode: 0755]
backend/scripts/update_avail_spk.sh.in [new file with mode: 0755]
backend/src/core/nativeinstallercore.c [new file with mode: 0755]
backend/src/core/nativeinstallertool.c [new file with mode: 0755]
backend/src/dpkg/nativeinstallerdpkg.c [new file with mode: 0755]
backend/src/parser/nativeinstallermanifestparser.c [new file with mode: 0755]
backend/src/vconf/nativebackendvconfintf.c [new file with mode: 0755]
common/CMakeLists.txt [new file with mode: 0755]
common/NativeInstallerUtil.c [new file with mode: 0755]
debian/changelog [new file with mode: 0755]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0755]
debian/control.slp [new file with mode: 0755]
debian/desktop.slp [new file with mode: 0644]
debian/dirs [new file with mode: 0644]
debian/docs [new file with mode: 0644]
debian/native-installer-dbg.postinst [new file with mode: 0755]
debian/native-installer.install.in [new file with mode: 0755]
debian/native-installer.postinst [new file with mode: 0755]
debian/rules [new file with mode: 0755]
frontend/CMakeLists.txt [new file with mode: 0755]
frontend/audit_spk.sh [new file with mode: 0755]
frontend/extract_manifest.sh [new file with mode: 0755]
frontend/find_package.sh [new file with mode: 0755]
frontend/inc/frontend.h [new file with mode: 0755]
frontend/install_spk.sh [new file with mode: 0755]
frontend/src/frontendappcoreintf.c [new file with mode: 0755]
frontend/src/frontendcmdline.c [new file with mode: 0755]
frontend/ui/include/frontendhomeview.h [new file with mode: 0755]
frontend/ui/layout/c-empty.edc [new file with mode: 0755]
frontend/ui/po/CMakeLists.txt [new file with mode: 0755]
frontend/ui/po/POTFILES.in [new file with mode: 0755]
frontend/ui/po/update-po.sh [new file with mode: 0755]
frontend/ui/res/icon/image_editor_button_cancel.png [new file with mode: 0755]
frontend/ui/res/locale/CMakeLists.txt [new file with mode: 0755]
frontend/ui/res/locale/en_GB.po [new file with mode: 0755]
frontend/ui/res/locale/en_US.po [new file with mode: 0755]
frontend/ui/res/locale/ja_JP.po [new file with mode: 0755]
frontend/ui/res/locale/ko_KR.po [new file with mode: 0755]
frontend/ui/res/locale/zh_CN.po [new file with mode: 0755]
frontend/ui/src/frontendhomeview.c [new file with mode: 0755]
frontend/uninstall_spk.sh [new file with mode: 0755]
frontend/update_avail_spk.sh [new file with mode: 0755]
inc/native_installer_util.h [new file with mode: 0755]
packaging/native-installer.spec [new file with mode: 0755]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9d99b2c
--- /dev/null
@@ -0,0 +1,21 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+
+PROJECT(native-installer C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 1.0)
+
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+##################
+## build comm libraries
+add_subdirectory(common)
+#add_subdirectory(backend)
+add_subdirectory(frontend)
+add_subdirectory(backend-lib)
+##################
+
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..9c13a9b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+                                 Apache License\r
+                           Version 2.0, January 2004\r
+                        http://www.apache.org/licenses/\r
+\r
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+   1. Definitions.\r
+\r
+      "License" shall mean the terms and conditions for use, reproduction,\r
+      and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+      "Licensor" shall mean the copyright owner or entity authorized by\r
+      the copyright owner that is granting the License.\r
+\r
+      "Legal Entity" shall mean the union of the acting entity and all\r
+      other entities that control, are controlled by, or are under common\r
+      control with that entity. For the purposes of this definition,\r
+      "control" means (i) the power, direct or indirect, to cause the\r
+      direction or management of such entity, whether by contract or\r
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+      outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+      "You" (or "Your") shall mean an individual or Legal Entity\r
+      exercising permissions granted by this License.\r
+\r
+      "Source" form shall mean the preferred form for making modifications,\r
+      including but not limited to software source code, documentation\r
+      source, and configuration files.\r
+\r
+      "Object" form shall mean any form resulting from mechanical\r
+      transformation or translation of a Source form, including but\r
+      not limited to compiled object code, generated documentation,\r
+      and conversions to other media types.\r
+\r
+      "Work" shall mean the work of authorship, whether in Source or\r
+      Object form, made available under the License, as indicated by a\r
+      copyright notice that is included in or attached to the work\r
+      (an example is provided in the Appendix below).\r
+\r
+      "Derivative Works" shall mean any work, whether in Source or Object\r
+      form, that is based on (or derived from) the Work and for which the\r
+      editorial revisions, annotations, elaborations, or other modifications\r
+      represent, as a whole, an original work of authorship. For the purposes\r
+      of this License, Derivative Works shall not include works that remain\r
+      separable from, or merely link (or bind by name) to the interfaces of,\r
+      the Work and Derivative Works thereof.\r
+\r
+      "Contribution" shall mean any work of authorship, including\r
+      the original version of the Work and any modifications or additions\r
+      to that Work or Derivative Works thereof, that is intentionally\r
+      submitted to Licensor for inclusion in the Work by the copyright owner\r
+      or by an individual or Legal Entity authorized to submit on behalf of\r
+      the copyright owner. For the purposes of this definition, "submitted"\r
+      means any form of electronic, verbal, or written communication sent\r
+      to the Licensor or its representatives, including but not limited to\r
+      communication on electronic mailing lists, source code control systems,\r
+      and issue tracking systems that are managed by, or on behalf of, the\r
+      Licensor for the purpose of discussing and improving the Work, but\r
+      excluding communication that is conspicuously marked or otherwise\r
+      designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+      "Contributor" shall mean Licensor and any individual or Legal Entity\r
+      on behalf of whom a Contribution has been received by Licensor and\r
+      subsequently incorporated within the Work.\r
+\r
+   2. Grant of Copyright License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      copyright license to reproduce, prepare Derivative Works of,\r
+      publicly display, publicly perform, sublicense, and distribute the\r
+      Work and such Derivative Works in Source or Object form.\r
+\r
+   3. Grant of Patent License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      (except as stated in this section) patent license to make, have made,\r
+      use, offer to sell, sell, import, and otherwise transfer the Work,\r
+      where such license applies only to those patent claims licensable\r
+      by such Contributor that are necessarily infringed by their\r
+      Contribution(s) alone or by combination of their Contribution(s)\r
+      with the Work to which such Contribution(s) was submitted. If You\r
+      institute patent litigation against any entity (including a\r
+      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+      or a Contribution incorporated within the Work constitutes direct\r
+      or contributory patent infringement, then any patent licenses\r
+      granted to You under this License for that Work shall terminate\r
+      as of the date such litigation is filed.\r
+\r
+   4. Redistribution. You may reproduce and distribute copies of the\r
+      Work or Derivative Works thereof in any medium, with or without\r
+      modifications, and in Source or Object form, provided that You\r
+      meet the following conditions:\r
+\r
+      (a) You must give any other recipients of the Work or\r
+          Derivative Works a copy of this License; and\r
+\r
+      (b) You must cause any modified files to carry prominent notices\r
+          stating that You changed the files; and\r
+\r
+      (c) You must retain, in the Source form of any Derivative Works\r
+          that You distribute, all copyright, patent, trademark, and\r
+          attribution notices from the Source form of the Work,\r
+          excluding those notices that do not pertain to any part of\r
+          the Derivative Works; and\r
+\r
+      (d) If the Work includes a "NOTICE" text file as part of its\r
+          distribution, then any Derivative Works that You distribute must\r
+          include a readable copy of the attribution notices contained\r
+          within such NOTICE file, excluding those notices that do not\r
+          pertain to any part of the Derivative Works, in at least one\r
+          of the following places: within a NOTICE text file distributed\r
+          as part of the Derivative Works; within the Source form or\r
+          documentation, if provided along with the Derivative Works; or,\r
+          within a display generated by the Derivative Works, if and\r
+          wherever such third-party notices normally appear. The contents\r
+          of the NOTICE file are for informational purposes only and\r
+          do not modify the License. You may add Your own attribution\r
+          notices within Derivative Works that You distribute, alongside\r
+          or as an addendum to the NOTICE text from the Work, provided\r
+          that such additional attribution notices cannot be construed\r
+          as modifying the License.\r
+\r
+      You may add Your own copyright statement to Your modifications and\r
+      may provide additional or different license terms and conditions\r
+      for use, reproduction, or distribution of Your modifications, or\r
+      for any such Derivative Works as a whole, provided Your use,\r
+      reproduction, and distribution of the Work otherwise complies with\r
+      the conditions stated in this License.\r
+\r
+   5. Submission of Contributions. Unless You explicitly state otherwise,\r
+      any Contribution intentionally submitted for inclusion in the Work\r
+      by You to the Licensor shall be under the terms and conditions of\r
+      this License, without any additional terms or conditions.\r
+      Notwithstanding the above, nothing herein shall supersede or modify\r
+      the terms of any separate license agreement you may have executed\r
+      with Licensor regarding such Contributions.\r
+\r
+   6. Trademarks. This License does not grant permission to use the trade\r
+      names, trademarks, service marks, or product names of the Licensor,\r
+      except as required for reasonable and customary use in describing the\r
+      origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+   7. Disclaimer of Warranty. Unless required by applicable law or\r
+      agreed to in writing, Licensor provides the Work (and each\r
+      Contributor provides its Contributions) on an "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+      implied, including, without limitation, any warranties or conditions\r
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+      PARTICULAR PURPOSE. You are solely responsible for determining the\r
+      appropriateness of using or redistributing the Work and assume any\r
+      risks associated with Your exercise of permissions under this License.\r
+\r
+   8. Limitation of Liability. In no event and under no legal theory,\r
+      whether in tort (including negligence), contract, or otherwise,\r
+      unless required by applicable law (such as deliberate and grossly\r
+      negligent acts) or agreed to in writing, shall any Contributor be\r
+      liable to You for damages, including any direct, indirect, special,\r
+      incidental, or consequential damages of any character arising as a\r
+      result of this License or out of the use or inability to use the\r
+      Work (including but not limited to damages for loss of goodwill,\r
+      work stoppage, computer failure or malfunction, or any and all\r
+      other commercial damages or losses), even if such Contributor\r
+      has been advised of the possibility of such damages.\r
+\r
+   9. Accepting Warranty or Additional Liability. While redistributing\r
+      the Work or Derivative Works thereof, You may choose to offer,\r
+      and charge a fee for, acceptance of support, warranty, indemnity,\r
+      or other liability obligations and/or rights consistent with this\r
+      License. However, in accepting such obligations, You may act only\r
+      on Your own behalf and on Your sole responsibility, not on behalf\r
+      of any other Contributor, and only if You agree to indemnify,\r
+      defend, and hold each Contributor harmless for any liability\r
+      incurred by, or claims asserted against, such Contributor by reason\r
+      of your accepting any such warranty or additional liability.\r
+\r
+   END OF TERMS AND CONDITIONS\r
+\r
+   APPENDIX: How to apply the Apache License to your work.\r
+\r
+      To apply the Apache License to your work, attach the following\r
+      boilerplate notice, with the fields enclosed by brackets "[]"\r
+      replaced with your own identifying information. (Don't include\r
+      the brackets!)  The text should be enclosed in the appropriate\r
+      comment syntax for the file format. We also recommend that a\r
+      file or class name and description of purpose be included on the\r
+      same "printed page" as the copyright notice for easier\r
+      identification within third-party archives.\r
+\r
+   Copyright [yyyy] [name of copyright owner]\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
diff --git a/backend-lib/CMakeLists.txt b/backend-lib/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..65605a6
--- /dev/null
@@ -0,0 +1,49 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+#Verbose
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc )
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED dbus-glib-1 pkgmgr-types )
+#pkg_check_modules(pkgs REQUIRED pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util )
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(libpkgs REQUIRED dbus-glib-1 pkgmgr-types)
+
+FOREACH(flag ${libpkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server pkgmgr-types)
+
+link_directories (${STATUS_LIBRARY_DIRS})
+include_directories (${STATUS_INCLUDE_DIRS})
+
+SET(backend_lib_dir "${CMAKE_CURRENT_SOURCE_DIR}")
+SET(backend_lib_inc_dir "${backend_lib_dir}/include")
+SET(backend_lib_c_src_dir "${backend_lib_dir}/src")
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+###################################################################################################
+## for backend_lib (binary)
+SET(backend_lib_SOURCES ${backend_lib_c_src_dir}/libdebinternals.c ${backend_lib_c_src_dir}/libdeb.c)
+#SET(backend_lib_SOURCES ${backend_lib_c_src_dir}/libdeb.c ${backend_lib_c_src_dir}/libdebinternals.c)
+SET(backend_lib_CFLAGS " -I. -I${backend_lib_inc_dir} ${pkg_CFLAGS}")
+SET(backend_lib_LDFLAGS ${pkgs_LDFLAGS})
+
+ADD_LIBRARY(deb SHARED ${backend_lib_SOURCES})
+SET_TARGET_PROPERTIES(deb PROPERTIES COMPILE_FLAGS "${backend_lib_CFLAGS}")
+####################################################################################################
+
+INSTALL(TARGETS deb DESTINATION etc/package-manager/backendlib/ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE )
+
+####################################################################################################
+
+
diff --git a/backend-lib/inc/libdebinternals.h b/backend-lib/inc/libdebinternals.h
new file mode 100755 (executable)
index 0000000..9901cfc
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+  
+#include <package-manager-plugin.h>
+#include <unistd.h>
+#include <vconf.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+#define API __attribute__ ((visibility("default")))
+#define DEBUG_ERR      0x0001
+#define DEBUG_INFO     0x0002
+#define DEBUG_RESULT   0x0004
+#define LIBDEB_LOG     1
+#define LIBDEB_SUCCESS 0
+#define LIBDEB_ERROR   -1
+#define PKGMETAINFO    "/var/lib/dpkg/available"
+#define BLOCK_SIZE      4096 /*in bytes*/
+
+#define LIKELY(expr) __builtin_expect((expr), 1)
+#define UNLIKELY(expr) __builtin_expect((expr), 0)
+
+void _libdeb_print_msg(int type, int exetype, char *format, ...);
+#define _libdeb_print(type, fmtstr, args...) { \
+_libdeb_print_msg(type, LIBDEB_LOG, "%s():%d: " fmtstr, \
+__func__, __LINE__, ##args); \
+}
+
+int _libdeb_xsystem(const char *argv[]);
+char *_libdeb_substring(const char *str, size_t begin, size_t len);
+char *_libdeb_get_filename(const char *packagefilepath);
+int _libdeb_fill_pkginfo_from_control_file(package_manager_pkg_detail_info_t
+                                          *pkg_detail_info, char *line);
+int _libdeb_fill_pkginfo_from_desktop_file(package_manager_pkg_detail_info_t
+                                          *pkg_detail_info, char *line);
+int _libdeb_populate_control_info(const char *pkgname,
+                                 package_manager_pkg_detail_info_t
+                                 *pkg_detail_info, char *controlfilepath);
+int _libdeb_populate_desktop_info(package_manager_pkg_detail_info_t
+                                 *pkg_detail_info, char *desktopfilepath);
+long long _libdeb_calculate_dir_size(char *dirname);
+
+#ifdef __cplusplus
+}
+#endif                 /* __cplusplus */
diff --git a/backend-lib/src/Makefile b/backend-lib/src/Makefile
new file mode 100755 (executable)
index 0000000..b214d64
--- /dev/null
@@ -0,0 +1,4 @@
+all:
+       gcc -g -Wall -fPIC -shared -I../inc -o libdeb.so libdeb.c libdebinternals.c
+clean:
+       rm -rf libdeb.so
diff --git a/backend-lib/src/libdeb.c b/backend-lib/src/libdeb.c
new file mode 100755 (executable)
index 0000000..bf809ab
--- /dev/null
@@ -0,0 +1,317 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+#include "libdebinternals.h"
+
+#define EXTRACT_MENIFEST                       "/usr/bin/extract_manifest.sh"
+#define FIND_PACKAGE                           "/usr/bin/find_package.sh"
+#define MANIFEST_FILE_NAME                     "control"
+#define BASEDIR                                                "/opt/share"
+#define THIRD_PARTY_DESKTOP_FILE_PATH \
+       BASEDIR"/install-info/application"
+#define INHOUSE_DESKTOP_FILE_PATH \
+       BASEDIR"/applications"
+#define BUFFSIZE                                               256
+
+void pkg_native_plugin_on_unload(void)
+{
+       return;
+}
+
+int pkg_plugin_app_is_installed(const char *pkg_name)
+{
+       FILE *fp = NULL;
+       char *lineptr = NULL;
+       size_t len = 512;
+       ssize_t read;
+       char buff[512] = { 0, };
+       /* Check for valid arguments */
+       if (pkg_name == NULL) {
+               _libdeb_print
+                   (DEBUG_ERR,
+                    "[pkg_plugin_app_is_installed] pkg_name is NULL\n");
+               return LIBDEB_ERROR;
+       }
+       fp = fopen(PKGMETAINFO, "r");
+       if (fp == NULL) {
+               _libdeb_print(DEBUG_ERR,
+                             "failed to open file(%s)\n", PKGMETAINFO);
+               return LIBDEB_ERROR;
+       }
+       snprintf(buff, 512, "Package: %s", pkg_name);
+       /*allocate memory for lineptr. If it is less
+          getline will realloc it */
+       lineptr = (char *)malloc(sizeof(char)*512);
+       if(lineptr == NULL) {
+               _libdeb_print(DEBUG_ERR,
+                             "malloc failed\n");
+               fclose(fp);
+               return LIBDEB_ERROR;
+       }
+       memset(lineptr, 0x00, sizeof(char)*512);
+       clearerr(fp);
+       do {
+               read = getline(&lineptr, &len, fp);
+               if (read == -1) {
+                       if (feof(fp)) {
+                               _libdeb_print(DEBUG_ERR, "EOF reached" 
+                               "Package not installed\n");
+                       }
+                       else     {
+                               _libdeb_print(DEBUG_ERR, "getline failed\n");
+                       }
+                       fclose(fp);
+                       return LIBDEB_ERROR;
+               }
+               if (lineptr && (strncmp(lineptr, buff, strlen(buff)) == 0) &&
+                           (strlen(lineptr) == strlen(buff) + 1)) {
+                               _libdeb_print
+                                       (DEBUG_INFO,
+                                            "[pkg_plugin_app_is_installed] "
+                                            "package is installed\n");
+                       fclose(fp);     
+                       return LIBDEB_SUCCESS;
+                       } else {
+                               if (lineptr)
+                                       memset(lineptr, 0x00, len);
+                               continue;
+                       }
+       } while (lineptr != NULL);
+       fclose(fp);
+       _libdeb_print(DEBUG_INFO,"[pkg_plugin_app_is_installed] "
+                       "package is not installed\n");
+       return LIBDEB_ERROR;
+
+}
+
+int pkg_plugin_get_installed_apps_list(const char *category,
+                                      const char *option,
+                                      package_manager_pkg_info_t **list,
+                                      int *count)
+{
+       return LIBDEB_SUCCESS;
+}
+
+int pkg_plugin_get_app_detail_info(const char *pkg_name,
+                                  package_manager_pkg_detail_info_t
+                                  *pkg_detail_info)
+{
+       _libdeb_print(DEBUG_INFO,
+                     "pkg_plugin_get_app_detail_info() is called\n");
+       /* Check for valid arguments */
+       if (pkg_name == NULL || pkg_detail_info == NULL) {
+               _libdeb_print(DEBUG_ERR,
+                             "[pkg_plugin_get_app_detail_info_from_package] "
+                             "args supplied is NULL\n");
+               return LIBDEB_ERROR;
+       }
+       char dirname[BUFFSIZE] = { '\0' };
+       int ret = 0;
+       long long data_size = 0;
+       char buff[256] = {'\0'};
+       time_t install_time = 0;
+       
+       /*As Installed Size field is optional, it may not be present in control file.
+       So Initialize it to 0. If present it will be populated with app_size*/
+       pkg_detail_info->app_size = 0;
+               
+       /* pkgtype is by default deb */
+       strncpy(pkg_detail_info->pkg_type, "deb", sizeof(pkg_detail_info->pkg_type));
+
+       /* Populate the structure now */
+
+       /*get data_size*/
+       snprintf(dirname, BUFFSIZE-1, "/opt/apps/%s/data", pkg_name);
+       data_size = _libdeb_calculate_dir_size(dirname);
+       if (data_size < 0) {
+               _libdeb_print(DEBUG_ERR,
+                               "Calculate dir size failed\n");
+               pkg_detail_info->data_size = 0 ;
+       }
+       else {
+               data_size += BLOCK_SIZE; /* the function does not adds 4096 
+                                       bytes for the directory size itself*/
+               pkg_detail_info->data_size = data_size/1024 ;
+       }
+       ret = _libdeb_populate_control_info(pkg_name, pkg_detail_info,
+                                           PKGMETAINFO);
+       if (ret) {
+               _libdeb_print(DEBUG_ERR,
+                             "[pkg_plugin_get_app_detail_info] "
+                             "_libdeb_populate_control_info returns %d\n",
+                             ret);
+               return LIBDEB_ERROR;
+       }
+
+       /* Min Platform Version */
+       pkg_detail_info->min_platform_version[0] = '\0';
+
+       /* Optional ID*/
+       pkg_detail_info->optional_id[0] = '\0';
+
+       /* Total Installed Size*/
+       pkg_detail_info->installed_size = pkg_detail_info->app_size + 
+                                                                       pkg_detail_info->data_size;
+       /* Installed Time*/
+       snprintf(buff, 256, "db/app-info/%s/installed-time", pkg_name);
+       ret = vconf_get_int(buff, (int *)&install_time);
+       if (ret) {
+               _libdeb_print(DEBUG_ERR, "get installed time failed\n");
+               pkg_detail_info->installed_time = 0;
+       }
+       else
+               pkg_detail_info->installed_time = install_time;
+
+       
+       return LIBDEB_SUCCESS;
+}
+
+int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
+                                       package_manager_pkg_detail_info_t
+                                       *pkg_detail_info)
+{
+       _libdeb_print(DEBUG_INFO,
+                     "pkg_plugin_get_app_detail_info_from_package() is called\n");
+       
+       /* Check for valid arguments */
+       if (pkg_path == NULL || pkg_detail_info == NULL) {
+               _libdeb_print(DEBUG_ERR,
+                             "[pkg_plugin_get_app_detail_info_from_package]"
+                             "args supplied is NULL\n");
+               return LIBDEB_ERROR;
+       }
+
+       const char *argv[] = { EXTRACT_MENIFEST, pkg_path, NULL };
+       int ret = 0;
+       long long data_size = 0;
+       char *pkg_filename = NULL;
+       char *str = NULL;
+       char controlfilepath[BUFFSIZE] = { '\0' };
+       char dirname[BUFFSIZE] = { '\0' };
+       char buff[256] = {'\0'};
+       time_t install_time = 0;
+       
+       /* populate pkg type */
+       str = strrchr(pkg_path, 46);    /* 46 is ASCII for . */
+       strncpy(pkg_detail_info->pkg_type, (str + 1), strlen(str + 1));
+
+       /* extract the control file from the deb package */
+       ret = _libdeb_xsystem(argv);
+       if (ret != 0) {
+               _libdeb_print(DEBUG_ERR,
+                             "[pkg_plugin_get_app_detail_info_from_package] "
+                             "xsystem returns %d\n", ret);
+               return LIBDEB_ERROR;
+       }
+
+       /* Extract file name from file path */
+       pkg_filename = _libdeb_get_filename(pkg_path);
+       if (!pkg_filename) {
+               _libdeb_print(DEBUG_ERR,
+                             "[pkg_plugin_get_app_detail_info_from_package] "
+                             " _libdeb_get_filename returns %s\n",
+                             pkg_filename);
+               return LIBDEB_ERROR;
+       }
+       snprintf(controlfilepath, BUFFSIZE - 1, "/var/pkgmgr/%s/metainfo/%s",
+               pkg_filename, MANIFEST_FILE_NAME);
+       if (pkg_filename) {
+               free(pkg_filename);
+               pkg_filename = NULL;
+       }
+       ret =
+           _libdeb_populate_control_info(NULL, pkg_detail_info,
+                                         controlfilepath);
+       if (ret) {
+               _libdeb_print(DEBUG_ERR,
+                             "[pkg_plugin_get_app_detail_info_from_package] "
+                             " _libdeb_populate_control_info returns %d\n",
+                             ret);
+               return LIBDEB_ERROR;
+       }
+
+       
+       /*get data_size. If pkg is not installed it will be 0*/
+       snprintf(dirname, BUFFSIZE-1, "/opt/apps/%s/data", 
+                               pkg_detail_info->pkg_name);
+       
+        data_size = _libdeb_calculate_dir_size(dirname);
+        if (data_size < 0) {
+                _libdeb_print(DEBUG_ERR,
+                                "Calculate dir size failed\n");
+                pkg_detail_info->data_size = 0 ;
+        }
+        else {
+               data_size += BLOCK_SIZE; /* the function does not adds 4096 
+                                        bytes for the directory size itself*/
+
+                pkg_detail_info->data_size = data_size/1024 ;
+        }
+
+       /* Min Platform Version */
+       pkg_detail_info->min_platform_version[0] = '\0';
+
+       /* Optional ID*/
+       pkg_detail_info->optional_id[0] = '\0';
+
+       /* Total Installed Size*/
+       pkg_detail_info->installed_size = pkg_detail_info->app_size + 
+                                                                       pkg_detail_info->data_size;
+
+       /* Installed Time */
+       snprintf(buff, 256, "db/app-info/%s/installed-time", pkg_detail_info->pkg_name);
+       ret = vconf_get_int(buff, (int *)&install_time);
+       if (ret) {
+               _libdeb_print(DEBUG_ERR, "get installed time failed\n");
+               pkg_detail_info->installed_time = 0;
+       }
+       else
+               pkg_detail_info->installed_time = install_time;
+       
+
+       return LIBDEB_SUCCESS;
+}
+
+API int pkg_plugin_on_load(pkg_plugin_set *set)
+{
+       if (set == NULL) {
+               return LIBDEB_ERROR;
+       }
+
+       memset(set, 0x00, sizeof(pkg_plugin_set));
+
+       set->plugin_on_unload = pkg_native_plugin_on_unload;
+       set->pkg_is_installed = pkg_plugin_app_is_installed;
+       set->get_installed_pkg_list = pkg_plugin_get_installed_apps_list;
+       set->get_pkg_detail_info = pkg_plugin_get_app_detail_info;
+       set->get_pkg_detail_info_from_package =
+           pkg_plugin_get_app_detail_info_from_package;
+
+       return LIBDEB_SUCCESS;
+}
diff --git a/backend-lib/src/libdebinternals.c b/backend-lib/src/libdebinternals.c
new file mode 100755 (executable)
index 0000000..40d2b36
--- /dev/null
@@ -0,0 +1,445 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <regex.h>
+#include <dlog.h>
+#include "libdebinternals.h"
+
+/* This is backend lib's filter string for dlogutil*/
+#define LOCAL_LOG_TAG   "libdeb"
+int logging = 0x0004;
+#ifdef LOG_IN_FILE
+#define NATIVE_INSTALLER_LIBDEB_LOG_FILE "/tmp/libdeb"
+FILE *logfile = NULL;
+#endif
+
+void _libdeb_print_msg(int type, int exetype, char *format, ...)
+{
+       char buffer[FILENAME_MAX] = { 0 };
+       char tbuffer[FILENAME_MAX] = { 0 };
+
+       int nbuffer;
+       va_list args;
+       va_start(args, format);
+       nbuffer = vsnprintf(tbuffer, FILENAME_MAX, format, args);
+       va_end(args);
+
+       switch (type) {
+       case DEBUG_ERR:
+               LOG(LOG_ERROR, LOCAL_LOG_TAG, tbuffer);
+               break;
+       case DEBUG_RESULT:
+               LOG(LOG_WARN, LOCAL_LOG_TAG, tbuffer);
+               break;
+       case DEBUG_INFO:
+               LOG(LOG_DEBUG, LOCAL_LOG_TAG, tbuffer);
+       default:
+               break;
+       }
+
+       if (logging == 0)
+               return;
+
+       if (DEBUG_ERR == (logging & type)) {
+               nbuffer = snprintf(buffer, FILENAME_MAX, "ERROR:%s", tbuffer);
+               vfprintf(stderr, format, args);
+       } else if (DEBUG_INFO == (logging & type)) {
+               nbuffer = snprintf(buffer, FILENAME_MAX, "INFO:%s", tbuffer);
+               vfprintf(stdout, format, args);
+       } else if (DEBUG_RESULT == (logging & type)) {
+               nbuffer = snprintf(buffer, FILENAME_MAX, "RESULT:%s", tbuffer);
+               vfprintf(stdout, format, args);
+       } else {
+               return;
+       }
+
+#ifdef LOG_IN_FILE
+       if (logfile != NULL)
+               fwrite(buffer, sizeof(char), strlen(buffer), logfile);
+#endif                         /*LOG_IN_FILE */
+}
+
+int _libdeb_xsystem(const char *argv[])
+{
+       int status = 0;
+       pid_t pid;
+       pid = vfork();
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return LIBDEB_ERROR;
+       case 0:
+               /* child */
+               execvp(argv[0], (char *const *)argv);
+               _exit(-1);
+       default:
+               /* parent */
+               break;
+       }
+
+       _libdeb_print(DEBUG_INFO, "parent\n");
+       if (waitpid(pid, &status, 0) == -1) {
+               perror("waitpid failed");
+               return LIBDEB_ERROR;
+       }
+
+       if (WIFSIGNALED(status)) {
+               perror("signal");
+               return LIBDEB_ERROR;
+       }
+
+       if (!WIFEXITED(status)) {
+               /* shouldn't happen */
+               perror("should not happen");
+               return LIBDEB_ERROR;
+       }
+
+       return WEXITSTATUS(status);
+}
+
+char *_libdeb_substring(const char *str, size_t begin, size_t len)
+{
+       if (str == 0 || strlen(str) == 0 || strlen(str) < begin ||
+           strlen(str) < (begin + len))
+               return LIBDEB_SUCCESS;
+       return strndup(str + begin, len);
+}
+
+char *_libdeb_get_filename(const char *packagefilepath)
+{
+       regex_t re;
+       regmatch_t mached[5];
+       int ret = 0;
+       char *package_file_name = NULL;
+       if (packagefilepath == NULL) {
+               _libdeb_print(DEBUG_ERR,
+                             "[_libdeb_get_filename] invalid arguments\n");
+               return NULL;
+       }
+
+       ret =
+           regcomp(&re, "[/]*([.a-z_A-Z0-9-]+\\.([aA][pP][kK]|[dD][eE][bB]))",
+                   REG_EXTENDED);
+       if (ret != 0) {
+               _libdeb_print(DEBUG_ERR,
+                             "[_libdeb_get_filename] regcomp failed(%d)\n",
+                             ret);
+               return NULL;
+       }
+       ret = regexec(&re, packagefilepath, 5, mached, 0);
+       if (ret != 0) {
+               _libdeb_print(DEBUG_ERR,
+                             "[_libdeb_get_filename] regexec failed(%s)(%d)\n",
+                             packagefilepath, ret);
+               regfree(&re);
+               return NULL;
+       }
+
+       package_file_name = _libdeb_substring(packagefilepath, mached[1].rm_so,
+                                             mached[1].rm_eo -
+                                             mached[1].rm_so);
+
+       _libdeb_print(DEBUG_INFO,
+                     "[_libdeb_get_filename][%s] -> [%s] \n", packagefilepath,
+                     package_file_name);
+       regfree(&re);
+       return package_file_name;
+}
+
+int _libdeb_fill_pkginfo_from_control_file(package_manager_pkg_detail_info_t
+                                          *pkg_detail_info, char *line)
+{
+       regex_t re;
+       regmatch_t mached[5];
+       int ret = 0;
+       char *retstr;
+       /* Package Name */
+       ret = regcomp(&re, "[Pp]ackage[\\ ]*:[\\ ]*([.A-Z0-9a-z_\\-]+)",
+                     REG_EXTENDED);
+       if (ret != 0) {
+               _libdeb_print
+                   (DEBUG_ERR,
+                    "[_libdeb_fill_pkginfo_from_control_file]"
+                    " regcomp failed(%d)", ret);
+               return LIBDEB_ERROR;
+       }
+       ret = regexec(&re, line, 5, mached, 0);
+       if (ret != 0)
+               regfree(&re);
+       else {
+               retstr = _libdeb_substring(line, mached[1].rm_so,
+                                          mached[1].rm_eo - mached[1].rm_so);
+               _libdeb_print
+                   (DEBUG_INFO,
+                    "[_libdeb_fill_pkginfo_from_control_file] PackageName=%s\n",
+                    retstr);
+               strncpy(pkg_detail_info->pkg_name, retstr,
+                       sizeof(pkg_detail_info->pkg_name) - 1);
+               free(retstr);
+               regfree(&re);
+               return LIBDEB_SUCCESS;
+       }
+       /* Version */
+       ret = regcomp(&re,
+                     "Version[\\ ]*:[\\ ]*([0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3})",
+                     REG_EXTENDED);
+       if (ret != 0) {
+               _libdeb_print
+                   (DEBUG_ERR,
+                    "[_libdeb_fill_pkginfo_from_control_file] "
+                    "regcomp failed(%d)", ret);
+               return LIBDEB_ERROR;
+       }
+       ret = regexec(&re, line, 5, mached, 0);
+       if (ret != 0)
+               regfree(&re);
+       else {
+               retstr = _libdeb_substring(line, mached[1].rm_so,
+                                          mached[1].rm_eo - mached[1].rm_so);
+               _libdeb_print
+                   (DEBUG_INFO,
+                    "[_libdeb_fill_pkginfo_from_control_file] Version=%s\n",
+                    retstr);
+               strncpy(pkg_detail_info->version, retstr,
+                       sizeof(pkg_detail_info->version) - 1);
+               regfree(&re);
+               free(retstr);
+               return LIBDEB_SUCCESS;
+       }
+
+       /* Description */
+       ret = regcomp(&re, "[Dd]escription[\\ ]*:[\\ ]*([.A-Z0-9a-z_\\-]+)",
+                     REG_EXTENDED);
+       if (ret != 0) {
+               _libdeb_print
+                   (DEBUG_ERR,
+                    "[_libdeb_fill_pkginfo_from_control_file]"
+                    " regcomp failed(%d)", ret);
+               return LIBDEB_ERROR;
+       }
+       ret = regexec(&re, line, 5, mached, 0);
+       if (ret != 0)
+               regfree(&re);
+       else {
+               retstr = _libdeb_substring(line, mached[1].rm_so,
+                                          mached[1].rm_eo - mached[1].rm_so);
+               _libdeb_print
+                   (DEBUG_INFO,
+                    "[_libdeb_fill_pkginfo_from_control_file] Description=%s\n",
+                    retstr);
+               strncpy(pkg_detail_info->pkg_description, retstr,
+                       sizeof(pkg_detail_info->pkg_description) - 1);
+               free(retstr);
+               regfree(&re);
+               return LIBDEB_SUCCESS;
+       }
+
+       /* Installed Size */
+       ret = regcomp(&re,
+                     "[Ii]nstalled-[Ss]ize[\\ ]*:[\\ ]*([.A-Z0-9a-z_\\-]+)",
+                     REG_EXTENDED);
+       if (ret != 0) {
+               _libdeb_print
+                   (DEBUG_ERR,
+                    "[_libdeb_fill_pkginfo_from_control_file] "
+                    "regcomp failed(%d)", ret);
+               return LIBDEB_ERROR;
+       }
+       ret = regexec(&re, line, 5, mached, 0);
+       if (ret != 0)
+               regfree(&re);
+       else {
+               retstr = _libdeb_substring(line, mached[1].rm_so,
+                                          mached[1].rm_eo - mached[1].rm_so);
+               _libdeb_print
+                   (DEBUG_INFO,
+                    "[_libdeb_fill_pkginfo_from_control_file] "
+                    "Installed Size=%s\n", retstr);
+               pkg_detail_info->app_size = atoi(retstr);
+               free(retstr);
+               regfree(&re);
+               return LIBDEB_SUCCESS;
+       }
+
+       return LIBDEB_SUCCESS;
+}
+
+
+int _libdeb_populate_control_info(const char *pkgname,
+                                 package_manager_pkg_detail_info_t
+                                 *pkg_detail_info, char *controlfilepath)
+{
+       FILE *fp = NULL;
+       char *lineptr = NULL;
+       size_t len = 512;
+       ssize_t read;
+       char buff[512] = { 0, };
+       int flag;
+       int ret = 0;
+       if (strncmp(controlfilepath, PKGMETAINFO, strlen(PKGMETAINFO)))
+               flag = 1;       /*directly read from control file of pkg */
+       else
+               flag = 0;       /* read from dpkg available file */
+       _libdeb_print(DEBUG_INFO, "flag value is %d\n", flag);
+       fp = fopen(controlfilepath, "r");
+       if (fp == NULL) {
+               _libdeb_print(DEBUG_ERR,
+                             "failed to open file(%s)\n", controlfilepath);
+               return LIBDEB_ERROR;
+       }
+       if (pkgname)
+               snprintf(buff, 512, "Package: %s", pkgname);
+       /*allocate memory for lineptr. If it is less
+          getline will realloc it */
+       lineptr = (char *)malloc(sizeof(char) * 512);
+       if (UNLIKELY(lineptr == NULL)) {
+                _libdeb_print(DEBUG_ERR,
+                              "malloc failed\n");
+                fclose(fp);
+                return LIBDEB_ERROR;
+        }
+       memset(lineptr, 0x00, sizeof(char) * 512);
+       clearerr(fp);
+       do {
+               memset(lineptr, 0x00, sizeof(char) * 512);
+               read = getline(&lineptr, &len, fp);
+               if (lineptr == NULL)
+                       return LIBDEB_ERROR;
+               if (read == -1) {
+                       if (feof(fp)) {
+                               fclose(fp);
+                               return LIBDEB_SUCCESS;
+                       }
+                       _libdeb_print(DEBUG_ERR, "getline failed\n");
+                       fclose(fp);
+                       return LIBDEB_ERROR;
+               }
+               if (flag == 1) {
+                       /*got the entry in available file. Now read till
+                          next empty line and break */
+                       /*10 is ASCII of newline \n */
+                       if (*lineptr == 10)
+                               break;
+                       ret =
+                           _libdeb_fill_pkginfo_from_control_file
+                           (pkg_detail_info, lineptr);
+                       if (ret) {
+                               fclose(fp);
+                               return LIBDEB_ERROR;
+                       }
+               } else {
+                       if ((strncmp(lineptr, buff, strlen(buff)) == 0) &&
+                                   (strlen(lineptr) == strlen(buff) + 1)) {
+                               flag = 1;
+                               /*Parse the fields now */
+                               ret =
+                                   _libdeb_fill_pkginfo_from_control_file
+                                   (pkg_detail_info, lineptr);
+                               if (ret) {
+                                       fclose(fp);
+                                       return LIBDEB_ERROR;
+                               }
+
+                       } else {
+                               continue;
+                       }
+               }
+       } while (lineptr != NULL);
+       fclose(fp);
+       if (lineptr) {
+               free(lineptr);
+               lineptr = NULL;
+       }
+
+       return LIBDEB_SUCCESS;
+
+}
+
+
+long long _libdeb_calculate_dir_size(char *dirname)
+{
+       long long total = 0;
+       long long ret = 0;
+       int q = 0; /*quotient*/
+       int r = 0; /*remainder*/
+       DIR *dp = NULL;
+       struct dirent *ep = NULL;
+       struct stat fileinfo;
+       char abs_filename[FILENAME_MAX] = { 0, };
+       if (dirname == NULL) {
+               _libdeb_print(DEBUG_ERR,
+                               "dirname is NULL");
+               return LIBDEB_ERROR;
+       }
+       dp = opendir(dirname);
+       if (dp != NULL) {
+               while ((ep = readdir(dp)) != NULL) {
+                       if (!strcmp(ep->d_name, ".") || 
+                               !strcmp(ep->d_name, "..")) {
+                               continue;
+                       }
+                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+                                ep->d_name);
+                       if (stat(abs_filename, &fileinfo) < 0)
+                               perror(abs_filename);
+                       else {
+                               if (S_ISDIR(fileinfo.st_mode)) {
+                                       total += fileinfo.st_size;
+                                       if (strcmp(ep->d_name, ".")
+                                           && strcmp(ep->d_name, "..")) {
+                                               ret = _libdeb_calculate_dir_size
+                                                   (abs_filename);
+                                               total = total + ret;
+                                       }
+                               } 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 = q + 1;
+                               }
+                               total += q * BLOCK_SIZE;
+                               }
+                       }
+               }
+               (void)closedir(dp);
+       } else {
+               _libdeb_print(DEBUG_ERR,
+                            "Couldn't open the directory\n");
+               return -1;
+       }
+       return total;
+
+}
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..28f93f4
--- /dev/null
@@ -0,0 +1,79 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+#Verbose
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util )
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(libpkgs REQUIRED vconf sqlite3 dbus-glib-1 glib-2.0 db-util pkgmgr-installer-status-broadcast-server)
+
+FOREACH(flag ${libpkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server)
+
+link_directories (${STATUS_LIBRARY_DIRS})
+include_directories (${STATUS_INCLUDE_DIRS})
+
+SET(backend_dir "${CMAKE_CURRENT_SOURCE_DIR}")
+SET(backend_inc_dir "${backend_dir}/include")
+SET(backend_c_src_dir "${backend_dir}/src")
+SET(backend_script_dir "${backend_dir}/scripts")
+SET(SCRIPTS_DIR "${backend_script_dir}")
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+###################################################################################################
+## for native-backend (binary)
+SET(native-backend_SOURCES ${backend_c_src_dir}/core/nativeinstallercore.c ${backend_c_src_dir}/core/nativeinstallertool.c ${backend_c_src_dir}/dpkg/nativeinstallerdpkg.c ${backend_c_src_dir}/parser/nativeinstallermanifestparser.c ${backend_c_src_dir}/vconf/nativebackendvconfintf.c)
+SET(native-backend_CFLAGS " -I. -I${backend_inc_dir} ${pkg_CFLAGS}")
+SET(native-backend_LDFLAGS ${pkgs_LDFLAGS})
+
+ADD_EXECUTABLE(native-backend ${native-backend_SOURCES})
+TARGET_LINK_LIBRARIES(native-backend native-util)
+TARGET_LINK_LIBRARIES(native-backend ${libpkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(native-backend ${STATUS_LIBRARIES})
+SET_TARGET_PROPERTIES(native-backend PROPERTIES COMPILE_FLAGS "${native-backend_CFLAGS}")
+####################################################################################################
+
+### Create pc file 
+configure_file(${backend_script_dir}/install_spk.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_spk.sh @ONLY)
+configure_file(${backend_script_dir}/audit_spk.sh.in ${CMAKE_CURRENT_BINARY_DIR}/audit_spk.sh @ONLY)
+configure_file(${backend_script_dir}/extract_manifest.sh.in ${CMAKE_CURRENT_BINARY_DIR}/extract_manifest.sh @ONLY)
+configure_file(${backend_script_dir}/uninstall_spk.sh.in ${CMAKE_CURRENT_BINARY_DIR}/uninstall_spk.sh @ONLY)
+configure_file(${backend_script_dir}/update_avail_spk.sh.in ${CMAKE_CURRENT_BINARY_DIR}/update_avail_spk.sh @ONLY)
+configure_file(${backend_script_dir}/find_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/find_package.sh @ONLY)
+#SET(CLEAN_FILE_LIST "${CMAKE_CURRENT_BINARY_DIR}/extract_manifest.sh;${CLEAN_FILE_LIST}")
+#SET(CLEAN_FILE_LIST "${CMAKE_CURRENT_BINARY_DIR}/install_spk.sh;${CLEAN_FILE_LIST}")
+#SET(CLEAN_FILE_LIST "${CMAKE_CURRENT_BINARY_DIR}/audit_spk.sh;${CLEAN_FILE_LIST}")
+#SET(CLEAN_FILE_LIST "${CMAKE_CURRENT_BINARY_DIR}/uninstall_spk.sh;${CLEAN_FILE_LIST}")
+#SET(CLEAN_FILE_LIST "${CMAKE_CURRENT_BINARY_DIR}/update_avail_spk.sh;${CLEAN_FILE_LIST}")
+#SET(CLEAN_FILE_LIST "${CLEAN_FILE_LIST}update_avail_spk.sh")
+
+####################################################################################################
+
+INSTALL(TARGETS native-backend DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE)
+INSTALL(FILES 
+               ${CMAKE_CURRENT_BINARY_DIR}/install_spk.sh 
+               ${CMAKE_CURRENT_BINARY_DIR}/audit_spk.sh 
+               ${CMAKE_CURRENT_BINARY_DIR}/extract_manifest.sh 
+               ${CMAKE_CURRENT_BINARY_DIR}/uninstall_spk.sh 
+               ${CMAKE_CURRENT_BINARY_DIR}/update_avail_spk.sh 
+               ${CMAKE_CURRENT_BINARY_DIR}/find_package.sh 
+               DESTINATION bin)
+
+
+#INSTALL(DIRECTORY ${SCIPTS_DIR}/ DESTINATION bin FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE)
+#INSTALL(TARGETS native-backend DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE)
+####################################################################################################
+
+
diff --git a/backend/inc/nativeinstaller.h b/backend/inc/nativeinstaller.h
new file mode 100755 (executable)
index 0000000..d2eb908
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#ifndef NATIVEINSTALLER_H_
+#define NATIVEINSTALLER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
+#include "native_installer_util.h"
+#include <stdbool.h>
+
+#define PM_LIKELY(expr) __builtin_expect((expr), 1)
+#define PM_UNLIKELY(expr) __builtin_expect((expr), 0)
+
+/* backend state to be used for recovery */
+typedef enum {
+       REQUEST_ACCEPTED = 1,
+       GOT_PACKAGE_INFO_SUCCESSFULLY,
+       DPKG_REQUEST_COMPLETED,
+       DPKG_REQUEST_PENDING,
+       REQUEST_COMPLETED,
+} backend_state;
+
+struct pkginfo_st {
+       char package_name[128]; /* 32: linux username limit */
+       char version[11];       /* ###.###.### */
+};
+
+typedef struct pkginfo_st pkginfo;
+
+/**
+ * Install the package
+ * @in :pPkgFilePath : Package file path
+ * @in :bForceInstall: Whether we need to forceful overwrite. 
+ *     If package already installed then reinstall the application
+ * @in :installOptions: install options
+ */
+int _pkgmgr_package_install(char *ppkgfilepath, bool bforceinstall,
+                                                  char *installoptions);
+
+/**
+ * get the package information for the requested installed application
+ * return the package information
+ * @in :pkgName : package name for which information is requested
+ */
+pkginfo *_pkgmgr_get_installed_pkg_info(char *pkgname);
+
+/**
+ * Uninstall the Application
+ * @in :pkgName : application name to be uninstalled
+ */
+int _pkgmgr_package_uninstall(char *pkgname);
+
+pkginfo *_pkgmgr_get_pkg_info(char *pkgfilepath, int *errno,
+                               bool *alreayinstalled);
+
+/* Dbus related prototype */
+int _broadcast_status_notification(char *pkgname, char *key, char *val);
+
+/* DPKG operations prototype */
+int _pkgmgr_dpkg_uninstall_pkg(char *pkgname);
+int _pkgmgr_dpkg_install_pkg(char *pkgfilepath, char *installoptions);
+int _pkgmgr_dpkg_upgrade_pkg(char *pkgfilepath, char *installoptions);
+int _pkgmgr_clear_private_data(char *pkgname);
+int _set_backend_state(int state);
+int _get_backend_state();
+int _get_backend_state_info();
+int _set_backend_state_info(int state);
+int _get_last_input_info(char **pkgname, int *preqcommand, int *poptions);
+void _save_last_input_info(char *pkgname, int reqcommand, int options);
+/* For third party apps*/
+int _set_event_notification(int value);
+int _unset_event_notification();
+pkginfo *_pkgmgr_txt_parser_read_manifest(char *manifestfile);
+void stat_cb(const char *pkg_name, const char *key, const char *val);
+
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+
+#endif                         /* NATIVEINSTALLER_H_ */
diff --git a/backend/scripts/audit_spk.sh.in b/backend/scripts/audit_spk.sh.in
new file mode 100755 (executable)
index 0000000..7bd6ac3
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+
+PKG_LOG_DIR=/var/pkgmgr/native
+
+debug () {
+        echo ">>$DEBUG"
+}
+
+NOARG=$#
+#echo "No of Arguments = $NOARG"
+
+if [ $NOARG -lt 0 ] || [ $NOARG -gt 2 ] || [ $NOARG -eq 1 ]; then
+        DEBUG="Usage: audit_spk.sh";debug
+        exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+        STATUS_OPTIONS=$1
+        STATUS_FD=$2
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+        mkdir -p $PKG_LOG_DIR
+fi
+
+# 3. DELETE FILES
+dpkg $STATUS_OPTIONS $STATUS_FD --audit
+
diff --git a/backend/scripts/extract_manifest.sh.in b/backend/scripts/extract_manifest.sh.in
new file mode 100755 (executable)
index 0000000..dac43fd
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/sh
+# extract metainfo/manifest to /var/pkgmgr/packagename/metainfo/manifest
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+E_NOT_VALID_ARCHIVE=8
+echo "package path is "$1"" > /tmp/nativescriptlog
+
+CURDIR=`pwd`
+echo "current dir is $CURDIR" >> /tmp/nativescriptlog
+
+debug () {
+       echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+if [ $# -ne 1 ];then
+       DEBUG="Usage: extract_manifest.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+fi
+
+if [ ! -f "$1" ];then
+       DEBUG="File not found";debug
+       exit $E_FILE_NOT_FOUND
+fi
+
+PKGFILEPATH="$1"
+PKGFILENAME="${PKGFILEPATH##*/}"
+CURDIR=`pwd`
+
+TEMPDIR=/opt/ums/nativeinstaller/"$PKGFILENAME"-temp
+echo "$TEMPDIR" >> /tmp/nativescriptlog
+
+mkdir -p "$TEMPDIR"
+echo "pkg file path = "$PKGFILEPATH"" >> /tmp/nativescriptlog
+cp "$PKGFILEPATH" "$TEMPDIR"/
+cd "$TEMPDIR"
+
+filename=`ls`
+echo "filename = "$filename"" >> /tmp/nativescriptlog
+
+dpkg -e "$filename"
+retval=$?
+echo "retval = $retval" >> /tmp/nativescriptlog
+
+if [ $retval -ne 0 ];then
+       DEBUG="archive Not correct";debug
+       cd $CURDIR
+       exit $E_NOT_VALID_ARCHIVE
+fi
+
+CHECK_MANIFEST=`ls ./DEBIAN | grep control/*`
+echo $CHECK_MANIFEST >> /tmp/nativescriptlog
+if [ "$CHECK_MANIFEST" != "control" ];then
+       DEBUG="No manifest";debug
+       cd $CURDIR
+       rm -rf "$TEMPDIR"
+       exit $E_NO_MANIFEST
+fi
+
+mkdir -p /var/pkgmgr/"$PKGFILENAME"/metainfo
+mv ./DEBIAN/"$CHECK_MANIFEST" /var/pkgmgr/"$PKGFILENAME"/metainfo
+cd $CURDIR
+rm -rf "$TEMPDIR"
diff --git a/backend/scripts/find_package.sh.in b/backend/scripts/find_package.sh.in
new file mode 100755 (executable)
index 0000000..da4df95
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+# extract metainfo/manifest to /var/pkgmgr/packagename/metainfo/manifest
+E_DPKG_NOT_INSTALLED=1
+E_DPKG_ALREADY_INSTALLED=2
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+E_NOT_VALID_ARCHIVE=8
+
+echo "find pakcage $1" >> /tmp/nativescriptlog
+
+CURDIR=`pwd`
+echo $CURDIR >> /tmp/nativescriptlog
+
+debug () {
+       echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+if [ $# -ne 1 ];then
+       DEBUG="Usage: find_package.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+fi
+
+PKGNAME=$1
+echo "pkg name = $PKGNAME" >> /tmp/nativescriptlog
+
+PKG_LOG_DIR=/var/pkgmgr/$PKGNAME
+if [ ! -d $PKG_LOG_DIR ];then
+       DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+       mkdir -p $PKG_LOG_DIR
+fi
+
+
+
+dpkg --list |grep -w $PKGNAME
+retval=$?
+echo "retval = $retval" >> /tmp/nativescriptlog
+
+if [ $retval -ne 0 ];then
+       DEBUG="pakcage not exist";debug
+       cd $CURDIR
+       exit $E_DPKG_NOT_INSTALLED
+fi
+
+versioninfo=`dpkg --list |grep $PKGNAME|tr -s ' ' | cut -f3 "-d "`
+
+echo "Package: $PKGNAME" > $PKG_LOG_DIR/pkginfo
+echo "Version: $versioninfo" >> $PKG_LOG_DIR/pkginfo
+
+cd $CURDIR
+exit $E_DPKG_ALREADY_INSTALLED
diff --git a/backend/scripts/install_spk.sh.in b/backend/scripts/install_spk.sh.in
new file mode 100755 (executable)
index 0000000..60248b7
--- /dev/null
@@ -0,0 +1,107 @@
+#!/bin/sh
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+E_DPKG_ERROR=8
+
+PKG_LOG_DIR=/var/pkgmgr/native
+
+
+debug () {
+       echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+NOARG=$#
+#echo "No of Arguments = $NOARG"
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 4 ] ; then
+       DEBUG="Usage: install.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+       OPTIONS_FLAGS=$2
+elif [ $NOARG -eq 3 ] ; then
+       STATUS_OPTIONS=$2
+       STATUS_FD=$3
+elif [ $NOARG -eq 4 ] ; then
+       OPTIONS_FLAGS=$2
+       STATUS_OPTIONS=$3
+       STATUS_FD=$4
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+       DEBUG="File not found";debug
+       exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+       DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+       mkdir -p $PKG_LOG_DIR
+fi
+
+PKGFILENAME="${PKGFILE_PATH##*/}"
+###############
+#PKGNAME=${PKGFILENAME%-[0-9]*.*} <- NG(PKGName can be different with PkgFileName)
+/usr/bin/extract_manifest.sh "$PKGFILE_PATH"
+PKGNAME=`grep -i Package: /var/pkgmgr/"$PKGFILENAME"/metainfo/control | awk -F: '{print $2}' | sed 's/^[ ]*//'`
+rm -rf /var/pkgmgr/"$PKGFILENAME"
+###############
+
+touch $PKG_LOG_DIR/$PKGNAME.install
+echo "$PKGFILE_PATH" > $PKG_LOG_DIR/$PKGNAME.install
+
+#echo "pkg name = $PKGFILENAME"
+#echo "Options = $OPTIONS_FLAGS"
+#echo "Status Fd options = $STATUS_OPTIONS"
+#echo "Status Fd = $STATUS_FD"
+dpkg $OPTIONS_FLAGS $STATUS_OPTIONS $STATUS_FD --install "$PKGFILE_PATH"
+dpkgretval=$?
+if [ $dpkgretval -ne 0 ]; then                                                                               
+       DEBUG="dpkg returned error ";debug                                                                  
+       # just remove any partially installed package 
+       dpkg --purge "$PKGNAME"
+       exit $E_DPKG_ERROR                                                                                   
+else                                                                                                         
+       DEBUG="dpkg success ";debug                                                                          
+fi
+
+#DAC
+USERNAME=`echo $PKGNAME | tr '.' '_'`
+GROUPNAME=$USERNAME
+#INHOUSEGROUPNAME=`id -nG inhouse|tr ' ' ','`
+INHOUSEGROUPNAME=`id -nG inhouse`
+PKGFOLDERNAME=/opt/apps/$PKGNAME
+
+if [ -d $PKGFOLDERNAME ];then
+       DEBUG="home Folder exist";debug
+else
+       DEBUG="home Folder not exist; creating";debug
+       mkdir -p $PKGFOLDERNAME
+fi
+
+mkdir -p $PKGFOLDERNAME/data
+chown -R 5000:5000 /opt/apps/$PKGNAME/data
+
+#deluser $USERNAME
+#addgroup $GROUPNAME
+
+#i=10000
+#while [ $i -le 64999 ]
+#do
+#      adduser -G $GROUPNAME -h $PKGFOLDERNAME/home -u $i -D $USERNAME 
+#      if [ $? -eq 0 ]
+#      then
+#              break
+#      else
+#              i=`expr $i + 1`
+#      fi
+#done
+
+
+#for grp in $INHOUSEGROUPNAME
+#do
+#      addgroup $USERNAME $grp
+#done
+
+
diff --git a/backend/scripts/uninstall_spk.sh.in b/backend/scripts/uninstall_spk.sh.in
new file mode 100755 (executable)
index 0000000..db3abbf
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+# 1. REMOVE MENUSCREEN
+
+# 2. REMOVE DB
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+E_DPKG_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/native
+
+debug () {
+        echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+NOARG=$#
+#echo "No of Arguments = $NOARG"
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 3 ] || [ $NOARG -eq 2 ]; then
+        DEBUG="Usage: uninstall.sh <PackageName>";debug
+        exit $E_WRONG_ARGS
+elif [ $NOARG -eq 3 ]; then
+        STATUS_OPTIONS=$2
+        STATUS_FD=$3
+fi
+
+
+if [ ! -d $PKG_LOG_DIR ];then
+        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+        mkdir -p $PKG_LOG_DIR
+fi
+
+PKGNAME=$1
+
+# 3. DELETE FILES
+dpkg $STATUS_OPTIONS $STATUS_FD --purge $PKGNAME
+ret=$?
+if [ $ret -ne 0 ];then
+       DEBUG="Dpkg error";debug
+       exit $E_DPKG_ERROR
+fi
+# 4. remove account
+USERNAME=`echo $PKGNAME | tr '.' '_'`
+INHOUSEGROUPNAME=`id -nG inhouse|tr ' ' ','`
+
+#for grp in $INHOUSEGROUPNAME
+#do
+#      delgroup $USERNAME $grp
+#done
+
+if [ ! -d /opt/apps/$1 ];then
+        DEBUG="Package Directory not found";debug
+else
+       rm -rf /opt/apps/$PKGNAME
+fi
+
+
+#deluser $USERNAME
+#delgroup $USERNAME
+
+# 5. clear log
diff --git a/backend/scripts/update_avail_spk.sh.in b/backend/scripts/update_avail_spk.sh.in
new file mode 100755 (executable)
index 0000000..010084d
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+
+PKG_LOG_DIR=/var/pkgmgr/native
+
+debug () {
+        echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 3 ] || [ $NOARG -eq 2 ]; then
+        DEBUG="Usage: update_avail_spk.sh <controlfile>";debug
+        exit $E_WRONG_ARGS
+elif [ $NOARG -eq 3 ] ; then
+        STATUS_OPTIONS=$2
+        STATUS_FD=$3
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+        mkdir -p $PKG_LOG_DIR
+fi
+
+CONTROL_FILE=$1
+
+# 3. DELETE FILES
+dpkg $STATUS_OPTIONS $STATUS_FD --update-avail $CONTROL_FILE
+
diff --git a/backend/src/core/nativeinstallercore.c b/backend/src/core/nativeinstallercore.c
new file mode 100755 (executable)
index 0000000..028c318
--- /dev/null
@@ -0,0 +1,501 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+/* System Include files */
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <wait.h>
+#include <regex.h>
+
+/* SLP include files */
+#include "nativeinstaller.h"
+#include "native_installer_util.h"
+#include "db-util.h"
+
+#define EXTRACT_MENIFEST       "/usr/bin/extract_manifest.sh"
+#define FIND_PACKAGE           "/usr/bin/find_package.sh"
+#define MANIFEST_FILE_NAME "control"
+
+typedef struct _pkgfile_info {
+       char *ppkg_filename;
+       char *ppkgtype;
+       char pkg_manifest_filepath[256];
+       char extracted_pkg_location[256];
+
+} pkgfile_info;
+
+
+extern char *gptrpkgname;
+extern int do_upgrade;
+extern int quiet;
+static int __pkgmgr_get_filename(char *package_filepath, 
+                                pkgfile_info *ppkg_fileinfo);
+static int __recursive_delete_dir(char *dirname);
+
+pkginfo *_pkgmgr_get_installed_pkg_info(char *pkgname)
+{
+       char pkg_manifest_filepath[256];
+       pkginfo *info = NULL;
+       int err;
+       const char *argv[] = { FIND_PACKAGE, pkgname, NULL };
+
+       if (pkgname == NULL)
+               return NULL;
+
+       err = _xsystem(argv);
+       d_msg_backend(DEBUG_INFO,
+                     "[_pkgmgr_get_installed_pkg_info] _xsystem returns %d\n",
+                        err);
+       if (err == 1) {
+               d_msg_backend(DEBUG_INFO,
+                             "[_pkgmgr_get_installed_pkg_info] "
+                               "Package Not installed \n");
+       } else if (err == 2) {
+               d_msg_backend(DEBUG_INFO,
+                             "[_pkgmgr_get_installed_pkg_info] "
+                               "package already install\n");
+               snprintf(pkg_manifest_filepath, 255, "/var/pkgmgr/%s/pkginfo",
+                       pkgname);
+               d_msg_backend(DEBUG_INFO, "manifest=%s\n",
+                             pkg_manifest_filepath);
+               info =
+                   _pkgmgr_txt_parser_read_manifest(
+                                       (char *)(pkg_manifest_filepath));
+
+               if (info == NULL) {
+                       d_msg_backend(DEBUG_ERR,
+                                     "Failed to parse Manifest file \n");
+                       info = NULL;
+               }
+
+       } else {
+               d_msg_backend(DEBUG_ERR,
+                             "[_pkgmgr_get_installed_pkg_info] "
+                               "_xsystem returns error = %d\n",
+                               err);
+       }
+       return info;
+
+}
+
+static int __recursive_delete_dir(char *dirname)
+{
+       DIR *dp;
+       struct dirent *ep;
+       char abs_filename[FILENAME_MAX];
+       struct stat stFileInfo;
+       dp = opendir(dirname);
+       if (dp != NULL) {
+               while (ep = readdir(dp)) {
+                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+                                ep->d_name);
+                       if (lstat(abs_filename, &stFileInfo) < 0)
+                               perror(abs_filename);
+                       if (S_ISDIR(stFileInfo.st_mode)) {
+                               if (strcmp(ep->d_name, ".") &&
+                                   strcmp(ep->d_name, "..")) {
+                                       __recursive_delete_dir(abs_filename);
+                                       remove(abs_filename);
+                               }
+                       } else {
+                               remove(abs_filename);
+                       }
+               }
+               (void)closedir(dp);
+       } else {
+               d_msg_backend(DEBUG_ERR,"Couldn't open the directory\n");
+               return NATIVEINSTALLER_ERR_CLEAR_DATA_FAILED;
+       }
+
+       return NATIVEINSTALLER_SUCCESS;
+}
+
+static int __pkgmgr_get_filename(char *package_filepath, 
+                                pkgfile_info *ppkg_fileinfo)
+{
+       regex_t re;
+       regmatch_t mached[5];
+       int ret = 0;
+       char *ptr = NULL;
+       ret =
+           regcomp(&re, "[/]*([.a-z_A-Z0-9-]+\\.([aA][pP][kK]|[dD][eE][bB]))",
+                   REG_EXTENDED);
+       if (ret != 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "[__pkgmgr_get_filename]regcomp failed(%d)\n",
+                                       ret);
+               return -1;
+       }
+       ret = regexec(&re, package_filepath, 5, mached, 0);
+       if (ret != 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "[__pkgmgr_get_filename]regexec failed(%s)(%d)\n",
+                             package_filepath, ret);
+               regfree(&re);
+               return -1;
+       }
+       /*Use simple logic to extract filename 
+       as it may contain any character */
+       ptr = strrchr(package_filepath, 47);    /* 47 is ASCII for / */
+       if (!ptr)
+               return -1;
+       if (ptr + 1)
+               ppkg_fileinfo->ppkg_filename = strdup(ptr + 1);
+       ppkg_fileinfo->ppkgtype =
+           _substring(package_filepath, mached[2].rm_so,
+                     mached[2].rm_eo - mached[2].rm_so);
+
+       d_msg_backend(DEBUG_INFO,
+                     "[getPackageFileName][%s] -> [%s]; pkgtype = %s \n",
+                     package_filepath, ppkg_fileinfo->ppkg_filename,
+                     ppkg_fileinfo->ppkgtype);
+       regfree(&re);
+       return 1;
+}
+
+pkginfo *_pkgmgr_get_pkg_info(char *pkg_filepath, int *errno,
+                             bool *alreay_installed)
+{
+       pkgfile_info pkg_fileinfo;
+       pkginfo *info = NULL;
+       pkginfo *tmpinfo = NULL;
+       int err = 0;
+       const char *argv[] = { EXTRACT_MENIFEST, pkg_filepath, NULL };
+
+       if (pkg_filepath == NULL || errno == NULL || alreay_installed == NULL)
+               return NULL;
+
+       *errno = 0;
+       err = _xsystem(argv);
+       d_msg_backend(DEBUG_INFO, "[_pkgmgr_get_pkg_info] "
+       "_xsystem returns %d\n", err);
+       if (err != 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "[_pkgmgr_get_pkg_info] _xsystem returns %d\n", 
+                               err);
+               /*E_WRONG_ARGS=5 */
+               /*E_FILE_NOT_FOUND=6 */
+               /*E_NO_MANIFEST=7 */
+               /*E_NOT_VALID_ARCHIVE=8 */
+
+               switch (err) {
+               case 6:
+                       *errno = NATIVEINSTALLER_ERR_PKG_NOT_FOUND;
+                       break;
+               case 7:
+                       *errno = NATIVEINSTALLER_ERR_NO_MANIFEST;
+                       break;
+               case 8:
+                       *errno = NATIVEINSTALLER_ERR_NO_DEB_FILE;
+                       break;
+               default:
+                       *errno = NATIVEINSTALLER_ERR_UNKNOWN;
+                       break;
+               }
+               return NULL;
+       }
+
+       err = __pkgmgr_get_filename(pkg_filepath, &pkg_fileinfo);
+       if (err == -1) {
+               *errno = NATIVEINSTALLER_ERR_UNKNOWN;
+               return NULL;
+       }
+
+       if (pkg_fileinfo.ppkgtype == NULL) {
+               d_msg_backend(DEBUG_ERR, "Package type is returned NULL \n");
+               return NULL;
+       }
+
+       if (strcmp(pkg_fileinfo.ppkgtype, PKGTYPE) != 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "Package file is not a debian file \n");
+               *errno = NATIVEINSTALLER_ERR_NO_DEB_FILE;
+               return NULL;
+       }
+       snprintf(pkg_fileinfo.extracted_pkg_location, 255, "/var/pkgmgr/%s",
+               pkg_fileinfo.ppkg_filename);
+
+       snprintf(pkg_fileinfo.pkg_manifest_filepath, 255, 
+                "/var/pkgmgr/%s/metainfo/%s",
+               pkg_fileinfo.ppkg_filename, MANIFEST_FILE_NAME);
+       d_msg_backend(DEBUG_INFO, "manifest=%s\n",
+                     pkg_fileinfo.pkg_manifest_filepath);
+       info = _pkgmgr_txt_parser_read_manifest(
+                               (char *)(pkg_fileinfo.pkg_manifest_filepath));
+
+       if (info == NULL) {
+               d_msg_backend(DEBUG_ERR, "Failed to parse Manifest file \n");
+               *errno = NATIVEINSTALLER_ERR_UNKNOWN;
+               return NULL;
+       }
+       unlink(pkg_fileinfo.pkg_manifest_filepath);
+       if (pkg_fileinfo.ppkg_filename) {
+               free(pkg_fileinfo.ppkg_filename);
+               pkg_fileinfo.ppkg_filename = NULL;
+       }
+       if (pkg_fileinfo.ppkgtype) {
+               free(pkg_fileinfo.ppkgtype);
+               pkg_fileinfo.ppkgtype = NULL;
+       }
+
+       /* check is it already installed or not */
+       tmpinfo = _pkgmgr_get_installed_pkg_info(info->package_name);
+       if (tmpinfo != NULL) {
+               /*already installed */
+               *alreay_installed = true;
+               free(tmpinfo);
+               tmpinfo = NULL;
+       }
+
+       return info;
+}
+
+int _pkgmgr_package_install(char *pkgfilepath, bool forceinstall,
+                           char *installoptions)
+{
+       int err = 0;
+       pkginfo *info = NULL;
+       pkginfo *tmpinfo = NULL;
+       bool alreadyinstalled = false;
+       if (forceinstall == true && installoptions == NULL)
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+
+       info = _pkgmgr_get_pkg_info(pkgfilepath, &err, &alreadyinstalled);
+       if (err != 0 || info == NULL) {
+               if (info != NULL)
+                       free(info);
+               return err;
+       }
+#ifndef SEND_PKGPATH
+       gptrpkgname = strdup(info->package_name);
+       _broadcast_status_notification(info->package_name, "start", "install");
+       _broadcast_status_notification(info->package_name, 
+                                      "command", "Install");
+#endif
+
+       if (alreadyinstalled == true && forceinstall != true) {
+               tmpinfo = _pkgmgr_get_installed_pkg_info(info->package_name);
+               if (tmpinfo == NULL)
+                       return NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+
+               d_msg_backend(DEBUG_ERR,
+                             "installed version is %s and to be "
+                               "installed version is %s\n",
+                             tmpinfo->version, info->version);
+               if (strcmp(info->version, tmpinfo->version) == 0) {
+                       _set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+                       err = _pkgmgr_dpkg_upgrade_pkg(pkgfilepath,
+                                                installoptions);
+                       if (err != 0) {
+                               d_msg_backend(DEBUG_ERR,
+                                     "upgrade complete with error(%d)\n",
+                                             err);
+                               if (info) {
+                                       free(info);
+                                       info = NULL;
+                               }
+                               if (tmpinfo) {
+                                       free(tmpinfo);
+                                       tmpinfo = NULL;
+                               }
+                               return err;
+                       }
+                       _set_backend_state_info(DPKG_REQUEST_COMPLETED);
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       if (tmpinfo) {
+                               free(tmpinfo);
+                               tmpinfo = NULL;
+                       }
+                       return NATIVEINSTALLER_SUCCESS;
+               } else if (strcmp(info->version, tmpinfo->version) > 0) {
+                       /*upgrade */
+                       _set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+                       err = _pkgmgr_dpkg_upgrade_pkg(
+                                               pkgfilepath, installoptions);
+                       if (err != 0) {
+                               d_msg_backend(DEBUG_ERR,
+                                             "upgrade complete with error(%d)\n",
+                                             err);
+                               if (info) {
+                                       free(info);
+                                       info = NULL;
+                               }
+                               if (tmpinfo) {
+                                       free(tmpinfo);
+                                       tmpinfo = NULL;
+                               }
+                               return err;
+                       }
+                       _set_backend_state_info(DPKG_REQUEST_COMPLETED);
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       if (tmpinfo) {
+                               free(tmpinfo);
+                               tmpinfo = NULL;
+                       }
+                       return NATIVEINSTALLER_SUCCESS;
+
+               } else if (strcmp(info->version, tmpinfo->version) < 0) {
+                       /*show popup and confirm from user if non quiet mode
+                       else continue downgrade*/
+                       if (quiet == 1) {
+                               do_upgrade = 1;
+                       }
+                       switch (do_upgrade) {
+                       case -1:
+                                       _set_backend_state_info(DPKG_REQUEST_PENDING);
+                                       if (info) {
+                                                free(info);
+                                                info = NULL;
+                                        }
+                                        if (tmpinfo) {
+                                                free(tmpinfo);
+                                                tmpinfo = NULL;
+                                        }
+                                       return NATIVEINSTALLER_ERR_NEED_USER_CONFIRMATION;
+                       case 0:
+                                       /*return */
+                                       if (info) {
+                                               free(info);
+                                               info = NULL;
+                                       }
+                                       if (tmpinfo) {
+                                               free(tmpinfo);
+                                               tmpinfo = NULL;
+                                       }
+                                       _set_backend_state_info(DPKG_REQUEST_COMPLETED);
+                                       return NATIVEINSTALLER_PACKAGE_NOT_UPGRADED;
+                       case 1:
+                                       /*continue with downgrade */
+                                       _set_backend_state_info
+                                       (GOT_PACKAGE_INFO_SUCCESSFULLY);
+                                       err =
+                                       _pkgmgr_dpkg_upgrade_pkg(pkgfilepath,
+                                                        installoptions);
+                                       if (err != 0) {
+                                               d_msg_backend(DEBUG_ERR,
+                                                     "upgrade complete with error(%d)\n",
+                                                     err);
+                                               if (info) {
+                                                       free(info);
+                                                       info = NULL;
+                                               }
+                                               if (tmpinfo) {
+                                                       free(tmpinfo);
+                                                       tmpinfo = NULL;
+                                               }
+                                               return err;
+                                       }
+                                       _set_backend_state_info(DPKG_REQUEST_COMPLETED);
+                                       if (info) {
+                                               free(info);
+                                               info = NULL;
+                                       }
+                                       if (tmpinfo) {
+                                               free(tmpinfo);
+                                               tmpinfo = NULL;
+                                       }
+                                       return NATIVEINSTALLER_SUCCESS;
+                                       
+                       }
+               
+
+               }
+
+       } else {
+               _set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+               err = _pkgmgr_dpkg_install_pkg(pkgfilepath, installoptions);
+               if (err != 0) {
+                       d_msg_backend(DEBUG_ERR,
+                                     "install complete with error(%d)\n", err);
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       return err;
+               }
+
+               _set_backend_state_info(DPKG_REQUEST_COMPLETED);
+               if (info) {
+                       free(info);
+                       info = NULL;
+               }
+               return NATIVEINSTALLER_SUCCESS;
+       }
+       if (tmpinfo) {
+               free(tmpinfo);
+               tmpinfo = NULL;
+       }
+       return NATIVEINSTALLER_SUCCESS;
+}
+
+int _pkgmgr_package_uninstall(char *pkgname)
+{
+       int ret = 0;
+
+       pkginfo *tmppkginfo = _pkgmgr_get_installed_pkg_info(pkgname);
+       if (tmppkginfo == NULL)
+               return NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+
+       free(tmppkginfo);
+#ifndef SEND_PKGPATH
+       gptrpkgname = strdup(pkgname);
+       _broadcast_status_notification(pkgname, "start", "uninstall");
+       _broadcast_status_notification(pkgname, "command", "Uninstall");
+#endif
+       _set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+       /* call remove package using package installer module */
+       ret = _pkgmgr_dpkg_uninstall_pkg(pkgname);
+
+       _set_backend_state_info(DPKG_REQUEST_COMPLETED);
+
+       return ret;
+}
+
+int _pkgmgr_clear_private_data(char *pkgname)
+{
+       if (pkgname == NULL)
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       char dir_path[256] = {'\0'};
+       int ret = -1;
+       snprintf(dir_path, 255, "/opt/apps/%s/data/", pkgname);
+       ret = __recursive_delete_dir(dir_path);
+       return ret;
+}
diff --git a/backend/src/core/nativeinstallertool.c b/backend/src/core/nativeinstallertool.c
new file mode 100755 (executable)
index 0000000..07464d7
--- /dev/null
@@ -0,0 +1,739 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <ctype.h>
+#include "nativeinstaller.h"
+#include<pkgmgr_installer.h>
+
+#define DEB    "/usr/etc/package-manager/backend/deb"
+
+char *gptrpkgname = NULL;
+extern char scrolllabel[256];
+enum command {
+       INVALID_BACKEND_CMD = 0,
+       INSTALL_BACKEND_CMD = 1,
+       REMOVE_BACKEND_CMD = 2,
+       UPGRADE_BACKEND_CMD = 3,
+       AUDIT_BACKEND_CMD = 4,
+       RECOVER_BACKEND_CMD = 5,
+       CLEAR_BACKEND_CMD = 6
+};
+
+enum optionsflags {
+       INVALID_OPTIONS = 0,
+       FORCE_OVERWITE = 1,
+       IGNORE_DEPENDS = 2,
+       UPDATE_AVAIL = 3,
+};
+
+struct parsedout_st {
+       int reqcommand;
+       char *preq_cmd_string;
+       char *ppkgname;
+       int forceoverwrite;
+};
+
+static int __pkgmgr_show_pkginfo(char *pkgname);
+static int __uninstall_package(char *pkgname);
+static int __clear_private_data(char *pkgname);
+static void __show_usage();
+static int __native_recovery(int lastbackstate);
+static inline int __read_proc(const char *path, char *buf, int size);
+static inline int __find_pid_by_cmdline(const char *dname,
+                                      const char *cmdline, const char *priv);
+static bool __is_another_instance_running(const char *exepath);
+int main_of_backend(char *keyid, char *pkgname, char *reqcommand);
+
+static int __pkgmgr_show_pkginfo(char *pkgname)
+{
+
+       if (pkgname == NULL)
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       pkginfo *info = NULL;
+       info = _pkgmgr_get_installed_pkg_info(pkgname);
+       if (info == NULL) {
+               d_msg_backend(DEBUG_ERR, "(%s) package not exist\n", pkgname);
+       } else {
+               printf("----------------------------\n");
+               printf("PackageName\t: %s\n", info->package_name);
+               printf("Version\t\t: %s\n", info->version);
+               printf("----------------------------\n");
+       }
+       if (info) {
+               free(info);
+               info = NULL;
+       }
+       return 0;
+}
+
+static int __uninstall_package(char *pkgname)
+{
+
+       if (pkgname == NULL)
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       int ret = 0;
+       ret = _pkgmgr_package_uninstall(pkgname);
+       if (ret == NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED) {
+               d_msg_backend(DEBUG_ERR, "[__uninstall_package]%s "
+                                               "not installed\n",
+                             pkgname);
+       } else if (ret != 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "[__uninstall_package]%s uninstall failed(%d)\n",
+                             pkgname, ret);
+       } else {
+               d_msg_backend(DEBUG_ERR,
+                     "[__uninstall_package]%s successfully uninstalled\n",
+                             pkgname);
+       }
+       return ret;
+}
+
+static int __clear_private_data(char *pkgname)
+{
+
+       if (pkgname == NULL)
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       int ret = 0;
+       ret = _pkgmgr_clear_private_data(pkgname);
+       if (ret == NATIVEINSTALLER_SUCCESS) {
+               d_msg_backend(DEBUG_ERR,
+               "[__clear_private_data]%s clear data successful\n", pkgname);
+       } else {
+               d_msg_backend(DEBUG_ERR,
+               "[__clear_private_data]%s clear data failed(%d)\n", pkgname, ret);
+       }
+       return ret;
+}
+
+
+static void __show_usage()
+{
+       printf
+           ("\nbackend usage\n    backend <keyid> <pkgname> <commands> \n\n");
+       printf("<Commands> \n");
+       printf
+               ("\tkeyid <pkgname> install       :"
+               " install package <PackageFile>\n");
+       printf
+               ("\tkeyid <pkgname> remove      : "
+               "uninstall package <PackageName>\n");
+       printf
+               ("\tkeyid dummy recover         :"
+               " recover the system\n");
+}
+
+static int __native_recovery(int lastbackstate)
+{
+       char *pkgname = NULL;
+       int lastreq;
+       int options;
+
+       pkginfo *ptmp_pkginfo = NULL;
+       bool already_installed = false;
+       int err = 0;
+
+       char *installoptions = NULL;
+
+       d_msg_backend(DEBUG_INFO, "Native Installer recovery Entry \n");
+
+       /* which package it was installing and what was state at that time */
+       _get_last_input_info(&pkgname, &lastreq, &options);
+
+       switch (lastbackstate) {
+       case REQUEST_ACCEPTED:
+               /* 
+                * we can restart the last operations 
+                * once again as request was only accepted
+                * but nothing had done 
+                * It will be same as restarting the last request again
+                */
+               d_msg_backend(DEBUG_INFO,
+                     "Native Installer recovery REQUEST_ACCEPTED started \n");
+               switch (lastreq) {
+               case INSTALL_BACKEND_CMD:
+                       ptmp_pkginfo =
+                   _pkgmgr_get_pkg_info(pkgname, &err, &already_installed);
+                       if (err != 0 || ptmp_pkginfo == NULL) {
+                               if (ptmp_pkginfo != NULL) {
+                                       free(ptmp_pkginfo);
+                                       ptmp_pkginfo = NULL;
+                               }
+                               goto RECOVERYERROR;
+                       }
+
+                       break;
+
+               case REMOVE_BACKEND_CMD:
+                       ptmp_pkginfo = _pkgmgr_get_installed_pkg_info(pkgname);
+                       if (ptmp_pkginfo == NULL)
+                               goto RECOVERYERROR;
+                       if (ptmp_pkginfo != NULL) {
+                               free(ptmp_pkginfo);
+                               ptmp_pkginfo = NULL;
+                       }
+                       break;
+               }
+               d_msg_backend(DEBUG_INFO,
+                             " Native Installer recovery REQUEST_ACCEPTED Ended \n");
+
+               _set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+
+       case GOT_PACKAGE_INFO_SUCCESSFULLY:
+               d_msg_backend(DEBUG_INFO,
+                             " Native Installer recovery "
+                               "GOT_PACKAGE_INFO_SUCCESSFULLY started \n");
+               /* 
+                * Package information is been read successfully
+                * For Install and upgrade: This means 
+                *      manifest file has been successfully processed
+                * For remove: This means 
+                *      package was already installed.
+                */
+               switch (lastreq) {
+               case INSTALL_BACKEND_CMD:
+                       err = _pkgmgr_dpkg_install_pkg(pkgname, installoptions);
+                       if (err != 0) {
+                               d_msg_backend(DEBUG_ERR,
+                                             "_pkgmgr_dpkg_install_pkg "
+                                               "return error(%d)\n",
+                                             err);
+                               goto RECOVERYERROR;
+                       }
+                       break;
+
+               case REMOVE_BACKEND_CMD:
+                       err = _pkgmgr_dpkg_uninstall_pkg(pkgname);
+                       if (err != 0) {
+                               d_msg_backend(DEBUG_ERR,
+                                     "_pkgmgr_dpkg_uninstall_pkg "
+                                       "return error(%d)\n",
+                                             err);
+                               /* TO DO clean db and menu screen */
+                               goto RECOVERYERROR;
+                       }
+                       break;
+               }
+               d_msg_backend(DEBUG_INFO,
+                             " Native Installer recovery "
+                               "GOT_PACKAGE_INFO_SUCCESSFULLY ended \n");
+               _set_backend_state_info(DPKG_REQUEST_COMPLETED);
+
+       case DPKG_REQUEST_COMPLETED:
+               d_msg_backend(DEBUG_INFO,
+                             " Native Installer recovery "
+                               "DPKG_REQUEST_COMPLETED started \n");
+
+               d_msg_backend(DEBUG_INFO,
+                             " Native Installer recovery"
+                               " DPKG_REQUEST_COMPLETED ended \n");
+
+               _set_backend_state_info(REQUEST_COMPLETED);
+               break;
+       default:
+               /*
+                * Unknown state
+                * No need to recover
+                */
+               d_msg_backend(DEBUG_INFO,
+                             " Native Installer recovery Default state \n");
+               break;
+
+       }
+       return 0;
+
+RECOVERYERROR:
+       d_msg_backend(DEBUG_ERR, "Error in Recovery error number = (%d)\n",
+                     err);
+       return err;
+}
+
+static inline int __read_proc(const char *path, char *buf, int size)
+{
+       int fd;
+       int ret;
+
+       if (buf == NULL || path == NULL)
+               return -1;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0)
+               return -1;
+
+       ret = read(fd, buf, size - 1);
+       if (ret <= 0) {
+               close(fd);
+               return -1;
+       } else
+               buf[ret] = 0;
+
+       close(fd);
+
+       return ret;
+}
+
+static inline int __find_pid_by_cmdline(const char *dname,
+                                      const char *cmdline, const char *priv)
+{
+       int pid = 0;
+       if (strncmp(cmdline, priv, strlen(DEB)) == 0) {
+               pid = atoi(dname);
+               if (pid != getpgid(pid))
+                       pid = 0;
+               if (pid == getpid())
+                       pid = 0;
+       }
+
+       return pid;
+}
+
+static bool __is_another_instance_running(const char *exepath)
+{
+       DIR *dp;
+       struct dirent *dentry;
+       int pid;
+       int ret;
+       char buf[256] = {0,};
+       char buf1[256] = {0,};
+       dp = opendir("/proc");
+       if (dp == NULL) {
+               return 0;
+       }
+       while ((dentry = readdir(dp)) != NULL) {
+               if (!isdigit(dentry->d_name[0]))
+                       continue;
+               snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
+               ret = __read_proc(buf, buf1, sizeof(buf));
+               if (ret <= 0)
+                       continue;
+               pid = __find_pid_by_cmdline(dentry->d_name, buf1, exepath);
+               if (pid > 0) {
+                       closedir(dp);
+                       return 1;
+               }
+       }
+
+       closedir(dp);
+       return 0;
+
+}
+
+/* 
+*      check if status some other instance is running or not  
+*      if status file exist then back end exit with reason code
+*      another instance is in progress
+*
+*      We can use a vconf entry for checking whether back end
+*      is running properly or not
+*      When we start the back end, we check the value of vconf,
+*      there are following scenario
+*      1) Back end start for the first time. It mean this is the
+*      first time we are calling backend. 
+*      then ther will not be any vconf entry
+*      2) Back end was successfully complete the requested operation
+*      vconf entry will be completed state
+*      3) Back end had not able to complete the operation and
+*      some problem occured in installation like segmentation fault,
+*      Poweroff, low battery.
+*      vconf entry will be in started state
+*      Not-init = -1
+*      completed = 1
+*      started = 0
+*/
+/* int main(int argc, char **argv) */
+int main_of_backend(char *keyid, char *pkgname, char *reqcommand)
+{
+       int ret = -1;
+       struct parsedout_st pardata = { 0 };
+       int backendstate;
+       _d_msg_init("backend");
+       d_msg_backend(DEBUG_RESULT, "Backend version: %s\n",
+                     NATIVE_INSTALLER_VERSION);
+       if (reqcommand == NULL) {
+               d_msg_backend(DEBUG_ERR,"reqcommand is NULL\n");
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       }
+       if (strcmp(reqcommand, "recover") != 0) {
+               if (keyid == NULL || pkgname == NULL) {
+                       d_msg_backend(DEBUG_ERR,
+                                     " Either keyid/pkgname is NULL\n");
+                       return NATIVEINSTALLER_ERR_WRONG_PARAM;
+               }
+       }
+
+       if (strcmp(reqcommand, "install") == 0) {
+               pardata.reqcommand = INSTALL_BACKEND_CMD;
+               pardata.preq_cmd_string = strdup("install");
+               if (pardata.preq_cmd_string == NULL) {
+                       d_msg_backend(DEBUG_ERR,
+                                     "strdup failed due to insufficient memory\n");
+               }
+       } else if (strcmp(reqcommand, "remove") == 0) {
+               pardata.reqcommand = REMOVE_BACKEND_CMD;
+               pardata.preq_cmd_string = strdup("uninstall");
+               if (pardata.preq_cmd_string == NULL) {
+                       d_msg_backend(DEBUG_ERR,
+                                     "strdup failed due to insufficient memory\n");
+               }
+       } else if (strcmp(reqcommand, "clear") == 0) {
+               pardata.reqcommand = CLEAR_BACKEND_CMD;
+               pardata.preq_cmd_string = strdup("clear");
+               if (pardata.preq_cmd_string == NULL) {
+                       d_msg_backend(DEBUG_ERR,
+                                     "strdup failed due to insufficient memory\n");
+               }
+       }else if (strcmp(reqcommand, "recover") == 0) {
+               pardata.reqcommand = RECOVER_BACKEND_CMD;
+               pardata.preq_cmd_string = strdup("recover");
+               if (pardata.preq_cmd_string == NULL) {
+                       d_msg_backend(DEBUG_ERR,
+                                     "strdup failed due to insufficient memory\n");
+               }
+       } else {
+               d_msg_backend(DEBUG_INFO, "wrong input parameter\n");
+               d_msg_backend(DEBUG_RESULT, "%d\n",
+                             NATIVEINSTALLER_ERR_WRONG_PARAM);
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       }
+
+       pardata.ppkgname = pkgname;
+       backendstate = _get_backend_state();
+
+       if (RECOVER_BACKEND_CMD == pardata.reqcommand) {
+               if (0 == backendstate) {
+                       int lastbackstate;
+
+                       /* check the current state of backend */
+                       lastbackstate = _get_backend_state_info();
+
+                       if (REQUEST_COMPLETED == lastbackstate) {
+                               d_msg_backend(DEBUG_INFO,
+                                             " Native Installer recovery is in REQUEST_COMPLETED  \n");
+                               snprintf(scrolllabel, sizeof(scrolllabel), "No Recovery Needed");
+                       } else
+                               ret = __native_recovery(lastbackstate);
+                               if(ret == 0)
+                                       snprintf(scrolllabel, sizeof(scrolllabel), "Recovery Success");
+
+                       /* set the backend state as completed */
+                       _set_backend_state(1);
+               } else {
+                       /* nothing to recover */
+                       d_msg_backend(DEBUG_INFO,
+                                     " Native Installer recovery Nothing need to be done\n");
+                       ret = 0;
+                       snprintf(scrolllabel, sizeof(scrolllabel), "No Recovery Needed");
+               }
+               d_msg_backend(DEBUG_RESULT, "%d\n", ret);
+               return ret;
+       }
+
+       /* Non Recovery case */
+
+       if (0 == backendstate) {
+               /* back state is in wrong state; 
+                * either other instance is running 
+                * or some thing went wrong in last execution of backend 
+                */
+               /* if last execution had problem 
+                * then request is for the same operation again
+                * then reexecute the same command 
+                * other wise roll back the old command
+                */
+               char *pkgname = NULL;
+               int lastreq;
+               int options;
+
+               /* which package it was installing and 
+               what was state at that time */
+               _get_last_input_info(&pkgname, &lastreq, &options);
+
+               if ((pardata.reqcommand == lastreq) &&
+                   (strcmp(pkgname, pardata.ppkgname) == 0)) {
+                       /* same command is executed for 2nd time */
+                       /* this is same as recover  */
+                       /* call recover */
+                       int lastbackstate;
+
+                       /* check the current state of backend */
+                       lastbackstate = _get_backend_state_info();
+                       /* Publish Notification that backend has started */
+                       _broadcast_status_notification(pardata.ppkgname,
+                                                           "start",
+                                                   pardata.preq_cmd_string);
+                       _broadcast_status_notification(pardata.ppkgname,
+                                                           "command",
+                                                   pardata.preq_cmd_string);
+                       if (REQUEST_COMPLETED == lastbackstate) {
+                               d_msg_backend(DEBUG_INFO,
+                                             " Native Installer recovery"
+                                             " is in REQUEST_COMPLETED  \n");
+                       } else
+                               ret = __native_recovery(lastbackstate);
+
+                       d_msg_backend(DEBUG_INFO,
+                                     "Recovery of old instance failed errno: %d\n ",
+                                     ret);
+                       d_msg_backend(DEBUG_RESULT, "%d\n", ret);
+
+                       if (ret != 0) {
+                               char *errstr = NULL;
+                               _error_no_to_string(ret, &errstr);
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                           "error", errstr);
+                               stat_cb(pardata.ppkgname, "error", errstr);
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                           "end", "fail");
+                               stat_cb(pardata.ppkgname, "end", "fail");
+                               d_msg_backend(DEBUG_ERR,
+                                             "recovery failed with err(%d) (%s)\n",
+                                             ret, errstr);
+                       } else {
+                               d_msg_backend(DEBUG_INFO,
+                                             "recovery of last request success\n");
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                           "end", "ok");
+                               stat_cb(pardata.ppkgname, "end", "ok");
+                       }
+
+                       /* set the backend state as completed */
+                       _set_backend_state(1);
+               } else {
+                       /* 
+                        * Another Instance may be running 
+                        * Check for it 
+                        */
+                       ret = __is_another_instance_running(DEB);
+                       if (ret == 1) {
+
+                               if (pardata.ppkgname) {
+                                       _broadcast_status_notification
+                                           (pardata.ppkgname, "error",
+                                            "Another Instance Running");
+                                       stat_cb(pardata.ppkgname, "error",
+                                               "Another Instance Running");
+                                       _broadcast_status_notification
+                                           (pardata.ppkgname, "end", "fail");
+                                       stat_cb(pardata.ppkgname, "end",
+                                               "fail");
+                               } else {
+                                       _broadcast_status_notification(
+                                                               "unknown",
+                                                                   "error",
+                                                                   "Another Instance Running");
+                                       stat_cb("unknown", "error",
+                                               "Another Instance Running");
+                                       _broadcast_status_notification(
+                                                               "unknown",
+                                                                   "end",
+                                                                   "fail");
+                                       stat_cb("unknown", "end", "fail");
+                               }
+                               d_msg_backend(DEBUG_INFO,
+                                             "Request Failed as "
+                                             "Another Instance is running \n");
+
+                               ret = NATIVEINSTALLER_ERR_RESOURCE_BUSY;
+                               return ret;
+                       }
+
+               }
+
+       }
+
+       /* set the backend state as started */
+       _set_backend_state(0);
+
+#ifdef SEND_PKGPATH
+       gptrpkgname = strdup(pardata.ppkgname);
+
+       /* Publish Notification that backend has started */
+       if (pardata.ppkgname)
+               _broadcast_status_notification(pardata.ppkgname, "start",
+                                           pardata.preq_cmd_string);
+       else
+               _broadcast_status_notification("unknown", "start",
+                                           pardata.preq_cmd_string);
+#endif
+
+       _set_backend_state_info(REQUEST_ACCEPTED);
+
+       /* Set the input request info */
+       _save_last_input_info(pardata.ppkgname, pardata.reqcommand,
+                         pardata.forceoverwrite);
+
+       switch (pardata.reqcommand) {
+       case INSTALL_BACKEND_CMD:
+               {
+                       d_msg_backend(DEBUG_INFO, "[%s] --install %s\n",
+                                     "backend", pardata.ppkgname);
+#ifdef SEND_PKGPATH
+                       _broadcast_status_notification(pardata.ppkgname,
+                                                "command",
+                                                   "Install");
+#endif
+                       if (pardata.forceoverwrite == FORCE_OVERWITE) {
+                               d_msg_backend(DEBUG_INFO,
+                                             "[%s] --install %s --force-overwrite\n",
+                                             "backend", pardata.ppkgname);
+                               ret =
+                                   _pkgmgr_package_install(pardata.ppkgname,
+                                                          true,
+                                                          "--force-overwrite");
+                       } else {
+                               d_msg_backend(DEBUG_INFO, "[%s] --install %s\n",
+                                             "backend", pardata.ppkgname);
+                               ret =
+                                   _pkgmgr_package_install(pardata.ppkgname,
+                                                          false, NULL);
+                       }
+                       if (ret == NATIVEINSTALLER_ERR_NEED_USER_CONFIRMATION) {
+                               break;
+                       }
+                       else if (ret == NATIVEINSTALLER_SUCCESS) {
+                               d_msg_backend(DEBUG_INFO, "install success\n");
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                              "end", "ok");
+                               stat_cb(pardata.ppkgname, "end", "ok");
+                               }
+                       else {
+
+                               char *errstr = NULL;
+                               _error_no_to_string(ret, &errstr);
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                              "error", errstr);
+                               stat_cb(pardata.ppkgname, "error", errstr);
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                              "end", "fail");
+                               sleep(2);
+                               stat_cb(pardata.ppkgname, "end", "fail");
+                               d_msg_backend(DEBUG_ERR,
+                                             "install failed with err(%d) (%s)\n",
+                                             ret, errstr);
+                       } 
+               }
+               break;
+       case REMOVE_BACKEND_CMD:
+               {
+                       d_msg_backend(DEBUG_INFO, "[%s] uninstall %s\n",
+                                     "backend", pardata.ppkgname);
+#ifdef SEND_PKGPATH
+                       _broadcast_status_notification(pardata.ppkgname,
+                                                      "command",
+                                                      "Remove");
+#endif
+                       ret = __uninstall_package(pardata.ppkgname);
+                       if (ret != 0) {
+                               char *errstr = NULL;
+                               _error_no_to_string(ret, &errstr);
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                           "error", errstr);
+                               stat_cb(pardata.ppkgname, "error", errstr);
+                               sleep(2);
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                           "end", "fail");
+                               stat_cb(pardata.ppkgname, "end", "fail");
+                               d_msg_backend(DEBUG_ERR,
+                                             "remove failed with err(%d) (%s)\n",
+                                             ret, errstr);
+                       } else {
+                               d_msg_backend(DEBUG_INFO, "remove success\n");
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                              "end", "ok");
+                               stat_cb(pardata.ppkgname, "end", "ok");
+                       }
+               }
+               break;
+       case CLEAR_BACKEND_CMD:
+               {
+                       d_msg_backend(DEBUG_INFO, "[%s] clear data %s\n",
+                                     "backend", pardata.ppkgname);
+#ifdef SEND_PKGPATH
+                       _broadcast_status_notification(pardata.ppkgname,
+                                                      "command",
+                                                      "clear");
+#endif
+                       ret = __clear_private_data(pardata.ppkgname);
+                       if (ret != 0) {
+                               char *errstr = NULL;
+                               _error_no_to_string(ret, &errstr);
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                           "error", errstr);
+                               stat_cb(pardata.ppkgname, "error", errstr);
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                           "end", "fail");
+                               stat_cb(pardata.ppkgname, "end", "fail");
+                               d_msg_backend(DEBUG_ERR,
+                                             "clear data failed with err(%d) (%s)\n",
+                                             ret, errstr);
+                       } else {
+                               d_msg_backend(DEBUG_INFO, "clear data success\n");
+                               _broadcast_status_notification(pardata.ppkgname,
+                                                              "end", "ok");
+                               stat_cb(pardata.ppkgname, "end", "ok");
+                       }
+               }
+               break;
+       default:
+               {
+                       _broadcast_status_notification("unknown", "command",
+                                                      "unknown");
+                       _broadcast_status_notification("unknown", "error",
+                                                      "not supported");
+                       stat_cb("unknown", "error", "not supported");
+                       _broadcast_status_notification("unknown", 
+                                                      "end", "fail");
+                       stat_cb("unknown", "end", "fail");
+                       d_msg_backend(DEBUG_ERR, "unknown command \n");
+                       __show_usage();
+                       ret = NATIVEINSTALLER_ERR_WRONG_PARAM;
+               }
+       }
+
+       if (gptrpkgname) {
+               free(gptrpkgname);
+               gptrpkgname = NULL;
+       }
+       if (_get_backend_state_info() != DPKG_REQUEST_PENDING) {
+               
+               _set_backend_state_info(REQUEST_COMPLETED);
+               /* set the backend state as completed */
+               _set_backend_state(1);
+               d_msg_backend(DEBUG_RESULT, "%d\n", ret);
+               _d_msg_deinit();
+       }
+
+       
+       return ret;
+}
+
diff --git a/backend/src/dpkg/nativeinstallerdpkg.c b/backend/src/dpkg/nativeinstallerdpkg.c
new file mode 100755 (executable)
index 0000000..a6c0c36
--- /dev/null
@@ -0,0 +1,1229 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#define __USE_GNU
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <wait.h>
+#include <stdio.h>
+#include <signal.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>             /* for isspace () */
+#include <time.h>
+#include <vconf.h>
+
+#include "native_installer_util.h"
+#include "nativeinstaller.h"
+
+#define INSTALL_SCRIPT         "/usr/bin/install_spk.sh"
+#define UNINSTALL_SCRIPT       "/usr/bin/uninstall_spk.sh"
+#define UPDATE_PKG_SCRIPT      "/usr/bin/update_avail_spk.sh"
+#define AUDIT_SCRIPT           "/usr/bin/audit_spk_sh"
+
+typedef enum __dpkg_request_type {
+       INSTALL_REQ,
+       UNINSTALL_REQ,
+       AUDIT_REQ,
+       UPGRADE_REQ,
+       UPDATE_CONTROL_REQ,
+} dpkg_request_type;
+
+typedef enum __dpkgaction {
+       DPKGNONE,
+       DPKGINSTALL,
+       DPKGCONFIGURE,
+       DPKGUNINSTALL,
+       DPKGPURGE,
+       DPKGUPGRADE,
+       DPKGUNKNOWN,
+       DPKGMAXOPR
+} dpkgaction;
+
+typedef struct __operationsinfo {
+       dpkgaction action;
+       int lastactivity;
+       int totalactivity;
+       struct __operationsinfo *nextoperations;
+} operationsinfo;
+
+typedef struct __dpkgoperations {
+       dpkg_request_type requesttype;
+       dpkgaction runningoperations;
+       operationsinfo *operationshead;
+       int totaloperations;
+       int currentprogress;
+       int percentageprogress;
+} dpkgoperations;
+
+
+dpkgoperations dpkgrequestedoperations;
+static int is_operations_cleaned;
+extern char *gptrpkgname;
+
+static char *__make_notification_string(dpkg_request_type request_type, 
+                               char *status,
+                            char *msg);
+static int __map_dpkg_operation_to_enum(char *action);
+static int __native_installer_init_operations(dpkg_request_type requesttype);
+static int __pkgmgr_dpkg_xsystem(dpkg_request_type requesttype, 
+                               const char *argv[]);
+static void __native_installer_clean_operations();
+static void __dpkg_process_status(char *pkgqstate);
+static void __perform_dpkg_status_fd_read(int fd);
+static void __dpkg_process_action(char *action);
+static void __process_dpkg_status_line(char *line);
+extern char evt_notification[64];
+
+static char *__make_notification_string(dpkg_request_type request_type, 
+                               char *status,
+                            char *msg)
+{
+       char requeststr[16];
+       char *statusstring = NULL;
+       int len = strlen(status) + strlen(msg);
+       len = len + 16;
+       statusstring = (char *)malloc(len);
+       if (PM_UNLIKELY(statusstring == NULL)) {
+               d_msg_backend(DEBUG_ERR, "Malloc Failed\n");
+               return NULL;
+       }
+       switch (request_type) {
+       case INSTALL_REQ:
+               snprintf(requeststr, sizeof(requeststr), "Install");
+               break;
+       case UNINSTALL_REQ:
+               snprintf(requeststr, sizeof(requeststr), "Remove");
+               break;
+       case AUDIT_REQ:
+               snprintf(requeststr, sizeof(requeststr), "Audit");
+               break;
+       case UPGRADE_REQ:
+               snprintf(requeststr, sizeof(requeststr), "Update");
+               break;
+       default:
+               snprintf(requeststr, sizeof(requeststr), "default");
+               break;
+       }
+
+       snprintf(statusstring, len, "%s\t%s\t%s", requeststr, status, msg);
+       return statusstring;
+
+}
+
+static int __map_dpkg_operation_to_enum(char *action)
+{
+       if (strncmp(action, "install", strlen("install")) == 0)
+               return DPKGINSTALL;
+       else if (strncmp(action, "configure", strlen("configure")) == 0)
+               return DPKGCONFIGURE;
+       else if (strncmp(action, "purge", strlen("purge")) == 0)
+               return DPKGPURGE;
+       else if (strncmp(action, "remove", strlen("remove")) == 0)
+               return DPKGUNINSTALL;
+       else if (strncmp(action, "upgrade", strlen("upgrade")) == 0)
+               return DPKGUPGRADE;
+       else
+               return DPKGUNKNOWN;
+}
+
+static void __native_installer_clean_operations()
+{
+       operationsinfo *ptemp = dpkgrequestedoperations.operationshead;
+       operationsinfo *ptempnext;
+       while (ptemp != NULL) {
+               ptempnext = ptemp->nextoperations;
+               free(ptemp);
+               ptemp = ptempnext;
+       }
+       dpkgrequestedoperations.operationshead = NULL;
+}
+
+/* This function will be called when status message
+received by installer from dpkg */
+
+static void __dpkg_process_status(char *pkgqstate)
+{
+       /* status:   <pkg>:  <pkg  qstate> */
+       int increment = 0;
+       int increamentactivity = 0;
+       int expectedpercentage = 0;
+
+       d_msg_backend(DEBUG_INFO, "__dpkg_process_status :: %s \n", pkgqstate);
+       d_msg_backend(DEBUG_INFO,
+                     "__dpkg_process_status current request type:: %d Current running Operations = %d \n",
+                     dpkgrequestedoperations.requesttype,
+                     dpkgrequestedoperations.runningoperations);
+       switch (dpkgrequestedoperations.requesttype) {
+       case INSTALL_REQ:
+               {
+                       switch (dpkgrequestedoperations.runningoperations) {
+                       case DPKGINSTALL:
+                               {
+                                       operationsinfo *pinstall =
+                                           dpkgrequestedoperations.operationshead;
+                                       if (pinstall == NULL)
+                                               goto RETURN;
+
+                                       if (pinstall->action != DPKGINSTALL)
+                                               goto RETURN;
+
+                                       if (strncmp(pkgqstate, "half-installed",
+                                                   strlen("half-installed")) == 0) {
+                                               if (pinstall->lastactivity == 1) {
+                                       /* got "half-installed" repeated times */
+                                                       increment = 5;
+                                               } else if (pinstall->lastactivity == 0) {
+                                       /* got  "half-installed" first times  */
+                                                       pinstall->lastactivity = 1;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else
+                                           if (strncmp(pkgqstate, "unpacked",
+                                                       strlen("unpacked")) == 0) {
+                                               if (pinstall->lastactivity == 2) {
+                                       /* got "unpacked" repeated times */
+                                                       increment = 5;
+                                               } else if (pinstall->lastactivity == 1) {
+                                       /* got  "unpacked" first times  */
+                                                       pinstall->lastactivity =
+                                                           2;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       }
+                                       break;
+                               }
+
+                       case DPKGCONFIGURE:
+                               {
+                                       operationsinfo *pconfigure =
+                                           dpkgrequestedoperations.operationshead;
+                                       if (pconfigure == NULL)
+                                               goto RETURN;
+
+                                       if (pconfigure->action != DPKGCONFIGURE)
+                                               goto RETURN;
+                                       if (strncmp(pkgqstate, "unpacked",
+                                                   strlen("unpacked")) == 0) {
+                                               if (pconfigure->lastactivity == 1) {
+                                       /* got "unpacked" repeated times */
+                                                       increment = 5;
+                                               } else if (pconfigure->lastactivity == 0) {
+                                       /* got  "unpacked" first times  */
+                                                       pconfigure->lastactivity = 1;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "half-configured",
+                                                          strlen("half-configured")) == 0) {
+                                               if (pconfigure->lastactivity == 2) {
+                                       /* got "half-configured" repeated times */
+                                                       increment = 5;
+                                               } else if (pconfigure->lastactivity == 1) {
+                                       /* got  "half-configured" first times  */
+                                                       pconfigure->lastactivity = 2;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "installed",
+                                                          strlen("installed")) == 0) {
+                                               increamentactivity = 1;
+                                               dpkgrequestedoperations.percentageprogress = 100;
+                                               increment = 0;
+                                               dpkgrequestedoperations.operationshead =
+                                                   pconfigure->nextoperations;
+                                               if (pconfigure)
+                                                       free(pconfigure);
+                                       }
+                                       break;
+                               }
+                       default:
+                               break;
+
+                       }
+                       if (strncmp(pkgqstate, "installed", strlen("installed")) == 0) {
+                               increamentactivity = 0;
+                               dpkgrequestedoperations.percentageprogress = 100;
+                               increment = 0;
+                       }
+                       break;
+               }
+
+       case UNINSTALL_REQ:
+               {
+                       switch (dpkgrequestedoperations.runningoperations) {
+                       case DPKGUNINSTALL:
+                               {
+                                       operationsinfo *ptemp =
+                                           dpkgrequestedoperations.operationshead;
+                                       if (!ptemp)
+                                               goto RETURN;
+
+                                       if (ptemp->action != DPKGUNINSTALL)
+                                               goto RETURN;
+
+                                       if (strncmp(pkgqstate, "half-configured",
+                                                   strlen("half-configured")) == 0) {
+                                               if (ptemp->lastactivity == 1) {
+                               /* got "half-configured" repeated times */
+                                                       increment = 5;
+                                               } else if (ptemp->lastactivity == 0) {
+                               /* got  "half-configured" first times  */
+                                                       ptemp->lastactivity = 1;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else
+                                           if (strncmp(pkgqstate, "half-installed",
+                                                       strlen("half-installed")) == 0) {
+                                               if (ptemp->lastactivity == 2) {
+                               /* got "half-installed" repeated times */
+                                                       increment = 5;
+                                               } else if (ptemp->lastactivity == 1) {
+                               /* got  "half-installed" first times  */
+                                                       ptemp->lastactivity = 2;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "config-files",
+                                                          strlen("config-files")) == 0) {
+                                               if (ptemp->lastactivity == 3) {
+                                       /* got "config-files" repeated times */
+                                                       increment = 5;
+                                               } else if (ptemp->lastactivity == 2) {
+                                       /* got  "config-files" first times  */
+                                                       ptemp->lastactivity = 3;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "not-installed",
+                                                          strlen("not-installed")) == 0) {
+                                               increamentactivity = 1;
+                                               dpkgrequestedoperations.percentageprogress = 100;
+                                               increment = 0;
+                                               dpkgrequestedoperations.operationshead =
+                                                   ptemp->nextoperations;
+                                               if (ptemp)
+                                                       free(ptemp);
+                                       }
+                                       break;
+                               }
+
+                       default:
+                               break;
+
+                       }
+                       if (strncmp
+                           (pkgqstate, "not-installed",
+                            strlen("not-installed")) == 0) {
+                               increamentactivity = 0;
+                               dpkgrequestedoperations.percentageprogress = 100;
+                               increment = 0;
+                       }
+                       break;
+               }
+
+       case UPGRADE_REQ:
+               {
+                       switch (dpkgrequestedoperations.runningoperations) {
+                       case DPKGUPGRADE:
+                               {
+                                       operationsinfo *pupgrade =
+                                           dpkgrequestedoperations.
+                                           operationshead;
+                       /*d_msg_backend(DEBUG_INFO, "DpkgProcessStatus ::
+                       Inside DPKGUPGRADE %s \n", pkgqstate); */
+                                       if (pupgrade == NULL)
+                                               goto RETURN;
+                                       if (pupgrade->action != DPKGUPGRADE)
+                                               goto RETURN;
+
+                                       if (strncmp(pkgqstate, "half-configured",
+                                                   strlen("half-configured")) == 0) {
+                                               if (pupgrade->lastactivity == 1) {
+                               /* got "half-configured" repeated times */
+                                                       increment = 5;
+                                               } else if (pupgrade->lastactivity == 0) {
+                               /* got  "half-configured" first times  */
+                                                       pupgrade->lastactivity =
+                                                           1;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "unpacked",
+                                                          strlen("unpacked")) == 0) {
+                                               if (pupgrade->lastactivity == 2) {
+                               /* got "unpacked" repeated times */
+                                                       increment = 5;
+                                               } else if (pupgrade->lastactivity == 1) {
+                               /* got  "unpacked" first times  */
+                                                       pupgrade->lastactivity =
+                                                           2;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "half-installed",
+                                                          strlen("half-installed")) == 0) {
+                                               if (pupgrade->lastactivity 
+                                                       == 3) {
+                               /* got "half-installed" repeated times */
+                                                       increment = 5;
+                                               } else if (pupgrade->lastactivity == 2) {
+                               /* got  "half-installed" first times  */
+                                                       pupgrade->lastactivity 
+                                                       = 3;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "unpacked",
+                                                  strlen("unpacked")) == 0) {
+                                               if (pupgrade->lastactivity == 4) {
+                                       /* got "unpacked" repeated times */
+                                                       increment = 5;
+                                               } else if (pupgrade->lastactivity == 3) {
+                                       /* got  "unpacked" first times  */
+                                                       pupgrade->lastactivity 
+                                                               = 4;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       }
+                                       break;
+                               }
+
+                       case DPKGCONFIGURE:
+                               {
+                                       operationsinfo *pconfigure =
+                                           dpkgrequestedoperations.operationshead;
+                       /*d_msg_backend(DEBUG_INFO, "DpkgProcessStatus ::
+                       Inside DPKGCONFIGURE %s \n", pkgqstate); */
+                                       if (pconfigure == NULL)
+                                               goto RETURN;
+
+                                       if (pconfigure->action != DPKGCONFIGURE)
+                                               goto RETURN;
+                                       if (strncmp(pkgqstate, "unpacked",
+                                                   strlen("unpacked")) == 0) {
+                                               if (pconfigure->lastactivity == 1) {
+                                       /* got "unpacked" repeated times */
+                                                       increment = 5;
+                                               } else if (pconfigure->lastactivity == 0) {
+                                       /* got  "unpacked" first times  */
+                                                       pconfigure->lastactivity
+                                                           = 1;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "half-configured",
+                                                          strlen("half-configured")) == 0) {
+                                               if (pconfigure->lastactivity == 2) {
+                               /* got "half-configured" repeated times */
+                                                       increment = 5;
+                                               } else if (pconfigure->lastactivity == 1) {
+                               /* got  "half-configured" first times  */
+                                                       pconfigure->lastactivity
+                                                           = 2;
+                                                       increamentactivity = 1;
+                                                       increment = 0;
+                                               }
+                                       } else if (strncmp(pkgqstate, "installed",
+                                                          strlen("installed")) == 0) {
+                                               increamentactivity = 1;
+                                               dpkgrequestedoperations.percentageprogress = 100;
+                                               increment = 0;
+                                               dpkgrequestedoperations.operationshead =
+                                                   pconfigure->nextoperations;
+                                               if (pconfigure)
+                                                       free(pconfigure);
+                                       }
+                                       break;
+                               }
+                       default:
+                               d_msg_backend(DEBUG_ERR,
+                                             "__dpkg_process_status ::"
+                                               " Inside default %s \n",
+                                             pkgqstate);
+                               break;
+
+                       }
+                       if (strncmp(pkgqstate, "installed",
+                                   strlen("installed")) == 0) {
+                               increamentactivity = 0;
+                               dpkgrequestedoperations.percentageprogress = 100;
+                               increment = 0;
+                       }
+                       break;
+               }
+       default:
+               break;
+
+       }
+
+       if (increamentactivity == 1) {
+               dpkgrequestedoperations.currentprogress += 1;
+               if (dpkgrequestedoperations.currentprogress >
+                   dpkgrequestedoperations.totaloperations)
+                       dpkgrequestedoperations.currentprogress =
+                           dpkgrequestedoperations.totaloperations;
+       }
+
+       expectedpercentage =
+           (dpkgrequestedoperations.currentprogress * 100) /
+           dpkgrequestedoperations.totaloperations;
+       if (dpkgrequestedoperations.percentageprogress < expectedpercentage)
+               dpkgrequestedoperations.percentageprogress = expectedpercentage;
+       else
+               dpkgrequestedoperations.percentageprogress += increment;
+
+       if (dpkgrequestedoperations.percentageprogress == 100) {
+               operationsinfo *ptemp = dpkgrequestedoperations.operationshead;
+               operationsinfo *ptempnext;
+               while (ptemp != NULL) {
+                       ptempnext = ptemp->nextoperations;
+                       free(ptemp);
+                       ptemp = ptempnext;
+               }
+               dpkgrequestedoperations.operationshead = NULL;
+       }
+       return;
+RETURN:
+       d_msg_backend(DEBUG_ERR, "__dpkg_process_status :: Error Happened \n");
+       return;
+
+}
+
+static void __dpkg_process_action(char *action)
+{
+       /* This function will be called when  */
+       dpkgaction currentaction = DPKGUNKNOWN;
+
+       currentaction = __map_dpkg_operation_to_enum(action);
+
+       if (currentaction <= DPKGNONE || currentaction >= DPKGUNKNOWN)
+               return;
+
+       d_msg_backend(DEBUG_INFO, "__dpkg_process_action :: %s = %d \n", action,
+                     currentaction);
+       d_msg_backend(DEBUG_INFO,
+                     "__dpkg_process_action current request type::"
+                     " %d Current running Operations = %d \n",
+                     dpkgrequestedoperations.requesttype,
+                     dpkgrequestedoperations.runningoperations);
+       switch (dpkgrequestedoperations.requesttype) {
+       case INSTALL_REQ:
+               {
+                       switch (currentaction) {
+                       case DPKGINSTALL:
+                               {
+                                       switch (dpkgrequestedoperations.runningoperations) {
+                                       case DPKGNONE:
+                                               {
+                                                       dpkgrequestedoperations.runningoperations =
+                                                           DPKGINSTALL;
+
+                                                       break;
+                                               }
+                                       default:
+                                               break;
+                                       }
+                                       break;
+                               }
+
+                       case DPKGCONFIGURE:
+                               {
+                                       switch (dpkgrequestedoperations.runningoperations) {
+                                       case DPKGINSTALL:
+                                               {
+                                                       operationsinfo *ptemp =
+                                                       dpkgrequestedoperations.operationshead;
+                                                       dpkgrequestedoperations.operationshead =
+                                                           ptemp->nextoperations;
+                                                       free(ptemp);
+
+                                                       dpkgrequestedoperations.runningoperations =
+                                                           DPKGCONFIGURE;
+                                               }
+                                               break;
+                                       default:
+                                               break;
+                                       }
+                                       break;
+                               }
+                       default:
+                               break;
+                       }
+                       break;
+               }
+
+       case UNINSTALL_REQ:
+               {
+                       switch (currentaction) {
+                       case DPKGUNINSTALL:
+                               {
+                                       switch (dpkgrequestedoperations.runningoperations) {
+                                       case DPKGNONE:
+                                               {
+                                                       dpkgrequestedoperations.runningoperations =
+                                                           DPKGUNINSTALL;
+                                                       break;
+                                               }
+                                       default:
+                                               break;
+                                       }
+                                       break;
+                               }
+                       default:
+                               break;
+                       }
+                       break;
+               }
+       case UPGRADE_REQ:
+               {
+                       switch (currentaction) {
+                       case DPKGUPGRADE:
+                               {
+                                       switch (dpkgrequestedoperations.runningoperations) {
+                                       case DPKGNONE:
+                                               {
+                                                       dpkgrequestedoperations.runningoperations =
+                                                           DPKGUPGRADE;
+                                                       break;
+                                               }
+                                       default:
+                                               break;
+                                       }
+                                       break;
+                               }
+
+                       case DPKGCONFIGURE:
+                               {
+                                       switch
+                                           (dpkgrequestedoperations.runningoperations) {
+                                       case DPKGUPGRADE:
+                                               {
+                                                       operationsinfo *ptemp =
+                                                           dpkgrequestedoperations.operationshead;
+                                                       dpkgrequestedoperations.operationshead =
+                                                           ptemp->nextoperations;
+                                                       free(ptemp);
+
+                                                       dpkgrequestedoperations.runningoperations =
+                                                           DPKGCONFIGURE;
+                                               }
+                                               break;
+                                       default:
+                                               break;
+                                       }
+                                       break;
+                               }
+                       default:
+                               break;
+                       }
+                       break;
+               }
+       default:
+               break;
+
+       }
+}
+
+/**
+       dpkg sends strings like this:
+       'status:   <pkg>:  <pkg  qstate>'
+       errors look like this:
+       'status: /var/cache/apt/archives/krecipes_0.8.1-0ubuntu1_i386.deb 
+       : error : trying to overwrite
+       `/usr/share/doc/kde/HTML/en/krecipes/krectip.png', 
+       which is also in package krecipes-data 
+       and conffile-prompt like this
+       'status: conffile-prompt: conffile : 'current-conffile' 'new-conffile' 
+       useredited distedited
+
+       Newer versions of dpkg sent also:
+       'processing: install: pkg'
+       'processing: configure: pkg'
+       'processing: remove: pkg'
+       'processing: trigproc: trigger'
+       'processing: upgrade: pkg'
+
+*/
+
+static void __process_dpkg_status_line(char *line)
+{
+       /* the status we output */
+       int value = 0;
+       char valuestr[4];
+       char status[256];
+       /*char *notification = NULL; */
+       int len;
+       char *tok[6];
+       if (line == NULL)
+               return;
+       d_msg_backend(DEBUG_INFO, "%s\n", line);
+
+       if (is_operations_cleaned == 1) {
+               d_msg_backend(DEBUG_ERR,
+                             "ignoring status: Operations Cancelled \n");
+               return;
+       }
+       _tok_split_string(':', line, tok, sizeof(tok) / sizeof(tok[0]));
+       if (tok[0] == NULL || tok[1] == NULL || tok[2] == NULL) {
+               d_msg_backend(DEBUG_ERR, "ignoring line: not enough ':' \n");
+               return;
+       }
+       char *action = tok[2];
+
+       /* 'processing' from dpkg looks like */
+       /* 'processing: <action>: package */
+       if (strncmp(tok[0], "processing", strlen("processing")) == 0) {
+               action = tok[1];
+               __dpkg_process_action(action);
+
+               value = dpkgrequestedoperations.percentageprogress;
+               snprintf(valuestr, 4, "%d", value);
+               _broadcast_status_notification(tok[2], "install_percent",
+                                              valuestr);
+               stat_cb(tok[2], "install_percent", valuestr);
+               len = snprintf(status, sizeof(status), "status: %s: %d\n",
+                              tok[2], value);
+               d_msg_backend(DEBUG_INFO, "%s", status);
+               return;
+       }
+
+       if (strncmp(action, "error", strlen("error")) == 0) {
+               
+               /* sometimes there is ":" in the error string so that
+               the error message is split between tok[3] and tok[4],
+               concat them again */
+               if (tok[4] != NULL)
+                       tok[3][strlen(tok[3])] = ':';
+
+               snprintf(valuestr, 4, "%d", value);
+               _broadcast_status_notification(tok[1], "error", tok[3]);
+               stat_cb(tok[1], "error", tok[3]);
+               /*sleep(1); */
+               len = snprintf(status, sizeof(status), "error: %s: %s\n",
+                              tok[1], tok[3]);
+               d_msg_backend(DEBUG_INFO, "%s", status);
+               __native_installer_clean_operations();
+               is_operations_cleaned = 1;
+               return;
+       }
+       /* status: conffile-prompt: conffile : 'current-conffile' 
+       'new-conffile' useredited distedited */
+       if (strncmp(action, "conffile", strlen("conffile")) == 0) {
+               value += 10;
+               snprintf(valuestr, 4, "%d", value);
+               _broadcast_status_notification(tok[1], "install_percent",
+                                              valuestr);
+               stat_cb(tok[1], "install_percent", valuestr);
+               /*sleep(1); */
+               len = snprintf(status, sizeof(status), "status: %s: %d\n",
+                              tok[1], value);
+               d_msg_backend(DEBUG_INFO, "%s", status);
+               return;
+       }
+
+       /* status:   <pkg>:  <pkg  qstate> */
+       if (strncmp(tok[0], "status", strlen("status")) == 0) {
+               __dpkg_process_status(tok[2]);
+               value = dpkgrequestedoperations.percentageprogress;
+               snprintf(valuestr, 4, "%d", value);
+               _broadcast_status_notification(tok[1], "install_percent",
+                                              valuestr);
+               stat_cb(tok[1], "install_percent", valuestr);
+               /*sleep(1); */
+               len = snprintf(status, sizeof(status), "status: %s: %d\n",
+                              tok[1], value);
+               d_msg_backend(DEBUG_INFO, "%s", status);
+               return;
+       }
+
+       len = snprintf(status, sizeof(status),
+                      "(parsed from dpkg) pkg: %s action: %s\n", tok[1],
+                      action);
+       d_msg_backend(DEBUG_INFO, "%s", status);
+}
+
+static void __perform_dpkg_status_fd_read(int fd)
+{
+       char *buf_ptr = NULL;
+       char *tmp_ptr = NULL;
+       int size = 0;
+       static char buffer[1024] = {0,};
+       static int buffer_position;
+
+       size = read(fd, &buffer[buffer_position],
+                  sizeof(buffer) - buffer_position);
+       buffer_position += size;
+       if (size <= 0)
+               return;
+
+       /* Process each line of the recieved buffer */
+       buf_ptr = tmp_ptr = buffer;
+       while ((tmp_ptr = (char *)memchr(buf_ptr, '\n',
+                                  buffer + buffer_position - buf_ptr)) != NULL) {
+               *tmp_ptr = 0;
+               __process_dpkg_status_line(buf_ptr);
+               /* move to next line and continue*/
+               buf_ptr = tmp_ptr + 1;  
+       }
+
+       /*move the remaining bits at the start of the buffer
+         and update the buffer position */
+       buf_ptr = (char *)memrchr(buffer, 0, buffer_position);
+       if (buf_ptr == NULL)
+               return;
+
+       /* we have processed till the last \n which has now become 
+        0x0. So we increase the pointer to next position*/
+       buf_ptr++;
+
+       memmove(buffer, buf_ptr, buf_ptr - buffer);
+       buffer_position = buffer + buffer_position - buf_ptr;
+}
+
+static int __native_installer_init_operations(dpkg_request_type requesttype)
+{
+       operationsinfo *pHead = NULL;
+       int totaloperations = 0;
+
+       switch (requesttype) {
+       case INSTALL_REQ:
+               {
+                       /*      
+                          processing: install: <pkg>
+                          status: <pkg>: half-installed
+                          status: <pkg>: unpacked
+                          status: <pkg>: unpacked
+                          processing: configure: <pkg>
+                          status: <pkg>: unpacked
+                          status: <pkg>: half-configured
+                          status: <pkg>: installed
+
+                        */
+
+                       operationsinfo *pinstall = NULL, *pconfigure = NULL;
+                       pinstall =
+                           (operationsinfo *) malloc(sizeof(operationsinfo));
+                       pconfigure =
+                           (operationsinfo *) malloc(sizeof(operationsinfo));
+                       if (!pinstall || !pconfigure) {
+                               if (pinstall)
+                                       free(pinstall);
+                               if (pconfigure)
+                                       free(pconfigure);
+                               goto ERROR;
+                       }
+                       /* install operations */
+                       pinstall->action = DPKGINSTALL;
+                       pinstall->lastactivity = 0;
+                       pinstall->totalactivity = 2;
+                       pinstall->nextoperations = pconfigure;
+
+                       /* configure operations */
+                       pconfigure->action = DPKGCONFIGURE;
+                       pconfigure->lastactivity = 0;
+                       pconfigure->totalactivity = 3;
+                       pconfigure->nextoperations = NULL;
+
+                       pHead = pinstall;
+
+                       totaloperations =
+                           pinstall->totalactivity + pconfigure->totalactivity;
+                       if (totaloperations == 0) {
+                               if (pinstall)
+                                       free(pinstall);
+                               if (pconfigure)
+                                       free(pconfigure);
+                               goto ERROR;
+                       }
+                       break;
+               }
+       case UNINSTALL_REQ:
+               {
+                       /*
+                          processing: remove: <pkg>
+                          status: <pkg>: half-configured
+                          status: <pkg>: half-installed
+                          status: <pkg>: config-files
+                          status: <pkg>: config-files
+                          status: <pkg>: config-files
+                          status: <pkg>: not-installed
+                        */
+
+                       operationsinfo *pUnInstall = NULL;
+                       pUnInstall =
+                           (operationsinfo *) malloc(sizeof(operationsinfo));
+                       if (!pUnInstall) {
+                               goto ERROR;
+                       }
+                       /* UNINSTALL_REQ operations */
+                       pUnInstall->action = DPKGUNINSTALL;
+                       pUnInstall->lastactivity = 0;
+                       pUnInstall->totalactivity = 4;
+                       pUnInstall->nextoperations = NULL;
+
+                       pHead = pUnInstall;
+
+                       totaloperations = pUnInstall->totalactivity;
+                       if (totaloperations == 0) {
+                               if (pUnInstall)
+                                       free(pUnInstall);
+                               goto ERROR;
+                       }
+                       break;
+               }
+
+       case UPGRADE_REQ:
+               {
+                       /*      
+                          processing: upgrade: <pkg>
+                          status: <pkg>: half-configured
+                          status: <pkg>: unpacked
+                          status: <pkg>: half-installed
+                          status: <pkg>: unpacked
+                          status: <pkg>: unpacked
+                          processing: configure: <pkg>
+                          status: <pkg>: unpacked
+                          status: <pkg>: unpacked
+                          status: <pkg>: half-configured
+                          status: <pkg>: installed
+
+                        */
+                       operationsinfo *pupgrade = NULL;
+                       operationsinfo *pconfigure = NULL;
+                       pupgrade =
+                           (operationsinfo *) malloc(sizeof(operationsinfo));
+                       pconfigure =
+                           (operationsinfo *) malloc(sizeof(operationsinfo));
+                       if (!pupgrade || !pconfigure) {
+                               if (pupgrade)
+                                       free(pupgrade);
+                               if (pconfigure)
+                                       free(pconfigure);
+                               goto ERROR;
+                       }
+                       /* install operations */
+                       pupgrade->action = DPKGUPGRADE;
+                       pupgrade->lastactivity = 0;
+                       pupgrade->totalactivity = 4;
+                       pupgrade->nextoperations = pconfigure;
+
+                       /* configure operations */
+                       pconfigure->action = DPKGCONFIGURE;
+                       pconfigure->lastactivity = 0;
+                       pconfigure->totalactivity = 3;
+                       pconfigure->nextoperations = NULL;
+
+                       pHead = pupgrade;
+
+                       totaloperations =
+                           pupgrade->totalactivity + pconfigure->totalactivity;
+                       if (totaloperations == 0) {
+                               if (pupgrade)
+                                       free(pupgrade);
+                               if (pconfigure)
+                                       free(pconfigure);
+                               goto ERROR;
+                       }
+                       break;
+               }
+
+       default:
+               break;
+
+       }
+
+       dpkgrequestedoperations.requesttype = requesttype;
+       dpkgrequestedoperations.operationshead = pHead;
+       dpkgrequestedoperations.runningoperations = DPKGNONE;
+       dpkgrequestedoperations.currentprogress = 0;
+       dpkgrequestedoperations.percentageprogress = 0;
+       dpkgrequestedoperations.totaloperations = totaloperations;
+       is_operations_cleaned = 0;
+       return 0;
+ ERROR:
+       d_msg_backend(DEBUG_ERR, "__native_installer_init_operations"
+                               " :: Failed \n");
+       return -1;
+}
+
+static int __pkgmgr_dpkg_xsystem(dpkg_request_type requesttype,
+                                const char *argv[])
+{
+       sigset_t sigmask;
+       sigset_t original_sigmask;
+       int err = 0;
+       int n = 0;
+       char statusfd[32];
+       int fd[2];
+       int status;
+       pid_t pid;
+       const char *Args[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+       if (__native_installer_init_operations(requesttype) == -1) {
+               d_msg_backend(DEBUG_ERR,
+                             "_pkgmgr_dpkg_install_pkg::"
+                             " __native_installer_init_operations failed ",
+                             err);
+               return -1;
+       }
+
+       while (argv[n] != NULL) {
+               /*d_msg_backend(DEBUG_INFO, "%s\t", argv[n] ); */
+               Args[n] = argv[n];
+               n++;
+       }
+       err = pipe(fd);
+       if (err != 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "_pkgmgr_dpkg_install_pkg:: status Pipe creation failed ",
+                             err);
+       } else {
+               snprintf(statusfd, 32, "%d", fd[1]);
+               Args[n++] = "--status-fd";
+               Args[n++] = statusfd;
+       }
+
+       /* Mask off sig int/quit. We do this because dpkg also does when 
+          it forks scripts. What happens is that when you hit ctrl-c it sends
+          it to all processes in the group. Since dpkg ignores the signal 
+          it doesn't die but we do! So we must also ignore it */
+       __sighandler_t old_SIGQUIT = signal(SIGQUIT, SIG_IGN);
+       __sighandler_t old_SIGINT = signal(SIGINT, SIG_IGN);
+
+       /* ignore SIGHUP as well (debian #463030) */
+       __sighandler_t old_SIGHUP = signal(SIGHUP, SIG_IGN);
+
+       pid = vfork();
+
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               /* child */
+               {
+                       close(fd[0]);
+                       if (execvp(argv[0], (char *const *)Args) == -1) {
+                               perror("execvp");
+                       }
+                       _exit(100);
+               }
+       default:
+               /* parent */
+               break;
+       }
+
+       close(fd[1]);
+       /* setups fds */
+       sigemptyset(&sigmask);
+       sigprocmask(SIG_BLOCK, &sigmask, &original_sigmask);
+
+       while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
+               if (err < 0) {
+                       if (errno == EINTR)
+                               continue;
+                       perror("waitpid");
+                       /* Restore sig int/quit */
+                       signal(SIGQUIT, old_SIGQUIT);
+                       signal(SIGINT, old_SIGINT);
+                       signal(SIGHUP, old_SIGHUP);
+                       close(fd[0]);
+                       return -1;
+               }
+               /* read the status using status fd */
+               int select_ret;
+               fd_set rfds;
+               struct timespec tv;
+               FD_ZERO(&rfds);
+               /*FD_SET(0, &rfds); */
+               FD_SET(fd[0], &rfds);
+               tv.tv_sec = 1;
+               tv.tv_nsec = 0;
+               select_ret =
+                   pselect(fd[0] + 1, &rfds, NULL, NULL, &tv,
+                           &original_sigmask);
+               if (select_ret == 0)
+                       continue;
+
+               else if (select_ret < 0 && errno == EINTR)
+                       continue;
+               else if (select_ret < 0) {
+                       perror("select() returned error");
+                       continue;
+               }
+               if (FD_ISSET(fd[0], &rfds))
+                       __perform_dpkg_status_fd_read(fd[0]);
+       }
+       close(fd[0]);
+
+       /* Restore sig int/quit */
+       signal(SIGQUIT, old_SIGQUIT);
+       signal(SIGINT, old_SIGINT);
+       signal(SIGHUP, old_SIGHUP);
+
+       /* Check for an error code. */
+       if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0) {
+               /* if it was set to "keep-dpkg-runing" then we won't return */
+               /* here but keep the loop going and just report it as a error */
+               /* for later */
+
+               if (WIFSIGNALED(status) != 0 && WTERMSIG(status) == SIGSEGV) {
+                       d_msg_backend(DEBUG_INFO,
+                                     "Sub-process %s received a segmentation fault. \n",
+                                     Args[0]);
+               } else if (WIFEXITED(status) != 0) {
+                       d_msg_backend(DEBUG_INFO,
+                                     "Sub-process %s returned an error code (%u)\n",
+                                     Args[0], WEXITSTATUS(status));
+               } else {
+                       d_msg_backend(DEBUG_INFO,
+                                     "Sub-process %s exited unexpectedly\n",
+                                     Args[0]);
+               }
+       }
+       return WEXITSTATUS(status);
+}
+
+int _pkgmgr_dpkg_uninstall_pkg(char *pkgname)
+{
+       int ret = 0;
+       int err = 0;
+       char buff[256] = {'\0'};
+       ret = _unset_event_notification();
+       if (ret < 0) {
+               d_msg_backend(DEBUG_ERR, "_unset_event_notification failed\n");
+       }
+       const char *argv[] = { UNINSTALL_SCRIPT, pkgname, NULL };
+       ret = __pkgmgr_dpkg_xsystem(UNINSTALL_REQ, argv);
+       if (ret != 0) {
+               d_msg_backend(DEBUG_ERR, "uninstall failed with error(%d)\n",
+                             ret);
+               return ret;
+       }
+       /* Uninstallation Success. Remove the installation time key from vconf*/
+       snprintf(buff, 256, "db/app-info/%s/installed-time", gptrpkgname);
+       err= vconf_unset(buff);
+       if (err) {
+               d_msg_backend(DEBUG_ERR, "unset installation time failed\n");
+       }
+       return ret;
+}
+
+int _pkgmgr_dpkg_install_pkg(char *pkgfilepath, char *installoptions)
+{
+       int err = 0;
+       int ret = 0;
+       int value = 0;
+       time_t cur_time;
+       char buff[256] = {'\0'};
+       const char *argv[] = {
+               INSTALL_SCRIPT, pkgfilepath, installoptions, NULL
+       };
+       if (!strncmp(evt_notification, "True", strlen("True"))
+           || !strncmp(evt_notification, "False", strlen("False"))) {
+               if (!strncmp(evt_notification, "True", strlen("True")))
+                       value = 1;
+               else
+                       value = 0;
+
+               err = _set_event_notification(value);
+               if (err < 0) {
+                       d_msg_backend(DEBUG_ERR,
+                                     "_set_event_notification failed\n");
+                       /* TODO : handle error */
+               }
+       }
+       err = __pkgmgr_dpkg_xsystem(INSTALL_REQ, argv);
+       if (err != 0) {
+               d_msg_backend(DEBUG_ERR, "install complete with error(%d)\n",
+                             err);
+               return err;
+       }
+       /* Install Success. Store the installation time*/
+       cur_time = time(NULL);
+       snprintf(buff, 256, "db/app-info/%s/installed-time", gptrpkgname);
+       /* The time is stored in time_t format. It can be converted to
+       local time or GMT time as per the need by the apps*/
+       ret = vconf_set_int(buff, cur_time);
+       if(ret) {
+               d_msg_backend(DEBUG_ERR, "setting installation time failed\n");
+               vconf_unset(buff);
+       }
+       return err;
+}
+
+int _pkgmgr_dpkg_upgrade_pkg(char *pkgfilepath, char *installoptions)
+{
+       int err = 0;
+       int value = 0;
+       int ret = 0;
+       time_t cur_time;
+       char buff[256] = {'\0'};
+       if (!strncmp(evt_notification, "True", strlen("True")) ||
+           !strncmp(evt_notification, "False", strlen("False"))) {
+               if (!strncmp(evt_notification, "True", strlen("True")))
+                       value = 1;
+               else
+                       value = 0;
+
+               err = _set_event_notification(value);
+               if (err < 0) {
+                       d_msg_backend(DEBUG_ERR,
+                                     "_set_event_notification failed\n");
+                       /* TODO : handle error */
+               }
+       }
+       const char *argv[] = {
+               INSTALL_SCRIPT, pkgfilepath, installoptions, NULL
+       };
+       err = __pkgmgr_dpkg_xsystem(UPGRADE_REQ, argv);
+       if (err != 0) {
+               d_msg_backend(DEBUG_ERR, "install complete with error(%d)\n",
+                             err);
+               return err;
+       }
+       /* Upgrade Success. Store the upgradation time*/
+       cur_time = time(NULL);
+       snprintf(buff, 256, "db/app-info/%s/installed-time", gptrpkgname);
+       /* The time is stored in time_t format. It can be converted to
+       local time or GMT time as per the need by the apps*/
+       ret = vconf_set_int(buff, cur_time);
+       if(ret) {
+               d_msg_backend(DEBUG_ERR, "setting upgradation time failed\n");
+       }
+       return err;
+}
+
diff --git a/backend/src/parser/nativeinstallermanifestparser.c b/backend/src/parser/nativeinstallermanifestparser.c
new file mode 100755 (executable)
index 0000000..5c89f71
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#include <regex.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "nativeinstaller.h"
+#include "native_installer_util.h"
+
+static int __pkgmgr_txt_parser_fill_pkginfo(pkginfo *info, char *line);
+
+char evt_notification[64] = { 0, };
+
+static int __pkgmgr_txt_parser_fill_pkginfo(pkginfo *info, char *line)
+{
+       regex_t re;
+       regmatch_t mached[5];
+       int ret = 0;
+       char *retstr;
+
+       ret = regcomp(&re, "[Pp]ackage[\\ ]*:[\\ ]*([.A-Z0-9a-z_\\-]+)",
+                     REG_EXTENDED);
+       if (ret != 0) {
+               d_msg_backend(DEBUG_ERR, "[fillPkgInfo]regcomp failed(%d)",
+                             ret);
+               return -1;
+       }
+       ret = regexec(&re, line, 5, mached, 0);
+       if (ret != 0)
+               regfree(&re);
+       else {
+               retstr = _substring(line, mached[1].rm_so,
+                                   mached[1].rm_eo - mached[1].rm_so);
+               d_msg_backend(DEBUG_ERR, "[fillPkgInfo]PackageName=%s\n",
+                             retstr);
+               strncpy(info->package_name, retstr,
+                       sizeof(info->package_name) - 1);
+               free(retstr);
+               regfree(&re);
+               return 1;
+       }
+
+       ret = regcomp(&re,
+                     "Version[\\ ]*:[\\ ]*([0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3})",
+                     REG_EXTENDED);
+       if (ret != 0) {
+               d_msg_backend(DEBUG_ERR, "[fillPkgInfo]regcomp failed(%d)",
+                             ret);
+               return -1;
+       }
+       ret = regexec(&re, line, 5, mached, 0);
+       if (ret != 0)
+               regfree(&re);
+       else {
+               retstr = _substring(line, mached[1].rm_so,
+                                   mached[1].rm_eo - mached[1].rm_so);
+               d_msg_backend(DEBUG_INFO, "[fillPkgInfo]Version=%s\n", retstr);
+               strncpy(info->version, retstr, sizeof(info->version) - 1);
+               regfree(&re);
+               free(retstr);
+               return 1;
+       }
+
+       ret = regcomp(&re,
+                     "[Aa]pp[Ss]etting[Nn]otification[\\ ]*:[\\ ]*([.A-Z0-9a-z_\\-]+)",
+                     REG_EXTENDED);
+       if (ret != 0) {
+               d_msg_backend(DEBUG_ERR, "[fillPkgInfo]regcomp failed(%d)",
+                             ret);
+               return -1;
+       }
+       ret = regexec(&re, line, 5, mached, 0);
+       if (ret != 0)
+               regfree(&re);
+       else {
+               retstr = _substring(line, mached[1].rm_so,
+                                   mached[1].rm_eo - mached[1].rm_so);
+               d_msg_backend(DEBUG_ERR,
+                             "[fillPkgInfo]AppSettingNotification=%s\n",
+                             retstr);
+               strncpy(evt_notification, retstr, strlen(retstr));
+               free(retstr);
+               regfree(&re);
+               return 1;
+       }
+       return 0;
+}
+
+pkginfo *_pkgmgr_txt_parser_read_manifest(char *manifestfile)
+{
+       FILE *fp1;
+       char line[512];
+       char *c;
+       pkginfo *info = malloc(sizeof(pkginfo));
+       if (info == NULL)
+               return NULL;
+       memset(info, 0, sizeof(pkginfo));
+
+       fp1 = fopen(manifestfile, "r");
+       if (fp1 == NULL) {
+               d_msg_backend(DEBUG_ERR, "failed to open file(%s)\n",
+                             manifestfile);
+               if (info) {
+                       free(info);
+                       info = NULL;
+               }
+               return NULL;
+       }
+
+       do {
+               c = fgets(line, 512, fp1);
+               if (c != NULL) {
+                       __pkgmgr_txt_parser_fill_pkginfo(info, line);
+               }
+       } while (c != NULL);
+
+       fclose(fp1);
+       return info;
+}
+
diff --git a/backend/src/vconf/nativebackendvconfintf.c b/backend/src/vconf/nativebackendvconfintf.c
new file mode 100755 (executable)
index 0000000..8735b17
--- /dev/null
@@ -0,0 +1,259 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+  
+#include <pkgmgr_installer.h>
+#include <vconf.h>
+#include <errno.h>
+
+#include "native_installer_util.h"
+
+#define VCONF_LOCATION                                                 "db"
+#define VCONF_NATIVE_INSTALLER         VCONF_LOCATION"/nativeinstaller"
+
+#define VCONF_NATIVE_INSTALLER_BACKEND_STATE \
+       VCONF_NATIVE_INSTALLER"/state"
+#define VCONF_NATIVE_INSTALLER_BACKEND_STATEINFO \
+       VCONF_NATIVE_INSTALLER"/stateinfo"
+
+#define VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_COMMAND \
+       VCONF_NATIVE_INSTALLER"/requestinfo/command"
+#define VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_PKGNAME \
+       VCONF_NATIVE_INSTALLER"/requestinfo/pkgname"
+#define VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_OPTIONS \
+       VCONF_NATIVE_INSTALLER"/requestinfo/options"
+#define VCONF_NATIVE_INSTALLER_APPSETTING      "db/app-settings"
+
+extern char *gptrpkgname;
+extern pkgmgr_installer *pi;
+
+int _set_event_notification(int value)
+{
+       int pid;
+       int ret = -1;
+       char buff[256] = { 0, };
+       char strval[8] = { 0, };
+       ret =
+           snprintf(buff, sizeof(buff) - 1,
+                    VCONF_NATIVE_INSTALLER_APPSETTING "/noti-enabled/%s",
+                    gptrpkgname);
+       if (ret < 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "_set_event_notification: snprintf FAIL\n");
+               return ret;
+       }
+
+       ret = snprintf(strval, sizeof(strval) - 1, "%d", value);
+       if (ret < 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "_set_event_notification: snprintf FAIL\n");
+               return ret;
+       }
+
+       if ((pid = fork()) < 0) {
+               ret = -1;
+       } else if (pid == 0) {
+               execl("/usr/bin/vconftool", "vconftool", "-g", "6514", "set",
+                     "-t", "int", buff, strval, (char *)0);
+               exit(127);      /* execl error */
+       } else {
+               while (waitpid(pid, &ret, 0) < 0) {
+                       if (errno != EINTR) {
+                               ret = -1;       /* error other  than EINTR 
+                                               from waitpid() */
+                               break;
+                       }
+               }
+       }
+
+       if (ret != 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "_set_event_notification: vconf_set_int FAIL\n");
+               return ret;
+       } else
+               return NATIVEINSTALLER_SUCCESS;
+}
+
+int _unset_event_notification()
+{
+       int pid;
+       int ret = -1;
+       char buff[256] = { 0, };
+       ret = snprintf(buff, sizeof(buff) - 1,
+                      VCONF_NATIVE_INSTALLER_APPSETTING "/noti-enabled/%s",
+                      gptrpkgname);
+       if (ret < 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "_unset_event_notification: snprintf FAIL\n");
+               return ret;
+       }
+
+       if ((pid = fork()) < 0) {
+               ret = -1;
+       } else if (pid == 0) {
+               execl("/usr/bin/vconftool", "vconftool", "unset", buff,
+                     (char *)0);
+               exit(127);      /* execl error */
+       } else {
+               while (waitpid(pid, &ret, 0) < 0) {
+                       if (errno != EINTR) {
+                               ret = -1;       /* error other than EINTR
+                                               from waitpid() */
+                               break;
+                       }
+               }
+       }
+
+       if (ret != 0) {
+               d_msg_backend(DEBUG_ERR,
+                             "_unset_event_notification: vconf_unset FAIL\n");
+               return ret;
+       } else {
+               return NATIVEINSTALLER_SUCCESS;
+       }
+}
+
+int _get_backend_state()
+{
+       int ret = -1;
+       int state = -1;
+       ret = vconf_get_int(VCONF_NATIVE_INSTALLER_BACKEND_STATE, &state);
+       if (ret == -1) {
+               d_msg_backend(DEBUG_ERR,
+                             "_get_backend_state: vconf_get_int FAIL\n");
+       } else {
+               ret = state;
+       }
+       return ret;
+}
+
+int _set_backend_state(int state)
+{
+       int ret = -1;
+
+       if (state == 0) {
+               vconf_unset_recursive(VCONF_NATIVE_INSTALLER);
+       }
+
+       ret = vconf_set_int(VCONF_NATIVE_INSTALLER_BACKEND_STATE, state);
+       if (ret == -1) {
+               d_msg_backend(DEBUG_ERR,
+                             "_set_backend_state: vconf_set_int FAIL\n");
+       }
+
+       return ret;
+}
+
+int _get_backend_state_info()
+{
+       int ret = -1;
+       int state = -1;
+       ret = vconf_get_int(VCONF_NATIVE_INSTALLER_BACKEND_STATEINFO, &state);
+       if (ret == -1) {
+               d_msg_backend(DEBUG_ERR,
+                             "_get_backend_state_info: vconf_get_int FAIL\n");
+       } else {
+               ret = state;
+       }
+       return ret;
+}
+
+int _set_backend_state_info(int state)
+{
+       int ret = -1;
+       ret = vconf_set_int(VCONF_NATIVE_INSTALLER_BACKEND_STATEINFO, state);
+       if (ret == -1)
+               d_msg_backend(DEBUG_ERR,
+                             "_set_backend_state_info: vconf_set_int FAIL\n");
+
+       return ret;
+}
+
+int _get_last_input_info(char **pkgname, int *preqcommand, int *poptions)
+{
+       int ret = -1;
+       if (!pkgname || !preqcommand || !poptions)
+               return -1;
+       ret = vconf_get_int(VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_COMMAND,
+                           preqcommand);
+       if (ret == -1)
+               d_msg_backend(DEBUG_ERR,
+                             "_get_last_input_info: VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_COMMAND: vconf_get_int FAIL\n");
+
+       ret = vconf_get_int(VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_OPTIONS,
+                           poptions);
+       if (ret == -1)
+               d_msg_backend(DEBUG_ERR,
+                             "_get_last_input_info: VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_OPTIONS: vconf_get_int FAIL\n");
+
+       *pkgname =
+           vconf_get_str(VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_PKGNAME);
+       return 0;
+}
+
+void _save_last_input_info(char *pkgname, int reqcommand, int options)
+{
+       keylist_t *kl = NULL;
+       kl = vconf_keylist_new();
+
+       vconf_keylist_add_int(kl,
+                             VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_COMMAND,
+                             reqcommand);
+       vconf_keylist_add_str(kl,
+                             VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_PKGNAME,
+                             pkgname);
+       vconf_keylist_add_int(kl,
+                             VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_OPTIONS,
+                             options);
+
+       if (vconf_set(kl))
+               d_msg_backend(DEBUG_ERR,
+                             "_save_last_input_info: Failure in writing vconf\n");
+
+       vconf_keylist_free(kl);
+}
+
+
+
+void _broadcast_status_notification(char *pkgname, char *key, char *val)
+{
+       char *ppkgname = NULL;
+
+       if (gptrpkgname != NULL)
+               ppkgname = gptrpkgname;
+       else
+               ppkgname = pkgname;
+
+       d_msg_backend(DEBUG_INFO, "pkgname = %s, key = %s, val = %s\n",
+                     ppkgname, key, val);
+
+       
+       if (pi != NULL)
+               pkgmgr_installer_send_signal(pi, PKGTYPE, ppkgname, key, val);
+       else
+               d_msg_backend(DEBUG_ERR,
+                             "Failure in sending broadcast message\n");
+}
+
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..743d017
--- /dev/null
@@ -0,0 +1,41 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+#Verbose
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/inc)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED glib-2.0)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(pkgs_CFLAGS_str "${pkgs_CFLAGS_str} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(libpkgs REQUIRED dbus-glib-1 db-util vconf sqlite3 dlog)
+
+FOREACH(flag ${libpkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(comm_dir "${CMAKE_SOURCE_DIR}")
+SET(comm_c_src_dir "${comm_dir}")
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+###################################################################################################
+## for libnative-util.so (library)
+
+add_library(native-util STATIC
+                ${CMAKE_CURRENT_SOURCE_DIR}/NativeInstallerUtil.c
+                )
+set_target_properties(native-util PROPERTIES COMPILE_FLAGS "${pkgs_CFLAGS_str}")
+target_link_libraries(native-util ${libpkg_LDFLAGS})
+###################################################################################################
+
+INSTALL(TARGETS
+       native-util
+       DESTINATION lib/native-installer
+       COMPONENT RuntimeLibraries)
diff --git a/common/NativeInstallerUtil.c b/common/NativeInstallerUtil.c
new file mode 100755 (executable)
index 0000000..c6015a6
--- /dev/null
@@ -0,0 +1,332 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#include <string.h>
+#include <stdarg.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <wait.h>
+#include <stdio.h>
+#include <ctype.h>             /* for isspace () */
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <syslog.h>
+#include "native_installer_util.h"
+
+#include <dlog.h>
+
+#define LOG_TAG                                "nativeinstaller"
+#define LOG_TAG_BACKEND                "native-backend"
+#define LOG_TAG_FRONTEND       "native-frontend"
+
+int logging = 0x0004;
+#ifdef LOG_IN_FILE
+#define NATIVE_INSTALLER_LOG_FILE "/tmp/native-installer"
+FILE *logfile = NULL;
+#endif
+
+/**
+ * This is intended to be a faster splitter, it does not use dynamic
+ *  memories. Input is changed to insert nulls at each token location. 
+ */
+int _tok_split_string(char tok, char *input, char **list, unsigned long listmax)
+{
+       /* Strip any leading spaces */
+       char *Start = input;
+       char *Stop = Start + strlen(Start);
+       for (; *Start != 0 && isspace(*Start) != 0; Start++) ;
+
+       unsigned long Count = 0;
+       char *Pos = Start;
+       while (Pos != Stop) {
+               /* Skip to the next Token */
+               for (; Pos != Stop && *Pos != tok; Pos++) ;
+
+               /* Back remove spaces */
+               char *End = Pos;
+               for (; 
+                    End > Start && (End[-1] == tok || isspace(End[-1]) != 0);
+                    End--) ;
+
+               *End = 0;
+
+               list[Count++] = Start;
+               if (Count >= listmax) {
+                       list[Count - 1] = 0;
+                       return -1;
+               }
+               /* Advance pos */
+               for (;
+                    Pos != Stop && (*Pos == tok || isspace(*Pos) != 0
+                                    || *Pos == 0); Pos++) ;
+
+               Start = Pos;
+       }
+
+       list[Count] = 0;
+       return 0;
+}
+
+void _d_msg_init(char *program)
+{
+       if (logging == 0)
+               return;
+
+#ifdef LOG_IN_FILE
+       char logfilename[64];
+       char buffer[256] = { 0 };
+       snprintf(logfilename, 64, "%s-%s", NATIVE_INSTALLER_LOG_FILE, program);
+       logfile = fopen(logfilename, "a+");
+
+       if (logfile == NULL)
+               printf("Error opening log file\n");
+       else {
+               snprintf(buffer, 64, "\nLog File %s Created", logfilename);
+               fwrite(buffer, sizeof(char), strlen(buffer), logfile);
+               snprintf(buffer, 64, "\nLog Started\n");
+               fwrite(buffer, sizeof(char), strlen(buffer), logfile);
+       }
+#endif
+}
+
+void _d_msg_deinit()
+{
+       if (logging == 0)
+               return;
+
+#ifdef LOG_IN_FILE
+       if (logfile != NULL)
+               fclose(logfile);
+#endif
+}
+
+void _print_msg(int type, int exetype, char *format, ...)
+{
+       char buffer[1024] = { 0 };
+       char tbuffer[1024] = { 0 };
+       int nbuffer;
+       va_list args;
+       va_start(args, format);
+       nbuffer = vsnprintf(tbuffer, 1024, format, args);
+       va_end(args);
+
+       switch (type) {
+       case DEBUG_ERR:
+               LOG(LOG_ERROR, LOG_TAG, tbuffer);
+               break;
+       case DEBUG_RESULT:
+               LOG(LOG_WARN, LOG_TAG, tbuffer);
+               break;
+       case DEBUG_INFO:
+               LOG(LOG_DEBUG, LOG_TAG, tbuffer);
+       default:
+               break;
+       }
+
+       if (logging == 0)
+               return;
+
+       if (DEBUG_ERR == (logging & type)) {
+               nbuffer = snprintf(buffer, 1024, "ERROR:%s", tbuffer);
+               vfprintf(stderr, format, args);
+       } else if (DEBUG_INFO == (logging & type)) {
+               nbuffer = snprintf(buffer, 1024, "INFO:%s", tbuffer);
+               vfprintf(stdout, format, args);
+       } else if (DEBUG_RESULT == (logging & type)) {
+               nbuffer = snprintf(buffer, 1024, "RESULT:%s", tbuffer);
+               vfprintf(stdout, format, args);
+       } else {
+               return;
+       }
+
+#ifdef LOG_IN_FILE
+       if (logfile != NULL)
+               fwrite(buffer, sizeof(char), strlen(buffer), logfile);
+#endif                         /*LOG_IN_FILE */
+}
+
+/* Like system(3), but with error messages printed if the fork fails
+   or if the child process dies due to an uncaught signal. Also, the
+   return value is a bit simpler:
+
+   -1 if there was any problem
+   Otherwise, the 8-bit return value of the program ala WEXITSTATUS
+   as defined in <sys/wait.h>.
+   */
+int _xsystem(const char *argv[])
+{
+       int status;
+       pid_t pid;
+       pid = vfork();
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               /* child */
+               execvp(argv[0], (char *const *)argv);
+               _exit(-1);
+       default:
+               /* parent */
+               break;
+       }
+
+       d_msg_backend(DEBUG_INFO, "parent\n");
+       if (waitpid(pid, &status, 0) == -1) {
+               perror("waitpid failed");
+               return -1;
+       }
+
+       if (WIFSIGNALED(status)) {
+               perror("signal");
+               return -1;
+       }
+
+       if (!WIFEXITED(status)) {
+               /* shouldn't happen */
+               perror("should not happen");
+               return -1;
+       }
+
+       return WEXITSTATUS(status);
+}
+
+char *_substring(const char *str, size_t begin, size_t len)
+{
+       if (str == 0 || strlen(str) == 0 || strlen(str) < begin
+           || strlen(str) < (begin + len))
+               return 0;
+       return strndup(str + begin, len);
+}
+
+void _error_no_to_string(int errnumber, char **errstr)
+{
+       if (errstr == NULL)
+               return;
+       switch (errnumber) {
+       case NATIVEINSTALLER_SUCCESS:
+               *errstr = NATIVEINSTALLER_SUCCESS_STR;
+               break;
+       case NATIVEINSTALLER_ERR_WRONG_PARAM:
+               *errstr = NATIVEINSTALLER_ERR_WRONG_PARAM_STR;
+               break;
+       case NATIVEINSTALLER_ERR_DBUS_PROBLEM:
+               *errstr = NATIVEINSTALLER_ERR_DBUS_PROBLEM_STR;
+               break;
+       case NATIVEINSTALLER_ERR_NOT_ENOUGH_MEMORY:
+               *errstr = NATIVEINSTALLER_ERR_NOT_ENOUGH_MEMORY_STR;
+               break;
+       case NATIVEINSTALLER_ERR_NO_MANIFEST:
+               *errstr = NATIVEINSTALLER_ERR_NO_MANIFEST_STR;
+               break;
+       case NATIVEINSTALLER_ERR_PACKAGE_EXIST:
+               *errstr = NATIVEINSTALLER_ERR_PACKAGE_EXIST_STR;
+               break;
+       case NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED:
+               *errstr = NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR;
+               break;
+       case NATIVEINSTALLER_ERR_RESOURCE_BUSY:
+               *errstr = NATIVEINSTALLER_ERR_RESOURCE_BUSY_STR;
+               break;
+       case NATIVEINSTALLER_ERR_UNKNOWN:
+               *errstr = NATIVEINSTALLER_ERR_UNKNOWN_STR;
+               break;
+       case NATIVEINSTALLER_ERR_PKG_NOT_FOUND:
+               *errstr = NATIVEINSTALLER_ERR_PKG_NOT_FOUND_STR;
+               break;
+       case NATIVEINSTALLER_ERR_NOT_SUPPOTED_VERSION:
+               *errstr = NATIVEINSTALLER_ERR_NOT_SUPPOTED_VERSION_STR;
+               break;
+       case NATIVEINSTALLER_ERR_NO_DEB_FILE:
+               *errstr = NATIVEINSTALLER_ERR_NO_DEB_FILE_STR;
+               break;
+       case NATIVEINSTALLER_ERR_DB_ACCESS_FAILED:
+               *errstr = NATIVEINSTALLER_ERR_DB_ACCESS_FAILED_STR;
+               break;
+       case NATIVEINSTALLER_ERR_DPKG_OPERATION_FAILED:
+               *errstr = NATIVEINSTALLER_ERR_DPKG_OPERATION_FAILED_STR;
+               break;
+       case NATIVEINSTALLER_PACKAGE_NOT_UPGRADED:
+               *errstr = NATIVEINSTALLER_PACKAGE_NOT_UPGRADED_STR;
+               break;
+       case NATIVEINSTALLER_ERR_CLEAR_DATA_FAILED:
+               *errstr = NATIVEINSTALLER_ERR_CLEAR_DATA_FAILED_STR;
+               break;
+       default:
+               *errstr = NATIVEINSTALLER_ERR_UNKNOWN_STR;
+               break;
+       }
+}
+
+int _string_to_error_no(char *errstr)
+{
+       int errnumber = NATIVEINSTALLER_ERR_UNKNOWN;
+       if (errstr == NULL)
+               return errnumber;
+
+       if (strcmp(errstr, NATIVEINSTALLER_SUCCESS_STR) == 0)
+               errnumber = NATIVEINSTALLER_SUCCESS;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_WRONG_PARAM_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_WRONG_PARAM;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_DBUS_PROBLEM_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_DBUS_PROBLEM;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_NOT_ENOUGH_MEMORY_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_NOT_ENOUGH_MEMORY;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_NO_MANIFEST_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_NO_MANIFEST;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_PACKAGE_EXIST_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_PACKAGE_EXIST;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR)
+                == 0)
+               errnumber = NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_RESOURCE_BUSY_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_RESOURCE_BUSY;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_UNKNOWN_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_UNKNOWN;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_PKG_NOT_FOUND_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_PKG_NOT_FOUND;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_NOT_SUPPOTED_VERSION_STR) ==
+                0)
+               errnumber = NATIVEINSTALLER_ERR_NOT_SUPPOTED_VERSION;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_NO_DEB_FILE_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_NO_DEB_FILE;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_DB_ACCESS_FAILED_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_DB_ACCESS_FAILED;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_DPKG_OPERATION_FAILED_STR)
+                == 0)
+               errnumber = NATIVEINSTALLER_ERR_DPKG_OPERATION_FAILED;
+       else if (strcmp(errstr, NATIVEINSTALLER_PACKAGE_NOT_UPGRADED_STR) == 0)
+               errnumber = NATIVEINSTALLER_PACKAGE_NOT_UPGRADED;
+       else if (strcmp(errstr, NATIVEINSTALLER_ERR_CLEAR_DATA_FAILED_STR) == 0)
+               errnumber = NATIVEINSTALLER_ERR_CLEAR_DATA_FAILED;
+       return errnumber;
+}
+
diff --git a/debian/changelog b/debian/changelog
new file mode 100755 (executable)
index 0000000..c91b130
--- /dev/null
@@ -0,0 +1,7 @@
+native-installer (1.2.66) unstable; urgency=low
+
+  * Initial Release.
+  * Git: pkgs/n/native-installer
+  * Tag: native-installer_1.2.66
+
+ -- Sewook Park <sewook7.park@samsung.com>  Wed, 07 Dec 2011 12:55:49 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100755 (executable)
index 0000000..2678065
--- /dev/null
@@ -0,0 +1,18 @@
+Source: native-installer
+Section: base
+Priority: extra
+Maintainer: Shobhit Srivastava <shobhit.s@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Youmin Ha <youmin.ha@samsung.com>
+Build-Depends: debhelper (>= 5), libslp-setting-dev, libsqlite3-dev, libslp-db-util-dev, libdbus-glib-1-dev, libglib2.0-dev, libpkgmgr-installer-dev, libsecurity-server-client-dev, libelm-dev, libappcore-efl-dev, dlog-dev, libpkgmgr-types-dev, libevas-dev, libecore-dev, libedje-dev
+Standards-Version: 3.7.2
+
+Package: native-installer 
+Section: base
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: native installer package 
+
+Package: native-installer-dbg
+Section: debug 
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends} native-installer 
+Description: native installer debug package 
diff --git a/debian/control.slp b/debian/control.slp
new file mode 100755 (executable)
index 0000000..dde6b4f
--- /dev/null
@@ -0,0 +1,3 @@
+#Sat May 15 19:14:26 KST 2010
+Package=native-installer
+AppInstallPath=/usr
diff --git a/debian/desktop.slp b/debian/desktop.slp
new file mode 100644 (file)
index 0000000..dc2dc4d
--- /dev/null
@@ -0,0 +1,11 @@
+#Thu May 20 17:26:45 KST 2010
+Name=native-installer
+Type=Application
+Exec=/usr/etc/package-manager/frontend/deb
+Icon=
+Comment=
+MimeType=application/x-deb
+Hidden=true
+Version=1.2.10
+X-SLP-TaskManage=true
+X-SLP-Multiple=true
diff --git a/debian/dirs b/debian/dirs
new file mode 100644 (file)
index 0000000..ca882bb
--- /dev/null
@@ -0,0 +1,2 @@
+usr/bin
+usr/sbin
diff --git a/debian/docs b/debian/docs
new file mode 100644 (file)
index 0000000..a0f0008
--- /dev/null
@@ -0,0 +1 @@
+CMakeLists.txt
diff --git a/debian/native-installer-dbg.postinst b/debian/native-installer-dbg.postinst
new file mode 100755 (executable)
index 0000000..75723e1
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+mkdir -p /usr/etc/package-manager/frontend
+mkdir -p /usr/etc/package-manager/backend
+vconftool set -t int memory/nativelogging 7
+if [ "${USER}" = "root" ]
+then
+        chown 5000:5000 /usr/lib/native-installer/libnative-util.a
+        chown 5000:5000 /usr/lib/debug/usr/bin/native-backend
+fi
+
+chmod 755 /usr/lib/native-installer/libnative-util.a
+chmod 755 /usr/lib/debug/usr/bin/native-backend
diff --git a/debian/native-installer.install.in b/debian/native-installer.install.in
new file mode 100755 (executable)
index 0000000..a7cfeb0
--- /dev/null
@@ -0,0 +1,16 @@
+@PREFIX@/lib/native-installer/libnative-util.a
+@PREFIX@/bin/native-backend
+@PREFIX@/bin/install_spk.sh
+@PREFIX@/bin/audit_spk.sh
+@PREFIX@/bin/extract_manifest.sh
+@PREFIX@/bin/uninstall_spk.sh
+@PREFIX@/bin/update_avail_spk.sh
+@PREFIX@/bin/native-frontend
+@PREFIX@/share/icon
+@PREFIX@/share/icon/icon_application.png
+@PREFIX@/share/icon/image_editor_button_cancel.png
+@PREFIX@/usr/share/data
+@PREFIX@/share/data/c-empty.edj
+@PREFIX@/share/locale/en_US/LC_MESSAGES/native-installer.mo
+@PREFIX@/share/locale/ko_KR/LC_MESSAGES/native-installer.mo
+@PREFIX/usr/etc/package-manager/backendlib/libdeb.so
diff --git a/debian/native-installer.postinst b/debian/native-installer.postinst
new file mode 100755 (executable)
index 0000000..9941049
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+mkdir -p /usr/etc/package-manager/frontend
+mkdir -p /usr/etc/package-manager/backend
+ln -sf /usr/bin/native-backend /usr/etc/package-manager/backend/deb
+if [ "${USER}" = "root" ]
+then
+        chown 5000:5000 /usr/lib/native-installer/libnative-util.a
+        chown 5000:5000 /usr/bin/native-backend
+fi
+
+chmod 755 /usr/lib/native-installer/libnative-util.a
+chmod 755 /usr/bin/native-backend
+
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..6e1caf4
--- /dev/null
@@ -0,0 +1,115 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+include debian/desktop.slp
+include debian/control.slp
+
+PKGDIR = debian/$(Package)
+DESKTOPFILE = debian/desktop.slp
+DESKTOPDIR = usr/share/install-info/application
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+else
+       CFLAGS += -O2
+endif
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+       # Add here commands to configure the package.
+       rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+       cmake . -DCMAKE_INSTALL_PREFIX=/usr
+       rm -rf CMakeFiles/CompilerIdC*
+       touch configure-stamp
+
+
+build: build-stamp
+
+build-stamp: configure-stamp 
+       dh_testdir
+
+       # Add here commands to compile the package.
+       $(MAKE)
+       #docbook-to-man debian/native-installer.sgml > native-installer.1
+
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+       # Add here commands to clean up after the build process.
+       -$(MAKE) clean
+       dh_clean 
+       rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+       cd backend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+       rm -f backend/audit_spk.sh  backend/extract_manifest.sh  backend/install_spk.sh  backend/uninstall_spk.sh  backend/update_avail_spk.sh backend/find_package.sh
+       cd frontend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+       cd frontend && rm -rf extract_manifest.sh install_spk.sh uninstall_spk.sh find_package.sh *.edj native-backend
+       cd common && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.a
+       cd frontend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+       cd backend-lib && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake *.deb *.so
+       cd frontend/ui/res/locale && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+       rm -rf $(CURDIR)/debian/native-installer
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+       dh_installdirs
+
+       # Add here commands to install the package into debian/native-installer.
+       $(MAKE) DESTDIR=$(CURDIR)/$(PKGDIR) install
+#      mkdir -p $(CURDIR)/$(PKGDIR)/$(DESKTOPDIR)
+#      cp $(DESKTOPFILE) $(CURDIR)/$(PKGDIR)/$(DESKTOPDIR)/$(Package).desktop
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot 
+       dh_installchangelogs
+       dh_installdocs
+       dh_installexamples
+#      cp $(DESKTOPFILE) $(CURDIR)/debian/native-installer/$(DESKTOPDIR)/$(Package).desktop    
+#      dh_install
+#      dh_installmenu
+#      dh_installdebconf       
+#      dh_installlogrotate
+#      dh_installemacsen
+#      dh_installpam
+#      dh_installmime
+#      dh_python
+#      dh_installinit
+#      dh_installcron
+#      dh_installinfo
+       dh_installman
+       dh_link
+       dh_strip --dbg-package=$(Package)-dbg
+       dh_compress
+       dh_fixperms
+#      dh_perl
+#      dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/frontend/CMakeLists.txt b/frontend/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..a04dd6e
--- /dev/null
@@ -0,0 +1,120 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+#Verbose
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/backend/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED pkgmgr-installer pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util elementary appcore-efl)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(libpkgs REQUIRED security-server pkgmgr-installer pkgmgr-installer-status-broadcast-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util elementary appcore-efl)
+
+FOREACH(flag ${libpkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server pkgmgr-installer)
+link_directories (${STATUS_LIBRARY_DIRS})
+include_directories (${STATUS_INCLUDE_DIRS})
+
+pkg_check_modules(COMMCLIENT pkgmgr-installer-client)
+link_directories (${COMMCLIENT_LIBRARY_DIRS})
+include_directories (${COMMCLIENT_INCLUDE_DIRS})
+
+pkg_check_modules(APPCODEEFL appcore-efl evas ecore edje ecore-input ecore-x)
+link_directories (${APPCODEEFL_LIBRARY_DIRS})
+include_directories (${APPCODEEFL_INCLUDE_DIRS})
+
+pkg_check_modules(SECURITYSERVER security-server)
+link_directories (${SECURITYSERVER_LIBRARY_DIRS})
+include_directories (${SECURITYSERVER_INCLUDE_DIRS})
+
+## DEFINITIONS
+ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DPACKAGE=\"${PROJECT_NAME}\"")
+
+SET(backend_dir "${CMAKE_CURRENT_SOURCE_DIR}/../backend")
+SET(backend_inc_dir "${backend_dir}/include")
+SET(backend_c_src_dir "${backend_dir}/src")
+SET(backend_script_dir "${backend_dir}/scripts")
+SET(SCRIPTS_DIR "${backend_script_dir}")
+
+SET(frontend_dir "${CMAKE_CURRENT_SOURCE_DIR}")
+SET(frontend_inc_dir "${frontend_dir}/inc")
+SET(frontend_c_src_dir "${frontend_dir}/src")
+SET(frontend_c_ui_src_dir "${frontend_dir}/ui/src")
+SET(frontend_c_ui_inc_dir "${frontend_dir}/ui/include")
+
+
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -rdynamic")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+####################################################################################################
+## for native-backend (binary)
+SET(native-backend_SOURCES ${backend_c_src_dir}/core/nativeinstallercore.c ${backend_c_src_dir}/core/nativeinstallertool.c ${backend_c_src_dir}/dpkg/nativeinstallerdpkg.c ${backend_c_src_dir}/parser/nativeinstallermanifestparser.c ${backend_c_src_dir}/vconf/nativebackendvconfintf.c ${frontend_c_src_dir}/frontendappcoreintf.c  ${frontend_c_src_dir}/frontendcmdline.c  ${frontend_c_ui_src_dir}/frontendhomeview.c)
+
+SET(native-backend_CFLAGS " -I. -I${backend_inc_dir} -I${frontend_inc_dir} -I${frontend_c_ui_inc_dir} ${pkg_CFLAGS}")
+SET(native-backend_LDFLAGS ${pkgs_LDFLAGS})
+
+ADD_EXECUTABLE(native-backend ${native-backend_SOURCES})
+TARGET_LINK_LIBRARIES(native-backend native-util)
+TARGET_LINK_LIBRARIES(native-backend ${libpkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(native-backend ${COMMCLIENT_LIBRARIES})
+TARGET_LINK_LIBRARIES(native-backend ${APPCODEEFL_LIBRARIES})
+TARGET_LINK_LIBRARIES(native-backend ${SECURITYSERVER_LIBRARIES})
+TARGET_LINK_LIBRARIES(native-backend ${STATUS_LIBRARIES})
+
+SET_TARGET_PROPERTIES(native-backend PROPERTIES COMPILE_FLAGS "${native-backend_CFLAGS}")
+####################################################################################################
+
+SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ui/res")
+
+# INSTALL
+INSTALL(DIRECTORY ${RESOURCE_DIR}/icon DESTINATION share)
+#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share)
+
+ADD_CUSTOM_TARGET(c-empty.edj
+                COMMAND edje_cc -id ${CMAKE_CURRENT_SOURCE_DIR}/ui/layout
+                ${CMAKE_CURRENT_SOURCE_DIR}/ui/layout/c-empty.edc ${CMAKE_CURRENT_SOURCE_DIR}/c-empty.edj
+       )
+       
+ADD_DEPENDENCIES(native-backend c-empty.edj)
+SET(CLEAN_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/c-empty.edj;${CLEAN_FILE_LIST}")
+INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/c-empty.edj" DESTINATION share/data)
+       
+SET(CLEAN_FILE_LIST "${CLEAN_FILE_LIST}c-empty.edj")
+
+MESSAGE("${CLEAN_FILE_LIST}")
+SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_FILE_LIST}")
+
+
+# INCLUDE LOCALE DIRECTORY
+ADD_SUBDIRECTORY(ui/res/locale)
+
+###################################################################################################i
+configure_file(${backend_script_dir}/install_spk.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_spk.sh @ONLY)
+configure_file(${backend_script_dir}/audit_spk.sh.in ${CMAKE_CURRENT_BINARY_DIR}/audit_spk.sh @ONLY)
+configure_file(${backend_script_dir}/extract_manifest.sh.in ${CMAKE_CURRENT_BINARY_DIR}/extract_manifest.sh @ONLY)
+configure_file(${backend_script_dir}/uninstall_spk.sh.in ${CMAKE_CURRENT_BINARY_DIR}/uninstall_spk.sh @ONLY)
+configure_file(${backend_script_dir}/update_avail_spk.sh.in ${CMAKE_CURRENT_BINARY_DIR}/update_avail_spk.sh @ONLY)
+configure_file(${backend_script_dir}/find_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/find_package.sh @ONLY)
+
+INSTALL(FILES
+                ${CMAKE_CURRENT_BINARY_DIR}/install_spk.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/audit_spk.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/extract_manifest.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/uninstall_spk.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/update_avail_spk.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/find_package.sh
+                DESTINATION bin)
+
+
+INSTALL(TARGETS native-backend DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE)
+
diff --git a/frontend/audit_spk.sh b/frontend/audit_spk.sh
new file mode 100755 (executable)
index 0000000..7bd6ac3
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+
+PKG_LOG_DIR=/var/pkgmgr/native
+
+debug () {
+        echo ">>$DEBUG"
+}
+
+NOARG=$#
+#echo "No of Arguments = $NOARG"
+
+if [ $NOARG -lt 0 ] || [ $NOARG -gt 2 ] || [ $NOARG -eq 1 ]; then
+        DEBUG="Usage: audit_spk.sh";debug
+        exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+        STATUS_OPTIONS=$1
+        STATUS_FD=$2
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+        mkdir -p $PKG_LOG_DIR
+fi
+
+# 3. DELETE FILES
+dpkg $STATUS_OPTIONS $STATUS_FD --audit
+
diff --git a/frontend/extract_manifest.sh b/frontend/extract_manifest.sh
new file mode 100755 (executable)
index 0000000..264b4e8
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/sh
+# extract metainfo/manifest to /var/pkgmgr/packagename/metainfo/manifest
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+E_NOT_VALID_ARCHIVE=8
+echo "package path is "$1"" > /tmp/nativescriptlog
+
+CURDIR=`pwd`
+echo "current dir is $CURDIR" >> /tmp/nativescriptlog
+
+debug () {
+       echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+if [ $# -ne 1 ];then
+       DEBUG="Usage: extract_manifest.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+fi
+
+if [ ! -f "$1" ];then
+       DEBUG="File not found";debug
+       exit $E_FILE_NOT_FOUND
+fi
+
+PKGFILEPATH="$1"
+PKGFILENAME="${PKGFILEPATH##*/}"
+CURDIR=`pwd`
+
+TEMPDIR=/opt/ums/nativeinstaller/"$PKGFILENAME"-temp
+echo "$TEMPDIR" >> /tmp/nativescriptlog
+
+mkdir -p "$TEMPDIR"
+echo "pkg file path = "$PKGFILEPATH"" >> /tmp/nativescriptlog
+cp "$PKGFILEPATH" "$TEMPDIR"/
+cd "$TEMPDIR"
+
+filename=`ls`
+echo "filename = "$filename"" >> /tmp/nativescriptlog
+
+ar -x "$filename"
+retval=$?
+echo "retval = $retval" >> /tmp/nativescriptlog
+
+if [ $retval -ne 0 ];then
+       DEBUG="archive Not correct";debug
+       cd $CURDIR
+       #rm -rf $TEMPDIR
+       exit $E_NOT_VALID_ARCHIVE
+fi
+
+CHECK_MANIFEST=`tar -tf control.tar.gz | grep control/*`
+echo $CHECK_MANIFEST >> /tmp/nativescriptlog
+if [ $? -ne 0 ];then
+       DEBUG="No manifest";debug
+       cd $CURDIR
+       rm -rf "$TEMPDIR"
+       exit $E_NO_MANIFEST
+fi
+
+mkdir -p /var/pkgmgr/"$PKGFILENAME"/metainfo
+tar -zxf control.tar.gz $CHECK_MANIFEST 
+mv $CHECK_MANIFEST /var/pkgmgr/"$PKGFILENAME"/metainfo
+cd $CURDIR
+rm -rf "$TEMPDIR"
diff --git a/frontend/find_package.sh b/frontend/find_package.sh
new file mode 100755 (executable)
index 0000000..5329b97
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+# extract metainfo/manifest to /var/pkgmgr/packagename/metainfo/manifest
+E_DPKG_NOT_INSTALLED=1
+E_DPKG_ALREADY_INSTALLED=2
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+E_NOT_VALID_ARCHIVE=8
+
+echo "find pakcage $1" >> /tmp/nativescriptlog
+
+CURDIR=`pwd`
+echo $CURDIR >> /tmp/nativescriptlog
+
+debug () {
+       echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+if [ $# -ne 1 ];then
+       DEBUG="Usage: find_package.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+fi
+
+PKGNAME=$1
+echo "pkg name = $PKGNAME" >> /tmp/nativescriptlog
+
+PKG_LOG_DIR=/var/pkgmgr/$PKGNAME
+if [ ! -d $PKG_LOG_DIR ];then
+       DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+       mkdir -p $PKG_LOG_DIR
+fi
+
+
+
+dpkg --list |grep $PKGNAME
+retval=$?
+echo "retval = $retval" >> /tmp/nativescriptlog
+
+if [ $retval -ne 0 ];then
+       DEBUG="pakcage not exist";debug
+       cd $CURDIR
+       exit $E_DPKG_NOT_INSTALLED
+fi
+
+versioninfo=`dpkg --list |grep $PKGNAME|tr -s ' ' | cut -f3 "-d "`
+
+echo "Package: $PKGNAME" > $PKG_LOG_DIR/pkginfo
+echo "Version: $versioninfo" >> $PKG_LOG_DIR/pkginfo
+
+cd $CURDIR
+exit $E_DPKG_ALREADY_INSTALLED
diff --git a/frontend/inc/frontend.h b/frontend/inc/frontend.h
new file mode 100755 (executable)
index 0000000..1b1c1d7
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#ifndef __DEF_EMPTY_H_
+#define __DEF_EMPTY_H_
+
+#include <Elementary.h>
+/*#include <comm_client.h>*/
+#include<pkgmgr_installer.h>
+
+#ifndef APP_DIR
+#define APP_DIR        "/usr"
+#endif                         /* APP_DIR */
+
+#ifndef PACKAGE
+#define PACKAGE        ""
+#endif                         /* PACKAGE */
+
+#define LOCALE_PATH    APP_DIR"/share/locale"
+#define EDJ_PATH       APP_DIR"/share/data"
+#define EDJ_NAME       EDJ_PATH"/c-empty.edj"
+#define GRP_MAIN       "default"
+
+extern int greturn_main_value;
+
+struct frontendcmdlinearg {
+       int reqcommand;
+       char *ppkgname;
+       char *pkeyid;
+       int quiteoptions;
+};
+
+enum command {
+       INVALID_CMD = 0,
+       INSTALL_CMD = 1,
+       DELETE_CMD = 2,
+       UPDATE_CMD = 3,
+       RECOVER_CMD = 4,
+       CLEAR_CMD = 5
+};
+
+typedef struct data_t {
+       const char *name;
+       const char *key;
+       const char *val;
+} uidata;
+struct frontenddata {
+
+       /* add more variables here */
+       struct frontendcmdlinearg *cmdlineargs;
+       /*comm_client *GCommClient;*/
+       char *gptr_security_cookie;
+       char *perror_string;
+};
+
+struct appdata {
+       Evas *evas;
+       Evas_Object *win_main;
+       Evas_Coord root_w;
+       Evas_Coord root_h;
+
+       Evas_Object *main_view; /* for main view layout*/
+       Evas_Object *details_scroller;
+       Evas_Object *progressbar;
+       Evas_Object *scrollbar_label;
+
+       Ecore_Event_Handler *key_up;
+       Ecore_Event_Handler *key_down;
+};
+
+int app_create(void *user_data);
+int app_terminate(void *user_data);
+int app_pause(void *user_data);
+int app_resume(void *user_data);
+int app_reset(bundle *b, void *user_data);
+int app_rotation(enum appcore_rm, void *user_data);
+
+int _cmdline_destroy(struct frontenddata *data);
+int _cmdline_process(struct frontenddata *data);
+int _parse_cmdline(int argc, char **argv, struct frontendcmdlinearg *pardata);
+void _package_downgrade_information(const char *message);
+void _frontend_update_progress_info(struct appdata *data, char *progressinfo);
+
+
+#endif                         /* __DEF_EMPTY_H_ */
diff --git a/frontend/install_spk.sh b/frontend/install_spk.sh
new file mode 100755 (executable)
index 0000000..0e49ca1
--- /dev/null
@@ -0,0 +1,102 @@
+#!/bin/sh
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+E_DPKG_ERROR=8
+
+PKG_LOG_DIR=/var/pkgmgr/native
+
+
+debug () {
+       echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+NOARG=$#
+#echo "No of Arguments = $NOARG"
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 4 ] ; then
+       DEBUG="Usage: install.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+       OPTIONS_FLAGS=$2
+elif [ $NOARG -eq 3 ] ; then
+       STATUS_OPTIONS=$2
+       STATUS_FD=$3
+elif [ $NOARG -eq 4 ] ; then
+       OPTIONS_FLAGS=$2
+       STATUS_OPTIONS=$3
+       STATUS_FD=$4
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+       DEBUG="File not found";debug
+       exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+       DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+       mkdir -p $PKG_LOG_DIR
+fi
+
+PKGFILENAME="${PKGFILE_PATH##*/}"
+###############
+#PKGNAME=${PKGFILENAME%-[0-9]*.*} <- NG(PKGName can be different with PkgFileName)
+/usr/bin/extract_manifest.sh "$PKGFILE_PATH"
+PKGNAME=`grep -i Package: /var/pkgmgr/"$PKGFILENAME"/metainfo/control | awk -F: '{print $2}' | sed 's/^[ ]*//'`
+rm -rf /var/pkgmgr/"$PKGFILENAME"
+###############
+
+touch $PKG_LOG_DIR/$PKGNAME.install
+echo "$PKGFILE_PATH" > $PKG_LOG_DIR/$PKGNAME.install
+
+#echo "pkg name = $PKGFILENAME"
+#echo "Options = $OPTIONS_FLAGS"
+#echo "Status Fd options = $STATUS_OPTIONS"
+#echo "Status Fd = $STATUS_FD"
+dpkg $OPTIONS_FLAGS $STATUS_OPTIONS $STATUS_FD --install "$PKGFILE_PATH"
+dpkgretval=$?
+if [ $dpkgretval -ne 0 ]; then                                                                               
+       DEBUG="dpkg returned error ";debug                                                                   
+       exit $E_DPKG_ERROR                                                                                   
+else                                                                                                         
+       DEBUG="dpkg success ";debug                                                                          
+fi
+
+#DAC
+USERNAME=`echo $PKGNAME | tr '.' '_'`
+GROUPNAME=$USERNAME
+#INHOUSEGROUPNAME=`id -nG inhouse|tr ' ' ','`
+INHOUSEGROUPNAME=`id -nG inhouse`
+PKGFOLDERNAME=/opt/apps/$PKGNAME
+
+if [ -d $PKGFOLDERNAME ];then
+       DEBUG="home Folder exist";debug
+else
+       DEBUG="home Folder not exist; creating";debug
+       mkdir -p $PKGFOLDERNAME
+fi
+
+#deluser $USERNAME
+#addgroup $GROUPNAME
+
+#i=10000
+#while [ $i -le 64999 ]
+#do
+#      adduser -G $GROUPNAME -h $PKGFOLDERNAME/home -u $i -D $USERNAME 
+#      if [ $? -eq 0 ]
+#      then
+#              break
+#      else
+#              i=`expr $i + 1`
+#      fi
+#done
+
+
+#for grp in $INHOUSEGROUPNAME
+#do
+#      addgroup $USERNAME $grp
+#done
+
+
diff --git a/frontend/src/frontendappcoreintf.c b/frontend/src/frontendappcoreintf.c
new file mode 100755 (executable)
index 0000000..06644e7
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+  
+#include <stdio.h>
+#include <Elementary.h>
+#include <appcore-efl.h>
+#include <string.h>
+#include <glib-object.h>
+/*#include <utilX.h>*/
+
+#include "frontend.h"
+#include "frontendhomeview.h"
+#include "native_installer_util.h"
+#include "nativeinstaller.h"
+#include<pkgmgr_installer.h>
+
+static void __start_processing(void *user_data);
+
+int greturn_main_value = -1;
+struct appdata ad;
+extern struct frontenddata frontdata;
+extern char scrolllabel[256];
+pkgmgr_installer *pi = NULL;
+extern int do_upgrade;
+
+/**< Called before main loop */
+int app_create(void *user_data)
+{
+       int ret = 0;
+       struct appdata *data = (struct appdata *)user_data;
+       struct frontendcmdlinearg *pardata = frontdata.cmdlineargs;
+
+       if (pardata->quiteoptions == 0) {
+               /* Launch UI */
+               ret = _frontend_launch_main_view(data);
+               return ret;
+       }
+
+       return 0;
+}
+
+/**< Called after main loop */
+int app_terminate(void *user_data)
+{
+       struct appdata *data = (struct appdata *)user_data;
+       struct frontendcmdlinearg *pardata = frontdata.cmdlineargs;
+       if (pardata->quiteoptions == 0) {
+               /* Launch UI */
+               _destroy_home_view(data);
+       }
+       return 0;
+}
+
+/**< Called when every window goes back */
+int app_pause(void *user_data)
+{
+       /*printf("called app_pause\n"); */
+       return 0;
+}
+
+/**< Called when any window comes on top */
+int app_resume(void *user_data)
+{
+       /*printf("called app_resume\n"); */
+       return 0;
+}
+
+/**< Called at the first idler*/
+int app_reset(bundle *b, void *user_data)
+{
+       /*printf("called app_reset\n"); */
+       return 0;
+}
+
+/**< Called at rotate device*/
+int app_rotation(enum appcore_rm mode, void *user_data)
+{
+       struct appdata *data = (struct appdata *)user_data;
+       int angle;
+       switch (mode) {
+       case APPCORE_RM_LANDSCAPE_NORMAL:
+               angle = -90;
+               break;
+
+       case APPCORE_RM_LANDSCAPE_REVERSE:
+               angle = 90;
+               break;
+
+       case APPCORE_RM_PORTRAIT_REVERSE:
+               angle = 180;
+               break;
+
+       case APPCORE_RM_UNKNOWN:
+       case APPCORE_RM_PORTRAIT_NORMAL:
+       default:
+               angle = 0;
+               break;
+       }
+       elm_win_rotation_with_resize_set(data->win_main, angle);
+       return 0;
+}
+
+Eina_Bool show_popup_cb(void *data)
+{
+       int state = -1;
+       const char message[256] = {'\0'};
+       strncpy(message, _("Continue Downgrade?"), 255);
+       state = _get_backend_state_info();
+       switch (state) {
+       case REQUEST_ACCEPTED:
+               break;
+       case GOT_PACKAGE_INFO_SUCCESSFULLY:
+               break;
+       case DPKG_REQUEST_PENDING:
+               _package_downgrade_information(message);
+               _set_backend_state_info(REQUEST_ACCEPTED);
+               break;
+       case DPKG_REQUEST_COMPLETED:
+       default:
+               if (frontdata.cmdlineargs->quiteoptions == 0) {
+                       _frontend_update_progress_info(&ad, scrolllabel);
+                       return 0;
+               }
+               else
+                       elm_exit();
+               break;
+       }
+
+       return 1;
+}
+
+static void __start_processing(void *user_data)
+{
+       int ret = 0;
+       struct frontenddata *data = (struct frontenddata *)user_data;
+       g_type_init();
+       ret = _cmdline_process(data);
+       greturn_main_value = ret;
+       _cmdline_destroy(data);
+       
+}
+
+int main(int argc, char *argv[])
+{
+       int ret = 0;
+       struct frontendcmdlinearg *pardata = NULL;
+       struct appcore_ops ops;
+       Ecore_Idler *popup_handle = NULL;
+       ops.create = app_create;
+       ops.terminate = app_terminate;
+       ops.pause = app_pause;
+       ops.resume = app_resume;
+       ops.reset = app_reset;
+       ops.data = &ad;
+
+       ecore_init();
+       appcore_set_i18n(PACKAGE, LOCALE_PATH);
+       _d_msg_init("frontend");
+       d_msg_frontend(DEBUG_RESULT, "Frontend version: %s\n",
+                      NATIVE_INSTALLER_VERSION);
+       pardata = (struct frontendcmdlinearg *)calloc(1,
+                                       sizeof(struct frontendcmdlinearg));
+       if (pardata == NULL) {
+               d_msg_frontend(DEBUG_ERR, "not enough memory\n");
+               ret = NATIVEINSTALLER_ERR_NOT_ENOUGH_MEMORY;
+               goto ERROR;
+       }
+       pardata->pkeyid = NULL;
+       pardata->ppkgname = NULL;
+       pardata->quiteoptions = 0;
+       pardata->reqcommand = INVALID_CMD;
+
+       /* We need to use pkgmgr_installer_receive request() 
+       to parse the arguments */
+       if ((ret =
+            _parse_cmdline(argc, argv, pardata)) != NATIVEINSTALLER_SUCCESS) {
+               d_msg_frontend(DEBUG_ERR, "_parse_cmdline failed \n");
+               goto ERROR;
+       }
+
+       frontdata.cmdlineargs = pardata;
+       frontdata.gptr_security_cookie = NULL;
+       frontdata.perror_string = NULL;
+       __start_processing(&frontdata);
+       
+       /*The installer has finished the installation/uninstallation.
+       Now, if it was a non quite operation we need to show the popup. */
+       popup_handle = ecore_idler_add(show_popup_cb, NULL);
+       
+       d_msg_frontend(DEBUG_RESULT, "about to run efl main loop");
+       appcore_efl_main(PACKAGE, &argc, &argv, &ops);
+       d_msg_frontend(DEBUG_RESULT, "%d\n", greturn_main_value);
+#if 1
+       _d_msg_deinit();
+       if (pi) {
+               pkgmgr_installer_free(pi);
+               pi = NULL;
+       }
+#endif
+       return greturn_main_value;
+
+ ERROR:
+       if (pardata) {
+               if (pardata->ppkgname) {
+                       free(pardata->ppkgname);
+                       pardata->ppkgname = NULL;
+               }
+               if (pardata->pkeyid) {
+                       free(pardata->pkeyid);
+                       pardata->pkeyid = NULL;
+               }
+               free(pardata);
+               pardata = NULL;
+       }
+       d_msg_frontend(DEBUG_RESULT, "%d\n", ret);
+       _d_msg_deinit();
+       return ret;
+
+}
+
diff --git a/frontend/src/frontendcmdline.c b/frontend/src/frontendcmdline.c
new file mode 100755 (executable)
index 0000000..aac09c1
--- /dev/null
@@ -0,0 +1,367 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+  
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <appcore-efl.h>
+#include "frontend.h"
+
+#include "native_installer_util.h"
+#include "nativeinstaller.h"
+#include<pkgmgr_installer.h>
+#include <security-server.h>
+
+#define _FIX_POP_UP_
+extern struct appdata ad;
+extern pkgmgr_installer *pi;
+struct frontenddata frontdata;
+char scrolllabel[256];
+int quiet;
+
+static void __show_usage(char **arg);
+static int __process_request(struct frontendcmdlinearg *pardata);
+
+
+extern int main_of_backend(char *keyid, char *pkgname, char *reqcommand);
+
+static void __show_usage(char **arg)
+{
+       int i = 0;
+       char buffer[256];
+       char tBuff[256] = "";
+       while (arg[i] != NULL) {
+               snprintf(buffer, 256, "%s %s", tBuff, arg[i]);
+               strncpy(tBuff, buffer, 255);
+               i++;
+       }
+
+       d_msg_frontend(DEBUG_INFO, "%s\n", buffer);
+       d_msg_frontend(DEBUG_INFO,
+                      "\nnative-backend usage\n   native-backend -k <keyid>  <command> <pkg_name | pkg_path> [-q] \n\n");
+       d_msg_frontend(DEBUG_INFO, "<Commands> \n");
+       d_msg_frontend(DEBUG_INFO,
+               "\t -i <PackageFilePath>          : install package file \n");
+       d_msg_frontend(DEBUG_INFO,
+               "\t -k <keyid>                  : key id file \n");
+       d_msg_frontend(DEBUG_INFO,
+               "\t -r : (recover). Must ignore specific package name or path \n");
+       d_msg_frontend(DEBUG_INFO,
+               "\t -d <PackageName>            : delete a package with Package Name \n");
+       d_msg_frontend(DEBUG_INFO,
+               "\t -q : (quite) run in background without any user interaction \n");
+}
+
+int _parse_cmdline(int argc, char **argv, struct frontendcmdlinearg *pardata)
+{
+       int reqcommand = INVALID_CMD;
+       const char *ppkgname = NULL;
+       int quiteopt = 0;
+       const char *pkeyid = NULL;
+       int ret = 0;
+       /*const char *licensePath = NULL;
+       FILE *fd = NULL;
+       char licenseBuf[1024*4] = {'\0'};
+       unsigned int licenseBuflen = 0;
+       char decLicenseBuf[1024*4] = {'\0'};
+       unsigned int decLicenseBuflen = 0;
+       char decPackageName[256] = {'\0'};
+       char temp[256] = {'\0'};
+       char *ptr = NULL;*/
+       pi = pkgmgr_installer_new();
+       if (!pi) {
+               d_msg_frontend(DEBUG_ERR,
+                              "Failure in creating the pkgmgr_installer object \n");
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       }
+       ret = pkgmgr_installer_receive_request(pi, argc, argv);
+       if (ret) {
+               d_msg_frontend(DEBUG_ERR,
+                              "pkgmgr_installer_receive_request failed \n");
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       }
+       ret = pkgmgr_installer_get_request_type(pi);
+       switch (ret) {
+       case PKGMGR_REQ_INSTALL:
+               reqcommand = INSTALL_CMD;
+               break;
+       case PKGMGR_REQ_UNINSTALL:
+               reqcommand = DELETE_CMD;
+               break;
+       case PKGMGR_REQ_RECOVER:
+               reqcommand = RECOVER_CMD;
+               break;
+       case PKGMGR_REQ_CLEAR:
+               reqcommand = CLEAR_CMD;
+               break;
+       case PKGMGR_REQ_PERM:
+               goto PARSEERROR;
+       case PKGMGR_REQ_INVALID:
+               reqcommand = INVALID_CMD;
+               goto PARSEERROR;
+       default:
+               goto PARSEERROR;
+       }
+       if (reqcommand != RECOVER_CMD) {
+               ppkgname = pkgmgr_installer_get_request_info(pi);
+               if (!ppkgname) {
+                       d_msg_frontend(DEBUG_ERR,
+                                      "pkgmgr_installer_get_request_info failed \n");
+                       return NATIVEINSTALLER_ERR_WRONG_PARAM;
+               }
+               pkeyid = pkgmgr_installer_get_session_id(pi);
+               if (!pkeyid) {
+                       d_msg_frontend(DEBUG_ERR,
+                                      "pkgmgr_installer_get_session_id failed \n");
+                       return NATIVEINSTALLER_ERR_WRONG_PARAM;
+               }
+
+               quiteopt = pkgmgr_installer_is_quiet(pi);
+               if (quiteopt != 0 && quiteopt != 1) {
+                       d_msg_frontend(DEBUG_ERR,
+                                      "pkgmgr_installer_is_quiet failed \n");
+                       return NATIVEINSTALLER_ERR_WRONG_PARAM;
+               }
+       }
+       quiet = quiteopt;
+       if (reqcommand != INSTALL_CMD && reqcommand != DELETE_CMD
+           && reqcommand != RECOVER_CMD && reqcommand != CLEAR_CMD) {
+               d_msg_frontend(DEBUG_ERR, "invalid command \n");
+               goto PARSEERROR;
+       }
+       
+       pardata->reqcommand = reqcommand;
+       pardata->ppkgname = (char *)ppkgname;
+       pardata->quiteoptions = quiteopt;
+       pardata->pkeyid = (char *)pkeyid;
+       return NATIVEINSTALLER_SUCCESS;
+
+ PARSEERROR:
+       d_msg_frontend(DEBUG_ERR, "Error in parsing input parameter\n");
+       __show_usage(argv);
+       return NATIVEINSTALLER_ERR_WRONG_PARAM;
+
+}
+
+static int __process_request(struct frontendcmdlinearg *pardata)
+{
+       int ret = 0;
+       if (!pardata)
+               return NATIVEINSTALLER_ERR_WRONG_PARAM;
+       char *pkgname = NULL;
+       char *keyid = NULL;
+       if (pardata->reqcommand != RECOVER_CMD) {
+               pkgname = strdup(pardata->ppkgname);
+               if (PM_UNLIKELY(pkgname == NULL)) {
+                       d_msg_frontend(DEBUG_ERR, "strdup failed\n");
+                        return NATIVEINSTALLER_ERR_WRONG_PARAM;
+               }
+               keyid = strdup(pardata->pkeyid);
+               if (PM_UNLIKELY(keyid == NULL)) {
+                       d_msg_frontend(DEBUG_ERR, "strdup failed\n");
+                       free(pkgname);
+                       return NATIVEINSTALLER_ERR_WRONG_PARAM;
+               }
+       }
+       switch (pardata->reqcommand) {
+       case INSTALL_CMD:
+               d_msg_frontend(DEBUG_INFO, "native-backend -i %s\n", pkgname);
+               ret = main_of_backend(keyid, pkgname, "install");
+               break;
+       case DELETE_CMD:
+               d_msg_frontend(DEBUG_INFO, "native-backend -d %s\n", pkgname);
+               ret = main_of_backend(keyid, pkgname, "remove");
+               break;
+       case RECOVER_CMD:
+               d_msg_frontend(DEBUG_INFO, "native-backend -r \n");
+               ret = main_of_backend(keyid, pkgname, "recover");
+               break;
+       case CLEAR_CMD:
+               d_msg_frontend(DEBUG_INFO, "native-backend -c %s\n", pkgname);
+               ret = main_of_backend(keyid, pkgname, "clear");
+               break;
+       default:
+               d_msg_frontend(DEBUG_ERR,
+                              "Error Never Come Here as Error is already checked\n");
+
+       }
+       if (keyid) {
+               free(keyid);
+               keyid = NULL;
+       }
+       if (pkgname) {
+               free(pkgname);
+               pkgname = NULL;
+       }
+
+       return ret;
+}
+
+void stat_cb(const char *pkg_name, const char *key, const char *val)
+{
+
+#ifdef _FIX_POP_UP_
+
+       if (NULL == pkg_name || NULL == key || NULL == val) {
+               d_msg_frontend(DEBUG_ERR, "Either pkg_name/key/val is NULL\n");
+               return;         /*TODO: handle error. */
+       }
+
+       char *pkg_name_modified = NULL;
+       char delims[] = "/";
+       char *result = NULL;
+       char *pkgname = NULL;
+       char *saveptr = NULL;
+
+       pkg_name_modified = (char *)malloc(strlen(pkg_name) + 1);
+       if (pkg_name_modified == NULL) {
+               d_msg_frontend(DEBUG_ERR,
+                              "pkg_name_modified is NULL. Malloc failed\n");
+               return;
+       }
+       memset(pkg_name_modified, '\0', strlen(pkg_name) + 1);
+       memcpy(pkg_name_modified, pkg_name, strlen(pkg_name));
+
+       result = strtok_r(pkg_name_modified, delims, &saveptr);
+       while (result != NULL) {
+               pkgname = result;
+               result = strtok_r(NULL, delims, &saveptr);
+       }
+
+#else
+       char *pkgname = pkg_name;
+#endif
+
+       if (strcmp(key, "install_percent") == 0) {
+               return;
+       } else if (strcmp(key, "error") == 0) {
+               /* Store the error to be display to the user */
+               frontdata.perror_string = strdup(val);
+       } else if (strcmp(key, "end") == 0) {
+
+               char requesttype[32];
+               switch (frontdata.cmdlineargs->reqcommand) {
+               case INSTALL_CMD:
+                       snprintf(requesttype, sizeof(requesttype), _("Installation"));
+                       break;
+               case DELETE_CMD:
+                       snprintf(requesttype, sizeof(requesttype), _("Deletion"));
+                       break;
+               case CLEAR_CMD:
+                       snprintf(requesttype, sizeof(requesttype), _("Clear Data"));
+                       break;
+               default:
+                       snprintf(requesttype, sizeof(requesttype), _("Recovery"));
+                       break;
+               }
+
+               if (frontdata.perror_string) {
+                       /* Error Happened */
+                       snprintf(scrolllabel, sizeof(scrolllabel), "%s :: %s:: %s:: %s",
+                               requesttype, pkgname,
+                               dgettext("sys_string", "IDS_COM_POP_ERROR"),
+                               frontdata.perror_string);
+                       d_msg_frontend(DEBUG_ERR, "%s\n", scrolllabel);
+                       greturn_main_value =
+                           _string_to_error_no(frontdata.perror_string);
+                       d_msg_frontend(DEBUG_ERR, "%d\n", greturn_main_value);
+                       /*gReturnMainValue = -1; */
+               } else {
+                       snprintf(scrolllabel, sizeof(scrolllabel), " %s :: %s :: %s",
+                               requesttype, pkgname,
+                               dgettext("sys_string", "IDS_COM_POP_SUCCESS"));
+                       d_msg_frontend(DEBUG_INFO, "%s\n", scrolllabel);
+                       greturn_main_value = 0;
+               }
+
+               
+       }
+
+}
+
+int _cmdline_process(struct frontenddata *data)
+{
+       char *cookie = NULL;
+       int cookie_size = 0;
+       int cookie_ret = 0;
+
+       int ret = 0;
+       struct frontendcmdlinearg *pardata = data->cmdlineargs;
+
+       cookie_size = security_server_get_cookie_size();
+       /* If security server is down or some other
+       error occured, raise failure */
+       if (0 >= cookie_size) {
+               /* TODO: raise error */
+               d_msg_frontend(DEBUG_ERR,
+                              "security_server_get_cookie_size: Security server down \n");
+       } else {
+               cookie = calloc(cookie_size, sizeof(char));
+               if(cookie == NULL)
+                       goto RETURN;
+               
+               cookie_ret =
+                   security_server_request_cookie(cookie, cookie_size);
+               /* TODO: Check cookie_ret...
+               (See security-server.h to check return code) */
+       }
+
+       if (cookie != NULL)
+               d_msg_frontend(DEBUG_INFO, "Frontend Cookies is generated - size[%d]\n", cookie_size);
+
+       data->gptr_security_cookie = cookie;
+
+       ret = __process_request(pardata);
+       if (ret != NATIVEINSTALLER_SUCCESS) {
+               d_msg_frontend(DEBUG_ERR, "__process_request: Error\n");
+               goto RETURN;
+       }
+
+       return NATIVEINSTALLER_SUCCESS;
+
+ RETURN:
+
+       if (data->gptr_security_cookie) {
+               free(data->gptr_security_cookie);
+               data->gptr_security_cookie = NULL;
+       }
+
+       return ret;
+}
+
+int _cmdline_destroy(struct frontenddata *data)
+{
+       if (data == NULL)
+               return 0;
+
+       if (data->gptr_security_cookie)
+               free(data->gptr_security_cookie);
+
+       return 0;
+
+}
+
diff --git a/frontend/ui/include/frontendhomeview.h b/frontend/ui/include/frontendhomeview.h
new file mode 100755 (executable)
index 0000000..2b2faac
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#ifndef HOME_VIEW_H_
+#define HOME_VIEW_H_
+
+void _information_popup(Evas_Smart_Cb func, const char *output,
+                       void *user_param);
+void _package_downgrade_popup(Evas_Smart_Cb func1, Evas_Smart_Cb func2, const char *output,
+                             void *user_param);
+Eina_Bool _init_appdata(struct appdata *ad);
+Eina_Bool _init_home_view(struct appdata *ad);
+void _destroy_home_view(struct appdata *ad);
+int _frontend_launch_main_view(struct appdata *data);
+
+#endif                         /* HOME_VIEW_H_ */
+
diff --git a/frontend/ui/layout/c-empty.edc b/frontend/ui/layout/c-empty.edc
new file mode 100755 (executable)
index 0000000..6b266cb
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ *  native-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#define FONT_TITLE_NAME "system_title" //"system_title"
+#define FONT_CONTENT_NAME "system_content"     //"system_content"
+#define FONT_SUBCONTENT_NAME "system_subcontent"       //"system_subcontent"
+
+#define MAIN_H 480
+#define MAIN_W 800
+
+#define RESOURCE_PATH  ui/res/icon
+
+images {
+       image: "ui/res/icon/image_editor_button_cancel.png" COMP;
+}
+       
+styles{
+       style 
+       { 
+               name: "info_style";
+               base: "font=system_content font_size=24  align=left color=#ffffff linesize =20 ";
+               //tag:  "br" "\n";
+               tag:  "tab" "\t";
+               tag:  "em" "+ font=system_content:style=Oblique";
+               tag:  "b" "+ font=system_content:style=Bold"; 
+               tag:  "link" "+ color=#800 underline=on underline_color=#8008";
+               tag:  "hilight" "+ font=system_content:style=Bold";
+       }
+}
+
+collections {
+       group{ name: "main";
+               parts {
+                       part { 
+                               name: "background_main";
+                               type: RECT;
+                               mouse_events: 1;
+                               description
+                               {
+                                       state: "default" 0.0;
+                                       visible :1;
+                                       rel1 {  relative: 0.0 0.0;  }
+                                       rel2 {  relative: 1.0 1.0;  }
+                                       color:0 0 0 255;
+                   }
+               }
+                       part { 
+                               name: "titlebar";
+                               type: RECT;
+                               mouse_events: 1;
+                               description
+                               {
+                                       state: "default" 0.0;
+                                       visible :1;
+                                       rel1 {  relative: 0.0 0.05;  }
+                                       rel2 {  relative: 1.0 0.1;  }
+                                       color:0 0 0 255;
+                   }
+               }               
+                       part { 
+                               name: "title";
+                               type: TEXT; 
+                               mouse_events: 0; 
+                               description
+                               {
+                                       state: "default" 0.0;
+                                       rel1 { relative: 0.0 0.0; to: "titlebar"; }
+                                       rel2 { relative: 0.9 1.0;  to: "titlebar"; }
+                               text {
+                               text: "native installation";
+                               font: FONT_TITLE_NAME;
+                               size:   30;
+                                    } 
+                               }
+                             }
+                       part { 
+                               name: "exit_btn";
+                               type: IMAGE; 
+                               mouse_events: 1; 
+                               description
+                               {
+                                       state: "default" 0.0;
+                                       min: 30 30;
+                                       max: 40 40;
+                                       fixed: 1 1;
+                                       rel1 { relative: 0.9 0.0; to: "titlebar"; }
+                                       rel2 { relative: 1.0 1.0; to: "titlebar"; }
+                                       image { normal: "ui/res/icon/image_editor_button_cancel.png"; } 
+                 }
+                               description
+                               {
+                                       state: "hide" 0.0;
+                                       visible :0;
+                }
+                       }
+
+                       part { 
+                               name: "details_scroller_bg";
+                               type: RECT; 
+                               mouse_events: 0; 
+                               description
+                               {
+                                       state: "default" 0.0;
+                                       visible :1;
+                                       rel1 { relative: 0.0 0.1; to: "background_main"; }
+                                       rel2 { relative: 1.0 0.6; to: "background_main"; }                                      
+                                       color: 255 255 255 255;
+                }
+                       }                       
+                       part { 
+                               name: "details_scroller";
+                               type: SWALLOW; 
+                               mouse_events: 1; 
+                               description
+                               {
+                                       state: "default" 0.0;
+                                       fixed: 1 1;                             
+                                       rel1 { relative: 0.0 0.0; to: "details_scroller_bg"; }
+                                       rel2 { relative: 1.0 1.0; to: "details_scroller_bg"; }
+                }
+                       }
+                       
+               }       
+               
+               programs {
+                       program { 
+                               name: "exit_btn_clicked"; 
+                               signal: "mouse,clicked,1"; 
+                               source: "exit_btn"; 
+                               script { 
+                                       emit("clicked", "EXIT"); 
+                               } 
+                       }
+                       program { 
+                               name: "exit_btn_hide"; 
+                               signal: "exit_btn ,hide"; 
+                               source: "exit_btn"; 
+                               action: STATE_SET "hide" 0.0;
+                               target: "exit_btn";
+                       }
+                       program { 
+                               name: "exit_btn_show"; 
+                               signal: "exit_btn ,show"; 
+                               source: "exit_btn"; 
+                               action: STATE_SET "default" 0.0;
+                               target: "exit_btn";
+                       }                       
+               } // programs
+       } // groups
+}
+
diff --git a/frontend/ui/po/CMakeLists.txt b/frontend/ui/po/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..e3aebb4
--- /dev/null
@@ -0,0 +1,24 @@
+# for i18n
+
+SET(POFILES en_US.po en_GB.po ja_JP.po ko_KR.po zh_CN.po)
+
+SET(MSGFMT "/usr/bin/msgfmt")
+
+FOREACH(pofile ${POFILES})
+       SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile})
+       MESSAGE("PO: ${pofile}")
+       GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE)
+       GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE)
+       SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo)
+       ADD_CUSTOM_COMMAND(
+                       OUTPUT ${moFile}
+                       COMMAND ${MSGFMT} -o ${moFile} ${absPofile}
+                       DEPENDS ${absPofile}
+       )
+       INSTALL(FILES ${moFile}
+                       DESTINATION share/locale/${lang}/LC_MESSAGES RENAME ${PROJECT_NAME}.mo)
+       SET(moFiles ${moFiles} ${moFile})
+ENDFOREACH(pofile)
+
+MESSAGE(".mo files: ${moFiles}")
+ADD_CUSTOM_TARGET(po ALL DEPENDS ${moFiles})
diff --git a/frontend/ui/po/POTFILES.in b/frontend/ui/po/POTFILES.in
new file mode 100755 (executable)
index 0000000..0df340a
--- /dev/null
@@ -0,0 +1,4 @@
+# List of source files containing translatable strings.
+frontend/src/frontendappcoreintf.c
+frontend/src/frontendcmdline.c
+frontend/ui/src/frontendhomeview.c
diff --git a/frontend/ui/po/update-po.sh b/frontend/ui/po/update-po.sh
new file mode 100755 (executable)
index 0000000..80c74e7
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+PACKAGE=native-installer
+SRCROOT=..
+POTFILES=POTFILES.in
+
+#ALL_LINGUAS= am az be ca cs da de el en_CA en_GB es et fi fr hr hu it ja ko lv mk ml ms nb ne nl pa pl pt pt_BR ru rw sk sl sr sr@Latn sv ta tr uk vi zh_CN zh_TW
+ALL_LINGUAS="en_US en_GB ja_JP ko_KR zh_CN"
+
+XGETTEXT=/usr/bin/xgettext
+MSGMERGE=/usr/bin/msgmerge
+
+echo -n "Make ${PACKAGE}.pot  "
+if [ ! -e $POTFILES ] ; then
+       echo "$POTFILES not found"
+       exit 1
+fi
+
+$XGETTEXT --default-domain=${PACKAGE} --directory=${SRCROOT} \
+               --add-comments --keyword=_ --keyword=N_ --files-from=$POTFILES
+if [ $? -ne 0 ]; then
+       echo "xgettext error"
+       exit 1  
+fi
+
+if [ ! -f ${PACKAGE}.po ]; then
+       echo "No such file: ${PACKAGE}.po"
+       exit 1
+fi
+
+rm -f ${PACKAGE}.pot && mv ${PACKAGE}.po ${PACKAGE}.pot
+echo "done"
+
+for LANG in $ALL_LINGUAS; do 
+       echo "$LANG : "
+
+       if [ ! -e $LANG.po ] ; then
+               sed 's/CHARSET/UTF-8/g' ${PACKAGE}.pot > ${LANG}.po
+               echo "${LANG}.po created"
+       else
+               if $MSGMERGE ${LANG}.po ${PACKAGE}.pot -o ${LANG}.new.po ; then
+                       if cmp ${LANG}.po ${LANG}.new.po > /dev/null 2>&1; then
+                               rm -f ${LANG}.new.po
+                       else
+                               if mv -f ${LANG}.new.po ${LANG}.po; then
+                                       echo "" 
+                               else
+                                       echo "msgmerge for $LANG.po failed: cannot move $LANG.new.po to $LANG.po" 1>&2
+                                       rm -f ${LANG}.new.po
+                                       exit 1
+                               fi
+                       fi
+               else
+                       echo "msgmerge for $LANG failed!"
+                       rm -f ${LANG}.new.po
+               fi
+       fi
+       echo ""
+done
+
diff --git a/frontend/ui/res/icon/image_editor_button_cancel.png b/frontend/ui/res/icon/image_editor_button_cancel.png
new file mode 100755 (executable)
index 0000000..8d9d4f1
Binary files /dev/null and b/frontend/ui/res/icon/image_editor_button_cancel.png differ
diff --git a/frontend/ui/res/locale/CMakeLists.txt b/frontend/ui/res/locale/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..e3aebb4
--- /dev/null
@@ -0,0 +1,24 @@
+# for i18n
+
+SET(POFILES en_US.po en_GB.po ja_JP.po ko_KR.po zh_CN.po)
+
+SET(MSGFMT "/usr/bin/msgfmt")
+
+FOREACH(pofile ${POFILES})
+       SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile})
+       MESSAGE("PO: ${pofile}")
+       GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE)
+       GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE)
+       SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo)
+       ADD_CUSTOM_COMMAND(
+                       OUTPUT ${moFile}
+                       COMMAND ${MSGFMT} -o ${moFile} ${absPofile}
+                       DEPENDS ${absPofile}
+       )
+       INSTALL(FILES ${moFile}
+                       DESTINATION share/locale/${lang}/LC_MESSAGES RENAME ${PROJECT_NAME}.mo)
+       SET(moFiles ${moFiles} ${moFile})
+ENDFOREACH(pofile)
+
+MESSAGE(".mo files: ${moFiles}")
+ADD_CUSTOM_TARGET(po ALL DEPENDS ${moFiles})
diff --git a/frontend/ui/res/locale/en_GB.po b/frontend/ui/res/locale/en_GB.po
new file mode 100755 (executable)
index 0000000..7131edf
--- /dev/null
@@ -0,0 +1,42 @@
+# 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 <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/frontendappcoreintf.c:128
+#, c-format
+msgid "Continue Downgrade?"
+msgstr ""
+
+#: frontend/src/frontendcmdline.c:260
+#, c-format
+msgid "Installation"
+msgstr ""
+
+#: frontend/src/frontendcmdline.c:263
+#, c-format
+msgid "Deletion"
+msgstr ""
+
+#: frontend/src/frontendcmdline.c:266
+#, c-format
+msgid "Recovery"
+msgstr ""
+
+#: frontend/src/frontendcmdline.c:273
+#, c-format
+msgid "Clear Data"
+msgstr ""
diff --git a/frontend/ui/res/locale/en_US.po b/frontend/ui/res/locale/en_US.po
new file mode 100755 (executable)
index 0000000..7131edf
--- /dev/null
@@ -0,0 +1,42 @@
+# 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 <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/frontendappcoreintf.c:128
+#, c-format
+msgid "Continue Downgrade?"
+msgstr ""
+
+#: frontend/src/frontendcmdline.c:260
+#, c-format
+msgid "Installation"
+msgstr ""
+
+#: frontend/src/frontendcmdline.c:263
+#, c-format
+msgid "Deletion"
+msgstr ""
+
+#: frontend/src/frontendcmdline.c:266
+#, c-format
+msgid "Recovery"
+msgstr ""
+
+#: frontend/src/frontendcmdline.c:273
+#, c-format
+msgid "Clear Data"
+msgstr ""
diff --git a/frontend/ui/res/locale/ja_JP.po b/frontend/ui/res/locale/ja_JP.po
new file mode 100755 (executable)
index 0000000..e6285ca
--- /dev/null
@@ -0,0 +1,42 @@
+# 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 <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/frontendappcoreintf.c:128
+#, c-format
+msgid "Continue Downgrade?"
+msgstr "ダウングレード を続行しますか?"
+
+#: frontend/src/frontendcmdline.c:260
+#, c-format
+msgid "Installation"
+msgstr "インストール"
+
+#: frontend/src/frontendcmdline.c:263
+#, c-format
+msgid "Deletion"
+msgstr "削除"
+
+#: frontend/src/frontendcmdline.c:266
+#, c-format
+msgid "Recovery"
+msgstr "回復"
+
+#: frontend/src/frontendcmdline.c:273
+#, c-format
+msgid "Clear Data"
+msgstr "明確な データ"
diff --git a/frontend/ui/res/locale/ko_KR.po b/frontend/ui/res/locale/ko_KR.po
new file mode 100755 (executable)
index 0000000..aadd876
--- /dev/null
@@ -0,0 +1,42 @@
+# 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 <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/frontendappcoreintf.c:128
+#, c-format
+msgid "Continue Downgrade?"
+msgstr "다운 그레이드 를 계속하시겠습니까?"
+
+#: frontend/src/frontendcmdline.c:260
+#, c-format
+msgid "Installation"
+msgstr "설치"
+
+#: frontend/src/frontendcmdline.c:263
+#, c-format
+msgid "Deletion"
+msgstr "삭제"
+
+#: frontend/src/frontendcmdline.c:266
+#, c-format
+msgid "Recovery"
+msgstr "회복"
+
+#: frontend/src/frontendcmdline.c:273
+#, c-format
+msgid "Clear Data"
+msgstr "삭제 데이터"
diff --git a/frontend/ui/res/locale/zh_CN.po b/frontend/ui/res/locale/zh_CN.po
new file mode 100755 (executable)
index 0000000..d9aad84
--- /dev/null
@@ -0,0 +1,42 @@
+# 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 <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/frontendappcoreintf.c:128
+#, c-format
+msgid "Continue Downgrade?"
+msgstr "繼續 降級?"
+
+#: frontend/src/frontendcmdline.c:260
+#, c-format
+msgid "Installation"
+msgstr "安裝"
+
+#: frontend/src/frontendcmdline.c:263
+#, c-format
+msgid "Deletion"
+msgstr "刪除"
+
+#: frontend/src/frontendcmdline.c:266
+#, c-format
+msgid "Recovery"
+msgstr "恢復"
+
+#: frontend/src/frontendcmdline.c:273
+#, c-format
+msgid "Clear Data"
+msgstr "清除數據"
diff --git a/frontend/ui/src/frontendhomeview.c b/frontend/ui/src/frontendhomeview.c
new file mode 100755 (executable)
index 0000000..65def89
--- /dev/null
@@ -0,0 +1,256 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#include <appcore-efl.h>
+#include <Ecore_X.h>
+#include "frontend.h"
+#include "native_installer_util.h"
+#include "nativeinstaller.h"
+
+#define DESKTOP_W   720.0
+
+extern struct appdata ad;
+extern struct frontenddata frontdata;
+int do_upgrade = -1;
+
+static void __response_cb(void *data, Evas_Object * obj, void *event);
+static void __win_del(void *data, Evas_Object * obj, void *event);
+static Eina_Bool __perform_downgrade(void *data);
+
+void _information_popup(Evas_Smart_Cb func, const char *output,
+                               void *user_param)
+{
+       if (!ad.win_main)
+               return;
+       evas_object_show(ad.win_main);
+       Evas_Object *popup = NULL;
+       popup = elm_popup_add(ad.win_main);
+       if (!popup)
+               return;
+       elm_object_part_text_set(popup, dgettext("sys_string",
+                                               "IDS_COM_BODY_INFORMATION"), NULL);
+       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
+                                               EVAS_HINT_EXPAND);
+       elm_object_text_set(popup, output);
+
+       Evas_Object *button = NULL;
+       button = elm_button_add(popup);
+       elm_object_text_set(button, dgettext("sys_string", "IDS_COM_SK_OK"));
+       elm_object_part_content_set(popup, "button1", button);
+
+       evas_object_smart_callback_add(button, "clicked", func, user_param);
+       evas_object_show(popup);
+}
+
+void _package_downgrade_popup(Evas_Smart_Cb func1, Evas_Smart_Cb func2,
+                               const char *output, void *user_param)
+{
+       if (!ad.win_main) {
+               d_msg_frontend(DEBUG_ERR, "Main Window NULL\n");
+               return;
+       }
+       evas_object_show(ad.win_main);
+       
+       Evas_Object *popup = NULL;
+       popup = elm_popup_add(ad.win_main);
+       if (!popup) {
+               d_msg_frontend(DEBUG_ERR, "Add Popup Fail\n");
+               return;
+       }
+       elm_object_part_text_set(popup,
+                                       dgettext("sys_string", "IDS_COM_BODY_INFORMATION"), NULL);
+       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
+                                        EVAS_HINT_EXPAND);
+       elm_object_text_set(popup, output);
+
+       Evas_Object *button1 = NULL;
+       Evas_Object *button2 = NULL;
+
+       button1 = elm_button_add(popup);
+       elm_object_text_set(button1, dgettext("sys_string", "IDS_COM_SK_YES"));
+       elm_object_part_content_set(popup, "button1", button1);
+       evas_object_smart_callback_add(button1, "clicked", func1, user_param);
+
+       button2 = elm_button_add(popup);
+       elm_object_text_set(button2, dgettext("sys_string", "IDS_COM_SK_NO"));
+       elm_object_part_content_set(popup, "button2", button2);
+       evas_object_smart_callback_add(button2, "clicked", func2, user_param);
+
+       evas_object_show(popup);
+}
+
+static void __win_del(void *data, Evas_Object * obj, void *event)
+{
+       elm_exit();
+}
+
+static Eina_Bool __perform_downgrade(void *data)
+{
+       int ret = -1;
+       ret = _pkgmgr_package_install(frontdata.cmdlineargs->ppkgname,
+                                                          false, NULL);
+       if (ret != 0) {
+               char *errstr = NULL;
+               _error_no_to_string(ret, &errstr);
+               _broadcast_status_notification(frontdata.cmdlineargs->ppkgname,
+                                              "error", errstr);
+               stat_cb(frontdata.cmdlineargs->ppkgname, "error", errstr);
+               _broadcast_status_notification(frontdata.cmdlineargs->ppkgname,
+                                              "end", "fail");
+               stat_cb(frontdata.cmdlineargs->ppkgname, "end", "fail");
+               d_msg_backend(DEBUG_ERR,
+                             "install failed with err(%d) (%s)\n",
+                             ret, errstr);
+       } else {
+               d_msg_backend(DEBUG_INFO, "install success\n");
+               _broadcast_status_notification(frontdata.cmdlineargs->ppkgname,
+                                              "end", "ok");
+               stat_cb(frontdata.cmdlineargs->ppkgname, "end", "ok");
+       }
+       _set_backend_state_info(REQUEST_COMPLETED);
+       _set_backend_state(1);
+       return 0;
+}
+
+static void __response_cb1(void *data, Evas_Object * obj, void *event)
+{
+       printf("\nresponse callback=%d\n", (int)event);
+       Ecore_Idler *handle = NULL;
+       int response = (int)event;
+       
+       do_upgrade = 1;
+       handle = ecore_idler_add(__perform_downgrade, NULL);
+       d_msg_frontend(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
+       evas_object_del(obj);
+       obj = NULL;
+}
+
+static void __response_cb2(void *data, Evas_Object * obj, void *event)
+{
+       printf("\nresponse callback=%d\n", (int)event);
+       Ecore_Idler *handle = NULL;
+       
+       do_upgrade = 0;
+       handle = ecore_idler_add(__perform_downgrade, NULL);
+       evas_object_del(obj);
+       d_msg_frontend(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
+       obj = NULL;
+}
+
+Eina_Bool _init_appdata(struct appdata *user_data)
+{
+       unsigned char *prop_data = NULL;
+       int rotation = 0;
+       int w;
+       int h;
+       int x;
+       int y;
+       int count = 0;
+       user_data->win_main = elm_win_add(NULL, PACKAGE, ELM_WIN_DIALOG_BASIC);
+       if (!user_data->win_main)
+               return EINA_FALSE;
+
+       elm_win_title_set(user_data->win_main, PACKAGE);
+       elm_win_alpha_set(user_data->win_main, EINA_TRUE);
+       elm_win_borderless_set(user_data->win_main, EINA_TRUE);
+       elm_win_raise(user_data->win_main);
+       ecore_x_window_geometry_get(ecore_x_window_root_get
+                                   (ecore_x_window_focus_get()), &x, &y, &w,
+                                   &h);
+       int ret =
+           ecore_x_window_prop_property_get(ecore_x_window_root_get
+                                    (ecore_x_window_focus_get()),
+                                    ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE,
+                                    ECORE_X_ATOM_CARDINAL, 32,
+                                    &prop_data, &count);
+       if (ret && prop_data)
+               memcpy(&rotation, prop_data, sizeof(int));
+       if (prop_data)
+               free(prop_data);
+       evas_object_resize(user_data->win_main, w, h);
+       evas_object_move(user_data->win_main, x, y);
+       /*evas_object_show(user_data->win_main); */
+       evas_object_smart_callback_add(user_data->win_main, "delete,request",
+                                      __win_del, NULL);
+       elm_win_indicator_mode_set(user_data->win_main, ELM_WIN_INDICATOR_SHOW);
+
+       double s;
+       s = w / DESKTOP_W;
+       elm_config_scale_set(s);
+
+       /*evas_object_geometry_get(user_data->win_main, NULL,
+       NULL, &user_data->root_w, &user_data->root_h); */
+
+       user_data->evas = evas_object_evas_get(user_data->win_main);
+       if (!user_data->evas)
+               return EINA_FALSE;
+
+       return EINA_TRUE;
+}
+
+Eina_Bool _init_home_view(struct appdata *user_data)
+{
+       return EINA_TRUE;
+
+}
+
+void _destroy_home_view(struct appdata *user_data)
+{
+
+       if (!user_data) {
+               return;
+       }
+       evas_object_del(user_data->main_view);
+}
+
+int _frontend_launch_main_view(struct appdata *data)
+{
+       /* create UI */
+       if (!_init_appdata(data)) {
+               printf("ERROR: fail create window\n");
+               return 0;
+       }
+       /*ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, keydown_event, NULL); */
+
+       if (!_init_home_view(data)) {
+               printf("ERROR: fail create home view\n");
+               return 0;
+       }
+       return 0;
+}
+
+
+void _frontend_update_progress_info(struct appdata *data, char *progressinfo)
+{
+       elm_object_text_set(data->scrollbar_label, progressinfo);
+       _information_popup(__win_del, progressinfo, data);
+}
+
+void _package_downgrade_information(const char *message)
+{
+       _package_downgrade_popup(__response_cb1, __response_cb2, message, &ad);
+}
+
diff --git a/frontend/uninstall_spk.sh b/frontend/uninstall_spk.sh
new file mode 100755 (executable)
index 0000000..9d22b6e
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# 1. REMOVE MENUSCREEN
+
+# 2. REMOVE DB
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+E_DPKG_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/native
+
+debug () {
+        echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+NOARG=$#
+#echo "No of Arguments = $NOARG"
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 3 ] || [ $NOARG -eq 2 ]; then
+        DEBUG="Usage: uninstall.sh <PackageName>";debug
+        exit $E_WRONG_ARGS
+elif [ $NOARG -eq 3 ]; then
+        STATUS_OPTIONS=$2
+        STATUS_FD=$3
+fi
+
+
+if [ ! -d $PKG_LOG_DIR ];then
+        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+        mkdir -p $PKG_LOG_DIR
+fi
+
+PKGNAME=$1
+
+# 3. DELETE FILES
+dpkg $STATUS_OPTIONS $STATUS_FD --purge $PKGNAME
+ret=$?
+if [ $ret -ne 0 ];then
+       DEBUG="Dpkg error";debug
+       exit $E_DPKG_ERROR
+fi
+# 4. remove account
+USERNAME=`echo $PKGNAME | tr '.' '_'`
+INHOUSEGROUPNAME=`id -nG inhouse|tr ' ' ','`
+
+for grp in $INHOUSEGROUPNAME
+do
+       delgroup $USERNAME $grp
+done
+
+if [ ! -d /opt/apps/$1 ];then
+        DEBUG="Package Directory not found";debug
+       rm -rf /opt/apps/$PKGNAME
+fi
+
+
+deluser $USERNAME
+#delgroup $USERNAME
+
+# 5. clear log
diff --git a/frontend/update_avail_spk.sh b/frontend/update_avail_spk.sh
new file mode 100755 (executable)
index 0000000..010084d
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+E_WRONG_ARGS=5
+E_FILE_NOT_FOUND=6
+E_NO_MANIFEST=7
+
+PKG_LOG_DIR=/var/pkgmgr/native
+
+debug () {
+        echo ">>$DEBUG" >> /tmp/nativescriptlog
+}
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 3 ] || [ $NOARG -eq 2 ]; then
+        DEBUG="Usage: update_avail_spk.sh <controlfile>";debug
+        exit $E_WRONG_ARGS
+elif [ $NOARG -eq 3 ] ; then
+        STATUS_OPTIONS=$2
+        STATUS_FD=$3
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+        mkdir -p $PKG_LOG_DIR
+fi
+
+CONTROL_FILE=$1
+
+# 3. DELETE FILES
+dpkg $STATUS_OPTIONS $STATUS_FD --update-avail $CONTROL_FILE
+
diff --git a/inc/native_installer_util.h b/inc/native_installer_util.h
new file mode 100755 (executable)
index 0000000..c170701
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#ifndef NATIVEINSTALLERUTIL_H_
+#define NATIVEINSTALLERUTIL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
+#include <string.h>
+#include <stdarg.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <wait.h>
+#include <stdio.h>
+
+#define NATIVE_BACKEND_EXEC    "native-backend"
+
+#define PKGTYPE "deb"
+#define NATIVE_INSTALLER_VERSION                       "1.2.10"
+
+#define NATIVEINSTALLER_SUCCESS                                        0
+#define NATIVEINSTALLER_ERR_WRONG_PARAM                                3
+#define NATIVEINSTALLER_ERR_DBUS_PROBLEM                       4
+#define NATIVEINSTALLER_ERR_NOT_ENOUGH_MEMORY                  5
+#define NATIVEINSTALLER_ERR_NO_MANIFEST                                6
+#define NATIVEINSTALLER_ERR_PACKAGE_EXIST                      7
+#define NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED              8
+#define NATIVEINSTALLER_ERR_RESOURCE_BUSY                      9
+#define NATIVEINSTALLER_ERR_UNKNOWN                            10
+#define NATIVEINSTALLER_ERR_PKG_NOT_FOUND                      11
+#define NATIVEINSTALLER_ERR_NOT_SUPPOTED_VERSION               12
+#define NATIVEINSTALLER_ERR_NO_DEB_FILE                                13
+#define NATIVEINSTALLER_ERR_DB_ACCESS_FAILED                   14
+#define NATIVEINSTALLER_ERR_DPKG_OPERATION_FAILED              15
+#define NATIVEINSTALLER_PACKAGE_NOT_UPGRADED                   16
+#define NATIVEINSTALLER_ERR_NEED_USER_CONFIRMATION             17
+#define NATIVEINSTALLER_ERR_CLEAR_DATA_FAILED          18
+
+#define NATIVEINSTALLER_SUCCESS_STR                    "success"
+#define NATIVEINSTALLER_ERR_WRONG_PARAM_STR            "Wrong Input Param"
+#define NATIVEINSTALLER_ERR_DBUS_PROBLEM_STR                   "dbus error"
+#define NATIVEINSTALLER_ERR_NOT_ENOUGH_MEMORY_STR      "Not Enough Memory"
+#define NATIVEINSTALLER_ERR_NO_MANIFEST_STR                    "No Manifest"
+#define NATIVEINSTALLER_ERR_PACKAGE_EXIST_STR  "Package Already Installed"
+#define NATIVEINSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR  "Package Not Installed"
+#define NATIVEINSTALLER_ERR_RESOURCE_BUSY_STR                  "Resource Busy"
+#define NATIVEINSTALLER_ERR_UNKNOWN_STR                        "Unknown Error"
+#define NATIVEINSTALLER_ERR_PKG_NOT_FOUND_STR  "Package file not found"
+#define NATIVEINSTALLER_ERR_NOT_SUPPOTED_VERSION_STR   "Version Not supported"
+#define NATIVEINSTALLER_ERR_NO_DEB_FILE_STR    "No Debian Package"
+#define NATIVEINSTALLER_ERR_DB_ACCESS_FAILED_STR       "DB Access Failed"
+#define NATIVEINSTALLER_ERR_DPKG_OPERATION_FAILED_STR  "dpkg operation failed"
+#define NATIVEINSTALLER_PACKAGE_NOT_UPGRADED_STR       "Package Not Upgraded"
+#define NATIVEINSTALLER_ERR_CLEAR_DATA_FAILED_STR      "Clear Data Failed"
+
+#define DEBUG_ERR      0x0001
+#define DEBUG_INFO     0x0002
+#define DEBUG_RESULT   0x0004
+
+#define FRONTEND_LOG   1
+#define BACKEND_LOG    2
+
+extern int logging;
+
+void _print_msg(int type, int exetype, char *format, ...);
+#define d_msg_frontend(type, fmtstr, args...) { \
+_print_msg(type, FRONTEND_LOG, "%s():%d: " fmtstr, \
+__func__, __LINE__, ##args); \
+}
+
+#define d_msg_backend(type, fmtstr, args...) { \
+_print_msg(type, BACKEND_LOG, "%s():%d: " fmtstr, \
+__func__, __LINE__, ##args); \
+}
+
+void _d_msg_init(char *program);
+void _d_msg_deinit();
+int _xsystem(const char *argv[]);
+char *_substring(const char *str, size_t begin, size_t len);
+int _tok_split_string(char tok, char *input, char **list,
+                  unsigned long ListMax);
+void _error_no_to_string(int errnumber, char **errstr);
+int _string_to_error_no(char *errstr);
+
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+#endif                         /* NATIVEINSTALLERUTIL_H_ */
+
diff --git a/packaging/native-installer.spec b/packaging/native-installer.spec
new file mode 100755 (executable)
index 0000000..e955233
--- /dev/null
@@ -0,0 +1,73 @@
+Name:       native-installer
+Summary:    Native debian installer
+Version:    1.2.66
+Release:    1
+Group:      System/Libraries
+License:    Apache License, Version 2.0
+Source0:    %{name}-%{version}.tar.gz
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+BuildRequires:  cmake
+BuildRequires:  edje-bin
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(dbus-glib-1)
+BuildRequires:  pkgconfig(sqlite3)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(db-util)
+BuildRequires:  pkgconfig(pkgmgr-types)
+BuildRequires:  pkgconfig(pkgmgr-installer)
+BuildRequires:  pkgconfig(mdm)
+BuildRequires:  pkgconfig(security-server)
+BuildRequires:  pkgconfig(elementary)
+BuildRequires:  pkgconfig(appcore-efl)
+BuildRequires:  pkgconfig(evas)
+BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(edje)
+BuildRequires:  gettext-tools
+
+%description
+Native debian installer
+
+%prep
+%setup -q
+
+%build
+CFLAGS+=" -fpic"
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post
+mkdir -p /usr/etc/package-manager/backend
+mkdir -p /usr/etc/package-manager/backendlib
+ln -sf /usr/bin/native-backend /usr/etc/package-manager/backend/deb
+if [ "${USER}" = "root" ]
+then
+        chown 5000:5000 /usr/lib/native-installer/libnative-util.a
+        chown 5000:5000 /usr/bin/native-backend
+fi
+
+chmod 755 /usr/lib/native-installer/libnative-util.a
+chmod 755 /usr/bin/native-backend
+
+%files
+/usr/bin/native-backend
+/usr/bin/install_spk.sh
+/usr/bin/audit_spk.sh
+/usr/bin/extract_manifest.sh
+/usr/bin/uninstall_spk.sh
+/usr/bin/update_avail_spk.sh
+/usr/bin/find_package.sh
+/usr/share/icon/image_editor_button_cancel.png
+/usr/share/data/c-empty.edj
+/usr/share/locale/en_GB/LC_MESSAGES/native-installer.mo
+/usr/share/locale/ja_JP/LC_MESSAGES/native-installer.mo
+/usr/share/locale/zh_CN/LC_MESSAGES/native-installer.mo
+/usr/share/locale/en_US/LC_MESSAGES/native-installer.mo
+/usr/share/locale/ko_KR/LC_MESSAGES/native-installer.mo
+/usr/etc/package-manager/backendlib/libdeb.so