toolkit/components/url-classifier/nsUrlClassifierUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/url-classifier/nsUrlClassifierUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef nsUrlClassifierUtils_h_
     1.9 +#define nsUrlClassifierUtils_h_
    1.10 +
    1.11 +#include "nsAutoPtr.h"
    1.12 +#include "nsIUrlClassifierUtils.h"
    1.13 +#include "nsTArray.h"
    1.14 +#include "nsDataHashtable.h"
    1.15 +#include "mozilla/Attributes.h"
    1.16 +
    1.17 +class nsUrlClassifierUtils MOZ_FINAL : public nsIUrlClassifierUtils
    1.18 +{
    1.19 +private:
    1.20 +  /**
    1.21 +   * A fast, bit-vector map for ascii characters.
    1.22 +   *
    1.23 +   * Internally stores 256 bits in an array of 8 ints.
    1.24 +   * Does quick bit-flicking to lookup needed characters.
    1.25 +   */
    1.26 +  class Charmap
    1.27 +  {
    1.28 +  public:
    1.29 +    Charmap(uint32_t b0, uint32_t b1, uint32_t b2, uint32_t b3,
    1.30 +            uint32_t b4, uint32_t b5, uint32_t b6, uint32_t b7)
    1.31 +    {
    1.32 +      mMap[0] = b0; mMap[1] = b1; mMap[2] = b2; mMap[3] = b3;
    1.33 +      mMap[4] = b4; mMap[5] = b5; mMap[6] = b6; mMap[7] = b7;
    1.34 +    }
    1.35 +
    1.36 +    /**
    1.37 +     * Do a quick lookup to see if the letter is in the map.
    1.38 +     */
    1.39 +    bool Contains(unsigned char c) const
    1.40 +    {
    1.41 +      return mMap[c >> 5] & (1 << (c & 31));
    1.42 +    }
    1.43 +
    1.44 +  private:
    1.45 +    // Store the 256 bits in an 8 byte array.
    1.46 +    uint32_t mMap[8];
    1.47 +  };
    1.48 +
    1.49 +
    1.50 +public:
    1.51 +  nsUrlClassifierUtils();
    1.52 +  ~nsUrlClassifierUtils() {}
    1.53 +
    1.54 +  NS_DECL_ISUPPORTS
    1.55 +  NS_DECL_NSIURLCLASSIFIERUTILS
    1.56 +
    1.57 +  nsresult Init();
    1.58 +
    1.59 +  nsresult CanonicalizeHostname(const nsACString & hostname,
    1.60 +                                nsACString & _retval);
    1.61 +  nsresult CanonicalizePath(const nsACString & url, nsACString & _retval);
    1.62 +
    1.63 +  // This function will encode all "special" characters in typical url encoding,
    1.64 +  // that is %hh where h is a valid hex digit.  The characters which are encoded
    1.65 +  // by this function are any ascii characters under 32(control characters and
    1.66 +  // space), 37(%), and anything 127 or above (special characters).  Url is the
    1.67 +  // string to encode, ret is the encoded string.  Function returns true if
    1.68 +  // ret != url.
    1.69 +  bool SpecialEncode(const nsACString & url,
    1.70 +                       bool foldSlashes,
    1.71 +                       nsACString & _retval);
    1.72 +
    1.73 +  void ParseIPAddress(const nsACString & host, nsACString & _retval);
    1.74 +  void CanonicalNum(const nsACString & num,
    1.75 +                    uint32_t bytes,
    1.76 +                    bool allowOctal,
    1.77 +                    nsACString & _retval);
    1.78 +
    1.79 +private:
    1.80 +  // Disallow copy constructor
    1.81 +  nsUrlClassifierUtils(const nsUrlClassifierUtils&);
    1.82 +
    1.83 +  // Function to tell if we should encode a character.
    1.84 +  bool ShouldURLEscape(const unsigned char c) const;
    1.85 +
    1.86 +  void CleanupHostname(const nsACString & host, nsACString & _retval);
    1.87 +
    1.88 +  nsAutoPtr<Charmap> mEscapeCharmap;
    1.89 +};
    1.90 +
    1.91 +#endif // nsUrlClassifierUtils_h_

mercurial