CSC install/uninstall is applied.
authorDuyoung Jang <duyoung.jang@samsung.com>
Tue, 23 Apr 2013 05:22:44 +0000 (14:22 +0900)
committerDuyoung Jang <duyoung.jang@samsung.com>
Tue, 23 Apr 2013 05:31:27 +0000 (14:31 +0900)
Change-Id: If05ba249f3bdcd07b1c3e648fda4ad16c95dbcc9
Signed-off-by: Duyoung Jang <duyoung.jang@samsung.com>
inc/InstallerDefs.h
src/Manager/InstallerManager.cpp
src/Manager/InstallerManager.h
src/Util/InstallerUtil.cpp
src/Util/InstallerUtil.h

index 4ae369f..ec4d524 100755 (executable)
@@ -23,7 +23,7 @@
 
 #include "InstallerUtil.h"
 
-#define OSP_INSTALLER_VERSION "version=[20130421.1]"
+#define OSP_INSTALLER_VERSION "version=[20130423.1]"
 
 #define DIR_BIN                                L"/bin"
 #define DIR_INFO                       L"/info"
@@ -214,6 +214,7 @@ enum InstallerOption
        INSTALLER_OPTION_HYBRID = 8,
        INSTALLER_OPTION_NO_INPUT = 16,
        INSTALLER_OPTION_FILELOG_ON = 32,
+       INSTALLER_OPTION_UPDATE_STDOUT = 64,
 
 };
 
@@ -285,6 +286,7 @@ enum
        INSTALLER_MODE_UNINSTALL = 2,
        INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL = 3,
        INSTALLER_MODE_REINSTALL = 4,
+       INSTALLER_MODE_PARSE_CSC_STRING = 5,
 };
 
 enum CategoryType
index 41f5af5..c35bc53 100755 (executable)
@@ -156,23 +156,7 @@ InstallerManager::Construct(const String& path, InstallerOperation operation, In
 
                if (pOptionalData)
                {
-                       PackageId packageId;
-                       pOptionalData->SubString(0, PACKAGE_ID_LENGTH, packageId);
-                       __pContext->__packageId = packageId;
-                       AppLog(" # package = [%ls]", packageId.GetPointer());
-
-                       // format -> pOptionalData = "abcde12345:StoreClientId=12345abcde.TizenStore"
-                       int indexOf = 0;
-                       String storeClientId;
-                       String tokenDelimiter(":StoreClientId=");
-                       r = pOptionalData->IndexOf(tokenDelimiter, 0, indexOf);
-                       if (!IsFailed(r))
-                       {
-                               pOptionalData->SubString(indexOf + tokenDelimiter.GetLength(), storeClientId);
-                               __pContext->__storeClientId = storeClientId;
-                               AppLog(" # storeClient = [%ls]", storeClientId.GetPointer());
-                       }
-
+                       ParseOptionalData(pOptionalData);
                        SendEvent(__pContext, __pContext->__packageId, "start", "install");
                }
                else
@@ -306,7 +290,6 @@ InstallerManager::Register(void)
 InstallerError
 InstallerManager::End(void)
 {
-       SendEvent(__pContext, __pContext->__packageId, "install_percent", "100");
        return __pInstaller->OnEnd();
 }
 
@@ -380,6 +363,7 @@ InstallerManager::Activate(void)
 CATCH:
        if (error == INSTALLER_ERROR_NONE)
        {
+               SendEvent(__pContext, __pContext->__packageId, "install_percent", "100");
                SendEvent(__pContext, __pContext->__packageId, "end", "ok");
        }
        else
@@ -411,10 +395,85 @@ InstallerManager::GetContext(void)
        return __pContext;
 }
 
+bool
+InstallerManager::ParseOptionalData(const String* pOptionalData)
+{
+       TryReturn(__pContext, false, "__pContext is null.");
+
+       if (pOptionalData == null)
+       {
+               AppLog("pOptionalData is null.");
+               return true;
+       }
+
+       // format -> pOptionalData = "abcde12345:StoreClientId=12345abcde.TizenStore"
+       // format -> pOptionalData = "abcde12345"
+       // format -> pOptionalData = "path=/opt/usr/apps/22VoFBmj2I/:op=install:removable=true"
+
+       AppLog(" # optionalData = [%ls]", pOptionalData->GetPointer());
+
+       if ((pOptionalData->GetLength() == 10) || (pOptionalData->StartsWith(L":", 10) == true))
+       {
+               PackageId packageId;
+               pOptionalData->SubString(0, PACKAGE_ID_LENGTH, packageId);
+               __pContext->__packageId = packageId;
+               AppLog(" # package = [%ls]", packageId.GetPointer());
+       }
+
+       String tokenDelimiter(":");
+
+       std::unique_ptr< IMap > pMap(InstallerUtil::ParseN(*pOptionalData, tokenDelimiter));
+       if (pMap)
+       {
+               std::unique_ptr< IMapEnumerator > pEnum(pMap->GetMapEnumeratorN());
+               TryReturn(pEnum, false, "GetMapEnumeratorN() failed. [%s]", GetErrorMessage(GetLastResult()));
+
+               String storeClientId;
+               String removable;
+
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       String* pKey = static_cast< String* > (pEnum->GetKey());
+                       TryReturn(pEnum, false, "GetKey() failed. [%s]", GetErrorMessage(GetLastResult()));
+
+                       String* pValue = static_cast< String* > (pEnum->GetValue());
+                       TryReturn(pEnum, false, "GetValue() failed. [%s]", GetErrorMessage(GetLastResult()));
+
+                       AppLog("key = [%ls], value = [%ls]", pKey->GetPointer(), pValue->GetPointer());
+
+                       if (pKey->Equals(L"StoreClientId", false) == true)
+                       {
+                               storeClientId = (*pValue);
+                       }
+
+                       if (pKey->Equals(L"removable", false) == true)
+                       {
+                               removable = (*pValue);
+                       }
+               }
+
+               if (storeClientId.IsEmpty() == false)
+               {
+                       __pContext->__storeClientId = storeClientId;
+                       AppLog(" # storeClient = [%ls]", storeClientId.GetPointer());
+               }
+
+#if 0
+               if (removable.IsEmpty() == false)
+               {
+                       // TODO : removable
+               }
+#endif
+
+       }
+
+       return true;
+}
+
 int
-InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output)
+InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, InstallerOption& option)
 {
-       const char* pOpts_str = "u:i:r:v:m";
+       const char* pOpts_str = "u:i:r:v:m:c";
        int s = 0;
 
        if (mode == NULL)
@@ -447,7 +506,8 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, b
                        if (optarg[0] == 'v')
                        {
                                AppLog("__osp_installer_parse_options: v");
-                               *output = true;
+                               option = (InstallerOption)(option | INSTALLER_OPTION_HYBRID);
+                               option = (InstallerOption)(option | INSTALLER_OPTION_UPDATE_STDOUT);
                                strncpy(buf, argv[optind++], BUFSIZE);
                                AppLog("__osp_installer_parse_options: buf = [%s]", buf);
                        }
@@ -469,7 +529,8 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, b
                        if (optarg[0] == 'v')
                        {
                                AppLog("__osp_installer_parse_options: v");
-                               *output = true;
+                               option = (InstallerOption)(option | INSTALLER_OPTION_HYBRID);
+                               option = (InstallerOption)(option | INSTALLER_OPTION_UPDATE_STDOUT);
                                strncpy(buf, argv[optind++], BUFSIZE);
                                AppLog("__osp_installer_parse_options: buf = [%s]", buf);
                        }
@@ -494,7 +555,7 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, b
 
                case 'v':
                        AppLog("__osp_installer_parse_options: v");
-                       *output = true;
+                       option = (InstallerOption)(option | INSTALLER_OPTION_UPDATE_STDOUT);
                        AppLog("__osp_installer_parse_options: optarg = [%s]", optarg);
                        break;
 
@@ -510,6 +571,20 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, b
                        AppLog("__osp_installer_parse_options: optarg = [%s]", optarg);
                        break;
 
+               case 'c':
+                       if (*mode)
+                       {
+                               break;
+                       }
+
+                       AppLog("__osp_installer_parse_options: c");
+                       option = (InstallerOption)(option | INSTALLER_OPTION_UPDATE_STDOUT);
+                       *mode = INSTALLER_MODE_PARSE_CSC_STRING;
+                       AppLog("__osp_installer_parse_options: argv[optind] = [%s]", argv[optind]);
+                       strncpy(buf, argv[optind], BUFSIZE);
+
+                       break;
+
                default:
                        AppLog("Invalid option");
                        exit(-1);
@@ -956,7 +1031,6 @@ InstallerManager::RequestByCommand(int argc, char **argv)
        int mode = 0;
        char buf[BUFSIZE] = {0};
        int errorType = 0;
-       bool output = false;
        InstallerOption option = INSTALLER_OPTION_NORMAL;
 
        AppLog(" # argc = [%d]", argc);
@@ -966,12 +1040,9 @@ InstallerManager::RequestByCommand(int argc, char **argv)
                AppLog(" # argv[%d] = [%s]", i, argv[i]);
        }
 
-       InstallerManager::ParseCommandArg(argc, argv, &mode, buf, &output);
-       if (output == true)
-       {
-               AppLog("HybridService is detected in ParseCommandArg()");
-               option = (InstallerOption)(option | INSTALLER_OPTION_HYBRID);
-       }
+       InstallerManager::ParseCommandArg(argc, argv, &mode, buf, option);
+
+       AppLog("option = [%d]", (int)option);
 
        switch (mode)
        {
@@ -1018,6 +1089,16 @@ InstallerManager::RequestByCommand(int argc, char **argv)
                }
                break;
 
+       case INSTALLER_MODE_PARSE_CSC_STRING:
+               {
+                       AppLog("------------------------------------------");
+                       AppLog(" # CSC = [%s]", buf);
+
+                       option = (InstallerOption)(option | INSTALLER_OPTION_FILELOG_ON);
+                       errorType = InstallerManager::RequestCsc(buf, option);
+               }
+               break;
+
        default:
                {
                        AppLog("__install_package_by_cmd, Invalid mode");
@@ -1027,9 +1108,9 @@ InstallerManager::RequestByCommand(int argc, char **argv)
 
        AppLog("==========================================");
 
-       if (output == true)
+       if (option & INSTALLER_OPTION_UPDATE_STDOUT)
        {
-               AppLog("stdout is updated by errorType");
+               AppLog("stdout is updated by errorType [%d]", errorType);
                fprintf(stdout, "%d", errorType);
        }
 
@@ -1158,3 +1239,65 @@ CATCH:
        return errorType;
 }
 
+int
+InstallerManager::RequestCsc(const String& buffer, InstallerOption option)
+{
+       int errorType = 0;
+
+       String str(buffer);
+       String tokenDelimiter(":");
+
+       std::unique_ptr< IMap > pMap(InstallerUtil::ParseN(str, tokenDelimiter));
+       TryReturn(pMap, INSTALLER_ERROR_FATAL_ERROR, "CSC String[%ls] is invalid.", buffer.GetPointer());
+
+       std::unique_ptr< IMapEnumerator > pEnum(pMap->GetMapEnumeratorN());
+       TryReturn(pEnum, INSTALLER_ERROR_FATAL_ERROR, "GetMapEnumeratorN() failed. [%s]", GetErrorMessage(GetLastResult()));
+
+       String op;
+       String path;
+       String removable;
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               String* pKey = static_cast< String* > (pEnum->GetKey());
+               TryReturn(pEnum, -1, "GetKey() failed. [%s]", GetErrorMessage(GetLastResult()));
+
+               String* pValue = static_cast< String* > (pEnum->GetValue());
+               TryReturn(pEnum, -1, "GetValue() failed. [%s]", GetErrorMessage(GetLastResult()));
+
+               AppLog("key = [%ls], value = [%ls]", pKey->GetPointer(), pValue->GetPointer());
+
+               if (pKey->Equals(L"path", false) == true)
+               {
+                       path = (*pValue);
+               }
+
+               if (pKey->Equals(L"op", false) == true)
+               {
+                       op = (*pValue);
+               }
+
+               if (pKey->Equals(L"removable", false) == true)
+               {
+                       removable = (*pValue);
+               }
+       }
+
+       AppLog("path = [%ls], op = [%ls], removable = [%ls]", path.GetPointer(), op.GetPointer(), removable.GetPointer());
+
+       if (op.Equals(L"install", false) == true)
+       {
+               errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, option, null);
+       }
+       else if (op.Equals(L"uninstall", false) == true)
+       {
+               errorType = InstallerManager::Request(path, INSTALLER_OPERATION_UNINSTALL, option, null);
+       }
+       else
+       {
+               AppLog("Operation[%ls] is invalid.", op.GetPointer());
+               errorType = INSTALLER_ERROR_FATAL_ERROR;
+       }
+
+       return errorType;
+}
index 8540052..5d3f174 100755 (executable)
@@ -65,6 +65,7 @@ public:
        static int RequestByCommand(int argc, char **argv);
        static int ReqeustByTest(void);
        static int RequestMove(const Tizen::App::PackageId& packageId, int moveType);
+       static int RequestCsc(const Tizen::Base::String& buffer, InstallerOption option);
 
 private:
        InstallerManager(const InstallerManager& value);
@@ -86,7 +87,9 @@ private:
        Installer* CreateInstaller(InstallerType installerType);
        InstallationContext* GetContext(void);
 
-       static int ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output);
+       bool ParseOptionalData(const Tizen::Base::String* pOptionalData);
+
+       static int ParseCommandArg(int argc, char **argv, int *mode, char *buf, InstallerOption& option);
 
 private:
        static InstallerManager* __pInstallerManager;
index 7b6ec33..8970b6e 100755 (executable)
@@ -854,3 +854,55 @@ InstallerUtil::GetFileDigest(const String& filePath, String& digestValue)
 
        return true;
 }
+
+IMap*
+InstallerUtil::ParseN(const String& str, const String& tokenDelimiter)
+{
+       TryReturn(str.IsEmpty() == false, null, "str is empty.");
+       TryReturn(tokenDelimiter.IsEmpty() == false, null, "tokenDelimiter is empty.");
+
+       std::unique_ptr< HashMap > pMap(new (std::nothrow) HashMap);
+       TryReturn(pMap, null, "pMap is null.");
+
+       result r = pMap->Construct();
+       TryReturn(!IsFailed(r), null, "pMap->Construct() is failed.");
+
+       StringTokenizer strTok(str, tokenDelimiter);
+       while(strTok.HasMoreTokens() == true)
+       {
+               String token;
+               r = strTok.GetNextToken(token);
+               TryReturn(!IsFailed(r), null, "strTok.GetNextToken() is failed.");
+
+               AppLog("token = [%ls]", token.GetPointer());
+
+               StringTokenizer infoTok(token, L"=");
+
+               if (infoTok.GetTokenCount() != 2)
+               {
+                       AppLog("'=' is not existed.");
+                       continue;
+               }
+
+               std::unique_ptr< String > pKey(new (std::nothrow) String);
+               r = infoTok.GetNextToken(*pKey);
+               TryReturn(!IsFailed(r), null, "infoTok.GetNextToken(*pKey) is failed.");
+               AppLog(" - key = [%ls]", pKey->GetPointer());
+
+               std::unique_ptr< String > pValue(new (std::nothrow) String);
+               r = infoTok.GetNextToken(*pValue);
+               TryReturn(!IsFailed(r), null, "infoTok.GetNextToken(*pValue) is failed.");
+               AppLog(" - value = [%ls]", pValue->GetPointer());
+
+               r = pMap->Add(pKey.release(), pValue.release());
+               TryReturn(!IsFailed(r), null, "pMap->Add() is failed.");
+       }
+
+       if (pMap->GetCount() <= 0)
+       {
+               AppLog("pMap->GetCount() is invalid.");
+               return null;
+       }
+
+       return pMap.release();
+}
index 05f8adb..0a71d78 100755 (executable)
@@ -33,6 +33,7 @@ class String;
 namespace Tizen { namespace Base { namespace Collection
 {
 class IList;
+class IMap;
 }}}
 
 /**
@@ -83,6 +84,8 @@ public:
        static const char* GetInstallerOperationString(int operation);
        static bool GetFileDigest(const Tizen::Base::String& filePath, Tizen::Base::String& digestValue);
 
+       static Tizen::Base::Collection::IMap* ParseN(const Tizen::Base::String& str, const Tizen::Base::String& tokenDelimiter);
+
 private:
        static char LogChangeHexToStr(int hex);
        InstallerUtil(const InstallerUtil& value);