intl/uconv/ucvcn/nsISO2022CNToUnicode.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5 #ifndef nsISO2022CNToUnicode_h__
michael@0 6 #define nsISO2022CNToUnicode_h__
michael@0 7 #include "nsCOMPtr.h"
michael@0 8 #include "nsUCSupport.h"
michael@0 9 #include "mozilla/Telemetry.h"
michael@0 10
michael@0 11 #define MBYTE 0x8e
michael@0 12 #undef PMASK
michael@0 13 #define PMASK 0xa0
michael@0 14
michael@0 15 #define SI 0x0f
michael@0 16 #define SO 0x0e
michael@0 17 #define ESC 0x1b
michael@0 18 #define SS2 0x4e
michael@0 19 #define SS3 0x4f
michael@0 20
michael@0 21 class nsISO2022CNToUnicode : public nsBasicDecoderSupport
michael@0 22 {
michael@0 23 public:
michael@0 24 nsISO2022CNToUnicode() :
michael@0 25 mState(eState_ASCII),
michael@0 26 mPlaneID(0),
michael@0 27 mRunLength(0)
michael@0 28 {
michael@0 29 mozilla::Telemetry::Accumulate(
michael@0 30 mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022CN, true);
michael@0 31 }
michael@0 32
michael@0 33 virtual ~nsISO2022CNToUnicode() {}
michael@0 34
michael@0 35 NS_IMETHOD Convert(const char *aSrc, int32_t * aSrcLength,
michael@0 36 char16_t * aDest, int32_t * aDestLength) ;
michael@0 37
michael@0 38 NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength,
michael@0 39 int32_t * aDestLength)
michael@0 40 {
michael@0 41 *aDestLength = aSrcLength;
michael@0 42 return NS_OK;
michael@0 43 }
michael@0 44
michael@0 45 NS_IMETHOD Reset()
michael@0 46 {
michael@0 47 mState = eState_ASCII;
michael@0 48 mPlaneID = 0;
michael@0 49 mRunLength = 0;
michael@0 50
michael@0 51 return NS_OK;
michael@0 52 }
michael@0 53
michael@0 54 private:
michael@0 55 // State Machine ID
michael@0 56 enum {
michael@0 57 eState_ASCII,
michael@0 58 eState_ESC, // ESC
michael@0 59 eState_ESC_24, // ESC $
michael@0 60
michael@0 61 eState_ESC_24_29, // ESC $ )
michael@0 62 eState_ESC_24_29_A, // ESC $ ) A
michael@0 63 eState_GB2312_1980, // ESC $ ) A SO
michael@0 64 eState_GB2312_1980_2ndbyte, // ESC $ ) A SO
michael@0 65 eState_ESC_24_29_A_SO_SI, // ESC $ ) A SO SI
michael@0 66 eState_ESC_24_29_G, // ESC $ ) G or H
michael@0 67 eState_CNS11643_1, // ESC $ ) G SO
michael@0 68 eState_CNS11643_1_2ndbyte, // ESC $ ) G SO
michael@0 69 eState_ESC_24_29_G_SO_SI, // ESC $ ) G SO SI
michael@0 70
michael@0 71 eState_ESC_24_2A, // ESC $ *
michael@0 72 eState_ESC_24_2A_H, // ESC $ * H
michael@0 73 eState_ESC_24_2A_H_ESC, // ESC $ * H ESC
michael@0 74 eState_CNS11643_2, // ESC $ * H ESC SS2
michael@0 75 eState_CNS11643_2_2ndbyte, // ESC $ * H ESC SS2
michael@0 76 eState_ESC_24_2A_H_ESC_SS2_SI, // ESC $ * H ESC SS2 SI
michael@0 77 eState_ESC_24_2A_H_ESC_SS2_SI_ESC, // ESC $ * H ESC SS2 SI ESC
michael@0 78
michael@0 79 eState_ESC_24_2B, // ESC $ +
michael@0 80 eState_ESC_24_2B_I, // ESC $ + I
michael@0 81 eState_ESC_24_2B_I_ESC, // ESC $ + I ESC
michael@0 82 eState_CNS11643_3, // ESC $ + I ESC SS3
michael@0 83 eState_CNS11643_3_2ndbyte, // ESC $ + I ESC SS3
michael@0 84 eState_ESC_24_2B_I_ESC_SS3_SI, // ESC $ + I ESC SI
michael@0 85 eState_ESC_24_2B_I_ESC_SS3_SI_ESC, // ESC $ + I ESC SI ESC
michael@0 86 eState_ERROR
michael@0 87 } mState;
michael@0 88
michael@0 89 char mData;
michael@0 90
michael@0 91 // Plane number for CNS11643 code
michael@0 92 int mPlaneID;
michael@0 93
michael@0 94 // Length of non-ASCII run
michael@0 95 uint32_t mRunLength;
michael@0 96
michael@0 97 // Decoder handler
michael@0 98 nsCOMPtr<nsIUnicodeDecoder> mGB2312_Decoder;
michael@0 99 nsCOMPtr<nsIUnicodeDecoder> mEUCTW_Decoder;
michael@0 100
michael@0 101 NS_IMETHOD GB2312_To_Unicode(unsigned char *aSrc, int32_t aSrcLength,
michael@0 102 char16_t * aDest, int32_t * aDestLength) ;
michael@0 103
michael@0 104 NS_IMETHOD EUCTW_To_Unicode(unsigned char *aSrc, int32_t aSrcLength,
michael@0 105 char16_t * aDest, int32_t * aDestLength) ;
michael@0 106 };
michael@0 107 #endif // nsISO2022CNToUnicode_h__

mercurial