diff options
author | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-16 01:17:14 +0900 |
---|---|---|
committer | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-16 01:17:14 +0900 |
commit | 5e755d91d8b859a71c012556f497f1b4a9d7b08b (patch) | |
tree | f4f20daf745023f4a7e85070e77da6bf31fdf2f3 /pkgmgr_account/src/account.cpp | |
parent | b51ef7bc64f1e98f74c1d2ba05fb99627de022c1 (diff) | |
download | social-5e755d91d8b859a71c012556f497f1b4a9d7b08b.tar.gz social-5e755d91d8b859a71c012556f497f1b4a9d7b08b.tar.bz2 social-5e755d91d8b859a71c012556f497f1b4a9d7b08b.zip |
merge with master
Diffstat (limited to 'pkgmgr_account/src/account.cpp')
-rw-r--r-- | pkgmgr_account/src/account.cpp | 266 |
1 files changed, 266 insertions, 0 deletions
diff --git a/pkgmgr_account/src/account.cpp b/pkgmgr_account/src/account.cpp new file mode 100644 index 0000000..f915c7d --- /dev/null +++ b/pkgmgr_account/src/account.cpp @@ -0,0 +1,266 @@ +// +// Open Service Platform +// Copyright (c) 2013 Samsung Electronics Co., Ltd. +// +// 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 <errno.h> +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <account.h> +#include <account-types.h> +#include <FBaseDataType.h> +#include <FBaseSysLog.h> + +#define _SysTryReturn(NID, condition, returnValue, ...) \ + if (!(condition)) { \ + SysLog(NID, __VA_ARGS__); \ + return returnValue; \ + } \ + else {;} + +#define _SysTryCatch(NID, condition, expr, ...) \ + if (!(condition)) { \ + SysLog(NID, __VA_ARGS__); \ + expr; \ + goto CATCH; \ + } \ + else {;} + + +static const xmlChar _NODE_ACCOUNT_PROVIDER[] = "account-provider"; +static const xmlChar _NODE_ICON[] = "icon"; +static const xmlChar _NODE_LABEL[] = "label"; +static const xmlChar _NODE_CAPABILITY[] = "capability"; + +static const xmlChar _ATTRIBUTE_APP_ID[] = "appid"; +static const xmlChar _ATTRIBUTE_MULTIPLE_ACCOUNTS_SUPPORT[] = "multiple-accounts-support"; +static const xmlChar _ATTRIBUTE_SECTION[] = "section"; +static const xmlChar _ATTRIBUTE_TYPE[] = "type"; +static const xmlChar _ATTRIBUTE_XML_LANG[] = "xml:lang"; + +static const xmlChar _VALUE_TRUE[] = "true"; +static const xmlChar _VALUE_ACCOUNT[] = "account"; +static const xmlChar _VALUE_ACCOUNT_SMALL[] = "account-small"; +static const xmlChar _VALUE_XHIGH[] = "Xhigh"; + + +extern "C" +__attribute__ ((visibility("default"))) +int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId) +{ + SysLog(NID_SCL, "Registering the Account Provider."); + + int ret = account_connect(); + _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred."); + + account_type_h accountTypeHandle = null; + ret = account_type_create(&accountTypeHandle); + if (ret != ACCOUNT_ERROR_NONE || accountTypeHandle == null) + { + SysLog(NID_SCL, "Memory allocation failed."); + account_disconnect(); + + return -ENOMEM; + } + + // Node: <account> + xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr)); + _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the element."); + + SysLog(NID_SCL, "Node: %s", curPtr->name); + + // Get the children nodes + curPtr = curPtr->xmlChildrenNode; + _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the child element."); + + while(curPtr != null) + { + SysLog(NID_SCL, "Node: %s", curPtr->name); + + // Node: <account-provider> + if ((!xmlStrcmp(curPtr->name, _NODE_ACCOUNT_PROVIDER))) + { + // Attribute: appid + 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); + 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."); + + // Attribute: multiple-accounts-support + 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); + if ((!xmlStrcmp(pMultipleAccountsSupport, _VALUE_TRUE))) + { + ret = account_type_set_multiple_account_support(accountTypeHandle, true); + _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the multiple accounts support."); + } + else + { + ret = account_type_set_multiple_account_support(accountTypeHandle, false); + _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the multiple accounts support."); + } + + // Get the children nodes + curPtr = curPtr->xmlChildrenNode; + _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the child element."); + + while (curPtr != NULL) + { + SysLog(NID_SCL, "Node: %s", curPtr->name); + + // Node: <icon> + if ((!xmlStrcmp(curPtr->name, _NODE_ICON))) + { + // Attribute: section + 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); + + 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); + 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."); + } + else if ((!xmlStrcmp(pSection, _VALUE_ACCOUNT_SMALL))) + { + 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); + 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."); + } + } + // Node: <label> + else if ((!xmlStrcmp(curPtr->name, _NODE_LABEL))) + { + SysLog(NID_SCL, "Node: %s", curPtr->name); + + // Attribute: xml:lang + xmlChar* pLang = xmlNodeGetLang(curPtr); + if (pLang != null) + { + SysLog(NID_SCL, "Attribute: xml:lang - %s", pLang); + + 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)); + _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); + + 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); + 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."); + } + + curPtr = curPtr->next; + } + + break; + } + + curPtr = curPtr->next; + } + + // Insert the account to the account DB + { + int accountTypeDbId = 0; + ret = account_type_insert_to_db(accountTypeHandle, &accountTypeDbId); + _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "A system error has occurred."); + } + + account_type_destroy(accountTypeHandle); + account_disconnect(); + + return 0; + +CATCH: + account_type_destroy(accountTypeHandle); + account_disconnect(); + + return ret; +} + +extern "C" +__attribute__ ((visibility("default"))) +int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId) +{ + SysLog(NID_SCL, "Unregistering the Account Provider."); + + int ret = account_connect(); + _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred."); + + // Node: <account> + xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr)); + _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the element."); + + SysLog(NID_SCL, "Node: %s", curPtr->name); + + // Get the children nodes + curPtr = curPtr->xmlChildrenNode; + _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the child element."); + + while(curPtr != null) + { + SysLog(NID_SCL, "Node: %s", curPtr->name); + + // Node: <account-provider> + if ((!xmlStrcmp(curPtr->name, _NODE_ACCOUNT_PROVIDER))) + { + // Attribute: appid + 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); + + 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."); + + ret = account_type_delete_by_app_id(reinterpret_cast<char*> (pAppIdId)); + _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "A system error has occurred."); + + break; + } + + curPtr = curPtr->next; + } + + account_disconnect(); + + return 0; + +CATCH: + account_disconnect(); + + return ret; +} |