michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsURLParsers_h__ michael@0: #define nsURLParsers_h__ michael@0: michael@0: #include "nsIURLParser.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: //---------------------------------------------------------------------------- michael@0: // base class for url parsers michael@0: //---------------------------------------------------------------------------- michael@0: michael@0: class nsBaseURLParser : public nsIURLParser michael@0: { michael@0: public: michael@0: NS_DECL_NSIURLPARSER michael@0: michael@0: nsBaseURLParser() { } michael@0: michael@0: protected: michael@0: // implemented by subclasses michael@0: virtual void ParseAfterScheme(const char *spec, int32_t specLen, michael@0: uint32_t *authPos, int32_t *authLen, michael@0: uint32_t *pathPos, int32_t *pathLen) = 0; michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------------- michael@0: // an url parser for urls that do not have an authority section michael@0: // michael@0: // eg. file:foo/bar.txt michael@0: // file:/foo/bar.txt (treated equivalently) michael@0: // file:///foo/bar.txt michael@0: // michael@0: // eg. file:////foo/bar.txt (UNC-filepath = \\foo\bar.txt) michael@0: // michael@0: // XXX except in this case: michael@0: // file://foo/bar.txt (the authority "foo" is ignored) michael@0: //---------------------------------------------------------------------------- michael@0: michael@0: class nsNoAuthURLParser MOZ_FINAL : public nsBaseURLParser michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: michael@0: #if defined(XP_WIN) michael@0: NS_IMETHOD ParseFilePath(const char *, int32_t, michael@0: uint32_t *, int32_t *, michael@0: uint32_t *, int32_t *, michael@0: uint32_t *, int32_t *); michael@0: #endif michael@0: michael@0: NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen, michael@0: uint32_t *usernamePos, int32_t *usernameLen, michael@0: uint32_t *passwordPos, int32_t *passwordLen, michael@0: uint32_t *hostnamePos, int32_t *hostnameLen, michael@0: int32_t *port); michael@0: michael@0: void ParseAfterScheme(const char *spec, int32_t specLen, michael@0: uint32_t *authPos, int32_t *authLen, michael@0: uint32_t *pathPos, int32_t *pathLen); michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------------- michael@0: // an url parser for urls that must have an authority section michael@0: // michael@0: // eg. http:www.foo.com/bar.html michael@0: // http:/www.foo.com/bar.html michael@0: // http://www.foo.com/bar.html (treated equivalently) michael@0: // http:///www.foo.com/bar.html michael@0: //---------------------------------------------------------------------------- michael@0: michael@0: class nsAuthURLParser : public nsBaseURLParser michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: michael@0: virtual ~nsAuthURLParser() {} michael@0: michael@0: NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen, michael@0: uint32_t *usernamePos, int32_t *usernameLen, michael@0: uint32_t *passwordPos, int32_t *passwordLen, michael@0: uint32_t *hostnamePos, int32_t *hostnameLen, michael@0: int32_t *port); michael@0: michael@0: NS_IMETHOD ParseUserInfo(const char *userinfo, int32_t userinfoLen, michael@0: uint32_t *usernamePos, int32_t *usernameLen, michael@0: uint32_t *passwordPos, int32_t *passwordLen); michael@0: michael@0: NS_IMETHOD ParseServerInfo(const char *serverinfo, int32_t serverinfoLen, michael@0: uint32_t *hostnamePos, int32_t *hostnameLen, michael@0: int32_t *port); michael@0: michael@0: void ParseAfterScheme(const char *spec, int32_t specLen, michael@0: uint32_t *authPos, int32_t *authLen, michael@0: uint32_t *pathPos, int32_t *pathLen); michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------------- michael@0: // an url parser for urls that may or may not have an authority section michael@0: // michael@0: // eg. http:www.foo.com (www.foo.com is authority) michael@0: // http:www.foo.com/bar.html (www.foo.com is authority) michael@0: // http:/www.foo.com/bar.html (www.foo.com is part of file path) michael@0: // http://www.foo.com/bar.html (www.foo.com is authority) michael@0: // http:///www.foo.com/bar.html (www.foo.com is part of file path) michael@0: //---------------------------------------------------------------------------- michael@0: michael@0: class nsStdURLParser : public nsAuthURLParser michael@0: { michael@0: public: michael@0: void ParseAfterScheme(const char *spec, int32_t specLen, michael@0: uint32_t *authPos, int32_t *authLen, michael@0: uint32_t *pathPos, int32_t *pathLen); michael@0: }; michael@0: michael@0: #endif // nsURLParsers_h__