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 <memory> 20 #include <set> 21 #include <string> 22 23 namespace OHOS { 24 namespace Telephony { 25 class SmsWapPushBuffer { 26 public: 27 SmsWapPushBuffer(); 28 virtual ~SmsWapPushBuffer(); 29 30 virtual std::unique_ptr<char[]> ReadDataBuffer(uint32_t desLen); 31 virtual std::unique_ptr<char[]> ReadDataBuffer(uint32_t offset, uint32_t desLen); 32 virtual bool WriteRawStringBuffer(const std::string &inSrc); 33 virtual bool WriteDataBuffer(std::unique_ptr<char[]> inBuff, uint32_t len); 34 virtual uint32_t GetCurPosition() const; 35 virtual uint32_t GetSize() const; 36 37 bool PeekOneByte(uint8_t &oneByte); 38 bool GetOneByte(uint8_t &oneByte); 39 bool IncreasePointer(uint32_t offset); 40 bool DecreasePointer(uint32_t offset); 41 void MarkPosition(); 42 void UnMarkPosition(); 43 44 bool DecodeIsString(); 45 bool DecodeShortLength(uint8_t &sValueLength); 46 bool DecodeValueLengthReturnLen(uint32_t &valueLength, uint32_t &length); 47 bool DecodeValueLength(uint32_t &valueLength); 48 bool DecodeUintvar(uint32_t &uintVar, uint32_t &count); 49 bool DecodeText(std::string &str, uint32_t &len); 50 static bool CharIsToken(uint8_t oneByte); 51 bool DecodeTokenText(std::string &str, uint32_t &len); 52 bool DecodeQuotedText(std::string &str, uint32_t &len); 53 bool DecodeShortInteger(uint8_t &sInteger); 54 bool DecodeIsShortInt(); 55 bool DecodeLongInteger(uint64_t &lInteger); 56 bool DecodeInteger(uint64_t &iInteger); 57 bool DecodeIsValueLength(); 58 bool DecodeExtensionMedia(); 59 bool DecodeConstrainedEncoding(); 60 bool DecodeTextValue(std::string &str, bool &isNoValue); 61 bool DecodeNoValue(bool &isNoValue); 62 63 private: 64 std::unique_ptr<char[]> pduBuffer_; 65 uint32_t curPosition_ = 0; 66 uint32_t totolLength_ = 0; 67 uint32_t savePosition_ = 0; 68 69 private: 70 const uint32_t CODE_BUFFER_MAX_SIZE = 300 * 1024; 71 static constexpr uint8_t EDN_S = 0; 72 static constexpr uint8_t NARMAL_TEXT_MIN = 32; 73 static constexpr uint8_t NARMAL_TEXT_MAX = 126; 74 static constexpr uint8_t LONG_VALUE_LEN_MAX = 8; 75 }; 76 } // namespace Telephony 77 } // namespace OHOS 78 #endif 79