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"
25 #include "MmsPluginUtil.h"
27 gint _g_time_rev_set = 0;
30 /** Sending message related variables ------------------------ */
32 static char gszMmsEncodeBuf[MSG_MMS_ENCODE_BUFFER_MAX] = {0, };
33 static int gCurMmsEncodeBuffPos = 0; /* number of characters on gpMmsEncodeBuf */
34 static int gMmsEncodeMaxLen = 0;
35 static int gMmsEncodeCurOffset = 0; /* offset in file */
36 static char *gpMmsEncodeBuf = NULL;
39 /* Acknowledge.ind & NotifyResp.ind related variables ------------------------ */
41 static char gszMmsEncodeBuf2[MSG_MMS_ENCODE_BUFFER_MAX] = {0, };
42 static int gCurMmsEncodeBuffPos2 = 0; /* number of characters on gpMmsEncodeBuf */
43 static int gMmsEncodeMaxLen2 = 0;
44 static int gMmsEncodeCurOffset2 = 0; /* offset in file */
45 static char *gpMmsEncodeBuf2 = NULL;
48 bool _MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg);
49 bool _MmsBinaryEncodeAckIndHdr(FILE *pFile, char *pTrID, bool bReportAllowed);
50 bool _MmsBinaryEncodeNotiRespIndHdr(FILE* pFile, char *pTrID, msg_delivery_report_status_t iStatus, bool bReportAllowed);
51 bool _MmsBinaryEncodeForwardReqHdr(FILE *pFile, char *szContentLocation, char *szForwardTo, char *szForwardCc, char *szForwardBcc);
52 bool _MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus);
53 bool _MmsBinaryEncodeReadReport11Hdr(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus);
55 static bool __MmsEncodeSendReq(FILE *pFile, MmsMsg *pMsg, bool bIncludeSendReqHeader);
56 static int MmsBinaryEncodeUintvarLen(UINT32 integer);
57 static bool MmsBinaryEncodeUintvar(FILE *pFile, UINT32 integer, int length);
58 static int MmsBinaryEncodeValueLengthLen(UINT32 integer);
59 static bool MmsBinaryEncodeValueLength(FILE *pFile, UINT32 integer, int length);
60 static int MmsBinaryEncodeIntegerLen(UINT32 integer);
61 static bool MmsBinaryEncodeInteger(FILE *pFile, UINT32 integer, int length);
62 static int MmsBinaryEncodeLongIntegerLen(UINT32 integer);
63 static bool MmsBinaryEncodeLongInteger(FILE *pFile, UINT32 integer, int length);
64 static int MmsBinaryEncodeTextStringLen(UINT8 *source);
65 static bool MmsBinaryEncodeTextString(FILE *pFile, UINT8 *source, int length);
66 static int MmsBinaryEncodeQuotedStringLen(UINT8 *pSrc);
67 static bool MmsBinaryEncodeQuotedString(FILE *pFile, UINT8 *source, int length);
68 static int MmsBinaryEncodeEncodedStringLen(UINT8 *source);
69 static bool MmsBinaryEncodeEncodedString(FILE *pFile, UINT8 *source, int length);
70 bool MmsBinaryEncodeSendReqHdrwithinBufRegi(FILE *pFile, MmsMsg *pMsg);
71 bool MmsBinaryEncodeSendReqHdrContTypeFildCode(FILE *pFile, int msgID);
73 static bool __MmsBinaryEncodeFieldCodeAndValue(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue);
75 static bool __MmsBinaryEncodeMmsVersion(FILE *pFile);
76 static bool __MmsBinaryEncodeTrID(FILE *pFile, char *szTrID, int bufLen);
77 static bool __MmsBinaryEncodeMsgID(FILE *pFile, const char *szMsgID); /** 2005-05-24, added for read-reply PDU 1.2 */
78 static bool __MmsBinaryEncodeFrom(FILE *pFile);
79 static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeStruct time);
80 static bool __MmsBinaryEncodeDate(FILE *pFile);
81 static bool __MmsBinaryEncodeOneAddress(FILE *pFile, MmsFieldCode addrType, char *szAddrStr);
82 static bool __MmsBinaryEncodeAddress(FILE *pFile, MmsFieldCode addrType, char *szAddr);
85 /* Functions for Acknowledge.ind & NotifyResp.ind ------------------------ */
87 static bool MmsBinaryEncodeTextString2(FILE *pFile, UINT8 *source, int length);
88 static bool __MmsBinaryEncodeMmsVersion2(FILE *pFile);
89 static bool __MmsBinaryEncodeFieldCodeAndValue2(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue);
90 extern int MsgProcessUrgentEvent(int iMode);
93 /** -----------------------------------------------------------------
95 * * -----------------------------------------------------------------*/
98 static void __MmsCleanEncodeBuff(void)
100 memset(gpMmsEncodeBuf, 0, MSG_MMS_ENCODE_BUFFER_MAX);
101 gCurMmsEncodeBuffPos = 0;
105 void _MmsRegisterEncodeBuffer(char *pInBuff, int maxLen)
107 gpMmsEncodeBuf = pInBuff;
108 gCurMmsEncodeBuffPos = 0;
109 gMmsEncodeMaxLen = maxLen;
110 gMmsEncodeCurOffset = 0;
113 void _MmsUnregisterEncodeBuffer(void)
115 gpMmsEncodeBuf = NULL;
116 gCurMmsEncodeBuffPos = 0;
117 gMmsEncodeMaxLen = 0;
118 gMmsEncodeCurOffset = 0;
121 int _MmsGetEncodeOffset(void)
123 return (gMmsEncodeCurOffset + gCurMmsEncodeBuffPos);
127 bool _MmsEncodeMsg(void)
129 MSG_DEBUG("_MmsEncodeMsg: Start Binary Encoding now ============= \n");
134 bool _MmsEncodeSendReq(FILE *pFile, MmsMsg *pMsg)
136 return __MmsEncodeSendReq(pFile, pMsg, true);
140 bool _MmsEncodeTemplate(FILE *pFile, MmsMsg *pMsg)
142 return __MmsEncodeSendReq(pFile, pMsg, false);
146 static bool __MmsEncodeSendReq(FILE* pFile, MmsMsg* pMsg, bool bIncludeSendReqHeader)
148 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
150 if (bIncludeSendReqHeader) {
151 if (_MmsBinaryEncodeSendReqHdr(pFile, pMsg) == false) {
152 _MmsUnregisterEncodeBuffer();
157 if (MmsBinaryEncodeMsgBody(pFile, &pMsg->msgType, &pMsg->msgBody, pMsg->nPartCount, !bIncludeSendReqHeader) == false) {
158 _MmsUnregisterEncodeBuffer();
162 _MmsUnregisterEncodeBuffer();
168 /* Functions for Acknowledge.ind & NotifyResp.ind ------------------------ */
170 static void __MmsCleanEncodeBuff2(void)
172 memset(gpMmsEncodeBuf2, 0, MSG_MMS_ENCODE_BUFFER_MAX);
173 gCurMmsEncodeBuffPos2 = 0;
177 void _MmsRegisterEncodeBuffer2(char *pInBuff, int maxLen)
179 gpMmsEncodeBuf2 = pInBuff;
180 gCurMmsEncodeBuffPos2 = 0;
181 gMmsEncodeMaxLen2 = maxLen;
182 gMmsEncodeCurOffset2 = 0;
185 void _MmsUnregisterEncodeBuffer2(void)
187 gpMmsEncodeBuf2 = NULL;
188 gCurMmsEncodeBuffPos2 = 0;
189 gMmsEncodeMaxLen2 = 0;
190 gMmsEncodeCurOffset2 = 0;
195 * @param source [in] originam string
196 * @param length [in] gotten from MmsBinaryEncodeTextStringLen()
197 * @param dest [in] buffer to store quted string
198 * @return changed string length
200 static bool MmsBinaryEncodeTextString2(FILE *pFile, UINT8 *source, int length)
202 MSG_DEBUG("MmsBinaryEncodeTextString2: \n");
206 * Text-string = [Quote] *TEXT End-of-string
207 * If the 1st char in the TEXT is in the range of 128-255, a Quote char must precede it.
208 * Otherwise the Quote char must be omitted.
209 * The Quote is not part of the contents.
210 * Quote = <Octet 127>
213 if (pFile == NULL || source == NULL) {
214 MSG_DEBUG("MmsBinaryEncodeTextString2: source == NULL \n");
218 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < length) {
219 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
220 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
221 MSG_DEBUG("MmsBinaryEncodeTextString2: MsgWriteDataFromEncodeBuffer fail \n");
226 if (source[0] > 0x7F) {
227 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = QUOTE;
231 strncpy(gpMmsEncodeBuf2 + gCurMmsEncodeBuffPos2, (char*)source, (length - 1)); /** except NULL */
232 gCurMmsEncodeBuffPos2 += (length - 1); /** except NULL */
233 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = (UINT8)NULL;
242 static bool __MmsBinaryEncodeFieldCodeAndValue2(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue)
244 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < 2) {
245 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
246 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
247 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: MsgWriteDataFromEncodeBuffer fail \n");
252 if (fieldCode == 0xff) {
253 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldCode \n");
257 if (fieldValue == 0xff) {
258 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldValue \n");
262 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = fieldCode;
263 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = fieldValue;
272 static bool __MmsBinaryEncodeMmsVersion2(FILE *pFile)
274 UINT8 majorVer = MMS_MAJOR_VERSION;
275 UINT8 minorVer = MMS_MINOR_VERSION;
277 MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: \n");
280 MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: invalid input file \n");
284 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < 2) {
285 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
286 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
287 MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: MsgWriteDataFromEncodeBuffer fail \n");
292 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_VERSION) | 0x80;
293 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2] = (majorVer << 4) | (minorVer & 0x0f) | MSB;
295 if (gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2] < 0x80) {
296 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] |= 0x80;
298 gCurMmsEncodeBuffPos2++;
308 bool _MmsBinaryEncodeAckIndHdr(FILE *pFile, char *szTrID, bool bReportAllowed)
311 UINT8 fieldCode = 0xff;
312 UINT8 fieldValue = 0xff;
314 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: szTrID = %s\n", szTrID);
315 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: bReportAllowed = %d\n", bReportAllowed);
317 __MmsCleanEncodeBuff2();
320 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
321 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_ACKNOWLEDGE_IND) | 0x80;
322 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
323 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: msgType error\n");
327 /* trID (other type of message) */
328 length = MmsBinaryEncodeTextStringLen((UINT8*)szTrID);
330 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MmsBinaryEncodeTextStringLen fail \n");
334 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < (length + 1)) {
335 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
336 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
337 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MsgWriteDataFromEncodeBuffer fail \n");
342 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
344 if (MmsBinaryEncodeTextString2(pFile, (UINT8*)szTrID, length) == false) {
345 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MmsBinaryEncodeTextString fail\n");
350 if (__MmsBinaryEncodeMmsVersion2(pFile) == false) {
351 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: __MmsBinaryEncodeMmsVersion error\n");
357 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPORTALLOWED) | 0x80;
359 if (bReportAllowed) {
360 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed, MMS_REPORTALLOWED_YES) | 0x80;
362 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed, MMS_REPORTALLOWED_NO) | 0x80;
365 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
366 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: Report Allowed error\n");
370 /* flush remained data on encoding file */
371 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
372 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
373 MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
386 bool _MmsBinaryEncodeNotiRespIndHdr(FILE *pFile, char *szTrID, msg_delivery_report_status_t iStatus, bool bReportAllowed)
389 UINT8 fieldCode = 0xff;
390 UINT8 fieldValue = 0xff;
392 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: szTrID = %s\n", szTrID);
393 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: iStatus = %d\n", iStatus);
394 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: bReportAllowed = %d\n", bReportAllowed);
396 __MmsCleanEncodeBuff2();
399 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
400 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_NOTIFYRESP_IND) | 0x80;
402 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
403 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: msgType error\n");
408 /* trID (other type of message) */
409 length = MmsBinaryEncodeTextStringLen((UINT8*)szTrID);
411 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MmsBinaryEncodeTextStringLen fail \n");
415 if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < (length + 1)) {
416 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
417 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
418 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgWriteDataFromEncodeBuffer fail \n");
423 gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
424 if (MmsBinaryEncodeTextString2(pFile, (UINT8*)szTrID, length) == false) {
425 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MmsBinaryEncodeTextString fail\n");
430 if (__MmsBinaryEncodeMmsVersion2(pFile) == false) {
431 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: __MmsBinaryEncodeMmsVersion error\n");
437 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgStatus = %d\n", iStatus);
439 if (iStatus != MSG_DELIVERY_REPORT_NONE) {
440 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGSTATUS) | 0x80;
441 fieldValue = _MmsGetBinaryValue(MmsCodeMsgStatus, iStatus) | 0x80;
442 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
443 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgStatus error\n");
450 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPORTALLOWED) | 0x80;
452 if (bReportAllowed) {
453 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed, MMS_REPORTALLOWED_YES) | 0x80;
455 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed, MMS_REPORTALLOWED_NO) | 0x80;
458 if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
459 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: Report Allowed error\n");
463 /* flush remained data on encoding file */
464 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
465 gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
466 MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
478 bool _MmsEncodeAckInd(FILE *pFile, char *pTrID, bool bReportAllowed)
480 _MmsRegisterEncodeBuffer2(gszMmsEncodeBuf2, MSG_MMS_ENCODE_BUFFER_MAX);
482 MSG_DEBUG("_MmsEncodeAckInd: Start Binary Encoding now ============= \n");
484 if (_MmsBinaryEncodeAckIndHdr(pFile, pTrID, bReportAllowed) == false) {
485 MSG_DEBUG("_MmsEncodeAckInd: SendReq Binary encoding fail \n");
489 _MmsUnregisterEncodeBuffer2();
495 MSG_DEBUG("## _MmsEncodeAckInd: failed");
496 _MmsUnregisterEncodeBuffer2();
503 bool _MmsEncodeNotiRespInd(FILE *pFile, char *pTrID, msg_delivery_report_status_t iStatus, bool bReportAllowed)
505 _MmsRegisterEncodeBuffer2(gszMmsEncodeBuf2, MSG_MMS_ENCODE_BUFFER_MAX);
507 MSG_DEBUG("_MmsEncodeNotiRespInd: Start Binary Encoding now ============= \n");
509 if (_MmsBinaryEncodeNotiRespIndHdr(pFile, pTrID, iStatus, bReportAllowed) == false) {
510 MSG_DEBUG("_MmsEncodeNotiRespInd: SendReq Binary encoding fail \n");
514 _MmsUnregisterEncodeBuffer2();
524 /* Functions for Acknowledge.ind & NotifyResp.ind (END) ------------------------ */
525 bool _MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus)
528 MsgMultipart *pPart = NULL;
532 char *pszReportMsg = NULL;
535 struct tm *dateTime = NULL;
539 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
541 MSG_DEBUG("_MmsEncodeMsg: Start Binary Encoding now V1.0============= \n");
543 if (_MmsBinaryEncodeReadReport10Hdr(pFile, pMsg, mmsReadStatus) == false) {
544 MSG_DEBUG("_MmsEncodeReadReport10: SendReq Binary encoding fail \n");
548 memset(&msgType, 0, sizeof(MsgType));
549 memset(&msgBody, 0, sizeof(MsgBody));
551 pText = (char *)malloc(MSG_STDSTR_LONG);
553 MSG_DEBUG("__MmsSendReadReportV10: text body malloc fail \n");
557 memset(pText, 0, MSG_STDSTR_LONG);
560 dateTime = localtime(&RawTime);
561 dateSec = mktime(dateTime);
563 // get report message
564 if (mmsReadStatus == MSG_READ_REPORT_IS_DELETED) {
565 pszReportMsg = (char*)"Your message has been deleted " ;
567 pszReportMsg = (char*)"Your message has been read " ;
570 // make report body ..
571 maxLen = strlen (pszReportMsg) +16 /* date string */ + 8 /* enter chars */ ;
573 if (maxLen > MSG_STDSTR_LONG) {
574 snprintf (pText, MSG_STDSTR_LONG, "%s\n", pszReportMsg);
576 snprintf(pText, MSG_STDSTR_LONG, "%s\r\n\r\n%.4d/%.2d/%.2d %.2d:%.2d\r\n",
577 pszReportMsg, dateTime->tm_year+1900, dateTime->tm_mon+1, dateTime->tm_mday, dateTime->tm_hour, dateTime->tm_min);
581 msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
582 msgType.contentSize = strlen(pText);
583 msgType.param.charset = MSG_CHARSET_UNKNOWN;
586 if ((pPart = MmsAllocMultipart()) == NULL) {
587 MSG_DEBUG("__MmsSendReadReportV10: MsgAllocMultipart Fail \n");
592 pPart->type.type = MIME_TEXT_PLAIN;
593 pPart->type.contentSize = strlen(pText);
594 pPart->type.param.charset = MSG_CHARSET_UTF8;
596 if (pPart->pBody == NULL) {
597 MSG_DEBUG("__MmsSendReadReportV10: pPart->pBody is NULL \n");
601 pPart->pBody->size = strlen(pText);
602 pPart->pBody->body.pText = pText;
604 msgBody.body.pMultipart = pPart;
606 if (MmsBinaryEncodeMsgBody(pFile, &msgType, &msgBody, 1, false) == false) {
607 MSG_DEBUG("__MmsSendReadReportV10: MmsBinaryEncodeMsgBody fail \n");
611 MSG_DEBUG("__MmsSendReadReportV10: Send To RM ReadReport Msg \n");
627 _MmsUnregisterEncodeBuffer();
647 _MmsUnregisterEncodeBuffer();
653 bool _MmsEncodeReadReport11(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus)
655 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
657 MSG_DEBUG("_MmsEncodeMsg: Start Binary Encoding now V1.1============= \n");
659 if (_MmsBinaryEncodeReadReport11Hdr(pFile, pMsg, mmsReadStatus) == false) {
660 MSG_DEBUG("_MmsEncodeMsg: SendReq Binary encoding fail \n");
664 _MmsUnregisterEncodeBuffer();
669 _MmsUnregisterEncodeBuffer();
676 /* ==========================================================
678 B I N A R Y E N C O D I N G
680 ==========================================================*/
683 * Binary Encoded Message Format
685 * < Single Part Body Message >
686 * -----------------------------------
688 * -----------------------------------
689 * | Content Type:start=xxx;type=xxx | ->(ex) Text/Plain, Text/Html, ....
690 * -----------------------------------
691 * | Single Part Body |
692 * -----------------------------------
694 * < Multi Part Body Message >
695 * -----------------------------------
697 * -----------------------------------
698 * | Content Type:start=xxx;type=xxx | -> (ex) Application/vnd.wap.multipart.mixed(related), multipart/mixed(related)
699 * -----------------------------------
700 * | # of Entries (body parts) |
701 * ----------------------------------- < Each Entry >
702 * | Entry 1 | -> -----------------------------
703 * ----------------------------------- | header Length |
704 * | Entry 2 | -----------------------------
705 * ----------------------------------- | Data Length |
706 * | ...... | ----------------------------- -
707 * ----------------------------------- | Content-Type | |
708 * | Entry n | ----------------------------- | Header Length
709 * ----------------------------------- | Header | |
710 * ----------------------------- -
711 * | Data | | Data Length
712 * ----------------------------- -
715 bool _MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
717 UINT8 fieldCode = 0xff;
718 UINT8 fieldValue = 0xff;
721 __MmsCleanEncodeBuff();
724 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
725 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_SEND_REQ) | 0x80;
726 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
727 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: msgType error\n");
731 /* trID (other type of message) */
732 if (__MmsBinaryEncodeTrID(pFile, pMsg->szTrID, MMS_TR_ID_LEN + 1) == false) {
733 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: trID error\n");
737 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: pMsg->szTrID = %s\n", pMsg->szTrID);
739 if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
740 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeMmsVersion error\n");
744 /* From : Insert Token mode */
745 if (__MmsBinaryEncodeFrom(pFile) == false) {
746 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeFrom fail\n");
751 /* To = Encoded-string-value */
752 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szTo) == false)
754 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: To __MmsBinaryEncodeAddress fail\n");
759 /* Cc = Encoded-string-value */
760 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_CC, pMsg->mmsAttrib.szCc) == false) {
761 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: Cc __MmsBinaryEncodeAddress fail\n");
766 /* Bcc = Encoded-string-value */
768 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_BCC, pMsg->mmsAttrib.szBcc) == false) {
769 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: Bcc __MmsBinaryEncodeAddress fail\n");
774 MSG_DEBUG("_MmsBinaryEnocdeSendReqHdr() pMsg->mmsAttrib.szSubject =%s\n",pMsg->mmsAttrib.szSubject);
776 /* Subject = Encoded-string-value */
777 if (pMsg->mmsAttrib.szSubject[0]) {
778 length = MmsBinaryEncodeEncodedStringLen((UINT8*)pMsg->mmsAttrib.szSubject);
780 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MmsBinaryEncodeEncodedStringLen fail \n");
784 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
785 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
786 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
787 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MsgWriteDataFromEncodeBuffer fail \n");
792 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SUBJECT) | 0x80;
793 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
794 if (MmsBinaryEncodeEncodedString(pFile, (UINT8*)pMsg->mmsAttrib.szSubject, length) == false) {
795 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MmsBinaryEncodeEncodedString fail \n");
800 /* MMS-1.3-con-739 */
802 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGCLASS) | 0x80;
803 fieldValue = _MmsGetBinaryValue(MmsCodeMsgClass, (int)pMsg->mmsAttrib.msgClass) | 0x80;
804 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
805 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: msgClass error\n");
808 /* MMS-1.3-con-739 */
809 /* MMS-1.3-con-733 */
810 /* Date = Long-integer */
811 if (!__MmsBinaryEncodeDate(pFile)) {
812 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeDate error\n");
815 /* MMS-1.3-con-733 */
817 /* Expiry Time : Value-length Absolute-token Date-value */
818 if (pMsg->mmsAttrib.bUseExpiryCustomTime == true) {
819 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_EXPIRYTIME, pMsg->mmsAttrib.expiryCustomTime) == false) {
820 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: expiryTime __MmsBinaryEncodeTime fail\n");
823 } else if (pMsg->mmsAttrib.expiryTime.type != MMS_TIMETYPE_NONE) { // for avoiding the creation of the expiry field in case the user selects the maximum
824 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_EXPIRYTIME, pMsg->mmsAttrib.expiryTime) == false) {
825 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: expiryTime __MmsBinaryEncodeTime fail\n");
830 /* Use Custom time for Delivery Time */
831 if (pMsg->mmsAttrib.bUseDeliveryCustomTime == true) {
832 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_DELIVERYTIME, pMsg->mmsAttrib.deliveryCustomTime) == false) {
833 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: deliveryTime __MmsBinaryEncodeTime fail\n");
837 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_DELIVERYTIME, pMsg->mmsAttrib.deliveryTime) == false) {
838 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: deliveryTime __MmsBinaryEncodeTime fail\n");
844 if (pMsg->mmsAttrib.priority!= MMS_PRIORITY_ERROR && pMsg->mmsAttrib.priority!= MMS_PRIORITY_NORMAL) {
845 /* MMS_PRIORITY_NORMAL is default : don't send optional field */
847 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_PRIORITY)|0x80;
848 fieldValue = _MmsGetBinaryValue(MmsCodePriority, pMsg->mmsAttrib.priority)|0x80;
850 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
851 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: priority error\n");
856 /* Sender Visible (hide | show) */
857 if (pMsg->mmsAttrib.bHideAddress == true) {
858 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SENDERVISIBILLITY) | MSB;
859 fieldValue = _MmsGetBinaryValue(MmsCodeSenderVisibility, MMS_SENDER_HIDE) | 0x80;
861 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
862 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: sender visibility error\n");
867 /* Delivery Report (yes | no) */
868 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DELIVERYREPORT)|0x80;
870 if (pMsg->mmsAttrib.bAskDeliveryReport) {
871 fieldValue = _MmsGetBinaryValue(MmsCodeDeliveryReport, MMS_REPORT_YES) | 0x80;
873 fieldValue = _MmsGetBinaryValue(MmsCodeDeliveryReport, MMS_REPORT_NO) | 0x80;
876 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
877 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: sender visibility error\n");
881 /* Read Reply (Yes | no) */
882 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_READREPLY)|0x80;
883 if (pMsg->mmsAttrib.bAskReadReply) {
884 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply, MMS_REPORT_YES)|0x80;
886 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply, MMS_REPORT_NO)|0x80;
889 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
890 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: read reply error\n");
894 if ((pMsg->mmsAttrib.replyCharge.chargeType == MMS_REPLY_REQUESTED) ||
895 (pMsg->mmsAttrib.replyCharge.chargeType == MMS_REPLY_REQUESTED_TEXT_ONLY)) {
898 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPLYCHARGING)|0x80;
899 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply, pMsg->mmsAttrib.replyCharge.chargeType)|0x80;
901 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
902 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyCharging error\n");
906 /** fixme: Reply-charging-deadline */
907 if (pMsg->mmsAttrib.replyCharge.deadLine.time > 0) {
908 if (__MmsBinaryEncodeTime(pFile, MMS_CODE_REPLYCHARGINGDEADLINE, pMsg->mmsAttrib.replyCharge.deadLine) == false) {
909 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyCharging __MmsBinaryEncodeTime fail\n");
914 /** fixme: Reply-charging-size */
915 if (pMsg->mmsAttrib.replyCharge.chargeSize > 0) {
916 length = MmsBinaryEncodeIntegerLen(pMsg->mmsAttrib.replyCharge.chargeSize);
918 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
919 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
920 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
921 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
926 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPLYCHARGINGSIZE) | 0x80;
928 if (MmsBinaryEncodeInteger(pFile, pMsg->mmsAttrib.replyCharge.chargeSize, length) == false) {
929 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyChargingSize MmsBinaryEncodeInteger error\n");
934 /** fixme: Reply-charging-ID ----> used only when reply message */
935 if (pMsg->mmsAttrib.replyCharge.szChargeID[0]) {
936 length = MmsBinaryEncodeTextStringLen((UINT8*)pMsg->mmsAttrib.replyCharge.szChargeID);
938 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: szReplyChargingID MmsBinaryEncodeTextStringLen fail\n");
942 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
943 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
944 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
945 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
950 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPLYCHARGINGID) | 0x80;
952 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pMsg->mmsAttrib.replyCharge.szChargeID, length) == false) {
953 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: szContentLocation MmsBinaryEncodeTextString fail\n");
959 /* flush remained data on encoding file */
960 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
961 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
969 MSG_DEBUG("## _MmsBinaryEncodeSendReqHdr: failed");
973 bool MmsBinaryEncodeSendReqHdrwithinBufRegi(FILE *pFile, MmsMsg *pMsg)
977 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
978 ret = _MmsBinaryEncodeSendReqHdr(pFile, pMsg);
979 _MmsUnregisterEncodeBuffer();
984 bool _MmsBinaryEncodeContentTypeFieldCode(FILE *pFile, int msgID)
986 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 2) {
987 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
988 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
989 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: MsgWriteDataFromEncodeBuffer fail \n");
994 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_CONTENTTYPE) | 0x80;
996 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
997 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
1004 bool MmsBinaryEncodeSendReqHdrContTypeFildCode(FILE *pFile, int msgID)
1008 _MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
1010 ret = _MmsBinaryEncodeContentTypeFieldCode(pFile, msgID);
1012 _MmsUnregisterEncodeBuffer();
1020 _MmsBinaryEncodeForwardReqHdr(FILE* pFile, char* szContentLocation, char* szForwardTo, char* szForwardCc, char* szForwardBcc)
1023 UINT8 fieldCode = 0xff;
1024 UINT8 fieldValue = 0xff;
1028 __MmsCleanEncodeBuff();
1031 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
1032 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_FORWARD_REQ) | 0x80;
1033 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false)
1035 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: msgType error\n");
1040 /* trID (other type of message) */
1041 if (__MmsBinaryEncodeTrID(pFile, NULL, 0) == false)
1043 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: __MmsBinaryEncodeTrID error\n");
1048 /* MMS version (currently we use 1.0 : VDF Spain's version) */
1049 if (__MmsBinaryEncodeMmsVersion(pFile) == false)
1051 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: __MmsBinaryEncodeMmsVersion error\n");
1056 /* Date = Long-integer */
1057 if (!__MmsBinaryEncodeDate(pFile))
1059 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeDate error\n");
1063 /* From : Insert Token mode */
1064 if (__MmsBinaryEncodeFrom(pFile) == false)
1066 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: __MmsBinaryEncodeFrom fail\n");
1071 /* To = Encoded-string */
1072 if (__MmsBinaryEncodeAddress(pFile,
1074 szForwardTo) == false)
1076 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: To __MmsBinaryEncodeAddress fail\n");
1081 /* Cc = Encoded-string */
1082 if (__MmsBinaryEncodeAddress(pFile,
1084 szForwardCc) == false)
1086 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: Cc __MmsBinaryEncodeAddress fail\n");
1091 /* Bcc = Encoded-string */
1092 if (__MmsBinaryEncodeAddress(pFile,
1094 szForwardBcc) == false)
1096 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: Bcc __MmsBinaryEncodeAddress fail\n");
1101 /* Expiry Time : Value-length Absolute-token Date-value */
1102 if (gMmsSetup.sendSetup.bExpiryUseCustomTime == true) //jhlee expiry time use custom time
1104 if (__MmsBinaryEncodeTime(pFile,
1105 MMS_CODE_EXPIRYTIME,
1106 gMmsSetup.sendSetup.expiryCustomTime) == false)
1108 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: expiryTime __MmsBinaryEncodeTime fail\n");
1114 if (__MmsBinaryEncodeTime(pFile,
1115 MMS_CODE_EXPIRYTIME,
1116 gMmsSetup.sendSetup.expiryTime) == false)
1118 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: expiryTime __MmsBinaryEncodeTime fail\n");
1125 /* Delivery Time : Value-length Absolute-token Date-value */
1126 if (__MmsBinaryEncodeTime(pFile,
1127 MMS_CODE_DELIVERYTIME,
1128 gMmsSetup.sendSetup.deliveryTime) == false)
1130 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: deliveryTime __MmsBinaryEncodeTime fail\n");
1135 /* Report Allowed */
1136 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPORTALLOWED) | 0x80;
1137 if (gMmsSetup.recvSetup.bSendDeliveryReport)
1138 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed,
1139 MMS_REPORTALLOWED_YES) | 0x80;
1141 fieldValue = _MmsGetBinaryValue(MmsCodeReportAllowed,
1142 MMS_REPORTALLOWED_NO) | 0x80;
1143 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false)
1145 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: Report Allowed error\n");
1150 /* Delivery Report */
1151 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DELIVERYREPORT) | 0x80;
1152 if (gMmsSetup.recvSetup.bSendDeliveryReport)
1153 fieldValue = _MmsGetBinaryValue(MmsCodeDeliveryReport,
1154 MMS_REPORT_YES) | 0x80;
1156 fieldValue = _MmsGetBinaryValue(MmsCodeDeliveryReport,
1157 MMS_REPORT_NO) | 0x80;
1158 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false)
1160 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: Report Allowed error\n");
1166 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_READREPLY) | 0x80;
1167 if (gMmsSetup.recvSetup.bSendDeliveryReport)
1168 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply,
1169 MMS_REPORT_YES) | 0x80;
1171 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply,
1172 MMS_REPORT_NO) | 0x80;
1173 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false)
1175 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: Read Reply error\n");
1180 /* Content Location */
1181 if (szContentLocation[0])
1183 length = MmsBinaryEncodeTextStringLen((UINT8*)szContentLocation);
1186 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: szContentLocation MmsBinaryEncodeTextStringLen fail\n");
1190 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) // + fieldCode
1192 if (MsgWriteDataFromEncodeBuffer(pFile,
1194 &gCurMmsEncodeBuffPos,
1196 &gMmsEncodeCurOffset) == false)
1198 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
1203 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode,
1204 MMS_CODE_CONTENTLOCATION) | 0x80;
1205 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szContentLocation, length) == false)
1207 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: szContentLocation MmsBinaryEncodeTextString fail\n");
1212 /* flush remained data on encoding file */
1213 if (MsgWriteDataFromEncodeBuffer(pFile,
1215 &gCurMmsEncodeBuffPos,
1217 &gMmsEncodeCurOffset) == false)
1219 MSG_DEBUG("_MmsBinaryEncodeForwardReqHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
1227 MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset);
1233 bool _MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus)
1237 UINT8 fieldCode = 0xff;
1238 UINT8 fieldValue = 0xff;
1239 char szSubject[MSG_LOCALE_SUBJ_LEN + 8] = {0, };
1242 MSG_DEBUG("pMsg is NULL");
1246 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: mmsReadStatus = %d\n", mmsReadStatus);
1248 __MmsCleanEncodeBuff();
1251 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
1252 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_SEND_REQ) | 0x80;
1253 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1254 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: msgType error\n");
1258 /* trID (other type of message) */
1259 if (__MmsBinaryEncodeTrID(pFile, NULL, 0) == false) {
1260 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeTrID error\n");
1264 if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
1265 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeMmsVersion error\n");
1269 /* Date = Long-integer */
1270 if (!__MmsBinaryEncodeDate(pFile)) {
1271 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: date __MmsBinaryEncodeDate error\n");
1275 /* From : Insert Token mode */
1276 if (__MmsBinaryEncodeFrom(pFile) == false) {
1277 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeFrom fail\n");
1281 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", pMsg->mmsAttrib.szFrom);
1283 /* To = Encoded-string */
1284 if (pMsg && (strchr(pMsg->mmsAttrib.szFrom, '/') == NULL)) {
1285 length = strlen(pMsg->mmsAttrib.szFrom);
1286 szTo = (char *)malloc(length + 11);
1288 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: szTo alloc fail\n");
1292 snprintf(szTo, length + 11, "%s/TYPE=PLMN", pMsg->mmsAttrib.szFrom);
1293 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", szTo);
1295 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, szTo) == false) {
1296 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
1305 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szFrom) == false) {
1306 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
1311 /* Subject = Encoded-string-value */
1312 if (pMsg && pMsg->mmsAttrib.szSubject[0]) {
1313 if (mmsReadStatus == MSG_READ_REPORT_IS_READ) {
1314 snprintf(szSubject, MSG_LOCALE_SUBJ_LEN + 8, "%s%s", MMS_READ_REPORT_STRING_READ, pMsg->mmsAttrib.szSubject);
1316 snprintf(szSubject, MSG_LOCALE_SUBJ_LEN + 8, "%s%s", MMS_READ_REPORT_STRING_DELETED, pMsg->mmsAttrib.szSubject);
1319 if (mmsReadStatus == MSG_READ_REPORT_IS_READ) {
1320 snprintf(szSubject, MSG_LOCALE_SUBJ_LEN + 8, "%s", MMS_READ_REPORT_STRING_READ);
1323 snprintf(szSubject, MSG_LOCALE_SUBJ_LEN + 8, "%s", MMS_READ_REPORT_STRING_DELETED );
1327 length = MmsBinaryEncodeEncodedStringLen((UINT8*)szSubject);
1329 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MmsBinaryEncodeEncodedStringLen fail \n");
1333 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
1334 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1335 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MsgWriteDataFromEncodeBuffer fail \n");
1340 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SUBJECT) | 0x80;
1341 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
1342 if (MmsBinaryEncodeEncodedString(pFile, (UINT8*)szSubject, length) == false) {
1343 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MmsBinaryEncodeEncodedString fail \n");
1348 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGCLASS) | 0x80;
1349 fieldValue = _MmsGetBinaryValue(MmsCodeMsgClass, MMS_MSGCLASS_AUTO) | 0x80;
1350 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1351 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: msgClass error\n");
1356 /* Delivery Report (yes | no) */
1357 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DELIVERYREPORT) | 0x80;
1358 fieldValue = _MmsGetBinaryValue(MmsCodeDeliveryReport, MMS_REPORT_NO) | 0x80;
1359 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1360 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Delivery Report error\n");
1365 /* Read Reply (Yes | no) */
1366 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_READREPLY) | 0x80;
1367 fieldValue = _MmsGetBinaryValue(MmsCodeReadReply, MMS_REPORT_NO) | 0x80;
1368 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1369 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Read Reply error\n");
1374 /* Sender Visible (hide | show) */
1375 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SENDERVISIBILLITY) | 0x80;
1376 fieldValue = _MmsGetBinaryValue(MmsCodeSenderVisibility, MMS_SENDER_SHOW) | 0x80;
1377 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1378 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Sender Visible error\n");
1382 /* fixme: msgContentType */
1383 /* fixme: msgHeader */
1384 /* fixme: msgBody */
1386 /* flush remained data on encoding file */
1387 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
1388 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1389 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
1406 bool _MmsBinaryEncodeReadReport11Hdr(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus)
1408 UINT8 fieldCode = 0xff;
1409 UINT8 fieldValue = 0xff;
1412 __MmsCleanEncodeBuff();
1415 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
1416 fieldValue = _MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_READREC_IND) | 0x80;
1417 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1418 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: msgType error\n");
1423 if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
1424 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeMmsVersion error\n");
1428 if (__MmsBinaryEncodeMsgID(pFile, pMsg->szMsgID) == false)
1431 /* To = Encoded-string */
1432 if (strchr(pMsg->mmsAttrib.szFrom, '/') == NULL) {
1434 length = strlen(pMsg->mmsAttrib.szFrom);
1435 szTo = (char *)malloc(length + 11);
1438 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: szTo alloc fail\n");
1442 snprintf(szTo, length + 11,"%s/TYPE=PLMN", pMsg->mmsAttrib.szFrom);
1443 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", szTo);
1445 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, szTo) == false) {
1446 MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
1455 if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szFrom) == false) {
1456 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: To __MmsBinaryEncodeAddress fail\n");
1461 /* From : Insert Token mode */
1462 if (__MmsBinaryEncodeFrom(pFile) == false) {
1463 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeFrom fail\n");
1467 /* Date = Long-integer */
1468 if (!__MmsBinaryEncodeDate(pFile)) {
1469 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeDate error\n");
1473 /* Read Status (Yes | no) */
1474 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_READSTATUS) | 0x80;
1475 fieldValue = _MmsGetBinaryValue(MmsCodeReadStatus, mmsReadStatus) | 0x80;
1477 if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
1478 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: Read Status error\n");
1482 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
1483 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1484 MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
1499 bool MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody, int nPartCount, bool bTemplate)
1502 MsgMultipart *pMultipart = NULL;
1504 MSG_DEBUG("MmsBinaryEncodeMsgBody: nPartCount = %d\n", nPartCount);
1506 if (pFile == NULL || pType == NULL) {
1507 MSG_DEBUG("MmsBinaryEncodeMsgBody: invalid file handle\n");
1511 if (MmsIsMultipart(pType->type)) {
1514 /* ---------------------------
1516 * ---------------------------*/
1518 pType->offset = _MmsGetEncodeOffset();
1521 length = MmsBinaryEncodeContentTypeLen(pType);
1523 MSG_DEBUG("MmsBinaryEncodeMsgBody: MmsBinaryEncodeContentTypeLen fail \n");
1526 if (bTemplate == false)
1527 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_CONTENTTYPE) | 0x80;
1529 if (MmsBinaryEncodeContentType(pFile, pType, length) == false) {
1530 MSG_DEBUG("MmsBinaryEncodeMsgBody: MmsBinaryEncodeContentType fail \n");
1534 pBody->offset = _MmsGetEncodeOffset();
1537 if (pBody->pPresentationBody) {
1538 nEntries = nPartCount + 1;
1540 nEntries = nPartCount;
1543 if (nEntries >= 0) {
1544 length = MmsBinaryEncodeUintvarLen(nEntries);
1546 MSG_DEBUG("MmsBinaryEncodeMsgBody: nEntries MmsBinaryEncodeUintvarLen fail \n");
1549 if (MmsBinaryEncodeUintvar(pFile, nEntries, length) == false) {
1550 MSG_DEBUG("MmsBinaryEncodeMsgBody: nEntries MmsBinaryEncodeUintvar fail \n");
1554 pType->size = _MmsGetEncodeOffset() - pType->offset;
1558 if (nEntries && pBody->pPresentationBody) {
1559 if (MmsBinaryEncodeMsgPart(pFile, pType->type, &pBody->presentationType, pBody->pPresentationBody) == false) {
1560 MSG_DEBUG("MmsBinaryEncodeMsgBody: __MmsBinaryEncodeMsgPart fail \n");
1567 pMultipart = pBody->body.pMultipart;
1568 while (nEntries && pMultipart) {
1569 if (MmsBinaryEncodeMsgPart(pFile, pType->type, &pMultipart->type, pMultipart->pBody) == false) {
1570 MSG_DEBUG("MmsBinaryEncodeMsgBody: __MmsBinaryEncodeMsgPart fail \n");
1573 pMultipart = pMultipart->pNext;
1577 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
1578 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
1579 MSG_DEBUG("MmsBinaryEncodeMsgBody: Empty message body MsgWriteDataFromEncodeBuffer fail \n");
1584 pBody->size = _MmsGetEncodeOffset() - pBody->offset;
1586 /* ---------------------------
1587 * Singlepart message
1588 * ---------------------------*/
1589 pType->offset = _MmsGetEncodeOffset();
1591 if (MmsBinaryEncodeContentHeader(pFile, (MimeType)pType->type, pType, false) == false)
1594 length = MmsBinaryEncodeContentTypeLen(pType);
1596 MSG_DEBUG("MmsBinaryEncodeMsgBody: Singlepart MmsBinaryEncodeContentTypeLen fail \n");
1600 if (MmsBinaryEncodeContentType(pFile, pType, length) == false)
1603 pType->size = _MmsGetEncodeOffset() - pType->offset;
1605 if (MmsBinaryEncodeContentBody(pFile, pBody) == false)
1612 MSG_DEBUG("## MmsBinaryEncodeMsgBody: failed\n");
1618 int MmsBinaryEncodeContentTypeLen(MsgType *pType)
1621 int totalLength = 0;
1622 UINT16 fieldValue = 0xffff;
1623 char *szTextType = NULL;
1624 int contentType = MIME_UNKNOWN;
1626 MSG_DEBUG("MSmsBinaryEncodeContentTypeLen: type\n");
1629 * Content-type-value = Constrained-media | Content-general-form
1630 * Constrained-media = Constrained-encoding
1631 * Constrained-encoding = Extension-Media | Short-integer
1632 * Extension-media = *TEXT End-of-string
1633 * Content-general-form = Value-length Media-type
1634 * Media-type = (Well-known-media | Extension-Media) *(Parameter)
1637 /* Content-type-value = Content-general-form ------------------------------- */
1640 contentType = pType->type;
1642 fieldValue = _MmsGetBinaryValue(MmsCodeContentType, contentType);
1643 if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
1644 /* Extension-media type */
1645 szTextType = _MmsGetTextValue(MmsCodeContentType, contentType);
1646 if (szTextType != NULL) {
1647 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
1649 MSG_DEBUG("MSmsBinaryEncodeContentTypeLen: szTextType MmsBinaryEncodeTextStringLen fail \n");
1652 totalLength += length;
1660 /* Parameters -------------------------------------------------------------- */
1662 MSG_DEBUG("MSmsBinaryEncodeContentTypeLen: parameters \n\n");
1664 /* Well-known-charset = Any-charset | Integer-value ----------------------- */
1666 if (pType->param.charset != MSG_CHARSET_UNKNOWN) {
1667 fieldValue = _MmsGetBinaryValue(MmsCodeCharSet, pType->param.charset);
1668 length = MmsBinaryEncodeIntegerLen(fieldValue);
1670 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: charSet MmsBinaryEncodeIntegerLen fail \n");
1673 totalLength += (length + 1);
1675 if (MmsIsText(contentType)) { // Any-charset
1676 if (!MmsIsVitemContent (contentType, pType->param.szName))
1682 /* Name = Text-string ------------------------------------------------------ */
1684 if (pType->param.szName[0]) {
1685 char* pszName = NULL;
1687 if (MsgIsASCII (pType->param.szName)) {
1688 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is consisted of ascii char-set chars. \n");
1690 pszName = (char *)malloc(strlen(pType->param.szName) +1);
1691 memset(pszName, 0, (strlen(pType->param.szName)+1));
1692 strcpy(pszName, pType->param.szName);
1694 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is not consisted of ascii char-set chars. \n");
1695 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pType->param.szName : %s\n", pType->param.szName);
1697 /* if msg-server can't support non ascii, then convert non-ascii to '_' by using _MsgReplaceNonAscii*/
1698 int filelen = strlen(pType->param.szName);
1700 pszName = (char *)malloc(filelen + 1);
1701 memset(pszName, 0, (filelen + 1));
1702 strncpy(pszName, pType->param.szName, filelen);
1704 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pszName : %s\n", pszName);
1707 //change empty space to '_' in the file name
1708 if (MsgIsSpace(pszName)) {
1709 char *pszTempName = NULL;
1711 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName has space(' '). \n");
1713 MsgReplaceSpecialChar(pszName, &pszTempName, ' ');
1717 pszName = pszTempName;
1719 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pszName : %s\n", pszName);
1722 length = MmsBinaryEncodeTextStringLen((UINT8*)pszName);
1726 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName MmsBinaryEncodeIntegerLen fail \n");
1730 totalLength += (length + 1);
1733 #ifdef FEATURE_JAVA_MMS
1734 if (pType->param.szApplicationID) {
1735 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szApplicationID);
1737 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szApplicationID MmsBinaryEncodeTextStrinLen fail \n");
1741 totalLength += (length);
1742 if (_MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID) == UNDEFINED_BINARY) {
1743 totalLength += strlen(_MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID)) + 1; /* NULL */
1749 if (pType->param.szReplyToApplicationID) {
1750 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szReplyToApplicationID);
1752 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szApplicationID MmsBinaryEncodeTextStrinLen fail \n");
1756 totalLength += (length);
1757 if (_MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID) == UNDEFINED_BINARY) {
1758 totalLength += strlen(_MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID)) + 1; /* NULL */
1765 /* type, start, & startInfo : multipart/related only parameters -------------- */
1766 if (contentType == MIME_MULTIPART_RELATED || contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
1767 /* type ------------------------------------- */
1768 fieldValue = _MmsGetBinaryValue(MmsCodeContentType, pType->param.type);
1769 if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
1770 /* Extension-media type */
1771 szTextType = _MmsGetTextValue(MmsCodeContentType, pType->param.type);
1772 if (szTextType != NULL) {
1773 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
1775 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: type param MmsBinaryEncodeTextStringLen fail \n");
1778 totalLength += (length + 1);
1786 /* start = Text-string ----------------------- */
1787 if (pType->param.szStart[0]) {
1788 /* start = Text-string */
1789 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStart);
1791 MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextStringLen fail \n");
1795 totalLength += (length + 1);
1799 /* startInfo = Text-string -------------------- */
1800 if (pType->param.szStartInfo[0]) {
1801 /* StartInfo (with multipart/related) = Text-string */
1802 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStartInfo);
1804 MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextStringLen fail \n");
1808 totalLength += (length + 1);
1816 MSG_DEBUG("## MmsBinaryEncodeContentTypeLen: failed");
1822 bool MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLength)
1825 UINT16 fieldValue = 0xffff;
1826 char *szTextType = NULL;
1827 int contentType = MIME_UNKNOWN;
1829 #ifdef FEATURE_JAVA_MMS
1830 char *szParameter = NULL;
1833 MSG_DEBUG("************************************************************************************\n");
1834 MSG_DEBUG("MmsBinaryEncodeContentType: C O N T E N T T Y P E \n\n");
1837 * Content-type-value = Constrained-media | Content-general-form
1838 * Constrained-media = Constrained-encoding
1839 * Constrained-encoding = Extension-Media | Short-integer
1840 * Extension-media = *TEXT End-of-string
1841 * Content-general-form = Value-length Media-type
1842 * Media-type = (Well-known-media | Extension-Media) *(Parameter)
1845 if (pFile == NULL) {
1846 MSG_DEBUG("MmsBinaryEncodeContentType: invalid file handle\n");
1851 /* Content-Type = Content-general-form ------------------------------- */
1853 length = MmsBinaryEncodeValueLengthLen(typeLength);
1855 MSG_DEBUG("MSmsBinaryEncodeContentType : MmsBinaryEncodeValueLengthLen fail.\n");
1859 if (MmsBinaryEncodeValueLength(pFile, typeLength, length) == false) {
1860 MSG_DEBUG("MSmsBinaryEncodeContentType : MmsBinaryEncodeValueLength fail.\n");
1864 contentType = pType->type;
1866 fieldValue = _MmsGetBinaryValue(MmsCodeContentType, (int)contentType);
1867 if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
1868 /* Extension-media type */
1869 szTextType = _MmsGetTextValue(MmsCodeContentType, (int)contentType);
1870 if (szTextType == NULL)
1874 if (szTextType == NULL) {
1875 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)fieldValue | 0x80;
1877 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
1879 MSG_DEBUG("MSmsBinaryEncodeContentType: szTextType MmsBinaryEncodeTextStringLen fail \n");
1883 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szTextType, length) == false) {
1884 MSG_DEBUG("MmsBinaryEncodeContentType: szTextType MmsBinaryEncodeTextString fail \n");
1889 /* Parameters -------------------------------------------------------------- */
1891 MSG_DEBUG("MmsBinaryEncodeContentType: P A R M E T E R S \n\n");
1893 /* Name = Text-string ------------------------------------------------------ */
1895 if (pType->param.szName[0]) {
1896 char* pszName = NULL;
1898 if (MsgIsASCII (pType->param.szName)) {
1900 MSG_DEBUG("MmsBinaryEncodeContentType: szName is consisted of ascii char-set chars. \n");
1902 pszName = (char *)malloc(strlen(pType->param.szName) +1);
1903 memset(pszName, 0, (strlen(pType->param.szName)+1));
1904 strcpy(pszName, pType->param.szName);
1906 MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is not consisted of ascii char-set chars. \n");
1908 /* if msg-server can't support non ascii, then convert non-ascii to '_' by using _MsgReplaceNonAscii*/
1909 int filelen = strlen(pType->param.szName);
1911 pszName = (char *)malloc(filelen + 1);
1912 memset(pszName, 0, (filelen + 1));
1913 strncpy(pszName, pType->param.szName, filelen);
1915 MSG_DEBUG("MmsBinaryEncodeContentType: pszName : %s\n", pszName);
1918 //change empty space to '_' in the file name
1919 if (MsgIsSpace(pszName)) {
1920 char* pszTempName = NULL;
1922 MSG_DEBUG("MmsBinaryEncodeContentType: szName has space(' '). \n");
1924 MsgReplaceSpecialChar(pszName, &pszTempName, ' ');
1928 pszName = pszTempName;
1930 MSG_DEBUG("MmsBinaryEncodeContentType: pszName : %s\n", pszName);
1933 length = MmsBinaryEncodeTextStringLen((UINT8*)pszName);
1935 MSG_DEBUG("MmsBinaryEncodeContentType: szName MmsBinaryEncodeIntegerLen fail \n");
1939 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_NAME) | 0x80;
1941 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pszName, length) == false) {
1942 MSG_DEBUG("MmsBinaryEncodeContentType: szName MmsBinaryEncodeTextString fail\n");
1948 #ifdef FEATURE_JAVA_MMS
1949 MSG_DEBUG(" MmsBinaryEncodeContentType: Application-ID \n");
1951 /* Application-ID: Text-string */
1952 if (pType->param.szApplicationID) {
1953 length = MmsBinaryEncodeTextStringLen((UINT8*) pType->param.szApplicationID);
1955 MSG_DEBUG("MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeIntegerLen Fail \n");
1959 fieldValue = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID);
1961 if (fieldValue == UNDEFINED_BINARY)
1962 szParameter = _MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID);
1964 if (szParameter == NULL) {
1965 MSG_DEBUG("MmsBinaryEncodeContentType: szParameter is NULL \n");
1969 strncpy(gpMmsEncodeBuf + gCurMmsEncodeBuffPos, (char*)szParameter, strlen(szParameter));
1970 gCurMmsEncodeBuffPos += strlen(szParameter);
1971 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] =(UINT8)NULL;
1973 if (MmsBinaryEncodeTextString(pFile, (UINT8*) pType->param.szApplicationID, length) == false) {
1974 MSG_DEBUG(" MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeTextString fail\n");
1980 /* ReplyToApplicationID: Text-string */
1981 if (pType->param.szReplyToApplicationID) {
1982 length = MmsBinaryEncodeTextStringLen((UINT8*) pType->param.szReplyToApplicationID);
1984 MSG_DEBUG("MmsBinaryEncodeContentType: szReplyToApplicationID MmsBinaryEncodeIntegerLen Fail \n");
1988 fieldValue = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID);
1990 if (fieldValue == UNDEFINED_BINARY)
1991 szParameter = _MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID);
1993 if (szParameter == NULL) {
1994 MSG_DEBUG("MmsBinaryEncodeContentType: szParameter is NULL \n");
1998 strncpy(gpMmsEncodeBuf + gCurMmsEncodeBuffPos, (char*)szParameter, strlen(szParameter));
1999 gCurMmsEncodeBuffPos += strlen(szParameter);
2000 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] =(UINT8)NULL;
2002 if (MmsBinaryEncodeTextString(pFile, (UINT8*) pType->param.szReplyToApplicationID, length) == false) {
2003 MSG_DEBUG(" MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeTextString fail\n");
2009 /* Well-known-charset = Any-charset | Integer-value ----------------------- */
2011 if (pType->param.charset != MSG_CHARSET_UNKNOWN) {
2012 fieldValue = _MmsGetBinaryValue(MmsCodeCharSet, pType->param.charset);
2013 length = MmsBinaryEncodeIntegerLen(fieldValue);
2015 MSG_DEBUG("MmsBinaryEncodeContentType: charSet MmsBinaryEncodeIntegerLen fail \n");
2019 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_CHARSET) | 0x80;
2020 if (MmsBinaryEncodeInteger(pFile, fieldValue, length) == false) {
2021 MSG_DEBUG("MmsBinaryEncodeContentType: charSet MmsBinaryEncodeInteger fail\n");
2026 if (MmsIsText(contentType)) {
2027 if (!MmsIsVitemContent (contentType, pType->param.szName)) {
2028 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_CHARSET) | 0x80;
2029 fieldValue = 0x0000; //laconic_warning, just to remove warning message
2030 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)fieldValue | 0x80;
2035 /* type, start, & startInfo : multipart/related only parameters -------------- */
2036 if (contentType == MIME_MULTIPART_RELATED || contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
2037 /* type ------------------------------------- */
2038 fieldValue = _MmsGetBinaryValue(MmsCodeContentType, pType->param.type);
2039 if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
2040 /* Extension-media type */
2041 szTextType = _MmsGetTextValue(MmsCodeContentType, pType->param.type);
2042 if (szTextType == NULL)
2046 if (szTextType == NULL) {
2047 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)fieldValue | 0x80;
2048 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_TYPE) | 0x80;
2050 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
2052 MSG_DEBUG("MmsBinaryEncodeContentType: type param MmsBinaryEncodeTextStringLen fail \n");
2056 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_TYPE) | 0x80;
2057 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szTextType, length) == false) {
2058 MSG_DEBUG("MmsBinaryEncodeContentType: type param MmsBinaryEncodeTextString fail \n");
2063 /* start = Text-string ----------------------- */
2064 if (pType->param.szStart[0]) {
2065 /* start = Text-string */
2066 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStart);
2068 MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextStringLen fail \n");
2072 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode,
2073 MSG_PARAM_START) | 0x80;
2074 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pType->param.szStart, length) == false) {
2075 MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextString fail \n");
2080 /* startInfo = Text-string -------------------- */
2081 if (pType->param.szStartInfo[0]) {
2082 /* StartInfo (with multipart/related) = Text-string */
2083 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStartInfo);
2085 MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextStringLen fail \n");
2089 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_START_INFO) | 0x80;
2090 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pType->param.szStartInfo, length) == false) {
2091 MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextString fail \n");
2100 MSG_DEBUG("## MmsBinaryEncodeContentType: failed");
2106 bool MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pType, MsgBody *pBody)
2108 FILE *pFile2 = NULL;
2113 if (pType->offset && pType->size) {
2114 /* header length & body length --------------------------- */
2116 length = MmsBinaryEncodeUintvarLen(pType->size);
2118 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. headerLeng MmsBinaryEncodeUintvarLen fail \n");
2122 if (MmsBinaryEncodeUintvar(pFile, pType->size, length) == false) {
2123 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. eaderLeng fail \n");
2127 length = MmsBinaryEncodeUintvarLen(pBody->size);
2129 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. bodyLeng MmsBinaryEncodeUintvarLen fail \n");
2133 if (MmsBinaryEncodeUintvar(pFile, pBody->size, length) == false) {
2134 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. bodyLeng fail \n");
2138 pFile2 = MsgOpenFile(pType->szOrgFilePath, "rb");
2139 if (pFile != NULL) {
2140 pData = (char *)malloc(pType->size);
2144 if (MsgFseek(pFile2, pType->offset, SEEK_SET) < 0) {
2145 MSG_DEBUG("MmsBinaryEncodeMsgPart: MsgFseek fail \n");
2151 if ((nRead = MsgReadFile(pData, sizeof(char), pType->size, pFile2)) == 0) {
2152 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2153 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2154 MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. header MsgWriteDataFromEncodeBuffer fail \n");
2157 pType->offset = _MmsGetEncodeOffset();
2158 if(MsgWriteFile(pData, sizeof(char), nRead, pFile) != (size_t)nRead) {
2159 MSG_DEBUG("MsgWriteFile failed");
2162 gMmsEncodeCurOffset = MsgFtell(pFile);
2163 if(gMmsEncodeCurOffset < 0) {
2164 MSG_DEBUG("MsgFtell returns negative value [%ld]", gMmsEncodeCurOffset);
2169 MsgCloseFile(pFile2);
2174 int contentTypeLen = 0;
2175 int contentHdrLen = 0;
2177 /* header length & body length --------------------------- */
2178 contentTypeLen = MmsBinaryEncodeContentTypeLen(pType);
2179 length = MmsBinaryEncodeValueLengthLen(contentTypeLen);
2180 contentHdrLen = MmsBinaryEncodeContentHeaderLen((MimeType)contentType, pType, true);
2182 if (contentTypeLen == -1 || length == -1 || contentHdrLen == -1) {
2183 MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng calculation fail \n");
2187 headerLeng = contentTypeLen + contentHdrLen + length;
2188 length = MmsBinaryEncodeUintvarLen(headerLeng);
2190 MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng MmsBinaryEncodeUintvarLen fail \n");
2194 if (MmsBinaryEncodeUintvar(pFile, headerLeng, length) == false) {
2195 MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng fail \n");
2199 length = MmsBinaryEncodeUintvarLen(pBody->size);
2201 MSG_DEBUG("MmsBinaryEncodeMsgPart: bodyLeng MmsBinaryEncodeUintvarLen fail \n");
2205 if (MmsBinaryEncodeUintvar(pFile, pBody->size, length) == false) {
2206 MSG_DEBUG("MmsBinaryEncodeMsgPart: bodyLeng fail \n");
2210 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2211 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2212 MSG_DEBUG("MmsBinaryEncodeMsgPart: 2. header MsgWriteDataFromEncodeBuffer fail \n");
2216 /* content-type & header --------------------------- */
2217 pType->offset = _MmsGetEncodeOffset();
2219 if (MmsBinaryEncodeContentType(pFile, pType, contentTypeLen) == false) {
2220 MSG_DEBUG("MmsBinaryEncodeMsgPart: MmsBinaryEncodeContentType fail \n");
2224 if (MmsBinaryEncodeContentHeader(pFile, (MsgContentType)contentType, pType, true) == false) {
2225 MSG_DEBUG("MmsBinaryEncodeMsgPart: MmsBinaryEncodeContentHeader fail \n");
2229 pType->size = _MmsGetEncodeOffset() - pType->offset;
2232 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2233 MSG_DEBUG("MmsBinaryEncodeMsgPart: contentBody MsgWriteDataFromEncodeBuffer fail \n");
2237 /* content-body --------------------------- */
2238 if (MmsBinaryEncodeContentBody(pFile, pBody) == false) {
2239 MSG_DEBUG("MmsBinaryEncodeMsgPart: MmsBinaryEncodeContentBody fail \n");
2257 MSG_DEBUG("## MmsBinaryEncodeMsgPart: failed\n");
2259 MsgCloseFile(pFile2);
2267 int MmsBinaryEncodeContentHeaderLen(MsgContentType contentType, MsgType *pType, bool bMultipart)
2270 int totalLength = 0;
2271 char *szTextValue = NULL;
2274 MSG_DEBUG("MmsBinaryEncodeContentHeaderLen: S T A R T \n\n");
2276 /* content-id ------------------------------------------------- */
2277 if (pType->szContentID[0]) {
2278 if (bMultipart) { //Binary Encoding
2281 /* content-id = Quoted-string */
2282 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-ID");
2284 MSG_DEBUG("MmsBinaryEncodeContentHeaderLen: Content-ID MmsBinaryEncodeTextStringLen fail.\n");
2288 totalLength += length;
2291 length = MmsBinaryEncodeQuotedStringLen((UINT8*)pType->szContentID);
2293 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedStringLen fail.\n");
2296 totalLength += length;
2300 if (pType->szContentLocation[0]) {
2301 if (bMultipart) { //Binary Encoding
2304 /* content-location = Quoted-string */
2305 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-Location");
2307 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextStringLen fail.\n");
2311 totalLength += length;
2314 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->szContentLocation);
2316 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextStringLen fail.\n");
2320 totalLength += length;
2324 /* MIME_APPLICATION_VND_WAP_MULTIPART_RELATEDrequires always "inline" */
2326 if (contentType != MIME_APPLICATION_VND_WAP_MULTIPART_RELATED &&
2327 contentType != MIME_MULTIPART_RELATED &&
2328 pType->disposition != INVALID_VALUE) {
2331 * Content-disposition-value = Value-length Disposition *(Parameter)
2332 * Disposition = Form-data | Attachment | Inline | Token-text
2333 * Form-data = <Octet 128> : 0x80
2334 * Attachment = <Octet 129> : 0x81
2335 * Inline = <Octet 130> : 0x82
2338 if (bMultipart) { //Binary Encoding
2341 /* content-disposition = Quoted-string */
2342 szTextValue = _MmsGetTextValue(MmsCodeMsgDisposition, pType->disposition);
2345 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-Disposition");
2347 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
2351 totalLength += length;
2353 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextValue);
2355 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
2358 totalLength += length;
2366 MSG_DEBUG("## MmsBinaryEncodeContentHeadeLen: failed");
2373 bool MmsBinaryEncodeContentHeader(FILE *pFile, MsgContentType contentType, MsgType *pType, bool bMultipart)
2376 char *szTextValue = NULL;
2378 MSG_DEBUG("MmsBinaryEncodeContentHeader: S T A R T \n\n");
2380 /* content-id ------------------------------------------------- */
2381 if (pType->szContentID[0]) {
2382 if (bMultipart) { //Binary Encoding
2383 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeMsgBodyHeaderCode, MMS_BODYHDR_CONTENTID) | 0x80;
2385 /* content-id = Quoted-string */
2386 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-ID");
2388 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-ID MmsBinaryEncodeTextStringLen fail.\n");
2392 if (MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-ID", length) == false) {
2393 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-ID MmsBinaryEncodeTextString fail.\n");
2398 length = MmsBinaryEncodeQuotedStringLen((UINT8*)pType->szContentID);
2400 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedStringLen fail.\n");
2404 if (MmsBinaryEncodeQuotedString(pFile, (UINT8*)pType->szContentID, length) == false) {
2405 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedString fail.\n");
2410 if (pType->szContentLocation[0]) {
2411 if (bMultipart) { //Binary Encoding
2412 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeMsgBodyHeaderCode, MMS_BODYHDR_CONTENTLOCATION) | 0x80;
2414 /* content-location = Quoted-string */
2415 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-Location");
2417 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextStringLen fail.\n");
2421 if (MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-Location", length) == false) {
2422 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextString fail.\n");
2427 length = MmsBinaryEncodeTextStringLen((UINT8*)pType->szContentLocation);
2429 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextStringLen fail.\n");
2433 if (MmsBinaryEncodeTextString(pFile, (UINT8*)pType->szContentLocation, length) == false) {
2434 MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextString fail.\n");
2439 /* MIME_APPLICATION_VND_WAP_MULTIPART_RELATEDrequires always "inline" */
2441 if (contentType != MIME_APPLICATION_VND_WAP_MULTIPART_RELATED &&
2442 contentType != MIME_MULTIPART_RELATED &&
2443 pType->disposition != INVALID_VALUE) {
2446 * Content-disposition-value = Value-length Disposition *(Parameter)
2447 * Disposition = Form-data | Attachment | Inline | Token-text
2448 * Form-data = <Octet 128> : 0x80
2449 * Attachment = <Octet 129> : 0x81
2450 * Inline = <Octet 130> : 0x82
2453 if (bMultipart) {//Binary Encoding
2455 UINT8 fieldValue = 0xff;
2456 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeMsgBodyHeaderCode, MMS_BODYHDR_DISPOSITION) | 0x80;
2458 fieldValue = _MmsGetBinaryValue(MmsCodeMsgDisposition, pType->disposition) | 0x80;
2460 if (fieldValue == 0xff)
2463 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = 0x01;
2464 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldValue;
2466 /* content-disposition = Disposition (no support parameter) */
2468 szTextValue = _MmsGetTextValue(MmsCodeMsgDisposition, pType->disposition);
2471 length = MmsBinaryEncodeTextStringLen((UINT8*)"Content-Disposition");
2473 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
2477 if (MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-Disposition", length) == false) {
2478 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextString fail.\n");
2482 length = MmsBinaryEncodeTextStringLen((UINT8*)szTextValue);
2484 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
2488 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szTextValue, length) == false) {
2489 MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextString fail.\n");
2499 MSG_DEBUG("## MmsBinaryEncodeContentHeader: failed");
2505 bool MmsBinaryEncodeContentBody(FILE *pFile, MsgBody *pBody)
2517 if (pBody->szOrgFilePath[0]) {
2518 pData = MsgOpenAndReadMmsFile(pBody->szOrgFilePath, pBody->offset, pBody->size, &nRead);
2522 pBody->offset = _MmsGetEncodeOffset();
2523 if(MsgWriteFile(pData, sizeof(char), nRead, pFile) != (size_t)nRead) {
2524 MSG_DEBUG("MsgWriteFile failed");
2527 gMmsEncodeCurOffset = MsgFtell(pFile);
2529 if (gMmsEncodeCurOffset < 0) {
2530 MSG_DEBUG("MsgFtell returns negative value [%ld]", gMmsEncodeCurOffset);
2538 } else if (pBody->body.pText && pBody->size) {
2539 pBody->offset = _MmsGetEncodeOffset();
2540 if (MsgWriteFile(pBody->body.pText, sizeof(char),(size_t)pBody->size, pFile) != (size_t)pBody->size) {
2541 MSG_DEBUG("MsgWriteFile failed");
2544 gMmsEncodeCurOffset = MsgFtell(pFile);
2546 if(gMmsEncodeCurOffset < 0) {
2547 MSG_DEBUG("MsgFtell returns negative value [%ld]", gMmsEncodeCurOffset);
2555 MSG_DEBUG("## MmsBinaryEncodeContentBody: failed\n");
2566 /* =========================================================================
2568 B I N A R Y E N C O D I N G U T I L I T Y
2570 =========================================================================*/
2572 static int MmsBinaryEncodeIntegerLen(UINT32 integer)
2574 if (integer < 0x80) {
2581 * Long-integer = Short-length Multi-octet-integer
2582 * The Short-length indicates the length of the Multi-octet-integer
2587 integer = (integer >> 8);
2590 length++; // + Short-length
2598 * This makes value-length by specified integer value
2600 * @param length [in] gotten from MmsBinaryEncodeIntegerLen()
2602 static bool MmsBinaryEncodeInteger(FILE *pFile, UINT32 integer, int length)
2610 if (pFile == NULL) {
2611 MSG_DEBUG("MmsBinaryEncodeInteger: source == NULL \n");
2615 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2616 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2617 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2618 MSG_DEBUG("MmsBinaryEncodeInteger: MsgWriteDataFromEncodeBuffer fail \n");
2623 if (integer < 0x80) {
2625 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)integer | 0x80;
2628 * Long-integer = Short-length Multi-octet-integer
2629 * The Short-length indicates the length of the Multi-octet-integer
2631 changer.integer = integer;
2632 length--; // - "Short-length"
2634 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)length;
2637 for(i = 0; i < length; i++)
2638 gpMmsEncodeBuf[gCurMmsEncodeBuffPos + i] = changer.seg[length - (i + 1)];
2640 gCurMmsEncodeBuffPos += length;
2650 static int MmsBinaryEncodeLongIntegerLen(UINT32 integer)
2655 * Long-integer = Short-length Multi-octet-integer
2656 * The Short-length indicates the length of the Multi-octet-integer
2664 integer = (integer >> 8);
2667 length++; // + Short-length
2674 * This makes value-length by specified integer value
2676 * @param length [in] gotten from MmsBinaryEncodeIntegerLen()
2678 static bool MmsBinaryEncodeLongInteger(FILE *pFile, UINT32 integer, int length)
2688 * Long-integer = Short-length Multi-octet-integer
2689 * The Short-length indicates the length of the Multi-octet-integer
2692 if (pFile == NULL) {
2693 MSG_DEBUG("MmsBinaryEncodeLongInteger: source == NULL \n");
2697 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2698 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2699 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2700 MSG_DEBUG("MmsBinaryEncodeLongInteger: MsgWriteDataFromEncodeBuffer fail \n");
2705 changer.integer = integer;
2706 length--; // - "Short-length"
2708 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)length;
2710 for(i = 0; i < length; i++)
2711 gpMmsEncodeBuf[gCurMmsEncodeBuffPos + i] = changer.seg[length - (i + 1)];
2713 gCurMmsEncodeBuffPos += length;
2723 static int MmsBinaryEncodeTextStringLen(UINT8 *source)
2727 MSG_DEBUG("MmsBinaryEncodeTextStringLen: \n");
2729 if (source == NULL) {
2730 MSG_DEBUG("MmsBinaryEncodeTextStringLen: source == NULL \n");
2734 length = (int)strlen((char*)source);
2735 if (source[0] > 0x7F) {
2736 length += 2; // + NULL
2746 * @param source [in] originam string
2747 * @param length [in] gotten from MmsBinaryEncodeTextStringLen()
2748 * @param dest [in] buffer to store quted string
2749 * @return changed string length
2751 static bool MmsBinaryEncodeTextString(FILE *pFile, UINT8 *source, int length)
2754 MSG_DEBUG("MmsBinaryEncodeTextString: \n");
2758 * Text-string = [Quote] *TEXT End-of-string
2759 * If the 1st char in the TEXT is in the range of 128-255, a Quote char must precede it.
2760 * Otherwise the Quote char must be omitted.
2761 * The Quote is not part of the contents.
2762 * Quote = <Octet 127>
2765 if (pFile == NULL || source == NULL) {
2766 MSG_DEBUG("MmsBinaryEncodeTextString: source == NULL \n");
2770 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2771 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2772 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2773 MSG_DEBUG("MmsBinaryEncodeTextString: MsgWriteDataFromEncodeBuffer fail \n");
2778 if (source[0] > 0x7F) {
2779 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = QUOTE;
2783 strncpy(gpMmsEncodeBuf + gCurMmsEncodeBuffPos, (char*)source, (length - 1)); // except NULL
2784 gCurMmsEncodeBuffPos += (length - 1); // except NULL
2785 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)NULL;
2796 * Encode 28bit unsigned integer(Maximum) to uintvar
2798 * @param interger [in] integer to be encoded
2799 * @return encoded UINTVAR stream
2801 const UINT32 UINTVAR_LENGTH_1 = 0x0000007f; //7bit
2802 const UINT32 UINTVAR_LENGTH_2 = 0x00003fff; //14bit
2803 const UINT32 UINTVAR_LENGTH_3 = 0x001fffff; //21bit
2806 static int MmsBinaryEncodeUintvarLen(UINT32 integer)
2810 /* Find encoded unitvar length */
2811 if (integer <= UINTVAR_LENGTH_1) {
2814 if (integer <= UINTVAR_LENGTH_2) {
2817 if (integer <= UINTVAR_LENGTH_3) {
2829 static bool MmsBinaryEncodeUintvar(FILE *pFile, UINT32 integer, int length)
2831 const char ZERO = 0x00;
2833 char szReverse[MSG_STDSTR_LONG] = {0, };
2840 if (pFile == NULL) {
2841 MSG_DEBUG("MmsBinaryEncodeUintvar: pFile == INVALID_HBOJ \n");
2845 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2846 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2847 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2848 MSG_DEBUG("MmsBinaryEncodeUintvar: MsgWriteDataFromEncodeBuffer fail \n");
2853 source.integer = integer;
2854 memset(szReverse, 0, MSG_STDSTR_LONG);
2856 /* Seperate integer to 4 1 byte integer */
2857 szReverse[3] = source.bytes[3] & 0x0f;
2858 szReverse[0] = source.bytes[0];
2859 szReverse[0] = szReverse[0] & 0x7f;
2861 while (length >= i) { // initially, i = 2
2862 /* Move integer bit to proper position */
2863 source.integer = source.integer << 1;
2864 source.integer = source.integer >> 8;
2865 source.bytes[3] = ZERO;
2867 /* Retrive 1 encode uintvar */
2868 szReverse[i-1] = source.bytes[0];
2869 szReverse[i-1] = szReverse[i-1] | 0x80;
2873 for(i=0; i < length; i++)
2874 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = szReverse[length - i - 1];
2884 static int MmsBinaryEncodeValueLengthLen(UINT32 integer)
2888 if (integer < 0x1f) {
2891 length = MmsBinaryEncodeUintvarLen(integer) + 1; //LENGTH_QUOTE
2899 * This makes value-length by specified integer value
2901 * @param length [in] from MmsBinaryEncodeValueLengthLen()
2902 * @return encoded value-length
2904 static bool MmsBinaryEncodeValueLength(FILE *pFile, UINT32 integer, int length)
2907 * Value-length = Short-length | (Length-quote Length)
2908 * ; Value length is used to indicate the length of the value to follow
2909 * Short-length = <Any octet 0-30>
2910 * Length-quote = <Octet 31>
2911 * Length = Uintvar-integer
2914 if (pFile == NULL) {
2915 MSG_DEBUG("MmsBinaryEncodeValueLength: pFile == INVALID_HBOJ \n");
2919 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2920 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2921 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2922 MSG_DEBUG("MmsBinaryEncodeValueLength: MsgWriteDataFromEncodeBuffer fail \n");
2927 if (integer < 0x1F) {
2928 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)integer;
2930 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)LENGTH_QUOTE;
2931 if (MmsBinaryEncodeUintvar(pFile, integer, length - 1) == false) { // LENGTH_QUOTE
2932 MSG_DEBUG("MmsBinaryEncodeValueLength: MmsBinaryEncodeUintvar fail\n");
2944 static int MmsBinaryEncodeQuotedStringLen(UINT8 *pSrc)
2947 MSG_DEBUG("MmsBinaryEncodeQuotedStringLen: invalid file\n");
2951 return (strlen((char*)pSrc) + 2); // QUOTE + NULL
2959 * make quoted string
2960 * Quoted-string = <Octet 34> *TEXT End-of-string
2962 * @param source [in] original string
2963 * @param length [in] length (in bytes) of data
2964 * @param dest [out] buffer to store quted string
2965 * @return changed string length
2967 static bool MmsBinaryEncodeQuotedString(FILE *pFile, UINT8 *source, int length)
2969 if (source == NULL || pFile == NULL) {
2970 MSG_DEBUG("MmsBinaryEncodeQuotedString: invalid file\n");
2974 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
2975 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
2976 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
2977 MSG_DEBUG("MmsBinaryEncodeQuotedString: MsgWriteDataFromEncodeBuffer fail \n");
2982 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = '\"';
2983 strncpy(gpMmsEncodeBuf + gCurMmsEncodeBuffPos, (char*)source, length - 2); // except '\"' & NULL
2984 gCurMmsEncodeBuffPos += (length - 2);
2985 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)NULL;
2995 static int MmsBinaryEncodeEncodedStringLen(UINT8 *source)
2997 UINT32 charset = 0x6A; // default = utf-8
3000 int valueLengthLen = 0;
3003 MSG_DEBUG("MmsBinaryEncodeEncodedStringLen: \n");
3005 /* value-length charSet text-string */
3006 /* Estimate charset value length and text string length */
3007 charLeng = MmsBinaryEncodeIntegerLen(charset);
3008 if (charLeng == -1) {
3009 MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : charLeng MmsBinaryEncodeTextStringLen fail.\n");
3013 textLeng = MmsBinaryEncodeTextStringLen((UINT8*)source);
3014 if (textLeng == -1) {
3015 MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : textLeng MmsBinaryEncodeTextStringLen fail.\n");
3019 valueLengthLen = MmsBinaryEncodeValueLengthLen(charLeng + textLeng);
3020 if (valueLengthLen == -1) {
3021 MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : valLengthLen MmsBinaryEncodeTextStringLen fail.\n");
3025 return (charLeng + textLeng + valueLengthLen);
3033 * This makes value-length by specified integer value
3035 * @param length [in] from MmsBinaryEncodeEncodedStringLen()
3036 * @return encoded encoded-string
3038 static bool MmsBinaryEncodeEncodedString(FILE *pFile, UINT8 *source, int length)
3040 UINT32 charset = 0x6A; // default = utf-8
3043 int valLengthLen = 0;
3046 MSG_DEBUG("MmsBinaryEncodeEncodedString: \n");
3048 /* value-length charSet text-string */
3050 if (pFile == NULL || source == NULL) {
3051 MSG_DEBUG("MmsBinaryEncodeEncodedString: invalid input parameter\n");
3055 /* Estimate charset value length and text string length */
3056 charLeng = MmsBinaryEncodeIntegerLen(charset);
3057 if (charLeng == -1) {
3058 MSG_DEBUG("MmsBinaryEncodeEncodedString : charLeng MmsBinaryEncodeTextStringLen fail.\n");
3062 textLeng = MmsBinaryEncodeTextStringLen((UINT8*)source);
3063 if (textLeng == -1) {
3064 MSG_DEBUG("MmsBinaryEncodeEncodedString : textLeng MmsBinaryEncodeTextStringLen fail.\n");
3068 valLengthLen = MmsBinaryEncodeValueLengthLen(charLeng + textLeng);
3069 if (valLengthLen == -1) {
3070 MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeValueLengthLen fail.\n");
3074 if (length != (charLeng + textLeng + valLengthLen))
3076 MSG_DEBUG("MmsBinaryEncodeEncodedString: invalid length\n");
3080 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
3081 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3082 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3083 MSG_DEBUG("MmsBinaryEncodeEncodedString: MsgWriteDataFromEncodeBuffer fail \n");
3088 /* Value length of charset value and text string */
3089 if (MmsBinaryEncodeValueLength(pFile, charLeng + textLeng, valLengthLen) == false) {
3090 MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeValueLength fail.\n");
3094 /* fixme: Write charset on buffer -> integer value not long-integer */
3095 if (MmsBinaryEncodeInteger(pFile, charset, charLeng) == false) {
3096 MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeInteger fail.\n");
3101 /* Write text string on buffer */
3102 if (MmsBinaryEncodeTextString(pFile, (UINT8*)source, textLeng) == false) {
3103 MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeTextString fail.\n");
3114 static bool __MmsBinaryEncodeFieldCodeAndValue(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue)
3116 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 2) {
3117 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3118 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3119 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: MsgWriteDataFromEncodeBuffer fail \n");
3124 if (fieldCode == 0xff) {
3125 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldCode \n");
3129 if (fieldValue == 0xff) {
3130 MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldValue \n");
3134 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
3135 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldValue;
3145 static bool __MmsBinaryEncodeTrID(FILE *pFile, char *szTrID, int bufLen)
3148 UINT8 fieldCode = 0xff;
3149 char szBuff[MMS_TR_ID_LEN + 1] = {0, };
3150 struct tm *dateTime = NULL;
3155 dateTime = localtime(&RawTime);
3156 dateSec = mktime(dateTime);
3159 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
3160 if (fieldCode == 0xff) {
3161 MSG_DEBUG("__MmsBinaryEncodeTrID: invalid fieldCode \n");
3165 snprintf(szBuff, MMS_TR_ID_LEN + 1, "%lu.%lu", dateSec, (unsigned long)random());
3166 MSG_DEBUG("__MmsBinaryEncodeTrID: 2. szBuff = %s\n", szBuff);
3168 length = MmsBinaryEncodeTextStringLen((UINT8*)szBuff);
3170 MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextStringLen fail \n");
3174 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
3175 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3176 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3177 MSG_DEBUG("__MmsBinaryEncodeTrID: MsgWriteDataFromEncodeBuffer fail \n");
3183 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
3184 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szBuff, length) == false) {
3185 MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextString fail\n");
3190 memset(szTrID, 0, bufLen);
3191 strncpy(szTrID, szBuff, bufLen - 1);
3201 static bool __MmsBinaryEncodeMsgID(FILE *pFile, const char *szMsgID)
3204 UINT8 fieldCode = 0xff;
3206 fieldCode = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGID) | 0x80;
3207 if (fieldCode == 0xff) {
3208 MSG_DEBUG("__MmsBinaryEncodeTrID: invalid fieldCode \n");
3212 MSG_DEBUG("__MmsBinaryEncodeMsgID: 2. szBuff = %s\n", szMsgID);
3214 length = MmsBinaryEncodeTextStringLen((UINT8*)szMsgID);
3216 MSG_DEBUG("__MmsBinaryEncodeMsgID: MmsBinaryEncodeTextStringLen fail \n");
3220 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
3221 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3222 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3223 MSG_DEBUG("__MmsBinaryEncodeTrID: MsgWriteDataFromEncodeBuffer fail \n");
3228 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
3229 if (MmsBinaryEncodeTextString(pFile, (UINT8*)szMsgID, length) == false) {
3230 MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextString fail\n");
3243 static bool __MmsBinaryEncodeMmsVersion(FILE *pFile)
3245 UINT8 majorVer = MMS_MAJOR_VERSION;
3246 UINT8 minorVer = MMS_MINOR_VERSION;
3248 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: \n");
3250 if (pFile == NULL) {
3251 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: invalid input file \n");
3255 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 2) {
3256 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3257 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3258 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: MsgWriteDataFromEncodeBuffer fail \n");
3263 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_VERSION) | 0x80;
3265 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: major version (%d)\n", majorVer);
3266 MSG_DEBUG("__MmsBinaryEncodeMmsVersion: minor version (%d)\n", minorVer);
3268 gpMmsEncodeBuf[gCurMmsEncodeBuffPos] = (majorVer << 4) | (minorVer & 0x0f) | MSB;
3270 if (gpMmsEncodeBuf[gCurMmsEncodeBuffPos] < 0x80) {
3271 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] |= 0x80;
3273 gCurMmsEncodeBuffPos++;
3284 static bool __MmsBinaryEncodeDate(FILE *pFile)
3286 struct tm *dateTime = NULL;
3289 dateSec = time(NULL);
3290 dateTime = localtime(&dateSec);
3292 MSG_DEBUG("%d - %d - %d, %d : %d (SYSTEM)", dateTime->tm_year + 1900, dateTime->tm_mon + 1, dateTime->tm_mday
3293 , dateTime->tm_hour, dateTime->tm_min);
3297 length = MmsBinaryEncodeLongIntegerLen(dateSec);
3299 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) { // + fieldCode
3300 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3301 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3302 MSG_DEBUG("__MmsBinaryEncodeDate: MsgWriteDataFromEncodeBuffer fail \n");
3307 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DATE) | 0x80;
3309 if (MmsBinaryEncodeLongInteger(pFile, dateSec, length) == false) {
3310 MSG_DEBUG("__MmsBinaryEncodeDate: date MmsBinaryEncodeLongInteger error\n");
3314 MSG_DEBUG("__MmsBinaryEncodeDate: date has a negative value (%d) \n", dateSec);
3325 static bool __MmsBinaryEncodeFrom(FILE *pFile)
3327 if (pFile == NULL) {
3328 MSG_DEBUG("__MmsBinaryEncodeFrom: invalid input file \n");
3332 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 3) {
3333 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3334 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3335 MSG_DEBUG("__MmsBinaryEncodeFrom: MsgWriteDataFromEncodeBuffer fail \n");
3340 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_FROM) | 0x80;
3341 /* length of MMS_INSERT_ADDRESS_TOKEN value */
3342 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = 0x01;
3343 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeAddressType, MMS_INSERT_ADDRESS_TOKEN) | 0x80;
3351 static bool __MmsBinaryEncodeOneAddress(FILE *pFile, MmsFieldCode addrType, char *szAddrStr)
3355 if (pFile == NULL) {
3356 MSG_DEBUG("__MmsBinaryEncodeOneAddress: invalid input file \n");
3361 length = MmsBinaryEncodeEncodedStringLen((UINT8*)szAddrStr);
3364 MSG_DEBUG("__MmsBinaryEncodeOneAddress: MmsBinaryEncodeEncodedStringLen fail \n");
3368 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
3369 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3370 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3371 MSG_DEBUG("__MmsBinaryEncodeOneAddress: MsgWriteDataFromEncodeBuffer fail \n");
3376 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, addrType) | 0x80;
3379 if (MmsBinaryEncodeEncodedString(pFile, (UINT8*)szAddrStr, length) == false) {
3380 MSG_DEBUG("__MmsBinaryEncodeOneAddress: MmsBinaryEncodeEncodedString fail \n");
3391 static bool __MmsBinaryEncodeAddress(FILE *pFile, MmsFieldCode addrType, char *szAddr)
3393 char *pSingleAddr = NULL;
3396 if (pFile == NULL) {
3397 MSG_DEBUG("__MmsBinaryEncodeAddress: invalid input file \n");
3401 while (szAddr && szAddr[0]) {
3402 szAddr = _MsgSkipWS3(szAddr);
3406 pSingleAddr = strchr(szAddr, MSG_CH_SEMICOLON);
3409 *pSingleAddr = MSG_CH_NULL;
3410 if (__MmsBinaryEncodeOneAddress(pFile, addrType, szAddr) == false) {
3411 MSG_DEBUG("__MmsBinaryEncodeAddress: __MmsBinaryEncodeAddress fail\n");
3414 *pSingleAddr = MSG_CH_SEMICOLON;
3416 szAddr = pSingleAddr + 1;
3419 if (__MmsBinaryEncodeOneAddress(pFile, addrType, szAddr) == false) {
3420 MSG_DEBUG("__MmsBinaryEncodeAddress: __MmsBinaryEncodeAddress fail\n");
3436 static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeStruct time)
3441 if (pFile == NULL) {
3442 MSG_DEBUG("__MmsBinaryEncodeTime: invalid input file \n");
3446 if (time.time == 0 ||
3447 (fieldCode != MMS_CODE_EXPIRYTIME && fieldCode != MMS_CODE_DELIVERYTIME && fieldCode != MMS_CODE_REPLYCHARGINGDEADLINE) ||
3448 (time.type != MMS_TIMETYPE_ABSOLUTE && time.type != MMS_TIMETYPE_RELATIVE)) {
3449 MSG_DEBUG("__MmsBinaryEncodeTime: time.type = %d \n", time.type);
3454 * use temporary buffer to estimate value length
3455 * and copy it to pData buffer later.
3458 if (time.type == MMS_TIMETYPE_RELATIVE) {
3459 timeLen = MmsBinaryEncodeIntegerLen(time.time);
3461 timeLen = MmsBinaryEncodeLongIntegerLen(time.time);
3465 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongIntegerLen fail \n");
3469 length = MmsBinaryEncodeValueLengthLen(timeLen + 1); //time length + time type token
3471 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeValueLengthLen fail \n");
3475 if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + timeLen + 2)) { // + fieldCode + timeType
3477 if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
3478 gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
3479 MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
3485 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeFieldCode, fieldCode) | 0x80;
3488 if (MmsBinaryEncodeValueLength(pFile, timeLen + 1, length) == false) {
3489 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeValueLength fail \n");
3493 /* time type & value */
3494 if (time.type == MMS_TIMETYPE_RELATIVE) {
3495 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_RELATIVE) | 0x80;
3496 if (MmsBinaryEncodeInteger(pFile, time.time, timeLen) == false) {
3497 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongInteger fail \n");
3501 gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = _MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE) | 0x80;
3502 if (MmsBinaryEncodeLongInteger(pFile, time.time, timeLen) == false) {
3503 MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongInteger fail \n");