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