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.
31 #ifndef MMS_PLUGIN_CODEC_H
32 #define MMS_PLUGIN_CODEC_H
35 /*==================================================================================================
37 ==================================================================================================*/
41 #include "MsgMmsTypes.h"
42 #include "MmsPluginMessage.h"
43 #include "MsgTransportTypes.h"
45 /*==================================================================================================
47 ==================================================================================================*/
49 #define MMS_MAJOR_VERSION 1
52 #define MMS_MINOR_VERSION 1
53 #define MMS_VERSION 0x91
55 #elif defined(MMS_V1_2)
56 #define MMS_MINOR_VERSION 2
57 #define MMS_VERSION 0x92
60 #define MMS_MINOR_VERSION 0
61 #define MMS_VERSION 0x90
64 #define MMS_SIGN_TEXT_LEN 100
65 #define MMS_MAX_FIELD_VALUE_COUNT 74
66 #define MMS_MAX_FIELD_TYPE_COUNT 21
67 #define MSG_MMS_ENCODE_BUFFER_MAX (2 * 1024)
68 #define MSG_MMS_DECODE_BUFFER_MAX (2 * 1024)
71 #define MARK 0x22 // "
73 #define LENGTH_QUOTE 0x1F
74 #define MSG_STDSTR_LONG 0xFF
75 #define INVALID_VALUE -1
76 #define MSG_INVALID_VALUE -1
78 #define MMS_MAX_FIELD_VALUE_COUNT 74
79 #define MMS_MAX_FIELD_TYPE_COUNT 21
81 #define MSG_LOCAL_TEMP_BUF_SIZE 1024
82 #define MSG_INBOX_DIRECTORY "/User/Msg/Inbox"
83 /*==================================================================================================
85 ==================================================================================================*/
90 MMS_CODE_CONTENTLOCATION,
93 MMS_CODE_DELIVERYREPORT,
94 MMS_CODE_DELIVERYTIME,
104 MMS_CODE_REPORTALLOWED,
105 MMS_CODE_RESPONSESTATUS,
106 MMS_CODE_RETRIEVESTATUS, /* Add by MMSENC v1.1 */
107 MMS_CODE_RESPONSETEXT,
108 MMS_CODE_RETRIEVETEXT, /* Add by MMSENC v1.1 */
109 MMS_CODE_SENDERVISIBILLITY,
115 /* Add by MMSENC v1.1 */
117 MMS_CODE_REPLYCHARGING,
118 MMS_CODE_REPLYCHARGINGDEADLINE,
119 MMS_CODE_REPLYCHARGINGID,
120 MMS_CODE_REPLYCHARGINGSIZE,
121 MMS_CODE_PREVIOUSLYSENTBY,
122 MMS_CODE_PREVIOUSLYSENTDATE,
124 MMS_CODE_TRANSFERENCODING,
125 MMS_CODE_DISPOSITION,
130 MMS_BODYHDR_TRANSFERENCODING,
131 MMS_BODYHDR_DISPOSITION,
132 MMS_BODYHDR_CONTENTID,
133 MMS_BODYHDR_CONTENTLOCATION,
134 MMS_BODYHDR_X_OMA_DRM_SEPARATE_DELIVERY, // DRM RO WAITING
140 MmsCodeParameterCode,
141 MmsCodeMsgBodyHeaderCode,
145 MmsCodeDeliveryReport,
149 MmsCodeResponseStatus,
150 MmsCodeRetrieveStatus,
152 MmsCodeReportAllowed,
153 MmsCodeSenderVisibility,
158 MmsCodeReplyCharging,
162 MmsCodeMsgDisposition,
163 MmsCodeContentTransferEncoding
167 MSG_PRESENTATION_NONE = -1,
168 MSG_PRESENTATION_FIRSTPART, //Content-type == type parameter
169 MSG_PRESENTATION_TYPE_BASE, //Content-type == type parameter
170 MSG_PRESENTATION_LOCATION, //Content-Location == start parameter
171 MSG_PRESENTATION_ID, //Content-ID == start parameter
172 } MsgPresentationFactor;
174 /*==================================================================================================
176 ==================================================================================================*/
190 MsgPresentationFactor factor;
191 MsgMultipart *pPrevPart;
192 MsgMultipart *pCurPresentation;
193 } MsgPresentaionInfo;
195 // for Decoding & Encoding
199 int msgID; // if noti.ind, msgID is -1.
202 char szTrID[MMS_TR_ID_LEN+1];
206 MsgHeaderAddress *pFrom; //"/TYPE=PLMN", /"TYPE=IPv4", "/TYPE=IPv6"
207 MsgHeaderAddress *pTo;
208 MsgHeaderAddress *pCc;
209 MsgHeaderAddress *pBcc;
210 char szSubject[MSG_LOCALE_SUBJ_LEN + 1];
211 MmsResponseStatus responseStatus;
212 MmsRetrieveStatus retrieveStatus;
213 char szResponseText[MMS_LOCALE_RESP_TEXT_LEN + 1];
214 char szRetrieveText[MMS_LOCALE_RESP_TEXT_LEN + 1];
216 MmsMsgClass msgClass;
217 MmsTimeStruct expiryTime;
218 MmsTimeStruct deliveryTime;
219 MmsPriority priority;
220 MmsSenderVisible hideAddress;
221 MmsReport deliveryReport;
223 MmsReportAllowed reportAllowed;
224 char szContentLocation[MMS_LOCATION_LEN + 1];
226 MSG_DELIVERY_REPORT_STATUS_T msgStatus;
227 MSG_READ_REPORT_STATUS_T readStatus;
229 MmsReplyCharge replyCharge;
231 // only used at Decoding module
232 char szMsgID[MMS_MSG_ID_LEN + 1];
235 #ifdef __SUPPORT_DRM__
239 // dependent to Client implementation
244 extern const MmsField gMmsField[MMS_MAX_FIELD_TYPE_COUNT][MMS_MAX_FIELD_VALUE_COUNT];
245 extern char gszMmsLoadBuf1[MSG_MMS_DECODE_BUFFER_MAX + 1];
246 extern char gszMmsLoadBuf2[MSG_MMS_DECODE_BUFFER_MAX + 1];
248 extern MmsHeader mmsHeader;
251 char *_MmsGetTextValue(MmsCode i, int j);
252 char *_MmsGetTextValuebyField(int field, int value);
253 int _MmsGetTextType(MmsCode i, char *pValue);
254 UINT16 _MmsGetBinaryValue(MmsCode i, int j);
255 int _MmsGetBinaryType(MmsCode i, UINT16 value);
256 UINT8 _MmsGetVersion(MmsMsg *pMsg);
257 bool _MmsSetVersion(int majorVer, int minorVer);
261 void _MmsInitHeader();
262 void _MmsCleanDecodeBuff(void);
263 bool _MmsDecodeInitialize(void);
264 void _MmsRegisterDecodeBuffer(char *pInBuff1, char *pInBuffer2, int maxLen);
265 void _MmsUnregisterDecodeBuffer(void);
266 int _MmsGetDecodeOffset(void);
268 bool MmsBinaryDecodeMsgBody(FILE *pFile, char *szFilePath, int totalLength);
269 bool MmsBinaryDecodeContentType(FILE *pFile, char *szFilePath, int totalLength); // for JAVA MMS AppId
271 bool MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, int totalLength);
272 int MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int totalLength);
273 bool MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int headerLen, int totalLength);
274 bool MmsBinaryDecodePartBody(FILE *pFile, UINT32 bodyLength, int totalLength);
275 bool MmsBinaryDecodeEntries(FILE *pFile, UINT32 *npEntries, int totalLength);
276 bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength);
278 bool MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, int totalLength);
282 void _MmsRegisterEncodeBuffer(char *pInBuff, int maxLen);
283 void _MmsUnregisterEncodeBuffer(void);
284 int _MmsGetEncodeOffset(void);
286 bool _MmsEncodeMsg(void);
287 bool _MmsEncodeSendReq(FILE *pFile, MmsMsg *pMsg);
288 bool _MmsEncodeTemplate(FILE *pFile, MmsMsg *pMsg); // just encode MMS Body without any header.
289 bool _MmsEncodeAckInd(FILE *pFile, char *szTrID, bool bReportAllowed);
290 bool _MmsEncodeNotiRespInd(FILE *pFile, char *szTrID, MSG_DELIVERY_REPORT_STATUS_T iStatus, bool bReportAllowed);
291 bool _MmsEncodeForwardReq(FILE *pFile, char *szContentLocation, char *szForwardTo, char *szForwardCc, char *szForwardBcc);
292 bool _MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, MSG_READ_REPORT_STATUS_T mmsReadStatus);
293 bool _MmsEncodeReadReport11(FILE *pFile, MmsMsg *pMsg, MSG_READ_REPORT_STATUS_T mmsReadStatus);
296 bool MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody, int nPartCount, bool bTemplate);//NEW_TEMPLATE
298 int MmsBinaryEncodeContentTypeLen(MsgType *pType);
299 bool MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLength);
300 int MmsBinaryEncodeContentHeaderLen(MsgContentType contentType, MsgType *pType, bool bMultipart);
301 bool MmsBinaryEncodeContentHeader(FILE *pFile, MsgContentType contentType, MsgType *pType, bool bMultipart);
302 bool MmsBinaryEncodeContentBody(FILE *pFile, MsgBody *pBody);
303 bool MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pType, MsgBody *pBody);
304 bool MmsBinaryEncodeSendReqHdrwithinBufRegi(FILE *pFile, MmsMsg *pMsg);
305 bool MsgWriteDataFromEncodeBuffer(FILE *pFile, char *pInBuffer, int *pPtr, int maxLen, int *pOffset);
306 bool MsgLoadDataToDecodeBuffer(FILE *pFile, char **ppBuf, int *pPtr, int *pOffset, char *pInBuf1, char *pInBuf2, int maxLen, int *npRead, int endOfFile);
307 bool MsgFreeHeaderAddress(MsgHeaderAddress *pAddr);
308 bool MsgCheckFileNameHasInvalidChar(char *szName);
309 bool _MsgReplaceInvalidFileNameChar(char *szInText, char replaceChar);
310 char *_MsgGetStringUntilDelimiter(char *pszString, char delimiter);
311 char *MsgChangeHexString(char *pOrg);
312 bool _MsgParseParameter(MsgType *pType, char *pSrc);
313 char *_MsgSkipWS(char *s);
314 char *__MsgSkipComment(char *s, long trim);
315 int _MsgGetCode(MsgHeaderField tableId, char *pStr);
316 char *MsgConvertLatin2UTF8FileName(char *pSrc);
317 bool _MsgChangeSpace(char *pOrg, char **ppNew);
318 void _MsgRemoveFilePath(char *pSrc);
319 bool MsgIsUTF8String(unsigned char *szSrc, int nChar);
320 bool MsgIsPercentSign(char *pSrc);
321 MsgMultipart *MsgAllocMultipart(void);
322 bool _MsgInitMsgType(MsgType *pMsgType);
323 bool _MsgInitMsgBody(MsgBody *pMsgBody);
324 MsgPresentationFactor MsgIsPresentationEx(MsgType *multipartType, char *szStart, MsgContentType typeParam);
325 void MsgConfirmPresentationPart(MsgType *pMsgType, MsgBody *pMsgBody, MsgPresentaionInfo *pPresentationInfo);
326 bool MsgIsMultipartRelated(int type);
327 bool MsgIsPresentablePart(int type);
328 bool MsgIsText(int type);
329 bool _MsgFreeBody(MsgBody *pBody, int type);
330 bool MsgFreeAttrib(MmsAttrib *pAttrib);
331 bool MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody);
332 char *MsgResolveContentURI(char *szSrc);
333 bool _MsgParsePartHeader(MsgType *pType, const char *pRawData, int nRawData);
334 char *MsgRemoveQuoteFromFilename(char *pSrc);
335 MmsMsg *MmsGetMsgById(MmsMsgID msgID, bool msgLock);
336 bool MsgIsMultipart(int type);
337 bool MsgIsHexChar(char *pSrc);
338 char _MsgConvertHexValue(char *pSrc);
339 int __MsgConvertCharToInt(char ch);
340 bool __MsgInitMsgContentParam(MsgContentParam *pMsgContentParam);
341 bool MsgCopyNestedMsgType(MsgType *pMsgType1, MsgType *pMsgType2);
342 bool MsgCopyNestedMsgParam(MsgContentParam *pParam1, MsgContentParam *pParam2);
343 bool MsgIsMultipartMixed(int type);
344 bool MsgStrcpyWithoutCRLF(char *pOrg, char **ppNew);
345 bool __MsgIsInvalidFileNameChar(char ch);
346 bool MmsAddrUtilCompareAddr(char *pszAddr1, char *pszAddr2);
347 bool _MmsDataUpdateLastStatus(MmsMsg *pMsg);
349 bool _MsgEncodeBase64(void *pSrc, unsigned long srcLen, unsigned long *len, unsigned char *ret);
350 void *_MsgDecodeBase64(unsigned char *pSrc, unsigned long srcLen, unsigned long *len);
351 bool _MsgEncodeQuotePrintable(unsigned char *pSrc, unsigned long srcLen, unsigned long *len, unsigned char *ret);
352 unsigned char *_MsgDecodeQuotePrintable(unsigned char *pSrc, unsigned long srcLen, unsigned long *len);
353 bool _MsgEncode2Base64(void *pSrc, unsigned long srcLen, unsigned long *len, unsigned char *ret);
354 char *_MsgDecodeText(char *pOri);
355 char *MsgEncodeText(char *pOri);
356 int MsgGetLatin2UTFCodeSize(unsigned char *szSrc, int nChar);
357 int MsgLatin5code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar);
358 int MsgGetLatin52UTFCodeSize(unsigned char *szSrc, int nChar);
359 int MsgLatin2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar);
360 int MsgLatin7code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar);
361 int MsgGetLatin72UTFCodeSize(unsigned char *szSrc, int nChar);
362 int MsgUnicode2UTF(unsigned char *des, int outBufSize, unsigned short *szSrc, int nChar);
363 int MsgGetUnicode2UTFCodeSize(unsigned short *szSrc, int nChar);
364 bool MmsAddrUtilCheckEmailAddress(char *pszAddr);
365 bool MmsAddrUtilRemovePlmnString(char *pszAddr);
366 int MsgCutUTFString(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar);
367 void MsgMIMERemoveQuote(char *szSrc);
368 bool _MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody, char *pszMailboxPath, char *pszMsgFilename, int index, bool bSave);
369 bool MsgGetTypeByFileName(int *type, char *szFileName);
370 bool MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE *pFile);
371 char *MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue, int msgTypeValue, int msgCharsetValue, int *npRead);
372 #ifndef __SUPPORT_DRM__
373 bool MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex);
375 bool MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex);
377 bool MsgGetFileNameWithoutExtension(char *szOutputName, char *szName);
378 int MmsGetMediaPartCount(MSG_MESSAGE_ID_T msgId);
379 bool MmsGetMediaPartHeader(int index, MsgType *pHeader);
380 bool MmsGetMsgAttrib(MmsMsgID msgID, MmsAttrib *pAttrib);
381 bool _MmsReadMsgBody(MSG_MESSAGE_ID_T msgID, bool bSavePartsAsTempFiles, bool bRetrieved, char *retrievedPath);
383 #ifdef __SUPPORT_DRM__
384 void _MsgFreeDRMInfo(MsgDRMInfo *pDrmInfo);
385 bool MsgCopyDrmInfo(MsgType *pPartType);
386 bool MmsDrm2ConvertMsgBody(char *szOriginFilePath);
387 bool MmsDrm2ReadMsgConvertedBody(MSG_MESSAGE_INFO_S *pMsg, bool bSavePartsAsTempFiles, bool bRetrieved, char *retrievedPath);
388 bool MmsDrm2DecodeConvertedMsg(int msgID, char *pszFullPath);
391 bool MmsDebugPrintMulitpartEntry(MsgMultipart *pMultipart, int index);