Sync with tizen_2.2.1 appfw spec
[platform/framework/native/appfw.git] / src / app / FApp_AppEntry.cpp
index e81f4c2..ce76bb0 100644 (file)
 #include <dlog.h>
 #include <privilege-control.h>
 #include <pkgmgr-info.h>
+#include <appinfo.h>
 
 #include <FOspConfig.h>
 
 
 #define LOG_IO_TAG  "LOADER"
-#define MAX_PACKAGE_ID   20
+#define MAX_PACKAGE_ID   10
 #define MAX_APP_EXECUTABLE_NAME        230
 #define MAX_PACKAGE_NAME       100
 #define        MAX_PR_NAME     16
@@ -58,40 +59,12 @@ extern "C"
 
 extern int OspMain(int argc, char* pArgv[]) __attribute__((weak));
 //extern void Osp_Initialize();
-extern void InitAppInfo(const char* appId, const char* exeName, int argc, char* pArgv[], int fd);
+extern void AppInfo_Update(void);
 
 static void
 AdjustPrivilege(const char* pkgname)
 {
-       void* handle = dlopen("libprivilege-control.so.0", RTLD_LAZY | RTLD_LOCAL);
-       if (!handle)
-       {
-               fprintf(stderr, "Cannot open libprivilege-control.so.0\n");
-               return;
-       }
-
-       char* msg = 0;
-       dlerror();
-
-       int (* ppriv_func)(const char*) = NULL;
-
-       ppriv_func = reinterpret_cast <int (*)(const char*)>(dlsym(handle, "set_privilege"));
-       msg = dlerror();
-       if (msg != NULL)
-       {
-               fprintf(stderr, "Dlsym error: %s\n", msg);
-
-               dlclose(handle);
-               return;
-       }
-
-       int ret = (*ppriv_func)(pkgname);
-       if (ret < 0)
-       {
-               fprintf(stderr, "set_privilege() returned %d\n", ret);
-       }
-
-       dlclose(handle);
+       set_privilege(pkgname);
 }
 
 extern "C" int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
@@ -141,7 +114,7 @@ AdjustCapability(void)
 
 
 static int
-GetAppIdAppExecutableNameFromPathNew(const char appName[], char* appId, char* exeName)
+GetPackageIdAppExecutableNameFromPath(const char appName[], char* appId, char* exeName)
 {
        char buffer[PATH_MAX];
 
@@ -185,54 +158,6 @@ GetAppIdAppExecutableNameFromPathNew(const char appName[], char* appId, char* ex
        return 0;
 }
 
-static int
-GetAppIdAppExecutableNameFromPath(const char appName[], char* appId, char* exeName)
-{
-       const char* begin = NULL;
-       const char* end = NULL;
-       const int path_len = strlen(appName);
-
-       // Calculate the header
-       const char* p = strstr(appName, "/apps/org.tizen.");
-       if (p == NULL)
-       {
-               return GetAppIdAppExecutableNameFromPathNew(appName, appId, exeName);
-       }
-
-       begin = p + 15;
-
-       end = strchr(begin + 1, '/');
-       if (end == NULL)
-       {
-               LOG(LOG_DEBUG, LOG_IO_TAG, "Tizen::Io, Improper appname %s", appName);
-               return -1;
-       }
-
-       int len = end - begin - 1;
-
-       if (len > MAX_PACKAGE_ID)
-       {
-               LOG(LOG_DEBUG, LOG_IO_TAG, "Tizen::Io, Improper appname %s with length %d", appName, len);
-               len = MAX_PACKAGE_ID;
-               //return -1;
-       }
-
-       strncpy(appId, begin + 1, len);
-       LOG(LOG_DEBUG, LOG_IO_TAG, "Tizen::Io, app is %s", appId);
-
-       int exe_len = 0;
-
-       if (path_len > len + 21)
-       {
-               exe_len = std::min(MAX_APP_EXECUTABLE_NAME - 1, path_len - len - 21);
-               strncpy(exeName, end + 5, exe_len);
-       }
-
-       LOG(LOG_DEBUG, LOG_IO_TAG, "Tizen::Io, exeName is %s", exeName);
-
-       return 0;
-}
-
 
 static void
 PrintArgs(int argc, char* argv[])
@@ -361,12 +286,12 @@ main(int argc, char* pArgv[])
 {
        bool bCommand = false;
 
-       char packageId[MAX_PACKAGE_ID];
+       char packageId[MAX_PACKAGE_ID + 1];
        char exeName[MAX_APP_EXECUTABLE_NAME];
        char fullPath[PATH_MAX];
 
-       memset(packageId, 0, MAX_PACKAGE_ID);
-       memset(exeName, 0, MAX_APP_EXECUTABLE_NAME);
+       memset(packageId, 0, sizeof(packageId));
+       memset(exeName, 0, sizeof(exeName));
        memset(fullPath, 0, PATH_MAX);
 
        LOG(LOG_DEBUG, LOG_IO_TAG, "Tizen::Io, %s, %d > executable binary path: %s", __func__, __LINE__, pArgv[0]);
@@ -386,7 +311,7 @@ main(int argc, char* pArgv[])
        LOG(LOG_DEBUG, LOG_IO_TAG, "Tizen::Io, %s, %d > processed binary path: %s", __func__, __LINE__, fullPath);
 
        // convert package path to packageId
-       GetAppIdAppExecutableNameFromPath(fullPath, packageId, exeName);
+       GetPackageIdAppExecutableNameFromPath(fullPath, packageId, exeName);
 
        // acquire appId from packageId and exec
        char appId[MAX_PACKAGE_ID + MAX_APP_EXECUTABLE_NAME + 2] = {0, };
@@ -401,7 +326,7 @@ main(int argc, char* pArgv[])
                DoPreExec(packageId, fullPath);
 
                // adjust privilege
-               AdjustPrivilege(packageId);
+               AdjustPrivilege(appId);
        }
 
        AdjustCapability();
@@ -415,9 +340,10 @@ main(int argc, char* pArgv[])
 
        }
 
-       // dlopen will load Osp_Initialize() internally as __attribute__((constructor))
-       //Osp_Initialize();
-       InitAppInfo(packageId, exeName, argc, pArgv, -1);
+       appinfo_init(appId, 0);
+       appinfo_set_argv(argc, pArgv);
+
+       AppInfo_Update();
 
        AdjustHwAccInfo(appId);