e98b95188601fd310b83b0ad53230229cbbfbde1
[platform/framework/web/wrt-plugins-tizen.git] / src / Messaging / Sms.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "Sms.h"
19 #include <vconf.h>
20 #include <net_connection.h>
21 #include <Commons/Exception.h>
22 #include "ReqReceiverMessage.h"
23 #include "Messaging.h"
24 #include "CallbackMgr.h"
25 #include "MsgServiceHandleMgr.h"
26 #include <Logger.h>
27
28 extern "C" {
29 #include <msg_storage.h>
30 }
31
32 using namespace std;
33
34 namespace {
35 const char* EMPTY_ID = "0";
36 }
37
38 namespace DeviceAPI {
39 namespace Messaging {
40
41 Sms::Sms(const string& id) :
42     IMessage(SMS, id),
43     m_messageData(NULL)
44 {
45     LoggerD("enter");
46     LoggerD("m_id=" << getIdRef());
47     LoggerD("m_msgType=" << getMessageType());
48
49     if (getIdRef().empty()) {
50         createNewMessage();
51     } else {
52         readExistingMessage();
53     }
54
55     Touch();
56 }
57
58 Sms::Sms(const std::string& id, const msg_struct_t msg_data) :
59         IMessage(SMS, id),
60         m_messageData(NULL)
61 {
62         LoggerD("enter");
63         LoggerD("m_id=" << getIdRef());
64         LoggerD("m_msgType=" << getMessageType());
65
66         LoggerD("created msg_data : " << msg_data);
67         m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
68         LoggerD("created m_messageData : " << m_messageData);
69
70         readConversationId(m_messageData);
71         readRecipientList(m_messageData);
72         readBody(m_messageData);
73         readFolder(m_messageData);
74         readDateTime(m_messageData);
75         readReadStatus(m_messageData);
76         readSize(m_messageData);
77         readMessageStatus(m_messageData);
78 //      setMessageStatus(MESSAGE_STATUS_LOADED);
79         Touch();
80 }
81
82 Sms::~Sms()
83 {
84     LoggerD("enter");
85
86     if (m_messageData) {
87         // release platform message structure
88         LoggerD("release m_messageData : " << m_messageData);
89         msg_release_struct(&m_messageData);
90     }
91 }
92
93 void Sms::update(bool draftsOnly)
94 {
95     LoggerD("updating m_id=" << getIdRef());
96
97     if (!m_messageData) {
98         //error if platform message not exists
99         LoggerE("message can not be updated");
100         Throw(WrtDeviceApis::Commons::PlatformException);
101     }
102
103     //update all sms data
104     if (!draftsOnly || getCurrentFolder() == DRAFTBOX) {
105         updateBody();
106         updateFrom();
107         updateTo();
108         updateSourceAddress();
109     }
110     updateReadStatus();
111 }
112
113 void Sms::readAllData()
114 {
115         if (getIdRef().empty() || (EMPTY_ID == getIdRef())) {
116                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
117         }
118
119         // release old data
120         if (m_messageData) {
121                 // release platform message if it was created previously
122         msg_release_struct(&m_messageData);
123         m_messageData = NULL;
124         }
125         msg_struct_t sendOpt = NULL;
126
127         Try {
128                 // create new platform structure
129                 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
130                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
131
132                 msg_message_id_t l_id = convertId(getIdRef());
133                 LoggerD("reading message id=" << l_id);
134                 // trying to get message from platform
135                 if (MSG_SUCCESS == msg_get_message(MsgGetCommonHandle(), l_id, m_messageData, sendOpt)) 
136                 {
137                         LoggerD("message found with msgId=" << getIdRef());
138
139                         // read all mms dat to abstraction layer
140                         readConversationId(m_messageData);
141 //                      readRecipientList(m_messageData);
142                         readBody(m_messageData);
143                         readFolder(m_messageData);
144                         readDateTime(m_messageData);
145                         readReadStatus(m_messageData);
146                         readSize(m_messageData);
147                         readMessageStatus(m_messageData);
148
149                 } else {
150                         LoggerE("message not found with msgId=" << getIdRef());
151                         setId("");
152                         Throw(WrtDeviceApis::Commons::PlatformException);
153                 }
154
155                 msg_release_struct(&sendOpt);
156         }
157         Catch(WrtDeviceApis::Commons::PlatformException) {
158                 LoggerE("exception");
159                 // nothing to do
160                 msg_release_struct(&sendOpt);
161         }
162
163 }
164
165 void Sms::moveToFolder(const FolderType newFolder)
166 {
167 /*
168     update();
169
170     Try
171     {
172         const msg_folder_id_t platfromFolderId =
173             Messaging::convertFolderToPlatform(newFolder);
174
175         //call platform api to move message to other folder
176         if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
177                                    platfromFolderId) != MSG_SUCCESS) {
178             Throw(WrtDeviceApis::Commons::PlatformException);
179         }
180     }
181
182     Catch(WrtDeviceApis::Commons::PlatformException) {
183         LoggerE("remove message error");
184         throw;
185     }
186 */
187 }
188
189 void Sms::moveToFolder(const std::string& newFolder)
190 {
191 //    update();
192     //TODO
193 }
194
195 void Sms::copyToFolder(const FolderType newFolder)
196 {
197 /*
198     update();
199
200     msg_message_t msg = msg_new_message();
201
202     Try
203     {
204         MSG_SENDINGOPT_S option = { false, false, false };
205         option.option.smsSendOpt.bReplyPath = true;
206         // trying to get message from platform
207         if (MSG_SUCCESS ==
208             msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
209                             &option)) {
210             const msg_folder_id_t platfromFolderId =
211                 Messaging::convertFolderToPlatform(newFolder);
212             // new id will me set (initialize to 0)
213             msg_set_message_id(msg, 0);
214             msg_set_folder_id(msg, platfromFolderId);
215
216             // trying to add message
217             int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
218             if (error != MSG_SUCCESS) {
219                 LoggerE("msg_add_message failed, error code=" << error);
220                 Throw(WrtDeviceApis::Commons::PlatformException);
221             }
222
223             //releasing platform message structure
224             msg_release_message(&msg);
225         }
226     }
227
228     Catch(WrtDeviceApis::Commons::PlatformException) {
229         LoggerE("remove message error");
230         if (msg) {
231             //releasing platform message structure
232             msg_release_message(&msg);
233         }
234         throw;
235     }
236 */
237 }
238
239 void Sms::copyToFolder(const std::string& newFolder)
240 {
241 //    update();
242     //TODO
243 }
244
245 int Sms::send()
246 {
247         LoggerD("sending message, id=" << getIdRef());
248         Try{
249                 if(m_messageData == NULL)
250                 {
251                         //prepare for sending sms
252                         update();
253                 }
254                 MsgGetCommonHandle();
255         }
256         Catch(WrtDeviceApis::Commons::PlatformException) 
257         {
258                 LoggerD("getHandle failed");
259                 Throw(WrtDeviceApis::Commons::PlatformException);
260         }
261
262     // split the message
263         SendRequest req;
264
265         msg_struct_list_s *addr_list = NULL;
266         msg_struct_list_s *new_addr_list = NULL;
267         char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
268         int nToCnt;
269         int tempInt;
270         int tempIdInt;
271
272         msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);  
273         msg_get_int_value(m_messageData, MSG_MESSAGE_ID_INT, &tempIdInt);
274
275         nToCnt = addr_list->nCount;
276         LoggerD("nToCnt : " << nToCnt);
277
278         for (int i = 0; i < nToCnt; ++i) 
279         {
280                 msg_struct_t new_msg = createNewCopyOfPLatformMsg(m_messageData);
281                 msg_set_int_value(new_msg, MSG_MESSAGE_ID_INT, tempIdInt);
282
283                 msg_get_list_handle(new_msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
284
285                 msg_get_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
286                 LoggerD("RECIPIENT_TYPE : " << tempInt);
287                 if(MSG_RECIPIENTS_TYPE_TO != tempInt) 
288                 {
289                         LoggerD("skip");
290                         continue;
291                 }
292                 
293                 msg_get_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
294                 msg_set_str_value(new_addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
295                 msg_set_int_value(new_addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_TO);              
296                 new_addr_list->nCount = 1;
297
298                 setMessageStatus(MESSAGE_STATUS_SENDING);
299
300                 req.queue.push(new_msg);                
301         }
302
303
304         DPL::Mutex::ScopedLock lock(&m_mutex);
305         m_sendRequests.push(req);
306
307     // schedule sending
308         PostEvent(0);
309
310         LoggerD("sending method finished");
311
312         return 0;               //sms handle is -1;
313 }
314
315 void Sms::sendingCallback(msg_struct_t sent_status)
316 {
317 //    LoggerI(
318 //        "sendingCallback callback received. Req id = " <<
319 //        sent_status->reqId << " Status = " << (int)sent_status->status <<
320 //        ", Recipient=" << getRecipient());
321     int status = MSG_NETWORK_SEND_FAIL;
322
323     msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
324
325     DPL::Mutex::ScopedLock lock(&m_mutex);
326
327     if (status != MSG_NETWORK_SEND_SUCCESS) {
328         m_sendRequests.front().failed = true; // TODO mutex
329         //send callback, error for recipient
330         LoggerD("Send failed with error " << status);
331         setSendingStatusFailed(getRecipient());
332         setMessageStatus(MESSAGE_STATUS_FAILED);
333     } else {
334         setSendingStatusOk(getRecipient());
335         setMessageStatus(MESSAGE_STATUS_SENT);
336     }
337         
338     msg_release_struct(&currentQueue().front());
339     currentQueue().pop();
340
341     //schedule another sub message send
342     PostEvent(0);
343 }
344
345 void Sms::OnEventReceived(const int&)
346 {
347     LoggerD("enter");
348     // send another one
349     sendSubMessage();
350 }
351
352 FolderType Sms::toFolder(const std::string &folder)
353 {
354     if (folder == "INBOX") {
355         return INBOX;
356     } else if (folder == "OUTBOX") {
357         return OUTBOX;
358     } else if (folder == "SENTBOX") {
359         return SENTBOX;
360     } else if (folder == "DRAFTBOX") {
361         return DRAFTBOX;
362     }
363     ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
364 }
365
366 bool Sms::getCellularOn()
367 {
368     auto cellularOn = true;
369     void* connectionHandle;
370     if (CONNECTION_ERROR_NONE == connection_create(&connectionHandle)) {
371         connection_cellular_state_e cellularState;
372         if (CONNECTION_ERROR_NONE == connection_get_cellular_state (connectionHandle,
373                                                          &cellularState)) {
374             if (CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE  == cellularState || CONNECTION_CELLULAR_STATE_FLIGHT_MODE == cellularState) {
375                 cellularOn = false;
376                 LoggerW("Cellular State Error" << cellularState);
377             }
378         } else {
379             LoggerE("Can't obtain state of cellular connection");
380         }
381         connection_destroy(connectionHandle);
382     } else {
383         LoggerE("Can't obtain state of cellular connection");
384     }
385     return cellularOn;
386 }
387
388 bool Sms::getFlightModeOn()
389 {
390     auto flightMode = 0;
391     if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flightMode) != 0) {
392         flightMode = 0;
393         LoggerW("Can't read flight mode from variable: "
394                 << VCONFKEY_TELEPHONY_FLIGHT_MODE);
395     }
396     if (flightMode) {
397         LoggerW("Flight Mode active. All network operations will fail.");
398     }
399     return flightMode;
400 }
401
402 void Sms::sendSubMessage()
403 {
404     LoggerD("enter");
405
406     DPL::Mutex::ScopedLock lock(&m_mutex);
407
408     // if current request queue gets empty, try next one
409     while (!m_sendRequests.empty()) {
410         // send as long as the sending fails until there are no more messages
411         for (msg_error_t err = MSG_ERR_UNKNOWN;
412              err != MSG_SUCCESS && !currentQueue().empty(); ) 
413         {
414             if (getFlightModeOn() || !getCellularOn()) {
415                 err = MSG_ERR_TRANSPORT_ERROR;
416                 LoggerW("SMS send error. No transport possible over network");
417             } else {
418                 err = CallbackMgrSingleton::Instance().registerAndSend(
419                         msg_sms_send_message,
420                         currentQueue().front(),
421                         this);
422             }
423             LoggerI("Sending Message (submit request) result:" << err);
424             if (err != MSG_SUCCESS) {
425                 LoggerD("Sending Message (submit request) failed!!! err=" << err);
426                 msg_release_struct(&currentQueue().front());
427                 currentQueue().pop();
428                 m_sendRequests.front().failed = true;
429                 // send callback, error for recipient
430                 // TODO: Add error processing based at err
431                 if (MSG_ERR_TRANSPORT_ERROR == err || MSG_ERR_NO_SIM == err) {
432                     setSendingStatusFailed(getRecipient(),
433                                            EventOnSendingFailed::NO_CONNECTION);
434                 } else {
435                     setSendingStatusFailed(getRecipient());
436                 }
437             }
438         }
439
440         // empty queue -> notify about results
441         if (currentQueue().empty()) {
442                 /*
443             if (m_sendRequests.front().failed) {
444                 setSendingStatusFailed();
445             } else {
446                 setSendingStatusOk();
447             }
448             */
449             // this request is finished, try next one
450             m_sendRequests.pop();
451             continue;
452         }
453         break;
454     }
455 }
456
457 void Sms::setSendingStatusOk(const string &recipient)
458 {
459     LoggerD("enter, success number is : " << recipient);
460     //success callback should be executed here
461     ReqReceiverMessage *requestReceiver = getRequestReceiver();
462     if (requestReceiver) {
463          EventMessagingServicePtr event = getMessagingServiceEvent();
464          event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
465          event->m_successRecipients.push_back(recipient);
466
467          msg_struct_list_s *addr_list = NULL;    
468          msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
469
470           if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)addr_list->nCount)
471         {
472                 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
473         }
474          
475 #if 0
476         EventSendMessagePtr event = getSendMessageEvent();
477         event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
478         event->m_successRecipients.push_back(recipient);
479           //LoggerD("total address size : " << msg_get_address_count(m_messageData) << " Status size : " << event->m_successRecipients.size() + event->m_failRecipients.size());
480         if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)msg_get_address_count(m_messageData))
481         {
482                 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventSendMessage >::ManualAnswer(event);
483         }
484 #endif
485                 
486     }
487 }
488
489 void Sms::setSendingStatusFailed(const string &recipient,
490                                  EventOnSendingFailed::ErrorCode error)
491
492
493 {
494     using namespace WrtDeviceApis::Commons;
495     LoggerD("enter, fail number is : " << recipient);
496     //error callback should be executed here
497     EventOnSendingFailedEmitterPtr emitter = getEmitter();
498     if (emitter) {
499         EventOnSendingFailedPtr event(new EventOnSendingFailed);
500         event->setError(error);
501         emitter->emit(event);
502     } else {
503         ReqReceiverMessage* requestReceiver = getRequestReceiver();
504         if (requestReceiver) {
505             LoggerD("calling JS error callback");
506             EventMessagingServicePtr event = getMessagingServiceEvent();
507             auto errorCode = ExceptionCodes::UnknownException;
508             switch (error) {
509                 case EventOnSendingFailed::NO_NETWORKING:
510                     errorCode = ExceptionCodes::PlatformWrongStateException;
511                 break;
512                 case EventOnSendingFailed::NO_CONNECTION:
513                     errorCode = ExceptionCodes::PlatformWrongStateException;
514                 break;
515                 case EventOnSendingFailed::BAD_PAYLOAD:
516                     errorCode = ExceptionCodes::InvalidArgumentException;
517                 break;
518                 case EventOnSendingFailed::UNKNOWN:
519                     errorCode = ExceptionCodes::UnknownException;
520                 break;
521                 default:
522                     LoggerW("Unknown error code for send fail");
523             }
524             LoggerD("Send error " << error << " converted to " << errorCode);
525             event->setExceptionCode(errorCode);
526             event->m_successRecipients.push_back(recipient);
527             msg_struct_list_s *addr_list = NULL;
528             msg_get_list_handle(m_messageData,
529                                 MSG_MESSAGE_ADDR_LIST_STRUCT,
530                                (void**)&addr_list);
531             auto successSize = event->m_successRecipients.size();
532             auto failedSize = event->m_failRecipients.size();
533             auto originalSize = (unsigned int)addr_list->nCount;
534             if (successSize + failedSize == originalSize) {
535                 LoggerD("Manual answer");
536                 requestReceiver->EventRequestReceiver< EventMessagingService >::
537                         ManualAnswer(event);
538             }
539         }
540     }
541 }
542
543 void Sms::remove()
544 {
545     Try
546     {
547         // delete message from platform
548         if (msg_delete_message(MsgGetCommonHandle(),
549                                convertId(getId())) != MSG_SUCCESS) {
550             LoggerE("delete message failed");
551             Throw(WrtDeviceApis::Commons::PlatformException);
552         } else {
553             LoggerD("message deleted succesfully");
554         }
555     }
556
557     Catch(WrtDeviceApis::Commons::PlatformException) {
558         LoggerE("remove message error");
559         throw;
560     }
561 }
562
563 void Sms::createNewMessage()
564 {
565     LoggerD("enter");
566     if (m_messageData) {
567         // release platform message if it was created previously
568         msg_release_struct(&m_messageData);
569         m_messageData = NULL;
570     }
571     // create new platform message
572     LoggerD("create messeage instance");
573     m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
574     LoggerD("created message : " << m_messageData);
575         
576     Try
577     {
578         //default message initialization
579         // update sms data
580         updateBody();
581         updateTo();
582
583         setMessageStatus(MESSAGE_STATUS_DRAFT);
584
585         tm dateT = getDateTime();
586         msg_set_int_value(m_messageData, MSG_MESSAGE_DISPLAY_TIME_INT, (int)mktime(&dateT));
587
588           setMessageStatus(MESSAGE_STATUS_CREATED);
589         LoggerD("Message created successfully, msgId=" << getId());
590     }
591     Catch(WrtDeviceApis::Commons::PlatformException) {
592         msg_release_struct(&m_messageData);
593         m_messageData = NULL;
594         LoggerE("Problem with message creation, cleaning");
595     }
596 }
597
598 void Sms::readExistingMessage()
599 {
600         if (getIdRef().empty() || (EMPTY_ID == getIdRef())) {
601                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
602         }
603
604         // release old data
605         if (m_messageData) {
606                 // release platform message if it was created previously
607         msg_release_struct(&m_messageData);
608         m_messageData = NULL;
609         }
610         msg_struct_t sendOpt = NULL;
611
612         Try {
613                 // create new platform structure
614                 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
615                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
616
617                 msg_message_id_t l_id = convertId(getIdRef());
618                 LoggerD("reading message id=" << l_id);
619                 // trying to get message from platform
620                 if (MSG_SUCCESS == msg_get_message(MsgGetCommonHandle(), l_id, m_messageData, sendOpt)) 
621                 {
622                         LoggerD("message found with msgId=" << getIdRef());
623
624                         // read all mms dat to abstraction layer
625                         readConversationId(m_messageData);
626                         readRecipientList(m_messageData);
627                         readBody(m_messageData);
628                         readFolder(m_messageData);
629                         readDateTime(m_messageData);
630                         readReadStatus(m_messageData);
631                         readSize(m_messageData);
632                         readMessageStatus(m_messageData);
633
634                 } else {
635                         LoggerE("message not found with msgId=" << getIdRef());
636                         setId("");
637                         Throw(WrtDeviceApis::Commons::PlatformException);
638                 }
639
640                 msg_release_struct(&sendOpt);
641         }
642         Catch(WrtDeviceApis::Commons::PlatformException) {
643                 LoggerE("exception");
644                 // nothing to do
645                 msg_release_struct(&sendOpt);
646         }
647 }
648
649 void Sms::updateBody()
650 {
651     // check if abstraction body value has been changed
652     if (isBodyValid()) {
653         return;
654     }
655     LoggerI("updating platfoprm body");
656
657     // change body value in platform structure
658     if (  getBodyRef().length() >  0)
659     {
660                 if (msg_set_str_value(m_messageData, MSG_MESSAGE_SMS_DATA_STR, 
661                         const_cast<char*>(getBodyRef().c_str()), getBodyRef().length()) != MSG_SUCCESS)
662                 {
663         LoggerE("problem with update Body");
664         Throw(WrtDeviceApis::Commons::PlatformException);
665         }
666     // set flag as true - platform synchronized with abstraction
667     setBodyValidity(true);
668 }
669     // set flag as true - platform synchronized with abstraction
670 }
671
672 void Sms::updateTo()
673 {
674         // check if abstraction recipient value has been changed
675         if (getToRecipients().isValid()) {
676                 return;
677         }
678
679         LoggerI("SMS updating platform recipients");
680
681         msg_struct_list_s *addr_list = NULL;
682         msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
683         int nToCnt = addr_list->nCount;
684
685         LogInfo("nToCnt size  " << nToCnt);
686
687         if (nToCnt > 0)
688         {
689                 for (int i = 0; i < nToCnt; i++) {
690                         msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
691                         msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
692                         msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
693                         msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
694                         msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
695                 }
696                 nToCnt = 0;
697                 addr_list->nCount = nToCnt;
698         }
699
700         vector<string> to = getToRecipients().getRecipients();
701
702         // update addresses in platform structure
703         if (to.size())
704         {
705                 LoggerI("updating to");
706                 for (size_t i = 0; i < to.size(); i++)
707                 {
708                         string tmpAddr = to[i];
709                         if(validatePhoneNumber(tmpAddr))
710                         {
711                                 if (i >= MAX_TO_ADDRESS_CNT)
712                                 {
713                                         LoggerE("max number of recipient exceeded");
714                                         break;
715                                 }
716                                 LoggerD("adding to[" << i << "]=" << to[i]);
717
718                                 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
719
720                                 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
721                                 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
722                                 {
723                                         LoggerE("problem with adding to address");
724                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
725                                 }
726
727                                 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
728                                 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
729                                 {
730                                         LoggerE("problem with adding to address");
731                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
732                                 }
733
734                                 addr_list->nCount ++;
735                                 LoggerD("addr_list->nCount =" << addr_list->nCount);
736                         }
737                         else
738                         {
739                                 LoggerE("wrong phone number format");
740                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "wrong phone number format");                               
741                         }
742                 }
743         }
744
745         setToValidity(true);
746
747 }
748
749 void Sms::updateFrom()
750 {
751     // check if abstraction from field value has been changed
752     if (getFromValidity()) {
753         // do not update if not changed
754         return;
755     }
756     LoggerI("updating platform from");
757
758     //TODO
759
760     // set flag as true - platform synchronized with abstraction
761     setFromValidity(true);
762 }
763
764 void Sms::updateSourceAddress()
765 {
766     // check if abstraction source address value has been changed
767     if (getSourceAddressValidity()) {
768         // do not update if not changed
769         return;
770     }
771     LoggerI("updating platform source address");
772
773     //TODO
774
775     // set flag as true - platform synchronized with abstraction
776     setSourceAddressValidity(true);
777 }
778
779 void Sms::updateReadStatus()
780 {
781     LoggerI("updating platform read status: " << isRead());
782     if (isReadStatusValid()) {
783         // do not update if not changed
784         return;
785     }
786     if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
787         LoggerE("problem with setting subject");
788         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
789     }
790     setReadStatusValidity(true);
791 }
792
793 void Sms::updateIsRead()
794 {
795     LoggerD("updating m_id=" << getIdRef());
796
797     if (!m_messageData) {
798         //error if platform message not exists
799         LoggerE("message can not be updated");
800         Throw(WrtDeviceApis::Commons::PlatformException);
801     }
802         
803     // check if abstraction from m_isReadChange value has been changed
804     if (isReadChangeStatusValid()) {
805         // do not update if not changed
806         return;
807     }
808         
809     Try
810     {
811         if (this->getIdRef().empty()) {
812             LoggerE("existing msgId is zero, remove msg not done");
813             ThrowMsg(WrtDeviceApis::Commons::PlatformException,
814                     "existing msgId is zero, remove msg not done");
815         }
816
817         if (MSG_SUCCESS !=
818             msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
819         {
820             LoggerE("Failed to update isRead");
821             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
822         }
823     }
824     Catch(WrtDeviceApis::Commons::PlatformException) {
825         LoggerE("platform error occurs");
826     }
827     setisReadChangeStatusValidity(true);
828         
829 }
830
831 void Sms::updateMessage()
832 {
833         LoggerD("updating m_id=" << getIdRef());
834         msg_error_t err = MSG_SUCCESS;
835         
836         msg_struct_t msg = NULL;
837         msg_struct_t sendOpt = NULL;
838         
839         if (!m_messageData) {
840                 //error if platform message not exists
841                 LoggerE("message can not be updated");
842                 Throw(WrtDeviceApis::Commons::PlatformException);
843         }
844         
845         Try
846         {
847
848                 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
849                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
850                 
851                 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
852                 
853                 if (err != MSG_SUCCESS)
854                 {
855                         LoggerE("Get Message Failed!");
856                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
857                 }
858         
859                 if (this->getIdRef().empty()) {
860                         LoggerE("existing msgId is zero, update msg not done");
861                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
862                                         "existing msgId is zero, update msg not done");
863                 }
864                 
865                 update(TRUE);
866                 
867                 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
868                 {
869                         LoggerE("Failed to update message");
870                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
871                 }
872                 msg_release_struct(&msg);
873                 msg_release_struct(&sendOpt);
874         }
875         Catch(WrtDeviceApis::Commons::PlatformException) {
876                 msg_release_struct(&msg);
877                 msg_release_struct(&sendOpt);
878                 LoggerE("platform error occurs");
879         }
880 }
881
882 void Sms::createSendMessage()
883 {
884         LoggerD("convert m_id= " << convertId(getIdRef()));     
885
886         //prepare for add sms to draft folder
887         if (!m_messageData) {
888                 //error if platform message not exists
889                 LoggerE("message can not be updated");
890                 Throw(WrtDeviceApis::Commons::PlatformException);
891         }
892
893         //update all sms data
894         if (getCurrentFolder() == DRAFTBOX) {
895                 LoggerD("update all sms data");
896                 updateBody();
897                 updateFrom();
898                 updateTo();
899                 updateSourceAddress();
900         }
901
902         Try
903         {
904                 int msgId = 0;
905 //              MSG_SENDINGOPT_S option = { false, false, false };
906 //              option.option.smsSendOpt.bReplyPath = true;
907                 // trying to get message from platform
908
909 //              const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
910
911 //              msg_set_message_id(m_messageData, msgId);               
912 //              msg_set_folder_id(m_messageData, platfromFolderId);
913 //              msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
914
915                 setId(convertId(msgId));
916                 setFolderType(DRAFTBOX);
917                 setMessageStatus(MESSAGE_STATUS_DRAFT);
918         }
919         Catch(WrtDeviceApis::Commons::PlatformException) {
920                 LoggerE("remove message error");
921                 if (m_messageData) {
922                         //releasing platform message structure
923                         msg_release_struct(&m_messageData);
924                         m_messageData = NULL;
925                 }
926                 throw;
927         }
928
929 }
930
931
932
933 void Sms::addMessageToDraft()
934 {
935     LoggerD("convert m_id= " << convertId(getIdRef())); 
936     msg_struct_t sendOpt = NULL;
937
938     //prepare for add sms to draft folder
939     if (!m_messageData) {
940         //error if platform message not exists
941         LoggerE("message can not be updated");
942         Throw(WrtDeviceApis::Commons::PlatformException);
943     }
944
945     //update all sms data
946     if (getCurrentFolder() == DRAFTBOX) {
947         LoggerD("update all sms data");
948         updateBody();
949         updateFrom();
950         updateTo();
951         updateSourceAddress();
952     }
953
954     Try
955     {
956         sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
957         msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
958         int msgId = -1;
959
960         // trying to add message
961         int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
962         if(ret < MSG_SUCCESS) {
963             LoggerE("msg_add_message failed, error code=" << ret);
964             Throw(WrtDeviceApis::Commons::PlatformException);
965         }
966         else
967         {
968             msgId = ret;        
969         }
970                         
971         LoggerD("Message ID : " << msgId);
972         if (msgId < 0)
973         {
974             LoggerD("Message ID is invailded ");
975             Throw(WrtDeviceApis::Commons::PlatformException);
976         }
977           
978         msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
979
980         setId(convertId(msgId));
981
982         readAllData();
983         msg_release_struct(&sendOpt);
984
985     }
986     Catch(WrtDeviceApis::Commons::PlatformException) {
987         LoggerE("remove message error");
988         if (m_messageData) {
989             //releasing platform message structure
990             msg_release_struct(&m_messageData);
991             m_messageData = NULL;
992             msg_release_struct(&sendOpt);
993         }
994         throw;
995     }
996
997 }
998
999 void Sms::readConversationId(msg_struct_t& messageData)
1000 {
1001         int tempInt = 0;
1002         msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
1003         LoggerD("conversationID : " <<tempInt);
1004         setConvId(tempInt);
1005 }
1006
1007 void Sms::readRecipientList(msg_struct_t& messageData)
1008 {
1009         std::string phoneNumber;
1010 //      int recipientCount = msg_get_address_count(messageData);
1011 //      LoggerD("Recipient count " << recipientCount);
1012
1013         msg_struct_list_s *addr_list;
1014         msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1015
1016         int tempInt = 0;
1017         char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1018
1019         int recipientCount = addr_list->nCount;
1020         LoggerD("Recipient count " << recipientCount);
1021
1022         
1023         for (int i = 0; i < recipientCount; ++i) 
1024 {
1025                 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1026                 int type = tempInt;
1027
1028                 if (MSG_DIRECTION_TYPE_MT == type) 
1029                 {
1030                         msg_struct_t addr_info = addr_list->msg_struct_info[i];
1031                         msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1032                         phoneNumber = strNumber;
1033                 
1034                         if (validatePhoneNumber(phoneNumber)) 
1035                         {
1036                                 setSourceAddress(phoneNumber);
1037                                 setFrom(phoneNumber);
1038                         }
1039                         LoggerD("MT number: " << phoneNumber);
1040             }
1041                 else if (MSG_DIRECTION_TYPE_MO == type) 
1042                 {
1043                         msg_struct_t addr_info = addr_list->msg_struct_info[i];
1044                         msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1045                         LoggerD("MO number: " << strNumber);
1046                         appendToRecipients(strNumber);
1047                 } 
1048                 else 
1049                 {
1050                         LoggerE("Wrong type of recipient");
1051                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
1052         }
1053     }
1054 }
1055
1056 void Sms::readBody(msg_struct_t& messageData)
1057 {
1058     //set abstraction body value
1059     int tempInt;
1060     msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1061     LoggerE("body Size : " <<tempInt);
1062     char msgText[tempInt+1];
1063     memset(msgText, 0, tempInt+1);
1064     msg_get_str_value(messageData, MSG_MESSAGE_SMS_DATA_STR, msgText, tempInt);
1065 //    setBody(msg_sms_get_message_body(messageData));
1066     LoggerE("body : " <<msgText);
1067     setBody(msgText);
1068 }
1069
1070 void Sms::readFolder(msg_struct_t& messageData)
1071 {
1072     int tempInt = 0;
1073     msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1074     LoggerE("Folder : " <<tempInt);
1075
1076     switch (tempInt) {
1077     case MSG_INBOX_ID:
1078         setFolderType(INBOX);
1079         break;
1080     case MSG_OUTBOX_ID:
1081         setFolderType(OUTBOX);
1082         break;
1083     case MSG_SENTBOX_ID:
1084         setFolderType(SENTBOX);
1085         break;
1086     case MSG_DRAFT_ID:
1087         setFolderType(DRAFTBOX);
1088         break;
1089     default:
1090         LoggerE("Wrong folder id");
1091         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
1092     }
1093 }
1094
1095 void Sms::readMessageStatus(msg_struct_t& messageData)
1096 {
1097         int tempValue = 0;
1098         msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
1099         LoggerD("readMessageStatus folder : " << tempValue);
1100
1101         switch (tempValue) {
1102                 case MSG_INBOX_ID:
1103                         setMessageStatus(MESSAGE_STATUS_LOADED);
1104                         break;
1105                 case MSG_OUTBOX_ID:
1106                         setMessageStatus(MESSAGE_STATUS_SENDING);
1107                         break;
1108                 case MSG_SENTBOX_ID:
1109                         setMessageStatus(MESSAGE_STATUS_SENT);
1110                         break;
1111                 case MSG_DRAFT_ID:
1112                         setMessageStatus(MESSAGE_STATUS_DRAFT);
1113                         break;
1114                 default:
1115                         setMessageStatus(MESSAGE_STATUS_LOADED);
1116                         break;                  
1117         }
1118 }
1119
1120
1121 void Sms::readDateTime(msg_struct_t& messageData)
1122 {
1123 //  tm* time = localtime(msg_get_time(messageData));
1124 //    tm dateT = getDateTime();
1125     int tempInt = 0;
1126     msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1127
1128     LoggerE("readDateTime : " <<tempInt);
1129
1130     tm* time = localtime((time_t*)&tempInt);
1131     if (!time) {
1132         LoggerE("localtime failed");
1133         Throw(WrtDeviceApis::Commons::PlatformException);
1134     }
1135     setDateTime(*time);
1136 }
1137
1138 void Sms::readReadStatus(msg_struct_t& messageData)
1139 {
1140     // get read status
1141     bool tempBool = 0;
1142     msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
1143     LoggerE("readReadStatus : " <<tempBool);
1144     setReadStatus(tempBool);
1145 }
1146
1147 void Sms::readSize(msg_struct_t& messageData)
1148 {
1149     int tempInt;
1150     msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1151 //    setSize(msg_get_message_body_size(messageData));
1152     LoggerE("readSize : " <<tempInt);
1153     setSize(tempInt);
1154 }
1155
1156 msg_struct_t Sms::createNewCopyOfPLatformMsg(const msg_struct_t src) const
1157 {
1158         int tempInt;
1159         bool tempBool;
1160         
1161         msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1162
1163         msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1164         msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1165
1166         msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1167         msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1168
1169         msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1170         char tempStr[tempInt+1];
1171         memset(tempStr, 0, tempInt+1);
1172
1173         msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1174         msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1175
1176         msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1177         msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1178
1179 //    msg_set_network_status(msg, msg_get_network_status(src));
1180         msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1181         msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT,  tempInt);
1182
1183 //    msg_set_encode_type(msg, msg_get_encode_type(src));
1184         msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1185         msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT,  tempInt);
1186
1187 //    msg_set_read_status(msg, msg_is_read(src));
1188         msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1189         msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1190
1191 //        msg_set_protect_status(msg, msg_is_protected(src));
1192         msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1193         msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1194
1195 //        msg_set_priority_info(msg, msg_get_priority_info(src));
1196         msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1197         msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT,  tempInt);
1198
1199 //        msg_set_direction_info(msg, msg_get_direction_info(src));
1200         msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1201         msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT,  tempInt);
1202
1203 //        msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1204         msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1205         msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT,  tempInt);
1206         msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1207         msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT,  tempInt);
1208
1209     return msg;
1210 }
1211
1212 msg_struct_t Sms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
1213 {
1214         int tempInt;
1215         bool tempBool;
1216         msg_struct_list_s *addr_list;
1217         msg_struct_list_s *new_addr_list;
1218         
1219         msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1220
1221         msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1222         msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1223
1224         msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1225         msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1226
1227         msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1228         char tempStr[tempInt+1];
1229         memset(tempStr, 0, tempInt+1);
1230
1231         msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1232         msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1233
1234         msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1235         msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1236
1237 //    msg_set_network_status(msg, msg_get_network_status(src));
1238         msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1239         msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT,  tempInt);
1240
1241 //    msg_set_encode_type(msg, msg_get_encode_type(src));
1242         msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1243         msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT,  tempInt);
1244
1245 //    msg_set_read_status(msg, msg_is_read(src));
1246         msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1247         msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1248
1249 //        msg_set_protect_status(msg, msg_is_protected(src));
1250         msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1251         msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1252
1253 //        msg_set_priority_info(msg, msg_get_priority_info(src));
1254         msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1255         msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT,  tempInt);
1256
1257 //        msg_set_direction_info(msg, msg_get_direction_info(src));
1258         msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1259         msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT,  tempInt);
1260
1261 //        msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1262         msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1263         msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT,  tempInt);
1264         msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1265         msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT,  tempInt);
1266
1267 // copy addr list
1268         msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1269         msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
1270
1271         new_addr_list->nCount = addr_list->nCount;
1272
1273         for(int i=0; i<addr_list->nCount; i++)
1274         {
1275                 msg_struct_t addr_info = NULL;
1276                 msg_struct_t new_addr_info = NULL;
1277                 char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
1278                 
1279                 //get original address
1280                 addr_info = addr_list->msg_struct_info[i];
1281                 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1282                 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
1283
1284                 //copy original address
1285                 new_addr_info = new_addr_list->msg_struct_info[i];
1286                 msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1287                 msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
1288         }
1289
1290     return msg;
1291 }
1292
1293 }
1294 }