Modify flora license version.
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerSetting.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 "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 = (MSG_OPTION_TYPE_T*)pCmd->cmdData;
101
102         // Get Config Data
103         MSG_SETTING_S setting;
104         setting.type = *type;
105
106         err = MsgGetConfigData(&setting);
107
108         if (err == MSG_SUCCESS)
109         {
110                 MSG_DEBUG("Command Handle Success : MsgGetConfigData()");
111
112                 // Encoding Config Data
113                 switch (setting.type)
114                         {
115                                 case MSG_GENERAL_OPT :
116                                         dataSize += sizeof(MSG_GENERAL_OPT_S);
117                                         break;
118                                 case MSG_SMS_SENDOPT :
119                                         dataSize += sizeof(MSG_SMS_SENDOPT_S);
120                                         break;
121                                 case MSG_SMSC_LIST :
122                                         dataSize += sizeof(MSG_SMSC_LIST_S);
123                                         break;
124                                 case MSG_MMS_SENDOPT :
125                                         dataSize += sizeof(MSG_MMS_SENDOPT_S);
126                                         break;
127                                 case MSG_MMS_RECVOPT :
128                                         dataSize += sizeof(MSG_MMS_RECVOPT_S);
129                                         break;
130                                 case MSG_MMS_STYLEOPT :
131                                         dataSize += sizeof(MSG_MMS_STYLEOPT_S);
132                                         break;
133                                 case MSG_PUSHMSG_OPT :
134                                         dataSize += sizeof(MSG_PUSHMSG_OPT_S);
135                                         break;
136                                 case MSG_CBMSG_OPT :
137                                         dataSize += sizeof(MSG_CBMSG_OPT_S);
138                                         break;
139                                 case MSG_VOICEMAIL_OPT :
140                                         dataSize += sizeof(MSG_VOICEMAIL_OPT_S);
141                                         break;
142                                 case MSG_MSGSIZE_OPT :
143                                         dataSize += sizeof(MSG_MSGSIZE_OPT_S);
144                                         break;
145                                 default:
146                                         break;
147                         }
148
149                         encodedData = (char*)new char[dataSize];
150                         void* p = (void*)encodedData;
151
152                         switch (setting.type)
153                         {
154                         case MSG_GENERAL_OPT :
155                                 memcpy(p, &(setting.option.generalOpt), dataSize);
156                                 break;
157                         case MSG_SMS_SENDOPT :
158                                 memcpy(p, &(setting.option.smsSendOpt), dataSize);
159                                 break;
160                         case MSG_SMSC_LIST :
161                                 memcpy(p, &(setting.option.smscList), dataSize);
162                                 break;
163                         case MSG_MMS_SENDOPT :
164                                 memcpy(p, &(setting.option.mmsSendOpt), dataSize);
165                                 break;
166                         case MSG_MMS_RECVOPT :
167                                 memcpy(p, &(setting.option.mmsRecvOpt), dataSize);
168                                 break;
169                         case MSG_MMS_STYLEOPT :
170                                 memcpy(p, &(setting.option.mmsStyleOpt), dataSize);
171                                 break;
172                         case MSG_PUSHMSG_OPT :
173                                 memcpy(p, &(setting.option.pushMsgOpt), dataSize);
174                                 break;
175                         case MSG_CBMSG_OPT :
176                                 memcpy(p, &(setting.option.cbMsgOpt), dataSize);
177                                 break;
178                         case MSG_VOICEMAIL_OPT :
179                                 memcpy(p, &(setting.option.voiceMailOpt), dataSize);
180                                 break;
181                         case MSG_MSGSIZE_OPT :
182                                 memcpy(p, &(setting.option.msgSizeOpt), dataSize);
183                                 break;
184                         default:
185                                 break;
186                         }
187         } else {
188                 MSG_DEBUG("Command Handle Fail : MsgGetConfigData()");
189         }
190
191         MSG_DEBUG("dataSize [%d]", dataSize);
192
193         switch (pCmd->cmdType) {
194         case MSG_CMD_GET_SMSC_OPT :
195                 eventType = MSG_EVENT_GET_SMSC_OPT;
196                 break;
197         case MSG_CMD_GET_CB_OPT :
198                 eventType = MSG_EVENT_GET_CB_OPT;
199                 break;
200         case MSG_CMD_GET_SMS_SEND_OPT :
201                 eventType = MSG_EVENT_GET_SMS_SEND_OPT;
202                 break;
203         case MSG_CMD_GET_MMS_SEND_OPT :
204                 eventType = MSG_EVENT_GET_MMS_SEND_OPT;
205                 break;
206         case MSG_CMD_GET_MMS_RECV_OPT :
207                 eventType = MSG_EVENT_GET_MMS_RECV_OPT;
208                 break;
209         case MSG_CMD_GET_PUSH_MSG_OPT :
210                 eventType = MSG_EVENT_GET_PUSH_MSG_OPT;
211                 break;
212         case MSG_CMD_GET_VOICE_MSG_OPT :
213                 eventType = MSG_EVENT_GET_VOICE_MSG_OPT;
214                 break;
215         case MSG_CMD_GET_GENERAL_MSG_OPT :
216                 eventType = MSG_EVENT_GET_GENERAL_MSG_OPT;
217                 break;
218         case MSG_CMD_GET_MSG_SIZE_OPT :
219                         eventType = MSG_EVENT_GET_MSG_SIZE_OPT;
220                 break;
221         default :
222                 break;
223         }
224
225         // Make Event Data
226         eventSize = MsgMakeEvent(encodedData, dataSize, eventType, err, (void**)ppEvent);
227
228         return eventSize;
229 }