3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
32 #include "MsgUtilFunction.h"
34 /*==================================================================================================
35 FUNCTION IMPLEMENTATION
36 ==================================================================================================*/
39 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
43 dataSize = sizeof(MSG_COUNT_INFO_S);
45 *ppDest = (char*)new char[dataSize];
47 void* p = (void*)*ppDest;
49 memcpy(p, pCountInfo, dataSize);
55 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
57 int count = 0, dataSize = 0;
59 count = pRecipientList->recipientCnt;
60 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
62 *ppDest = (char*)new char[dataSize];
64 void* p = (void*)*ppDest;
66 memcpy(p, &count, sizeof(int));
67 p = (void*)((char*)p + sizeof(int));
69 for (int i = 0; i < count; i++)
71 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
72 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
79 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
83 dataSize = sizeof(int);
85 *ppDest = (char*)new char[dataSize];
87 void* p = (void*)*ppDest;
89 memcpy(p, &MsgCount, dataSize);
95 int MsgEncodeMsgId(MSG_MESSAGE_ID_T *pMsgId, char **ppDest)
99 dataSize = (sizeof(MSG_MESSAGE_ID_T));
101 *ppDest = (char*)new char[dataSize];
103 void* p = (void*)*ppDest;
105 memcpy(p, pMsgId, dataSize);
111 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
115 dataSize = sizeof(MSG_MESSAGE_INFO_S);
117 *ppDest = (char*)new char[dataSize];
119 void* p = (void*)*ppDest;
121 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
123 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
129 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
133 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S));
135 *ppDest = (char*)new char[dataSize];
137 void* p = (void*)*ppDest;
139 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
141 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
143 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
149 int MsgEncodeFolderViewList(MSG_LIST_S *pFolderViewList, char **ppDest)
151 int count = 0, dataSize = 0;
153 count = pFolderViewList->nCount;
155 dataSize = sizeof(int) + (sizeof(MSG_MESSAGE_S)*count);
157 *ppDest = (char*)new char[dataSize];
159 void* p = (void*)*ppDest;
161 memcpy(p, &count, sizeof(int));
162 p = (void*)((char*)p + sizeof(int));
164 for (int i = 0; i < count; i++)
166 memcpy(p, &(pFolderViewList->msgInfo[i]), sizeof(MSG_MESSAGE_S));
167 p = (void*)((char*)p + sizeof(MSG_MESSAGE_S));
174 int MsgEncodeFolderList(MSG_FOLDER_LIST_S *pFolderList, char **ppDest)
176 int count = 0, dataSize = 0;
178 count = pFolderList->nCount;
179 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
181 *ppDest = (char*)new char[dataSize];
183 void* p = (void*)*ppDest;
185 memcpy(p, &count, sizeof(int));
186 p = (void*)((char*)p + sizeof(int));
188 for (int i = 0; i < count; i++)
190 memcpy(p, &(pFolderList->folderInfo[i]), sizeof(MSG_FOLDER_INFO_S));
191 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
198 int MsgEncodeSetting(MSG_SETTING_S *pSetting, char **ppDest)
200 int dataSize = sizeof(MSG_OPTION_TYPE_T);
202 switch (pSetting->type)
204 case MSG_GENERAL_OPT :
205 dataSize += sizeof(MSG_GENERAL_OPT_S);
207 case MSG_SMS_SENDOPT :
208 dataSize += sizeof(MSG_SMS_SENDOPT_S);
211 dataSize += sizeof(MSG_SMSC_LIST_S);
213 case MSG_MMS_SENDOPT :
214 dataSize += sizeof(MSG_MMS_SENDOPT_S);
216 case MSG_MMS_RECVOPT :
217 dataSize += sizeof(MSG_MMS_RECVOPT_S);
219 case MSG_MMS_STYLEOPT :
220 dataSize += sizeof(MSG_MMS_STYLEOPT_S);
222 case MSG_PUSHMSG_OPT :
223 dataSize += sizeof(MSG_PUSHMSG_OPT_S);
226 dataSize += sizeof(MSG_CBMSG_OPT_S);
228 case MSG_VOICEMAIL_OPT :
229 dataSize += sizeof(MSG_VOICEMAIL_OPT_S);
231 case MSG_MSGSIZE_OPT :
232 dataSize += sizeof(MSG_MSGSIZE_OPT_S);
236 *ppDest = (char*)new char[dataSize];
238 void* p = (void*)*ppDest;
240 memcpy(p, pSetting, dataSize);
246 int MsgEncodeMsgType(MSG_MESSAGE_TYPE_S *pMsgType, char **ppDest)
250 dataSize = (sizeof(MSG_MESSAGE_TYPE_S));
252 *ppDest = (char*)new char[dataSize];
254 void* p = (void*)*ppDest;
256 memcpy(p, pMsgType, dataSize);
262 int MsgEncodeThreadViewList(MSG_THREAD_VIEW_LIST_S *pThreadViewList, char **ppDest)
264 int count = 0, dataSize = 0;
266 count = pThreadViewList->nCount;
268 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
270 *ppDest = (char*)new char[dataSize];
272 void* p = (void*)*ppDest;
274 memcpy(p, &count, sizeof(int));
275 p = (void*)((char*)p + sizeof(int));
277 for (int i = 0; i < count; i++)
279 memcpy(p, &(pThreadViewList->msgThreadInfo[i]), sizeof(MSG_THREAD_VIEW_S));
280 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
287 int MsgEncodeConversationViewList(MSG_LIST_S *pConvViewList, char **ppDest)
289 int count = 0, dataSize = 0;
291 count = pConvViewList->nCount;
293 dataSize = sizeof(int) + (sizeof(MSG_LIST_S)*count);
295 *ppDest = (char*)new char[dataSize];
297 void* p = (void*)*ppDest;
299 memcpy(p, &count, sizeof(int));
300 p = (void*)((char*)p + sizeof(int));
302 for (int i = 0; i < count; i++)
304 memcpy(p, &(pConvViewList->msgInfo[i]), sizeof(MSG_LIST_S));
305 p = (void*)((char*)p + sizeof(MSG_LIST_S));
312 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
314 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
316 MSG_DEBUG("datasize = [%d] \n", dataSize);
318 *ppDest = (char*)new char[dataSize];
320 void* p = (void*)*ppDest;
322 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
323 p = (void*)((char*)p + sizeof(int));
325 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
326 p = (void*)((char*)p + sizeof(int));
328 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
329 p = (void*)((char*)p + sizeof(int));
331 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
332 p = (void*)((char*)p + sizeof(int));
337 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
341 dataSize = sizeof(unsigned int);
343 *ppDest = (char*)new char[dataSize];
345 void* p = (void*)*ppDest;
347 memcpy(p, memsize, dataSize);
353 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
357 dataSize = sizeof(int) + sizeof(int);
359 *ppDest = (char*)new char[dataSize];
361 void* p = (void*)*ppDest;
363 memcpy(p, &msgId, sizeof(int));
364 p = (void*)((char*)p + sizeof(int));
366 memcpy(p, &extId, sizeof(int));
372 int MsgEncodeStorageChangeData(const MSG_STORAGE_CHANGE_TYPE_T storageChangeType, const MSG_MSGID_LIST_S *pMsgIdList, char **ppDest)
377 count = pMsgIdList->nCount;
379 dataSize = sizeof(MSG_STORAGE_CHANGE_TYPE_T) + sizeof(int) + (sizeof(MSG_MESSAGE_ID_T)*count);
381 *ppDest = (char*)new char[dataSize];
383 void* p = (void*)*ppDest;
385 memcpy(p, &storageChangeType, sizeof(MSG_STORAGE_CHANGE_TYPE_T));
386 p = (void*)((char*)p + sizeof(MSG_STORAGE_CHANGE_TYPE_T));
388 memcpy(p, &count, sizeof(int));
389 p = (void*)((char*)p + sizeof(int));
391 for (int i = 0; i < count; i++) {
392 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(MSG_MESSAGE_ID_T));
393 p = (void*)((char*)p + sizeof(MSG_MESSAGE_ID_T));
400 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, char **ppDest)
404 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S));
406 *ppDest = (char*)new char[dataSize];
408 void* p = (void*)*ppDest;
410 memcpy(p, pReportStatus, dataSize);
417 void MsgDecodeMsgId(char *pSrc, MSG_MESSAGE_ID_T *pMsgId)
419 memcpy(pMsgId, pSrc, sizeof(MSG_MESSAGE_ID_T));
423 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
425 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
429 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
431 memcpy(memsize, pSrc, sizeof(unsigned int));
435 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
437 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
439 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
441 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
445 void MsgDecodeFolderViewList(char *pSrc, MSG_LIST_S *pFolderViewList)
449 memcpy(&count, pSrc, sizeof(int));
450 pSrc = pSrc + sizeof(int);
454 pFolderViewList->nCount = count;
455 pFolderViewList->msgInfo = (msg_message_t*)new char[sizeof(MSG_MESSAGE_S)*count];
457 MSG_MESSAGE_S* pInfoTmp = (MSG_MESSAGE_S*)pFolderViewList->msgInfo;
459 for (int i = 0; i < count; i++)
461 memcpy(pInfoTmp, pSrc, sizeof(MSG_MESSAGE_S));
462 pSrc = pSrc + sizeof(MSG_MESSAGE_S);
466 else if ( count == 0 )
468 pFolderViewList->nCount = count;
469 pFolderViewList->msgInfo = NULL;
474 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
478 memcpy(&count, pSrc, sizeof(int));
479 pSrc = pSrc + sizeof(int);
481 pRecipientList->recipientCnt= count;
482 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
484 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
486 for (int i = 0; i < count; i++)
488 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
489 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
495 void MsgDecodeFolderList(char *pSrc, MSG_FOLDER_LIST_S *pFolderList)
499 memcpy(&count, pSrc, sizeof(int));
500 pSrc = pSrc + sizeof(int);
502 pFolderList->nCount = count;
503 pFolderList->folderInfo = (MSG_FOLDER_INFO_S*)new char[sizeof(MSG_FOLDER_INFO_S)*count];
505 MSG_FOLDER_INFO_S* pInfoTmp = pFolderList->folderInfo;
507 for (int i = 0; i < count; i++)
509 memcpy(pInfoTmp, pSrc, sizeof(MSG_FOLDER_INFO_S));
510 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
516 void MsgDecodeSetting(char *pSrc, MSG_SETTING_S *pSetting)
518 int dataSize = sizeof(MSG_OPTION_TYPE_T);
520 switch (pSetting->type)
522 case MSG_GENERAL_OPT :
523 dataSize += sizeof(MSG_GENERAL_OPT_S);
525 case MSG_SMS_SENDOPT :
526 dataSize += sizeof(MSG_SMS_SENDOPT_S);
529 dataSize += sizeof(MSG_SMSC_LIST_S);
531 case MSG_MMS_SENDOPT :
532 dataSize += sizeof(MSG_MMS_SENDOPT_S);
534 case MSG_MMS_RECVOPT :
535 dataSize += sizeof(MSG_MMS_RECVOPT_S);
537 case MSG_MMS_STYLEOPT :
538 dataSize += sizeof(MSG_MMS_STYLEOPT_S);
540 case MSG_PUSHMSG_OPT :
541 dataSize += sizeof(MSG_PUSHMSG_OPT_S);
544 dataSize += sizeof(MSG_CBMSG_OPT_S);
546 case MSG_VOICEMAIL_OPT :
547 dataSize += sizeof(MSG_VOICEMAIL_OPT_S);
549 case MSG_MSGSIZE_OPT :
550 dataSize += sizeof(MSG_MSGSIZE_OPT_S);
554 memcpy(pSetting, pSrc, dataSize);
558 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
560 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
564 void MsgDecodeThreadViewList(char *pSrc, MSG_THREAD_VIEW_LIST_S *pThreadViewList)
568 memcpy(&count, pSrc, sizeof(int));
569 pSrc = pSrc + sizeof(int);
573 pThreadViewList->nCount = count;
574 pThreadViewList->msgThreadInfo = (msg_thread_view_t*)new char[sizeof(MSG_THREAD_VIEW_S)*count];
576 MSG_THREAD_VIEW_S* pInfoTmp = (MSG_THREAD_VIEW_S*)pThreadViewList->msgThreadInfo;
578 for (int i = 0; i < count; i++)
580 memcpy(pInfoTmp, pSrc, sizeof(MSG_THREAD_VIEW_S));
581 pSrc = pSrc + sizeof(MSG_THREAD_VIEW_S);
587 pThreadViewList->nCount = count;
588 pThreadViewList->msgThreadInfo = NULL;
593 void MsgDecodeConversationViewList(char *pSrc, MSG_LIST_S *pConvViewList)
597 memcpy(&count, pSrc, sizeof(int));
598 pSrc = pSrc + sizeof(int);
602 pConvViewList->nCount = count;
603 pConvViewList->msgInfo = (msg_message_t*)new char[sizeof(MSG_MESSAGE_S)*count];
605 MSG_MESSAGE_S* pInfoTmp = (MSG_MESSAGE_S*)pConvViewList->msgInfo;
607 for (int i = 0; i < count; i++)
609 memcpy(pInfoTmp, pSrc, sizeof(MSG_MESSAGE_S));
610 pSrc = pSrc + sizeof(MSG_MESSAGE_S);
616 pConvViewList->nCount = count;
617 pConvViewList->msgInfo = NULL;
622 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
629 memcpy(&count, pSrc, sizeof(int));
630 pSrc = pSrc + sizeof(int);
631 pMsgThreadCountList->totalCount = count;
634 memcpy(&count, pSrc, sizeof(int));
635 pSrc = pSrc + sizeof(int);
636 pMsgThreadCountList->unReadCount = count;
639 memcpy(&count, pSrc, sizeof(int));
640 pSrc = pSrc + sizeof(int);
641 pMsgThreadCountList->mmsMsgCount = count;
644 memcpy(&count, pSrc, sizeof(int));
645 pSrc = pSrc + sizeof(int);
646 pMsgThreadCountList->smsMsgCount = count;
653 void MsgDecodeReportStatus(char *pSrc, MSG_REPORT_STATUS_INFO_S *pReportStatus)
660 memcpy(&count, pSrc, sizeof(MSG_DELIVERY_REPORT_STATUS_T));
661 pSrc = pSrc + sizeof(MSG_DELIVERY_REPORT_STATUS_T);
662 pReportStatus->deliveryStatus = count;
665 memcpy(&count, pSrc, sizeof(time_t));
666 pSrc = pSrc + sizeof(time_t);
667 pReportStatus->deliveryStatusTime = count;
670 memcpy(&count, pSrc, sizeof(MSG_READ_REPORT_STATUS_T));
671 pSrc = pSrc + sizeof(MSG_READ_REPORT_STATUS_T);
672 pReportStatus->readStatus = count;
675 memcpy(&count, pSrc, sizeof(time_t));
676 pSrc = pSrc + sizeof(time_t);
677 pReportStatus->readStatusTime = count;
685 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, MSG_ERROR_T MsgError, void **ppEvent)
687 MSG_EVENT_S* pMsgEvent = NULL;
689 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
691 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
693 pMsgEvent->eventType = MsgEvent;
694 pMsgEvent->result = MsgError;
696 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
697 MSG_DEBUG("result [%d]", pMsgEvent->result);
700 memcpy((void*)pMsgEvent->data, pData, DataSize);
702 return (sizeof(MSG_EVENT_S) + DataSize);