Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2010 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef _UTILS_TOKENIZER_H |
michael@0 | 18 | #define _UTILS_TOKENIZER_H |
michael@0 | 19 | |
michael@0 | 20 | #include <assert.h> |
michael@0 | 21 | #include <utils/Errors.h> |
michael@0 | 22 | #include <utils/FileMap.h> |
michael@0 | 23 | #include <utils/String8.h> |
michael@0 | 24 | |
michael@0 | 25 | namespace android { |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * A simple tokenizer for loading and parsing ASCII text files line by line. |
michael@0 | 29 | */ |
michael@0 | 30 | class Tokenizer { |
michael@0 | 31 | Tokenizer(const String8& filename, FileMap* fileMap, char* buffer, |
michael@0 | 32 | bool ownBuffer, size_t length); |
michael@0 | 33 | |
michael@0 | 34 | public: |
michael@0 | 35 | ~Tokenizer(); |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * Opens a file and maps it into memory. |
michael@0 | 39 | * |
michael@0 | 40 | * Returns NO_ERROR and a tokenizer for the file, if successful. |
michael@0 | 41 | * Otherwise returns an error and sets outTokenizer to NULL. |
michael@0 | 42 | */ |
michael@0 | 43 | static status_t open(const String8& filename, Tokenizer** outTokenizer); |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Prepares to tokenize the contents of a string. |
michael@0 | 47 | * |
michael@0 | 48 | * Returns NO_ERROR and a tokenizer for the string, if successful. |
michael@0 | 49 | * Otherwise returns an error and sets outTokenizer to NULL. |
michael@0 | 50 | */ |
michael@0 | 51 | static status_t fromContents(const String8& filename, |
michael@0 | 52 | const char* contents, Tokenizer** outTokenizer); |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * Returns true if at the end of the file. |
michael@0 | 56 | */ |
michael@0 | 57 | inline bool isEof() const { return mCurrent == getEnd(); } |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Returns true if at the end of the line or end of the file. |
michael@0 | 61 | */ |
michael@0 | 62 | inline bool isEol() const { return isEof() || *mCurrent == '\n'; } |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Gets the name of the file. |
michael@0 | 66 | */ |
michael@0 | 67 | inline String8 getFilename() const { return mFilename; } |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * Gets a 1-based line number index for the current position. |
michael@0 | 71 | */ |
michael@0 | 72 | inline int32_t getLineNumber() const { return mLineNumber; } |
michael@0 | 73 | |
michael@0 | 74 | /** |
michael@0 | 75 | * Formats a location string consisting of the filename and current line number. |
michael@0 | 76 | * Returns a string like "MyFile.txt:33". |
michael@0 | 77 | */ |
michael@0 | 78 | String8 getLocation() const; |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Gets the character at the current position. |
michael@0 | 82 | * Returns null at end of file. |
michael@0 | 83 | */ |
michael@0 | 84 | inline char peekChar() const { return isEof() ? '\0' : *mCurrent; } |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * Gets the remainder of the current line as a string, excluding the newline character. |
michael@0 | 88 | */ |
michael@0 | 89 | String8 peekRemainderOfLine() const; |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Gets the character at the current position and advances past it. |
michael@0 | 93 | * Returns null at end of file. |
michael@0 | 94 | */ |
michael@0 | 95 | inline char nextChar() { return isEof() ? '\0' : *(mCurrent++); } |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Gets the next token on this line stopping at the specified delimiters |
michael@0 | 99 | * or the end of the line whichever comes first and advances past it. |
michael@0 | 100 | * Also stops at embedded nulls. |
michael@0 | 101 | * Returns the token or an empty string if the current character is a delimiter |
michael@0 | 102 | * or is at the end of the line. |
michael@0 | 103 | */ |
michael@0 | 104 | String8 nextToken(const char* delimiters); |
michael@0 | 105 | |
michael@0 | 106 | /** |
michael@0 | 107 | * Advances to the next line. |
michael@0 | 108 | * Does nothing if already at the end of the file. |
michael@0 | 109 | */ |
michael@0 | 110 | void nextLine(); |
michael@0 | 111 | |
michael@0 | 112 | /** |
michael@0 | 113 | * Skips over the specified delimiters in the line. |
michael@0 | 114 | * Also skips embedded nulls. |
michael@0 | 115 | */ |
michael@0 | 116 | void skipDelimiters(const char* delimiters); |
michael@0 | 117 | |
michael@0 | 118 | private: |
michael@0 | 119 | Tokenizer(const Tokenizer& other); // not copyable |
michael@0 | 120 | |
michael@0 | 121 | String8 mFilename; |
michael@0 | 122 | FileMap* mFileMap; |
michael@0 | 123 | char* mBuffer; |
michael@0 | 124 | bool mOwnBuffer; |
michael@0 | 125 | size_t mLength; |
michael@0 | 126 | |
michael@0 | 127 | const char* mCurrent; |
michael@0 | 128 | int32_t mLineNumber; |
michael@0 | 129 | |
michael@0 | 130 | inline const char* getEnd() const { return mBuffer + mLength; } |
michael@0 | 131 | |
michael@0 | 132 | }; |
michael@0 | 133 | |
michael@0 | 134 | } // namespace android |
michael@0 | 135 | |
michael@0 | 136 | #endif // _UTILS_TOKENIZER_H |