1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsURLParsers_h__
7 #define nsURLParsers_h__
9 #include "nsIURLParser.h"
10 #include "mozilla/Attributes.h"
12 //----------------------------------------------------------------------------
13 // base class for url parsers
14 //----------------------------------------------------------------------------
16 class nsBaseURLParser
: public nsIURLParser
{
20 nsBaseURLParser() = default;
23 // implemented by subclasses
24 virtual void ParseAfterScheme(const char* spec
, int32_t specLen
,
25 uint32_t* authPos
, int32_t* authLen
,
26 uint32_t* pathPos
, int32_t* pathLen
) = 0;
29 //----------------------------------------------------------------------------
30 // an url parser for urls that do not have an authority section
32 // eg. file:foo/bar.txt
33 // file:/foo/bar.txt (treated equivalently)
34 // file:///foo/bar.txt
36 // eg. file:////foo/bar.txt (UNC-filepath = \\foo\bar.txt)
38 // XXX except in this case:
39 // file://foo/bar.txt (the authority "foo" is ignored)
40 //----------------------------------------------------------------------------
42 class nsNoAuthURLParser final
: public nsBaseURLParser
{
43 ~nsNoAuthURLParser() = default;
46 NS_DECL_THREADSAFE_ISUPPORTS
49 NS_IMETHOD
ParseFilePath(const char*, int32_t, uint32_t*, int32_t*, uint32_t*,
50 int32_t*, uint32_t*, int32_t*) override
;
53 NS_IMETHOD
ParseAuthority(const char* auth
, int32_t authLen
,
54 uint32_t* usernamePos
, int32_t* usernameLen
,
55 uint32_t* passwordPos
, int32_t* passwordLen
,
56 uint32_t* hostnamePos
, int32_t* hostnameLen
,
57 int32_t* port
) override
;
59 void ParseAfterScheme(const char* spec
, int32_t specLen
, uint32_t* authPos
,
60 int32_t* authLen
, uint32_t* pathPos
,
61 int32_t* pathLen
) override
;
64 //----------------------------------------------------------------------------
65 // an url parser for urls that must have an authority section
67 // eg. http:www.foo.com/bar.html
68 // http:/www.foo.com/bar.html
69 // http://www.foo.com/bar.html (treated equivalently)
70 // http:///www.foo.com/bar.html
71 //----------------------------------------------------------------------------
73 class nsAuthURLParser
: public nsBaseURLParser
{
75 virtual ~nsAuthURLParser() = default;
78 NS_DECL_THREADSAFE_ISUPPORTS
80 NS_IMETHOD
ParseAuthority(const char* auth
, int32_t authLen
,
81 uint32_t* usernamePos
, int32_t* usernameLen
,
82 uint32_t* passwordPos
, int32_t* passwordLen
,
83 uint32_t* hostnamePos
, int32_t* hostnameLen
,
84 int32_t* port
) override
;
86 NS_IMETHOD
ParseUserInfo(const char* userinfo
, int32_t userinfoLen
,
87 uint32_t* usernamePos
, int32_t* usernameLen
,
88 uint32_t* passwordPos
,
89 int32_t* passwordLen
) override
;
91 NS_IMETHOD
ParseServerInfo(const char* serverinfo
, int32_t serverinfoLen
,
92 uint32_t* hostnamePos
, int32_t* hostnameLen
,
93 int32_t* port
) override
;
95 void ParseAfterScheme(const char* spec
, int32_t specLen
, uint32_t* authPos
,
96 int32_t* authLen
, uint32_t* pathPos
,
97 int32_t* pathLen
) override
;
100 //----------------------------------------------------------------------------
101 // an url parser for urls that may or may not have an authority section
103 // eg. http:www.foo.com (www.foo.com is authority)
104 // http:www.foo.com/bar.html (www.foo.com is authority)
105 // http:/www.foo.com/bar.html (www.foo.com is part of file path)
106 // http://www.foo.com/bar.html (www.foo.com is authority)
107 // http:///www.foo.com/bar.html (www.foo.com is part of file path)
108 //----------------------------------------------------------------------------
110 class nsStdURLParser
: public nsAuthURLParser
{
111 virtual ~nsStdURLParser() = default;
114 void ParseAfterScheme(const char* spec
, int32_t specLen
, uint32_t* authPos
,
115 int32_t* authLen
, uint32_t* pathPos
,
116 int32_t* pathLen
) override
;
119 #endif // nsURLParsers_h__