1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Darin Fisher (original author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsURLParsers_h__
40 : #define nsURLParsers_h__
41 :
42 : #include "nsIURLParser.h"
43 :
44 : //----------------------------------------------------------------------------
45 : // base class for url parsers
46 : //----------------------------------------------------------------------------
47 :
48 : class nsBaseURLParser : public nsIURLParser
49 : {
50 : public:
51 : NS_DECL_ISUPPORTS
52 : NS_DECL_NSIURLPARSER
53 :
54 4257 : nsBaseURLParser() { }
55 :
56 : protected:
57 : // implemented by subclasses
58 : virtual void ParseAfterScheme(const char *spec, PRInt32 specLen,
59 : PRUint32 *authPos, PRInt32 *authLen,
60 : PRUint32 *pathPos, PRInt32 *pathLen) = 0;
61 : };
62 :
63 : //----------------------------------------------------------------------------
64 : // an url parser for urls that do not have an authority section
65 : //
66 : // eg. file:foo/bar.txt
67 : // file:/foo/bar.txt (treated equivalently)
68 : // file:///foo/bar.txt
69 : //
70 : // eg. file:////foo/bar.txt (UNC-filepath = \\foo\bar.txt)
71 : //
72 : // XXX except in this case:
73 : // file://foo/bar.txt (the authority "foo" is ignored)
74 : //----------------------------------------------------------------------------
75 :
76 : class nsNoAuthURLParser : public nsBaseURLParser
77 1419 : {
78 : public:
79 : #if defined(XP_WIN) || defined(XP_OS2)
80 : NS_IMETHOD ParseFilePath(const char *, PRInt32,
81 : PRUint32 *, PRInt32 *,
82 : PRUint32 *, PRInt32 *,
83 : PRUint32 *, PRInt32 *);
84 : #endif
85 :
86 : NS_IMETHOD ParseAuthority(const char *auth, PRInt32 authLen,
87 : PRUint32 *usernamePos, PRInt32 *usernameLen,
88 : PRUint32 *passwordPos, PRInt32 *passwordLen,
89 : PRUint32 *hostnamePos, PRInt32 *hostnameLen,
90 : PRInt32 *port);
91 :
92 : void ParseAfterScheme(const char *spec, PRInt32 specLen,
93 : PRUint32 *authPos, PRInt32 *authLen,
94 : PRUint32 *pathPos, PRInt32 *pathLen);
95 : };
96 :
97 : //----------------------------------------------------------------------------
98 : // an url parser for urls that must have an authority section
99 : //
100 : // eg. http:www.foo.com/bar.html
101 : // http:/www.foo.com/bar.html
102 : // http://www.foo.com/bar.html (treated equivalently)
103 : // http:///www.foo.com/bar.html
104 : //----------------------------------------------------------------------------
105 :
106 : class nsAuthURLParser : public nsBaseURLParser
107 2838 : {
108 : public:
109 : NS_IMETHOD ParseAuthority(const char *auth, PRInt32 authLen,
110 : PRUint32 *usernamePos, PRInt32 *usernameLen,
111 : PRUint32 *passwordPos, PRInt32 *passwordLen,
112 : PRUint32 *hostnamePos, PRInt32 *hostnameLen,
113 : PRInt32 *port);
114 :
115 : NS_IMETHOD ParseUserInfo(const char *userinfo, PRInt32 userinfoLen,
116 : PRUint32 *usernamePos, PRInt32 *usernameLen,
117 : PRUint32 *passwordPos, PRInt32 *passwordLen);
118 :
119 : NS_IMETHOD ParseServerInfo(const char *serverinfo, PRInt32 serverinfoLen,
120 : PRUint32 *hostnamePos, PRInt32 *hostnameLen,
121 : PRInt32 *port);
122 :
123 : void ParseAfterScheme(const char *spec, PRInt32 specLen,
124 : PRUint32 *authPos, PRInt32 *authLen,
125 : PRUint32 *pathPos, PRInt32 *pathLen);
126 : };
127 :
128 : //----------------------------------------------------------------------------
129 : // an url parser for urls that may or may not have an authority section
130 : //
131 : // eg. http:www.foo.com (www.foo.com is authority)
132 : // http:www.foo.com/bar.html (www.foo.com is authority)
133 : // http:/www.foo.com/bar.html (www.foo.com is part of file path)
134 : // http://www.foo.com/bar.html (www.foo.com is authority)
135 : // http:///www.foo.com/bar.html (www.foo.com is part of file path)
136 : //----------------------------------------------------------------------------
137 :
138 : class nsStdURLParser : public nsAuthURLParser
139 1419 : {
140 : public:
141 : void ParseAfterScheme(const char *spec, PRInt32 specLen,
142 : PRUint32 *authPos, PRInt32 *authLen,
143 : PRUint32 *pathPos, PRInt32 *pathLen);
144 : };
145 :
146 : #endif // nsURLParsers_h__
|