toolkit/components/url-classifier/nsUrlClassifierUtils.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsUrlClassifierUtils_h_
michael@0 6 #define nsUrlClassifierUtils_h_
michael@0 7
michael@0 8 #include "nsAutoPtr.h"
michael@0 9 #include "nsIUrlClassifierUtils.h"
michael@0 10 #include "nsTArray.h"
michael@0 11 #include "nsDataHashtable.h"
michael@0 12 #include "mozilla/Attributes.h"
michael@0 13
michael@0 14 class nsUrlClassifierUtils MOZ_FINAL : public nsIUrlClassifierUtils
michael@0 15 {
michael@0 16 private:
michael@0 17 /**
michael@0 18 * A fast, bit-vector map for ascii characters.
michael@0 19 *
michael@0 20 * Internally stores 256 bits in an array of 8 ints.
michael@0 21 * Does quick bit-flicking to lookup needed characters.
michael@0 22 */
michael@0 23 class Charmap
michael@0 24 {
michael@0 25 public:
michael@0 26 Charmap(uint32_t b0, uint32_t b1, uint32_t b2, uint32_t b3,
michael@0 27 uint32_t b4, uint32_t b5, uint32_t b6, uint32_t b7)
michael@0 28 {
michael@0 29 mMap[0] = b0; mMap[1] = b1; mMap[2] = b2; mMap[3] = b3;
michael@0 30 mMap[4] = b4; mMap[5] = b5; mMap[6] = b6; mMap[7] = b7;
michael@0 31 }
michael@0 32
michael@0 33 /**
michael@0 34 * Do a quick lookup to see if the letter is in the map.
michael@0 35 */
michael@0 36 bool Contains(unsigned char c) const
michael@0 37 {
michael@0 38 return mMap[c >> 5] & (1 << (c & 31));
michael@0 39 }
michael@0 40
michael@0 41 private:
michael@0 42 // Store the 256 bits in an 8 byte array.
michael@0 43 uint32_t mMap[8];
michael@0 44 };
michael@0 45
michael@0 46
michael@0 47 public:
michael@0 48 nsUrlClassifierUtils();
michael@0 49 ~nsUrlClassifierUtils() {}
michael@0 50
michael@0 51 NS_DECL_ISUPPORTS
michael@0 52 NS_DECL_NSIURLCLASSIFIERUTILS
michael@0 53
michael@0 54 nsresult Init();
michael@0 55
michael@0 56 nsresult CanonicalizeHostname(const nsACString & hostname,
michael@0 57 nsACString & _retval);
michael@0 58 nsresult CanonicalizePath(const nsACString & url, nsACString & _retval);
michael@0 59
michael@0 60 // This function will encode all "special" characters in typical url encoding,
michael@0 61 // that is %hh where h is a valid hex digit. The characters which are encoded
michael@0 62 // by this function are any ascii characters under 32(control characters and
michael@0 63 // space), 37(%), and anything 127 or above (special characters). Url is the
michael@0 64 // string to encode, ret is the encoded string. Function returns true if
michael@0 65 // ret != url.
michael@0 66 bool SpecialEncode(const nsACString & url,
michael@0 67 bool foldSlashes,
michael@0 68 nsACString & _retval);
michael@0 69
michael@0 70 void ParseIPAddress(const nsACString & host, nsACString & _retval);
michael@0 71 void CanonicalNum(const nsACString & num,
michael@0 72 uint32_t bytes,
michael@0 73 bool allowOctal,
michael@0 74 nsACString & _retval);
michael@0 75
michael@0 76 private:
michael@0 77 // Disallow copy constructor
michael@0 78 nsUrlClassifierUtils(const nsUrlClassifierUtils&);
michael@0 79
michael@0 80 // Function to tell if we should encode a character.
michael@0 81 bool ShouldURLEscape(const unsigned char c) const;
michael@0 82
michael@0 83 void CleanupHostname(const nsACString & host, nsACString & _retval);
michael@0 84
michael@0 85 nsAutoPtr<Charmap> mEscapeCharmap;
michael@0 86 };
michael@0 87
michael@0 88 #endif // nsUrlClassifierUtils_h_

mercurial