RSA sync with private
[platform/core/messaging/msg-service.git] / mapi / msg_transport.cpp
1 /*
2 * Copyright 2012  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.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.tizenopensource.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->dataSize <= 0)
516         {
517                 MSG_FATAL("MMS data size is invalid");
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->pMmsData = read_report_data;
575
576         err = msg_submit_req(handle, req_t);
577         if (err == MSG_SUCCESS)
578                 MSG_DEBUG("Sending Message is OK!");
579         else
580                 MSG_DEBUG("Sending Message is failed!");
581
582         free(read_report_data);
583         read_report_data = NULL;
584         reqmsg->pMmsData = NULL;
585
586         msg_release_struct(&req_t);
587
588         return err;
589 }
590
591
592 EXPORT_API int msg_mms_forward_message(msg_handle_t handle, msg_struct_t req)
593 {
594         msg_error_t err =  MSG_SUCCESS;
595
596         if (handle == NULL || !req )
597         {
598                 MSG_FATAL("handle or req is NULL");
599                 return MSG_ERR_INVALID_PARAMETER;
600         }
601
602         msg_struct_s *req_s = (msg_struct_s *)req;
603         MSG_REQUEST_S *pReq = (MSG_REQUEST_S *)req_s->data;
604
605         pReq->reqId = 1;
606
607         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
608
609         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
610
611         reqmsg->mainType = MSG_MMS_TYPE;
612         reqmsg->subType = MSG_FORWARD_MMS;
613         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
614         reqmsg->networkStatus = MSG_NETWORK_SENDING;
615
616         err = msg_submit_req(handle, req);
617
618         if (err == MSG_SUCCESS)
619                 MSG_DEBUG("Sending Message is OK!");
620         else
621                 MSG_DEBUG("Sending Message is failed!");
622
623         return err;
624 }
625
626
627 EXPORT_API int msg_mms_retrieve_message(msg_handle_t handle, msg_struct_t req)
628 {
629         msg_error_t err = MSG_SUCCESS;
630
631         if ( handle == NULL|| !req)
632         {
633                 MSG_FATAL("handle or req is NULL");
634                 return MSG_ERR_INVALID_PARAMETER;
635         }
636
637         msg_struct_s *req_s = (msg_struct_s *)req;
638         MSG_REQUEST_S *pReq = (MSG_REQUEST_S *)req_s->data;
639
640         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
641         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
642
643         reqmsg->mainType = MSG_MMS_TYPE;
644         reqmsg->subType = MSG_RETRIEVE_MMS;
645         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
646         reqmsg->networkStatus = MSG_NETWORK_RETRIEVING;
647
648         err = msg_submit_req(handle, req);
649
650         if (err == MSG_SUCCESS)
651                 MSG_DEBUG("Sending Message is OK!");
652         else
653                 MSG_DEBUG("Sending Message is failed!");
654
655         return err;
656 }
657
658
659 /* reject_msg_support */
660 EXPORT_API int msg_mms_reject_message(msg_handle_t handle, msg_struct_t req)
661 {
662         msg_error_t err = MSG_SUCCESS;
663
664         if (handle == NULL || !req )
665         {
666                 MSG_FATAL("handle or req is NULL");
667                 return MSG_ERR_INVALID_PARAMETER;
668         }
669
670         msg_struct_s *req_s = (msg_struct_s *)req;
671         MSG_REQUEST_S *pReq = (MSG_REQUEST_S *)req_s->data;
672
673         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
674         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
675
676         reqmsg->mainType = MSG_MMS_TYPE;
677         reqmsg->subType = MSG_NOTIFYRESPIND_MMS;
678         reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
679         reqmsg->networkStatus = MSG_NETWORK_SENDING;
680
681         err = msg_submit_req(handle, req);
682
683         if (err == MSG_SUCCESS)
684                 MSG_DEBUG("Sending Message is OK!");
685         else
686                 MSG_DEBUG("Sending Message is failed!");
687
688         return err;
689 }
690 /* reject_msg_support */
691
692
693 int msg_request_get_int(void *request_info, int field)
694 {
695         int result = -1;
696         MSG_REQUEST_S *pRequest = (MSG_REQUEST_S *)request_info;
697         switch(field)
698         {
699         case MSG_REQUEST_REQUESTID_INT:
700                 result = pRequest->reqId;
701                 break;
702
703         default:
704                 break;
705         }
706         return result;
707 }
708
709
710 int msg_request_get_struct_handle(msg_struct_s *msg_struct, int field, void **value)
711 {
712         msg_error_t err =  MSG_SUCCESS;
713
714         if(!msg_struct || !value)
715                 return MSG_ERR_NULL_POINTER;
716
717         MSG_REQUEST_S *pRequest = (MSG_REQUEST_S *)msg_struct->data;
718         switch(field)
719         {
720         case MSG_REQUEST_MESSAGE_HND:
721                 *value = (void *)pRequest->msg;
722                 break;
723         case MSG_REQUEST_SENDOPT_HND:
724                 *value = (void *)pRequest->sendOpt;
725                 break;
726         default:
727                 err = MSG_ERR_UNKNOWN;
728                 break;
729
730         }
731         return err;
732 }
733
734 int msg_request_set_int(void *request_info, int field, int value)
735 {
736         msg_error_t err =  MSG_SUCCESS;
737         if(!request_info)
738                 return MSG_ERR_NULL_POINTER;
739
740         MSG_REQUEST_S *pRequest = (MSG_REQUEST_S *)request_info;
741         switch(field)
742         {
743         case MSG_REQUEST_REQUESTID_INT:
744                 pRequest->reqId = value;
745                 break;
746         default:
747                 err = MSG_ERR_UNKNOWN;
748         break;
749         }
750
751         return err;
752 }
753
754 int msg_request_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value)
755 {
756         msg_error_t err =  MSG_SUCCESS;
757         if(!msg_struct || !value)
758                 return MSG_ERR_NULL_POINTER;
759
760         MSG_REQUEST_S *pRequest = (MSG_REQUEST_S *)msg_struct->data;
761         msg_struct_s *pTmp = NULL;
762
763
764         switch(field)
765         {
766         case MSG_REQUEST_MESSAGE_HND:
767         {
768                 pTmp = (msg_struct_s *)pRequest->msg;
769                 MSG_MESSAGE_HIDDEN_S *pSrc = (MSG_MESSAGE_HIDDEN_S *)value->data;
770                 MSG_MESSAGE_HIDDEN_S *pDst = (MSG_MESSAGE_HIDDEN_S *)pTmp->data;
771                 msg_message_copy_message(pSrc, pDst);
772                 break;
773         }
774         case MSG_REQUEST_SENDOPT_HND:
775         {
776                 pTmp = (msg_struct_s *)pRequest->sendOpt;
777                 MSG_SENDINGOPT_S *pSrc = (MSG_SENDINGOPT_S *)value->data;
778                 MSG_SENDINGOPT_S *pDst = (MSG_SENDINGOPT_S *)pTmp->data;
779                 pDst->bDeliverReq = pSrc->bDeliverReq;
780                 pDst->bKeepCopy = pSrc->bKeepCopy;
781                 pDst->bSetting = pSrc->bSetting;
782
783                 msg_struct_s *tmpDstMmsSendOpt = (msg_struct_s *)pDst->mmsSendOpt;
784                 msg_struct_s *tmpDstSmsSendOpt = (msg_struct_s *)pDst->smsSendOpt;
785
786                 msg_struct_s *tmpSrcMmsSendOpt = (msg_struct_s *)pDst->mmsSendOpt;
787                 msg_struct_s *tmpSrcSmsSendOpt = (msg_struct_s *)pDst->smsSendOpt;
788
789                 tmpDstMmsSendOpt->type = tmpSrcMmsSendOpt->type;
790                 memcpy(tmpDstMmsSendOpt->data, tmpSrcMmsSendOpt->data, sizeof(MMS_SENDINGOPT_S));
791
792                 tmpDstSmsSendOpt->type = tmpSrcSmsSendOpt->type;
793                 memcpy(tmpDstSmsSendOpt->data, tmpSrcSmsSendOpt->data, sizeof(SMS_SENDINGOPT_S));
794
795                 break;
796         }
797         default:
798                 err = MSG_ERR_UNKNOWN;
799                 break;
800         }
801         return err;
802 }
803
804
805 int msg_sent_status_get_int(MSG_SENT_STATUS_S *sent_status_info, int field)
806 {
807         int result = -1;
808
809         switch(field)
810         {
811         case MSG_SENT_STATUS_REQUESTID_INT:
812                 result = sent_status_info->reqId;
813                 break;
814         case MSG_SENT_STATUS_NETWORK_STATUS_INT:
815                 result = sent_status_info->status;
816                 break;
817         default:
818                 break;
819         }
820         return result;
821 }