Update change log and spec for wrt-plugins-tizen_0.4.57
[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                 ReThrow(WrtDeviceApis::Commons::PlatformException);
880         }
881 }
882
883 void Sms::createSendMessage()
884 {
885         LoggerD("convert m_id= " << convertId(getIdRef()));     
886
887         //prepare for add sms to draft folder
888         if (!m_messageData) {
889                 //error if platform message not exists
890                 LoggerE("message can not be updated");
891                 Throw(WrtDeviceApis::Commons::PlatformException);
892         }
893
894         //update all sms data
895         if (getCurrentFolder() == DRAFTBOX) {
896                 LoggerD("update all sms data");
897                 updateBody();
898                 updateFrom();
899                 updateTo();
900                 updateSourceAddress();
901         }
902
903         Try
904         {
905                 int msgId = 0;
906 //              MSG_SENDINGOPT_S option = { false, false, false };
907 //              option.option.smsSendOpt.bReplyPath = true;
908                 // trying to get message from platform
909
910 //              const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
911
912 //              msg_set_message_id(m_messageData, msgId);               
913 //              msg_set_folder_id(m_messageData, platfromFolderId);
914 //              msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
915
916                 setId(convertId(msgId));
917                 setFolderType(DRAFTBOX);
918                 setMessageStatus(MESSAGE_STATUS_DRAFT);
919         }
920         Catch(WrtDeviceApis::Commons::PlatformException) {
921                 LoggerE("remove message error");
922                 if (m_messageData) {
923                         //releasing platform message structure
924                         msg_release_struct(&m_messageData);
925                         m_messageData = NULL;
926                 }
927                 throw;
928         }
929
930 }
931
932
933
934 void Sms::addMessageToDraft()
935 {
936     LoggerD("convert m_id= " << convertId(getIdRef())); 
937     msg_struct_t sendOpt = NULL;
938
939     //prepare for add sms to draft folder
940     if (!m_messageData) {
941         //error if platform message not exists
942         LoggerE("message can not be updated");
943         Throw(WrtDeviceApis::Commons::PlatformException);
944     }
945
946     //update all sms data
947     if (getCurrentFolder() == DRAFTBOX) {
948         LoggerD("update all sms data");
949         updateBody();
950         updateFrom();
951         updateTo();
952         updateSourceAddress();
953     }
954
955     Try
956     {
957         sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
958         msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
959         int msgId = -1;
960
961         // trying to add message
962         int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
963         if(ret < MSG_SUCCESS) {
964             LoggerE("msg_add_message failed, error code=" << ret);
965             Throw(WrtDeviceApis::Commons::PlatformException);
966         }
967         else
968         {
969             msgId = ret;        
970         }
971                         
972         LoggerD("Message ID : " << msgId);
973         if (msgId < 0)
974         {
975             LoggerD("Message ID is invailded ");
976             Throw(WrtDeviceApis::Commons::PlatformException);
977         }
978           
979         msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
980
981         setId(convertId(msgId));
982
983         readAllData();
984         msg_release_struct(&sendOpt);
985
986     }
987     Catch(WrtDeviceApis::Commons::PlatformException) {
988         LoggerE("remove message error");
989         if (m_messageData) {
990             //releasing platform message structure
991             msg_release_struct(&m_messageData);
992             m_messageData = NULL;
993             msg_release_struct(&sendOpt);
994         }
995         throw;
996     }
997
998 }
999
1000 void Sms::readConversationId(msg_struct_t& messageData)
1001 {
1002         int tempInt = 0;
1003         msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
1004         LoggerD("conversationID : " <<tempInt);
1005         setConvId(tempInt);
1006 }
1007
1008 void Sms::readRecipientList(msg_struct_t& messageData)
1009 {
1010         std::string phoneNumber;
1011 //      int recipientCount = msg_get_address_count(messageData);
1012 //      LoggerD("Recipient count " << recipientCount);
1013
1014         msg_struct_list_s *addr_list;
1015         msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1016
1017         int tempInt = 0;
1018         char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1019
1020         int recipientCount = addr_list->nCount;
1021         LoggerD("Recipient count " << recipientCount);
1022
1023         
1024         for (int i = 0; i < recipientCount; ++i) 
1025 {
1026                 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1027                 int type = tempInt;
1028
1029                 if (MSG_DIRECTION_TYPE_MT == type) 
1030                 {
1031                         msg_struct_t addr_info = addr_list->msg_struct_info[i];
1032                         msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1033                         phoneNumber = strNumber;
1034                 
1035                         if (validatePhoneNumber(phoneNumber)) 
1036                         {
1037                                 setSourceAddress(phoneNumber);
1038                                 setFrom(phoneNumber);
1039                         }
1040                         LoggerD("MT number: " << phoneNumber);
1041             }
1042                 else if (MSG_DIRECTION_TYPE_MO == type) 
1043                 {
1044                         msg_struct_t addr_info = addr_list->msg_struct_info[i];
1045                         msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1046                         LoggerD("MO number: " << strNumber);
1047                         appendToRecipients(strNumber);
1048                 } 
1049                 else 
1050                 {
1051                         LoggerE("Wrong type of recipient");
1052                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
1053         }
1054     }
1055 }
1056
1057 void Sms::readBody(msg_struct_t& messageData)
1058 {
1059     //set abstraction body value
1060     int tempInt;
1061     msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1062     LoggerE("body Size : " <<tempInt);
1063     char msgText[tempInt+1];
1064     memset(msgText, 0, tempInt+1);
1065     msg_get_str_value(messageData, MSG_MESSAGE_SMS_DATA_STR, msgText, tempInt);
1066 //    setBody(msg_sms_get_message_body(messageData));
1067     LoggerE("body : " <<msgText);
1068     setBody(msgText);
1069 }
1070
1071 void Sms::readFolder(msg_struct_t& messageData)
1072 {
1073     int tempInt = 0;
1074     msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1075     LoggerE("Folder : " <<tempInt);
1076
1077     switch (tempInt) {
1078     case MSG_INBOX_ID:
1079         setFolderType(INBOX);
1080         break;
1081     case MSG_OUTBOX_ID:
1082         setFolderType(OUTBOX);
1083         break;
1084     case MSG_SENTBOX_ID:
1085         setFolderType(SENTBOX);
1086         break;
1087     case MSG_DRAFT_ID:
1088         setFolderType(DRAFTBOX);
1089         break;
1090     default:
1091         LoggerE("Wrong folder id");
1092         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
1093     }
1094 }
1095
1096 void Sms::readMessageStatus(msg_struct_t& messageData)
1097 {
1098         int tempValue = 0;
1099         msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
1100         LoggerD("readMessageStatus folder : " << tempValue);
1101
1102         switch (tempValue) {
1103                 case MSG_INBOX_ID:
1104                         setMessageStatus(MESSAGE_STATUS_LOADED);
1105                         break;
1106                 case MSG_OUTBOX_ID:
1107                         setMessageStatus(MESSAGE_STATUS_SENDING);
1108                         break;
1109                 case MSG_SENTBOX_ID:
1110                         setMessageStatus(MESSAGE_STATUS_SENT);
1111                         break;
1112                 case MSG_DRAFT_ID:
1113                         setMessageStatus(MESSAGE_STATUS_DRAFT);
1114                         break;
1115                 default:
1116                         setMessageStatus(MESSAGE_STATUS_LOADED);
1117                         break;                  
1118         }
1119 }
1120
1121
1122 void Sms::readDateTime(msg_struct_t& messageData)
1123 {
1124 //  tm* time = localtime(msg_get_time(messageData));
1125 //    tm dateT = getDateTime();
1126     int tempInt = 0;
1127     msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1128
1129     LoggerE("readDateTime : " <<tempInt);
1130
1131     tm* time = localtime((time_t*)&tempInt);
1132     if (!time) {
1133         LoggerE("localtime failed");
1134         Throw(WrtDeviceApis::Commons::PlatformException);
1135     }
1136     setDateTime(*time);
1137 }
1138
1139 void Sms::readReadStatus(msg_struct_t& messageData)
1140 {
1141     // get read status
1142     bool tempBool = 0;
1143     msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
1144     LoggerE("readReadStatus : " <<tempBool);
1145     setReadStatus(tempBool);
1146 }
1147
1148 void Sms::readSize(msg_struct_t& messageData)
1149 {
1150     int tempInt;
1151     msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1152 //    setSize(msg_get_message_body_size(messageData));
1153     LoggerE("readSize : " <<tempInt);
1154     setSize(tempInt);
1155 }
1156
1157 msg_struct_t Sms::createNewCopyOfPLatformMsg(const msg_struct_t src) const
1158 {
1159         int tempInt;
1160         bool tempBool;
1161         
1162         msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1163
1164         msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1165         msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1166
1167         msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1168         msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1169
1170         msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1171         char tempStr[tempInt+1];
1172         memset(tempStr, 0, tempInt+1);
1173
1174         msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1175         msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1176
1177         msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1178         msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1179
1180 //    msg_set_network_status(msg, msg_get_network_status(src));
1181         msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1182         msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT,  tempInt);
1183
1184 //    msg_set_encode_type(msg, msg_get_encode_type(src));
1185         msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1186         msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT,  tempInt);
1187
1188 //    msg_set_read_status(msg, msg_is_read(src));
1189         msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1190         msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1191
1192 //        msg_set_protect_status(msg, msg_is_protected(src));
1193         msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1194         msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1195
1196 //        msg_set_priority_info(msg, msg_get_priority_info(src));
1197         msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1198         msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT,  tempInt);
1199
1200 //        msg_set_direction_info(msg, msg_get_direction_info(src));
1201         msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1202         msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT,  tempInt);
1203
1204 //        msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1205         msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1206         msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT,  tempInt);
1207         msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1208         msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT,  tempInt);
1209
1210     return msg;
1211 }
1212
1213 msg_struct_t Sms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
1214 {
1215         int tempInt;
1216         bool tempBool;
1217         msg_struct_list_s *addr_list;
1218         msg_struct_list_s *new_addr_list;
1219         
1220         msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1221
1222         msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1223         msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1224
1225         msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1226         msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1227
1228         msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1229         char tempStr[tempInt+1];
1230         memset(tempStr, 0, tempInt+1);
1231
1232         msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1233         msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1234
1235         msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1236         msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1237
1238 //    msg_set_network_status(msg, msg_get_network_status(src));
1239         msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1240         msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT,  tempInt);
1241
1242 //    msg_set_encode_type(msg, msg_get_encode_type(src));
1243         msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1244         msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT,  tempInt);
1245
1246 //    msg_set_read_status(msg, msg_is_read(src));
1247         msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1248         msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1249
1250 //        msg_set_protect_status(msg, msg_is_protected(src));
1251         msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1252         msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1253
1254 //        msg_set_priority_info(msg, msg_get_priority_info(src));
1255         msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1256         msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT,  tempInt);
1257
1258 //        msg_set_direction_info(msg, msg_get_direction_info(src));
1259         msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1260         msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT,  tempInt);
1261
1262 //        msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1263         msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1264         msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT,  tempInt);
1265         msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1266         msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT,  tempInt);
1267
1268 // copy addr list
1269         msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1270         msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
1271
1272         new_addr_list->nCount = addr_list->nCount;
1273
1274         for(int i=0; i<addr_list->nCount; i++)
1275         {
1276                 msg_struct_t addr_info = NULL;
1277                 msg_struct_t new_addr_info = NULL;
1278                 char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
1279                 
1280                 //get original address
1281                 addr_info = addr_list->msg_struct_info[i];
1282                 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1283                 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
1284
1285                 //copy original address
1286                 new_addr_info = new_addr_list->msg_struct_info[i];
1287                 msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1288                 msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
1289         }
1290
1291     return msg;
1292 }
1293
1294 }
1295 }