4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include "MsgUtilFunction.h"
22 #include "MsgCppTypes.h"
23 #include "MsgSpamFilter.h"
24 #include "MsgStorageHandler.h"
25 #include "MsgCmdHandler.h"
28 /*==================================================================================================
29 FUNCTION IMPLEMENTATION
30 ==================================================================================================*/
31 int MsgAddFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
33 msg_error_t err = MSG_SUCCESS;
37 // Get Filter Structure
38 MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
41 err = MsgStoAddFilter(pFilter);
43 if (err == MSG_SUCCESS)
45 MSG_DEBUG("Command Handle Success : MsgStoAddFilter()");
49 MSG_DEBUG("Command Handle Fail : MsgStoAddFilter()");
53 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_FILTER, err, (void**)ppEvent);
59 int MsgUpdateFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
61 msg_error_t err = MSG_SUCCESS;
65 // Get Filter Structure
66 MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
69 err = MsgStoUpdateFilter(pFilter);
71 if (err == MSG_SUCCESS)
73 MSG_DEBUG("Command Handle Success : MsgStoUpdateFilter()");
77 MSG_DEBUG("Command Handle Fail : MsgStoUpdateFilter()");
81 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_FILTER, err, (void**)ppEvent);
87 int MsgDeleteFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
89 msg_error_t err = MSG_SUCCESS;
93 // Get Filter Structure
94 msg_filter_id_t *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
96 MSG_DEBUG("Delete Filter id : %d", *pFilterId);
99 err = MsgStoDeleteFilter(*pFilterId);
101 if (err == MSG_SUCCESS)
103 MSG_DEBUG("Command Handle Success : MsgStoDeleteFilter()");
107 MSG_DEBUG("Command Handle Fail : MsgStoDeleteFilter()");
111 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_FILTER, err, (void**)ppEvent);
117 int MsgSetFilterActivationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
119 msg_error_t err = MSG_SUCCESS;
123 // Get Filter Structure
124 msg_filter_id_t *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
126 bool setFlag = false;
128 memcpy(&setFlag, pCmd->cmdData+sizeof(msg_filter_id_t), sizeof(bool));
130 MSG_DEBUG("Filter id : %d", *pFilterId);
133 err = MsgStoSetFilterActivation(*pFilterId, setFlag);
135 if (err == MSG_SUCCESS)
137 MSG_DEBUG("Command Handle Success : MsgStoSetFilterActivation()");
141 MSG_DEBUG("Command Handle Fail : MsgStoSetFilterActivation()");
145 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_ACTIVATION, err, (void**)ppEvent);
151 int MsgGetFilterListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
153 msg_error_t err = MSG_SUCCESS;
155 char* encodedData = NULL;
156 AutoPtr<char> buf(&encodedData);
158 int dataSize = 0, eventSize = 0;
161 msg_struct_list_s filterList;
163 err = MsgStoGetFilterList(&filterList);
165 if (err == MSG_SUCCESS)
167 MSG_DEBUG("Command Handle Success : MsgStoGetFilterList()");
169 // Encoding Filter List Data
170 dataSize = MsgEncodeFilterList(&filterList, &encodedData);
172 delete [] filterList.msg_struct_info;
176 MSG_DEBUG("Command Handle Fail : MsgStoGetFilterList()");
180 eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTERLIST, err, (void**)ppEvent);
186 int MsgSetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
188 msg_error_t err = MSG_SUCCESS;
193 bool setFlag = false;
195 memcpy(&setFlag, pCmd->cmdData, sizeof(bool));
198 err = MsgSetFilterOperation(setFlag);
200 if (err == MSG_SUCCESS)
202 MSG_DEBUG("Command Handle Success : MsgSetFilterOperation()");
206 MSG_DEBUG("Command Handle Fail : MsgSetFilterOperation()");
210 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_OPERATION, err, (void**)ppEvent);
216 int MsgGetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
218 msg_error_t err = MSG_SUCCESS;
220 char* encodedData = NULL;
221 AutoPtr<char> buf(&encodedData);
223 int dataSize = 0, eventSize = 0;
226 bool setFlag = false;
228 err = MsgGetFilterOperation(&setFlag);
230 if (err == MSG_SUCCESS)
232 MSG_DEBUG("Command Handle Success : MsgGetFilterOperation()");
234 // Encoding Filter List Data
235 dataSize = MsgEncodeFilterFlag(&setFlag, &encodedData);
239 MSG_DEBUG("Command Handle Fail : MsgFilterGetFilterList()");
243 eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTER_OPERATION, err, (void**)ppEvent);