2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "MmsPluginMessage.h"
21 #include "MmsPluginCodec.h"
23 #include "MsgUtilFile.h"
24 #include "MmsPluginMIME.h"
26 gint _g_time_rev_set = 0;
29 /** Sending message related variables ------------------------ */
31 static char gszMmsEncodeBuf[MSG_MMS_ENCODE_BUFFER_MAX] = {0, };
32 static int gCurMmsEncodeBuffPos = 0; /* number of characters on gpMmsEncodeBuf */
33 static int gMmsEncodeMaxLen = 0;
34 static int gMmsEncodeCurOffset = 0; /* offset in file */
35 static char *gpMmsEncodeBuf = NULL;
38 /* Acknowledge.ind & NotifyResp.ind related variables ------------------------ */
40 static char gszMmsEncodeBuf2[MSG_MMS_ENCODE_BUFFER_MAX] = {0, };
41 static int gCurMmsEncodeBuffPos2 = 0; /* number of characters on gpMmsEncodeBuf */
42 static int gMmsEncodeMaxLen2 = 0;
43 static int gMmsEncodeCurOffset2 = 0; /* offset in file */
44 static char *gpMmsEncodeBuf2 = NULL;
47 bool _MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg);
48 bool _MmsBinaryEncodeAckIndHdr(FILE *pFile, char *pTrID, bool bReportAllowed);
49 bool _MmsBinaryEncodeNotiRespIndHdr(FILE* pFile, char *pTrID, msg_delivery_report_status_t iStatus, bool bReportAllowed);
50 bool _MmsBinaryEncodeForwardReqHdr(FILE *pFile, char *szContentLocation, char *szForwardTo, char *szForwardCc, char *szForwardBcc);
51 bool _MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus);
52 bool _MmsBinaryEncodeReadReport11Hdr(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus);
54 static bool __MmsEncodeSendReq(FILE *pFile, MmsMsg *pMsg, bool bIncludeSendReqHeader);
55 static int MmsBinaryEncodeUintvarLen(UINT32 integer);
56 static bool MmsBinaryEncodeUintvar(FILE *pFile, UINT32 integer, int length);
57 static int MmsBinaryEncodeValueLengthLen(UINT32 integer);
58 static bool MmsBinaryEncodeValueLength(FILE *pFile, UINT32 integer, int length);
59 static int MmsBinaryEncodeIntegerLen(UINT32 integer);
60 static bool MmsBinaryEncodeInteger(FILE *pFile, UINT32 integer, int length);
61 static int MmsBinaryEncodeLongIntegerLen(UINT32 integer);
62 static bool MmsBinaryEncodeLongInteger(FILE *pFile, UINT32 integer, int length);
63 static int MmsBinaryEncodeTextStringLen(UINT8 *source);
64 static bool MmsBinaryEncodeTextString(FILE *pFile, UINT8 *source, int length);
65 static int MmsBinaryEncodeQuotedStringLen(UINT8 *pSrc);
66 static bool MmsBinaryEncodeQuotedString(FILE *pFile, UINT8 *source, int length);
67 static int MmsBinaryEncodeEncodedStringLen(UINT8 *source);
68 static bool MmsBinaryEncodeEncodedString(FILE *pFile, UINT8 *source, int length);
69 bool MmsBinaryEncodeSendReqHdrwithinBufRegi(FILE *pFile, MmsMsg *pMsg);
70 bool MmsBinaryEncodeSendReqHdrContTypeFildCode(FILE *pFile, int msgID);
72 static bool __MmsBinaryEncodeFieldCodeAndValue(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue);
74 static bool __MmsBinaryEncodeMmsVersion(FILE *pFile);
75 static bool __MmsBinaryEncodeTrID(FILE *pFile, char *szTrID, int bufLen);
76 static bool __MmsBinaryEncodeMsgID(FILE *pFile, const char *szMsgID); /** 2005-05-24, added for read-reply PDU 1.2 */
77 static bool __MmsBinaryEncodeFrom(FILE *pFile);
78 static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeStruct time);
79 static bool __MmsBinaryEncodeDate(FILE *pFile);
80 static bool __MmsBinaryEncodeOneAddress(FILE *pFile, MmsFieldCode addrType, char *szAddrStr);
81 static bool __MmsBinaryEncodeAddress(FILE *pFile, MmsFieldCode addrType, char *szAddr);
84 /* Functions for Acknowledge.ind & NotifyResp.ind ------------------------ */
86 static bool MmsBinaryEncodeTextString2(FILE *pFile, UINT8 *source, int length);
87 static bool __MmsBinaryEncodeMmsVersion2(FILE *pFile);
88 static bool __MmsBinaryEncodeFieldCodeAndValue2(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue);
89 extern int MsgProcessUrgentEvent(int iMode);
92 /** -----------------------------------------------------------------
94 * * -----------------------------------------------------------------*/
97 static void __MmsCleanEncodeBuff(void)
99 memset(gpMmsEncodeBuf, 0, MSG_MMS_ENCODE_BUFFER_MAX);
100 gCurMmsEncodeBuffPos = 0;
104 void _MmsRegisterEncodeBuffer(char *pInBuff, int maxLen)
106 gpMmsEncodeBuf = pInBuff;
107 gCurMmsEncodeBuffPos = 0;
108 gMmsEncodeMaxLen = maxLen;
109 gMmsEncodeCurOffset = 0;
112 void _MmsUnregisterEncodeBuffer(void)
114 gpMmsEncodeBuf = NULL;
115 gCurMmsEncodeBuffPos = 0;
116 gMmsEncodeMaxLen = 0;
117 gMmsEncodeCurOffset = 0;
120 int _MmsGetEncodeOffset(void)
122 return (gMmsEncodeCurOffset + gCurMmsEncodeBuffPos);
126 bool _MmsEncodeMsg(void)
128 MSG_DEBUG("_MmsEncodeMsg: Start Binary Encoding now ============= \n");
133 bool _MmsEncodeSendReq(FILE *pFile, MmsMsg *pMsg)
135 return __MmsEncodeSendReq(pFile, pMsg, true);
139 bool _MmsEncodeTemplate(FILE *pFile, MmsMsg *pMsg)
141 return __MmsEncodeSendReq(pFile, pMsg, false);
145 static bool __MmsEncodeSendReq(FILE* pFile, MmsMsg* pMsg, bool bIncludeSendReqHeader)
147 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
149 if (bIncludeSendReqHeader) {
150 if (_MmsBinaryEncodeSendReqHdr(pFile, pMsg) == false) {
151 _MmsUnregisterEncodeBuffer();
156 if (MmsBinaryEncodeMsgBody(pFile, &pMsg->msgType, &pMsg->msgBody, pMsg->nPartCount, !bIncludeSendReqHeader) == false) {
157 _MmsUnregisterEncodeBuffer();
161 _MmsUnregisterEncodeBuffer();
167 /* Functions for Acknowledge.ind & NotifyResp.ind ------------------------ */
169 static void __MmsCleanEncodeBuff2(void)
171 memset(gpMmsEncodeBuf2, 0, MSG_MMS_ENCODE_BUFFER_MAX);
172 gCurMmsEncodeBuffPos2 = 0;
176 void _MmsRegisterEncodeBuffer2(char *pInBuff, int maxLen)
178 gpMmsEncodeBuf2 = pInBuff;
179 gCurMmsEncodeBuffPos2 = 0;
180 gMmsEncodeMaxLen2 = maxLen;
181 gMmsEncodeCurOffset2 = 0;
184 void _MmsUnregisterEncodeBuffer2(void)
186 gpMmsEncodeBuf2 = NULL;
187 gCurMmsEncodeBuffPos2 = 0;
188 gMmsEncodeMaxLen2 = 0;
189 gMmsEncodeCurOffset2 = 0;
194 * @param source [in] originam string
195 * @param length [in] gotten from MmsBinaryEncodeTextStringLen()
196 * @param dest [in] buffer to store quted string
197 * @return changed string length
199 static bool MmsBinaryEncodeTextString2(FILE *pFile, UINT8 *source, int length)
201 MSG_DEBUG("MmsBinaryEncodeTextString2: \n");
205 * Text-string = [Quote] *TEXT End-of-string
206 * If the 1st char in the TEXT is in the range of 128-255, a Quote char must precede it.
207 * Otherwise the Quote char must be omitted.
208 * The Quote is not part of the contents.
209 * Quote = <Octet 127>
212 if (pFile == NULL || source == NULL) {
213 MSG_DEBUG("MmsBinaryEncodeTextString2: source == NULL \n");
217 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < length) {
218 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
219 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
220 MSG_DEBUG("MmsBinaryEncodeTextString2: MsgWriteDataFromEncodeBuffer fail \n");
225 if (source[0] > 0x7F) {
226 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = QUOTE;
230 strncpy(gpMmsEncodeBuf2 + gCurMmsEncodeBuffPos2, (char*)source, (length - 1)); /** except NULL */
231 gCurMmsEncodeBuffPos2 += (length - 1); /** except NULL */
232 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = (UINT8)NULL;
241 static bool __MmsBinaryEncodeFieldCodeAndValue2(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue)
243 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < 2) {
244 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
245 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
246 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: MsgWriteDataFromEncodeBuffer fail \n");
251 if (fieldCode == 0xff) {
252 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldCode \n");
256 if (fieldValue == 0xff) {
257 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldValue \n");
261 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = fieldCode;
262 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = fieldValue;
271 static bool __MmsBinaryEncodeMmsVersion2(FILE *pFile)
273 UINT8 majorVer = MMS_MAJOR_VERSION;
274 UINT8 minorVer = MMS_MINOR_VERSION;
276 MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: \n");
279 MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: invalid input file \n");
284 MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: invalid major version (%d)\n", majorVer);
288 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < 2) {
289 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
290 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
291 MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: MsgWriteDataFromEncodeBuffer fail \n");
296 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_VERSION) | 0x80;
297 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2] = (majorVer << 4) | (minorVer & 0x0f) | MSB;
299 if (gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2] < 0x80) {
300 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] |= 0x80;
302 gCurMmsEncodeBuffPos2++;
312 bool _MmsBinaryEncodeAckIndHdr(FILE *pFile, char *szTrID, bool bReportAllowed)
315 UINT8 fieldCode = 0xff;
316 UINT8 fieldValue = 0xff;
318 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: szTrID = %s\n", szTrID);
319 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: bReportAllowed = %d\n", bReportAllowed);
321 __MmsCleanEncodeBuff2();
324 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
325 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_ACKNOWLEDGE_IND) | 0x80;
326 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
327 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: msgType error\n");
331 /* trID (other type of message) */
332 length = MmsBinaryEncodeTextStringLen((UINT8*)szTrID);
334 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MmsBinaryEncodeTextStringLen fail \n");
338 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < (length + 1)) {
339 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
340 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
341 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MsgWriteDataFromEncodeBuffer fail \n");
346 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
348 if (MmsBinaryEncodeTextString2(pFile, (UINT8*)szTrID, length) == false) {
349 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MmsBinaryEncodeTextString fail\n");
354 if (__MmsBinaryEncodeMmsVersion2(pFile) == false) {
355 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: __MmsBinaryEncodeMmsVersion error\n");
361 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPORTALLOWED) | 0x80;
363 if (bReportAllowed) {
364 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed, MMS_REPORTALLOWED_YES) | 0x80;
366 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed, MMS_REPORTALLOWED_NO) | 0x80;
369 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
370 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: Report Allowed error\n");
374 /* flush remained data on encoding file */
375 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
376 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
377 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
390 bool _MmsBinaryEncodeNotiRespIndHdr(FILE *pFile, char *szTrID, msg_delivery_report_status_t iStatus, bool bReportAllowed)
393 UINT8 fieldCode = 0xff;
394 UINT8 fieldValue = 0xff;
396 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: szTrID = %s\n", szTrID);
397 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: iStatus = %d\n", iStatus);
398 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: bReportAllowed = %d\n", bReportAllowed);
400 __MmsCleanEncodeBuff2();
403 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
404 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_NOTIFYRESP_IND) | 0x80;
406 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
407 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: msgType error\n");
412 /* trID (other type of message) */
413 length = MmsBinaryEncodeTextStringLen((UINT8*)szTrID);
415 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MmsBinaryEncodeTextStringLen fail \n");
419 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < (length + 1)) {
420 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
421 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
422 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgWriteDataFromEncodeBuffer fail \n");
427 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
428 if (MmsBinaryEncodeTextString2(pFile, (UINT8*)szTrID, length) == false) {
429 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MmsBinaryEncodeTextString fail\n");
434 if (__MmsBinaryEncodeMmsVersion2(pFile) == false) {
435 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: __MmsBinaryEncodeMmsVersion error\n");
441 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgStatus = %d\n", iStatus);
443 if (iStatus != MSG_DELIVERY_REPORT_NONE) {
444 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGSTATUS) | 0x80;
445 fieldValue = _MmsGetBinaryValue(MmsCodeMsgStatus, iStatus) | 0x80;
446 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
447 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgStatus error\n");
454 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPORTALLOWED) | 0x80;
456 if (bReportAllowed) {
457 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed, MMS_REPORTALLOWED_YES) | 0x80;
459 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed, MMS_REPORTALLOWED_NO) | 0x80;
462 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
463 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: Report Allowed error\n");
467 /* flush remained data on encoding file */
468 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
469 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
470 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
482 bool _MmsEncodeAckInd(FILE *pFile, char *pTrID, bool bReportAllowed)
484 _MmsRegisterEncodeBuffer2(gszMmsEncodeBuf2, MSG_MMS_ENCODE_BUFFER_MAX);
486 MSG_DEBUG("_MmsEncodeAckInd: Start Binary Encoding now ============= \n");
488 if (_MmsBinaryEncodeAckIndHdr(pFile, pTrID, bReportAllowed) == false) {
489 MSG_DEBUG("_MmsEncodeAckInd: SendReq Binary encoding fail \n");
493 _MmsUnregisterEncodeBuffer2();
499 MSG_DEBUG("## _MmsEncodeAckInd: failed");
500 _MmsUnregisterEncodeBuffer2();
507 bool _MmsEncodeNotiRespInd(FILE *pFile, char *pTrID, msg_delivery_report_status_t iStatus, bool bReportAllowed)
509 _MmsRegisterEncodeBuffer2(gszMmsEncodeBuf2, MSG_MMS_ENCODE_BUFFER_MAX);
511 MSG_DEBUG("_MmsEncodeNotiRespInd: Start Binary Encoding now ============= \n");
513 if (_MmsBinaryEncodeNotiRespIndHdr(pFile, pTrID, iStatus, bReportAllowed) == false) {
514 MSG_DEBUG("_MmsEncodeNotiRespInd: SendReq Binary encoding fail \n");
518 _MmsUnregisterEncodeBuffer2();
528 /* Functions for Acknowledge.ind & NotifyResp.ind (END) ------------------------ */
529 bool _MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus)
532 MsgMultipart *pPart = NULL;
536 char *pszReportMsg = NULL;
539 struct tm *dateTime = NULL;
543 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
545 MSG_DEBUG("_MmsEncodeMsg: Start Binary Encoding now V1.0============= \n");
547 if (_MmsBinaryEncodeReadReport10Hdr(pFile, pMsg, mmsReadStatus) == false) {
548 MSG_DEBUG("_MmsEncodeReadReport10: SendReq Binary encoding fail \n");
552 memset(&msgType, 0, sizeof(MsgType));
553 memset(&msgBody, 0, sizeof(MsgBody));
555 pText = (char *)malloc(MSG_STDSTR_LONG);
557 MSG_DEBUG("__MmsSendReadReportV10: text body malloc fail \n");
561 memset(pText, 0, MSG_STDSTR_LONG);
564 dateTime = localtime(&RawTime);
565 dateSec = mktime(dateTime);
567 // get report message
568 if (mmsReadStatus == MSG_READ_REPORT_IS_DELETED) {
569 pszReportMsg = (char*)"Your message has been deleted " ;
571 pszReportMsg = (char*)"Your message has been read " ;
574 // make report body ..
575 maxLen = strlen (pszReportMsg) +16 /* date string */ + 8 /* enter chars */ ;
577 if (maxLen > MSG_STDSTR_LONG) {
578 snprintf (pText, MSG_STDSTR_LONG, "%s\n", pszReportMsg);
580 snprintf(pText, MSG_STDSTR_LONG, "%s\r\n\r\n%.4d/%.2d/%.2d %.2d:%.2d\r\n",
581 pszReportMsg, dateTime->tm_year+1900, dateTime->tm_mon+1, dateTime->tm_mday, dateTime->tm_hour, dateTime->tm_min);
585 msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
586 msgType.contentSize = strlen(pText);
587 msgType.param.charset = MSG_CHARSET_UNKNOWN;
590 if ((pPart = MmsAllocMultipart()) == NULL) {
591 MSG_DEBUG("__MmsSendReadReportV10: MsgAllocMultipart Fail \n");
596 pPart->type.type = MIME_TEXT_PLAIN;
597 pPart->type.contentSize = strlen(pText);
598 pPart->type.param.charset = MSG_CHARSET_UTF8;
600 if (pPart->pBody == NULL) {
601 MSG_DEBUG("__MmsSendReadReportV10: pPart->pBody is NULL \n");
605 pPart->pBody->size = strlen(pText);
606 pPart->pBody->body.pText = pText;
608 msgBody.body.pMultipart = pPart;
610 if (MmsBinaryEncodeMsgBody(pFile, &msgType, &msgBody, 1, false) == false) {
611 MSG_DEBUG("__MmsSendReadReportV10: MmsBinaryEncodeMsgBody fail \n");
615 MSG_DEBUG("__MmsSendReadReportV10: Send To RM ReadReport Msg \n");
631 _MmsUnregisterEncodeBuffer();
651 _MmsUnregisterEncodeBuffer();
657 bool _MmsEncodeReadReport11(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus)
659 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
661 MSG_DEBUG("_MmsEncodeMsg: Start Binary Encoding now V1.1============= \n");
663 if (_MmsBinaryEncodeReadReport11Hdr(pFile, pMsg, mmsReadStatus) == false) {
664 MSG_DEBUG("_MmsEncodeMsg: SendReq Binary encoding fail \n");
668 _MmsUnregisterEncodeBuffer();
673 _MmsUnregisterEncodeBuffer();
680 /* ==========================================================
682 B I N A R Y E N C O D I N G
684 ==========================================================*/
687 * Binary Encoded Message Format
689 * < Single Part Body Message >
690 * -----------------------------------
692 * -----------------------------------
693 * | Content Type:start=xxx;type=xxx | ->(ex) Text/Plain, Text/Html, ....
694 * -----------------------------------
695 * | Single Part Body |
696 * -----------------------------------
698 * < Multi Part Body Message >
699 * -----------------------------------
701 * -----------------------------------
702 * | Content Type:start=xxx;type=xxx | -> (ex) Application/vnd.wap.multipart.mixed(related), multipart/mixed(related)
703 * -----------------------------------
704 * | # of Entries (body parts) |
705 * ----------------------------------- < Each Entry >
706 * | Entry 1 | -> -----------------------------
707 * ----------------------------------- | header Length |
708 * | Entry 2 | -----------------------------
709 * ----------------------------------- | Data Length |
710 * | ...... | ----------------------------- -
711 * ----------------------------------- | Content-Type | |
712 * | Entry n | ----------------------------- | Header Length
713 * ----------------------------------- | Header | |
714 * ----------------------------- -
715 * | Data | | Data Length
716 * ----------------------------- -
719 bool _MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
721 UINT8 fieldCode = 0xff;
722 UINT8 fieldValue = 0xff;
725 __MmsCleanEncodeBuff();
728 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
729 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_SEND_REQ) | 0x80;
730 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
731 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: msgType error\n");
735 /* trID (other type of message) */
736 if (__MmsBinaryEncodeTrID(pFile, pMsg->szTrID, MMS_TR_ID_LEN + 1) == false) {
737 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: trID error\n");
741 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: pMsg->szTrID = %s\n", pMsg->szTrID);
743 if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
744 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeMmsVersion error\n");
748 /* From : Insert Token mode */
749 if (__MmsBinaryEncodeFrom(pFile) == false) {
750 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeFrom fail\n");
755 /* To = Encoded-string-value */
756 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szTo) == false)
758 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: To __MmsBinaryEncodeAddress fail\n");
763 /* Cc = Encoded-string-value */
764 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_CC, pMsg->mmsAttrib.szCc) == false) {
765 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: Cc __MmsBinaryEncodeAddress fail\n");
770 /* Bcc = Encoded-string-value */
772 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_BCC, pMsg->mmsAttrib.szBcc) == false) {
773 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: Bcc __MmsBinaryEncodeAddress fail\n");
778 MSG_DEBUG("_MmsBinaryEnocdeSendReqHdr() pMsg->mmsAttrib.szSubject =%s\n",pMsg->mmsAttrib.szSubject);
780 /* Subject = Encoded-string-value */
781 if (pMsg->mmsAttrib.szSubject[0]) {
782 length = MmsBinaryEncodeEncodedStringLen((UINT8*)pMsg->mmsAttrib.szSubject);
784 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MmsBinaryEncodeEncodedStringLen fail \n");
788 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
789 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
790 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
791 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MsgWriteDataFromEncodeBuffer fail \n");
796 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SUBJECT) | 0x80;
797 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
798 if (MmsBinaryEncodeEncodedString(pFile, (UINT8*)pMsg->mmsAttrib.szSubject, length) == false) {
799 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MmsBinaryEncodeEncodedString fail \n");
804 /* MMS-1.3-con-739 */
806 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGCLASS) | 0x80;
807 fieldValue = _MmsGetBinaryValue(MmsCodeMsgClass, (int)pMsg->mmsAttrib.msgClass) | 0x80;
808 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
809 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: msgClass error\n");
812 /* MMS-1.3-con-739 */
813 /* MMS-1.3-con-733 */
814 /* Date = Long-integer */
815 if (!__MmsBinaryEncodeDate(pFile)) {
816 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeDate error\n");
819 /* MMS-1.3-con-733 */
821 /* Expiry Time : Value-length Absolute-token Date-value */
822 if (pMsg->mmsAttrib.bUseExpiryCustomTime == true) {
823 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_EXPIRYTIME, pMsg->mmsAttrib.expiryCustomTime) == false) {
824 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: expiryTime __MmsBinaryEncodeTime fail\n");
827 } else if (pMsg->mmsAttrib.expiryTime.type != MMS_TIMETYPE_NONE) { // for avoiding the creation of the expiry field in case the user selects the maximum
828 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_EXPIRYTIME, pMsg->mmsAttrib.expiryTime) == false) {
829 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: expiryTime __MmsBinaryEncodeTime fail\n");
834 /* Use Custom time for Delivery Time */
835 if (pMsg->mmsAttrib.bUseDeliveryCustomTime == true) {
836 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_DELIVERYTIME, pMsg->mmsAttrib.deliveryCustomTime) == false) {
837 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: deliveryTime __MmsBinaryEncodeTime fail\n");
841 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_DELIVERYTIME, pMsg->mmsAttrib.deliveryTime) == false) {
842 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: deliveryTime __MmsBinaryEncodeTime fail\n");
848 if (pMsg->mmsAttrib.priority!= MMS_PRIORITY_ERROR && pMsg->mmsAttrib.priority!= MMS_PRIORITY_NORMAL) {
849 /* MMS_PRIORITY_NORMAL is default : don't send optional field */
851 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_PRIORITY)|0x80;
852 fieldValue = _MmsGetBinaryValue(MmsCodePriority, pMsg->mmsAttrib.priority)|0x80;
854 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
855 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: priority error\n");
860 /* Sender Visible (hide | show) */
861 if (pMsg->mmsAttrib.bHideAddress == true) {
862 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SENDERVISIBILLITY) | MSB;
863 fieldValue = _MmsGetBinaryValue(MmsCodeSenderVisibility, MMS_SENDER_HIDE) | 0x80;
865 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
866 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: sender visibility error\n");
871 /* Delivery Report (yes | no) */
872 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DELIVERYREPORT)|0x80;
874 if (pMsg->mmsAttrib.bAskDeliveryReport) {
875 fieldValue = _MmsGetBinaryValue(MmsCodeDeliveryReport, MMS_REPORT_YES) | 0x80;
877 fieldValue = _MmsGetBinaryValue(MmsCodeDeliveryReport, MMS_REPORT_NO) | 0x80;
880 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
881 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: sender visibility error\n");
885 /* Read Reply (Yes | no) */
886 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_READREPLY)|0x80;
887 if (pMsg->mmsAttrib.bAskReadReply) {
888 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply, MMS_REPORT_YES)|0x80;
890 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply, MMS_REPORT_NO)|0x80;
893 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
894 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: read reply error\n");
898 if ((pMsg->mmsAttrib.replyCharge.chargeType == MMS_REPLY_REQUESTED) ||
899 (pMsg->mmsAttrib.replyCharge.chargeType == MMS_REPLY_REQUESTED_TEXT_ONLY)) {
902 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPLYCHARGING)|0x80;
903 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply, pMsg->mmsAttrib.replyCharge.chargeType)|0x80;
905 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
906 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyCharging error\n");
910 if (pMsg->mmsAttrib.replyCharge.deadLine.time > 0) {
911 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_REPLYCHARGINGDEADLINE, pMsg->mmsAttrib.replyCharge.deadLine) == false) {
912 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyCharging __MmsBinaryEncodeTime fail\n");
917 if (pMsg->mmsAttrib.replyCharge.chargeSize > 0) {
918 length = MmsBinaryEncodeIntegerLen(pMsg->mmsAttrib.replyCharge.chargeSize);
920 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
921 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
922 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
923 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
928 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPLYCHARGINGSIZE) | 0x80;
930 if (MmsBinaryEncodeInteger(pFile, pMsg->mmsAttrib.replyCharge.chargeSize, length) == false) {
931 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyChargingSize MmsBinaryEncodeInteger error\n");
936 if (pMsg->mmsAttrib.replyCharge.szChargeID[0]) {
937 length = MmsBinaryEncodeTextStringLen((UINT8*)pMsg->mmsAttrib.replyCharge.szChargeID);
939 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: szReplyChargingID MmsBinaryEncodeTextStringLen fail\n");
943 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
944 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
945 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
946 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
951 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPLYCHARGINGID) | 0x80;
953 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pMsg->mmsAttrib.replyCharge.szChargeID, length) == false) {
954 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: szContentLocation MmsBinaryEncodeTextString fail\n");
960 /* flush remained data on encoding file */
961 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
962 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
970 MSG_DEBUG("## _MmsBinaryEncodeSendReqHdr: failed");
974 bool MmsBinaryEncodeSendReqHdrwithinBufRegi(FILE *pFile, MmsMsg *pMsg)
978 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
979 ret = _MmsBinaryEncodeSendReqHdr(pFile, pMsg);
980 _MmsUnregisterEncodeBuffer();
985 bool _MmsBinaryEncodeContentTypeFieldCode(FILE *pFile, int msgID)
987 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 2) {
988 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
989 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
990 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: MsgWriteDataFromEncodeBuffer fail \n");
995 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_CONTENTTYPE) | 0x80;
997 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
998 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
1005 bool MmsBinaryEncodeSendReqHdrContTypeFildCode(FILE *pFile, int msgID)
1009 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
1011 ret = _MmsBinaryEncodeContentTypeFieldCode(pFile, msgID);
1013 _MmsUnregisterEncodeBuffer();
1019 bool _MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus)
1023 UINT8 fieldCode = 0xff;
1024 UINT8 fieldValue = 0xff;
1025 char szSubject[MSG_LOCALE_SUBJ_LEN + 8] = {0, };
1028 MSG_DEBUG("pMsg is NULL");
1032 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: mmsReadStatus = %d\n", mmsReadStatus);
1034 __MmsCleanEncodeBuff();
1037 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
1038 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_SEND_REQ) | 0x80;
1039 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1040 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: msgType error\n");
1044 /* trID (other type of message) */
1045 if (__MmsBinaryEncodeTrID(pFile, NULL, 0) == false) {
1046 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeTrID error\n");
1050 if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
1051 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeMmsVersion error\n");
1055 /* Date = Long-integer */
1056 if (!__MmsBinaryEncodeDate(pFile)) {
1057 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: date __MmsBinaryEncodeDate error\n");
1061 /* From : Insert Token mode */
1062 if (__MmsBinaryEncodeFrom(pFile) == false) {
1063 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeFrom fail\n");
1067 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", pMsg->mmsAttrib.szFrom);
1069 /* To = Encoded-string */
1070 if (pMsg && (strchr(pMsg->mmsAttrib.szFrom, '/') == NULL)) {
1071 length = strlen(pMsg->mmsAttrib.szFrom);
1072 szTo = (char *)malloc(length + 11);
1074 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: szTo alloc fail\n");
1078 snprintf(szTo, length + 11, "%s/TYPE=PLMN", pMsg->mmsAttrib.szFrom);
1079 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", szTo);
1081 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, szTo) == false) {
1082 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
1091 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szFrom) == false) {
1092 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
1097 /* Subject = Encoded-string-value */
1098 if (pMsg && pMsg->mmsAttrib.szSubject[0]) {
1099 if (mmsReadStatus == MSG_READ_REPORT_IS_READ) {
1100 snprintf(szSubject, MSG_LOCALE_SUBJ_LEN + 8, "%s%s", MMS_READ_REPORT_STRING_READ, pMsg->mmsAttrib.szSubject);
1102 snprintf(szSubject, MSG_LOCALE_SUBJ_LEN + 8, "%s%s", MMS_READ_REPORT_STRING_DELETED, pMsg->mmsAttrib.szSubject);
1105 if (mmsReadStatus == MSG_READ_REPORT_IS_READ) {
1106 snprintf(szSubject, MSG_LOCALE_SUBJ_LEN + 8, "%s", MMS_READ_REPORT_STRING_READ);
1109 snprintf(szSubject, MSG_LOCALE_SUBJ_LEN + 8, "%s", MMS_READ_REPORT_STRING_DELETED );
1113 length = MmsBinaryEncodeEncodedStringLen((UINT8*)szSubject);
1115 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MmsBinaryEncodeEncodedStringLen fail \n");
1119 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
1120 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1121 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MsgWriteDataFromEncodeBuffer fail \n");
1126 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SUBJECT) | 0x80;
1127 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
1128 if (MmsBinaryEncodeEncodedString(pFile, (UINT8*)szSubject, length) == false) {
1129 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MmsBinaryEncodeEncodedString fail \n");
1134 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGCLASS) | 0x80;
1135 fieldValue = _MmsGetBinaryValue(MmsCodeMsgClass, MMS_MSGCLASS_AUTO) | 0x80;
1136 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1137 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: msgClass error\n");
1142 /* Delivery Report (yes | no) */
1143 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DELIVERYREPORT) | 0x80;
1144 fieldValue = _MmsGetBinaryValue(MmsCodeDeliveryReport, MMS_REPORT_NO) | 0x80;
1145 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1146 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Delivery Report error\n");
1151 /* Read Reply (Yes | no) */
1152 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_READREPLY) | 0x80;
1153 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply, MMS_REPORT_NO) | 0x80;
1154 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1155 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Read Reply error\n");
1160 /* Sender Visible (hide | show) */
1161 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SENDERVISIBILLITY) | 0x80;
1162 fieldValue = _MmsGetBinaryValue(MmsCodeSenderVisibility, MMS_SENDER_SHOW) | 0x80;
1163 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1164 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Sender Visible error\n");
1168 /* flush remained data on encoding file */
1169 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
1170 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1171 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
1188 bool _MmsBinaryEncodeReadReport11Hdr(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus)
1190 UINT8 fieldCode = 0xff;
1191 UINT8 fieldValue = 0xff;
1194 __MmsCleanEncodeBuff();
1197 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
1198 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_READREC_IND) | 0x80;
1199 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1200 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: msgType error\n");
1205 if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
1206 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeMmsVersion error\n");
1210 if (__MmsBinaryEncodeMsgID(pFile, pMsg->szMsgID) == false)
1213 /* To = Encoded-string */
1214 if (strchr(pMsg->mmsAttrib.szFrom, '/') == NULL) {
1216 length = strlen(pMsg->mmsAttrib.szFrom);
1217 szTo = (char *)malloc(length + 11);
1220 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: szTo alloc fail\n");
1224 snprintf(szTo, length + 11,"%s/TYPE=PLMN", pMsg->mmsAttrib.szFrom);
1225 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", szTo);
1227 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, szTo) == false) {
1228 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
1237 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szFrom) == false) {
1238 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: To __MmsBinaryEncodeAddress fail\n");
1243 /* From : Insert Token mode */
1244 if (__MmsBinaryEncodeFrom(pFile) == false) {
1245 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeFrom fail\n");
1249 /* Date = Long-integer */
1250 if (!__MmsBinaryEncodeDate(pFile)) {
1251 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeDate error\n");
1255 /* Read Status (Yes | no) */
1256 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_READSTATUS) | 0x80;
1257 fieldValue = _MmsGetBinaryValue(MmsCodeReadStatus, mmsReadStatus) | 0x80;
1259 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1260 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: Read Status error\n");
1264 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
1265 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1266 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
1281 bool MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody, int nPartCount, bool bTemplate)
1284 MsgMultipart *pMultipart = NULL;
1286 MSG_DEBUG("MmsBinaryEncodeMsgBody: nPartCount = %d\n", nPartCount);
1288 if (pFile == NULL || pType == NULL) {
1289 MSG_DEBUG("MmsBinaryEncodeMsgBody: invalid file handle\n");
1293 if (MmsIsMultipart(pType->type)) {
1296 /* ---------------------------
1298 * ---------------------------*/
1300 pType->offset = _MmsGetEncodeOffset();
1303 length = MmsBinaryEncodeContentTypeLen(pType);
1305 MSG_DEBUG("MmsBinaryEncodeMsgBody: MmsBinaryEncodeContentTypeLen fail \n");
1308 if (bTemplate == false)
1309 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_CONTENTTYPE) | 0x80;
1311 if (MmsBinaryEncodeContentType(pFile, pType, length) == false) {
1312 MSG_DEBUG("MmsBinaryEncodeMsgBody: MmsBinaryEncodeContentType fail \n");
1316 pBody->offset = _MmsGetEncodeOffset();
1319 if (pBody->pPresentationBody) {
1320 nEntries = nPartCount + 1;
1322 nEntries = nPartCount;
1325 if (nEntries >= 0) {
1326 length = MmsBinaryEncodeUintvarLen(nEntries);
1328 MSG_DEBUG("MmsBinaryEncodeMsgBody: nEntries MmsBinaryEncodeUintvarLen fail \n");
1331 if (MmsBinaryEncodeUintvar(pFile, nEntries, length) == false) {
1332 MSG_DEBUG("MmsBinaryEncodeMsgBody: nEntries MmsBinaryEncodeUintvar fail \n");
1336 pType->size = _MmsGetEncodeOffset() - pType->offset;
1340 if (nEntries && pBody->pPresentationBody) {
1341 if (MmsBinaryEncodeMsgPart(pFile, pType->type, &pBody->presentationType, pBody->pPresentationBody) == false) {
1342 MSG_DEBUG("MmsBinaryEncodeMsgBody: __MmsBinaryEncodeMsgPart fail \n");
1349 pMultipart = pBody->body.pMultipart;
1350 while (nEntries && pMultipart) {
1351 if (MmsBinaryEncodeMsgPart(pFile, pType->type, &pMultipart->type, pMultipart->pBody) == false) {
1352 MSG_DEBUG("MmsBinaryEncodeMsgBody: __MmsBinaryEncodeMsgPart fail \n");
1355 pMultipart = pMultipart->pNext;
1359 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
1360 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1361 MSG_DEBUG("MmsBinaryEncodeMsgBody: Empty message body MsgWriteDataFromEncodeBuffer fail \n");
1366 pBody->size = _MmsGetEncodeOffset() - pBody->offset;
1368 /* ---------------------------
1369 * Singlepart message
1370 * ---------------------------*/
1371 pType->offset = _MmsGetEncodeOffset();
1373 if (MmsBinaryEncodeContentHeader(pFile, (MimeType)pType->type, pType, false) == false)
1376 length = MmsBinaryEncodeContentTypeLen(pType);
1378 MSG_DEBUG("MmsBinaryEncodeMsgBody: Singlepart MmsBinaryEncodeContentTypeLen fail \n");
1382 if (MmsBinaryEncodeContentType(pFile, pType, length) == false)
1385 pType->size = _MmsGetEncodeOffset() - pType->offset;
1387 if (MmsBinaryEncodeContentBody(pFile, pBody) == false)
1394 MSG_DEBUG("## MmsBinaryEncodeMsgBody: failed\n");
1400 int MmsBinaryEncodeContentTypeLen(MsgType *pType)
1403 int totalLength = 0;
1404 UINT16 fieldValue = 0xffff;
1405 char *szTextType = NULL;
1406 int contentType = MIME_UNKNOWN;
1408 MSG_DEBUG("MSmsBinaryEncodeContentTypeLen: type\n");
1411 * Content-type-value = Constrained-media | Content-general-form
1412 * Constrained-media = Constrained-encoding
1413 * Constrained-encoding = Extension-Media | Short-integer
1414 * Extension-media = *TEXT End-of-string
1415 * Content-general-form = Value-length Media-type
1416 * Media-type = (Well-known-media | Extension-Media) *(Parameter)
1419 /* Content-type-value = Content-general-form ------------------------------- */
1422 contentType = pType->type;
1424 fieldValue = _MmsGetBinaryValue(MmsCodeContentType, contentType);
1425 if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
1426 /* Extension-media type */
1427 szTextType = _MmsGetTextValue(MmsCodeContentType, contentType);
1428 if (szTextType != NULL) {
1429 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
1431 MSG_DEBUG("MSmsBinaryEncodeContentTypeLen: szTextType MmsBinaryEncodeTextStringLen fail \n");
1434 totalLength += length;
1442 /* Parameters -------------------------------------------------------------- */
1444 MSG_DEBUG("MSmsBinaryEncodeContentTypeLen: parameters \n\n");
1446 /* Well-known-charset = Any-charset | Integer-value ----------------------- */
1448 if (pType->param.charset != MSG_CHARSET_UNKNOWN) {
1449 fieldValue = _MmsGetBinaryValue(MmsCodeCharSet, pType->param.charset);
1450 length = MmsBinaryEncodeIntegerLen(fieldValue);
1452 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: charSet MmsBinaryEncodeIntegerLen fail \n");
1455 totalLength += (length + 1);
1457 if (MmsIsText(contentType)) { // Any-charset
1458 if (!MmsIsVitemContent (contentType, pType->param.szName))
1464 /* Name = Text-string ------------------------------------------------------ */
1466 if (pType->param.szName[0]) {
1467 char* pszName = NULL;
1469 if (_MsgIsASCII (pType->param.szName)) {
1470 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is consisted of ascii char-set chars. \n");
1472 pszName = (char *)malloc(strlen(pType->param.szName) +1);
1473 memset(pszName, 0, (strlen(pType->param.szName)+1));
1474 strcpy(pszName, pType->param.szName);
1476 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is not consisted of ascii char-set chars. \n");
1477 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pType->param.szName : %s\n", pType->param.szName);
1479 /* if msg-server can't support non ascii, then convert non-ascii to '_' by using _MsgReplaceNonAscii*/
1480 int filelen = strlen(pType->param.szName);
1482 pszName = (char *)malloc(filelen + 1);
1483 memset(pszName, 0, (filelen + 1));
1484 strncpy(pszName, pType->param.szName, filelen);
1486 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pszName : %s\n", pszName);
1489 //change empty space to '_' in the file name
1490 if (_MsgIsSpace(pszName)) {
1491 char *pszTempName = NULL;
1493 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName has space(' '). \n");
1495 _MsgReplaceSpecialChar(pszName, &pszTempName, ' ');
1499 pszName = pszTempName;
1501 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pszName : %s\n", pszName);
1504 length = MmsBinaryEncodeTextStringLen((UINT8*)pszName);
1508 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName MmsBinaryEncodeIntegerLen fail \n");
1512 totalLength += (length + 1);
1515 #ifdef FEATURE_JAVA_MMS
1516 if (pType->param.szApplicationID) {
1517 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szApplicationID);
1519 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szApplicationID MmsBinaryEncodeTextStrinLen fail \n");
1523 totalLength += (length);
1524 if (_MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID) == UNDEFINED_BINARY) {
1525 totalLength += strlen(_MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID)) + 1; /* NULL */
1531 if (pType->param.szReplyToApplicationID) {
1532 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szReplyToApplicationID);
1534 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szApplicationID MmsBinaryEncodeTextStrinLen fail \n");
1538 totalLength += (length);
1539 if (_MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID) == UNDEFINED_BINARY) {
1540 totalLength += strlen(_MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID)) + 1; /* NULL */
1547 /* type, start, & startInfo : multipart/related only parameters -------------- */
1548 if (contentType == MIME_MULTIPART_RELATED || contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
1549 /* type ------------------------------------- */
1550 fieldValue = _MmsGetBinaryValue(MmsCodeContentType, pType->param.type);
1551 if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
1552 /* Extension-media type */
1553 szTextType = _MmsGetTextValue(MmsCodeContentType, pType->param.type);
1554 if (szTextType != NULL) {
1555 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
1557 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: type param MmsBinaryEncodeTextStringLen fail \n");
1560 totalLength += (length + 1);
1568 /* start = Text-string ----------------------- */
1569 if (pType->param.szStart[0]) {
1570 /* start = Text-string */
1571 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStart);
1573 MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextStringLen fail \n");
1577 totalLength += (length + 1);
1581 /* startInfo = Text-string -------------------- */
1582 if (pType->param.szStartInfo[0]) {
1583 /* StartInfo (with multipart/related) = Text-string */
1584 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStartInfo);
1586 MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextStringLen fail \n");
1590 totalLength += (length + 1);
1598 MSG_DEBUG("## MmsBinaryEncodeContentTypeLen: failed");
1604 bool MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLength)
1607 UINT16 fieldValue = 0xffff;
1608 char *szTextType = NULL;
1609 int contentType = MIME_UNKNOWN;
1611 #ifdef FEATURE_JAVA_MMS
1612 char *szParameter = NULL;
1615 MSG_DEBUG("************************************************************************************\n");
1616 MSG_DEBUG("MmsBinaryEncodeContentType: C O N T E N T T Y P E \n\n");
1619 * Content-type-value = Constrained-media | Content-general-form
1620 * Constrained-media = Constrained-encoding
1621 * Constrained-encoding = Extension-Media | Short-integer
1622 * Extension-media = *TEXT End-of-string
1623 * Content-general-form = Value-length Media-type
1624 * Media-type = (Well-known-media | Extension-Media) *(Parameter)
1627 if (pFile == NULL) {
1628 MSG_DEBUG("MmsBinaryEncodeContentType: invalid file handle\n");
1633 /* Content-Type = Content-general-form ------------------------------- */
1635 length = MmsBinaryEncodeValueLengthLen(typeLength);
1637 MSG_DEBUG("MSmsBinaryEncodeContentType : MmsBinaryEncodeValueLengthLen fail.\n");
1641 if (MmsBinaryEncodeValueLength(pFile, typeLength, length) == false) {
1642 MSG_DEBUG("MSmsBinaryEncodeContentType : MmsBinaryEncodeValueLength fail.\n");
1646 contentType = pType->type;
1648 fieldValue = _MmsGetBinaryValue(MmsCodeContentType, (int)contentType);
1649 if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
1650 /* Extension-media type */
1651 szTextType = _MmsGetTextValue(MmsCodeContentType, (int)contentType);
1652 if (szTextType == NULL)
1656 if (szTextType == NULL) {
1657 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)fieldValue | 0x80;
1659 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
1661 MSG_DEBUG("MSmsBinaryEncodeContentType: szTextType MmsBinaryEncodeTextStringLen fail \n");
1665 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szTextType, length) == false) {
1666 MSG_DEBUG("MmsBinaryEncodeContentType: szTextType MmsBinaryEncodeTextString fail \n");
1671 /* Parameters -------------------------------------------------------------- */
1673 MSG_DEBUG("MmsBinaryEncodeContentType: P A R M E T E R S \n\n");
1675 /* Name = Text-string ------------------------------------------------------ */
1677 if (pType->param.szName[0]) {
1678 char* pszName = NULL;
1680 if (_MsgIsASCII (pType->param.szName)) {
1682 MSG_DEBUG("MmsBinaryEncodeContentType: szName is consisted of ascii char-set chars. \n");
1684 pszName = (char *)malloc(strlen(pType->param.szName) +1);
1685 memset(pszName, 0, (strlen(pType->param.szName)+1));
1686 strcpy(pszName, pType->param.szName);
1688 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is not consisted of ascii char-set chars. \n");
1690 /* if msg-server can't support non ascii, then convert non-ascii to '_' by using _MsgReplaceNonAscii*/
1691 int filelen = strlen(pType->param.szName);
1693 pszName = (char *)malloc(filelen + 1);
1694 memset(pszName, 0, (filelen + 1));
1695 strncpy(pszName, pType->param.szName, filelen);
1697 MSG_DEBUG("MmsBinaryEncodeContentType: pszName : %s\n", pszName);
1700 //change empty space to '_' in the file name
1701 if (_MsgIsSpace(pszName)) {
1702 char* pszTempName = NULL;
1704 MSG_DEBUG("MmsBinaryEncodeContentType: szName has space(' '). \n");
1706 _MsgReplaceSpecialChar(pszName, &pszTempName, ' ');
1710 pszName = pszTempName;
1712 MSG_DEBUG("MmsBinaryEncodeContentType: pszName : %s\n", pszName);
1715 length = MmsBinaryEncodeTextStringLen((UINT8*)pszName);
1717 MSG_DEBUG("MmsBinaryEncodeContentType: szName MmsBinaryEncodeIntegerLen fail \n");
1721 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_NAME) | 0x80;
1723 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pszName, length) == false) {
1724 MSG_DEBUG("MmsBinaryEncodeContentType: szName MmsBinaryEncodeTextString fail\n");
1730 #ifdef FEATURE_JAVA_MMS
1731 MSG_DEBUG(" MmsBinaryEncodeContentType: Application-ID \n");
1733 /* Application-ID: Text-string */
1734 if (pType->param.szApplicationID) {
1735 length = MmsBinaryEncodeTextStringLen((UINT8*) pType->param.szApplicationID);
1737 MSG_DEBUG("MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeIntegerLen Fail \n");
1741 fieldValue = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID);
1743 if (fieldValue == UNDEFINED_BINARY)
1744 szParameter = _MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID);
1746 if (szParameter == NULL) {
1747 MSG_DEBUG("MmsBinaryEncodeContentType: szParameter is NULL \n");
1751 strncpy(gpMmsEncodeBuf + gCurMmsEncodeBuffPos, (char*)szParameter, strlen(szParameter));
1752 gCurMmsEncodeBuffPos += strlen(szParameter);
1753 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] =(UINT8)NULL;
1755 if (MmsBinaryEncodeTextString(pFile, (UINT8*) pType->param.szApplicationID, length) == false) {
1756 MSG_DEBUG(" MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeTextString fail\n");
1762 /* ReplyToApplicationID: Text-string */
1763 if (pType->param.szReplyToApplicationID) {
1764 length = MmsBinaryEncodeTextStringLen((UINT8*) pType->param.szReplyToApplicationID);
1766 MSG_DEBUG("MmsBinaryEncodeContentType: szReplyToApplicationID MmsBinaryEncodeIntegerLen Fail \n");
1770 fieldValue = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID);
1772 if (fieldValue == UNDEFINED_BINARY)
1773 szParameter = _MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID);
1775 if (szParameter == NULL) {
1776 MSG_DEBUG("MmsBinaryEncodeContentType: szParameter is NULL \n");
1780 strncpy(gpMmsEncodeBuf + gCurMmsEncodeBuffPos, (char*)szParameter, strlen(szParameter));
1781 gCurMmsEncodeBuffPos += strlen(szParameter);
1782 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] =(UINT8)NULL;
1784 if (MmsBinaryEncodeTextString(pFile, (UINT8*) pType->param.szReplyToApplicationID, length) == false) {
1785 MSG_DEBUG(" MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeTextString fail\n");
1791 /* Well-known-charset = Any-charset | Integer-value ----------------------- */
1793 if (pType->param.charset != MSG_CHARSET_UNKNOWN) {
1794 fieldValue = _MmsGetBinaryValue(MmsCodeCharSet, pType->param.charset);
1795 length = MmsBinaryEncodeIntegerLen(fieldValue);
1797 MSG_DEBUG("MmsBinaryEncodeContentType: charSet MmsBinaryEncodeIntegerLen fail \n");
1801 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_CHARSET) | 0x80;
1802 if (MmsBinaryEncodeInteger(pFile, fieldValue, length) == false) {
1803 MSG_DEBUG("MmsBinaryEncodeContentType: charSet MmsBinaryEncodeInteger fail\n");
1808 if (MmsIsText(contentType)) {
1809 if (!MmsIsVitemContent (contentType, pType->param.szName)) {
1810 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_CHARSET) | 0x80;
1811 fieldValue = 0x0000; //laconic_warning, just to remove warning message
1812 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)fieldValue | 0x80;
1817 /* type, start, & startInfo : multipart/related only parameters -------------- */
1818 if (contentType == MIME_MULTIPART_RELATED || contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
1819 /* type ------------------------------------- */
1820 fieldValue = _MmsGetBinaryValue(MmsCodeContentType, pType->param.type);
1821 if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
1822 /* Extension-media type */
1823 szTextType = _MmsGetTextValue(MmsCodeContentType, pType->param.type);
1824 if (szTextType == NULL)
1828 if (szTextType == NULL) {
1829 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)fieldValue | 0x80;
1830 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_TYPE) | 0x80;
1832 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
1834 MSG_DEBUG("MmsBinaryEncodeContentType: type param MmsBinaryEncodeTextStringLen fail \n");
1838 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_TYPE) | 0x80;
1839 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szTextType, length) == false) {
1840 MSG_DEBUG("MmsBinaryEncodeContentType: type param MmsBinaryEncodeTextString fail \n");
1845 /* start = Text-string ----------------------- */
1846 if (pType->param.szStart && pType->param.szStart[0]) {
1847 /* start = Text-string */
1848 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStart);
1850 MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextStringLen fail \n");
1854 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode,
1855 MSG_PARAM_START) | 0x80;
1856 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pType->param.szStart, length) == false) {
1857 MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextString fail \n");
1862 /* startInfo = Text-string -------------------- */
1863 if (pType->param.szStartInfo[0]) {
1864 /* StartInfo (with multipart/related) = Text-string */
1865 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStartInfo);
1867 MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextStringLen fail \n");
1871 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_START_INFO) | 0x80;
1872 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pType->param.szStartInfo, length) == false) {
1873 MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextString fail \n");
1882 MSG_DEBUG("## MmsBinaryEncodeContentType: failed");
1888 bool MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pType, MsgBody *pBody)
1890 FILE *pFile2 = NULL;
1895 if (pType->offset && pType->size) {
1896 /* header length & body length --------------------------- */
1898 length = MmsBinaryEncodeUintvarLen(pType->size);
1900 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. headerLeng MmsBinaryEncodeUintvarLen fail \n");
1904 if (MmsBinaryEncodeUintvar(pFile, pType->size, length) == false) {
1905 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. eaderLeng fail \n");
1909 length = MmsBinaryEncodeUintvarLen(pBody->size);
1911 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. bodyLeng MmsBinaryEncodeUintvarLen fail \n");
1915 if (MmsBinaryEncodeUintvar(pFile, pBody->size, length) == false) {
1916 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. bodyLeng fail \n");
1920 pFile2 = MsgOpenFile(pType->szOrgFilePath, "rb");
1921 if (pFile != NULL) {
1922 pData = (char *)malloc(pType->size);
1926 if (MsgFseek(pFile2, pType->offset, SEEK_SET) < 0) {
1927 MSG_DEBUG("MmsBinaryEncodeMsgPart: MsgFseek fail \n");
1933 if ((nRead = MsgReadFile(pData, sizeof(char), pType->size, pFile2)) == 0) {
1934 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
1935 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1936 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. header MsgWriteDataFromEncodeBuffer fail \n");
1939 pType->offset = _MmsGetEncodeOffset();
1940 if(MsgWriteFile(pData, sizeof(char), nRead, pFile) != (size_t)nRead) {
1941 MSG_DEBUG("MsgWriteFile failed");
1944 gMmsEncodeCurOffset = MsgFtell(pFile);
1945 if(gMmsEncodeCurOffset < 0) {
1946 MSG_DEBUG("MsgFtell returns negative value [%ld]", gMmsEncodeCurOffset);
1951 MsgCloseFile(pFile2);
1956 int contentTypeLen = 0;
1957 int contentHdrLen = 0;
1959 /* header length & body length --------------------------- */
1960 contentTypeLen = MmsBinaryEncodeContentTypeLen(pType);
1961 length = MmsBinaryEncodeValueLengthLen(contentTypeLen);
1962 contentHdrLen = MmsBinaryEncodeContentHeaderLen((MimeType)contentType, pType, true);
1964 if (contentTypeLen == -1 || length == -1 || contentHdrLen == -1) {
1965 MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng calculation fail \n");
1969 headerLeng = contentTypeLen + contentHdrLen + length;
1970 length = MmsBinaryEncodeUintvarLen(headerLeng);
1972 MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng MmsBinaryEncodeUintvarLen fail \n");
1976 if (MmsBinaryEncodeUintvar(pFile, headerLeng, length) == false) {
1977 MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng fail \n");
1981 length = MmsBinaryEncodeUintvarLen(pBody->size);
1983 MSG_DEBUG("MmsBinaryEncodeMsgPart: bodyLeng MmsBinaryEncodeUintvarLen fail \n");
1987 if (MmsBinaryEncodeUintvar(pFile, pBody->size, length) == false) {
1988 MSG_DEBUG("MmsBinaryEncodeMsgPart: bodyLeng fail \n");
1992 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
1993 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1994 MSG_DEBUG("MmsBinaryEncodeMsgPart: 2. header MsgWriteDataFromEncodeBuffer fail \n");
1998 /* content-type & header --------------------------- */
1999 pType->offset = _MmsGetEncodeOffset();
2001 if (MmsBinaryEncodeContentType(pFile, pType, contentTypeLen) == false) {
2002 MSG_DEBUG("MmsBinaryEncodeMsgPart: MmsBinaryEncodeContentType fail \n");
2006 if (MmsBinaryEncodeContentHeader(pFile, (MsgContentType)contentType, pType, true) == false) {
2007 MSG_DEBUG("MmsBinaryEncodeMsgPart: MmsBinaryEncodeContentHeader fail \n");
2011 pType->size = _MmsGetEncodeOffset() - pType->offset;
2014 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2015 MSG_DEBUG("MmsBinaryEncodeMsgPart: contentBody MsgWriteDataFromEncodeBuffer fail \n");
2019 /* content-body --------------------------- */
2020 if (MmsBinaryEncodeContentBody(pFile, pBody) == false) {
2021 MSG_DEBUG("MmsBinaryEncodeMsgPart: MmsBinaryEncodeContentBody fail \n");
2039 MSG_DEBUG("## MmsBinaryEncodeMsgPart: failed\n");
2041 MsgCloseFile(pFile2);
2049 int MmsBinaryEncodeContentHeaderLen(MsgContentType contentType, MsgType *pType, bool bMultipart)
2052 int totalLength = 0;
2053 char *szTextValue = NULL;
2056 MSG_DEBUG("MmsBinaryEncodeContentHeaderLen: S T A R T \n\n");
2058 /* content-id ------------------------------------------------- */
2059 if (pType->szContentID[0]) {
2060 if (bMultipart) { //Binary Encoding
2063 /* content-id = Quoted-string */
2064 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-ID");
2066 MSG_DEBUG("MmsBinaryEncodeContentHeaderLen: Content-ID MmsBinaryEncodeTextStringLen fail.\n");
2070 totalLength += length;
2073 length = MmsBinaryEncodeQuotedStringLen((UINT8*)pType->szContentID);
2075 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedStringLen fail.\n");
2078 totalLength += length;
2082 if (pType->szContentLocation[0]) {
2083 if (bMultipart) { //Binary Encoding
2086 /* content-location = Quoted-string */
2087 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-Location");
2089 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextStringLen fail.\n");
2093 totalLength += length;
2096 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->szContentLocation);
2098 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextStringLen fail.\n");
2102 totalLength += length;
2106 /* MIME_APPLICATION_VND_WAP_MULTIPART_RELATEDrequires always "inline" */
2108 if (contentType != MIME_APPLICATION_VND_WAP_MULTIPART_RELATED &&
2109 contentType != MIME_MULTIPART_RELATED &&
2110 pType->disposition != INVALID_VALUE) {
2113 * Content-disposition-value = Value-length Disposition *(Parameter)
2114 * Disposition = Form-data | Attachment | Inline | Token-text
2115 * Form-data = <Octet 128> : 0x80
2116 * Attachment = <Octet 129> : 0x81
2117 * Inline = <Octet 130> : 0x82
2120 if (bMultipart) { //Binary Encoding
2123 /* content-disposition = Quoted-string */
2124 szTextValue = _MmsGetTextValue(MmsCodeMsgDisposition, pType->disposition);
2127 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-Disposition");
2129 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
2133 totalLength += length;
2135 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextValue);
2137 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
2140 totalLength += length;
2148 MSG_DEBUG("## MmsBinaryEncodeContentHeadeLen: failed");
2155 bool MmsBinaryEncodeContentHeader(FILE *pFile, MsgContentType contentType, MsgType *pType, bool bMultipart)
2158 char *szTextValue = NULL;
2160 MSG_DEBUG("MmsBinaryEncodeContentHeader: S T A R T \n\n");
2162 /* content-id ------------------------------------------------- */
2163 if (pType->szContentID[0]) {
2164 if (bMultipart) { //Binary Encoding
2165 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeMsgBodyHeaderCode, MMS_BODYHDR_CONTENTID) | 0x80;
2167 /* content-id = Quoted-string */
2168 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-ID");
2170 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-ID MmsBinaryEncodeTextStringLen fail.\n");
2174 if (MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-ID", length) == false) {
2175 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-ID MmsBinaryEncodeTextString fail.\n");
2180 length = MmsBinaryEncodeQuotedStringLen((UINT8*)pType->szContentID);
2182 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedStringLen fail.\n");
2186 if (MmsBinaryEncodeQuotedString(pFile, (UINT8*)pType->szContentID, length) == false) {
2187 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedString fail.\n");
2192 if (pType->szContentLocation[0]) {
2193 if (bMultipart) { //Binary Encoding
2194 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeMsgBodyHeaderCode, MMS_BODYHDR_CONTENTLOCATION) | 0x80;
2196 /* content-location = Quoted-string */
2197 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-Location");
2199 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextStringLen fail.\n");
2203 if (MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-Location", length) == false) {
2204 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextString fail.\n");
2209 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->szContentLocation);
2211 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextStringLen fail.\n");
2215 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pType->szContentLocation, length) == false) {
2216 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextString fail.\n");
2221 /* MIME_APPLICATION_VND_WAP_MULTIPART_RELATEDrequires always "inline" */
2223 if (contentType != MIME_APPLICATION_VND_WAP_MULTIPART_RELATED &&
2224 contentType != MIME_MULTIPART_RELATED &&
2225 pType->disposition != INVALID_VALUE) {
2228 * Content-disposition-value = Value-length Disposition *(Parameter)
2229 * Disposition = Form-data | Attachment | Inline | Token-text
2230 * Form-data = <Octet 128> : 0x80
2231 * Attachment = <Octet 129> : 0x81
2232 * Inline = <Octet 130> : 0x82
2235 if (bMultipart) {//Binary Encoding
2237 UINT8 fieldValue = 0xff;
2238 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeMsgBodyHeaderCode, MMS_BODYHDR_DISPOSITION) | 0x80;
2240 fieldValue = _MmsGetBinaryValue(MmsCodeMsgDisposition, pType->disposition) | 0x80;
2242 if (fieldValue == 0xff)
2245 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = 0x01;
2246 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldValue;
2248 /* content-disposition = Disposition (no support parameter) */
2250 szTextValue = _MmsGetTextValue(MmsCodeMsgDisposition, pType->disposition);
2253 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-Disposition");
2255 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
2259 if (MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-Disposition", length) == false) {
2260 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextString fail.\n");
2264 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextValue);
2266 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
2270 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szTextValue, length) == false) {
2271 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextString fail.\n");
2281 MSG_DEBUG("## MmsBinaryEncodeContentHeader: failed");
2287 bool MmsBinaryEncodeContentBody(FILE *pFile, MsgBody *pBody)
2299 if (pBody->szOrgFilePath[0]) {
2300 pData = MsgOpenAndReadMmsFile(pBody->szOrgFilePath, pBody->offset, pBody->size, &nRead);
2304 pBody->offset = _MmsGetEncodeOffset();
2305 if(MsgWriteFile(pData, sizeof(char), nRead, pFile) != nRead) {
2306 MSG_DEBUG("MsgWriteFile failed");
2309 gMmsEncodeCurOffset = MsgFtell(pFile);
2311 if (gMmsEncodeCurOffset < 0) {
2312 MSG_DEBUG("MsgFtell returns negative value [%ld]", gMmsEncodeCurOffset);
2320 } else if (pBody->body.pText && pBody->size) {
2321 pBody->offset = _MmsGetEncodeOffset();
2322 if (MsgWriteFile(pBody->body.pText, sizeof(char),pBody->size, pFile) != pBody->size) {
2323 MSG_DEBUG("MsgWriteFile failed");
2326 gMmsEncodeCurOffset = MsgFtell(pFile);
2328 if(gMmsEncodeCurOffset < 0) {
2329 MSG_DEBUG("MsgFtell returns negative value [%ld]", gMmsEncodeCurOffset);
2337 MSG_DEBUG("## MmsBinaryEncodeContentBody: failed\n");
2348 /* =========================================================================
2350 B I N A R Y E N C O D I N G U T I L I T Y
2352 =========================================================================*/
2354 static int MmsBinaryEncodeIntegerLen(UINT32 integer)
2356 if (integer < 0x80) {
2363 * Long-integer = Short-length Multi-octet-integer
2364 * The Short-length indicates the length of the Multi-octet-integer
2369 integer = (integer >> 8);
2372 length++; // + Short-length
2380 * This makes value-length by specified integer value
2382 * @param length [in] gotten from MmsBinaryEncodeIntegerLen()
2384 static bool MmsBinaryEncodeInteger(FILE *pFile, UINT32 integer, int length)
2392 if (pFile == NULL) {
2393 MSG_DEBUG("MmsBinaryEncodeInteger: source == NULL \n");
2397 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2398 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2399 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2400 MSG_DEBUG("MmsBinaryEncodeInteger: MsgWriteDataFromEncodeBuffer fail \n");
2405 if (integer < 0x80) {
2407 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)integer | 0x80;
2410 * Long-integer = Short-length Multi-octet-integer
2411 * The Short-length indicates the length of the Multi-octet-integer
2413 changer.integer = integer;
2414 length--; // - "Short-length"
2416 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)length;
2419 for(i = 0; i < length; i++)
2420 gpMmsEncodeBuf[gCurMmsEncodeBuffPos + i] = changer.seg[length - (i + 1)];
2422 gCurMmsEncodeBuffPos += length;
2432 static int MmsBinaryEncodeLongIntegerLen(UINT32 integer)
2437 * Long-integer = Short-length Multi-octet-integer
2438 * The Short-length indicates the length of the Multi-octet-integer
2446 integer = (integer >> 8);
2449 length++; // + Short-length
2456 * This makes value-length by specified integer value
2458 * @param length [in] gotten from MmsBinaryEncodeIntegerLen()
2460 static bool MmsBinaryEncodeLongInteger(FILE *pFile, UINT32 integer, int length)
2470 * Long-integer = Short-length Multi-octet-integer
2471 * The Short-length indicates the length of the Multi-octet-integer
2474 if (pFile == NULL) {
2475 MSG_DEBUG("MmsBinaryEncodeLongInteger: source == NULL \n");
2479 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2480 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2481 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2482 MSG_DEBUG("MmsBinaryEncodeLongInteger: MsgWriteDataFromEncodeBuffer fail \n");
2487 changer.integer = integer;
2488 length--; // - "Short-length"
2490 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)length;
2492 for(i = 0; i < length; i++)
2493 gpMmsEncodeBuf[gCurMmsEncodeBuffPos + i] = changer.seg[length - (i + 1)];
2495 gCurMmsEncodeBuffPos += length;
2505 static int MmsBinaryEncodeTextStringLen(UINT8 *source)
2509 MSG_DEBUG("MmsBinaryEncodeTextStringLen: \n");
2511 if (source == NULL) {
2512 MSG_DEBUG("MmsBinaryEncodeTextStringLen: source == NULL \n");
2516 length = (int)strlen((char*)source);
2517 if (source[0] > 0x7F) {
2518 length += 2; // + NULL
2528 * @param source [in] originam string
2529 * @param length [in] gotten from MmsBinaryEncodeTextStringLen()
2530 * @param dest [in] buffer to store quted string
2531 * @return changed string length
2533 static bool MmsBinaryEncodeTextString(FILE *pFile, UINT8 *source, int length)
2536 MSG_DEBUG("MmsBinaryEncodeTextString: \n");
2540 * Text-string = [Quote] *TEXT End-of-string
2541 * If the 1st char in the TEXT is in the range of 128-255, a Quote char must precede it.
2542 * Otherwise the Quote char must be omitted.
2543 * The Quote is not part of the contents.
2544 * Quote = <Octet 127>
2547 if (pFile == NULL || source == NULL) {
2548 MSG_DEBUG("MmsBinaryEncodeTextString: source == NULL \n");
2552 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2553 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2554 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2555 MSG_DEBUG("MmsBinaryEncodeTextString: MsgWriteDataFromEncodeBuffer fail \n");
2560 if (source[0] > 0x7F) {
2561 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = QUOTE;
2565 strncpy(gpMmsEncodeBuf + gCurMmsEncodeBuffPos, (char*)source, (length - 1)); // except NULL
2566 gCurMmsEncodeBuffPos += (length - 1); // except NULL
2567 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)NULL;
2578 * Encode 28bit unsigned integer(Maximum) to uintvar
2580 * @param interger [in] integer to be encoded
2581 * @return encoded UINTVAR stream
2583 const UINT32 UINTVAR_LENGTH_1 = 0x0000007f; //7bit
2584 const UINT32 UINTVAR_LENGTH_2 = 0x00003fff; //14bit
2585 const UINT32 UINTVAR_LENGTH_3 = 0x001fffff; //21bit
2588 static int MmsBinaryEncodeUintvarLen(UINT32 integer)
2592 /* Find encoded unitvar length */
2593 if (integer <= UINTVAR_LENGTH_1) {
2596 if (integer <= UINTVAR_LENGTH_2) {
2599 if (integer <= UINTVAR_LENGTH_3) {
2611 static bool MmsBinaryEncodeUintvar(FILE *pFile, UINT32 integer, int length)
2613 const char ZERO = 0x00;
2615 char szReverse[MSG_STDSTR_LONG] = {0, };
2622 if (pFile == NULL) {
2623 MSG_DEBUG("MmsBinaryEncodeUintvar: pFile == INVALID_HBOJ \n");
2627 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2628 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2629 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2630 MSG_DEBUG("MmsBinaryEncodeUintvar: MsgWriteDataFromEncodeBuffer fail \n");
2635 source.integer = integer;
2636 memset(szReverse, 0, MSG_STDSTR_LONG);
2638 /* Seperate integer to 4 1 byte integer */
2639 szReverse[3] = source.bytes[3] & 0x0f;
2640 szReverse[0] = source.bytes[0];
2641 szReverse[0] = szReverse[0] & 0x7f;
2643 while (length >= i) { // initially, i = 2
2644 /* Move integer bit to proper position */
2645 source.integer = source.integer << 1;
2646 source.integer = source.integer >> 8;
2647 source.bytes[3] = ZERO;
2649 /* Retrive 1 encode uintvar */
2650 szReverse[i-1] = source.bytes[0];
2651 szReverse[i-1] = szReverse[i-1] | 0x80;
2655 for(i=0; i < length; i++)
2656 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = szReverse[length - i - 1];
2666 static int MmsBinaryEncodeValueLengthLen(UINT32 integer)
2670 if (integer < 0x1f) {
2673 length = MmsBinaryEncodeUintvarLen(integer) + 1; //LENGTH_QUOTE
2681 * This makes value-length by specified integer value
2683 * @param length [in] from MmsBinaryEncodeValueLengthLen()
2684 * @return encoded value-length
2686 static bool MmsBinaryEncodeValueLength(FILE *pFile, UINT32 integer, int length)
2689 * Value-length = Short-length | (Length-quote Length)
2690 * ; Value length is used to indicate the length of the value to follow
2691 * Short-length = <Any octet 0-30>
2692 * Length-quote = <Octet 31>
2693 * Length = Uintvar-integer
2696 if (pFile == NULL) {
2697 MSG_DEBUG("MmsBinaryEncodeValueLength: pFile == INVALID_HBOJ \n");
2701 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2702 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2703 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2704 MSG_DEBUG("MmsBinaryEncodeValueLength: MsgWriteDataFromEncodeBuffer fail \n");
2709 if (integer < 0x1F) {
2710 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)integer;
2712 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)LENGTH_QUOTE;
2713 if (MmsBinaryEncodeUintvar(pFile, integer, length - 1) == false) { // LENGTH_QUOTE
2714 MSG_DEBUG("MmsBinaryEncodeValueLength: MmsBinaryEncodeUintvar fail\n");
2726 static int MmsBinaryEncodeQuotedStringLen(UINT8 *pSrc)
2729 MSG_DEBUG("MmsBinaryEncodeQuotedStringLen: invalid file\n");
2733 return (strlen((char*)pSrc) + 2); // QUOTE + NULL
2741 * make quoted string
2742 * Quoted-string = <Octet 34> *TEXT End-of-string
2744 * @param source [in] original string
2745 * @param length [in] length (in bytes) of data
2746 * @param dest [out] buffer to store quted string
2747 * @return changed string length
2749 static bool MmsBinaryEncodeQuotedString(FILE *pFile, UINT8 *source, int length)
2751 if (source == NULL || pFile == NULL) {
2752 MSG_DEBUG("MmsBinaryEncodeQuotedString: invalid file\n");
2756 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2757 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2758 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2759 MSG_DEBUG("MmsBinaryEncodeQuotedString: MsgWriteDataFromEncodeBuffer fail \n");
2764 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = '\"';
2765 strncpy(gpMmsEncodeBuf + gCurMmsEncodeBuffPos, (char*)source, length - 2); // except '\"' & NULL
2766 gCurMmsEncodeBuffPos += (length - 2);
2767 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)NULL;
2777 static int MmsBinaryEncodeEncodedStringLen(UINT8 *source)
2779 UINT32 charset = 0x6A; // default = utf-8
2782 int valueLengthLen = 0;
2785 MSG_DEBUG("MmsBinaryEncodeEncodedStringLen: \n");
2787 /* value-length charSet text-string */
2788 /* Estimate charset value length and text string length */
2789 charLeng = MmsBinaryEncodeIntegerLen(charset);
2790 if (charLeng == -1) {
2791 MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : charLeng MmsBinaryEncodeTextStringLen fail.\n");
2795 textLeng = MmsBinaryEncodeTextStringLen((UINT8*)source);
2796 if (textLeng == -1) {
2797 MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : textLeng MmsBinaryEncodeTextStringLen fail.\n");
2801 valueLengthLen = MmsBinaryEncodeValueLengthLen(charLeng + textLeng);
2802 if (valueLengthLen == -1) {
2803 MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : valLengthLen MmsBinaryEncodeTextStringLen fail.\n");
2807 return (charLeng + textLeng + valueLengthLen);
2815 * This makes value-length by specified integer value
2817 * @param length [in] from MmsBinaryEncodeEncodedStringLen()
2818 * @return encoded encoded-string
2820 static bool MmsBinaryEncodeEncodedString(FILE *pFile, UINT8 *source, int length)
2822 UINT32 charset = 0x6A; // default = utf-8
2825 int valLengthLen = 0;
2828 MSG_DEBUG("MmsBinaryEncodeEncodedString: \n");
2830 /* value-length charSet text-string */
2832 if (pFile == NULL || source == NULL) {
2833 MSG_DEBUG("MmsBinaryEncodeEncodedString: invalid input parameter\n");
2837 /* Estimate charset value length and text string length */
2838 charLeng = MmsBinaryEncodeIntegerLen(charset);
2839 if (charLeng == -1) {
2840 MSG_DEBUG("MmsBinaryEncodeEncodedString : charLeng MmsBinaryEncodeTextStringLen fail.\n");
2844 textLeng = MmsBinaryEncodeTextStringLen((UINT8*)source);
2845 if (textLeng == -1) {
2846 MSG_DEBUG("MmsBinaryEncodeEncodedString : textLeng MmsBinaryEncodeTextStringLen fail.\n");
2850 valLengthLen = MmsBinaryEncodeValueLengthLen(charLeng + textLeng);
2851 if (valLengthLen == -1) {
2852 MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeValueLengthLen fail.\n");
2856 if (length != (charLeng + textLeng + valLengthLen))
2858 MSG_DEBUG("MmsBinaryEncodeEncodedString: invalid length\n");
2862 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2863 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2864 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2865 MSG_DEBUG("MmsBinaryEncodeEncodedString: MsgWriteDataFromEncodeBuffer fail \n");
2870 /* Value length of charset value and text string */
2871 if (MmsBinaryEncodeValueLength(pFile, charLeng + textLeng, valLengthLen) == false) {
2872 MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeValueLength fail.\n");
2876 /* Write charset on buffer -> integer value not long-integer */
2877 if (MmsBinaryEncodeInteger(pFile, charset, charLeng) == false) {
2878 MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeInteger fail.\n");
2883 /* Write text string on buffer */
2884 if (MmsBinaryEncodeTextString(pFile, (UINT8*)source, textLeng) == false) {
2885 MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeTextString fail.\n");
2896 static bool __MmsBinaryEncodeFieldCodeAndValue(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue)
2898 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 2) {
2899 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2900 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2901 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: MsgWriteDataFromEncodeBuffer fail \n");
2906 if (fieldCode == 0xff) {
2907 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldCode \n");
2911 if (fieldValue == 0xff) {
2912 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldValue \n");
2916 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
2917 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldValue;
2927 static bool __MmsBinaryEncodeTrID(FILE *pFile, char *szTrID, int bufLen)
2930 UINT8 fieldCode = 0xff;
2931 char szBuff[MMS_TR_ID_LEN + 1] = {0, };
2932 struct tm *dateTime = NULL;
2937 dateTime = localtime(&RawTime);
2938 dateSec = mktime(dateTime);
2941 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
2942 if (fieldCode == 0xff) {
2943 MSG_DEBUG("__MmsBinaryEncodeTrID: invalid fieldCode \n");
2947 snprintf(szBuff, MMS_TR_ID_LEN + 1, "%lu.%lu", dateSec, (unsigned long)random());
2948 MSG_DEBUG("__MmsBinaryEncodeTrID: 2. szBuff = %s\n", szBuff);
2950 length = MmsBinaryEncodeTextStringLen((UINT8*)szBuff);
2952 MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextStringLen fail \n");
2956 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
2957 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2958 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2959 MSG_DEBUG("__MmsBinaryEncodeTrID: MsgWriteDataFromEncodeBuffer fail \n");
2965 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
2966 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szBuff, length) == false) {
2967 MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextString fail\n");
2972 memset(szTrID, 0, bufLen);
2973 strncpy(szTrID, szBuff, bufLen - 1);
2983 static bool __MmsBinaryEncodeMsgID(FILE *pFile, const char *szMsgID)
2986 UINT8 fieldCode = 0xff;
2988 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGID) | 0x80;
2989 if (fieldCode == 0xff) {
2990 MSG_DEBUG("__MmsBinaryEncodeTrID: invalid fieldCode \n");
2994 MSG_DEBUG("__MmsBinaryEncodeMsgID: 2. szBuff = %s\n", szMsgID);
2996 length = MmsBinaryEncodeTextStringLen((UINT8*)szMsgID);
2998 MSG_DEBUG("__MmsBinaryEncodeMsgID: MmsBinaryEncodeTextStringLen fail \n");
3002 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
3003 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3004 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3005 MSG_DEBUG("__MmsBinaryEncodeTrID: MsgWriteDataFromEncodeBuffer fail \n");
3010 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
3011 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szMsgID, length) == false) {
3012 MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextString fail\n");
3025 static bool __MmsBinaryEncodeMmsVersion(FILE *pFile)
3027 UINT8 majorVer = MMS_MAJOR_VERSION;
3028 UINT8 minorVer = MMS_MINOR_VERSION;
3030 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: \n");
3032 if (pFile == NULL) {
3033 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: invalid input file \n");
3038 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: invalid major version (%d)\n", majorVer);
3042 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 2) {
3043 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3044 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3045 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: MsgWriteDataFromEncodeBuffer fail \n");
3050 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_VERSION) | 0x80;
3052 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: major version (%d)\n", majorVer);
3053 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: minor version (%d)\n", minorVer);
3055 gpMmsEncodeBuf[gCurMmsEncodeBuffPos] = (majorVer << 4) | (minorVer & 0x0f) | MSB;
3057 if (gpMmsEncodeBuf[gCurMmsEncodeBuffPos] < 0x80) {
3058 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] |= 0x80;
3060 gCurMmsEncodeBuffPos++;
3071 static bool __MmsBinaryEncodeDate(FILE *pFile)
3073 struct tm *dateTime = NULL;
3076 dateSec = time(NULL);
3077 dateTime = localtime(&dateSec);
3079 MSG_DEBUG("%d - %d - %d, %d : %d (SYSTEM)", dateTime->tm_year + 1900, dateTime->tm_mon + 1, dateTime->tm_mday
3080 , dateTime->tm_hour, dateTime->tm_min);
3084 length = MmsBinaryEncodeLongIntegerLen(dateSec);
3086 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) { // + fieldCode
3087 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3088 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3089 MSG_DEBUG("__MmsBinaryEncodeDate: MsgWriteDataFromEncodeBuffer fail \n");
3094 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DATE) | 0x80;
3096 if (MmsBinaryEncodeLongInteger(pFile, dateSec, length) == false) {
3097 MSG_DEBUG("__MmsBinaryEncodeDate: date MmsBinaryEncodeLongInteger error\n");
3101 MSG_DEBUG("__MmsBinaryEncodeDate: date has a negative value (%d) \n", dateSec);
3112 static bool __MmsBinaryEncodeFrom(FILE *pFile)
3114 if (pFile == NULL) {
3115 MSG_DEBUG("__MmsBinaryEncodeFrom: invalid input file \n");
3119 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 3) {
3120 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3121 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3122 MSG_DEBUG("__MmsBinaryEncodeFrom: MsgWriteDataFromEncodeBuffer fail \n");
3127 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_FROM) | 0x80;
3128 /* length of MMS_INSERT_ADDRESS_TOKEN value */
3129 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = 0x01;
3130 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeAddressType, MMS_INSERT_ADDRESS_TOKEN) | 0x80;
3138 static bool __MmsBinaryEncodeOneAddress(FILE *pFile, MmsFieldCode addrType, char *szAddrStr)
3142 if (pFile == NULL) {
3143 MSG_DEBUG("__MmsBinaryEncodeOneAddress: invalid input file \n");
3148 length = MmsBinaryEncodeEncodedStringLen((UINT8*)szAddrStr);
3151 MSG_DEBUG("__MmsBinaryEncodeOneAddress: MmsBinaryEncodeEncodedStringLen fail \n");
3155 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
3156 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3157 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3158 MSG_DEBUG("__MmsBinaryEncodeOneAddress: MsgWriteDataFromEncodeBuffer fail \n");
3163 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, addrType) | 0x80;
3166 if (MmsBinaryEncodeEncodedString(pFile, (UINT8*)szAddrStr, length) == false) {
3167 MSG_DEBUG("__MmsBinaryEncodeOneAddress: MmsBinaryEncodeEncodedString fail \n");
3178 static bool __MmsBinaryEncodeAddress(FILE *pFile, MmsFieldCode addrType, char *szAddr)
3180 char *pSingleAddr = NULL;
3183 if (pFile == NULL) {
3184 MSG_DEBUG("__MmsBinaryEncodeAddress: invalid input file \n");
3188 while (szAddr && szAddr[0]) {
3189 szAddr = _MsgSkipWS3(szAddr);
3193 pSingleAddr = strchr(szAddr, MSG_CH_SEMICOLON);
3196 *pSingleAddr = MSG_CH_NULL;
3197 if (__MmsBinaryEncodeOneAddress(pFile, addrType, szAddr) == false) {
3198 MSG_DEBUG("__MmsBinaryEncodeAddress: __MmsBinaryEncodeAddress fail\n");
3201 *pSingleAddr = MSG_CH_SEMICOLON;
3203 szAddr = pSingleAddr + 1;
3206 if (__MmsBinaryEncodeOneAddress(pFile, addrType, szAddr) == false) {
3207 MSG_DEBUG("__MmsBinaryEncodeAddress: __MmsBinaryEncodeAddress fail\n");
3223 static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeStruct time)
3228 if (pFile == NULL) {
3229 MSG_DEBUG("__MmsBinaryEncodeTime: invalid input file \n");
3233 if (time.time == 0 ||
3234 (fieldCode != MMS_CODE_EXPIRYTIME && fieldCode != MMS_CODE_DELIVERYTIME && fieldCode != MMS_CODE_REPLYCHARGINGDEADLINE) ||
3235 (time.type != MMS_TIMETYPE_ABSOLUTE && time.type != MMS_TIMETYPE_RELATIVE)) {
3236 MSG_DEBUG("__MmsBinaryEncodeTime: time.type = %d \n", time.type);
3241 * use temporary buffer to estimate value length
3242 * and copy it to pData buffer later.
3245 if (time.type == MMS_TIMETYPE_RELATIVE) {
3246 timeLen = MmsBinaryEncodeIntegerLen(time.time);
3248 timeLen = MmsBinaryEncodeLongIntegerLen(time.time);
3252 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongIntegerLen fail \n");
3256 length = MmsBinaryEncodeValueLengthLen(timeLen + 1); //time length + time type token
3258 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeValueLengthLen fail \n");
3262 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + timeLen + 2)) { // + fieldCode + timeType
3264 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3265 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3266 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
3272 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, fieldCode) | 0x80;
3275 if (MmsBinaryEncodeValueLength(pFile, timeLen + 1, length) == false) {
3276 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeValueLength fail \n");
3280 /* time type & value */
3281 if (time.type == MMS_TIMETYPE_RELATIVE) {
3282 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_RELATIVE) | 0x80;
3283 if (MmsBinaryEncodeInteger(pFile, time.time, timeLen) == false) {
3284 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongInteger fail \n");
3288 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE) | 0x80;
3289 if (MmsBinaryEncodeLongInteger(pFile, time.time, timeLen) == false) {
3290 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongInteger fail \n");