1 // 2 // Copyright (C) 2015 The Android Open Source Project 3 // 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 DHCP_CLIENT_PARSER_H_ 18 #define DHCP_CLIENT_PARSER_H_ 19 20 #include <cstdint> 21 22 namespace dhcp_client { 23 24 class DHCPOptionsParser { 25 public: 26 virtual bool GetOption(const uint8_t* buffer, 27 uint8_t length, 28 void* value) = 0; ~DHCPOptionsParser()29 virtual ~DHCPOptionsParser() {} 30 }; 31 32 class UInt8Parser : public DHCPOptionsParser { 33 public: UInt8Parser()34 UInt8Parser() {} 35 bool GetOption(const uint8_t* buffer, 36 uint8_t length, 37 void* value) override; 38 }; 39 40 class UInt16Parser : public DHCPOptionsParser { 41 public: UInt16Parser()42 UInt16Parser() {} 43 bool GetOption(const uint8_t* buffer, 44 uint8_t length, 45 void* value) override; 46 }; 47 48 class UInt32Parser : public DHCPOptionsParser { 49 public: UInt32Parser()50 UInt32Parser() {} 51 bool GetOption(const uint8_t* buffer, 52 uint8_t length, 53 void* value) override; 54 }; 55 56 class UInt8ListParser : public DHCPOptionsParser { 57 public: UInt8ListParser()58 UInt8ListParser() {} 59 bool GetOption(const uint8_t* buffer, 60 uint8_t length, 61 void* value) override; 62 }; 63 64 class UInt16ListParser : public DHCPOptionsParser { 65 public: UInt16ListParser()66 UInt16ListParser() {} 67 bool GetOption(const uint8_t* buffer, 68 uint8_t length, 69 void* value) override; 70 }; 71 72 class UInt32ListParser : public DHCPOptionsParser { 73 public: UInt32ListParser()74 UInt32ListParser() {} 75 bool GetOption(const uint8_t* buffer, 76 uint8_t length, 77 void* value) override; 78 }; 79 80 class UInt32PairListParser : public DHCPOptionsParser { 81 public: UInt32PairListParser()82 UInt32PairListParser() {} 83 bool GetOption(const uint8_t* buffer, 84 uint8_t length, 85 void* value) override; 86 }; 87 88 class BoolParser : public DHCPOptionsParser { 89 public: BoolParser()90 BoolParser() {} 91 bool GetOption(const uint8_t* buffer, 92 uint8_t length, 93 void* value) override; 94 }; 95 96 class StringParser : public DHCPOptionsParser { 97 public: StringParser()98 StringParser() {} 99 bool GetOption(const uint8_t* buffer, 100 uint8_t length, 101 void* value) override; 102 }; 103 104 class ByteArrayParser : public DHCPOptionsParser { 105 public: 106 bool GetOption(const uint8_t* buffer, 107 uint8_t length, 108 void* value) override; 109 }; 110 } // namespace dhcp_client 111 112 #endif // DHCP_CLIENT_PARSER_H_ 113