shill: Add HTTP URL parser

This will be used in portal detection for parsing the configured
portal host.

TEST=New unit tests
BUG=chromium-os:23318

Change-Id: I3a56445a85618e966cff9410e96c70ac1a26c320
Reviewed-on: https://gerrit.chromium.org/gerrit/14436
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/http_url.h b/http_url.h
new file mode 100644
index 0000000..b98cb9e
--- /dev/null
+++ b/http_url.h
@@ -0,0 +1,53 @@
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_HTTP_URL_
+#define SHILL_HTTP_URL_
+
+#include <base/basictypes.h>
+
+#include <string>
+
+namespace shill {
+
+// Simple URL parsing class.
+class HTTPURL {
+ public:
+  enum Protocol {
+    kProtocolUnknown,
+    kProtocolHTTP,
+    kProtocolHTTPS
+  };
+
+  static const int kDefaultHTTPPort;
+  static const int kDefaultHTTPSPort;
+
+  HTTPURL();
+  virtual ~HTTPURL();
+
+  // Parse a URL from |url_string|.
+  bool ParseFromString(const std::string &url_string);
+
+  const std::string &host() const { return host_; }
+  const std::string &path() const { return path_; }
+  int port() const { return port_; }
+  Protocol protocol() const { return protocol_; }
+
+ private:
+  static const char kDelimiters[];
+  static const char kPortSeparator;
+  static const char kPrefixHTTP[];
+  static const char kPrefixHTTPS[];
+
+  std::string host_;
+  std::string path_;
+  int port_;
+  Protocol protocol_;
+
+  DISALLOW_COPY_AND_ASSIGN(HTTPURL);
+};
+
+}  // namespace shill
+
+#endif  // SHILL_HTTP_URL_