2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "MsgUtilFunction.h"
19 #include "MsgCppTypes.h"
20 #include "MsgSpamFilter.h"
21 #include "MsgStorageHandler.h"
22 #include "MsgCmdHandler.h"
25 /*==================================================================================================
26 FUNCTION IMPLEMENTATION
27 ==================================================================================================*/
28 int MsgAddFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
30 msg_error_t err = MSG_SUCCESS;
32 if (!pCmd || !ppEvent) {
33 MSG_DEBUG("pCmd or ppEvent is null");
39 /* Get Filter Structure */
40 MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
43 err = MsgStoAddFilter(pFilter);
45 if (err == MSG_SUCCESS) {
46 MSG_DEBUG("Command Handle Success : MsgStoAddFilter()");
48 MSG_DEBUG("Command Handle Fail : MsgStoAddFilter()");
52 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_FILTER, err, (void**)ppEvent);
58 int MsgUpdateFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
60 msg_error_t err = MSG_SUCCESS;
62 if (!pCmd || !ppEvent) {
63 MSG_DEBUG("pCmd or ppEvent is null");
69 /* Get Filter Structure */
70 MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
73 err = MsgStoUpdateFilter(pFilter);
75 if (err == MSG_SUCCESS) {
76 MSG_DEBUG("Command Handle Success : MsgStoUpdateFilter()");
78 MSG_DEBUG("Command Handle Fail : MsgStoUpdateFilter()");
82 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_FILTER, err, (void**)ppEvent);
88 int MsgDeleteFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
90 msg_error_t err = MSG_SUCCESS;
92 if (!pCmd || !ppEvent) {
93 MSG_DEBUG("pCmd or ppEvent is null");
99 /* Get Filter Structure */
100 msg_filter_id_t *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
102 MSG_DEBUG("Delete Filter id : %d", *pFilterId);
105 err = MsgStoDeleteFilter(*pFilterId);
107 if (err == MSG_SUCCESS) {
108 MSG_DEBUG("Command Handle Success : MsgStoDeleteFilter()");
110 MSG_DEBUG("Command Handle Fail : MsgStoDeleteFilter()");
113 /* Make Event Data */
114 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_FILTER, err, (void**)ppEvent);
120 int MsgSetFilterActivationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
122 msg_error_t err = MSG_SUCCESS;
124 if (!pCmd || !ppEvent) {
125 MSG_DEBUG("pCmd or ppEvent is null");
131 /* Get Filter Structure */
132 msg_filter_id_t *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
134 bool setFlag = false;
136 memcpy(&setFlag, pCmd->cmdData+sizeof(msg_filter_id_t), sizeof(bool));
138 MSG_DEBUG("Filter id : %d", *pFilterId);
141 err = MsgStoSetFilterActivation(*pFilterId, setFlag);
143 if (err == MSG_SUCCESS) {
144 MSG_DEBUG("Command Handle Success : MsgStoSetFilterActivation()");
146 MSG_DEBUG("Command Handle Fail : MsgStoSetFilterActivation()");
149 /* Make Event Data */
150 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_ACTIVATION, err, (void**)ppEvent);
156 int MsgGetFilterListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
158 msg_error_t err = MSG_SUCCESS;
160 if (!pCmd || !ppEvent) {
161 MSG_DEBUG("pCmd or ppEvent is null");
165 char* encodedData = NULL;
166 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
168 int dataSize = 0, eventSize = 0;
170 /* Get Filter List */
171 msg_struct_list_s filterList;
173 err = MsgStoGetFilterList(&filterList);
175 if (err == MSG_SUCCESS) {
176 MSG_DEBUG("Command Handle Success : MsgStoGetFilterList()");
178 /* Encoding Filter List Data */
179 dataSize = MsgEncodeFilterList(&filterList, &encodedData);
181 if (filterList.msg_struct_info) {
182 msg_struct_s *msg_struct;
183 for (int i = 0; i < filterList.nCount; i++) {
184 msg_struct = (msg_struct_s *)filterList.msg_struct_info[i];
186 delete (MSG_FILTER_S *)msg_struct->data;
190 g_free(filterList.msg_struct_info);
193 MSG_DEBUG("Command Handle Fail : MsgStoGetFilterList()");
196 /* Make Event Data */
197 eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTERLIST, err, (void**)ppEvent);
203 int MsgSetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
205 msg_error_t err = MSG_SUCCESS;
207 if (!pCmd || !ppEvent) {
208 MSG_DEBUG("pCmd or ppEvent is null");
214 /* Get Filter Flag */
215 bool setFlag = false;
217 memcpy(&setFlag, pCmd->cmdData, sizeof(bool));
220 err = MsgSetFilterOperation(setFlag);
222 if (err == MSG_SUCCESS) {
223 MSG_DEBUG("Command Handle Success : MsgSetFilterOperation()");
225 MSG_DEBUG("Command Handle Fail : MsgSetFilterOperation()");
228 /* Make Event Data */
229 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_OPERATION, err, (void**)ppEvent);
235 int MsgGetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
237 msg_error_t err = MSG_SUCCESS;
239 if (!pCmd || !ppEvent) {
240 MSG_DEBUG("pCmd or ppEvent is null");
244 char* encodedData = NULL;
245 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
247 int dataSize = 0, eventSize = 0;
249 /* Get Filter List */
250 bool setFlag = false;
252 err = MsgGetFilterOperation(&setFlag);
254 if (err == MSG_SUCCESS) {
255 MSG_DEBUG("Command Handle Success : MsgGetFilterOperation()");
257 /* Encoding Filter List Data */
258 dataSize = MsgEncodeFilterFlag(&setFlag, &encodedData);
260 MSG_DEBUG("Command Handle Fail : MsgFilterGetFilterList()");
263 /* Make Event Data */
264 eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTER_OPERATION, err, (void**)ppEvent);