3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
34 #include "MmsPluginCodec.h"
35 #include "MmsPluginCodec.h"
36 #include "MmsPluginMIME.h"
37 #include "MmsPluginMessage.h"
38 #include "MmsPluginWmLngPack.h"
40 const int MSG_MAX_CH_PER_LINE = 75;
42 /* ==================================================================
43 * Decode/Encode inline base64 string
45 * base64 : 3*8bit -> 4*6bit & convert the value into A~Z, a~z, 0~9, +, or /
46 * pad(=) is needed when the end of the string is < 24bit.
48 * Value Encoding Value Encoding Value Encoding Value Encoding
50 * 1 B 18 S 35 j 52 '0'
63 * 14 O 31 f 48 w (pad) =
67 * (1) the final quantum = 24 bits : no "=" padding,
68 * (2) the final quantum = 8 bits : two "=" + two characters
69 * (3) the final quantum = 16 bits : one "=" + three characters
70 * ================================================================== */
72 bool _MsgEncodeBase64(void *pSrc, unsigned long srcLen, unsigned long *len, unsigned char *ret)
74 unsigned char *d = NULL;
75 unsigned char *s = (unsigned char *)pSrc;
77 char *v = (char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
78 unsigned long i = ((srcLen + 2) / 3) * 4;
80 i += 2 * ((i / 60) + 1);
84 MSG_DEBUG("_MsgEncodeBase64: ret Memory Alloc Fail \n");
91 /* Convert 3*8bit into 4*6bit */
92 for (i = 0; srcLen > 0; s += 3) {
93 *d++ = v[s[0] >> 2]; // byte 1: high 6 bits of character-1
94 *d++ = v[((s[0] << 4) + (--srcLen ? (s[1] >> 4) : 0)) & 0x3f]; // byte 2: low 2 bits of character-1 and high 4 bits of character-2
95 *d++ = srcLen ? v[((s[1] << 2) + (--srcLen ? (s[2] >> 6) : 0)) & 0x3f] : '='; // byte 3: low 4 bits of charcter-2 and high 2 bits of character-3
96 *d++ = srcLen ? v[s[2] & 0x3f] : '='; // byte 4: low 6 bits of character-3
101 /* Insert CRLF at every 60 characters */
115 if (((unsigned long)(d - ret)) != *len) {
117 MSG_DEBUG("base64 encoding length = %d \n", *len);
124 void *_MsgDecodeBase64(unsigned char *pSrc, unsigned long srcLen, unsigned long *len)
131 ret = malloc((size_t)(*len = 4 + ((srcLen * 3) / 4)));
135 MSG_DEBUG("_MsgDecodeBase64: ret malloc Fail \n");
139 memset(ret, 0, (size_t)*len);
142 while (srcLen-- > 0) {
145 /* Convert base64 character into original value */
161 *len = d - (char *)ret;
169 *len = d - (char *)ret;
174 continue; // Actually, never get here
176 /* Pad 4*6bit character into 3*8bit character */
180 *d = c << 2; // byte 1: high 6 bits
184 *d++ |= c >> 4; // byte 1: low 2 bits
185 *d = c << 4; // byte 2: high 4 bits
189 *d++ |= c >> 2; // byte 2: low 4 bits
190 *d = c << 6; // byte 3: high 2 bits
194 *d++ |= c; // byte 3: low 6 bits
195 e = 0; // Calculate next unit.
199 MSG_DEBUG("_MsgDecodeBase64: Unknown paremeter\n");
204 *len = d - (char *)ret; // Calculate the size of decoded string.
211 /* ==========================================
212 * Decode/Encode inline base64 string
214 * quoted-printable := ([*(ptext / SPACE / TAB) ptext] ["="] CRLF)
215 * ; Maximum line length of 76 characters excluding CRLF
217 * ptext := octet /<any ASCII character except "=", SPACE, or TAB>
218 * ; characters not listed as "mail-safe" in Appendix B
219 * ; are also not recommended.
221 * octet := "=" 2(DIGIT / "A" / "B" / "C" / "D" / "E" / "F")
222 * ; octet must be used for characters > 127, =, SPACE, or TAB.
224 * ==========================================*/
226 bool _MsgEncodeQuotePrintable(unsigned char *pSrc, unsigned long srcLen, unsigned long *len, unsigned char *ret)
228 unsigned long lp = 0;
229 unsigned char *d = ret;
230 char *hex = (char *)"0123456789ABCDEF";
234 MSG_DEBUG("_MsgEncodeQuotePrintable: ret malloc Fail \n");
241 * The type of srcLen is unsigned long
242 * The value of srcLen is decreased by 1 -> We can't check by "srcLen > 0".
244 while (srcLen-- > 0) {
246 if (((c = *pSrc++) == '\015') && (*pSrc == '\012') && srcLen) {
252 if (iscntrl(c) || (c == 0x7f) || (c & 0x80) || (c == '=') || ((c == ' ') && (*pSrc == '\015'))) {
253 if ((lp += 3) > (unsigned long)MSG_MAX_CH_PER_LINE) {
260 *d++ = '='; /* quote character */
261 *d++ = hex[c >> 4]; /* high order 4 bits */
262 *d++ = hex[c & 0xf]; /* low order 4 bits */
264 /* Just copy ASCII character */
265 if ((++lp) > (unsigned long)MSG_MAX_CH_PER_LINE) {
283 unsigned char *_MsgDecodeQuotePrintable(unsigned char *pSrc, unsigned long srcLen, unsigned long *len)
285 unsigned char *ret = NULL;
286 unsigned char *d = NULL;
287 unsigned char *s = NULL; /* last non-blank */
291 d = s = ret = (unsigned char *)malloc((size_t)srcLen + 1);
293 MSG_DEBUG("_MsgDecodeQuotePrintable: ret malloc Fail \n");
300 while ((c = *pSrc++)!= '\0') {
302 case '=': /* octet characters (> 127, =, SPACE, or TAB) */
303 switch (c = *pSrc++) {
304 case '\0': /* end of string -> postpone to while */
307 case '\015': /* CRLF */
312 default: /* two hexes */
322 e = c - (isupper(c) ? 'A' - 10 : 'a' - 10);
334 c -= (isupper(c) ? 'A' - 10 : 'a' - 10);
342 case ' ': /* skip the blank */
346 case '\015': /* Line Feedback : to last non-blank character */
351 *d++ = c; /* ASCII character */
364 /* ========================================
365 * Decode/Encode inline base64 string
366 * Inline base64 has no "\r\n" in it,
367 * and has charset and encoding sign in it
368 * ======================================== */
369 bool _MsgEncode2Base64(void *pSrc, unsigned long srcLen, unsigned long *len, unsigned char *ret)
371 unsigned char *d = NULL;
372 unsigned char *s = (unsigned char *)pSrc;
373 char *v = (char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
374 unsigned long i = ((srcLen + 2) / 3) * 4;
376 i += 2 * ((i / 60) + 1);
380 MSG_DEBUG("_MsgEncode2Base64: ret Memory Alloc Fail \n");
387 /* Convert 3*8bit into 4*6bit */
388 for (i = 0; srcLen > 0; s += 3) {
389 *d++ = v[s[0] >> 2]; // byte 1: high 6 bits of character-1
390 *d++ = v[((s[0] << 4) + (--srcLen ? (s[1] >> 4) : 0)) & 0x3f]; // byte 2: low 2 bits of character-1 and high 4 bits of character-2
391 *d++ = srcLen ? v[((s[1] << 2) + (--srcLen ? (s[2] >> 6) : 0)) & 0x3f] : '='; // byte 3: low 4 bits of charcter-2 and high 2 bits of character-3
392 *d++ = srcLen ? v[s[2] & 0x3f] : '='; // byte 4: low 6 bits of character-3
400 if (((unsigned long)(d - ret)) != *len) {
402 MSG_DEBUG("base64 encoding length = %d \n", *len);
409 char *_MsgDecodeText(char *pOri)
418 char *pStrEnd = NULL;
419 char *pDecStart = NULL;
420 char *pDecEnd = NULL;
423 bool bEncoding = false;
424 int nCharset = MSG_CHARSET_UTF8;
428 char *pReturnStr = NULL;
429 char *pConvertedStr = NULL;
430 MCHAR *mszTempStr = NULL;
432 MCHAR *pmszOutTextStr = NULL;
434 char szTempBuf[MSG_LOCAL_TEMP_BUF_SIZE] = {0};
436 // copy original string
437 if (strlen(pOri) >= MSG_LOCAL_TEMP_BUF_SIZE) {
438 pSrc = MsgStrCopy( pOri );
440 memset(szTempBuf, 0, MSG_LOCAL_TEMP_BUF_SIZE);
441 strcpy(szTempBuf, pOri);
446 // it can be one or more encoding methods in a line
453 (ex) "=?euc-kr?B?Y2NqMjEyMw==?="
455 pDecStart: charset (=?euc-kr?B?Y2NqMjEyMw==?=)
456 pDecQ : Encoding type (B?Y2NqMjEyMw==?=)
457 pDecQ2 : Encoded text (Y2NqMjEyMw==?=)
458 pDecEnd : Encoded of text (?=)
463 if (((pDecStart = strstr(pSrc, MSG_STR_DEC_START)) != NULL) //"=?"
464 && ((pDecQ = strchr(pDecStart + 2, MSG_CH_QUESTION)) != NULL) // '?'
465 && ((pDecQ2 = strchr(pDecQ + 1, MSG_CH_QUESTION))!= NULL) // '?'
466 && ((pDecEnd = strstr(pDecQ2 + 1, MSG_STR_DEC_END))!= NULL)) { //"=?"
469 /* fixme: charset problem
470 * pDecStart ~ pDecQ : charSet & MSG_CHARSET_USC2 ~ MSG_CHARSET_UTF8 & LATIN
474 nCharset = _MsgGetCode(MSG_CHARSET, pDecStart + 2);
475 *pDecQ = MSG_CH_QUESTION;
482 // find end of string
483 pStrEnd = pSrc + strlen(pSrc);
486 if ((*(pDecQ2 - 1) == MSG_CH_BASE64_UPPER) ||
487 (*(pDecQ2 - 1) == MSG_CH_BASE64_LOWER) ||
488 (*(pDecQ + 1) == MSG_CH_BASE64_UPPER) ||
489 (*(pDecQ + 1) == MSG_CH_BASE64_LOWER)) {
490 pTemp = (char *)_MsgDecodeBase64((UCHAR *)(pDecQ2 + 1), (ULONG)(pDecEnd - pDecQ2 - 1), (ULONG *)&size);
493 pTemp[size] = MSG_CH_NULL;
500 pRe = (char *)malloc((pDecStart-pSrc) + size + (pStrEnd - (pDecEnd + 2)) + 1);
502 MSG_DEBUG("_MsgDecodeText: pRemalloc fail \n");
509 memcpy(pRe, pSrc, pDecStart - pSrc);
510 memcpy(&pRe[pDecStart-pSrc], pTemp, size);
511 memcpy(&pRe[(pDecStart - pSrc) + size], pDecEnd + 2, pStrEnd - (pDecEnd + 2));
512 pRe[(pDecStart - pSrc) + size + (pStrEnd - (pDecEnd + 2))] = MSG_CH_NULL;
517 if (pSrc != NULL && pSrc != szTempBuf) {
522 } else if ((*(pDecQ2-1) == MSG_CH_QPRINT_UPPER) ||
523 (*(pDecQ2-1) == MSG_CH_QPRINT_LOWER) ||
524 (*(pDecQ+1) == MSG_CH_QPRINT_UPPER) ||
525 (*(pDecQ+1) == MSG_CH_QPRINT_LOWER)) {
527 pTemp = (char *)_MsgDecodeQuotePrintable((UCHAR *)( pDecQ2 + 1 ), (ULONG)(pDecEnd - pDecQ2 - 1), (ULONG *)&size);
531 pTemp[size] = MSG_CH_NULL;
533 for (i = 0; i < size; i++) {
534 if (pTemp[i] == MSG_CH_UNDERLINE) {
535 pTemp[i] = MSG_CH_SP; // change '_' to ' '
544 pRe = (char *)malloc((pDecStart - pSrc) + size + (pStrEnd - (pDecEnd + 2)) + 1);
546 MSG_DEBUG("_MsgDecodeText: pRemalloc fail \n");
553 memcpy(pRe, pSrc, pDecStart - pSrc);
554 memcpy(&pRe[pDecStart - pSrc], pTemp, size);
555 memcpy(&pRe[(pDecStart - pSrc) + size], pDecEnd + 2, pStrEnd - (pDecEnd + 2));
556 pRe[(pDecStart - pSrc) + size + (pStrEnd - (pDecEnd + 2))] = MSG_CH_NULL;
563 if (pSrc != NULL && pSrc != szTempBuf) {
576 nTemp = strlen(pSrc);
579 case MSG_CHARSET_UTF16:
580 case MSG_CHARSET_USC2:
582 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_USC2 \n");
585 // mmf file name display patch
586 if (((UINT8)pTemp[0] == 0xFF && (UINT8)pTemp[1] == 0xFE) || ((UINT8)pTemp[0] == 0xFE && (UINT8)pTemp[1] == 0xFF)) {
588 nChar = (nTemp / 2 - 1);
591 if (MsgIsUTF8String((unsigned char *)pTemp + 2, nTemp - 2)) {
592 strncpy(pTemp, pTemp + 2, strlen(pTemp + 2));
594 MSG_DEBUG("_MsgDecodeText: real char-set = MSG_CHARSET_UTF8.\n");
598 mszTempStr = (unsigned short *)malloc(nChar * sizeof(unsigned short));
599 if (mszTempStr == NULL) {
600 MSG_DEBUG("_MsgDecodeText: 1. Memory Full !!! \n");
604 memcpy(mszTempStr, ((unsigned short *)pTemp + 1), nChar * sizeof(unsigned short));
606 nByte = MsgGetUnicode2UTFCodeSize(((unsigned short *)pTemp + 1), nChar);
608 pConvertedStr = (char *)malloc(nByte + 1);
610 MsgUnicode2UTF ((unsigned char *)pConvertedStr, nByte + 1, mszTempStr, nChar);
620 if (MsgIsUTF8String((unsigned char *)pTemp, nTemp)) {
621 MSG_DEBUG("_MsgDecodeText: real char-set = MSG_CHARSET_UTF8.\n");
625 mszTempStr = (unsigned short *)malloc(nChar * sizeof(unsigned short));
626 if (mszTempStr == NULL) {
627 MSG_DEBUG("_MsgDecodeText: 2. Memory Full !!! \n");
631 memcpy(mszTempStr, ((unsigned short *)pTemp), nChar * sizeof(unsigned short));
633 nByte = MsgGetUnicode2UTFCodeSize(((unsigned short *)pTemp), nChar);
635 pConvertedStr = (char *)malloc(nByte + 1);
637 MsgUnicode2UTF ((unsigned char *)pConvertedStr, nByte + 1, mszTempStr, nChar);
642 pTemp = pConvertedStr;
647 case MSG_CHARSET_US_ASCII:
649 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_US_ASCII \n");
652 case MSG_CHARSET_UTF8:
654 /* UTF8 is default charset of Messenger */
656 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_UTF8 \n");
660 case MSG_CHARSET_ISO_8859_1:
662 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_1 \n");
666 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
667 if (pmszOutTextStr == NULL) {
668 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
672 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
674 WmConvertLatinCode2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
675 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
678 if (pmszOutTextStr) {
679 free(pmszOutTextStr);
680 pmszOutTextStr = NULL;
683 pTemp = pConvertedStr;
688 case MSG_CHARSET_ISO_8859_2:
690 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_2 \n");
694 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
695 if (pmszOutTextStr == NULL) {
696 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
700 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
702 WmConvertLatin2Code2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
703 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
706 if (pmszOutTextStr) {
707 free(pmszOutTextStr);
708 pmszOutTextStr = NULL;
711 pTemp = pConvertedStr;
716 case MSG_CHARSET_ISO_8859_3:
718 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_3 \n");
720 nByte = WmGetLatin32UTFCodeSize((unsigned char *)pTemp, nTemp);
722 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
723 if (pmszOutTextStr == NULL) {
724 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
728 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
730 WmConvertLatin3Code2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
731 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
734 if (pmszOutTextStr) {
735 free(pmszOutTextStr);
736 pmszOutTextStr = NULL;
739 pTemp = pConvertedStr;
744 case MSG_CHARSET_ISO_8859_4:
746 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_4 \n");
748 nByte = WmGetLatin42UTFCodeSize((unsigned char *)pTemp, nTemp);
750 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
751 if (pmszOutTextStr == NULL) {
752 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
756 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
758 WmConvertLatin4Code2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
759 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
762 if (pmszOutTextStr) {
763 free(pmszOutTextStr);
764 pmszOutTextStr = NULL;
767 pTemp = pConvertedStr;
772 case MSG_CHARSET_ISO_8859_5:
774 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_5 \n");
776 nByte = WmGetLatin52UTFCodeSize((unsigned char *)pTemp, nTemp);
778 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
779 if (pmszOutTextStr == NULL) {
780 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
784 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
786 WmConvertLatin5Code2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
787 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
790 if (pmszOutTextStr) {
791 free(pmszOutTextStr);
792 pmszOutTextStr = NULL;
795 pTemp = pConvertedStr;
800 case MSG_CHARSET_ISO_8859_7:
803 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_9 \n");
805 nByte = MsgGetLatin72UTFCodeSize((unsigned char *)pTemp, nTemp);
806 pConvertedStr = (char *)malloc( nByte + 1);
808 MsgLatin7code2UTF((unsigned char *)pConvertedStr, nByte + 1 , (unsigned char *)pTemp, nTemp);
811 pTemp = pConvertedStr;
816 case MSG_CHARSET_ISO_8859_8:
818 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_8 \n");
820 nByte = WmGetLatin82UTFCodeSize((unsigned char *)pTemp, nTemp);
822 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
823 if (pmszOutTextStr == NULL) {
824 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
828 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
830 WmConvertLatin8Code2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
831 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
834 if (pmszOutTextStr) {
835 free(pmszOutTextStr);
836 pmszOutTextStr = NULL;
839 pTemp = pConvertedStr;
844 case MSG_CHARSET_ISO_8859_9:
847 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_9 \n");
849 nByte = MsgGetLatin52UTFCodeSize((unsigned char *)pTemp, nTemp);
850 pConvertedStr = (char *)malloc(nByte + 1);
852 MsgLatin5code2UTF((unsigned char *)pConvertedStr, nByte + 1 , (unsigned char *)pTemp, nTemp);
855 pTemp = pConvertedStr;
860 case MSG_CHARSET_ISO_8859_15:
862 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_ISO_8859_15 \n");
864 nByte = WmGetLatin152UTFCodeSize((unsigned char *)pTemp, nTemp);
866 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
867 if (pmszOutTextStr == NULL) {
868 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
872 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
874 WmConvertLatin15Code2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
875 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
878 if (pmszOutTextStr) {
879 free(pmszOutTextStr);
880 pmszOutTextStr = NULL;
883 pTemp = pConvertedStr;
888 case MSG_CHARSET_WIN1251:
889 case MSG_CHARSET_WINDOW_1251:
890 case MSG_CHARSET_WINDOWS_1251:
892 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_WINDOWS_1251 \n");
896 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
897 if (pmszOutTextStr == NULL) {
898 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
902 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
904 WmConvertWin1251Code2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
905 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
908 if (pmszOutTextStr) {
909 free(pmszOutTextStr);
910 pmszOutTextStr = NULL;
913 pTemp = pConvertedStr;
918 case MSG_CHARSET_KOI8_R:
920 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_KOI8_R \n");
924 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
925 if (pmszOutTextStr == NULL) {
926 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
930 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
932 WmConvertKoi8rCode2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
933 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
936 if (pmszOutTextStr) {
937 free(pmszOutTextStr);
938 pmszOutTextStr = NULL;
941 pTemp = pConvertedStr;
946 case MSG_CHARSET_KOI8_U:
948 MSG_DEBUG("_MsgDecodeText: MSG_CHARSET_KOI8_U \n");
952 pmszOutTextStr = (unsigned short *)malloc(sizeof(MCHAR *) * (nByte + 1));
953 if (pmszOutTextStr == NULL) {
954 MSG_DEBUG("_MsgDecodeText : Out Text String null !!! \n");
958 pConvertedStr = (char *)malloc(sizeof(char *) * (nByte + 1));
960 WmConvertKoi8uCode2PCode(pmszOutTextStr, sizeof(MCHAR *) * (nByte + 1), pTemp);
961 WmConvert2LCode(pConvertedStr, sizeof(char *) * (nByte + 1), pmszOutTextStr);
964 if (pmszOutTextStr) {
965 free(pmszOutTextStr);
966 pmszOutTextStr = NULL;
969 pTemp = pConvertedStr;
976 MSG_DEBUG("_MsgDecodeText: Other charsets \n");
978 nByte = MsgGetLatin2UTFCodeSize((unsigned char *)pTemp, nTemp);
979 pConvertedStr = (char *)malloc(nByte + 1);
981 MsgLatin2UTF((unsigned char *)pConvertedStr, nByte + 1, (unsigned char *)pTemp, nTemp);
984 pTemp = pConvertedStr;
990 pReturnStr = (char *)malloc(nTemp + 1);
991 if (pReturnStr == NULL) {
994 memset(pReturnStr, 0, nTemp + 1);
997 memcpy(pReturnStr, pTemp, nTemp);
1000 free(pConvertedStr);
1001 pConvertedStr = NULL;
1014 if (pSrc != NULL && pSrc != szTempBuf) {
1023 if (pConvertedStr) {
1024 free(pConvertedStr);
1025 pConvertedStr = NULL;
1038 if (pSrc != NULL && pSrc != szTempBuf) {
1047 char *MsgEncodeText(char *pOri)
1050 char *szBuff = NULL;
1053 length = (strlen(pOri) * 4) / 3 + 2 + 12 + 1 + 30;
1054 szBuff = (char *)malloc(length + 1);
1056 if (szBuff == NULL) {
1058 MSG_DEBUG("_MsgEncodeText: szBuff alloc is failed \n");
1062 memset(szBuff, 0 , length + 1);
1064 snprintf(szBuff, length+1, "%s%s%c%c%c", MSG_STR_DEC_START, "utf-8", MSG_CH_QUESTION, MSG_CH_BASE64_LOWER, MSG_CH_QUESTION);
1066 if (_MsgEncode2Base64((unsigned char *)pOri, strlen(pOri), &nLen, (unsigned char *)szBuff + 10) == false) {
1067 MSG_DEBUG("_MsgEncodeText: MsgEncodeBase64() is failed \n");
1071 strcat(szBuff, MSG_STR_DEC_END);