• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SMS_WAP_PUSH_BUFFER_H
17 #define SMS_WAP_PUSH_BUFFER_H
18 
19 #include <string>
20 #include <memory>
21 
22 namespace OHOS {
23 namespace Telephony {
24 class SmsWapPushBuffer {
25 public:
26     SmsWapPushBuffer();
27     virtual ~SmsWapPushBuffer();
28 
29     virtual std::unique_ptr<char[]> ReadDataBuffer(uint32_t desLen);
30     virtual std::unique_ptr<char[]> ReadDataBuffer(uint32_t offset, uint32_t desLen);
31     virtual bool WriteRawStringBuffer(const std::string &inSrc);
32     virtual bool WriteDataBuffer(std::unique_ptr<char[]> inBuff, uint32_t len);
33     virtual uint32_t GetCurPosition() const;
34     virtual uint32_t GetSize() const;
35 
36     bool PeekOneByte(uint8_t &oneByte);
37     bool GetOneByte(uint8_t &oneByte);
38     bool IncreasePointer(uint32_t offset);
39     bool DecreasePointer(uint32_t offset);
40     void MarkPosition();
41     void UnMarkPosition();
42 
43     bool DecodeIsString();
44     bool DecodeShortLength(uint8_t &sValueLength);
45     bool DecodeValueLengthReturnLen(uint32_t &valueLength, uint32_t &length);
46     bool DecodeValueLength(uint32_t &valueLength);
47     bool DecodeUintvar(uint32_t &uintVar, uint32_t &count);
48     bool DecodeText(std::string &str, uint32_t &len);
49     static bool CharIsToken(uint8_t oneByte);
50     bool DecodeTokenText(std::string &str, uint32_t &len);
51     bool DecodeQuotedText(std::string &str, uint32_t &len);
52     bool DecodeShortInteger(uint8_t &sInteger);
53     bool DecodeIsShortInt();
54     bool DecodeLongInteger(uint64_t &lInteger);
55     bool DecodeInteger(uint64_t &iInteger);
56     bool DecodeIsValueLength();
57     bool DecodeExtensionMedia();
58     bool DecodeConstrainedEncoding();
59     bool DecodeTextValue(std::string &str, bool &isNoValue);
60     bool DecodeNoValue(bool &isNoValue);
61 
62 private:
63     std::unique_ptr<char[]> pduBuffer_;
64     uint32_t curPosition_ = 0;
65     uint32_t totolLength_ = 0;
66     uint32_t savePosition_ = 0;
67 
68 private:
69     const uint32_t CODE_BUFFER_MAX_SIZE = 300 * 1024;
70     static constexpr uint8_t EDN_S = 0;
71     static constexpr uint8_t NARMAL_TEXT_MIN = 32;
72     static constexpr uint8_t NARMAL_TEXT_MAX = 126;
73     static constexpr uint8_t LONG_VALUE_LEN_MAX = 8;
74 };
75 } // namespace Telephony
76 } // namespace OHOS
77 #endif
78