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