Sync with tizen 2.4
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerSetting.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 "MsgCmdHandler.h"
19 #include "MsgSettingHandler.h"
20 #include "MsgUtilFunction.h"
21 #include "MsgCppTypes.h"
22
23
24 /*==================================================================================================
25                                      FUNCTION IMPLEMENTATION
26 ==================================================================================================*/
27 int MsgSetConfigHandler(const MSG_CMD_S *pCmd, char **ppEvent)
28 {
29         msg_error_t err = MSG_SUCCESS;
30
31         int eventSize = 0;
32         int eventType = -1;
33
34         // Get Setting Structure
35         MSG_SETTING_S* pSetting = (MSG_SETTING_S*)pCmd->cmdData;
36
37         // Set Config Data
38         err = MsgSetConfigData(pSetting);
39
40         if (err == MSG_SUCCESS)
41         {
42                 MSG_DEBUG("Command Handle Success : MsgSetConfigData()");
43         }
44         else
45         {
46                 MSG_DEBUG("Command Handle Fail : MsgSetConfigData()");
47         }
48
49         // Make Event Data
50         switch (pCmd->cmdType) {
51         case MSG_CMD_SET_SMSC_OPT :
52                 eventType = MSG_EVENT_SET_SMSC_OPT;
53                 break;
54         case MSG_CMD_SET_CB_OPT :
55                 eventType = MSG_EVENT_SET_CB_OPT;
56                 break;
57         case MSG_CMD_SET_SMS_SEND_OPT :
58                 eventType = MSG_EVENT_SET_SMS_SEND_OPT;
59                 break;
60         case MSG_CMD_SET_MMS_SEND_OPT :
61                 eventType = MSG_EVENT_SET_MMS_SEND_OPT;
62                 break;
63         case MSG_CMD_SET_MMS_RECV_OPT :
64                 eventType = MSG_EVENT_SET_MMS_RECV_OPT;
65                 break;
66         case MSG_CMD_SET_PUSH_MSG_OPT :
67                 eventType = MSG_EVENT_SET_PUSH_MSG_OPT;
68                 break;
69         case MSG_CMD_SET_VOICE_MSG_OPT :
70                 eventType = MSG_EVENT_SET_VOICE_MSG_OPT;
71                 break;
72         case MSG_CMD_SET_GENERAL_MSG_OPT :
73                 eventType = MSG_EVENT_SET_GENERAL_MSG_OPT;
74                 break;
75         case MSG_CMD_SET_MSG_SIZE_OPT :
76                         eventType = MSG_EVENT_SET_MSG_SIZE_OPT;
77                         break;
78         default :
79                 break;
80         }
81
82         eventSize = MsgMakeEvent(NULL, 0, eventType, err, (void**)ppEvent);
83
84         return eventSize;
85 }
86
87
88 int MsgGetConfigHandler(const MSG_CMD_S *pCmd, char **ppEvent)
89 {
90         msg_error_t err = MSG_SUCCESS;
91
92         char* encodedData = NULL;
93         AutoPtr<char> buf(&encodedData);
94
95         int dataSize = 0;
96         int eventSize = 0;
97         int eventType = -1;
98
99         // Get Option Type
100         MSG_OPTION_TYPE_T type = 0;
101         memcpy((void *)&type, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_OPTION_TYPE_T));
102
103         // Get Config Data
104         MSG_SETTING_S setting;
105         setting.type = type;
106
107         msg_sim_slot_id_t simIndex = 0;
108         switch(setting.type) {
109         case MSG_CBMSG_OPT :
110                 memcpy(&simIndex, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), sizeof(msg_sim_slot_id_t));
111                 setting.option.cbMsgOpt.simIndex = simIndex;
112                 break;
113         case MSG_VOICEMAIL_OPT :
114                 memcpy(&simIndex, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), sizeof(msg_sim_slot_id_t));
115                 setting.option.voiceMailOpt.simIndex = simIndex;
116                 break;
117         case MSG_SMSC_LIST :
118                 memcpy(&simIndex, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), sizeof(msg_sim_slot_id_t));
119                 setting.option.smscList.simIndex = simIndex;
120                 break;
121         default :
122                 break;
123         }
124
125         err = MsgGetConfigData(&setting);
126
127         if (err == MSG_SUCCESS)
128         {
129                 MSG_DEBUG("Command Handle Success : MsgGetConfigData()");
130
131                 // Encoding Config Data
132                 switch (setting.type)
133                         {
134                                 case MSG_GENERAL_OPT :
135                                         dataSize += sizeof(MSG_GENERAL_OPT_S);
136                                         break;
137                                 case MSG_SMS_SENDOPT :
138                                         dataSize += sizeof(MSG_SMS_SENDOPT_S);
139                                         break;
140                                 case MSG_SMSC_LIST :
141                                         dataSize += sizeof(MSG_SMSC_LIST_S);
142                                         break;
143                                 case MSG_MMS_SENDOPT :
144                                         dataSize += sizeof(MSG_MMS_SENDOPT_S);
145                                         break;
146                                 case MSG_MMS_RECVOPT :
147                                         dataSize += sizeof(MSG_MMS_RECVOPT_S);
148                                         break;
149                                 case MSG_MMS_STYLEOPT :
150                                         dataSize += sizeof(MSG_MMS_STYLEOPT_S);
151                                         break;
152                                 case MSG_PUSHMSG_OPT :
153                                         dataSize += sizeof(MSG_PUSHMSG_OPT_S);
154                                         break;
155                                 case MSG_CBMSG_OPT :
156                                         dataSize += sizeof(MSG_CBMSG_OPT_S);
157                                         break;
158                                 case MSG_VOICEMAIL_OPT :
159                                         dataSize += sizeof(MSG_VOICEMAIL_OPT_S);
160                                         break;
161                                 case MSG_MSGSIZE_OPT :
162                                         dataSize += sizeof(MSG_MSGSIZE_OPT_S);
163                                         break;
164                                 default:
165                                         break;
166                         }
167
168                         encodedData = (char*)new char[dataSize];
169                         void* p = (void*)encodedData;
170
171                         switch (setting.type)
172                         {
173                         case MSG_GENERAL_OPT :
174                                 memcpy(p, &(setting.option.generalOpt), dataSize);
175                                 break;
176                         case MSG_SMS_SENDOPT :
177                                 memcpy(p, &(setting.option.smsSendOpt), dataSize);
178                                 break;
179                         case MSG_SMSC_LIST :
180                                 memcpy(p, &(setting.option.smscList), dataSize);
181                                 break;
182                         case MSG_MMS_SENDOPT :
183                                 memcpy(p, &(setting.option.mmsSendOpt), dataSize);
184                                 break;
185                         case MSG_MMS_RECVOPT :
186                                 memcpy(p, &(setting.option.mmsRecvOpt), dataSize);
187                                 break;
188                         case MSG_MMS_STYLEOPT :
189                                 memcpy(p, &(setting.option.mmsStyleOpt), dataSize);
190                                 break;
191                         case MSG_PUSHMSG_OPT :
192                                 memcpy(p, &(setting.option.pushMsgOpt), dataSize);
193                                 break;
194                         case MSG_CBMSG_OPT :
195                                 memcpy(p, &(setting.option.cbMsgOpt), dataSize);
196                                 break;
197                         case MSG_VOICEMAIL_OPT :
198                                 memcpy(p, &(setting.option.voiceMailOpt), dataSize);
199                                 break;
200                         case MSG_MSGSIZE_OPT :
201                                 memcpy(p, &(setting.option.msgSizeOpt), dataSize);
202                                 break;
203                         default:
204                                 break;
205                         }
206         } else {
207                 MSG_DEBUG("Command Handle Fail : MsgGetConfigData()");
208         }
209
210         MSG_DEBUG("dataSize [%d]", dataSize);
211
212         switch (pCmd->cmdType) {
213         case MSG_CMD_GET_SMSC_OPT :
214                 eventType = MSG_EVENT_GET_SMSC_OPT;
215                 break;
216         case MSG_CMD_GET_CB_OPT :
217                 eventType = MSG_EVENT_GET_CB_OPT;
218                 break;
219         case MSG_CMD_GET_SMS_SEND_OPT :
220                 eventType = MSG_EVENT_GET_SMS_SEND_OPT;
221                 break;
222         case MSG_CMD_GET_MMS_SEND_OPT :
223                 eventType = MSG_EVENT_GET_MMS_SEND_OPT;
224                 break;
225         case MSG_CMD_GET_MMS_RECV_OPT :
226                 eventType = MSG_EVENT_GET_MMS_RECV_OPT;
227                 break;
228         case MSG_CMD_GET_PUSH_MSG_OPT :
229                 eventType = MSG_EVENT_GET_PUSH_MSG_OPT;
230                 break;
231         case MSG_CMD_GET_VOICE_MSG_OPT :
232                 eventType = MSG_EVENT_GET_VOICE_MSG_OPT;
233                 break;
234         case MSG_CMD_GET_GENERAL_MSG_OPT :
235                 eventType = MSG_EVENT_GET_GENERAL_MSG_OPT;
236                 break;
237         case MSG_CMD_GET_MSG_SIZE_OPT :
238                         eventType = MSG_EVENT_GET_MSG_SIZE_OPT;
239                 break;
240         default :
241                 break;
242         }
243
244         // Make Event Data
245         eventSize = MsgMakeEvent(encodedData, dataSize, eventType, err, (void**)ppEvent);
246
247         return eventSize;
248 }