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