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.
26 * This file contains the data structures and interfaces needed for application,
27 * to interact with email-service.
28 * @file email-api-rule.c
29 * @brief This file contains the data structures and interfaces of Rule related Functionality provided by
33 #include "email-api.h"
35 #include "email-convert.h"
36 #include "email-storage.h"
37 #include "email-utilities.h"
38 #include "email-ipc.h"
40 EXPORT_API int email_get_rule(int filter_id, email_rule_t** filtering_set)
42 EM_DEBUG_FUNC_BEGIN("filter_id[%d], filtering_set[%p]", filter_id, filtering_set);
46 EM_IF_NULL_RETURN_VALUE(filtering_set, EMAIL_ERROR_INVALID_PARAM);
47 EM_IF_NULL_RETURN_VALUE(filter_id, EMAIL_ERROR_INVALID_PARAM);
49 if (!emstorage_get_rule_by_id(0, filter_id, (emstorage_rule_tbl_t**)filtering_set, true, &err)) {
50 EM_DEBUG_EXCEPTION("emstorage_get_rule_by_id failed [%d]", err);
54 err = EMAIL_ERROR_NONE;
57 EM_DEBUG_FUNC_END("error value [%d]", err);
62 EXPORT_API int email_get_rule_list(email_rule_t** filtering_set, int* count)
64 EM_DEBUG_FUNC_BEGIN();
66 int err = EMAIL_ERROR_NONE;
69 EM_IF_NULL_RETURN_VALUE(filtering_set, EMAIL_ERROR_INVALID_PARAM);
70 EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM);
74 if (!emstorage_get_rule(0, 0, 0, count, &is_completed, (emstorage_rule_tbl_t**)filtering_set, true, &err)) {
75 EM_DEBUG_EXCEPTION("emstorage_get_rule failed [%d]", err);
80 err = EMAIL_ERROR_NONE;
89 EXPORT_API int email_add_rule(email_rule_t* filtering_set)
91 EM_DEBUG_FUNC_BEGIN("filtering_set[%p]", filtering_set);
94 int err = EMAIL_ERROR_NONE;
97 EM_IF_NULL_RETURN_VALUE(filtering_set, EMAIL_ERROR_INVALID_PARAM);
100 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_ADD_RULE);
101 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
103 stream = em_convert_rule_to_byte_stream(filtering_set, &size);
104 EM_PROXY_IF_NULL_RETURN_VALUE(stream, hAPI, EMAIL_ERROR_NULL_VALUE);
105 if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, stream, size)) {
106 EM_DEBUG_EXCEPTION("Add Param Failed");
107 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
111 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
112 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api Failed");
113 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
116 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
118 emipc_destroy_email_api(hAPI);
120 EM_DEBUG_FUNC_END("error value [%d]", err);
126 EXPORT_API int email_update_rule(int filter_id, email_rule_t* new_set)
128 EM_DEBUG_FUNC_BEGIN("filter_id[%d], new_set[%p]", filter_id, new_set);
132 int err = EMAIL_ERROR_NONE;
134 EM_IF_NULL_RETURN_VALUE(filter_id, EMAIL_ERROR_INVALID_PARAM);
135 EM_IF_NULL_RETURN_VALUE(new_set, EMAIL_ERROR_INVALID_PARAM);
137 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_UPDATE_RULE);
138 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
140 /* make filter info */
141 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&filter_id, sizeof(int))) {
142 EM_DEBUG_EXCEPTION("Add Param filter_id Failed");
143 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
146 stream = em_convert_rule_to_byte_stream(new_set, &size);
148 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
150 if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, stream, size)){
151 EM_DEBUG_EXCEPTION("Add Param new_set Failed");
152 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
155 /* request update rule with filter info */
156 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
157 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api Failed");
158 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
162 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
164 emipc_destroy_email_api(hAPI);
167 EM_DEBUG_FUNC_END("error value [%d]", err);
174 EXPORT_API int email_delete_rule(int filter_id)
176 EM_DEBUG_FUNC_BEGIN("filter_id[%d]", filter_id);
178 int err = EMAIL_ERROR_NONE;
180 EM_IF_NULL_RETURN_VALUE(filter_id, EMAIL_ERROR_INVALID_PARAM);
182 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DELETE_RULE);
184 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
187 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&filter_id, sizeof(int))) {
188 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
189 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
192 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
193 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
194 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
197 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
198 emipc_destroy_email_api(hAPI);
201 EM_DEBUG_FUNC_END("error value [%d]", err);
205 EXPORT_API int email_free_rule (email_rule_t** filtering_set, int count)
207 EM_DEBUG_FUNC_BEGIN();
208 int err = EMAIL_ERROR_NONE, i;
210 EM_IF_NULL_RETURN_VALUE(filtering_set, EMAIL_ERROR_INVALID_PARAM);
211 EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM);
214 email_rule_t* p = *filtering_set;
216 for (i = 0; i < count; i++) {
217 EM_SAFE_FREE(p[i].value);
220 EM_SAFE_FREE(p); *filtering_set = NULL;
223 EM_DEBUG_FUNC_END("error value [%d]", err);