1 // 2 // Copyright (C) 2012 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 SHILL_HTTP_URL_H_ 18 #define SHILL_HTTP_URL_H_ 19 20 #include <base/macros.h> 21 22 #include <string> 23 24 namespace shill { 25 26 // Simple URL parsing class. 27 class HTTPURL { 28 public: 29 enum Protocol { 30 kProtocolUnknown, 31 kProtocolHTTP, 32 kProtocolHTTPS 33 }; 34 35 static const int kDefaultHTTPPort; 36 static const int kDefaultHTTPSPort; 37 38 HTTPURL(); 39 virtual ~HTTPURL(); 40 41 // Parse a URL from |url_string|. 42 bool ParseFromString(const std::string& url_string); 43 host()44 const std::string& host() const { return host_; } path()45 const std::string& path() const { return path_; } port()46 int port() const { return port_; } protocol()47 Protocol protocol() const { return protocol_; } 48 49 private: 50 static const char kDelimiters[]; 51 static const char kPortSeparator; 52 static const char kPrefixHTTP[]; 53 static const char kPrefixHTTPS[]; 54 55 std::string host_; 56 std::string path_; 57 int port_; 58 Protocol protocol_; 59 60 DISALLOW_COPY_AND_ASSIGN(HTTPURL); 61 }; 62 63 } // namespace shill 64 65 #endif // SHILL_HTTP_URL_H_ 66