• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved
4  * Licensed under the Apache License, Version 2.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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #ifndef MSG_TEXT_CONVERT_H
18 #define MSG_TEXT_CONVERT_H
19 
20 #include <map>
21 #include <memory>
22 
23 #include "gsm_pdu_code_type.h"
24 #include "msg_text_convert_common.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 #define IN
29 #define OUT
30 
31 class MsgTextConvert {
32 public:
33     static MsgTextConvert *Instance();
34     int ConvertUTF8ToGSM7bit(std::tuple<unsigned char *, int, unsigned char *, int,
35         MSG_LANGUAGE_ID_T *, bool *> &parameters);
36     int ConvertUTF8ToUCS2(
37         OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen);
38     int ConvertCdmaUTF8ToAuto(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText,
39         IN int srcTextLen, OUT SmsCodingScheme *pCharType);
40     int ConvertGsmUTF8ToAuto(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText,
41         IN int srcTextLen, OUT SmsCodingScheme *pCharType);
42     int ConvertGSM7bitToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText,
43         IN int srcTextLen, const IN MsgLangInfo *pLangInfo);
44     int ConvertUCS2ToUTF8(
45         OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen);
46     int ConvertEUCKRToUTF8(
47         OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen);
48     int ConvertSHIFTJISToUTF8(
49         OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen) const;
50 
51     void Base64Encode(const std::string &src, std::string &dest);
52     void Base64Decode(const std::string &src, std::string &dest);
53     bool GetEncodeString(
54         std::string &encodeString, uint32_t charset, uint32_t valLength, const std::string &strEncodeString);
55 
56 private:
57     MsgTextConvert();
58     virtual ~MsgTextConvert();
59     int ConvertUCS2ToGSM7bit(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText,
60         IN int srcTextLen, OUT MSG_LANGUAGE_ID_T *pLangId, OUT bool *abnormalChar);
61     int ConvertUCS2ToGSM7bitAuto(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText,
62         IN int srcTextLen, OUT bool *pUnknown);
63     int ConvertUCS2ToASCII(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText,
64         IN int srcTextLen, OUT bool *pUnknown);
65     unsigned char GetLangType(const unsigned char *pSrcText, int srcTextLen);
66     int FindUCS2toGSM7Ext(unsigned char *pDestText, int maxLength, const unsigned short inText, bool &abnormalChar);
67     int FindUCS2toTurkish(unsigned char *pDestText, int maxLength, const unsigned short inText, bool &abnormalChar);
68     int FindUCS2toSpanish(unsigned char *pDestText, int maxLength, const unsigned short inText, bool &abnormalChar);
69     int FindUCS2toPortu(unsigned char *pDestText, int maxLength, const unsigned short inText, bool &abnormalChar);
70     unsigned char FindUCS2ReplaceChar(const unsigned short inText);
71 
72     int ConvertGSM7bitToUCS2(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText,
73         IN int srcTextLen, const IN MsgLangInfo *pLangInfo);
74     void ConvertDumpTextToHex(const unsigned char *pText, int length);
75     int EscapeTurkishLockingToUCS2(
76         const unsigned char *pSrcText, int srcLen, const MsgLangInfo &pLangInfo, unsigned short &result);
77     int EscapePortuLockingToUCS2(
78         const unsigned char *pSrcText, int srcLen, const MsgLangInfo &pLangInfo, unsigned short &result);
79     int EscapeGSM7BitToUCS2(
80         const unsigned char *pSrcText, int srcLen, const MsgLangInfo &pLangInfo, unsigned short &result);
81     unsigned short EscapeToUCS2(const unsigned char srcText, const MsgLangInfo &pLangInfo);
82 
83     void GetTurkishSingleToUCS2(const unsigned char &srcText, unsigned short &result);
84     void GetSpanishSingleToUCS2(const unsigned char &srcText, unsigned short &result);
85     void GetGsm7BitExtToUCS2(const unsigned char &srcText, unsigned short &result);
86     void GetPortuSingleToUCS2(const unsigned char &srcText, unsigned short &result);
87 
88     void InitExtCharMap();
89     void InitUCS2ToGSM7DefMap();
90     void InitUCS2ToExtMap();
91     void InitUCS2ToTurkishMap();
92     void InitUCS2ToSpanishMap();
93     void InitUCS2ToPortuMap();
94     void InitUCS2ToReplaceCharMap();
95 
96 private:
97     static std::shared_ptr<MsgTextConvert> instance_;
98     std::map<unsigned short, unsigned char> extCharMap_;
99     std::map<unsigned short, unsigned char> ucs2toGSM7DefMap_;
100     std::map<unsigned short, unsigned char> ucs2toGSM7ExtMap_;
101     std::map<unsigned short, unsigned char> ucs2toTurkishMap_;
102     std::map<unsigned short, unsigned char> ucs2toSpanishMap_;
103     std::map<unsigned short, unsigned char> ucs2toPortuMap_;
104     std::map<unsigned short, unsigned char> replaceCharMap_;
105 };
106 } // namespace Telephony
107 } // namespace OHOS
108 #endif