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
InstallerError
InstallerManager::End(void)
{
- SendEvent(__pContext, __pContext->__packageId, "install_percent", "100");
return __pInstaller->OnEnd();
}
CATCH:
if (error == INSTALLER_ERROR_NONE)
{
+ SendEvent(__pContext, __pContext->__packageId, "install_percent", "100");
SendEvent(__pContext, __pContext->__packageId, "end", "ok");
}
else
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)
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);
}
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);
}
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;
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);
int mode = 0;
char buf[BUFSIZE] = {0};
int errorType = 0;
- bool output = false;
InstallerOption option = INSTALLER_OPTION_NORMAL;
AppLog(" # argc = [%d]", argc);
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)
{
}
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");
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);
}
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;
+}
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();
+}