Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
5 :
6 : #ifndef nsURLParsers_h__
7 : #define nsURLParsers_h__
8 :
9 : #include "nsIURLParser.h"
10 : #include "mozilla/Attributes.h"
11 :
12 : //----------------------------------------------------------------------------
13 : // base class for url parsers
14 : //----------------------------------------------------------------------------
15 :
16 : class nsBaseURLParser : public nsIURLParser
17 : {
18 : public:
19 : NS_DECL_NSIURLPARSER
20 :
21 9 : nsBaseURLParser() { }
22 :
23 : protected:
24 : // implemented by subclasses
25 : virtual void ParseAfterScheme(const char *spec, int32_t specLen,
26 : uint32_t *authPos, int32_t *authLen,
27 : uint32_t *pathPos, int32_t *pathLen) = 0;
28 : };
29 :
30 : //----------------------------------------------------------------------------
31 : // an url parser for urls that do not have an authority section
32 : //
33 : // eg. file:foo/bar.txt
34 : // file:/foo/bar.txt (treated equivalently)
35 : // file:///foo/bar.txt
36 : //
37 : // eg. file:////foo/bar.txt (UNC-filepath = \\foo\bar.txt)
38 : //
39 : // XXX except in this case:
40 : // file://foo/bar.txt (the authority "foo" is ignored)
41 : //----------------------------------------------------------------------------
42 :
43 3 : class nsNoAuthURLParser final : public nsBaseURLParser
44 : {
45 0 : ~nsNoAuthURLParser() {}
46 :
47 : public:
48 : NS_DECL_THREADSAFE_ISUPPORTS
49 :
50 : #if defined(XP_WIN)
51 : NS_IMETHOD ParseFilePath(const char *, int32_t,
52 : uint32_t *, int32_t *,
53 : uint32_t *, int32_t *,
54 : uint32_t *, int32_t *) override;
55 : #endif
56 :
57 : NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
58 : uint32_t *usernamePos, int32_t *usernameLen,
59 : uint32_t *passwordPos, int32_t *passwordLen,
60 : uint32_t *hostnamePos, int32_t *hostnameLen,
61 : int32_t *port) override;
62 :
63 : void ParseAfterScheme(const char *spec, int32_t specLen,
64 : uint32_t *authPos, int32_t *authLen,
65 : uint32_t *pathPos, int32_t *pathLen) override;
66 : };
67 :
68 : //----------------------------------------------------------------------------
69 : // an url parser for urls that must have an authority section
70 : //
71 : // eg. http:www.foo.com/bar.html
72 : // http:/www.foo.com/bar.html
73 : // http://www.foo.com/bar.html (treated equivalently)
74 : // http:///www.foo.com/bar.html
75 : //----------------------------------------------------------------------------
76 :
77 6 : class nsAuthURLParser : public nsBaseURLParser
78 : {
79 : protected:
80 0 : virtual ~nsAuthURLParser() {}
81 :
82 : public:
83 : NS_DECL_THREADSAFE_ISUPPORTS
84 :
85 : NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
86 : uint32_t *usernamePos, int32_t *usernameLen,
87 : uint32_t *passwordPos, int32_t *passwordLen,
88 : uint32_t *hostnamePos, int32_t *hostnameLen,
89 : int32_t *port) override;
90 :
91 : NS_IMETHOD ParseUserInfo(const char *userinfo, int32_t userinfoLen,
92 : uint32_t *usernamePos, int32_t *usernameLen,
93 : uint32_t *passwordPos, int32_t *passwordLen) override;
94 :
95 : NS_IMETHOD ParseServerInfo(const char *serverinfo, int32_t serverinfoLen,
96 : uint32_t *hostnamePos, int32_t *hostnameLen,
97 : int32_t *port) override;
98 :
99 : void ParseAfterScheme(const char *spec, int32_t specLen,
100 : uint32_t *authPos, int32_t *authLen,
101 : uint32_t *pathPos, int32_t *pathLen) override;
102 : };
103 :
104 : //----------------------------------------------------------------------------
105 : // an url parser for urls that may or may not have an authority section
106 : //
107 : // eg. http:www.foo.com (www.foo.com is authority)
108 : // http:www.foo.com/bar.html (www.foo.com is authority)
109 : // http:/www.foo.com/bar.html (www.foo.com is part of file path)
110 : // http://www.foo.com/bar.html (www.foo.com is authority)
111 : // http:///www.foo.com/bar.html (www.foo.com is part of file path)
112 : //----------------------------------------------------------------------------
113 :
114 3 : class nsStdURLParser : public nsAuthURLParser
115 : {
116 0 : virtual ~nsStdURLParser() {}
117 :
118 : public:
119 : void ParseAfterScheme(const char *spec, int32_t specLen,
120 : uint32_t *authPos, int32_t *authLen,
121 : uint32_t *pathPos, int32_t *pathLen);
122 : };
123 :
124 : #endif // nsURLParsers_h__
|