Sync with tizen 2.4
[platform/core/messaging/msg-service.git] / mapi / msg_transport.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 <errno.h>
18 #include <privacy_checker_client.h>
19
20 #include "MsgHandle.h"
21 #include "MsgDebug.h"
22 #include "MsgException.h"
23 #include "MsgUtilFunction.h"
24
25 #include "msg.h"
26 #include "msg_private.h"
27 #include "msg_transport.h"
28
29
30 /*==================================================================================================
31                                      FUNCTION IMPLEMENTATION
32 ==================================================================================================*/
33 EXPORT_API int msg_submit_req(msg_handle_t handle, msg_struct_t req)
34 {
35         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
36         msg_error_t err =  MSG_SUCCESS;
37
38         //Privilege check
39         int ret = PRIV_MGR_ERROR_SUCCESS;
40         ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
41         if(ret != PRIV_MGR_ERROR_SUCCESS)
42         {
43                 return MSG_ERR_PERMISSION_DENIED;
44         }
45
46         if (handle == NULL ||req == NULL)
47         {
48                 return MSG_ERR_INVALID_PARAMETER;
49         }
50
51         MsgHandle* pHandle = (MsgHandle*)handle;
52
53         msg_struct_s *pStruct = (msg_struct_s *)req;
54
55         try
56         {
57                 err = pHandle->submitReq((MSG_REQUEST_S *)pStruct->data);
58         }
59         catch (MsgException& e)
60         {
61                 MSG_FATAL("%s", e.what());
62                 return MSG_ERR_TRANSPORT_ERROR;
63         }
64
65         return err;
66 }
67
68
69 EXPORT_API int msg_reg_sent_status_callback(msg_handle_t handle, msg_sent_status_cb cb, void *user_param)
70 {
71         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
72         msg_error_t err =  MSG_SUCCESS;
73
74         //Privilege check
75         int ret = PRIV_MGR_ERROR_SUCCESS;
76         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
77         if(ret != PRIV_MGR_ERROR_SUCCESS)
78         {
79                 return MSG_ERR_PERMISSION_DENIED;
80         }
81
82         if (handle == NULL || cb == NULL)
83         {
84                 return MSG_ERR_INVALID_PARAMETER;
85         }
86
87         MsgHandle* pHandle = (MsgHandle*)handle;
88
89         try
90         {
91                 err = pHandle->regSentStatusCallback(cb, user_param);
92         }
93         catch (MsgException& e)
94         {
95                 MSG_FATAL("%s", e.what());
96                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
97                         return MSG_ERR_PERMISSION_DENIED;
98                 else
99                         return MSG_ERR_CALLBACK_ERROR;
100         }
101
102         return err;
103 }
104
105
106 EXPORT_API int msg_reg_sms_message_callback(msg_handle_t handle, msg_sms_incoming_cb cb, unsigned short port, void *user_param)
107 {
108         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
109         msg_error_t err =  MSG_SUCCESS;
110
111         //Privilege check
112         int ret = PRIV_MGR_ERROR_SUCCESS;
113         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
114         if(ret != PRIV_MGR_ERROR_SUCCESS)
115         {
116                 return MSG_ERR_PERMISSION_DENIED;
117         }
118
119         if (handle == NULL || cb == NULL)
120         {
121                 return MSG_ERR_INVALID_PARAMETER;
122         }
123
124         MsgHandle* pHandle = (MsgHandle*)handle;
125
126         try
127         {
128                 err = pHandle->regSmsMessageCallback(cb, port, user_param);
129         }
130         catch (MsgException& e)
131         {
132                 MSG_FATAL("%s", e.what());
133                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
134                         return MSG_ERR_PERMISSION_DENIED;
135                 else
136                         return MSG_ERR_CALLBACK_ERROR;
137         }
138
139         return err;
140 }
141
142
143 EXPORT_API int msg_reg_mms_conf_message_callback(msg_handle_t handle, msg_mms_conf_msg_incoming_cb cb, const char *app_id, void *user_param)
144 {
145         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_MMS_FEATURE);
146         msg_error_t err =  MSG_SUCCESS;
147
148         //Privilege check
149         int ret = PRIV_MGR_ERROR_SUCCESS;
150         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
151         if(ret != PRIV_MGR_ERROR_SUCCESS)
152         {
153                 return MSG_ERR_PERMISSION_DENIED;
154         }
155
156         if (handle == NULL || cb == NULL)
157         {
158                 return MSG_ERR_INVALID_PARAMETER;
159         }
160
161         if (app_id && strlen(app_id) > MAX_MMS_JAVA_APPID_LEN)
162         {
163                 return MSG_ERR_INVALID_PARAMETER;
164         }
165
166         MsgHandle* pHandle = (MsgHandle*)handle;
167
168         try
169         {
170                 err = pHandle->regMmsConfMessageCallback(cb, app_id, user_param);
171         }
172         catch (MsgException& e)
173         {
174                 MSG_FATAL("%s", e.what());
175                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
176                         return MSG_ERR_PERMISSION_DENIED;
177                 else
178                         return MSG_ERR_CALLBACK_ERROR;
179         }
180
181         return err;
182 }
183
184
185 EXPORT_API int msg_reg_syncml_message_callback(msg_handle_t handle,  msg_syncml_msg_incoming_cb cb, void *user_param)
186 {
187         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
188         msg_error_t err =  MSG_SUCCESS;
189
190         //Privilege check
191         int ret = PRIV_MGR_ERROR_SUCCESS;
192         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
193         if(ret != PRIV_MGR_ERROR_SUCCESS)
194         {
195                 return MSG_ERR_PERMISSION_DENIED;
196         }
197
198         if (handle == NULL || cb == NULL)
199         {
200                 return MSG_ERR_INVALID_PARAMETER;
201         }
202
203         MsgHandle* pHandle = (MsgHandle*)handle;
204
205         try
206         {
207                 err = pHandle->regSyncMLMessageCallback(cb, user_param);
208         }
209         catch (MsgException& e)
210         {
211                 MSG_FATAL("%s", e.what());
212                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
213                         return MSG_ERR_PERMISSION_DENIED;
214                 else
215                         return MSG_ERR_CALLBACK_ERROR;
216         }
217
218         return err;
219 }
220
221
222 EXPORT_API int msg_reg_lbs_message_callback(msg_handle_t handle, msg_lbs_msg_incoming_cb cb, void *user_param)
223 {
224         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
225         msg_error_t err =  MSG_SUCCESS;
226
227         //Privilege check
228         int ret = PRIV_MGR_ERROR_SUCCESS;
229         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
230         if(ret != PRIV_MGR_ERROR_SUCCESS)
231         {
232                 return MSG_ERR_PERMISSION_DENIED;
233         }
234
235         if (handle == NULL || cb == NULL)
236         {
237                 return MSG_ERR_INVALID_PARAMETER;
238         }
239
240         MsgHandle* pHandle = (MsgHandle*)handle;
241
242         try
243         {
244                 err = pHandle->regLBSMessageCallback(cb, user_param);
245         }
246         catch (MsgException& e)
247         {
248                 MSG_FATAL("%s", e.what());
249                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
250                         return MSG_ERR_PERMISSION_DENIED;
251                 else
252                         return MSG_ERR_CALLBACK_ERROR;
253         }
254
255         return err;
256 }
257
258
259 EXPORT_API int msg_reg_syncml_message_operation_callback(msg_handle_t handle,  msg_syncml_msg_operation_cb cb, void *user_param)
260 {
261         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
262         msg_error_t err =  MSG_SUCCESS;
263
264         //Privilege check
265         int ret = PRIV_MGR_ERROR_SUCCESS;
266         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
267         if(ret != PRIV_MGR_ERROR_SUCCESS)
268         {
269                 return MSG_ERR_PERMISSION_DENIED;
270         }
271
272         if (handle == NULL || cb == NULL)
273         {
274                 return MSG_ERR_INVALID_PARAMETER;
275         }
276
277         MsgHandle* pHandle = (MsgHandle*)handle;
278
279         try
280         {
281                 err = pHandle->regSyncMLMessageOperationCallback(cb, user_param);
282         }
283         catch (MsgException& e)
284         {
285                 MSG_FATAL("%s", e.what());
286                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
287                         return MSG_ERR_PERMISSION_DENIED;
288                 else
289                         return MSG_ERR_CALLBACK_ERROR;
290         }
291
292         return err;
293 }
294
295
296 EXPORT_API int msg_reg_push_message_callback(msg_handle_t handle,  msg_push_msg_incoming_cb cb, const char *app_id, void *user_param)
297 {
298         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
299         msg_error_t err =  MSG_SUCCESS;
300
301         //Privilege check
302         int ret = PRIV_MGR_ERROR_SUCCESS;
303         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
304         if(ret != PRIV_MGR_ERROR_SUCCESS)
305         {
306                 return MSG_ERR_PERMISSION_DENIED;
307         }
308
309         if (handle == NULL || cb == NULL)
310         {
311                 return MSG_ERR_INVALID_PARAMETER;
312         }
313
314         if (app_id && strlen(app_id) > MAX_WAPPUSH_ID_LEN)
315         {
316                 return MSG_ERR_INVALID_PARAMETER;
317         }
318
319         MsgHandle* pHandle = (MsgHandle*)handle;
320
321         try
322         {
323                 err = pHandle->regPushMessageCallback(cb, app_id, user_param);
324         }
325         catch (MsgException& e)
326         {
327                 MSG_FATAL("%s", e.what());
328                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
329                         return MSG_ERR_PERMISSION_DENIED;
330                 else
331                         return MSG_ERR_CALLBACK_ERROR;
332         }
333
334         return err;
335 }
336
337 EXPORT_API int msg_reg_cb_message_callback(msg_handle_t handle, msg_cb_incoming_cb  cb, bool bsave, void *user_param)
338 {
339         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
340         msg_error_t err =  MSG_SUCCESS;
341
342         //Privilege check
343         int ret = PRIV_MGR_ERROR_SUCCESS;
344         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
345         if(ret != PRIV_MGR_ERROR_SUCCESS)
346         {
347                 return MSG_ERR_PERMISSION_DENIED;
348         }
349
350         if (handle == NULL || cb == NULL)
351         {
352                 return MSG_ERR_INVALID_PARAMETER;
353         }
354
355         MsgHandle* pHandle = (MsgHandle*)handle;
356
357         try
358         {
359                 err = pHandle->regCBMessageCallback(cb, bsave, user_param);
360         }
361         catch (MsgException& e)
362         {
363                 MSG_FATAL("%s", e.what());
364                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
365                         return MSG_ERR_PERMISSION_DENIED;
366                 else
367                         return MSG_ERR_CALLBACK_ERROR;
368         }
369
370         return err;
371 }
372
373
374 EXPORT_API int msg_reg_report_message_callback(msg_handle_t handle, msg_report_msg_incoming_cb cb, void *user_param)
375 {
376         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
377         msg_error_t err =  MSG_SUCCESS;
378
379         //Privilege check
380         int ret = PRIV_MGR_ERROR_SUCCESS;
381         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
382         if(ret != PRIV_MGR_ERROR_SUCCESS)
383         {
384                 return MSG_ERR_PERMISSION_DENIED;
385         }
386
387         if (handle == NULL || cb == NULL)
388         {
389                 return MSG_ERR_INVALID_PARAMETER;
390         }
391
392         MsgHandle* pHandle = (MsgHandle*)handle;
393
394         try
395         {
396                 err = pHandle->regReportMessageCallback(cb, user_param);
397         }
398         catch (MsgException& e)
399         {
400                 MSG_FATAL("%s", e.what());
401                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
402                         return MSG_ERR_PERMISSION_DENIED;
403                 else
404                         return MSG_ERR_CALLBACK_ERROR;
405         }
406
407         return err;
408 }
409
410
411 EXPORT_API int msg_syncml_message_operation(msg_handle_t handle,  msg_message_id_t msgId)
412 {
413         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
414         msg_error_t err =  MSG_SUCCESS;
415
416         //Privilege check
417         int ret = PRIV_MGR_ERROR_SUCCESS;
418         ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
419         if(ret != PRIV_MGR_ERROR_SUCCESS)
420         {
421                 return MSG_ERR_PERMISSION_DENIED;
422         }
423
424         if (handle == NULL || msgId < 1)
425         {
426                 return MSG_ERR_INVALID_PARAMETER;
427         }
428
429         MsgHandle* pHandle = (MsgHandle*)handle;
430
431         try
432         {
433                 err = pHandle->operateSyncMLMessage(msgId);
434         }
435         catch (MsgException& e)
436         {
437                 MSG_FATAL("%s", e.what());
438                 return MSG_ERR_TRANSPORT_ERROR;
439         }
440
441         return err;
442 }
443
444
445 static msg_handle_t msgHandle = NULL;
446 static msg_simple_sent_status_cb sentStatusCallback = NULL;
447
448 static void sent_status_cb_func(msg_handle_t handle, msg_struct_t sent_status, void *user_param)
449 {
450 //      MSG_DEBUG("Sent Status [%d]", sent_status->status);
451
452         msg_simple_sent_status_cb pfunc = sentStatusCallback;
453 // TODO : Fixme
454         pfunc((msg_struct_t)sent_status, user_param);
455
456         MSG_DEBUG("After entering callback function.");
457
458         // Close control handle instance
459         //      msg_close_msg_handle(&msgHandle);
460
461         //      MSG_DEBUG("After msg_close_msg_handle.");
462
463 }
464
465
466 static int msg_send_single_sms(const char *phone_num, const char *sms_text, msg_simple_sent_status_cb cb, void *user_param)
467 {
468         if (phone_num == NULL || sms_text == NULL || cb == NULL)
469         {
470                 MSG_SEC_DEBUG("Invalid parameter [%s] [%s] [%s]", phone_num, sms_text, cb);
471                 return MSG_ERR_INVALID_PARAMETER;
472         }
473
474         if (strlen(phone_num) > MAX_PHONE_NUMBER_LEN)
475         {
476                 MSG_SEC_DEBUG("Phone Number is too long [%s]", phone_num);
477                 return MSG_ERR_INVALID_PARAMETER;
478         }
479
480         msg_struct_s req = {0,};
481         MSG_REQUEST_S msgReq = {0};
482
483         req.type = MSG_STRUCT_REQUEST_INFO;
484         req.data = (void *)&msgReq;
485
486         msg_error_t retVal = MSG_SUCCESS;
487
488         // Open control handle instance
489         if ((retVal = msg_open_msg_handle(&msgHandle)) != MSG_SUCCESS)
490         {
491                 MSG_DEBUG("MsgOpenMsgHandle is failed. Error Code = %d", retVal);
492                 return retVal;
493         }
494
495         //msgReq.msg = msg_new_message();
496         MSG_MESSAGE_HIDDEN_S msg_info = {0,};
497         msg_struct_s msg = {0,};
498
499         msg.type = MSG_STRUCT_MESSAGE_INFO;
500         msg.data = &msg_info;
501
502         /* when sending SMS */
503         msg_info.mainType = MSG_SMS_TYPE;
504         msg_info.subType = MSG_NORMAL_SMS;
505         msg_info.msgId = 0;
506         msg_info.folderId = MSG_OUTBOX_ID;
507         msg_info.simIndex = MSG_SIM_SLOT_ID_1;
508
509         /* fill the destination number in msgReq */
510         MSG_ADDRESS_INFO_S address = {0,};
511         memset(&address, 0x00, sizeof(MSG_ADDRESS_INFO_S));
512
513         address.addressType = MSG_ADDRESS_TYPE_PLMN;
514         address.recipientType = MSG_RECIPIENTS_TYPE_TO;
515         snprintf(address.addressVal, MAX_ADDRESS_VAL_LEN, "%s", phone_num);
516
517         msg_struct_list_s addr_list = {0,};
518
519         addr_list.nCount = 1;
520         addr_list.msg_struct_info = (msg_struct_t *)calloc(1, sizeof(msg_struct_t));
521         addr_list.msg_struct_info[0] = (msg_struct_t)new msg_struct_s;
522
523         msg_struct_s *pTmp;
524         pTmp = (msg_struct_s *)addr_list.msg_struct_info[0];
525         pTmp->type = MSG_STRUCT_ADDRESS_INFO;
526         pTmp->data = &address;
527
528         msg_info.addr_list = (msg_struct_list_s *)&addr_list;
529
530         msg_info.bPortValid = false;
531
532         /* fill the msg text in msgReq */
533         msg_info.dataSize = strlen(sms_text);
534         msg_info.pData = (void*)sms_text;
535
536         /* Send option */
537         msg_struct_s sendOpt = {0,};
538         MSG_SENDINGOPT_S send_info;
539         memset(&send_info, 0x00, sizeof(MSG_SENDINGOPT_S));
540
541         sendOpt.type = MSG_STRUCT_SENDOPT;
542         sendOpt.data = (void *)&send_info;
543
544         msg_struct_s smsSendOpt = {0,};
545         SMS_SENDINGOPT_INFO_S sms_send_opt = {0,};
546         memset(&sms_send_opt, 0x00, sizeof(SMS_SENDINGOPT_INFO_S));
547
548         smsSendOpt.type = MSG_STRUCT_SMS_SENDOPT;
549         smsSendOpt.data = (void *)&sms_send_opt;
550
551         send_info.smsSendOpt = (msg_struct_t)&smsSendOpt;
552
553         sentStatusCallback = cb;
554
555         // register sent status callback
556         retVal = msg_reg_sent_status_callback(msgHandle, sent_status_cb_func, user_param);
557
558         if (retVal != MSG_SUCCESS)
559         {
560                 MSG_DEBUG("msg_reg_sent_status_callback() is failed. Error Code = %d", retVal);
561                 msg_close_msg_handle(&msgHandle);
562                 return retVal;
563         }
564
565         // sending message request
566         msgReq.msg = (msg_struct_t)&msg;
567         msgReq.sendOpt = (msg_struct_t)&sendOpt;
568
569         retVal = msg_submit_req(msgHandle, (msg_struct_t)&req);
570
571         if (addr_list.msg_struct_info) {
572                 g_free(addr_list.msg_struct_info);
573                 addr_list.msg_struct_info = NULL;
574         }
575
576         if (retVal != MSG_SUCCESS)
577         {
578                 MSG_DEBUG("msg_submit_req() is failed. Error Code = %d", retVal);
579                 msg_close_msg_handle(&msgHandle);
580                 return retVal;
581         }
582
583         return MSG_SUCCESS;
584 }
585
586 EXPORT_API int msg_sms_send(const char *phone_num_list, const char *sms_text, msg_simple_sent_status_cb cb, void *user_param)
587 {
588         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
589         //Privilege check
590         int ret = PRIV_MGR_ERROR_SUCCESS;
591         ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
592         if(ret != PRIV_MGR_ERROR_SUCCESS)
593         {
594                 return MSG_ERR_PERMISSION_DENIED;
595         }
596
597         if (phone_num_list == NULL || sms_text == NULL || cb == NULL)
598         {
599                 MSG_SEC_DEBUG("Invalid parameter [%s] [%s] [%s]", phone_num_list, sms_text, cb);
600                 return MSG_ERR_INVALID_PARAMETER;
601         }
602
603         char trimmed_num[strlen(phone_num_list)+1];
604         bzero(trimmed_num, strlen(phone_num_list)+1);
605
606         msg_error_t retVal = msg_verify_number(phone_num_list, trimmed_num);
607
608         if ( retVal != MSG_SUCCESS )
609                 return retVal;
610
611         for( char* cur_num = strtok(trimmed_num,", "); cur_num ; cur_num = strtok(NULL,", "))
612         {
613                 if (strlen(cur_num) > MAX_PHONE_NUMBER_LEN)
614                 {
615                         MSG_SEC_DEBUG("Phone number is too long [%s], and sending is skipped", cur_num);
616                         continue;
617                 }
618
619                 MSG_SEC_DEBUG("phone number: [%s]", cur_num);
620                 MSG_SEC_DEBUG("text: [%s]", sms_text);
621                 retVal = msg_send_single_sms(cur_num, sms_text, cb, user_param);
622
623                 if (retVal != MSG_SUCCESS)
624                         return retVal;
625         }
626
627         return MSG_SUCCESS;
628 }
629
630
631 EXPORT_API int msg_sms_send_message(msg_handle_t handle, msg_struct_t req)
632 {
633         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_FEATURE);
634         msg_error_t err =  MSG_SUCCESS;
635
636         //Privilege check
637         int ret = PRIV_MGR_ERROR_SUCCESS;
638         ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
639         if(ret != PRIV_MGR_ERROR_SUCCESS)
640         {
641                 return MSG_ERR_PERMISSION_DENIED;
642         }
643
644         if (handle == NULL || !req) {
645                 MSG_FATAL("handle or req is NULL");
646                 return MSG_ERR_NULL_POINTER;
647         }
648
649         msg_struct_s *req_s = (msg_struct_s *)req;
650         MSG_REQUEST_S *pReq = (MSG_REQUEST_S *)req_s->data;
651
652         pReq->reqId = 1;
653
654         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
655
656         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
657
658         if (reqmsg->dataSize <= 0) {
659                 MSG_FATAL("msg size is invalid : [%d]", reqmsg->dataSize);
660                 return MSG_ERR_INVALID_PARAMETER;
661         }
662
663         if (reqmsg->mainType != MSG_SMS_TYPE) {
664                 MSG_DEBUG("mainType is not SMS [%d]", reqmsg->mainType);
665                 reqmsg->mainType = MSG_SMS_TYPE;
666         }
667
668         if (reqmsg->subType > MSG_CONCAT_SIM_SMS) {
669                 MSG_DEBUG("subType is not SMS [%d]", reqmsg->subType);
670                 reqmsg->subType = MSG_NORMAL_SMS;
671         }
672
673         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
674         reqmsg->networkStatus = MSG_NETWORK_SENDING;
675
676         MSG_DEBUG("Coding Scheme From App. = [%d]", reqmsg->encodeType);
677
678         err = msg_submit_req(handle, req);
679
680         if (err == MSG_SUCCESS)
681                 MSG_DEBUG("Sending Message is OK!");
682         else
683                 MSG_DEBUG("Sending Message is failed! [%d]", err);
684
685         return err;
686 }
687
688
689 EXPORT_API int msg_mms_send_message(msg_handle_t handle, msg_struct_t req)
690 {
691         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_MMS_FEATURE);
692         msg_error_t err =  MSG_SUCCESS;
693
694         //Privilege check
695         int ret = PRIV_MGR_ERROR_SUCCESS;
696         ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
697         if(ret != PRIV_MGR_ERROR_SUCCESS)
698         {
699                 return MSG_ERR_PERMISSION_DENIED;
700         }
701
702         if (handle == NULL || !req)
703         {
704                 MSG_FATAL("handle or req is NULL");
705                 return MSG_ERR_INVALID_PARAMETER;
706         }
707
708         msg_struct_s *req_s = (msg_struct_s *)req;
709         MSG_REQUEST_S *pReq = (MSG_REQUEST_S *)req_s->data;
710
711         pReq->reqId = 1;
712
713         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
714
715         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
716
717         if (reqmsg->mmsDataSize <= 0)
718         {
719                 MSG_FATAL("MMS data size is invalid");
720                 return MSG_ERR_INVALID_PARAMETER;
721         }
722
723         reqmsg->mainType = MSG_MMS_TYPE;
724         reqmsg->subType = MSG_SENDREQ_MMS;
725         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
726         reqmsg->networkStatus = MSG_NETWORK_SENDING;
727
728         err = msg_submit_req(handle, req);
729
730         if (err == MSG_SUCCESS)
731                 MSG_DEBUG("Sending Message is OK!");
732         else
733                 MSG_DEBUG("Sending Message is failed! [%d]", err);
734
735         return err;
736 }
737
738
739 EXPORT_API int msg_mms_send_read_report(msg_handle_t handle, msg_message_id_t msgId, msg_read_report_status_t mms_read_status)
740 {
741         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_MMS_FEATURE);
742         msg_error_t err = MSG_SUCCESS;
743
744         //Privilege check
745         int ret = PRIV_MGR_ERROR_SUCCESS;
746         ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
747         if(ret != PRIV_MGR_ERROR_SUCCESS)
748         {
749                 return MSG_ERR_PERMISSION_DENIED;
750         }
751
752         if (handle == NULL)
753         {
754                 return MSG_ERR_INVALID_PARAMETER;
755         }
756
757         msg_struct_t req_t = msg_create_struct(MSG_STRUCT_REQUEST_INFO);
758
759         msg_struct_s *req_s = (msg_struct_s *)req_t;
760         MSG_REQUEST_S *req = (MSG_REQUEST_S *)req_s->data;
761         msg_struct_s *msg_s = (msg_struct_s *)req->msg;
762         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S *)msg_s->data;
763         void *read_report_data = NULL;
764         size_t read_report_datasize;
765
766         read_report_datasize = sizeof(msg_read_report_status_t);
767         read_report_data = (void *)calloc(read_report_datasize, 1);
768         if(read_report_data == NULL) {
769                 msg_release_struct(&req_t);
770                 return MSG_ERR_MEMORY_ERROR;
771         }
772
773         MSG_DEBUG("mms_read_status [%d]", mms_read_status);
774         memcpy(read_report_data, &mms_read_status, read_report_datasize);
775
776         req->reqId = 1;
777
778         reqmsg->bPortValid = false;
779         reqmsg->msgId = msgId;
780         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
781         reqmsg->mainType = MSG_MMS_TYPE;
782         reqmsg->subType = MSG_READREPLY_MMS;
783
784         reqmsg->mmsDataSize = read_report_datasize;
785         reqmsg->pMmsData = read_report_data;
786
787         err = msg_submit_req(handle, req_t);
788         if (err == MSG_SUCCESS)
789                 MSG_DEBUG("Sending Message is OK!");
790         else
791                 MSG_DEBUG("Sending Message is failed!");
792
793         free(read_report_data);
794         read_report_data = NULL;
795         reqmsg->pMmsData = NULL;
796
797         msg_release_struct(&req_t);
798
799         return err;
800 }
801
802
803 EXPORT_API int msg_mms_forward_message(msg_handle_t handle, msg_struct_t req)
804 {
805         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_MMS_FEATURE);
806         msg_error_t err =  MSG_SUCCESS;
807
808         //Privilege check
809         int ret = PRIV_MGR_ERROR_SUCCESS;
810         ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
811         if(ret != PRIV_MGR_ERROR_SUCCESS)
812         {
813                 return MSG_ERR_PERMISSION_DENIED;
814         }
815
816         if (handle == NULL || !req )
817         {
818                 MSG_FATAL("handle or req is NULL");
819                 return MSG_ERR_INVALID_PARAMETER;
820         }
821
822         msg_struct_s *req_s = (msg_struct_s *)req;
823         MSG_REQUEST_S *pReq = (MSG_REQUEST_S *)req_s->data;
824
825         pReq->reqId = 1;
826
827         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
828
829         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
830
831         reqmsg->mainType = MSG_MMS_TYPE;
832         reqmsg->subType = MSG_FORWARD_MMS;
833         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
834         reqmsg->networkStatus = MSG_NETWORK_SENDING;
835
836         err = msg_submit_req(handle, req);
837
838         if (err == MSG_SUCCESS)
839                 MSG_DEBUG("Sending Message is OK!");
840         else
841                 MSG_DEBUG("Sending Message is failed!");
842
843         return err;
844 }
845
846
847 EXPORT_API int msg_mms_retrieve_message(msg_handle_t handle, msg_struct_t req)
848 {
849         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_MMS_FEATURE);
850         msg_error_t err = MSG_SUCCESS;
851
852         //Privilege check
853         int ret = PRIV_MGR_ERROR_SUCCESS;
854         ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
855         if(ret != PRIV_MGR_ERROR_SUCCESS)
856         {
857                 return MSG_ERR_PERMISSION_DENIED;
858         }
859
860         if ( handle == NULL|| !req)
861         {
862                 MSG_FATAL("handle or req is NULL");
863                 return MSG_ERR_INVALID_PARAMETER;
864         }
865
866         msg_struct_s *req_s = (msg_struct_s *)req;
867         MSG_REQUEST_S *pReq = (MSG_REQUEST_S *)req_s->data;
868
869         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
870         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
871
872         reqmsg->mainType = MSG_MMS_TYPE;
873         reqmsg->subType = MSG_RETRIEVE_MMS;
874         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
875         reqmsg->networkStatus = MSG_NETWORK_RETRIEVING;
876
877         err = msg_submit_req(handle, req);
878
879         if (err == MSG_SUCCESS)
880                 MSG_DEBUG("Sending Message is OK!");
881         else
882                 MSG_DEBUG("Sending Message is failed!");
883
884         return err;
885 }
886
887
888 /* reject_msg_support */
889 EXPORT_API int msg_mms_reject_message(msg_handle_t handle, msg_struct_t req)
890 {
891         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_MMS_FEATURE);
892         msg_error_t err = MSG_SUCCESS;
893
894         //Privilege check
895         int ret = PRIV_MGR_ERROR_SUCCESS;
896         ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
897         if(ret != PRIV_MGR_ERROR_SUCCESS)
898         {
899                 return MSG_ERR_PERMISSION_DENIED;
900         }
901
902         if (handle == NULL || !req )
903         {
904                 MSG_FATAL("handle or req is NULL");
905                 return MSG_ERR_INVALID_PARAMETER;
906         }
907
908         msg_struct_s *req_s = (msg_struct_s *)req;
909         MSG_REQUEST_S *pReq = (MSG_REQUEST_S *)req_s->data;
910
911         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
912         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
913
914         reqmsg->mainType = MSG_MMS_TYPE;
915         reqmsg->subType = MSG_NOTIFYRESPIND_MMS;
916         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
917         reqmsg->networkStatus = MSG_NETWORK_SENDING;
918
919         err = msg_submit_req(handle, req);
920
921         if (err == MSG_SUCCESS)
922                 MSG_DEBUG("Sending Message is OK!");
923         else
924                 MSG_DEBUG("Sending Message is failed!");
925
926         return err;
927 }
928 /* reject_msg_support */
929
930
931 int msg_request_get_int(void *request_info, int field)
932 {
933         int result = -1;
934         MSG_REQUEST_S *pRequest = (MSG_REQUEST_S *)request_info;
935         switch(field)
936         {
937         case MSG_REQUEST_REQUESTID_INT:
938                 result = pRequest->reqId;
939                 break;
940
941         default:
942                 break;
943         }
944         return result;
945 }
946
947
948 int msg_request_get_struct_handle(msg_struct_s *msg_struct, int field, void **value)
949 {
950         msg_error_t err =  MSG_SUCCESS;
951
952         if(!msg_struct || !value)
953                 return MSG_ERR_NULL_POINTER;
954
955         MSG_REQUEST_S *pRequest = (MSG_REQUEST_S *)msg_struct->data;
956         switch(field)
957         {
958         case MSG_REQUEST_MESSAGE_HND:
959                 *value = (void *)pRequest->msg;
960                 break;
961         case MSG_REQUEST_SENDOPT_HND:
962                 *value = (void *)pRequest->sendOpt;
963                 break;
964         default:
965                 err = MSG_ERR_UNKNOWN;
966                 break;
967
968         }
969         return err;
970 }
971
972 int msg_request_set_int(void *request_info, int field, int value)
973 {
974         msg_error_t err =  MSG_SUCCESS;
975         if(!request_info)
976                 return MSG_ERR_NULL_POINTER;
977
978         MSG_REQUEST_S *pRequest = (MSG_REQUEST_S *)request_info;
979         switch(field)
980         {
981         case MSG_REQUEST_REQUESTID_INT:
982                 pRequest->reqId = value;
983                 break;
984         default:
985                 err = MSG_ERR_UNKNOWN;
986         break;
987         }
988
989         return err;
990 }
991
992 int msg_request_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value)
993 {
994         msg_error_t err =  MSG_SUCCESS;
995         if(!msg_struct || !value)
996                 return MSG_ERR_NULL_POINTER;
997
998         MSG_REQUEST_S *pRequest = (MSG_REQUEST_S *)msg_struct->data;
999         msg_struct_s *pTmp = NULL;
1000
1001
1002         switch(field)
1003         {
1004         case MSG_REQUEST_MESSAGE_HND:
1005         {
1006                 pTmp = (msg_struct_s *)pRequest->msg;
1007                 MSG_MESSAGE_HIDDEN_S *pSrc = (MSG_MESSAGE_HIDDEN_S *)value->data;
1008                 MSG_MESSAGE_HIDDEN_S *pDst = (MSG_MESSAGE_HIDDEN_S *)pTmp->data;
1009                 msg_message_copy_message(pSrc, pDst);
1010                 break;
1011         }
1012         case MSG_REQUEST_SENDOPT_HND:
1013         {
1014                 pTmp = (msg_struct_s *)pRequest->sendOpt;
1015                 MSG_SENDINGOPT_S *pSrc = (MSG_SENDINGOPT_S *)value->data;
1016                 MSG_SENDINGOPT_S *pDst = (MSG_SENDINGOPT_S *)pTmp->data;
1017                 pDst->bDeliverReq = pSrc->bDeliverReq;
1018                 pDst->bKeepCopy = pSrc->bKeepCopy;
1019                 pDst->bSetting = pSrc->bSetting;
1020
1021                 msg_struct_s *tmpDstMmsSendOpt = (msg_struct_s *)pDst->mmsSendOpt;
1022                 msg_struct_s *tmpDstSmsSendOpt = (msg_struct_s *)pDst->smsSendOpt;
1023
1024                 msg_struct_s *tmpSrcMmsSendOpt = (msg_struct_s *)pDst->mmsSendOpt;
1025                 msg_struct_s *tmpSrcSmsSendOpt = (msg_struct_s *)pDst->smsSendOpt;
1026
1027                 tmpDstMmsSendOpt->type = tmpSrcMmsSendOpt->type;
1028                 memcpy(tmpDstMmsSendOpt->data, tmpSrcMmsSendOpt->data, sizeof(MMS_SENDINGOPT_S));
1029
1030                 tmpDstSmsSendOpt->type = tmpSrcSmsSendOpt->type;
1031                 memcpy(tmpDstSmsSendOpt->data, tmpSrcSmsSendOpt->data, sizeof(SMS_SENDINGOPT_S));
1032
1033                 break;
1034         }
1035         default:
1036                 err = MSG_ERR_UNKNOWN;
1037                 break;
1038         }
1039         return err;
1040 }
1041
1042
1043 int msg_sent_status_get_int(MSG_SENT_STATUS_S *sent_status_info, int field)
1044 {
1045         int result = -1;
1046
1047         switch(field)
1048         {
1049         case MSG_SENT_STATUS_REQUESTID_INT:
1050                 result = sent_status_info->reqId;
1051                 break;
1052         case MSG_SENT_STATUS_NETWORK_STATUS_INT:
1053                 result = sent_status_info->status;
1054                 break;
1055         default:
1056                 break;
1057         }
1058         return result;
1059 }