{
#endif
+#ifndef ACCOUNT_API
+#define ACCOUNT_API __attribute__ ((visibility("default")))
+#endif
+
/**
* @file account.h
* @brief This file contains the Account API for account management
typedef bool (*account_type_cb)(account_type_h account_type, void *user_data);
typedef bool (*account_label_cb)(char* app_id, char* label, char* locale, void *user_data);
+typedef bool (*provider_feature_cb)(char* app_id, char* key, void* user_data);
+typedef bool (*account_event_cb)(const char* event_type, int account_id, void* user_data);
/**
*
* @see account_disconnect()
*/
-int account_connect(void);
+ACCOUNT_API int account_connect(void);
/**
*
* @see account_connect()
*/
-int account_disconnect(void);
+ACCOUNT_API int account_disconnect(void);
/**
*
* @see account_destroy()
*/
-int account_create(account_h *account);
+ACCOUNT_API int account_create(account_h *account);
/**
*
* @see account_create()
*/
-int account_destroy(account_h account);
+ACCOUNT_API int account_destroy(account_h account);
/**
* @retval #ACCOUNT_ERROR_NONE Successful
* @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #ACCOUNT_ERROR_DB_FAILED Database operation failed
+ * @retval #ACCOUNT_ERROR_DUPLICATED Same user name exist in your application
+ * @retval #ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE when you try to add an account inspite of multiple account false
+ * @retval #ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER when you try to add an account though you didn't register account type in manifest
*
* @pre This function requires an open connection to account service by account_connect().
*
* @see account_update_to_db_by_id()
* @see account_update_to_db_by_user_name()
*/
-int account_insert_to_db(account_h account, int *account_db_id);
+ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id);
/**
* @see account_update_to_db_by_id()
* @see account_update_to_db_by_user_name()
*/
-int account_delete_from_db_by_id(int account_db_id);
+ACCOUNT_API int account_delete_from_db_by_id(int account_db_id);
/**
* @see account_update_to_db_by_id()
* @see account_update_to_db_by_user_name()
*/
-int account_delete_from_db_by_user_name(char *user_name, char *package_name);
+ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name);
/**
* @see account_update_to_db_by_id()
* @see account_update_to_db_by_user_name()
*/
-int account_delete_from_db_by_package_name(char *package_name);
+ACCOUNT_API int account_delete_from_db_by_package_name(char *package_name);
/**
* @see account_delete_from_db_by_package_name()
* @see account_update_to_db_by_user_name()
*/
-int account_update_to_db_by_id(account_h account, int account_id);
+ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id);
/**
* @see account_update_to_db_by_id()
*
*/
-int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name);
+ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name);
/**
* @brief Gets the account id of account.
* @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
*
*/
-int account_get_account_id(account_h account, int *account_id);
+ACCOUNT_API int account_get_account_id(account_h account, int *account_id);
/**
*
* @see account_set_user_name()
*/
-int account_get_user_name(account_h account, char **user_name);
+ACCOUNT_API int account_get_user_name(account_h account, char **user_name);
/**
*
* @see account_get_user_name()
*/
-int account_set_user_name(account_h account, const char *user_name);
+ACCOUNT_API int account_set_user_name(account_h account, const char *user_name);
/**
*
* @see account_get_display_name()
*/
-int account_get_display_name(account_h account, char **display_name);
+ACCOUNT_API int account_get_display_name(account_h account, char **display_name);
/**
*
* @see account_get_display_name()
*/
-int account_set_display_name(account_h account, const char *display_name);
+ACCOUNT_API int account_set_display_name(account_h account, const char *display_name);
/**
* @brief Gets the capability detail of account.
*
* @see account_set_capability()
*/
-int account_get_capability(account_h account, const char* capability_type, account_capability_state_e* capability_value);
+ACCOUNT_API int account_get_capability(account_h account, const char* capability_type, account_capability_state_e* capability_value);
/**
* @brief Gets all the capabilities of account.
*
* @see account_set_capability()
*/
-int account_get_capability_all(account_h account, capability_cb cb_func, void *user_data);
+ACCOUNT_API int account_get_capability_all(account_h account, capability_cb cb_func, void *user_data);
/**
* @brief Sets the capability.
*
* @see account_get_capability()
*/
-int account_set_capability(account_h account, const char* capability_type, account_capability_state_e capability_state);
+ACCOUNT_API int account_set_capability(account_h account, const char* capability_type, account_capability_state_e capability_state);
/**
*
* @see account_set_icon_path()
*/
-int account_get_icon_path(account_h account, char **icon_path);
+ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path);
/**
*
* @see account_get_icon_path()
*/
-int account_set_icon_path(account_h account, const char *icon_path);
+ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path);
/**
*
* @see account_set_domain_name()
*/
-int account_get_domain_name(account_h account, char **domain_name);
+ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name);
/**
*
* @see account_get_domain_name()
*/
-int account_set_domain_name(account_h account, const char *domain_name);
+ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name);
/**
*
* @see account_set_email_address()
*/
-int account_get_email_address(account_h account, char **email_address);
+ACCOUNT_API int account_get_email_address(account_h account, char **email_address);
/**
*
* @see account_get_email_addres()
*/
-int account_set_email_address(account_h account, const char *email_address);
+ACCOUNT_API int account_set_email_address(account_h account, const char *email_address);
/**
*
* @see account_set_package_name()
*/
-int account_get_package_name(account_h account, char **package_name);
+ACCOUNT_API int account_get_package_name(account_h account, char **package_name);
/**
*
* @see account_get_email_addres()
*/
-int account_set_package_name(account_h account, const char *package_name);
+ACCOUNT_API int account_set_package_name(account_h account, const char *package_name);
/**
*
* @see account_set_access_token()
*/
-int account_get_access_token(account_h account, char **access_token);
+ACCOUNT_API int account_get_access_token(account_h account, char **access_token);
/**
*
* @see account_get_access_token()
*/
-int account_set_access_token(account_h account, const char *access_token);
+ACCOUNT_API int account_set_access_token(account_h account, const char *access_token);
/**
*
* @see account_set_user_text()
*/
-int account_get_user_text(account_h account, int user_text_index, char **user_text);
+ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **user_text);
/**
*
* @see account_get_user_text()
*/
-int account_set_user_text(account_h account, int user_text_index, const char *user_text);
+ACCOUNT_API int account_set_user_text(account_h account, int user_text_index, const char *user_text);
/**
*
* @see account_set_user_int()
*/
-int account_get_user_int(account_h account, int user_int_index, int *user_integer);
+ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *user_integer);
/**
*
* @see account_get_user_int()
*/
-int account_set_user_int(account_h account, int user_int_index, int user_integer);
+ACCOUNT_API int account_set_user_int(account_h account, int user_int_index, int user_integer);
/**
*
* @see account_set_auth_type()
*/
-int account_get_auth_type(account_h account, account_auth_type_e *auth_type);
+ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type);
/**
*
* @see account_get_auth_type()
*/
-int account_set_auth_type(account_h account, const account_auth_type_e auth_type);
+ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type);
/**
*
* @see account_set_secret()
*/
-int account_get_secret(account_h account, account_secrecy_state_e *secret);
+ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret);
/**
*
* @see account_get_secret()
*/
-int account_set_secret(account_h account, const account_secrecy_state_e secret);
+ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret);
/**
* @brief Gets the sync support.
*
* @see account_set_sync_support()
*/
-int account_get_sync_support(account_h account, account_sync_state_e *sync_support);
+ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support);
/**
*
* @see account_get_sync_support()
*/
-int account_set_sync_support(account_h account, const account_sync_state_e sync_support);
+ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support);
/**
*
* @see account_set_source()
*/
-int account_get_source(account_h account, char **source);
+ACCOUNT_API int account_get_source(account_h account, char **source);
/**
*
* @see account_get_source()
*/
-int account_set_source(account_h account, const char *source);
+ACCOUNT_API int account_set_source(account_h account, const char *source);
/**
* @brief Sets the capability.
*
* @see account_get_custom()
*/
-int account_set_custom(account_h account, const char* key, const char* value);
+ACCOUNT_API int account_set_custom(account_h account, const char* key, const char* value);
/**
* @brief Gets the user specific custom text of account key.
*
* @see account_set_custom()
*/
-int account_get_custom(account_h account, const char* key, char** value);
+ACCOUNT_API int account_get_custom(account_h account, const char* key, char** value);
/**
*
* @see account_set_custom()
*/
-int account_get_custom_all(account_h account, account_custom_cb cb_func, void* user_data);
+ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb cb_func, void* user_data);
/**
* @brief Retrieves all accounts details by invoking the given callback function iteratively.
* @see account_query_account_by_package_name()
* @see account_query_account_by_capability()
*/
-int account_foreach_account_from_db(account_cb callback, void *user_data);
+ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data);
/**
* @see account_query_account_by_package_name()
* @see account_query_account_by_capability()
*/
-int account_query_account_by_account_id(int account_db_id, account_h *account);
+ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account);
/**
* @brief Retrieves all accounts with the user name.
* @see account_query_account_by_capability()
*
*/
-int account_query_account_by_user_name(account_cb callback, const char* user_name, void* user_data);
+ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char* user_name, void* user_data);
/**
* @brief Retrieves all accounts with the package name.
* @see account_query_account_by_user_name()
* @see account_query_account_by_capability()
*/
-int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data);
+ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data);
/**
- * @brief Retrieves all accounts with the capability.
+ * @brief Retrieves all accounts with the capability type and capability value.
*
* @param[in] callback The callback function to invoke
* @param[in] capability_type The capablity type to search
* @see account_query_account_by_user_name()
* @see account_query_account_by_package_name()
*/
-int account_query_account_by_capability(account_cb callback, const char* capability_type, account_capability_state_e capability_value, void *user_data);
+ACCOUNT_API int account_query_account_by_capability(account_cb callback, const char* capability_type, account_capability_state_e capability_value, void *user_data);
+
+/**
+ * @brief Retrieves all accounts with the capability type.
+ *
+ * @param[in] callback The callback function to invoke
+ * @param[in] capability_type The capablity type to search
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ACCOUNT_ERROR_DB_FAILED Database operation failed
+ *
+ * @pre This function requires an open connection to account service by account_connect().
+ * @post This function invokes account_cb().
+ *
+ * @see account_connect()
+ * @see account_foreach_account_from_db()
+ * @see account_query_account_by_account_id()
+ * @see account_query_account_by_user_name()
+ * @see account_query_account_by_package_name()
+ */
+ACCOUNT_API int account_query_account_by_capability_type(account_cb cb_func, const char* capability_type, void* user_data);
/**
* @brief Retrieves all capabilities with the account database ID.
* @see account_get_capability()
* @see account_set_capability()
*/
-int account_query_capability_by_account_id(capability_cb callback, int account_db_id, void *user_data);
+ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_db_id, void *user_data);
/**
*
* @see account_connect()
*/
-int account_get_total_count_from_db(int *count);
+ACCOUNT_API int account_get_total_count_from_db(int *count);
/**
* @brief changes sync status of account by account id
*
* @see account_connect()
*/
-int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status);
+ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status);
/**
* @brief Called once for each service provider of account
* @post This function invokes service_list_cb().
*
*/
-int account_query_service_list_by_capability(service_list_cb callback, const char* capability_type, void *user_data);
+ACCOUNT_API int account_query_service_list_by_capability(service_list_cb callback, const char* capability_type, void *user_data);
/**
* @retval #ACCOUNT_ERROR_XML_FILE_NOT_FOUND XML file not found
*
*/
-int account_get_application_capability_support(char *package_name, char *capability_filter, bool *supported);
+ACCOUNT_API int account_get_application_capability_support(char *package_name, char *capability_filter, bool *supported);
/**
* @retval #ACCOUNT_ERROR_XML_FILE_NOT_FOUND XML file not found
*
*/
-int account_get_application_multiple_account_support(char * package_name, bool * supported);
+ACCOUNT_API int account_get_application_multiple_account_support(char * package_name, bool * supported);
/**
* @brief Get application's icon path.
* @retval #ACCOUNT_ERROR_XML_FILE_NOT_FOUND XML file not found
*
*/
-int account_get_application_icon_path(char *package_name, char **icon_path);
+ACCOUNT_API int account_get_application_icon_path(const char *package_name, char **icon_path);
/* Account type API */
*
* @see account_type_destroy()
*/
-int account_type_create(account_type_h *account_type);
+ACCOUNT_API int account_type_create(account_type_h *account_type);
/**
* @brief Destroys the account type handle and releases all its resources.
*
* @see account_type_create()
*/
-int account_type_destroy(account_type_h account_type);
+ACCOUNT_API int account_type_destroy(account_type_h account_type);
/**
* @brief Sets the app id. It should be filled with your application id. e.g) com.tizen.testapp
*
* @see account_type_get_app_id()
*/
-int account_type_set_app_id(account_type_h account_type, const char *app_id);
+ACCOUNT_API int account_type_set_app_id(account_type_h account_type, const char *app_id);
/**
* @brief Sets the service provider id. It should be filled with your service provider id.
*
* @see account_type_get_service_provider_id()
*/
-int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id);
+ACCOUNT_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id);
/**
* @brief Sets icon path. It represents your service provider or application.
*
* @see account_type_get_icon_path()
*/
-int account_type_set_icon_path(account_type_h account_type, const char *icon_path);
+ACCOUNT_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path);
/**
* @brief Sets small icon path. It also represents your service provider or application.
*
* @see account_type_get_small_icon_path()
*/
-int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path);
+ACCOUNT_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path);
/**
* @brief Sets multiple account. It represents whether your application support multiple accounts or not.
*
* @see account_type_get_multiple_account_support()
*/
-int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support);
+ACCOUNT_API int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support);
/**
* @brief Sets label and locale. Label represents the name of account type.
*
* @see account_type_get_label()
*/
-int account_type_set_label(account_type_h account_type, const char* label, const char* locale);
+ACCOUNT_API int account_type_set_label(account_type_h account_type, const char* label, const char* locale);
+
+/**
+ * @brief Sets the provider feature.
+ *
+ * @param[in] account_type The account type handle
+ * @param[in] provider_feature This will be capability key of account
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see account_set_capability()
+ */
+ACCOUNT_API int account_type_set_provider_feature(account_type_h account_type, const char* provider_feature);
+
+/**
+ * @brief Retrieves provider feature information with your applicaiton id.
+ *
+ * @param[in] cb_func Callback function will carry provider feature name of app id.
+ * @param[in] app_id Your application ID to search
+ * @param[in] user_data User data if you have your private data to carry into callback function, you can use.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ACCOUNT_ERROR_DB_FAILED Database operation failed
+ *
+ * @pre This function requires an open connection to account service by account_connect().
+ *
+ * @see account_connect()
+ * @see account_type_set_provider_feature()
+ * @see account_disconnect()
+ */
+ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb cb_func, const char* app_id, void *user_data );
+
+/**
+ * @brief Retrieves label information with your applicaiton id.
+ *
+ * @param[in] cb_func Callback function will carry provider feature name of app id.
+ * @param[in] app_id Your application ID to search
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval TRUE means the application supports the given capability
+ * @retval FALSE means the application does not support the given capability
+ *
+ * @pre This function requires an open connection to account service by account_connect().
+ *
+ * @see account_connect()
+ * @see account_type_set_provider_feature()
+ * @see account_disconnect()
+ */
+ACCOUNT_API bool account_type_query_supported_feature(const char* app_id, const char* capability);
/**
* @brief Gets the application id of account type.
* @see account_type_query_by_app_id()
* @see account_type_set_app_id()
*/
-int account_type_get_app_id(account_type_h account_type, char **app_id);
+ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id);
/**
* @brief Gets the service provider id of account type.
* @see account_type_query_by_app_id()
* @see account_type_set_service_provider_id()
*/
-int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id);
+ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id);
/**
* @brief Gets icon path of account type.
* @see account_type_query_by_app_id()
* @see account_type_set_icon_path()
*/
-int account_type_get_icon_path(account_type_h account_type, char **icon_path);
+ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path);
/**
* @brief Gets small icon path of account type.
* @see account_type_query_by_app_id()
* @see account_type_set_small_icon_path()
*/
-int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path);
+ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path);
/**
* @brief Gets small icon path of account type.
* @see account_type_query_by_app_id()
* @see account_type_set_small_icon_path()
*/
-int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support);
+ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support);
+
+/**
+ * @brief Retrieves provider feature information with the given account_type_h.
+ *
+ * @param[in] account_type The account type handle. It should be given by account_type_query_* functions or account_type_foreach_account_type_from_db
+ * @param[in] cb_func Callback function will carry provider feature name of app id.
+ * @param[in] user_data User data if you have your private data to carry into callback function, you can use.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ACCOUNT_ERROR_DB_FAILED Database operation failed
+ *
+ * @pre This function requires an open connection to account service by account_connect().
+ *
+ * @see account_connect()
+ * @see account_type_set_provider_feature()
+ * @see account_disconnect()
+ */
+ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb cb_func, void* user_data);
/**
* @brief Gets the label information detail of account type.
* @see account_type_query_by_app_id()
* @see account_type_set_label()
*/
-int account_type_get_label(account_type_h account_type, account_label_cb cb_func, void *user_data);
+ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb cb_func, void *user_data);
/**
* @brief Inserts the account type details to the database.
* @see account_type_update_to_db_by_app_id()
* @see account_disconnect()
*/
-int account_type_insert_to_db(account_type_h account_type, int* account_type_id);
+ACCOUNT_API int account_type_insert_to_db(account_type_h account_type, int* account_type_id);
/**
* @brief Updates the account details to the account database.
* @see account_type_delete_by_app_id()
* @see account_disconnect()
*/
-int account_type_update_to_db_by_app_id(const account_type_h account_type, const char* app_id);
+ACCOUNT_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char* app_id);
/**
* @brief Deletes the account type from the account database by application id.
* @see account_type_update_to_db_by_app_id()
* @see account_disconnect()
*/
-int account_type_delete_by_app_id(const char* app_id);
+ACCOUNT_API int account_type_delete_by_app_id(const char* app_id);
/**
* @brief Retrieves label information with your applicaiton id.
* @see account_type_foreach_account_type_from_db()
* @see account_disconnect()
*/
-int account_type_query_label_by_app_id(account_label_cb cb_func, const char* app_id, void *user_data );
+ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb cb_func, const char* app_id, void *user_data );
/**
* @brief Retrieves account type information with your applicaiton id.
* @retval #ACCOUNT_ERROR_NONE Successful
* @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #ACCOUNT_ERROR_DB_FAILED Database operation failed
+ * @retval #ACCOUNT_ERROR_RECORD_NOT_FOUND query data is not exist
*
* @pre This function requires an open connection to account service by account_connect().
*
* @see account_type_get_label()
* @see account_type_destroy()
*/
-int account_type_query_by_app_id(const char* app_id, account_type_h *account_type);
+ACCOUNT_API int account_type_query_by_app_id(const char* app_id, account_type_h *account_type);
/**
* @brief Retrieves all account type information with your applicaiton id.
* @see account_type_get_label()
* @see account_type_destroy()
*/
-int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data);
+ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data);
/**
* @brief Retrieves all account type information with your applicaiton id.
*
* @see account_connect()
*/
-int account_type_query_label_by_locale(const char* app_id, const char* locale, char** label);
+ACCOUNT_API int account_type_query_label_by_locale(const char* app_id, const char* locale, char** label);
+
+/**
+ * @brief Retrieves account type information with provider feature name.
+ *
+ * @param[in] cb_func callback function to retrieve account type information
+ * @param[in] key provider feature value to search account type . e.g) ACCOUNT_SUPPORTS_CAPABILITY_CONTACT or "http://tizen.org/account/capability/contact"
+ * @param[out] account_type_h handle corresponding provider feature name.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ACCOUNT_ERROR_DB_FAILED Database operation failed
+ *
+ * @pre This function requires an open connection to account service by account_connect().
+ *
+ * @see account_connect()
+ */
+ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb cb_func, const char* key, void* user_data);
+
+/**
+ * @brief Check account type db whether the given app_id exists.
+ *
+ * @param[in] app_id application id to check
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_RECORD_NOT_FOUND record not found
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER invalid app id
+ *
+ * @pre This function requires an open connection to account service by account_connect().
+ *
+ * @see account_type_query_by_app_id()
+ */
+ACCOUNT_API int account_type_query_app_id_exist(const char* app_id);
+
+
/* End of account type api */
/**
+ * @brief Creates a handle for account event subscription.
+ *
+ * @remarks @a account_subscribe handle must be released with account_unsubscribe_notification() by you. \n
+ *
+ * @param[in] account_subscribe The account subscription handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_OUT_OF_MEMORY Out of Memory
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see account_unsubscribe_notification()
+ * @see account_subscribe_notification()
+ */
+ACCOUNT_API int account_subscribe_create(account_subscribe_h* account_subscribe);
+
+/**
+ * @brief Start to subscribe account event through the given callback function
+ *
+ * @param[in] account_subscribe The account subscription handle
+ * @param[in] cb_func When an account is removed from account database. It will be called with event message and account id.
+ * @param[in] user_data user_data will be delivered to cb_func
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL Subscription fail
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see account_unsubscribe_notification()
+ * @see account_subscribe_notification()
+ */
+ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb cb_func, void* user_data);
+
+/**
+ * @brief Destroys the account subscribe handle and releases all its resources.
+ *
+ * @remarks @account_unsubscribe_notification must be called when you don't need to subscribe account event \n
+ *
+ * @param[in] account_subscribe The account subscription handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACCOUNT_ERROR_NONE Successful
+ * @retval #ACCOUNT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL Unsubscription fail
+ *
+ * @see account_create()
+ */
+ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe);
+
+/**
* @}
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <fcntl.h>
#include <account.h>
#include <glib.h>
#include <db-util.h>
#include <vconf.h>
#include <app.h>
+#define ACCOUNT_VERIFY
+#ifdef ACCOUNT_VERIFY
+#include <pkgmgr-info.h>
+#include <aul.h>
+#include <unistd.h>
+
+#define EAS_CMDLINE "/usr/bin/eas-engine"
+#define EMAIL_SERVICE_CMDLINE "/usr/bin/email-service"
+#define ACTIVESYNC_APPID "activesync-ui"
+#define EMAIL_APPID "email-setting-efl"
+#endif
+
static sqlite3* g_hAccountDB = NULL;
static int g_refCntDB = 0;
pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
static int _account_insert_custom(account_s *account, int account_id);
static int _account_update_custom(account_s *account, int account_id);
static int _account_query_custom_by_account_id(account_custom_cb cb_func, int account_id, void *user_data );
+static int _account_type_update_provider_feature(account_type_s *account_type, const char* app_id);
+
+#ifdef ACCOUNT_VERIFY
+int _account_get_current_appid_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ int ret = -1;
+ char* appid = NULL;
+ char* item = NULL;
+ GSList** appid_list = (GSList**)user_data;
+
+ ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ item = _account_get_text(appid);
+ *appid_list = g_slist_append(*appid_list, item);
+
+ return 0;
+}
+
+static inline int __read_proc(const char *path, char *buf, int size)
+{
+ int fd = 0, ret = 0;
+
+ if (buf == NULL || path == NULL) {
+ ACCOUNT_ERROR("path and buffer is mandatory\n");
+ return -1;
+ }
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ ACCOUNT_ERROR("fd open error(%d)\n", fd);
+ return -1;
+ }
+
+ ret = read(fd, buf, size - 1);
+ if (ret <= 0) {
+ ACCOUNT_ERROR("fd read error(%d)\n", fd);
+ close(fd);
+ return -1;
+ } else
+ buf[ret] = 0;
+
+ close(fd);
+
+ return ret;
+}
+
+char *_account_get_proc_cmdline_bypid(int pid)
+{
+ char buf[128];
+ int ret = 0;
+
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+ ret = __read_proc(buf, buf, sizeof(buf));
+ if (ret <= 0) {
+ ACCOUNT_INFO("No proc directory (%d)\n", pid);
+ return NULL;
+ }
+
+ return strdup(buf);
+}
+
+
+static char* _account_get_current_appid()
+{
+ int pid=0, ret=-1;
+ char appid[128]={0,};
+ pkgmgrinfo_appinfo_h ahandle=NULL;
+ char* appid_ret = NULL;
+
+ pid = getpid();
+ ACCOUNT_INFO("pid (%d)\n", pid, ret);
+ ret = aul_app_get_appid_bypid(pid, appid, sizeof(appid));
+ ACCOUNT_INFO("appid (%s) ret(%d)!!!!!!\n", appid, ret);
+
+ /* SLP platform core exception */
+ if(strlen(appid) == 0){
+ char* cmdline = NULL;
+ cmdline = _account_get_proc_cmdline_bypid(pid);
+ ACCOUNT_INFO("cmdline (%s)!!!!!!\n", cmdline);
+ if(!strcmp(cmdline, EAS_CMDLINE)) {
+ appid_ret = _account_get_text(ACTIVESYNC_APPID);
+ return appid_ret;
+ } else if (!strcmp(cmdline, EMAIL_SERVICE_CMDLINE)) {
+ appid_ret = _account_get_text(EMAIL_APPID);
+ return appid_ret;
+ } else {
+ ACCOUNT_ERROR("No app id\n");
+ return NULL;
+ }
+ }
+
+ appid_ret = _account_get_text(appid);
+
+ pkgmgrinfo_appinfo_destroy_appinfo(ahandle);
+ return appid_ret;
+}
+
+static bool _account_verify_permission(const char* appid)
+{
+ bool b_ret = FALSE;
+ int ret=-1;
+ pkgmgrinfo_appinfo_h ahandle=NULL;
+ pkgmgrinfo_pkginfo_h phandle=NULL;
+ char* package_id;
+ GSList* appid_list = NULL;
+ GSList* iter = NULL;
+
+ char* current_appid = _account_get_current_appid();
+
+ if(current_appid == NULL) {
+ // assuming current process is slp core daemon
+ ACCOUNT_DEBUG("current app id is null\n");
+ return FALSE;
+ }
+
+ /* Get app id family which is stored in account database */
+ ret = pkgmgrinfo_appinfo_get_appinfo(appid, &ahandle);
+ ACCOUNT_INFO("ahandle (%p), ret(%x)\n", ahandle, ret);
+ ret = pkgmgrinfo_appinfo_get_pkgid(ahandle, &package_id);
+ ACCOUNT_INFO("package_id (%s), ret(%x)\n", package_id, ret);
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(package_id, &phandle);
+ ACCOUNT_INFO("phandle (%p), ret(%x)\n", package_id, ret);
+
+ ret = pkgmgrinfo_appinfo_get_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list); //==> pkgÇڵ鿡 ¼ÓÇÑ ui-appid ¸ðµÎ ãÀ½
+ ACCOUNT_INFO("ret(%x)\n", ret);
+
+ /* Compare current app id with the stored app id family */
+ for(iter=appid_list;iter!=NULL;iter=g_slist_next(iter)){
+ char* tmp = (char*)iter->data;
+ if(tmp && !strcmp(tmp, current_appid)) {
+ ACCOUNT_INFO("permission verified appid(%s), current appid(%s)\n", tmp, current_appid);
+ b_ret = TRUE;
+ }
+ ACCOUNT_DEBUG("owner group app id(%s), current appid(%s)\n", tmp, current_appid);
+ _ACCOUNT_FREE(tmp);
+ }
+
+ g_slist_free(appid_list);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(phandle);
+ pkgmgrinfo_appinfo_destroy_appinfo(ahandle);
+
+ _ACCOUNT_FREE(current_appid);
+
+ return b_ret;
+
+}
+#endif
static const char *_account_db_err_msg()
{
return ACCOUNT_ERROR_NONE;
}
+static bool _account_check_add_more_account(const char* app_id)
+{
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+
+ ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_DEBUG("app id (%s)\n", app_id);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s' and MultipleAccountSupport = 1", ACCOUNT_TYPE_TABLE, app_id);
+ rc = _account_get_record_count(query);
+
+ ACCOUNT_DEBUG("app id (%s) supports multiple account. rc(%d)\n", app_id, rc);
+
+ /* multiple account support case */
+ if(rc > 0) {
+ ACCOUNT_DEBUG("app id (%s) supports multiple account. rc(%d)\n", app_id, rc);
+ return TRUE;
+ }
+
+ /* multiple account not support case */
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE package_name = '%s'", ACCOUNT_TABLE, app_id);
+ rc = _account_get_record_count(query);
+
+ if(rc <= 0) {
+ ACCOUNT_DEBUG("app id (%s) supports single account. and there is no account of the app id\n", app_id);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static int _account_create_all_tables(void)
{
int rc = -1;
ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", query, rc, _account_db_err_msg()));
}
+ /* Create account feature table */
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", PROVIDER_FEATURE_TABLE);
+ rc = _account_get_record_count(query);
+ if (rc <= 0) {
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), PROVIDER_FEATURE_SCHEMA, PROVIDER_FEATURE_TABLE);
+ ACCOUNT_INFO("Create %s table", PROVIDER_FEATURE_TABLE);
+ rc = _account_execute_query(query);
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", query, rc, _account_db_err_msg()));
+ }
+
return error_code;
}
ACCOUNT_VERBOSE("_account_check_is_all_table_exists");
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s')",
- ACCOUNT_TABLE, CAPABILITY_TABLE);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s', '%s', '%s', '%s', '%s')",
+ ACCOUNT_TABLE, CAPABILITY_TABLE, ACCOUNT_CUSTOM_TABLE, ACCOUNT_TYPE_TABLE, LABEL_TABLE, PROVIDER_FEATURE_TABLE);
rc = _account_get_record_count(query);
+
+ ACCOUNT_DEBUG("Table count = %d\n", rc);
+
if (rc != ACCOUNT_TABLE_TOTAL_COUNT) {
- ACCOUNT_INFO("Table count is not matched rc=%d\n", rc);
+ ACCOUNT_ERROR("Table count is not matched rc=%d\n", rc);
return FALSE;
}
static int _account_db_open(void)
{
int rc = 0;
- bool is_success = false;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_RETURN_VAL((rc == SQLITE_OK), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", rc));
g_refCntDB++;
- is_success = true;
ACCOUNT_INFO("_account_db_open: The database connected. refcnt=%d ", g_refCntDB);
} else {
g_refCntDB++;
- is_success = true;
ACCOUNT_INFO("The database already connected. refcnt=%d ", g_refCntDB);
}
return ACCOUNT_ERROR_NONE;
}
-int account_connect (void)
+ACCOUNT_API int account_connect (void)
{
return _account_connect();
}
return error_code;
}
-int account_disconnect (void)
+ACCOUNT_API int account_disconnect (void)
{
return _account_disconnect();
}
_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_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s where user_name='%s' and domain_name='%s'"
- , ACCOUNT_TABLE, data->user_name, data->domain_name);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s where user_name='%s' and package_name='%s'"
+ , ACCOUNT_TABLE, data->user_name, data->package_name);
count = _account_get_record_count(query);
if (count > 0) {
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
+#ifdef ACCOUNT_VERIFY
+ char* appid = NULL;
+ appid = _account_get_current_appid();
+
+ if(appid) {
+ //replace appid to account->package_name
+ _ACCOUNT_FREE(account->package_name);
+ account->package_name = _account_get_text(appid);
+ _ACCOUNT_FREE(appid);
+ }else {
+ // API caller cannot be recognized
+ ACCOUNT_ERROR("APP ID not detectable!\n");
+ return ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+#else
if (!account->package_name) {
ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
return ACCOUNT_ERROR_INVALID_PARAMETER;
}
+#endif
+
+ /* check whether app id exist in account type db */
if (!account->user_name && !account->display_name && !account->email_address) {
ACCOUNT_ERROR("Mandetory fields is NULL. At least one field is required among username, display name, email address\n");
return ACCOUNT_ERROR_INVALID_PARAMETER;
}
+ /* Check account own icon existence */
+ if(!account->icon_path) {
+ char* temptxt = NULL;
+ account_type_h account_type = NULL;
+ error_code = account_type_create(&account_type);
+ error_code = account_type_query_by_app_id((const char*)account->package_name, &account_type);
+ error_code = account_type_get_icon_path(account_type, &temptxt);
+ if (error_code != ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("account_type_get_icon_path: Failed \n");
+ } else if (temptxt && strlen(temptxt)) {
+ ACCOUNT_DEBUG("icon path (%s) app_id(%s) \n", temptxt, account->package_name);
+ account->icon_path = _account_get_text(temptxt);
+ } else {
+ ACCOUNT_DEBUG("account_get_icon_path: returned NULL \n");
+ }
+ _ACCOUNT_FREE(temptxt);
+ error_code = account_type_destroy(account_type);
+ }
+
+ /* End of Check account own icon existence */
+
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s( user_name, email_address , display_name , icon_path , source , package_name , "
"access_token , domain_name , auth_type , secret , sync_support , txt_custom0, txt_custom1, txt_custom2, txt_custom3, txt_custom4, "
for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
int rc, ret;
count = 1;
+
+ account_capability_s* cap_data = NULL;
+ cap_data = (account_capability_s*)iter->data;
+
+ ACCOUNT_VERBOSE("cap_data->type = %s, cap_data->value = %d \n", cap_data->type, cap_data->value);
+
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
"(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
-
hstmt = _account_prepare_query(query);
ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
- account_capability_s* cap_data = NULL;
- cap_data = (account_capability_s*)iter->data;
- ACCOUNT_VERBOSE("cap_data->type = %d, cap_data->value = %d \n", cap_data->type, cap_data->value);
-
ret = _account_query_bind_text(hstmt, count++, cap_data->type);
ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
ret = _account_query_bind_int(hstmt, count++, cap_data->value);
return (char *)sqlite3_column_text(pStmt, pos);
}
-static void _account_db_data_to_text(char *textbuf, char **output)
+static void _account_db_data_to_text(const char *textbuf, char **output)
{
if (textbuf && strlen(textbuf)>0) {
if (*output) {
*output = NULL;
}
*output = strdup(textbuf);
- } else {
- ACCOUNT_WARNING("_account_db_data_to_text : no text");
}
}
data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
- ACCOUNT_VERBOSE("_account_get_capability_text_cb :: %d\n", capability_type);
+ ACCOUNT_VERBOSE("_account_get_capability_text_cb :: %s\n", capability_type);
return TRUE;
}
return text_value;
}
+static int _account_compare_old_record_by_user_name(account_s *new_account, const char* user_name, const char* package_name)
+{
+ int error_code = ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ account_s *old_account = NULL;
+
+ ACCOUNT_RETURN_VAL((new_account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
+ ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+ old_account = (account_s*)calloc(1, sizeof(account_s));
+ if(!old_account) {
+ ACCOUNT_FATAL("Memory alloc fail\n");
+ return ACCOUNT_ERROR_OUT_OF_MEMORY;
+ }
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = '%s' and package_name='%s'", ACCOUNT_TABLE, user_name, package_name);
+ hstmt = _account_prepare_query(query);
+
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ while (rc == SQLITE_ROW) {
+ _account_convert_column_to_account(hstmt, old_account);
+ ACCOUNT_VERBOSE("get account info by id %p\n", old_account);
+ rc = _account_query_step(hstmt);
+ }
+
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+
+ // get capability
+ error_code = account_query_capability_by_account_id(_account_get_capability_text_cb, old_account->id, (void*)old_account);
+ ACCOUNT_CATCH_ERROR((error_code == ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
+
+ // get custom text
+ error_code = _account_query_custom_by_account_id(_account_get_custom_text_cb, old_account->id, (void*)old_account);
+ ACCOUNT_CATCH_ERROR((error_code == ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
+
+ // compare
+ new_account->id = old_account->id;
+
+ //user name
+ if(!new_account->user_name) {
+ if(old_account->user_name)
+ new_account->user_name = _account_get_text(old_account->user_name);
+ }
+
+ // display name
+ if(!new_account->display_name) {
+ if(old_account->display_name)
+ new_account->display_name = _account_get_text(old_account->display_name);
+ }
+
+ // email address
+ if(!new_account->email_address) {
+ if(old_account->email_address)
+ new_account->email_address = _account_get_text(old_account->email_address);
+ }
+
+ // domain name
+ if(!new_account->domain_name) {
+ if(old_account->domain_name)
+ new_account->domain_name = _account_get_text(old_account->domain_name);
+ }
+
+ // icon path
+ if(!new_account->icon_path) {
+ if(old_account->icon_path)
+ new_account->icon_path = _account_get_text(old_account->icon_path);
+ }
+
+ // source
+ if(!new_account->source) {
+ if(old_account->source)
+ new_account->source = _account_get_text(old_account->source);
+ }
+
+#ifndef ACCOUNT_VERIFY
+ // package name
+ if(!new_account->package_name) {
+ if(old_account->package_name)
+ new_account->package_name = _account_get_text(old_account->package_name);
+ }
+#endif
+
+ // access token
+ if(!new_account->access_token) {
+ if(old_account->access_token)
+ new_account->access_token = _account_get_text(old_account->access_token);
+ }
+
+ // user text
+ int i;
+ for(i=0;i<USER_TXT_CNT;i++) {
+ if(!new_account->user_data_txt[i]) {
+ if(old_account->user_data_txt[i])
+ new_account->user_data_txt[i] = _account_get_text(old_account->user_data_txt[i]);
+ }
+ }
+
+ // auth type
+ if(new_account->auth_type == ACCOUNT_AUTH_TYPE_INVALID) {
+ new_account->auth_type = old_account->auth_type;
+ }
+
+ //secret
+ if(new_account->secret== ACCOUNT_SECRECY_INVALID) {
+ new_account->secret = old_account->secret;
+ }
+
+ // sync support
+ if(new_account->sync_support == ACCOUNT_SYNC_INVALID) {
+ new_account->sync_support = old_account->sync_support;
+ }
+
+ // user int
+ for(i=0;i<USER_INT_CNT;i++) {
+ if(new_account->user_data_int[i] == 0) {
+ new_account->user_data_int[i] = old_account->user_data_int[i];
+ }
+ }
+
+ // capability
+
+ // user custom table
+
+
+
+ CATCH:
+ if (hstmt != NULL) {
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+ }
+
+ if (old_account) {
+ _account_free_account_items(old_account);
+ _ACCOUNT_FREE(old_account);
+ }
+
+ return ACCOUNT_ERROR_NONE;
+}
+
+
+
static int _account_update_account_by_user_name(account_s *account, char *user_name, char *package_name)
{
int rc = 0, binding_count = 0, count = 0;
ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is NULL.\n"));
ACCOUNT_RETURN_VAL((package_name!= NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is NULL.\n"));
+ _account_compare_old_record_by_user_name(account, user_name, package_name);
+
if (!account->user_name && !account->display_name && !account->email_address) {
ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
return ACCOUNT_ERROR_INVALID_PARAMETER;
}
+
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE user_name='%s' and package_name='%s'"
, ACCOUNT_TABLE, user_name, package_name);
/*update capability*/
error_code = _account_update_capability_by_user_name(account, user_name, package_name);
+ /* update custom */
+ error_code = _account_update_custom(account, account->id);
+
return error_code;
}
-int account_insert_to_db(account_h account, int *account_id)
+ACCOUNT_API int account_insert_to_db(account_h account, int *account_id)
{
int error_code = ACCOUNT_ERROR_NONE;
+ int ret_transaction = 0;
ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
pthread_mutex_lock(&account_mutex);
+ /* transaction control required*/
+ ret_transaction = _account_begin_transaction();
+
+ if (ret_transaction != ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return ret_transaction;
+ }
+
if (_account_check_duplicated(data)) {
- error_code = ACCOUNT_ERROR_DUPLICATED;
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("Duplicated, rollback insert query(%x)!!!!\n", ret_transaction);
+ *account_id = -1;
+ pthread_mutex_unlock(&account_mutex);
+ return ACCOUNT_ERROR_DUPLICATED;
} else {
*account_id = _account_get_next_sequence(ACCOUNT_TABLE);
- error_code = _account_execute_insert_query(data);
+ if(account_type_query_app_id_exist(data->package_name) != ACCOUNT_ERROR_NONE) {
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("App id is not registered in account type DB, transaction ret (%x)!!!!\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
+ }
- if (error_code != ACCOUNT_ERROR_NONE)
+ if(!_account_check_add_more_account(data->package_name)) {
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("No more account cannot be added, transaction ret (%x)!!!!\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE;
+ }
+
+ error_code = _account_execute_insert_query(data);
+
+ if (error_code != ACCOUNT_ERROR_NONE) {
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("INSERT account fail, rollback insert query(%x)!!!!\n", ret_transaction);
*account_id = -1;
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+ }
}
ACCOUNT_VERBOSE( "_account_execute_insert_query, insert error_code : %d", error_code);
- _account_insert_capability(data, *account_id);
- _account_insert_custom(data, *account_id);
+ error_code = _account_insert_capability(data, *account_id);
+ if (error_code != ACCOUNT_ERROR_NONE) {
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("INSERT capability fail, rollback insert capability query(%x)!!!!\n", ret_transaction);
+ *account_id = -1;
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+ }
+
+ error_code = _account_insert_custom(data, *account_id);
+ if (error_code != ACCOUNT_ERROR_NONE) {
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("INSERT custom fail, rollback insert capability query(%x)!!!!\n", ret_transaction);
+ *account_id = -1;
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+ }
pthread_mutex_unlock(&account_mutex);
- _account_insert_delete_update_notification_send(ACCOUNT_NOTI_NAME_INSERT);
+
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_INSERT, *account_id);
+ _account_insert_delete_update_notification_send(buf);
+
+ _account_end_transaction(TRUE);
return ACCOUNT_ERROR_NONE;
}
-int account_create(account_h *account)
+ACCOUNT_API int account_create(account_h *account)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_user_name(account_h account, const char *user_name)
+ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_display_name(account_h account, const char *display_name)
+ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_email_address(account_h account, const char *email_address)
+ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_icon_path(account_h account, const char *icon_path)
+ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_source(account_h account, const char *source)
+ACCOUNT_API int account_set_source(account_h account, const char *source)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_package_name(account_h account, const char *package_name)
+ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_domain_name(account_h account, const char *domain_name)
+ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_access_token(account_h account, const char *access_token)
+ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_user_text(account_h account, int index, const char *user_txt)
+ACCOUNT_API int account_set_user_text(account_h account, int index, const char *user_txt)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_custom(account_h account, const char* key, const char* value)
+ACCOUNT_API int account_set_custom(account_h account, const char* key, const char* value)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
+ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
return ACCOUNT_ERROR_NONE;
}
-int account_set_secret(account_h account, const account_secrecy_state_e secret)
+ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
return ACCOUNT_ERROR_NONE;
}
-int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
+ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
return ACCOUNT_ERROR_NONE;
}
-int account_set_user_int(account_h account, int index, const int user_int)
+ACCOUNT_API int account_set_user_int(account_h account, int index, const int user_int)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_set_capability(account_h account, const char* capability_type, account_capability_state_e capability_value)
+ACCOUNT_API int account_set_capability(account_h account, const char* capability_type, account_capability_state_e capability_value)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account handle is null"));
ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is null"));
return ACCOUNT_ERROR_NONE;
}
-int account_get_user_name(account_h account, char **user_name)
+ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_display_name(account_h account, char **display_name)
+ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_email_address(account_h account,char **email_address)
+ACCOUNT_API int account_get_email_address(account_h account,char **email_address)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_icon_path(account_h account, char **icon_path)
+ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_source(account_h account, char **source)
+ACCOUNT_API int account_get_source(account_h account, char **source)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_package_name(account_h account, char **package_name)
+ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_domain_name(account_h account, char **domain_name)
+ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_access_token(account_h account, char **access_token)
+ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_user_text(account_h account, int user_text_index, char **text)
+ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **text)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
+ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_secret(account_h account, account_secrecy_state_e *secret)
+ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
+ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_account_id(account_h account, int *account_id)
+ACCOUNT_API int account_get_account_id(account_h account, int *account_id)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_user_int(account_h account, int user_int_index, int *integer)
+ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
{
if (!account) {
ACCOUNT_ERROR("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_get_capability(account_h account, const char* capability_type, account_capability_state_e* capability_value)
+ACCOUNT_API int account_get_capability(account_h account, const char* capability_type, account_capability_state_e* capability_value)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is NULL"));
return ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
-int account_get_capability_all(account_h account, capability_cb cb_func, void *user_data)
+ACCOUNT_API int account_get_capability_all(account_h account, capability_cb cb_func, void *user_data)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
return ACCOUNT_ERROR_NONE;
}
-int account_get_custom(account_h account, const char* key, char** value)
+ACCOUNT_API int account_get_custom(account_h account, const char* key, char** value)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO KEY TO REQUEST"));
return ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
-int account_get_custom_all(account_h account, account_custom_cb cb_func, void* user_data)
+ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb cb_func, void* user_data)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
return ACCOUNT_ERROR_NONE;
}
-int account_query_capability_by_account_id(capability_cb cb_func, int account_id, void *user_data )
+ACCOUNT_API int account_query_capability_by_account_id(capability_cb cb_func, int account_id, void *user_data )
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
return error_code;
}
-#define URUSA_TEST
-
-#ifdef URUSA_TEST
static int _account_compare_old_record(account_s *new_account, int account_id)
{
int error_code = ACCOUNT_ERROR_NONE;
// get capability
error_code = account_query_capability_by_account_id(_account_get_capability_text_cb, old_account->id, (void*)old_account);
+ ACCOUNT_CATCH_ERROR((error_code == ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
// get custom text
error_code = _account_query_custom_by_account_id(_account_get_custom_text_cb, old_account->id, (void*)old_account);
-
+ ACCOUNT_CATCH_ERROR((error_code == ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
// compare
+ new_account->id = old_account->id;
+
//user name
if(!new_account->user_name) {
if(old_account->user_name)
new_account->email_address = _account_get_text(old_account->email_address);
}
+ // domain name
+ if(!new_account->domain_name) {
+ if(old_account->domain_name)
+ new_account->domain_name = _account_get_text(old_account->domain_name);
+ }
+
// icon path
if(!new_account->icon_path) {
if(old_account->icon_path)
new_account->source = _account_get_text(old_account->source);
}
+#ifndef ACCOUNT_VERIFY
// package name
if(!new_account->package_name) {
if(old_account->package_name)
new_account->package_name = _account_get_text(old_account->package_name);
}
+#endif
// access token
if(!new_account->access_token) {
return ACCOUNT_ERROR_NONE;
}
-#endif
static int _account_update_account(account_s *account, int account_id)
{
int rc = 0, binding_count =0;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int error_code = ACCOUNT_ERROR_NONE, count=0;
+ int error_code = ACCOUNT_ERROR_NONE, count=0, ret_transaction = 0;
account_stmt hstmt = NULL;
-
-#ifdef URUSA_TEST
_account_compare_old_record(account, account_id);
+
+#ifdef ACCOUNT_VERIFY
+
+ /* Check permission of requested appid */
+ if(!_account_verify_permission(account->package_name)) {
+ ACCOUNT_ERROR("No permission to update\n");
+ return ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
#endif
if (!account->package_name) {
return ACCOUNT_ERROR_INVALID_PARAMETER;
}
+
+ if(account_type_query_app_id_exist(account->package_name) != ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("App id is not registered in account type DB!!!!\n");
+ return ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
+ }
+
if (!account->user_name && !account->display_name && !account->email_address) {
ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
return ACCOUNT_ERROR_INVALID_PARAMETER;
return ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
+ /* transaction control required*/
+ ret_transaction = _account_begin_transaction();
+
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
"icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?, sync_support =?,"
"int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE _id=? ", ACCOUNT_TABLE);
hstmt = _account_prepare_query(query);
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s).\n", _account_db_err_msg()));
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s)(%x).\n", _account_db_err_msg(), _account_end_transaction(FALSE)));
binding_count = _account_convert_account_to_sql(account, hstmt, query);
_account_query_bind_int(hstmt, binding_count++, account_id);
/*update capability*/
error_code = _account_update_capability(account, account_id);
+ if(error_code != ACCOUNT_ERROR_NONE && error_code!= ACCOUNT_ERROR_RECORD_NOT_FOUND){
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
+ return error_code;
+ }
/* update custom */
error_code = _account_update_custom(account, account_id);
+ if(error_code != ACCOUNT_ERROR_NONE && error_code!= ACCOUNT_ERROR_RECORD_NOT_FOUND){
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
+ return error_code;
+ }
+
+ ret_transaction = _account_end_transaction(TRUE);
+ ACCOUNT_DEBUG("update capability success, trying to commit(%x) !!!\n", ret_transaction);
return error_code;
}
-int account_update_to_db_by_id(const account_h account, int account_id)
+ACCOUNT_API int account_update_to_db_by_id(const account_h account, int account_id)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
}
pthread_mutex_unlock(&account_mutex);
- _account_insert_delete_update_notification_send(ACCOUNT_NOTI_NAME_UPDATE);
+
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_UPDATE, account_id);
+ _account_insert_delete_update_notification_send(buf);
return ACCOUNT_ERROR_NONE;
}
-int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
+ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
{
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
error_code = _account_update_account_by_user_name(data, (char*)user_name, (char*)package_name);
pthread_mutex_unlock(&account_mutex);
- _account_insert_delete_update_notification_send(ACCOUNT_NOTI_NAME_UPDATE);
- return ACCOUNT_ERROR_NONE;
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_UPDATE, data->id);
+ _account_insert_delete_update_notification_send(buf);
+
+ return error_code;
}
-int account_foreach_account_from_db(account_cb callback, void *user_data)
+ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
return error_code;
}
-int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
+ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
_account_query_finalize(hstmt);
- _account_insert_delete_update_notification_send(ACCOUNT_NOTI_NAME_SYNC_UPDATE);
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_SYNC_UPDATE, account_db_id);
+ _account_insert_delete_update_notification_send(buf);
hstmt = NULL;
error_code = ACCOUNT_ERROR_NONE;
return error_code;
}
-int account_query_account_by_account_id(int account_db_id, account_h *account)
+ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
return error_code;
}
-int account_query_account_by_user_name(account_cb cb_func, const char *user_name, void *user_data)
+ACCOUNT_API int account_query_account_by_user_name(account_cb cb_func, const char *user_name, void *user_data)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
return error_code;
}
-int account_query_account_by_capability(account_cb cb_func, const char* capability_type, account_capability_state_e capability_value, void* user_data)
+ACCOUNT_API int account_query_account_by_capability(account_cb cb_func, const char* capability_type, account_capability_state_e capability_value, void* user_data)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
account_h account = NULL;
account = (account_h)iter->data;
+ account_s* testaccount = (account_s*)account;
+ account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
+ _account_query_custom_by_account_id(_account_get_custom_text_cb, testaccount->id, (void*)testaccount);
- account_s* testaccount = (account_s*)account;
+ ACCOUNT_VERBOSE("capability_list address = %p", testaccount->capablity_list);
- ACCOUNT_VERBOSE("id = %d", testaccount->id);
- ACCOUNT_VERBOSE("user_name = %s", testaccount->user_name);
- ACCOUNT_VERBOSE("email_address = %s", testaccount->email_address);
- ACCOUNT_VERBOSE("display_name = %s", testaccount->display_name);
- ACCOUNT_VERBOSE("icon_path = %s", testaccount->icon_path);
- ACCOUNT_VERBOSE("source = %s", testaccount->source);
- ACCOUNT_VERBOSE("package_name = %s", testaccount->package_name);
- ACCOUNT_VERBOSE("access_token = %s", testaccount->access_token);
- ACCOUNT_VERBOSE("domain_name = %s", testaccount->domain_name);
- ACCOUNT_VERBOSE("auth_type = %d", testaccount->auth_type);
- ACCOUNT_VERBOSE("secret = %d", testaccount->secret);
- ACCOUNT_VERBOSE("sync_support = %d", testaccount->sync_support);
+ cb_func(account, user_data);
+
+ }
+
+
+ error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+ if (hstmt != NULL) {
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+ }
+ if (account_head) {
+ if (account_head->account_list) {
+ _account_glist_free(account_head->account_list);
+ account_head->account_list = NULL;
+ _account_free_account_items(account_head);
+ }
+ _ACCOUNT_FREE(account_head);
+ }
+
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+}
+
+ACCOUNT_API int account_query_account_by_capability_type(account_cb cb_func, const char* capability_type, void* user_data)
+{
+ int error_code = ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ int ret = ACCOUNT_ERROR_NONE;
+
+ ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
+ ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+ ret = _do_account_owner_existance_check();
+ if (ret != ACCOUNT_ERROR_NONE) {
+ ACCOUNT_WARNING("_do_account_owner_existance_check Failed !!!\n");
+ }
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id IN (SELECT account_id from %s WHERE key=?)", ACCOUNT_TABLE, CAPABILITY_TABLE);
+
+ hstmt = _account_prepare_query(query);
+
+ int binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, (char*)capability_type);
+
+ rc = _account_query_step(hstmt);
+
+ account_s* account_head = NULL;
+
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ int tmp = 0;
+
+ account_head = (account_s*) malloc(sizeof(account_s));
+ if (account_head == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ if (hstmt != NULL) {
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+ }
+ return ACCOUNT_ERROR_OUT_OF_MEMORY;
+ }
+ ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
+
+ while (rc == SQLITE_ROW) {
+ account_s* account_record = NULL;
+
+ account_record = (account_s*) malloc(sizeof(account_s));
+
+ if (account_record == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ break;
+ }
+ ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
+
+ _account_convert_column_to_account(hstmt, account_record);
+
+ account_head->account_list = g_list_append(account_head->account_list, account_record);
+
+ rc = _account_query_step(hstmt);
+ tmp++;
+ ACCOUNT_VERBOSE("DETECTED COUNT %d\n", tmp);
+ }
+
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+
+ GList *iter;
+
+
+ tmp = g_list_length(account_head->account_list);
+ ACCOUNT_VERBOSE("GLIST LEN %d\n", tmp);
+
+ for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
+ account_h account = NULL;
+ account = (account_h)iter->data;
+ account_s* testaccount = (account_s*)account;
account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
_account_query_custom_by_account_id(_account_get_custom_text_cb, testaccount->id, (void*)testaccount);
}
-
error_code = ACCOUNT_ERROR_NONE;
CATCH:
return error_code;
}
-int account_query_account_by_package_name(account_cb cb_func, const char* package_name, void* user_data)
+ACCOUNT_API int account_query_account_by_package_name(account_cb cb_func, const char* package_name, void* user_data)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
account_s* account_head = NULL;
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.(%s)\n", package_name));
int tmp = 0;
return error_code;
}
-int account_delete(int account_id)
+ACCOUNT_API int account_delete(int account_id)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0, count = -1;
+ int rc = 0;
int ret_transaction = 0;
bool is_success = FALSE;
ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+#ifdef ACCOUNT_VERIFY
+ int count = -1;
+ account_h account = NULL;
/* Check requested ID to delete */
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE _id=%d", ACCOUNT_TABLE, account_id);
return ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
+ /* Check permission of requested appid */
+ account_create(&account);
+ account_query_account_by_account_id(account_id, &account);
+
+ if(!_account_verify_permission(((account_s*)account)->package_name)) {
+ ACCOUNT_ERROR("No permission to delete\n");
+ account_destroy(account);
+ return ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
+ account_destroy(account);
+#endif
+
/* transaction control required*/
ret_transaction = _account_begin_transaction();
if (ret_transaction != ACCOUNT_ERROR_NONE) {
ACCOUNT_ERROR("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
} else {
- if (is_success == true)
- _account_insert_delete_update_notification_send(ACCOUNT_NOTI_NAME_DELETE);
+ if (is_success == true) {
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_DELETE, account_id);
+ _account_insert_delete_update_notification_send(buf);
+ }
}
pthread_mutex_unlock(&account_mutex);
}
-int account_delete_from_db_by_id(int account_db_id)
+ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
{
ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
return error_code;
}
-int account_delete_from_db_by_user_name(char *user_name, char *package_name)
+ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
if (ret_transaction != ACCOUNT_ERROR_NONE) {
ACCOUNT_ERROR("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
} else {
- if (is_success == true)
- _account_insert_delete_update_notification_send(ACCOUNT_NOTI_NAME_DELETE);
+ if (is_success == true) {
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_DELETE, account_id);
+ _account_insert_delete_update_notification_send(buf);
+ }
}
pthread_mutex_unlock(&account_mutex);
return error_code;
}
-int account_delete_from_db_by_package_name(char *package_name)
+ACCOUNT_API int account_delete_from_db_by_package_name(char *package_name)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
if (ret_transaction != ACCOUNT_ERROR_NONE) {
ACCOUNT_ERROR("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
} else {
- if (is_success == true)
- _account_insert_delete_update_notification_send(ACCOUNT_NOTI_NAME_DELETE);
+ if (is_success == true) {
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_DELETE, -1);
+ _account_insert_delete_update_notification_send(buf);
+ }
}
pthread_mutex_unlock(&account_mutex);
return error_code;
}
-int account_get_total_count_from_db(int *count)
+ACCOUNT_API int account_get_total_count_from_db(int *count)
{
if (!count) {
ACCOUNT_ERROR("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
if (SQLITE_ROW != rc) {
ACCOUNT_ERROR("[ERROR] sqlite3_step() failed\n");
sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DB_FAILED;
+ return ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
ncount = sqlite3_column_int(pStmt, 0);
return ACCOUNT_ERROR_NONE;
}
-int account_destroy(account_h account)
+ACCOUNT_API int account_destroy(account_h account)
{
account_s *data = (account_s*)account;
return ACCOUNT_ERROR_NONE;
}
+static int _account_type_free_feature_items(provider_feature_s *data)
+{
+ _ACCOUNT_FREE(data->app_id);
+ _ACCOUNT_FREE(data->key);
+
+ return ACCOUNT_ERROR_NONE;
+}
+
static int _account_type_gslist_free(GSList* list)
{
ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("GSlist is NULL"));
return ACCOUNT_ERROR_NONE;
}
-int account_type_create(account_type_h *account_type)
+ACCOUNT_API int account_type_create(account_type_h *account_type)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_destroy(account_type_h account_type)
+ACCOUNT_API int account_type_destroy(account_type_h account_type)
{
account_type_s *data = (account_type_s*)account_type;
}
//app_id mandatory field
-int account_type_set_app_id(account_type_h account_type, const char *app_id)
+ACCOUNT_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
}
//service_provider_id mandatory field
-int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
+ACCOUNT_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
+ACCOUNT_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
+ACCOUNT_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support)
+ACCOUNT_API int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support)
{
ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
}
// unset?
-int account_type_set_label(account_type_h account_type, const char* label, const char* locale)
+ACCOUNT_API int account_type_set_label(account_type_h account_type, const char* label, const char* locale)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-
-int account_type_get_app_id(account_type_h account_type, char **app_id)
+ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
+ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_get_icon_path(account_type_h account_type, char **icon_path)
+ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
+ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
+ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
{
if (!account_type) {
ACCOUNT_ERROR("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
return ACCOUNT_ERROR_NONE;
}
-int account_type_get_label(account_type_h account_type, account_label_cb cb_func, void *user_data)
+ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb cb_func, void *user_data)
{
ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
/* check mandatory field */
// app id & service provider id
if (!account_type->app_id) {
- ACCOUNT_ERROR("App name is mandetory field, it can not be NULL!!!!\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- if (!account_type->service_provider_id) {
- ACCOUNT_ERROR("service_provider_id is mandetory field, it can not be NULL!!!!\n");
+ ACCOUNT_ERROR("App id is mandetory field, it can not be NULL!!!!\n");
return ACCOUNT_ERROR_INVALID_PARAMETER;
}
return ACCOUNT_ERROR_NONE;
}
-int account_type_insert_to_db(account_type_h account_type, int* account_type_id)
+static void _account_type_convert_column_to_provider_feature(account_stmt hstmt, provider_feature_s *feature_record)
{
- int error_code = ACCOUNT_ERROR_NONE;
+ char *textbuf = NULL;
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
- ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
+ textbuf = _account_query_table_column_text(hstmt, PROVIDER_FEATURE_FIELD_APP_ID);
+ _account_db_data_to_text(textbuf, &(feature_record->app_id));
- account_type_s *data = (account_type_s*)account_type;
+ textbuf = _account_query_table_column_text(hstmt, PROVIDER_FEATURE_FIELD_KEY);
+ _account_db_data_to_text(textbuf, &(feature_record->key));
- pthread_mutex_lock(&account_mutex);
+ ACCOUNT_VERBOSE("END _account_type_convert_column_to_provider_feature");
+}
- if (_account_type_check_duplicated(data)) {
- error_code = ACCOUNT_ERROR_DUPLICATED;
- } else {
- *account_type_id = _account_get_next_sequence(ACCOUNT_TYPE_TABLE);
+ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb cb_func, const char* app_id, void *user_data )
+{
+ int error_code = ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0, binding_count = 1;
- error_code = _account_type_execute_insert_query(data);
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- if (error_code != ACCOUNT_ERROR_NONE)
- *account_type_id = -1;
- }
+ ACCOUNT_VERBOSE("app_id = %s", app_id);
- ACCOUNT_INFO( "_account_type_execute_insert_query, insert error_code : %d", error_code);
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- _account_type_insert_label(data);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
+ hstmt = _account_prepare_query(query);
- pthread_mutex_unlock(&account_mutex);
+ _account_query_bind_text(hstmt, binding_count++, app_id);
- return ACCOUNT_ERROR_NONE;
-}
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-static int _account_type_update_label(account_type_s *account_type, const char* app_id)
-{
- int rc, count = 1;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- account_stmt hstmt = NULL;
+ provider_feature_s* feature_record = NULL;
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ while (rc == SQLITE_ROW) {
+ feature_record = (provider_feature_s*) malloc(sizeof(provider_feature_s));
- if (g_slist_length( account_type->label_list)==0) {
- ACCOUNT_ERROR( "_account_type_update_label, no label\n");
- return ACCOUNT_ERROR_NONE;
- }
+ if (feature_record == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ break;
+ }
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_MEMSET(feature_record, 0x00, sizeof(provider_feature_s));
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId=? ", LABEL_TABLE);
- hstmt = _account_prepare_query(query);
- count = 1;
- _account_query_bind_text(hstmt, count++, app_id);
- rc = _account_query_step(hstmt);
+ _account_type_convert_column_to_provider_feature(hstmt, feature_record);
- if (rc != SQLITE_DONE) {
- ACCOUNT_FATAL( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_DB_FAILED;
+ cb_func(feature_record->app_id, feature_record->key, user_data);
+
+ _account_type_free_feature_items(feature_record);
+ _ACCOUNT_FREE(feature_record);
+
+ rc = _account_query_step(hstmt);
}
+
_account_query_finalize(hstmt);
hstmt = NULL;
- GSList *iter;
+ error_code = ACCOUNT_ERROR_NONE;
- for (iter = account_type->label_list; iter != NULL; iter = g_slist_next(iter)) {
- int rc, ret;
- count = 1;
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(AppId, Label, Locale) VALUES "
- "(?, ?, ?) ", LABEL_TABLE);
+CATCH:
+ if (hstmt != NULL) {
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+ }
+
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+}
+
+ACCOUNT_API bool account_type_query_supported_feature(const char* app_id, const char* capability)
+{
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int record_count = 0;
+
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((capability != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CAPABILITY"));
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s where app_id='%s' and key='%s'", PROVIDER_FEATURE_TABLE, app_id, capability);
+
+ record_count = _account_get_record_count(query);
+
+ if (record_count <= 0) {
+ ACCOUNT_WARNING( "related capability type item is not existed rc=%d , %s", record_count, _account_db_err_msg());
+ return FALSE;
+ }
+
+ return TRUE;
+
+}
+
+
+ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb cb_func, void* user_data)
+{
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+
+ GSList *iter;
+ account_type_s *data = (account_type_s*)account_type;
+
+ for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
+ provider_feature_s *feature_data = NULL;
+
+ feature_data = (provider_feature_s*)iter->data;
+
+ ACCOUNT_VERBOSE("appid = %s, key = %s", feature_data->key, feature_data->app_id);
+
+ cb_func(feature_data->app_id, feature_data->key, user_data);
+ }
+
+ return ACCOUNT_ERROR_NONE;
+}
+
+ACCOUNT_API int account_type_set_provider_feature(account_type_h account_type, const char* provider_feature)
+{
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
+ ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
+
+ account_type_s *data = (account_type_s*)account_type;
+
+ GSList *iter = NULL;
+ bool b_is_new = TRUE;
+
+ for(iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
+ provider_feature_s *feature_data = NULL;
+ feature_data = (provider_feature_s*)iter->data;
+
+ if(!strcmp(feature_data->key, provider_feature)) {
+ b_is_new = FALSE;
+ break;
+ }
+ }
+
+ if(b_is_new) {
+ provider_feature_s* feature_data = (provider_feature_s*)malloc(sizeof(provider_feature_s));
+
+ if (feature_data == NULL)
+ return ACCOUNT_ERROR_OUT_OF_MEMORY;
+ ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
+
+ feature_data->key = _account_get_text(provider_feature);
+ data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
+ }
+
+ return ACCOUNT_ERROR_NONE;
+}
+
+static int _account_type_insert_provider_feature(account_type_s *account_type, const char* app_id)
+{
+ int rc, count = 1;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ account_stmt hstmt = NULL;
+
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+
+ if (g_slist_length( account_type->provider_feature_list)==0) {
+ ACCOUNT_ERROR( "no capability\n");
+ return ACCOUNT_ERROR_NONE;
+ }
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where AppId='%s'", ACCOUNT_TYPE_TABLE, app_id);
+
+ rc = _account_get_record_count(query);
+
+ if (rc <= 0) {
+ ACCOUNT_WARNING( "related account type item is not existed rc=%d , %s", rc, _account_db_err_msg());
+ return ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ }
+
+ /* insert query*/
+
+ GSList *iter;
+
+ for (iter = account_type->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
+ int rc, ret;
+ count = 1;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(app_id, key) VALUES "
+ "(?, ?) ", PROVIDER_FEATURE_TABLE);
+
+ hstmt = _account_prepare_query(query);
+
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
+
+ provider_feature_s* feature_data = NULL;
+ feature_data = (provider_feature_s*)iter->data;
+ ACCOUNT_VERBOSE("key = %s, app_id = %s \n", feature_data->key, app_id);
+
+ ret = _account_query_bind_text(hstmt, count++, app_id);
+ ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_text(hstmt, count++, feature_data->key);
+ ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
+
+ rc = _account_query_step(hstmt);
+
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_FATAL( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ break;
+ }
+
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+
+ }
+
+ ACCOUNT_VERBOSE( "_account_type_insert_provider_feature() DONE\n");
+
+ return ACCOUNT_ERROR_NONE;
+}
+
+ACCOUNT_API int account_type_insert_to_db(account_type_h account_type, int* account_type_id)
+{
+ int error_code = ACCOUNT_ERROR_NONE, ret_transaction = 0;
+
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
+
+ account_type_s *data = (account_type_s*)account_type;
+
+ pthread_mutex_lock(&account_mutex);
+
+
+ /* transaction control required*/
+ ret_transaction = _account_begin_transaction();
+
+ if (ret_transaction != ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("_account_begin_transaction fail %d\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return ret_transaction;
+ }
+
+ if (_account_type_check_duplicated(data)) {
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("Duplicated, rollback insert query(%x)!!!!\n", ret_transaction);
+ *account_type_id = -1;
+ pthread_mutex_unlock(&account_mutex);
+ return ACCOUNT_ERROR_DUPLICATED;
+ } else {
+ *account_type_id = _account_get_next_sequence(ACCOUNT_TYPE_TABLE);
+
+ error_code = _account_type_execute_insert_query(data);
+
+ if (error_code != ACCOUNT_ERROR_NONE){
+ error_code = ACCOUNT_ERROR_DUPLICATED;
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("Insert fail, rollback insert query(%x)!!!!\n", ret_transaction);
+ *account_type_id = -1;
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+ }
+ }
+
+ ACCOUNT_INFO( "_account_type_execute_insert_query, insert error_code : %d", error_code);
+
+ error_code = _account_type_insert_provider_feature(data, data->app_id);
+ if(error_code != ACCOUNT_ERROR_NONE) {
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("Insert provider feature fail(%x), rollback insert query(%x)!!!!\n", error_code, ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+ }
+ error_code = _account_type_insert_label(data);
+ if(error_code != ACCOUNT_ERROR_NONE) {
+ ret_transaction = _account_end_transaction(FALSE);
+ ACCOUNT_ERROR("Insert label fail(%x), rollback insert query(%x)!!!!\n", error_code, ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+ }
+
+ ret_transaction = _account_end_transaction(TRUE);
+ ACCOUNT_DEBUG("Insert success(%x), commit insert query(%x)!!!!\n", error_code, ret_transaction);
+
+ pthread_mutex_unlock(&account_mutex);
+
+ return ACCOUNT_ERROR_NONE;
+}
+
+static int _account_type_update_provider_feature(account_type_s *account_type, const char* app_id)
+{
+ int rc, count = 1;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ account_stmt hstmt = NULL;
+
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+
+ if (g_slist_length( account_type->provider_feature_list)==0) {
+ ACCOUNT_ERROR( "no feature\n");
+ return ACCOUNT_ERROR_NONE;
+ }
+
+ ACCOUNT_DEBUG( "app id", app_id);
+
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE app_id=? ", PROVIDER_FEATURE_TABLE);
+ hstmt = _account_prepare_query(query);
+ count = 1;
+ _account_query_bind_text(hstmt, count++, app_id);
+ rc = _account_query_step(hstmt);
+
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_FATAL( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ return ACCOUNT_ERROR_DB_FAILED;
+ }
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+
+ GSList *iter;
+
+ for (iter = account_type->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
+ int rc, ret;
+ count = 1;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(app_id, key) VALUES "
+ "(?, ?) ", PROVIDER_FEATURE_TABLE);
+
+ hstmt = _account_prepare_query(query);
+
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
+
+ provider_feature_s* feature_data = NULL;
+ feature_data = (provider_feature_s*)iter->data;
+
+ ret = _account_query_bind_text(hstmt, count++, account_type->app_id);
+ ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_text(hstmt, count++, feature_data->key);
+ ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+
+ rc = _account_query_step(hstmt);
+
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_FATAL( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ break;
+ }
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+ }
+
+ ACCOUNT_VERBOSE( "_account_type_update_label() DONE\n");
+
+ return ACCOUNT_ERROR_NONE;
+}
+
+static int _account_type_update_label(account_type_s *account_type, const char* app_id)
+{
+ int rc, count = 1;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ account_stmt hstmt = NULL;
+
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+
+ if (g_slist_length( account_type->label_list)==0) {
+ ACCOUNT_ERROR( "_account_type_update_label, no label\n");
+ return ACCOUNT_ERROR_NONE;
+ }
+
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId=? ", LABEL_TABLE);
+ hstmt = _account_prepare_query(query);
+ count = 1;
+ _account_query_bind_text(hstmt, count++, app_id);
+ rc = _account_query_step(hstmt);
+
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_FATAL( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ return ACCOUNT_ERROR_DB_FAILED;
+ }
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+
+ GSList *iter;
+
+ for (iter = account_type->label_list; iter != NULL; iter = g_slist_next(iter)) {
+ int rc, ret;
+ count = 1;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(AppId, Label, Locale) VALUES "
+ "(?, ?, ?) ", LABEL_TABLE);
hstmt = _account_prepare_query(query);
/*update label*/
error_code = _account_type_update_label(account_type, app_id);
+ /* update provider feature */
+ error_code = _account_type_update_provider_feature(account_type, app_id);
return error_code;
}
-int account_type_update_to_db_by_app_id(account_type_h account_type, const char* app_id)
+ACCOUNT_API int account_type_update_to_db_by_app_id(account_type_h account_type, const char* app_id)
{
ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_NONE;
+ return error_code;
}
-int account_type_delete_by_app_id(const char* app_id)
+ACCOUNT_API int account_type_delete_by_app_id(const char* app_id)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
binding_count = 1;
ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE app_id = ? ", PROVIDER_FEATURE_TABLE);
+
+ hstmt = _account_prepare_query(query);
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+
+ _account_query_bind_text(hstmt, binding_count++, app_id);
+
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. AppId=%s, rc=%d\n", app_id, rc));
+
+ _account_query_finalize(hstmt);
+ is_success = TRUE;
+
+ hstmt = NULL;
+
+ binding_count = 1;
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+
ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ? ", ACCOUNT_TYPE_TABLE);
hstmt = _account_prepare_query(query);
ACCOUNT_VERBOSE("END _account_type_convert_column_to_label");
}
-int account_type_query_label_by_app_id(account_label_cb cb_func, const char* app_id, void *user_data )
+ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb cb_func, const char* app_id, void *user_data )
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
return TRUE;
}
+bool _account_get_provider_feature_cb(char* app_id, char* key, void* user_data)
+{
+ account_type_s *data = (account_type_s*)user_data;
+
+ provider_feature_s *feature_data = (provider_feature_s*)malloc(sizeof(provider_feature_s));
+
+ if (feature_data == NULL) {
+ ACCOUNT_FATAL("_account_get_provider_feature_cb : MALLOC FAIL\n");
+ return FALSE;
+ }
+ ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
+
+ feature_data->app_id = _account_get_text(app_id);
+ feature_data->key = _account_get_text(key);
+
+ data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
+
+ ACCOUNT_VERBOSE("appid=%s, key=%s\n", feature_data->app_id, feature_data->key);
-int account_type_query_by_app_id(const char* app_id, account_type_h *account_type)
+ return TRUE;
+}
+
+ACCOUNT_API int account_type_query_by_app_id(const char* app_id, account_type_h *account_type)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ ACCOUNT_DEBUG("app id (%s)\n", app_id);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", ACCOUNT_TYPE_TABLE);
hstmt = _account_prepare_query(query);
}
_account_query_finalize(hstmt);
- account_type_query_label_by_app_id(_account_get_label_text_cb, account_type_record->app_id, (void*)account_type_record);
+ account_type_query_label_by_app_id(_account_get_label_text_cb, app_id, (void*)account_type_record);
+ account_type_query_provider_feature_by_app_id(_account_get_provider_feature_cb, app_id,(void*)account_type_record);
hstmt = NULL;
error_code = ACCOUNT_ERROR_NONE;
return error_code;
}
-int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
+ACCOUNT_API int account_type_query_app_id_exist(const char* app_id)
+{
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+
+ ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_DEBUG("app id (%s)\n", app_id);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s'", ACCOUNT_TYPE_TABLE, app_id);
+ rc = _account_get_record_count(query);
+
+ if (rc <= 0) {
+ ACCOUNT_DEBUG("(%s) not exist in account type db");
+ return ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ }
+
+ return ACCOUNT_ERROR_NONE;
+}
+
+ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb cb_func, const char* key, void* user_data)
+{
+ int error_code = ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ GList *account_type_list = NULL;
+
+ ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
+ ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId IN (SELECT app_id from %s WHERE key=?)", ACCOUNT_TYPE_TABLE, PROVIDER_FEATURE_TABLE);
+
+ hstmt = _account_prepare_query(query);
+
+ int binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, (char*)key);
+
+ rc = _account_query_step(hstmt);
+
+ account_type_s *account_type_record = NULL;
+
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ int k=0;
+ while(rc == SQLITE_ROW) {
+ account_type_record = (account_type_s*) malloc(sizeof(account_type_s));
+
+ if (account_type_record == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ break;
+ }
+
+ ACCOUNT_MEMSET(account_type_record, 0x00, sizeof(account_type_s));
+ _account_type_convert_column_to_account_type(hstmt, account_type_record);
+ account_type_list = g_list_append(account_type_list, account_type_record);
+ rc = _account_query_step(hstmt);
+ k++;
+ }
+
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+
+ GList* iter;
+ k = 0;
+ for (iter = account_type_list; iter != NULL; iter = g_list_next(iter)) {
+ account_type_s *account_type = NULL;
+ account_type = (account_type_s*)iter->data;
+ account_type_query_label_by_app_id(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
+ account_type_query_provider_feature_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+ cb_func((account_type_h)account_type, user_data);
+ k++;
+ }
+
+ error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+ if (hstmt != NULL) {
+ _account_query_finalize(hstmt);
+ hstmt = NULL;
+ }
+ if (account_type_list) {
+ _account_type_glist_free(account_type_list);
+ account_type_list = NULL;
+ }
+
+ return error_code;
+}
+
+
+ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
account_type_s *account_type = NULL;
account_type = (account_type_s*)iter->data;
account_type_query_label_by_app_id(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
+ account_type_query_provider_feature_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
callback((account_type_h)account_type, user_data);
k++;
}
}
// output parameter label must be free
-int account_type_query_label_by_locale(const char* app_id, const char* locale, char** label)
+ACCOUNT_API int account_type_query_label_by_locale(const char* app_id, const char* locale, char** label)
{
int error_code = ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ ACCOUNT_INFO( "account handle=%p, account_id=%d", account, account_id);
+
if (g_slist_length( account->custom_list)==0) {
ACCOUNT_ERROR( "_account_update_custom, no custom data\n");
return ACCOUNT_ERROR_NONE;
return error_code;
}
+static void _account_subscribe_vconf_callback(keynode_t *key, void *user_data)
+{
+ account_subscribe_s* tmp = (account_subscribe_s*)user_data;
+ char *msg = NULL, *vconf_key = NULL;
+ char event_msg[256] ={0, };
+ int account_id = -1;
+
+ ACCOUNT_DEBUG("START\n");
+
+ if(!key) {
+ ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
+ return;
+ }
+
+ if(!tmp) {
+ ACCOUNT_ERROR("user data required\n");
+ return;
+ }
+
+ if(!memcmp(vconf_keynode_get_name(key), VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
+ {
+ vconf_key = vconf_keynode_get_str(key);
+ msg = strdup(vconf_key);
+
+ char* event_type = NULL;
+ char* id = NULL;
+ char* ptr = NULL;
+
+ event_type = strtok_r(msg, ":", &ptr);
+ id = strtok_r(NULL, ":", &ptr);
+
+ ACCOUNT_DEBUG("msg(%s), event_type(%s), id(%s)\n", msg, event_type, id);
+
+ ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
+
+ account_id = atoi(id);
+
+ if(tmp->account_subscription_callback)
+ tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
+ }
+
+ _ACCOUNT_FREE(msg);
+
+ ACCOUNT_DEBUG("END\n");
+}
+
+ACCOUNT_API int account_subscribe_create(account_subscribe_h* account_subscribe)
+{
+ if (!account_subscribe) {
+ ACCOUNT_ERROR("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
+ return ACCOUNT_ERROR_INVALID_PARAMETER;
+ }
+
+ account_subscribe_s *data = (account_subscribe_s*)calloc(1,sizeof(account_subscribe_s));
+
+ if(!data) {
+ ACCOUNT_FATAL("OUT OF MEMORY\n");
+ return ACCOUNT_ERROR_OUT_OF_MEMORY;
+ }
+
+ ACCOUNT_VERBOSE("create handle=%p\n", *data);
+
+ *account_subscribe = (account_subscribe_h)data;
+
+ return ACCOUNT_ERROR_NONE;
+}
+
+ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb cb_func, void* user_data)
+{
+ ACCOUNT_DEBUG("START\n");
+
+ ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
+
+ account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
+
+ tmp->account_subscription_callback = cb_func;
+ tmp->user_data = user_data;
+
+ if (vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
+ (vconf_callback_fn)_account_subscribe_vconf_callback,
+ (void*)tmp) != 0) {
+ ACCOUNT_FATAL("Vconf Subscription Failed !!!!!\n");
+ return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
+ }
+
+ ACCOUNT_DEBUG("Vconf Subscription Success!!!!\n");
+ return ACCOUNT_ERROR_NONE;
+}
+
+ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
+{
+ ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
+
+ account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
+
+ _ACCOUNT_FREE(tmp);
+
+ if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
+ (vconf_callback_fn)_account_subscribe_vconf_callback) != 0) {
+ ACCOUNT_FATAL("Vconf Subscription Failed !!!!!\n");
+ return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
+ }
+
+ ACCOUNT_DEBUG("Vconf Unsubscription Success!!!!\n");
+ return ACCOUNT_ERROR_NONE;
+}