Back to index

lightning-sunbird  0.9+nobinonly
nsURLParsers.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Darin Fisher (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsURLParsers_h__
00040 #define nsURLParsers_h__
00041 
00042 #include "nsIURLParser.h"
00043 
00044 //----------------------------------------------------------------------------
00045 // base class for url parsers
00046 //----------------------------------------------------------------------------
00047 
00048 class nsBaseURLParser : public nsIURLParser
00049 {
00050 public:
00051     NS_DECL_ISUPPORTS
00052     NS_DECL_NSIURLPARSER
00053 
00054     nsBaseURLParser() { }
00055 
00056 protected:
00057     // implemented by subclasses
00058     virtual void ParseAfterScheme(const char *spec, PRInt32 specLen,
00059                                   PRUint32 *authPos, PRInt32 *authLen,
00060                                   PRUint32 *pathPos, PRInt32 *pathLen) = 0;
00061 };
00062 
00063 //----------------------------------------------------------------------------
00064 // an url parser for urls that do not have an authority section
00065 //
00066 // eg. file:foo/bar.txt
00067 //     file:/foo/bar.txt      (treated equivalently)
00068 //     file:///foo/bar.txt
00069 //
00070 // eg. file:////foo/bar.txt   (UNC-filepath = \\foo\bar.txt)
00071 //
00072 // XXX except in this case:
00073 //     file://foo/bar.txt     (foo is authority)
00074 //----------------------------------------------------------------------------
00075 
00076 class nsNoAuthURLParser : public nsBaseURLParser
00077 {
00078 public: 
00079 #if defined(XP_WIN) || defined(XP_OS2)
00080     NS_IMETHOD ParseFilePath(const char *, PRInt32,
00081                              PRUint32 *, PRInt32 *,
00082                              PRUint32 *, PRInt32 *,
00083                              PRUint32 *, PRInt32 *);
00084 #endif
00085 
00086     void ParseAfterScheme(const char *spec, PRInt32 specLen,
00087                           PRUint32 *authPos, PRInt32 *authLen,
00088                           PRUint32 *pathPos, PRInt32 *pathLen);
00089 };
00090 
00091 //----------------------------------------------------------------------------
00092 // an url parser for urls that must have an authority section
00093 //
00094 // eg. http:www.foo.com/bar.html
00095 //     http:/www.foo.com/bar.html
00096 //     http://www.foo.com/bar.html    (treated equivalently)
00097 //     http:///www.foo.com/bar.html
00098 //----------------------------------------------------------------------------
00099 
00100 class nsAuthURLParser : public nsBaseURLParser
00101 {
00102 public: 
00103     NS_IMETHOD ParseAuthority(const char *auth, PRInt32 authLen,
00104                               PRUint32 *usernamePos, PRInt32 *usernameLen,
00105                               PRUint32 *passwordPos, PRInt32 *passwordLen,
00106                               PRUint32 *hostnamePos, PRInt32 *hostnameLen,
00107                               PRInt32 *port);
00108 
00109     NS_IMETHOD ParseUserInfo(const char *userinfo, PRInt32 userinfoLen,
00110                              PRUint32 *usernamePos, PRInt32 *usernameLen,
00111                              PRUint32 *passwordPos, PRInt32 *passwordLen);
00112 
00113     NS_IMETHOD ParseServerInfo(const char *serverinfo, PRInt32 serverinfoLen,
00114                                PRUint32 *hostnamePos, PRInt32 *hostnameLen,
00115                                PRInt32 *port);
00116 
00117     void ParseAfterScheme(const char *spec, PRInt32 specLen,
00118                           PRUint32 *authPos, PRInt32 *authLen,
00119                           PRUint32 *pathPos, PRInt32 *pathLen);
00120 };
00121 
00122 //----------------------------------------------------------------------------
00123 // an url parser for urls that may or may not have an authority section
00124 //
00125 // eg. http:www.foo.com              (www.foo.com is authority)
00126 //     http:www.foo.com/bar.html     (www.foo.com is authority)
00127 //     http:/www.foo.com/bar.html    (www.foo.com is part of file path)
00128 //     http://www.foo.com/bar.html   (www.foo.com is authority)
00129 //     http:///www.foo.com/bar.html  (www.foo.com is part of file path)
00130 //----------------------------------------------------------------------------
00131 
00132 class nsStdURLParser : public nsAuthURLParser
00133 {
00134 public: 
00135     void ParseAfterScheme(const char *spec, PRInt32 specLen,
00136                           PRUint32 *authPos, PRInt32 *authLen,
00137                           PRUint32 *pathPos, PRInt32 *pathLen);
00138 };
00139 
00140 #endif // nsURLParsers_h__