4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 /******************************************************************************
25 * File : email-core-global.c
26 * Desc : Mail Engine Global
31 * 2010.08.25 : created
32 *****************************************************************************/
36 #include "email-core-global.h"
37 #include "email-debug-log.h"
38 #include "email-types.h"
39 #include "email-utilities.h"
40 #include "email-core-account.h"
42 static email_account_list_t *g_unvalidated_account_list = NULL;
43 static pthread_mutex_t _unvalidated_account_lock = PTHREAD_MUTEX_INITIALIZER;
45 extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) __THROW __nonnull ((1));
47 INTERNAL_FUNC int emcore_get_account_from_unvalidated_account_list(int input_unvalidated_account_id, email_account_t **oupput_account)
49 EM_DEBUG_FUNC_BEGIN("input_unvalidated_account_id[%d], oupput_account[%p]", input_unvalidated_account_id, oupput_account);
50 email_account_list_t *account_node = NULL;
51 int err = EMAIL_ERROR_NONE;
53 if(oupput_account == NULL) {
54 err = EMAIL_ERROR_INVALID_PARAM;
55 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
59 *oupput_account = NULL;
61 ENTER_CRITICAL_SECTION(_unvalidated_account_lock);
62 account_node = g_unvalidated_account_list;
64 if(account_node->account->account_id == input_unvalidated_account_id) {
65 emcore_duplicate_account(account_node->account, oupput_account, NULL);
68 account_node = account_node->next;
70 LEAVE_CRITICAL_SECTION(_unvalidated_account_lock);
72 if(*oupput_account == NULL)
73 err = EMAIL_ERROR_DATA_NOT_FOUND;
76 EM_DEBUG_FUNC_END("err [%d]", err);
80 INTERNAL_FUNC int emcore_add_account_to_unvalidated_account_list(email_account_t *input_new_account)
82 EM_DEBUG_FUNC_BEGIN("input_new_account[%p]", input_new_account);
83 email_account_list_t **account_node = NULL;
84 email_account_list_t *new_account_node = NULL;
85 int new_account_id = -1;
86 int err = EMAIL_ERROR_NONE;
88 if(input_new_account == NULL) {
89 err = EMAIL_ERROR_INVALID_PARAM;
90 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
94 new_account_node = em_malloc(sizeof(email_account_list_t));
96 if(new_account_node == NULL) {
97 err = EMAIL_ERROR_OUT_OF_MEMORY;
98 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
102 new_account_node->account = input_new_account;
103 new_account_node->next = NULL;
105 ENTER_CRITICAL_SECTION(_unvalidated_account_lock);
106 account_node = &g_unvalidated_account_list;
108 while(*account_node) {
109 if((*account_node)->account->account_id < new_account_id) {
110 new_account_id = (*account_node)->account->account_id - 1;
112 account_node = &((*account_node)->next);
115 input_new_account->account_id = new_account_id;
116 *account_node = new_account_node;
117 LEAVE_CRITICAL_SECTION(_unvalidated_account_lock);
120 EM_DEBUG_FUNC_END("err [%d]", err);
124 INTERNAL_FUNC int emcore_delete_account_from_unvalidated_account_list(int input_account_id)
126 EM_DEBUG_FUNC_BEGIN("input_account_id[%d]", input_account_id);
127 email_account_list_t *account_node = NULL, *prev_node = NULL;
128 email_account_t *found_account = NULL;
129 int err = EMAIL_ERROR_NONE;
131 ENTER_CRITICAL_SECTION(_unvalidated_account_lock);
132 account_node = g_unvalidated_account_list;
134 while(account_node) {
135 if(account_node->account->account_id == input_account_id) {
136 found_account = account_node->account;
138 prev_node->next = account_node->next;
140 g_unvalidated_account_list = account_node->next;
143 prev_node = account_node;
144 account_node = account_node->next;
148 emcore_free_account(found_account);
149 EM_SAFE_FREE(found_account);
150 EM_SAFE_FREE(account_node);
152 EM_DEBUG_EXCEPTION("EMAIL_ERROR_DATA_NOT_FOUND");
153 err = EMAIL_ERROR_DATA_NOT_FOUND;
155 LEAVE_CRITICAL_SECTION(_unvalidated_account_lock);
157 EM_DEBUG_FUNC_END("err [%d]", err);