diff options
author | jk7744.park <jk7744.park@samsung.com> | 2015-10-26 15:41:52 +0900 |
---|---|---|
committer | jk7744.park <jk7744.park@samsung.com> | 2015-10-26 15:41:52 +0900 |
commit | 4cf925783ebfb307e1910d7cb71e0a97e38a18ef (patch) | |
tree | 6f25334c49ef021d1b90f47e13d7c3de5cc515a3 | |
parent | bb3209aa318316debbe2e33331e52a4d45f7772f (diff) | |
download | account-common-4cf925783ebfb307e1910d7cb71e0a97e38a18ef.tar.gz account-common-4cf925783ebfb307e1910d7cb71e0a97e38a18ef.tar.bz2 account-common-4cf925783ebfb307e1910d7cb71e0a97e38a18ef.zip |
tizen 2.4 releasetizen_2.4_mobile_releasesubmit/tizen_2.4/20151028.063444accepted/tizen/2.4/mobile/20151029.035058
-rw-r--r-- | CMakeLists.txt | 11 | ||||
-rw-r--r-- | LICENSE.APLv2 | 202 | ||||
-rwxr-xr-x | NOTICE | 3 | ||||
-rw-r--r-- | account-common.manifest | 6 | ||||
-rw-r--r-- | common/CMakeLists.txt | 51 | ||||
-rw-r--r-- | common/account-common.pc.in | 13 | ||||
-rw-r--r-- | common/account_mgr.xml | 166 | ||||
-rw-r--r-- | common/include/account-private.h | 352 | ||||
-rw-r--r-- | common/include/account_free.h | 54 | ||||
-rw-r--r-- | common/include/account_ipc_marshal.h | 59 | ||||
-rw-r--r-- | common/include/dbg.h | 39 | ||||
-rw-r--r-- | common/src/account_free.c | 284 | ||||
-rw-r--r-- | common/src/account_ipc_marshal.c | 1341 | ||||
-rw-r--r-- | packaging/account-common.spec | 69 |
14 files changed, 2650 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a050c24 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(account-common C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include ") +SET(VERSION_MAJOR 0) +SET(VERSION "${VERSION_MAJOR}.0.6") + +ADD_SUBDIRECTORY(common) diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.APLv2 file for Apache License terms and conditions. diff --git a/account-common.manifest b/account-common.manifest new file mode 100644 index 0000000..81ace0c --- /dev/null +++ b/account-common.manifest @@ -0,0 +1,6 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> + diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 0000000..9e18ec6 --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,51 @@ + +SET(SRCS + ./src/account_ipc_marshal.c + ./src/account_free.c +) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(clientpkgs REQUIRED + dlog + glib-2.0 + gio-unix-2.0 + capi-base-common +) + +FOREACH(flag ${clientpkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror") +SET(CMAKE_LDFLAGS "-Wl,-zdefs") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +ADD_DEFINITIONS("-DSLP_DEBUG") + +ADD_CUSTOM_COMMAND( + WORKING_DIRECTORY + OUTPUT account-mgr-stub.c + COMMAND gdbus-codegen --interface-prefix org.tizen. + --generate-c-code account-mgr-stub ./account_mgr.xml + COMMENT "Generating Account Client GDBus .c/.h") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} account-mgr-stub.c) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${clientpkgs_LDFLAGS}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib/account-common) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) + +INSTALL(FILES ${CMAKE_SOURCE_DIR}/common/account-mgr-stub.h DESTINATION include) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/common/include/account_ipc_marshal.h DESTINATION include) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/common/include/account_free.h DESTINATION include) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/common/include/account-private.h DESTINATION include) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/common/include/dbg.h DESTINATION include) + +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/common/${PROJECT_NAME}.pc.in ${CMAKE_SOURCE_DIR}/common/${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/common/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) diff --git a/common/account-common.pc.in b/common/account-common.pc.in new file mode 100644 index 0000000..e306b59 --- /dev/null +++ b/common/account-common.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: account-common +Description: Account common library +Version: @VERSION@ +#Requires: capi-base-common +Libs: -L${libdir} -laccount-common +Cflags: -I${includedir} diff --git a/common/account_mgr.xml b/common/account_mgr.xml new file mode 100644 index 0000000..32cf6bf --- /dev/null +++ b/common/account_mgr.xml @@ -0,0 +1,166 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<node name="/org/tizen/account/manager"> + <interface name="org.tizen.account.manager"> + <method name="account_add"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="a{sv}" name="account_data" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="i" name="account_db_id" direction="out" /> + </method> + <method name="account_type_add"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="a{sv}" name="account_type_data" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="i" name="account_type_db_id" direction="out" /> + </method> + <method name="account_query_all"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="aa{sv}" name="account_data" direction="out" /> + </method> + <method name="account_type_query_all"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="aa{sv}" name="account_type_data" direction="out" /> + </method> + <method name="account_delete_from_db_by_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="i" name="account_db_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_delete_from_db_by_user_name"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="user_name" direction="in" /> + <arg type="s" name="package_name" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_delete_from_db_by_package_name"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="package_name" direction="in" /> + <arg type="b" name="permission" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_update_to_db_by_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="a{sv}" name="account_data" direction="in" /> + <arg type="i" name="account_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_get_total_count_from_db"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="b" name="include_hidden" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="i" name="count" direction="out" /> + </method> + <method name="account_query_account_by_account_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="i" name="account_db_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="a{sv}" name="account_data" direction="out" /> + </method> + <method name="account_update_to_db_by_user_name"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="a{sv}" name="account_data" direction="in" /> + <arg type="s" name="user_name" direction="in" /> + <arg type="s" name="package_name" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_type_query_label_by_locale"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="app_id" direction="in" /> + <arg type="s" name="locale" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="s" name="label_name" direction="out" /> + </method> + <method name="account_type_query_by_provider_feature"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="key" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="aa{sv}" name="account_type_list_data" direction="out" /> + </method> + <method name="account_query_account_by_user_name"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="user_name" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="aa{sv}" name="account_list_data" direction="out" /> + </method> + <method name="account_query_account_by_package_name"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="package_name" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="aa{sv}" name="account_list_data" direction="out" /> + </method> + <method name="account_query_account_by_capability"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="capability_type" direction="in" /> + <arg type="i" name="capability_value" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="aa{sv}" name="account_list_data" direction="out" /> + </method> + <method name="account_query_account_by_capability_type"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="capability_type" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="aa{sv}" name="account_list_data" direction="out" /> + </method> + <method name="account_query_capability_by_account_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="i" name="account_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="aa{sv}" name="account_list_data" direction="out" /> + </method> + <method name="account_update_sync_status_by_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="i" name="account_db_id" direction="in" /> + <arg type="i" name="sync_status" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_type_query_provider_feature_by_app_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="app_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="a(ss)" name="feature_list_data" direction="out" /> + </method> + <method name="account_type_query_supported_feature"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="app_id" direction="in" /> + <arg type="s" name="capability" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="i" name="is_supported" direction="out" /> + </method> + <method name="account_type_update_to_db_by_app_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="a{sv}" name="account_type_variant" direction="in" /> + <arg type="s" name="app_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_type_delete_by_app_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="app_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_type_query_label_by_app_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="app_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="a(sss)" name="label_list_variant" direction="out" /> + </method> + <method name="account_type_query_by_app_id"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="app_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + <arg type="a{sv}" name="account_type_variant" direction="out" /> + </method> + <method name="account_type_query_app_id_exist"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="s" name="app_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + <method name="account_update_to_db_by_id_ex"> + <arg type="s" name="account_db_path" direction="in" /> + <arg type="a{sv}" name="account_variant" direction="in" /> + <arg type="i" name="account_id" direction="in" /> + <arg type="s" name="cookie" direction="in" /> + </method> + </interface> +</node> diff --git a/common/include/account-private.h b/common/include/account-private.h new file mode 100644 index 0000000..8ce3d14 --- /dev/null +++ b/common/include/account-private.h @@ -0,0 +1,352 @@ +/* + * account + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Wonyoung Lee <wy1115.lee@samsung.com>, Sungchan Kim <sungchan81.kim@samsung.com> + * + * 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. + * + */ + +#ifndef __ACCOUNT_PRIVATE_H__ +#define __ACCOUNT_PRIVATE_H__ + +#include <stdlib.h> +#include <tizen.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include <glib.h> +#include <dlog.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "ACCOUNT" + +#define ACCOUNT_VERBOSE(fmt, arg...) \ + LOGD(": " fmt "\n", ##arg); +#define ACCOUNT_DEBUG(fmt, arg...) \ + LOGD(": " fmt "\n", ##arg); +#define ACCOUNT_ERROR(fmt, arg...) \ + LOGE(": " fmt "\n", ##arg); +#define ACCOUNT_FATAL(fmt, arg...) \ + LOGF(": " fmt "\n", ##arg); +#define ACCOUNT_SLOGD(fmt, arg...) \ + SECURE_LOGD(": " fmt "\n", ##arg); +#define ACCOUNT_SLOGI(fmt, arg...) \ + SECURE_LOGI(": " fmt "\n", ##arg); +#define ACCOUNT_SLOGE(fmt, arg...) \ + SECURE_LOGE(": " fmt "\n", ##arg); + +#define ACCOUNT_RETURN_VAL(eval, expr, ret_val, X)\ + if (!(eval)) \ +{\ + expr; \ + return ret_val;\ +} else {;} + +#define ACCOUNT_SNPRINTF(dest,size,format,arg...) \ + do { \ + snprintf(dest,size-1,format,##arg); \ + }while(0) + /* If the same pointer is passed to free twice, known as a double free. To avoid this, set pointers to +NULL after passing them to free: free(NULL) is safe (it does nothing). + */ + +#define ACCOUNT_MEMSET(dest,value,size) \ + do { \ + memset(dest,value,size); \ + }while(0) + +#define ACCOUNT_CATCH_ERROR(eval, expr, error_val, X) \ + if (!(eval)) \ +{\ + expr; \ + error_code = (error_val);\ + goto CATCH;\ +} else {;} + +#define ACCOUNT_CATCH_ERROR_P(eval, expr, error_val, X) \ + if (!(eval)) \ +{\ + expr; \ + *error_code = (error_val);\ + goto CATCH;\ +} else {;} + +#define _ACCOUNT_FREE(ptr) \ + if (ptr != NULL) { \ + free(ptr); \ + ptr = NULL; \ + } \ + + +#define _ACCOUNT_GFREE(ptr) \ + if (ptr != NULL) { \ + g_free(ptr); \ + ptr = NULL; \ + } \ + +#define ACCOUNT_DB_NAME "/opt/usr/dbspace/.account.db" +#define ACCOUNT_TABLE "account" +#define CAPABILITY_TABLE "capability" +#define ACCOUNT_CUSTOM_TABLE "account_custom" +#define ACCOUNT_TYPE_TABLE "account_type" +#define LABEL_TABLE "label" +#define PROVIDER_FEATURE_TABLE "provider_feature" +#define ACCOUNT_SQLITE_SEQ "sqlite_sequence" +#define ACCOUNT_SQL_LEN_MAX 1024 +#define ACCOUNT_TABLE_TOTAL_COUNT 6 + +#define FACEBOOK_PKG_NAME "com.samsung.facebook" +#define EMAIL_PKG_NAME "email-setting-efl" +#define EXCHANGE_PKG_NAME "activesync-ui" +#define IMS_SERVICE_PKG_NAME "ims-service" +#define SAMSUNGACCOUNTFRONT_PKG_NAME "com.samsung.samsung-account-front" +//#define SAMSUNGACCOUNT_PKG_NAME "gr47by21a5.SamsungAccount" +#define SAMSUNGACCOUNT_PKG_NAME "com.samsung.samsungaccount" +#define CHATON_PKG_NAME "xnq5eh9vop.ChatON" +#define DROPBOX_PKG_NAME "com.samsung.dropbox" +#define SYNCHRONISE_PKG_NAME "setting-synchronise-efl" + +#define USER_TXT_CNT 5 +#define USER_INT_CNT 5 + + +/* account uri list */ +#define ACCOUNT_DATA_SERVICE_PROVIDER "http://tizen.org/account/data/service_provider" +#define ACCOUNT_OPERATION_SIGNIN_OLD "http://tizen.org/account/operation/signin" + +// private account operation type +#define ACCOUNT_OPERATION_FMM "http://tizen.org/account/operation/fmm" +#define ACCOUNT_OPERATION_MYACCOUNT "http://tizen.org/account/operation/signin_from_myaccount" +// End of private account operation type + +#define ACCOUNT_SUPPORTS_CAPABILITY_POST "http://tizen.org/account/capability/post" +#define ACCOUNT_SUPPORTS_CAPABILITY_VOIP "http://tizen.org/account/capability/voip" +#define ACCOUNT_SUPPORTS_CAPABILITY_SAMSUNG_APPS "http://tizen.org/account/capability/samsungapps" +#define ACCOUNT_SUPPORTS_CAPABILITY_TASK "http://tizen.org/account/capability/task" +#define ACCOUNT_SUPPORTS_CAPABILITY_MOBILE_TRACKER "http://tizen.org/account/capability/mobiletracker" +#define ACCOUNT_SUPPORTS_CAPABILITY_S_NOTE "http://tizen.org/account/capability/snote" +#define ACCOUNT_SUPPORTS_CAPABILITY_GALLERY "http://tizen.org/account/capability/gallery" +#define ACCOUNT_SUPPORTS_CAPABILITY_MEMO "http://tizen.org/account/capability/memo" +#define ACCOUNT_SUPPORTS_CAPABILITY_CHAT "http://tizen.org/account/capability/chat" +#define ACCOUNT_SUPPORTS_CAPABILITY_BOOKMARK "http://tizen.org/account/capability/bookmark" +#define ACCOUNT_SUPPORTS_CAPABILITY_SYNCHRONISE "http://tizen.org/account/capability/synchronise" +#define ACCOUNT_SUPPORTS_CAPABILITY_TIZEN_EMAIL "http://tizen.org/account/capability/tizen_email" +#define ACCOUNT_SUPPORTS_CAPABILITY_INTERNET "http://tizen.org/account/capability/internet" +#define ACCOUNT_SUPPORTS_CAPABILITY_DOCOMO_SCHEDULE_MEMO "http://tizen.org/account/capability/docomo" +/* end of account uri list */ + +typedef struct _account_sso_access_list_s +{ + GList *acl; +}account_sso_access_list_s; + +typedef struct _account_s +{ + int id; + char* user_name; + char* email_address; + char* display_name; + char* icon_path; + char* source; + char* package_name; + char* access_token; + char* domain_name; /*< domain name [Ex: google, facebook, twitter, samsung, ...] */ +// char* auth_method; + int auth_type; + int secret; + int sync_support; + int user_data_int[USER_INT_CNT]; + char* user_data_txt[USER_TXT_CNT]; + GSList* capablity_list; + GList* account_list; + GSList* custom_list; +// GList* domain_list; +// GList* mechanism_list; +// account_sso_access_list_s *acl; +}account_s; + +typedef struct _capability_s +{ + int id; + char* type; + int value; + char* package_name; + char* user_name; + int account_id; +}account_capability_s; + + +typedef struct _account_custom_s +{ + int account_id; + char* app_id; + char* key; + char* value; +}account_custom_s; + +typedef struct _account_type_s +{ + int id; + char* app_id; + char* service_provider_id; + char* icon_path; + char* small_icon_path; + bool multiple_account_support; + GSList* label_list; +// GList* account_type_list; + GSList* provider_feature_list; +}account_type_s; + + +typedef struct _label_s +{ + char* app_id; + char* label; + char* locale; +}label_s; + +typedef struct _provider_feature_s +{ + char* key; + char* app_id; +}provider_feature_s; + +typedef struct _account_auth_data_s +{ + GVariant* auth_data; +}account_auth_data_s; + +/** + * @brief Enumarations for account handle fields. + */ + +typedef enum { + ACCOUNT_FIELD_NONE = -1, + ACCOUNT_FIELD_ID, + ACCOUNT_FIELD_USER_NAME, + ACCOUNT_FIELD_EMAIL_ADDRESS, + ACCOUNT_FIELD_DISPLAY_NAME, + ACCOUNT_FIELD_ICON_PATH, + ACCOUNT_FIELD_SOURCE, + ACCOUNT_FIELD_PACKAGE_NAME, + ACCOUNT_FIELD_ACCESS_TOKEN, + ACCOUNT_FIELD_DOMAIN_NAME, +// ACCOUNT_FIELD_AUTH_METHOD, + ACCOUNT_FIELD_AUTH_TYPE, + ACCOUNT_FIELD_SECRET, + ACCOUNT_FIELD_SYNC_SUPPORT, + ACCOUNT_FIELD_USER_TEXT_0, + ACCOUNT_FIELD_USER_TEXT_1, + ACCOUNT_FIELD_USER_TEXT_2, + ACCOUNT_FIELD_USER_TEXT_3, + ACCOUNT_FIELD_USER_TEXT_4, + ACCOUNT_FIELD_USER_INT_0, + ACCOUNT_FIELD_USER_INT_1, + ACCOUNT_FIELD_USER_INT_2, + ACCOUNT_FIELD_USER_INT_3, + ACCOUNT_FIELD_USER_INT_4, + ACCOUNT_DB_FIELD_END +} ACCOUNT_DB_IDX; + +/** + * @brief Enumarations for capability fields. + */ + +typedef enum { + CAPABILITY_FIELD_NONE = -1, + CAPABILITY_FIELD_ID, + CAPABILITY_FIELD_KEY, + CAPABILITY_FIELD_VALUE, + CAPABILITY_FIELD_PACKAGE_NAME, + CAPABILITY_FIELD_USER_NAME, + CAPABILITY_FIELD_ACCOUNT_ID, + CAPABILITY_FIELD_END, +}CAPABILITY_DB_IDX; + + +typedef enum { + ACCOUNT_CUSTOM_FIELD_NONE = -1, + ACCOUNT_CUSTOM_FIELD_ACCOUNT_ID, + ACCOUNT_CUSTOM_FIELD_APP_ID, + ACCOUNT_CUSTOM_FIELD_KEY, + ACCOUNT_CUSTOM_FIELD_VALUE, + ACCOUNT_CUSTOM_FIELD_END, +}ACCOUNT_CUSTOM_DB_IDX; + +typedef enum { + ACCOUNT_TYPE_FIELD_NONE = -1, + ACCOUNT_TYPE_FIELD_ID, + ACCOUNT_TYPE_FIELD_APP_ID, + ACCOUNT_TYPE_FIELD_SERVICE_PROVIDER_ID, + ACCOUNT_TYPE_FIELD_ICON_PATH, + ACCOUNT_TYPE_FIELD_SMALL_ICON_PATH, + ACCOUNT_TYPE_FIELD_MULTIPLE_ACCOUNT_SUPPORT, + ACCOUNT_TYPE_FIELD_END, +}ACCOUNT_TYPE_DB_IDX; + +typedef enum { + LABEL_FIELD_NONE = -1, + LABEL_FIELD_APP_ID, + LABEL_FIELD_LABEL, + LABEL_FIELD_LOCALE, + LABEL_FIELD_END, +}LABEL_DB_IDX; + +typedef enum { + PROVIDER_FEATURE_FIELD_NONE = -1, + PROVIDER_FEATURE_FIELD_APP_ID, + PROVIDER_FEATURE_FIELD_KEY, + PROVIDER_FEATURE_FIELD_END, +}PROVIDER_FEATURE_DB_IDX; + +typedef struct GSList account_iterator_s; + +#define ACCOUNT_SSO_MAX_LIST_COUNT 100 +#define ACCOUNT_SSO_MAX_APP_NAME_LENGTH 128 + +#define _ACCOUNT_SVC_ERROR_DOMAIN "accounts-svc" +#define _ACCOUNT_SVC_ERROR_PREFIX "org.tizen.account.manager.Error" + +#define EAS_CMDLINE "/usr/bin/eas-engine" +#define EMAIL_SERVICE_CMDLINE "/usr/bin/email-service" +#define IMS_ENGINE_CMDLINE "/usr/bin/ims-srv" +#define IMS_AGENT_CMDLINE "/usr/bin/ims-agent" +#define MDM_SERVER_CMDLINE "/usr/bin/mdm-server" + +#define RCS_APPID "com.samsung.rcs-im" +#define IMS_SERVICE_APPID "ims-service" +#define ACTIVESYNC_APPID "eas-ui" +#define EMAIL_APPID "email-setting-efl" +#define SYNCHRONISE_APPID "setting-synchronise-efl" +#define DS_AGENT_CMDLINE "/usr/bin/oma-ds-agent" + +#define FACEBOOK_SDK_APPID "com.samsung.facebook-service" +#define FACEBOOK_APPID "com.samsung.facebook" + +//Used by both accounts and gtme. However as of now, gtme does not have any dependency on account, so duplicating the same +#define MAX_SYS_CONTEXT_SIZE 1024 + +#ifdef __cplusplus +} +#endif + +#endif /* __ACCOUNT_PRIVATE_H__*/ diff --git a/common/include/account_free.h b/common/include/account_free.h new file mode 100644 index 0000000..016d021 --- /dev/null +++ b/common/include/account_free.h @@ -0,0 +1,54 @@ +/* + * account + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jiseob Jang <jiseob.jang@samsung.com> + * + * 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. + * + */ + +#ifndef __ACCOUNT_FREE_H__ +#define __ACCOUNT_FREE_H__ + + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include <glib.h> +#include <account-private.h> + +int _account_glist_account_free(GList* list); +int _account_gslist_account_free(GSList *list); +int _account_gslist_capability_free(GSList* list); +int _account_gslist_custom_free(GSList* list); +int _account_free_account_with_items(account_s *data); +int _account_free_capability_with_items(account_capability_s *data); +int _account_free_custom_with_items(account_custom_s *data); +//int _account_type_glist_free(GList* list); +int _account_type_gslist_account_type_free(GSList *list); +int _account_type_gslist_label_free(GSList* list); +int _account_type_gslist_feature_free(GSList* list); +int _account_type_item_free(account_type_s *data); +int _account_type_free_account_type_with_items(account_type_s *data); +int _account_type_free_label_with_items(label_s *data); +int _account_type_free_feature_with_items(provider_feature_s *data); + +#ifdef __cplusplus +} +#endif + +#endif /* __ACCOUNT_FREE_H__*/ diff --git a/common/include/account_ipc_marshal.h b/common/include/account_ipc_marshal.h new file mode 100644 index 0000000..ce94d9b --- /dev/null +++ b/common/include/account_ipc_marshal.h @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + * + */ + +#ifndef __ACC_IPC_MARSHAL_H__ +#define __ACC_IPC_MARSHAL_H__ + +#include "account-private.h" + +GVariant* marshal_account(const account_s* account); +account_s* umarshal_account(GVariant* in_data); + +GVariant* marshal_account_type(const account_type_s* account_type); +account_type_s* umarshal_account_type(GVariant* in_data); + +GVariant* marshal_account_list_double(GList* account_list); +GVariant* marshal_account_list(GSList* account_list); +GSList* unmarshal_account_list(GVariant* variant); + +GVariant* marshal_account_type_list(GSList* account_type_list); +GSList* unmarshal_account_type_list(GVariant* variant); + +GVariant* marshal_capability_list(GSList* capability_list); +GSList* unmarshal_capability_list(GVariant* variant); + +GVariant* marshal_custom_list(GSList* capability_list); +GSList* unmarshal_custom_list(GVariant* variant); + +GVariant* marshal_user_int_array(const int* user_data_int_array); +GVariant* marshal_user_txt_array(char* const* user_txt_array); + +int* unmarshal_user_int_array(GVariant* variant); +char** unmarshal_user_txt_array(GVariant* variant); + +account_s* create_empty_account_instance(void); + +GVariant * provider_feature_list_to_variant (GSList *list); +GSList* variant_to_provider_feature_list(GVariant *variant); + +GVariant *label_list_to_variant (GSList *list); +GSList *variant_to_label_list (GVariant *variant); + +account_type_s* create_empty_account_type_instance(void); + +#endif diff --git a/common/include/dbg.h b/common/include/dbg.h new file mode 100644 index 0000000..cb23b6b --- /dev/null +++ b/common/include/dbg.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef __DBG_H__ + +#include <dlog.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "ACCOUNT" + +#ifndef _ERR +#define _ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#endif + +#ifndef _DBG +#define _DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#endif + +#ifndef _INFO +#define _INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#endif + + +#endif /* __DBG_H__ */ diff --git a/common/src/account_free.c b/common/src/account_free.c new file mode 100644 index 0000000..de9e1dd --- /dev/null +++ b/common/src/account_free.c @@ -0,0 +1,284 @@ +/* + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 "account-private.h" +#include "dbg.h" +#include "account_free.h" + +int _account_glist_account_free(GList* list) +{ + if(!list){ + return -1; + } + + GList* iter; + + for (iter = list; iter != NULL; iter = g_list_next(iter)) { + account_s *account_record = (account_s*)iter->data; + _account_free_account_with_items(account_record); + } + + g_list_free(list); + list = NULL; + + return 0; +} + +int _account_gslist_account_free(GSList *list) +{ + if(!list){ + return -1; + } + + GSList* iter; + + for (iter = list; iter != NULL; iter = g_slist_next(iter)) { + account_s *account_data = (account_s*)iter->data; + _account_free_account_with_items(account_data); + } + + g_slist_free(list); + list = NULL; + + return 0; +} + +int _account_gslist_capability_free(GSList* list) +{ + if(!list){ + return -1; + } + + GSList* iter; + + for (iter = list; iter != NULL; iter = g_slist_next(iter)) { + account_capability_s *cap_data = (account_capability_s*)iter->data; + _account_free_capability_with_items(cap_data); + } + + g_slist_free(list); + list = NULL; + + return 0; +} + +int _account_gslist_custom_free(GSList* list) +{ + if(!list){ + return -1; + } + + GSList* iter; + + for (iter = list; iter != NULL; iter = g_slist_next(iter)) { + account_custom_s *custom_data = (account_custom_s*)iter->data; + _account_free_custom_with_items(custom_data); + } + + g_slist_free(list); + list = NULL; + + return 0; +} + +int _account_free_capability_with_items(account_capability_s *data) +{ + if(!data) + return -1; + + _ACCOUNT_FREE(data->type); + _ACCOUNT_FREE(data->package_name); + _ACCOUNT_FREE(data->user_name); + + _ACCOUNT_FREE(data); + + return 0; +} + +int _account_free_custom_with_items(account_custom_s *data) +{ + if(!data) + return -1; + + _ACCOUNT_FREE(data->app_id); + _ACCOUNT_FREE(data->key); + _ACCOUNT_FREE(data->value); + + _ACCOUNT_FREE(data); + + return 0; +} + +int _account_free_account_with_items(account_s *data) +{ + if(!data) + return -1; + + _ACCOUNT_FREE(data->user_name); + _ACCOUNT_FREE(data->email_address); + _ACCOUNT_FREE(data->display_name); + _ACCOUNT_FREE(data->icon_path); + _ACCOUNT_FREE(data->source); + _ACCOUNT_FREE(data->package_name); + _ACCOUNT_FREE(data->domain_name); + _ACCOUNT_FREE(data->access_token); + + int i; + for(i=0;i<USER_TXT_CNT;i++) + _ACCOUNT_FREE(data->user_data_txt[i]); + + _account_gslist_capability_free(data->capablity_list); + _account_glist_account_free(data->account_list); + _account_gslist_custom_free(data->custom_list); + + _ACCOUNT_FREE(data); + + return 0; +} + +int _account_type_free_label_with_items(label_s *data) +{ + if(!data) + return -1; + + _ACCOUNT_FREE(data->app_id); + _ACCOUNT_FREE(data->label); + _ACCOUNT_FREE(data->locale); + + _ACCOUNT_FREE(data); + + return 0; +} + +int _account_type_free_feature_with_items(provider_feature_s *data) +{ + if(!data) + return -1; + + _ACCOUNT_FREE(data->app_id); + _ACCOUNT_FREE(data->key); + + _ACCOUNT_FREE(data); + return 0; +} + +int _account_type_gslist_feature_free(GSList* list) +{ + if(!list) + return -1; + + GSList* iter; + + for (iter = list; iter != NULL; iter = g_slist_next(iter)) { + provider_feature_s *feature_data = (provider_feature_s*)iter->data; + _account_type_free_feature_with_items(feature_data); + } + + g_slist_free(list); + list = NULL; + + return 0; +} + +int _account_type_gslist_label_free(GSList* list) +{ + if(!list) + return -1; + + GSList* iter; + + for (iter = list; iter != NULL; iter = g_slist_next(iter)) { + label_s *label_data = (label_s*)iter->data; + _account_type_free_label_with_items(label_data); + } + + g_slist_free(list); + list = NULL; + + return 0; +} + +int _account_type_item_free(account_type_s *data) +{ + if(!data) + return -1; + + _ACCOUNT_FREE(data->app_id); + _ACCOUNT_FREE(data->service_provider_id); + _ACCOUNT_FREE(data->icon_path); + _ACCOUNT_FREE(data->small_icon_path); + + return 0; +} +/* +int _account_type_glist_free(GList* list) +{ + if(!list) + return -1; + + GList* iter; + + for (iter = list; iter != NULL; iter = g_list_next(iter)) { + account_type_s *account_type_record = (account_type_s*)iter->data; + _account_type_item_free(account_type_record); + _ACCOUNT_FREE(account_type_record); + } + + g_list_free(list); + list = NULL; + + return 0; +} +*/ +int _account_type_free_account_type_with_items(account_type_s *data) +{ + if(!data) + return -1; + + _account_type_item_free(data); + + _account_type_gslist_label_free(data->label_list); + _account_type_gslist_feature_free(data->provider_feature_list); +// _account_type_glist_free(data->account_type_list); + + _ACCOUNT_FREE(data); + + return 0; +} + +int _account_type_gslist_account_type_free(GSList* list) +{ + _INFO("_account_type_gslist_account_type_free(GSList* list) start"); + if(!list) + return -1; + + GSList* iter; + + for (iter = list; iter != NULL; iter = g_slist_next(iter)) { + account_type_s *account_type_data = (account_type_s*)iter->data; + _INFO("before _account_type_free_account_type_with_items(account_type_data)"); + _account_type_free_account_type_with_items(account_type_data); + _INFO("after _account_type_free_account_type_with_items(account_type_data)"); + } + + g_slist_free(list); + list = NULL; + + _INFO("_account_type_gslist_account_type_free(GSList* list) end"); + return 0; +} diff --git a/common/src/account_ipc_marshal.c b/common/src/account_ipc_marshal.c new file mode 100644 index 0000000..1e7dd0a --- /dev/null +++ b/common/src/account_ipc_marshal.c @@ -0,0 +1,1341 @@ +/* + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 <stdio.h> //snprintf +#include <stdlib.h> //calloc +#include <string.h> + +#include "account_ipc_marshal.h" +#include "dbg.h" + +#define ACCOUNT_DATA_KEY_ID "id" +#define ACCOUNT_DATA_KEY_USER_NAME "user_name" +#define ACCOUNT_DATA_KEY_EMAIL "email_address" +#define ACCOUNT_DATA_KEY_DISPLAY_NAME "display_name" +#define ACCOUNT_DATA_KEY_ICON_PATH "icon_path" +#define ACCOUNT_DATA_KEY_SOURCE "source" +#define ACCOUNT_DATA_KEY_PACKAGE_NAME "package_name" +#define ACCOUNT_DATA_KEY_ACCESS_TOKEN "access_token" +#define ACCOUNT_DATA_KEY_DOMAIN_NAME "domain_name" +#define ACCOUNT_DATA_KEY_AUTH_TYPE "auth_type" +#define ACCOUNT_DATA_KEY_SECRET "secret" +#define ACCOUNT_DATA_KEY_SYNC_SUPPORT "sync_support" +#define ACCOUNT_DATA_KEY_USER_DATA_INT "user_data_int" +#define ACCOUNT_DATA_KEY_USER_DATA_TXT "user_data_txt" +#define ACCOUNT_DATA_KEY_CAPABILITY_LIST "capability_list" +#define ACCOUNT_DATA_KEY_ACCOUNT_LIST "account_list" +#define ACCOUNT_DATA_KEY_CUSTOM_LIST "custom_list" + +#define ACCOUNT_TYPE_DATA_KEY_ID "id" +#define ACCOUNT_TYPE_DATA_KEY_APP_ID "app_id" +#define ACCOUNT_TYPE_DATA_KEY_SERVICE_PROVIDER_ID "service_provider_id" +#define ACCOUNT_TYPE_DATA_KEY_ICON_PATH "icon_path" +#define ACCOUNT_TYPE_DATA_KEY_SMALL_ICON_PATH "small_icon_path" +#define ACCOUNT_TYPE_DATA_KEY_MULTI_SUPPORT "multiple_account_support" +#define ACCOUNT_TYPE_DATA_KEY_LABEL_LIST "label_list" +#define ACCOUNT_TYPE_DATA_KEY_ACC_TYPE_LIST "account_type_list" +#define ACCOUNT_TYPE_DATA_KEY_PROVIDER_FEATURE_LIST "provider_feature_list" + +#define ACCOUNT_CAPABILITY_DATA_KEY_ID "id" +#define ACCOUNT_CAPABILITY_DATA_KEY_TYPE "type" +#define ACCOUNT_CAPABILITY_DATA_KEY_VALUE "value" +#define ACCOUNT_CAPABILITY_DATA_KEY_PACKAGE_NAME "package_name" +#define ACCOUNT_CAPABILITY_DATA_KEY_USER_NAME "user_name" +#define ACCOUNT_CAPABILITY_DATA_KEY_ACC_ID "account_id" + +#define ACCOUNT_CUSTOM_DATA_KEY_ACC_ID "account_id" +#define ACCOUNT_CUSTOM_DATA_KEY_APP_ID "app_id" +#define ACCOUNT_CUSTOM_DATA_KEY_KEY "key" +#define ACCOUNT_CUSTOM_DATA_KEY_VALUE "value" + +static label_s* +_variant_to_label(GVariant *variant) +{ + gchar *app_id = NULL; + gchar *label = NULL; + gchar *locale = NULL; + + g_return_val_if_fail (variant != NULL, NULL); + + g_variant_get (variant, "(sss)", &app_id, &label, &locale); + + label_s* label_data = (label_s*) calloc(1, sizeof(label_s)); + + if( label_data == NULL ) { + _ERR("provider_feature_s calloc failed - out of memory."); + return NULL; + } + + label_data->app_id = g_strdup(app_id); + label_data->label = g_strdup(label); + label_data->locale = g_strdup(locale); + + g_free (app_id); + g_free (label); + g_free (locale); + + return label_data; +} + +GSList* +variant_to_label_list(GVariant *variant) +{ + GSList *list = NULL; + GVariantIter iter; + GVariant *value; + + g_return_val_if_fail (variant != NULL, NULL); + + g_variant_iter_init (&iter, variant); + while ((value = g_variant_iter_next_value (&iter))) { + list = g_slist_append (list, + _variant_to_label(value)); + g_variant_unref (value); + } + + return list; +} + + +static GVariant * +_label_to_variant (label_s *label_data) +{ + GVariant *variant; + + g_return_val_if_fail (label_data != NULL, NULL); + + variant = g_variant_new ("(sss)", + label_data->app_id ? label_data->app_id : "", + label_data->label ? label_data->label : "", + label_data->locale ? label_data->locale : ""); + + return variant; +} + +GVariant * +label_list_to_variant (GSList *list) +{ + GVariantBuilder builder; + GVariant *variant; + label_s *label_data; + + GSList* iter; + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + for (iter = list ; iter != NULL; iter = g_slist_next (iter)) + { + label_data = (label_s*) (iter->data); + g_variant_builder_add_value ( + &builder, + _label_to_variant(label_data)); + } + variant = g_variant_builder_end (&builder); + + return variant; +} + + +static provider_feature_s* +_variant_to_provider_feature(GVariant *variant) +{ + gchar *key = NULL; + gchar *app_id = NULL; + + g_return_val_if_fail (variant != NULL, NULL); + + g_variant_get (variant, "(ss)", &key, &app_id); + + provider_feature_s* provider_feature_data = (provider_feature_s*) calloc(1, sizeof(provider_feature_s)); + + if( provider_feature_data == NULL ) { + _ERR("provider_feature_s calloc failed - out of memory."); + return NULL; + } + + provider_feature_data->key = g_strdup(key); + provider_feature_data->app_id = g_strdup(app_id); + + g_free (key); + g_free (app_id); + + return provider_feature_data; +} + +GSList* +variant_to_provider_feature_list(GVariant *variant) +{ + GSList *list = NULL; + GVariantIter iter; + GVariant *value; + + g_return_val_if_fail (variant != NULL, NULL); + + g_variant_iter_init (&iter, variant); + while ((value = g_variant_iter_next_value (&iter))) { + list = g_slist_append (list, + _variant_to_provider_feature(value)); + g_variant_unref (value); + } + + return list; +} + +static GVariant * +_provider_feature_to_variant (const provider_feature_s *pro_feature_data) +{ + GVariant *variant; + + g_return_val_if_fail (pro_feature_data != NULL, NULL); + + variant = g_variant_new ("(ss)", + pro_feature_data->key ? pro_feature_data->key : "", + pro_feature_data->app_id ? pro_feature_data->app_id : ""); + + return variant; +} + +GVariant * +provider_feature_list_to_variant (GSList *list) +{ + GVariantBuilder builder; + GVariant *variant; + provider_feature_s *provider_feature_data; + + GSList* iter; + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + for (iter = list ; iter != NULL; iter = g_slist_next (iter)) { + provider_feature_data = (provider_feature_s *) (iter->data); + g_variant_builder_add_value ( + &builder, + _provider_feature_to_variant(provider_feature_data)); + } + variant = g_variant_builder_end (&builder); + + return variant; +} + +GVariant * +marshal_account(const account_s* account) +{ + _INFO("_marshal_account start"); + + const account_s* in_data = account; + GVariantBuilder builder; + int i; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_ID, + g_variant_new_int32 (in_data->id)); + + if (in_data->user_name != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_USER_NAME, + g_variant_new_string (in_data->user_name)); + } + if (in_data->email_address != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_EMAIL, + g_variant_new_string (in_data->email_address)); + } + if (in_data->display_name != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_DISPLAY_NAME, + g_variant_new_string (in_data->display_name)); + } + if (in_data->icon_path != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_ICON_PATH, + g_variant_new_string (in_data->icon_path)); + } + if (in_data->source != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_SOURCE, + g_variant_new_string (in_data->source)); + } + if (in_data->package_name != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_PACKAGE_NAME, + g_variant_new_string (in_data->package_name)); + } + if (in_data->access_token != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_ACCESS_TOKEN, + g_variant_new_string (in_data->access_token)); + } + if (in_data->domain_name != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_DOMAIN_NAME, + g_variant_new_string (in_data->domain_name)); + } + + g_variant_builder_add (&builder, "{sv}", ACCOUNT_DATA_KEY_AUTH_TYPE, g_variant_new_int32 (in_data->auth_type)); + + g_variant_builder_add (&builder, "{sv}", ACCOUNT_DATA_KEY_SECRET, g_variant_new_int32 (in_data->secret)); + + g_variant_builder_add (&builder, "{sv}", ACCOUNT_DATA_KEY_SYNC_SUPPORT, g_variant_new_int32 (in_data->sync_support)); + + for(i=0; i<USER_INT_CNT; i++) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_USER_DATA_INT, + marshal_user_int_array((const int*) in_data->user_data_int)); + } + + for(i=0; i<USER_TXT_CNT; i++) + { + GVariant *variant = marshal_user_txt_array((char* const*)in_data->user_data_txt); + if( variant ) { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_USER_DATA_TXT, + variant); + } + } + + if (in_data->capablity_list != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_CAPABILITY_LIST, + marshal_capability_list (in_data->capablity_list)); + } + + if (in_data->custom_list != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_DATA_KEY_CUSTOM_LIST, + marshal_custom_list (in_data->custom_list)); + } + + //TODO: add support for rest + + _INFO("__marshal_account end"); + + return g_variant_builder_end (&builder); +} + +account_s* umarshal_account(GVariant* in_data) +{ + _INFO("umarshal_account start"); + + if (in_data == NULL) + { + _ERR("Null input"); + return NULL; + } + + GVariant* temp_var = in_data; + gchar* print_type = NULL; + print_type = g_variant_print(temp_var, TRUE); + if (print_type == NULL) + { + _ERR("Invalid input"); + return NULL; + } + + account_s* account = (account_s*)calloc(1, sizeof(account_s)); + if (account == NULL) + { + _ERR("Out of memory"); + return NULL; + } + + GVariantIter iter; + gchar *key = NULL; + GVariant *value = NULL; + + g_variant_iter_init (&iter, in_data); + + while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) + { + if (!strcmp(key, ACCOUNT_DATA_KEY_ID)) + { + account->id = g_variant_get_int32 (value); + } + + if (!strcmp(key, ACCOUNT_DATA_KEY_USER_NAME)) + { + account->user_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_EMAIL)) + { + account->email_address = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_DISPLAY_NAME)) + { + account->display_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_ICON_PATH)) + { + account->icon_path = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_SOURCE)) + { + account->source = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_PACKAGE_NAME)) + { + account->package_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_ACCESS_TOKEN)) + { + account->access_token = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_DOMAIN_NAME)) + { + account->domain_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_AUTH_TYPE)) + { + account->auth_type = g_variant_get_int32 (value); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_SECRET)) + { + account->secret = g_variant_get_int32 (value); + } + + else if (!strcmp(key, ACCOUNT_DATA_KEY_SYNC_SUPPORT)) + { + account->sync_support = g_variant_get_int32 (value); + } + else if (!strcmp(key, ACCOUNT_DATA_KEY_USER_DATA_INT)) + { + int i; + int* tmp_user_ints = unmarshal_user_int_array(value); + for(i=0; i<USER_INT_CNT; i++) + { + account->user_data_int[i] = tmp_user_ints[i]; + } + _ACCOUNT_FREE(tmp_user_ints); + } + else if (!strcmp(key, ACCOUNT_DATA_KEY_USER_DATA_TXT)) + { + int i; + char** tmp_user_txts = unmarshal_user_txt_array(value); + for(i=0; i<USER_TXT_CNT; i++) + { + account->user_data_txt[i] = strdup(tmp_user_txts[i]); + _ACCOUNT_FREE(tmp_user_txts[i]); + } + _ACCOUNT_FREE(tmp_user_txts); + } + else if (!strcmp(key, ACCOUNT_DATA_KEY_CAPABILITY_LIST)) + { + account->capablity_list = unmarshal_capability_list (value); + } + else if (!strcmp(key, ACCOUNT_DATA_KEY_CUSTOM_LIST)) + { + account->custom_list = unmarshal_custom_list (value); + } + //TODO: support for rest + } + + _INFO("unmarshal_account end"); + return account; +} + +GVariant* marshal_account_list_double(GList* account_list) +{ + _INFO("marshal_account_list start"); + if (account_list == NULL) + { + _ERR("input NULL."); + return NULL; + } + + GVariantBuilder builder; + account_s *account_data; + + GList* iter; + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + + for (iter = account_list ; iter != NULL; iter = g_list_next (iter)) + { + account_data = (account_s *) (iter->data); + g_variant_builder_add_value(&builder, marshal_account(account_data)); + } + _INFO("marshal_account_list end"); + return g_variant_builder_end (&builder); +} + +GVariant* marshal_account_list(GSList* account_list) +{ + _INFO("marshal_account_list start"); + if (account_list == NULL) + { + _ERR("input NULL."); + return NULL; + } + + GVariantBuilder builder; + account_s *account_data; + + GSList* iter; + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + + for (iter = account_list ; iter != NULL; iter = g_slist_next (iter)) + { + account_data = (account_s *) (iter->data); + g_variant_builder_add_value(&builder, marshal_account(account_data)); + _INFO("end one iteration of account_list"); + } + _INFO("marshal_account_list end"); + return g_variant_builder_end (&builder); +} + +GSList* unmarshal_account_list(GVariant* variant) +{ + _INFO("unmarshal_account_list start"); + GSList *list = NULL; + GVariantIter iter; + GVariantIter* iter_row = NULL; + const gchar *key = NULL; + GVariant *value = NULL; + + if (variant == NULL) + { + _ERR("input NULL"); + return NULL; + } + +// gchar* var_type = g_variant_print (variant, TRUE); +// _INFO("var_type = %s", var_type); + + g_variant_iter_init (&iter, variant); + + while (g_variant_iter_loop (&iter, "a{sv}", &iter_row)) + { + account_s* account = (account_s*)calloc(1, sizeof(account_s)); + + while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) + { + if (!g_strcmp0(key, ACCOUNT_DATA_KEY_ID)) + { + account->id = g_variant_get_int32 (value); + } + + if (!g_strcmp0(key, ACCOUNT_DATA_KEY_USER_NAME)) + { + account->user_name = g_strdup(g_variant_get_string(value, NULL)); + } + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_EMAIL)) + { + account->email_address = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_DISPLAY_NAME)) + { + account->display_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_ICON_PATH)) + { + account->icon_path = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_SOURCE)) + { + account->source = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_PACKAGE_NAME)) + { + account->package_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_ACCESS_TOKEN)) + { + account->access_token = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_DOMAIN_NAME)) + { + account->domain_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_AUTH_TYPE)) + { + account->auth_type = g_variant_get_int32 (value); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_SECRET)) + { + account->secret = g_variant_get_int32 (value); + } + + else if (!g_strcmp0(key, ACCOUNT_DATA_KEY_SYNC_SUPPORT)) + { + account->sync_support = g_variant_get_int32 (value); + } + else if (!strcmp(key, ACCOUNT_DATA_KEY_USER_DATA_INT)) + { + int i; + int* tmp_user_ints = unmarshal_user_int_array(value); + for(i=0; i<USER_INT_CNT; i++) + { + account->user_data_int[i] = tmp_user_ints[i]; + } + _ACCOUNT_FREE(tmp_user_ints); + } + else if (!strcmp(key, ACCOUNT_DATA_KEY_USER_DATA_TXT)) + { + int i; + char** tmp_user_txts = unmarshal_user_txt_array(value); + for(i=0; i<USER_TXT_CNT; i++) + { + account->user_data_txt[i] = strdup(tmp_user_txts[i]); + _ACCOUNT_FREE(tmp_user_txts[i]); + } + _ACCOUNT_FREE(tmp_user_txts); + } + else if (!strcmp(key, ACCOUNT_DATA_KEY_CAPABILITY_LIST)) + { + account->capablity_list = unmarshal_capability_list (value); + } + else if (!strcmp(key, ACCOUNT_DATA_KEY_CUSTOM_LIST)) + { + account->custom_list = unmarshal_custom_list (value); + } + } + list = g_slist_append (list, account); + + } + + _INFO("unmarshal_account_list end"); + return list; +} + +GVariant* marshal_account_type_list(GSList* account_type_list) +{ + _INFO("marshal_account_type_list start"); + if (account_type_list == NULL) + { + _ERR("input NULL."); + return NULL; + } + + GVariantBuilder builder; + account_type_s *account_type_data = NULL; + + GSList* iter; + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + + for (iter = account_type_list ; iter != NULL; iter = g_slist_next (iter)) + { + account_type_data = (account_type_s *) (iter->data); + g_variant_builder_add_value(&builder, marshal_account_type((account_type_s*)account_type_data)); + } + + _INFO("marshal_account_type_list end"); + return g_variant_builder_end (&builder); +} + +account_s* create_empty_account_instance(void) +{ + _INFO("create_empty_account_instance start"); + + account_s *data = (account_s*)malloc(sizeof(account_s)); + + if (data == NULL) + { + ACCOUNT_ERROR("Memory Allocation Failed"); + return NULL; + } + + ACCOUNT_MEMSET(data, 0, sizeof(account_s)); + + data->id = -1; + data->user_name = NULL; + data->email_address = NULL; + data->display_name = NULL; + data->icon_path = NULL; + data->source = NULL; + data->package_name = NULL; + data->access_token = NULL; + data->domain_name = NULL; + data->auth_type = 0; + data->secret = 0; + data->sync_support = false; + data->capablity_list = NULL; + data->account_list = NULL; + data->custom_list = NULL; + + _INFO("create_empty_account_instance end"); + + return data; +} + +account_type_s* create_empty_account_type_instance(void) +{ + _INFO("create_empty_account_type_instance start"); + account_type_s *data = (account_type_s*)malloc(sizeof(account_type_s)); + + if (data == NULL) + { + ACCOUNT_ERROR("Memory Allocation Failed"); + return NULL; + } + + ACCOUNT_MEMSET(data, 0, sizeof(account_type_s)); + + data->id = -1; + data->app_id = NULL; + data->service_provider_id = NULL; + data->icon_path = NULL; + data->small_icon_path = NULL; + data->multiple_account_support = false; + data->label_list = NULL; +// data->account_type_list = NULL; + data->provider_feature_list = NULL; + + _INFO("create_empty_account_type_instance end"); + return data; +} + +GSList* unmarshal_account_type_list(GVariant* variant) +{ + _INFO("unmarshal_account_type_list start"); + GSList *list = NULL; + GVariantIter iter; + GVariantIter* iter_row = NULL; + const gchar *key = NULL; + GVariant *value = NULL; + + if (variant == NULL) + { + _ERR("input NULL"); + return NULL; + } + +// gchar* var_type = g_variant_print (variant, TRUE); +// _INFO("var_type = %s", var_type); + + g_variant_iter_init (&iter, variant); + + while (g_variant_iter_loop (&iter, "a{sv}", &iter_row)) + { + account_type_s* account_type = create_empty_account_type_instance(); + + while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) + { + if (!g_strcmp0(key, ACCOUNT_TYPE_DATA_KEY_ID)) + { + account_type->id = g_variant_get_int32(value); + } + else if (!g_strcmp0(key, ACCOUNT_TYPE_DATA_KEY_APP_ID)) + { + account_type->app_id = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_TYPE_DATA_KEY_SERVICE_PROVIDER_ID)) + { + account_type->service_provider_id = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_TYPE_DATA_KEY_ICON_PATH)) + { + account_type->icon_path = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_TYPE_DATA_KEY_SMALL_ICON_PATH)) + { + account_type->small_icon_path = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_TYPE_DATA_KEY_MULTI_SUPPORT)) + { + account_type->multiple_account_support = g_variant_get_int32 (value); + } + else if (!g_strcmp0(key, ACCOUNT_TYPE_DATA_KEY_LABEL_LIST)) + { + account_type->label_list = variant_to_label_list(value); + } + + else if (!g_strcmp0(key, ACCOUNT_TYPE_DATA_KEY_PROVIDER_FEATURE_LIST)) + { + account_type->provider_feature_list = variant_to_provider_feature_list(value); + } + + } + list = g_slist_append (list, account_type); + + } + + _INFO("unmarshal_account_type_list end"); + return list; +} + +GVariant* marshal_account_type(const account_type_s* account_type) +{ + _INFO("marshal_account_type start"); + if (account_type == NULL) + { + _ERR("NULL input"); + return NULL; + } + + const account_type_s* in_data = account_type; + GVariantBuilder builder; + + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + + + if (in_data->app_id != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_TYPE_DATA_KEY_APP_ID, + g_variant_new_string (in_data->app_id)); + } + + if (in_data->service_provider_id != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_TYPE_DATA_KEY_SERVICE_PROVIDER_ID, + g_variant_new_string (in_data->service_provider_id)); + } + + if (in_data->icon_path != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_TYPE_DATA_KEY_ICON_PATH, + g_variant_new_string (in_data->icon_path)); + } + + if (in_data->small_icon_path != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_TYPE_DATA_KEY_SMALL_ICON_PATH, + g_variant_new_string (in_data->small_icon_path)); + } + + if (in_data->multiple_account_support == false) + { + g_variant_builder_add (&builder, "{sv}", ACCOUNT_TYPE_DATA_KEY_MULTI_SUPPORT, + g_variant_new_int32 (0)); + } + else + { + g_variant_builder_add (&builder, "{sv}", ACCOUNT_TYPE_DATA_KEY_MULTI_SUPPORT, + g_variant_new_int32 (1)); + } + + if (in_data->label_list != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_TYPE_DATA_KEY_LABEL_LIST, + label_list_to_variant(in_data->label_list)); + } + + if (in_data->provider_feature_list != NULL) + { + g_variant_builder_add (&builder, "{sv}", + ACCOUNT_TYPE_DATA_KEY_PROVIDER_FEATURE_LIST, + provider_feature_list_to_variant(in_data->provider_feature_list)); + } + + + _INFO("marshal_account_type end"); + + return g_variant_builder_end (&builder); +} + +account_type_s* umarshal_account_type(GVariant* in_data) +{ + _INFO("unmarshal_account_type start"); + if (in_data == NULL) + { + _ERR("Null input"); + return NULL; + } + + account_type_s* account_type = (account_type_s*)calloc(1, sizeof(account_type_s)); + if (account_type == NULL) + { + _ERR("Out of memory"); + return NULL; + } + + GVariantIter iter; + gchar *key = NULL; + GVariant *value = NULL; + + g_variant_iter_init (&iter, in_data); + while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) + { + if (!strcmp(key, ACCOUNT_TYPE_DATA_KEY_APP_ID)) + { + account_type->app_id = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_TYPE_DATA_KEY_SERVICE_PROVIDER_ID)) + { + account_type->service_provider_id = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_TYPE_DATA_KEY_ICON_PATH)) + { + account_type->icon_path = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_TYPE_DATA_KEY_SMALL_ICON_PATH)) + { + account_type->small_icon_path = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!strcmp(key, ACCOUNT_TYPE_DATA_KEY_MULTI_SUPPORT)) + { + account_type->multiple_account_support = g_variant_get_int32 (value); + } + + else if (!strcmp(key, ACCOUNT_TYPE_DATA_KEY_LABEL_LIST)) + { + account_type->label_list = variant_to_label_list(value); + } + + else if (!strcmp(key, ACCOUNT_TYPE_DATA_KEY_PROVIDER_FEATURE_LIST)) + { + account_type->provider_feature_list = variant_to_provider_feature_list(value); + } + + } + //TODO: support for collections + + _INFO("unmarshal_account_type end"); + + return account_type; +} + +GVariant* marshal_account_capability(account_capability_s* capability) +{ + _INFO("marshal_account_capability start"); + + if (capability == NULL) + { + _ERR("Null input"); + return NULL; + } + + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); + + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CAPABILITY_DATA_KEY_ID, g_variant_new_int32(capability->id)); + + if (capability->type != NULL) + { + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CAPABILITY_DATA_KEY_TYPE, g_variant_new_string(capability->type)); + + } + + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CAPABILITY_DATA_KEY_VALUE, g_variant_new_int32(capability->value)); + + if (capability->package_name != NULL) + { + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CAPABILITY_DATA_KEY_PACKAGE_NAME, g_variant_new_string(capability->package_name)); + + } + + if (capability->user_name != NULL) + { + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CAPABILITY_DATA_KEY_USER_NAME, g_variant_new_string(capability->user_name)); + + } + + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CAPABILITY_DATA_KEY_ACC_ID, g_variant_new_int32(capability->account_id)); + + _INFO("marshal_account_capability end"); + + return g_variant_builder_end(&builder); +} + +GVariant* marshal_capability_list(GSList* capability_list) +{ + _INFO("marshal_capability_list start"); + if (capability_list == NULL) + { + _ERR("input NULL."); + return NULL; + } + + GVariantBuilder builder; + account_capability_s *account_capability_data = NULL; + + GSList* iter; + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + + for (iter = capability_list ; iter != NULL; iter = g_slist_next (iter)) + { + account_capability_data = (account_capability_s *) (iter->data); + g_variant_builder_add_value(&builder, marshal_account_capability(account_capability_data)); + } + _INFO("marshal_capability_list end"); + return g_variant_builder_end (&builder); +} + +GVariant* marshal_account_custom(account_custom_s* custom) +{ + _INFO("marshal_account_custom start"); + + if (custom == NULL) + { + _ERR("Null input"); + return NULL; + } + + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); + + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CUSTOM_DATA_KEY_ACC_ID, g_variant_new_int32(custom->account_id)); + + if (custom->app_id != NULL) + { + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CUSTOM_DATA_KEY_APP_ID, g_variant_new_string(custom->app_id)); + } + + if (custom->key != NULL) + { + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CUSTOM_DATA_KEY_KEY, g_variant_new_string(custom->key)); + } + + if (custom->value != NULL) + { + g_variant_builder_add(&builder, "{sv}", + ACCOUNT_CUSTOM_DATA_KEY_VALUE, g_variant_new_string(custom->value)); + } + + _INFO("marshal_account_custom end"); + + return g_variant_builder_end(&builder); +} + +GVariant* marshal_custom_list(GSList* custom_list) +{ + _INFO("marshal_custom_list start"); + if (custom_list == NULL) + { + _ERR("input NULL."); + return NULL; + } + + GVariantBuilder builder; + account_custom_s *account_custom_data = NULL; + + GSList* iter; + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + + for (iter = custom_list ; iter != NULL; iter = g_slist_next (iter)) + { + account_custom_data = (account_custom_s *) (iter->data); + g_variant_builder_add_value(&builder, marshal_account_custom(account_custom_data)); + } + _INFO("marshal_custom_list end"); + return g_variant_builder_end (&builder); +} + +GSList* unmarshal_capability_list(GVariant* variant) +{ + _INFO("unmarshal_capability_list start"); + GSList *list = NULL; + GVariantIter iter; + GVariantIter* iter_row = NULL; + const gchar *key = NULL; + GVariant *value = NULL; + + if (variant == NULL) + { + _ERR("input NULL"); + return NULL; + } + +// gchar* var_type = g_variant_print (variant, TRUE); +// _INFO("var_type = %s", var_type); + + g_variant_iter_init (&iter, variant); + + + while (g_variant_iter_loop (&iter, "a{sv}", &iter_row)) + { + account_capability_s* account_capability = (account_capability_s*)calloc(1, sizeof(account_capability_s)); + + while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) + { + if (!g_strcmp0(key, ACCOUNT_CAPABILITY_DATA_KEY_ID)) + { + account_capability->id = g_variant_get_int32(value); + } + else if (!g_strcmp0(key, ACCOUNT_CAPABILITY_DATA_KEY_TYPE)) + { + account_capability->type = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_CAPABILITY_DATA_KEY_VALUE)) + { + account_capability->value = g_variant_get_int32(value); + } + + else if (!g_strcmp0(key, ACCOUNT_CAPABILITY_DATA_KEY_PACKAGE_NAME)) + { + account_capability->package_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_CAPABILITY_DATA_KEY_USER_NAME)) + { + account_capability->user_name = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_CAPABILITY_DATA_KEY_ACC_ID)) + { + account_capability->account_id = g_variant_get_int32(value); + } + + } + list = g_slist_append (list, account_capability); + } + + _INFO("unmarshal_capability_list end"); + return list; +} + +GSList* unmarshal_custom_list(GVariant* variant) +{ + _INFO("unmarshal_custom_list start"); + GSList *list = NULL; + GVariantIter iter; + GVariantIter* iter_row = NULL; + const gchar *key = NULL; + GVariant *value = NULL; + + if (variant == NULL) + { + _ERR("input NULL"); + return NULL; + } + +// gchar* var_type = g_variant_print (variant, TRUE); +// _INFO("var_type = %s", var_type); + + g_variant_iter_init (&iter, variant); + + while (g_variant_iter_loop (&iter, "a{sv}", &iter_row)) + { + account_custom_s* account_custom = (account_custom_s*)calloc(1, sizeof(account_custom_s)); + + while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) + { + if (!g_strcmp0(key, ACCOUNT_CUSTOM_DATA_KEY_ACC_ID)) + { + account_custom->account_id = g_variant_get_int32(value); + } + else if (!g_strcmp0(key, ACCOUNT_CUSTOM_DATA_KEY_APP_ID)) + { + account_custom->app_id = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_CUSTOM_DATA_KEY_KEY)) + { + account_custom->key = g_strdup(g_variant_get_string (value, NULL)); + } + + else if (!g_strcmp0(key, ACCOUNT_CUSTOM_DATA_KEY_VALUE)) + { + account_custom->value = g_strdup(g_variant_get_string (value, NULL)); + } + } + list = g_slist_append (list, account_custom); + } + + _INFO("unmarshal_custom_list end"); + return list; +} + +GVariant* marshal_user_int_array(const int* user_data_int_array) +{ + int i; + + _INFO("marshal_user_data_int_list start"); + if (user_data_int_array == NULL) + { + _ERR("input NULL."); + return NULL; + } + + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + + for(i = 0; i < USER_INT_CNT; i++) + { + char key[256]; + ACCOUNT_SNPRINTF(key, strlen(ACCOUNT_DATA_KEY_USER_DATA_INT)+3, "%s%d", ACCOUNT_DATA_KEY_USER_DATA_INT, i); + g_variant_builder_add(&builder, "{sv}", + key, + g_variant_new_int32(user_data_int_array[i])); + } + + _INFO("marshal_user_data_int_list end"); + return g_variant_builder_end (&builder); +} + +GVariant* marshal_user_txt_array(char* const* user_data_txt_array) +{ + int i; + bool is_all_null = true; + + _INFO("marshal_user_data_int_list start"); + if (user_data_txt_array == NULL) + { + _ERR("input NULL."); + return NULL; + } + + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + + for(i = 0; i < USER_TXT_CNT; i++) + { + char key[256]; + if (user_data_txt_array[i]) { + ACCOUNT_SNPRINTF(key, strlen(ACCOUNT_DATA_KEY_USER_DATA_TXT)+3, "%s%d", ACCOUNT_DATA_KEY_USER_DATA_TXT, i); + g_variant_builder_add(&builder, "{sv}", + key, + g_variant_new_string(user_data_txt_array[i])); + is_all_null = false; + } + } + + _INFO("marshal_user_data_int_list end"); + + if (is_all_null) { + g_variant_builder_clear (&builder); + return NULL; + } + + return g_variant_builder_end (&builder); +} + +int* unmarshal_user_int_array(GVariant* variant) +{ + _INFO("unmarshal_user_int_array start"); + GVariantIter iter; + const gchar *key = NULL; + char compare_key[USER_INT_CNT][256]; + GVariant *value = NULL; + int* user_data_int; + int i; + + if (variant == NULL) + { + _ERR("input NULL"); + return NULL; + } + +// gchar* var_type = g_variant_print (variant, TRUE); +// _INFO("var_type = %s", var_type); + + g_variant_iter_init (&iter, variant); + + user_data_int = (int*)calloc(USER_INT_CNT, sizeof(int)); + + for(i=0; i<USER_INT_CNT; i++) + { + ACCOUNT_SNPRINTF(compare_key[i], strlen(ACCOUNT_DATA_KEY_USER_DATA_INT)+3, "%s%d", ACCOUNT_DATA_KEY_USER_DATA_INT, i); + } + + while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) + { + for(i=0; i<USER_INT_CNT; i++) + { + if (!g_strcmp0(key, compare_key[i])) + { + user_data_int[i] = g_variant_get_int32(value); + } + } + } + + _INFO("unmarshal_user_int_array end"); + return user_data_int; +} + +char** unmarshal_user_txt_array(GVariant* variant) +{ + _INFO("unmarshal_user_txt_array start"); + GVariantIter iter; + const gchar *key = NULL; + char compare_key[USER_TXT_CNT][256]; + GVariant *value = NULL; + char** user_data_txts; + int i; + + if (variant == NULL) + { + _ERR("input NULL"); + return NULL; + } + +// gchar* var_type = g_variant_print (variant, TRUE); +// _INFO("var_type = %s", var_type); + + g_variant_iter_init (&iter, variant); + + user_data_txts = (char**)calloc(USER_TXT_CNT, sizeof(char*)); + + for(i=0; i<USER_TXT_CNT; i++) + { + ACCOUNT_SNPRINTF(compare_key[i], strlen(ACCOUNT_DATA_KEY_USER_DATA_TXT)+3, "%s%d", ACCOUNT_DATA_KEY_USER_DATA_TXT, i); + } + + while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) + { + for(i=0; i<USER_TXT_CNT; i++) + { + if (!g_strcmp0(key, compare_key[i])) + { + user_data_txts[i] = g_strdup(g_variant_get_string (value, NULL)); + } + } + } + + _INFO("unmarshal_user_txt_array end"); + return user_data_txts; +} diff --git a/packaging/account-common.spec b/packaging/account-common.spec new file mode 100644 index 0000000..2c5b1db --- /dev/null +++ b/packaging/account-common.spec @@ -0,0 +1,69 @@ + +Name: account-common +Summary: Account common library +Version: 0.0.6 +Release: 1 +Group: Social & Content/API +License: Apache-2.0 +Source0: account-common-%{version}.tar.gz + +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(glib-2.0) >= 2.26 +BuildRequires: pkgconfig(gio-unix-2.0) +BuildRequires: python-xml + +Requires(post): /sbin/ldconfig +Requires(post): /usr/bin/sqlite3 +Requires(postun): /sbin/ldconfig + +%description +Account common libraryXB-Public-Package: no + +%package devel +Summary: Development files for %{name} +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +%description devel +Development files for %{name} + +%prep +%setup -q + +%build +#export CFLAGS+=" -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default" +#export CXXFLAGS+=" -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default -Wnon-virtual-dtor -Wno-c++0x-compat" +#export CFLAGS+=" -Wno-unused-parameter -Wno-empty-body" +#export CXXFLAGS+=" -Wno-unused-parameter -Wno-empty-body" + +#export CFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow -fno-common" +#export CXXFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow" + +#export CFLAGS="${CFLAGS} -fPIC -fvisibility=hidden" +export CFLAGS="${CFLAGS} -fPIC" +cmake . -DCMAKE_INSTALL_PREFIX=/usr + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/usr/share/license +cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} +%make_install + +mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants + +rm -rf %{buildroot}/usr/lib/account-common + +%files +%manifest account-common.manifest +%defattr(-,root,root,-) +/usr/share/license/%{name} +%{_libdir}/*.so.* + +%files devel +%defattr(-,root,root,-) +%{_libdir}/*.so +%{_libdir}/pkgconfig/account-common.pc +%{_includedir}/*.h |