Fix the boiler plate codes
[framework/osp/social.git] / pkgmgr_account / src / account.cpp
index 9fd5ff2..fd7d9f5 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
 // See the License for the specific language governing permissions and
 // limitations under the License.
 //
+
 #include <errno.h>
+#include <new>
+#include <unique_ptr.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <account.h>
 #include <account-types.h>
 #include <FBaseDataType.h>
+#include <FBaseString.h>
 #include <FBaseSysLog.h>
+#include <FBaseUtilStringTokenizer.h>
+#include <FBaseUtilStringUtil.h>
 
 #define _SysTryReturn(NID, condition, returnValue, ...)        \
        if (!(condition)) { \
@@ -37,6 +42,8 @@
        } \
        else {;}
 
+using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
 
 static const xmlChar _NODE_ACCOUNT_PROVIDER[]                          = "account-provider";
 static const xmlChar _NODE_ICON[]                                                      = "icon";
@@ -54,6 +61,7 @@ static const xmlChar _VALUE_ACCOUNT[]                                         = "account";
 static const xmlChar _VALUE_ACCOUNT_SMALL[]                                    = "account-small";
 static const xmlChar _VALUE_XHIGH[]                                                    = "Xhigh";
 
+static const char _DEFAULT_LOCALE[]                                                    = "default";
 
 extern "C"
 __attribute__ ((visibility("default")))
@@ -68,9 +76,10 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
        ret = account_type_create(&accountTypeHandle);
        if (ret != ACCOUNT_ERROR_NONE || accountTypeHandle == null)
        {
-               SysLog(NID_SCL, "Memory allocation failed.");
-               account_disconnect();
+               ret = account_disconnect();
+               _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");
 
+               SysLog(NID_SCL, "Memory allocation failed.");
                return -ENOMEM;
        }
 
@@ -78,7 +87,7 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
        xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));
        _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the element.");
 
-       SysLog(NID_SCL, "Node: %s", curPtr->name);
+       SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
        // Get the children nodes
        curPtr = curPtr->xmlChildrenNode;
@@ -86,7 +95,7 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
 
        while(curPtr != null)
        {
-               SysLog(NID_SCL, "Node: %s", curPtr->name);
+               SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
                // Node: <account-provider>
                if ((!xmlStrcmp(curPtr->name, _NODE_ACCOUNT_PROVIDER)))
@@ -95,7 +104,7 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                        xmlChar* pAppIdId = xmlGetProp(curPtr, _ATTRIBUTE_APP_ID);
                        _SysTryCatch(NID_SCL, pAppIdId != null, ret = -EINVAL, "Failed to get the attribute.");
 
-                       SysLog(NID_SCL, "Attribute: appid - %s", pAppIdId);
+                       SysSecureLog(NID_SCL, "Attribute: appid - %s", pAppIdId);
                        ret = account_type_set_app_id(accountTypeHandle, reinterpret_cast<char*> (pAppIdId));
                        _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the app ID.");
 
@@ -103,7 +112,7 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                        xmlChar* pMultipleAccountsSupport = xmlGetProp(curPtr, _ATTRIBUTE_MULTIPLE_ACCOUNTS_SUPPORT);
                        _SysTryCatch(NID_SCL, pMultipleAccountsSupport != null, ret = -EINVAL, "Failed to get the attribute.");
 
-                       SysLog(NID_SCL, "Attribute: multiple-accounts-support - %s", pMultipleAccountsSupport);
+                       SysSecureLog(NID_SCL, "Attribute: multiple-accounts-support - %s", pMultipleAccountsSupport);
                        if ((!xmlStrcmp(pMultipleAccountsSupport, _VALUE_TRUE)))
                        {
                                ret = account_type_set_multiple_account_support(accountTypeHandle, true);
@@ -121,7 +130,7 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
 
                        while (curPtr != NULL)
                        {
-                               SysLog(NID_SCL, "Node: %s", curPtr->name);
+                               SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
                                // Node: <icon>
                                if ((!xmlStrcmp(curPtr->name, _NODE_ICON)))
@@ -130,14 +139,14 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                                        xmlChar* pSection = xmlGetProp(curPtr, _ATTRIBUTE_SECTION);
                                        _SysTryCatch(NID_SCL, pSection != null, ret = -EINVAL, "Failed to get the attribute.");
 
-                                       SysLog(NID_SCL, "Attribute: section - %s", pSection);
+                                       SysSecureLog(NID_SCL, "Attribute: section - %s", pSection);
 
                                        if ((!xmlStrcmp(pSection, _VALUE_ACCOUNT)))
                                        {
                                                xmlChar* pAccountIcon = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
                                                _SysTryCatch(NID_SCL, pAccountIcon != null, ret = -EINVAL, "Failed to get the value.");
 
-                                               SysLog(NID_SCL, "Node: icon - %s", pAccountIcon);
+                                               SysSecureLog(NID_SCL, "Node: icon - %s", pAccountIcon);
                                                ret = account_type_set_icon_path(accountTypeHandle, reinterpret_cast<char*> (pAccountIcon));
                                                _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the icon path.");
                                        }
@@ -146,7 +155,7 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                                                xmlChar* pAccountSmallIcon = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
                                                _SysTryCatch(NID_SCL, pAccountSmallIcon != null, ret = -EINVAL, "Failed to get the value.");
 
-                                               SysLog(NID_SCL, "Node: icon (small) - %s",  pAccountSmallIcon);
+                                               SysSecureLog(NID_SCL, "Node: icon (small) - %s",  pAccountSmallIcon);
                                                ret = account_type_set_small_icon_path(accountTypeHandle, reinterpret_cast<char*> (pAccountSmallIcon));
                                                _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the small icon path.");
                                        }
@@ -154,31 +163,58 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                                // Node: <label>
                                else if ((!xmlStrcmp(curPtr->name, _NODE_LABEL)))
                                {
-                                       SysLog(NID_SCL, "Node: %s", curPtr->name);
+                                       SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
                                // Attribute: xml:lang
                                        xmlChar* pLang = xmlNodeGetLang(curPtr);
                                        if (pLang != null)
                                        {
-                                               SysLog(NID_SCL, "Attribute: xml:lang - %s", pLang);
+                                               SysSecureLog(NID_SCL, "Attribute: xml:lang - %s", pLang);
+
+                                               String lang(reinterpret_cast<char*> (pLang));
+
+                                               StringTokenizer strTok(lang, L"-");
+                                               String token;
+                                               String convertedLang;
+
+                                               strTok.GetNextToken(convertedLang);
+                                               convertedLang.Append(L"_");
+
+                                               strTok.GetNextToken(token);
+                                               token.ToUpper();
+                                               convertedLang.Append(token);
+
+                                               std::unique_ptr<ByteBuffer> pConvertedLangBuf(StringUtil::StringToUtf8N(convertedLang));
+                                               _SysTryCatch(NID_SCL, pConvertedLangBuf != null, ret = -1, "Failed to convert String to Utf8N.");
 
+                                               SysSecureLog(NID_SCL, "Attribute: converted lang - %s", pConvertedLangBuf->GetPointer());
+
+                                               xmlChar* pLabel = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
+                                               _SysTryCatch(NID_SCL, pLabel != null, ret = -EINVAL, "Failed to get the value.");
+
+                                               SysSecureLog(NID_SCL, "Node: label - %s", pLabel);
+                                               ret = account_type_set_label(accountTypeHandle, reinterpret_cast<char*> (pLabel), reinterpret_cast<char*> (pConvertedLangBuf->GetPointer()));
+                                               _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the display name.");
+                                       }
+                                       else
+                                       {
                                                xmlChar* pLabel = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
                                                _SysTryCatch(NID_SCL, pLabel != null, ret = -EINVAL, "Failed to get the value.");
 
-                                               SysLog(NID_SCL, "Node: label - %s", pLabel);
-                                               ret = account_type_set_label(accountTypeHandle, reinterpret_cast<char*> (pLabel), reinterpret_cast<char*> (pLang));
+                                               SysSecureLog(NID_SCL, "Node: label - %s",  pLabel);
+                                               ret = account_type_set_label(accountTypeHandle, reinterpret_cast<char*> (pLabel), _DEFAULT_LOCALE);
                                                _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the display name.");
                                        }
                                }
                                // Node: <capability>
                                else if ((!xmlStrcmp(curPtr->name, _NODE_CAPABILITY)))
                                {
-                                       SysLog(NID_SCL, "Node: %s", curPtr->name);
+                                       SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
                                        xmlChar* pCapability = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
                                        _SysTryCatch(NID_SCL, pCapability != null, ret = -EINVAL, "Failed to get the value.");
 
-                                       SysLog(NID_SCL, "Node: capability - %s",  pCapability);
+                                       SysSecureLog(NID_SCL, "Node: capability - %s",  pCapability);
                                        ret = account_type_set_provider_feature(accountTypeHandle, reinterpret_cast<char*> (pCapability));
                                        _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the capability.");
                                }
@@ -225,7 +261,7 @@ int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
        xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));
        _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the element.");
 
-       SysLog(NID_SCL, "Node: %s", curPtr->name);
+       SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
        // Get the children nodes
        curPtr = curPtr->xmlChildrenNode;
@@ -233,7 +269,7 @@ int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
 
        while(curPtr != null)
        {
-               SysLog(NID_SCL, "Node: %s", curPtr->name);
+               SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
                // Node: <account-provider>
                if ((!xmlStrcmp(curPtr->name, _NODE_ACCOUNT_PROVIDER)))
@@ -242,7 +278,7 @@ int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
                        xmlChar* pAppIdId = xmlGetProp(curPtr, _ATTRIBUTE_APP_ID);
                        _SysTryCatch(NID_SCL, pAppIdId != null, ret = -EINVAL, "Failed to get the attribute.");
 
-                       SysLog(NID_SCL, "Attribute: appid - %s", pAppIdId);
+                       SysSecureLog(NID_SCL, "Attribute: appid - %s", pAppIdId);
 
                        ret = account_delete_from_db_by_package_name(reinterpret_cast<char*> (pAppIdId));
                        _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "A system error has occurred.");