Back to index

lightning-sunbird  0.9+nobinonly
nsURLHelper.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; 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  * Andreas Otte.
00019  * Portions created by the Initial Developer are Copyright (C) 2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsURLHelper_h__
00039 #define nsURLHelper_h__
00040 
00041 #include "nsString.h"
00042 
00043 class nsIFile;
00044 class nsIURLParser;
00045 
00046 enum netCoalesceFlags
00047 {
00048   NET_COALESCE_NORMAL = 0,
00049 
00055   NET_COALESCE_ALLOW_RELATIVE_ROOT = 1<<0,
00056 
00061   NET_COALESCE_DOUBLE_SLASH_IS_ROOT = 1<<1
00062 };
00063 
00064 //----------------------------------------------------------------------------
00065 // This module contains some private helper functions related to URL parsing.
00066 //----------------------------------------------------------------------------
00067 
00068 /* shutdown frees URL parser */
00069 NS_HIDDEN_(void) net_ShutdownURLHelper();
00070 
00071 /* access URL parsers */
00072 NS_HIDDEN_(nsIURLParser *) net_GetAuthURLParser();
00073 NS_HIDDEN_(nsIURLParser *) net_GetNoAuthURLParser();
00074 NS_HIDDEN_(nsIURLParser *) net_GetStdURLParser();
00075 
00076 /* convert between nsIFile and file:// URL spec */
00077 NS_HIDDEN_(nsresult) net_GetURLSpecFromFile(nsIFile *, nsACString &);
00078 NS_HIDDEN_(nsresult) net_GetFileFromURLSpec(const nsACString &, nsIFile **);
00079 
00080 /* extract file path components from file:// URL */
00081 NS_HIDDEN_(nsresult) net_ParseFileURL(const nsACString &inURL,
00082                                       nsACString &outDirectory,
00083                                       nsACString &outFileBaseName,
00084                                       nsACString &outFileExtension);
00085 
00086 /* handle .. in dirs while resolving URLs (path is UTF-8) */
00087 NS_HIDDEN_(void) net_CoalesceDirs(netCoalesceFlags flags, char* path);
00088 
00102 NS_HIDDEN_(nsresult) net_ResolveRelativePath(const nsACString &relativePath,
00103                                              const nsACString &basePath,
00104                                              nsACString &result);
00105 
00114 NS_HIDDEN_(nsresult) net_ExtractURLScheme(const nsACString &inURI,
00115                                           PRUint32 *startPos, 
00116                                           PRUint32 *endPos,
00117                                           nsACString *scheme = nsnull);
00118 
00119 /* check that the given scheme conforms to RFC 2396 */
00120 NS_HIDDEN_(PRBool) net_IsValidScheme(const char *scheme, PRUint32 schemeLen);
00121 
00122 inline PRBool net_IsValidScheme(const nsAFlatCString &scheme)
00123 {
00124     return net_IsValidScheme(scheme.get(), scheme.Length());
00125 }
00126 
00142 NS_HIDDEN_(PRBool) net_FilterURIString(const char *str, nsACString& result);
00143 
00144 #if defined(XP_WIN) || defined(XP_OS2)
00145 
00158 NS_HIDDEN_(PRBool) net_NormalizeFileURL(const nsACString &aURL,
00159                                         nsCString &aResultBuf);
00160 #endif
00161 
00162 /*****************************************************************************
00163  * generic string routines follow (XXX move to someplace more generic).
00164  */
00165 
00166 /* convert to lower case */
00167 NS_HIDDEN_(void) net_ToLowerCase(char* str, PRUint32 length);
00168 NS_HIDDEN_(void) net_ToLowerCase(char* str);
00169 
00175 NS_HIDDEN_(char *) net_FindCharInSet(const char *str, const char *end, const char *set);
00176 
00183 NS_HIDDEN_(char *) net_FindCharNotInSet(const char *str, const char *end, const char *set);
00184 
00189 NS_HIDDEN_(char *) net_RFindCharInSet(const char *str, const char *end, const char *set);
00190 
00195 NS_HIDDEN_(char *) net_RFindCharNotInSet(const char *str, const char *end, const char *set);
00196 
00205 NS_HIDDEN_(void) net_ParseContentType(const nsACString &aHeaderStr,
00206                                       nsACString       &aContentType,
00207                                       nsACString       &aContentCharset,
00208                                       PRBool*          aHadCharset);
00209 
00210 /* inline versions */
00211 
00212 /* remember the 64-bit platforms ;-) */
00213 #define NET_MAX_ADDRESS (((char*)0)-1)
00214 
00215 inline char *net_FindCharInSet(const char *str, const char *set)
00216 {
00217     return net_FindCharInSet(str, NET_MAX_ADDRESS, set);
00218 }
00219 inline char *net_FindCharNotInSet(const char *str, const char *set)
00220 {
00221     return net_FindCharNotInSet(str, NET_MAX_ADDRESS, set);
00222 }
00223 inline char *net_RFindCharInSet(const char *str, const char *set)
00224 {
00225     return net_RFindCharInSet(str, str + strlen(str), set);
00226 }
00227 inline char *net_RFindCharNotInSet(const char *str, const char *set)
00228 {
00229     return net_RFindCharNotInSet(str, str + strlen(str), set);
00230 }
00231 
00236 NS_HIDDEN_(PRBool) net_IsValidHostName(const nsCSubstring &host);
00237 
00238 #endif // !nsURLHelper_h__