Bug 394611 - Always prompt the user before changing a stored password. r=gavin
[wine-gecko.git] / toolkit / components / url-classifier / src / nsUrlClassifierUtils.h
blobf42c30ac09963cced857907027da7929224ea279
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is Url Classifier code
16 * The Initial Developer of the Original Code is
17 * Google Inc.
18 * Portions created by the Initial Developer are Copyright (C) 2007
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsUrlClassifierUtils_h_
38 #define nsUrlClassifierUtils_h_
40 #include "nsAutoPtr.h"
41 #include "nsIUrlClassifierUtils.h"
43 class nsUrlClassifierUtils : public nsIUrlClassifierUtils
45 private:
46 /**
47 * A fast, bit-vector map for ascii characters.
49 * Internally stores 256 bits in an array of 8 ints.
50 * Does quick bit-flicking to lookup needed characters.
52 class Charmap
54 public:
55 Charmap(PRUint32 b0, PRUint32 b1, PRUint32 b2, PRUint32 b3,
56 PRUint32 b4, PRUint32 b5, PRUint32 b6, PRUint32 b7)
58 mMap[0] = b0; mMap[1] = b1; mMap[2] = b2; mMap[3] = b3;
59 mMap[4] = b4; mMap[5] = b5; mMap[6] = b6; mMap[7] = b7;
62 /**
63 * Do a quick lookup to see if the letter is in the map.
65 PRBool Contains(unsigned char c) const
67 return mMap[c >> 5] & (1 << (c & 31));
70 private:
71 // Store the 256 bits in an 8 byte array.
72 PRUint32 mMap[8];
76 public:
77 nsUrlClassifierUtils();
78 ~nsUrlClassifierUtils() {}
80 NS_DECL_ISUPPORTS
81 NS_DECL_NSIURLCLASSIFIERUTILS
83 nsresult Init();
85 nsresult CanonicalizeHostname(const nsACString & hostname,
86 nsACString & _retval);
87 nsresult CanonicalizePath(const nsACString & url, nsACString & _retval);
89 // This function will encode all "special" characters in typical url encoding,
90 // that is %hh where h is a valid hex digit. The characters which are encoded
91 // by this function are any ascii characters under 32(control characters and
92 // space), 37(%), and anything 127 or above (special characters). Url is the
93 // string to encode, ret is the encoded string. Function returns true if
94 // ret != url.
95 PRBool SpecialEncode(const nsACString & url,
96 PRBool foldSlashes,
97 nsACString & _retval);
99 void ParseIPAddress(const nsACString & host, nsACString & _retval);
100 void CanonicalNum(const nsACString & num,
101 PRUint32 bytes,
102 PRBool allowOctal,
103 nsACString & _retval);
105 // Convert an urlsafe base64 string to a normal base64 string.
106 // This method will leave an already-normal base64 string alone.
107 static void UnUrlsafeBase64(nsACString & str);
109 // Takes an urlsafe-base64 encoded client key and gives back binary
110 // key data
111 static nsresult DecodeClientKey(const nsACString & clientKey,
112 nsACString & _retval);
113 private:
114 // Disallow copy constructor
115 nsUrlClassifierUtils(const nsUrlClassifierUtils&);
117 // Function to tell if we should encode a character.
118 PRBool ShouldURLEscape(const unsigned char c) const;
120 void CleanupHostname(const nsACString & host, nsACString & _retval);
122 nsAutoPtr<Charmap> mEscapeCharmap;
125 #endif // nsUrlClassifierUtils_h_