Modify flora license version.
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerFilter.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (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
7 *
8 *    http://floralicense.org/license/
9 *
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.
15 */
16
17 #include "MsgDebug.h"
18 #include "MsgUtilFunction.h"
19 #include "MsgCppTypes.h"
20 #include "MsgSpamFilter.h"
21 #include "MsgStorageHandler.h"
22 #include "MsgCmdHandler.h"
23
24
25 /*==================================================================================================
26                                      FUNCTION IMPLEMENTATION
27 ==================================================================================================*/
28 int MsgAddFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
29 {
30         msg_error_t err = MSG_SUCCESS;
31
32         int eventSize = 0;
33
34         // Get Filter Structure
35         MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
36
37         // Add Filter
38         err = MsgStoAddFilter(pFilter);
39
40         if (err == MSG_SUCCESS)
41         {
42                 MSG_DEBUG("Command Handle Success : MsgStoAddFilter()");
43         }
44         else
45         {
46                 MSG_DEBUG("Command Handle Fail : MsgStoAddFilter()");
47         }
48
49         // Make Event Data
50         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_FILTER, err, (void**)ppEvent);
51
52         return eventSize;
53 }
54
55
56 int MsgUpdateFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
57 {
58         msg_error_t err = MSG_SUCCESS;
59
60         int eventSize = 0;
61
62         // Get Filter Structure
63         MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
64
65         // Update Filter
66         err = MsgStoUpdateFilter(pFilter);
67
68         if (err == MSG_SUCCESS)
69         {
70                 MSG_DEBUG("Command Handle Success : MsgStoUpdateFilter()");
71         }
72         else
73         {
74                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateFilter()");
75         }
76
77         // Make Event Data
78         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_FILTER, err, (void**)ppEvent);
79
80         return eventSize;
81 }
82
83
84 int MsgDeleteFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
85 {
86         msg_error_t err = MSG_SUCCESS;
87
88         int eventSize = 0;
89
90         // Get Filter Structure
91         msg_filter_id_t  *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
92
93         MSG_DEBUG("Delete Filter id : %d", *pFilterId);
94
95         // Delete Filter
96         err = MsgStoDeleteFilter(*pFilterId);
97
98         if (err == MSG_SUCCESS)
99         {
100                 MSG_DEBUG("Command Handle Success : MsgStoDeleteFilter()");
101         }
102         else
103         {
104                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteFilter()");
105         }
106
107         // Make Event Data
108         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_FILTER, err, (void**)ppEvent);
109
110         return eventSize;
111 }
112
113
114 int MsgSetFilterActivationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
115 {
116         msg_error_t err = MSG_SUCCESS;
117
118         int eventSize = 0;
119
120         // Get Filter Structure
121         msg_filter_id_t  *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
122
123         bool setFlag = false;
124
125         memcpy(&setFlag, pCmd->cmdData+sizeof(msg_filter_id_t), sizeof(bool));
126
127         MSG_DEBUG("Filter id : %d", *pFilterId);
128
129         // Delete Filter
130         err = MsgStoSetFilterActivation(*pFilterId, setFlag);
131
132         if (err == MSG_SUCCESS)
133         {
134                 MSG_DEBUG("Command Handle Success : MsgStoSetFilterActivation()");
135         }
136         else
137         {
138                 MSG_DEBUG("Command Handle Fail : MsgStoSetFilterActivation()");
139         }
140
141         // Make Event Data
142         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_ACTIVATION, err, (void**)ppEvent);
143
144         return eventSize;
145 }
146
147
148 int MsgGetFilterListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
149 {
150         msg_error_t err = MSG_SUCCESS;
151
152         char* encodedData = NULL;
153         AutoPtr<char> buf(&encodedData);
154
155         int dataSize = 0, eventSize = 0;
156
157         // Get Filter List
158         msg_struct_list_s filterList;
159
160         err = MsgStoGetFilterList(&filterList);
161
162         if (err == MSG_SUCCESS)
163         {
164                 MSG_DEBUG("Command Handle Success : MsgStoGetFilterList()");
165
166                 // Encoding Filter List Data
167                 dataSize = MsgEncodeFilterList(&filterList, &encodedData);
168
169                 delete [] filterList.msg_struct_info;
170         }
171         else
172         {
173                 MSG_DEBUG("Command Handle Fail : MsgStoGetFilterList()");
174         }
175
176         // Make Event Data
177         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTERLIST, err, (void**)ppEvent);
178
179         return eventSize;
180 }
181
182
183 int MsgSetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
184 {
185         msg_error_t err = MSG_SUCCESS;
186
187         int eventSize = 0;
188
189         // Get Filter Flag
190         bool setFlag = false;
191
192         memcpy(&setFlag, pCmd->cmdData, sizeof(bool));
193
194         // Add Filter
195         err = MsgSetFilterOperation(setFlag);
196
197         if (err == MSG_SUCCESS)
198         {
199                 MSG_DEBUG("Command Handle Success : MsgSetFilterOperation()");
200         }
201         else
202         {
203                 MSG_DEBUG("Command Handle Fail : MsgSetFilterOperation()");
204         }
205
206         // Make Event Data
207         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_OPERATION, err, (void**)ppEvent);
208
209         return eventSize;
210 }
211
212
213 int MsgGetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
214 {
215         msg_error_t err = MSG_SUCCESS;
216
217         char* encodedData = NULL;
218         AutoPtr<char> buf(&encodedData);
219
220         int dataSize = 0, eventSize = 0;
221
222         // Get Filter List
223         bool setFlag = false;
224
225         err = MsgGetFilterOperation(&setFlag);
226
227         if (err == MSG_SUCCESS)
228         {
229                 MSG_DEBUG("Command Handle Success : MsgGetFilterOperation()");
230
231                 // Encoding Filter List Data
232                 dataSize = MsgEncodeFilterFlag(&setFlag, &encodedData);
233         }
234         else
235         {
236                 MSG_DEBUG("Command Handle Fail : MsgFilterGetFilterList()");
237         }
238
239         // Make Event Data
240         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTER_OPERATION, err, (void**)ppEvent);
241
242         return eventSize;
243 }