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