Tue, 06 Jan 2015 21:39:09 +0100
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 | /* 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 nsCRTGlue_h__ |
michael@0 | 6 | #define nsCRTGlue_h__ |
michael@0 | 7 | |
michael@0 | 8 | #include "nscore.h" |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * Scan a string for the first character that is *not* in a set of |
michael@0 | 12 | * delimiters. If the string is only delimiter characters, the end of the |
michael@0 | 13 | * string is returned. |
michael@0 | 14 | * |
michael@0 | 15 | * @param delims The set of delimiters (null-terminated) |
michael@0 | 16 | * @param str The string to search (null-terminated) |
michael@0 | 17 | */ |
michael@0 | 18 | NS_COM_GLUE const char* |
michael@0 | 19 | NS_strspnp(const char *delims, const char *str); |
michael@0 | 20 | |
michael@0 | 21 | /** |
michael@0 | 22 | * Tokenize a string. This function is similar to the strtok function in the |
michael@0 | 23 | * C standard library, but it does not use static variables to maintain state |
michael@0 | 24 | * and is therefore thread and reentrancy-safe. |
michael@0 | 25 | * |
michael@0 | 26 | * Any leading delimiters in str are skipped. Then the string is scanned |
michael@0 | 27 | * until an additional delimiter or end-of-string is found. The final |
michael@0 | 28 | * delimiter is set to '\0'. |
michael@0 | 29 | * |
michael@0 | 30 | * @param delims The set of delimiters. |
michael@0 | 31 | * @param str The string to search. This is an in-out parameter; it is |
michael@0 | 32 | * reset to the end of the found token + 1, or to the |
michael@0 | 33 | * end-of-string if there are no more tokens. |
michael@0 | 34 | * @return The token. If no token is found (the string is only |
michael@0 | 35 | * delimiter characters), nullptr is returned. |
michael@0 | 36 | */ |
michael@0 | 37 | NS_COM_GLUE char* |
michael@0 | 38 | NS_strtok(const char *delims, char **str); |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * "strlen" for char16_t strings |
michael@0 | 42 | */ |
michael@0 | 43 | NS_COM_GLUE uint32_t |
michael@0 | 44 | NS_strlen(const char16_t *aString); |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * "strcmp" for char16_t strings |
michael@0 | 48 | */ |
michael@0 | 49 | NS_COM_GLUE int |
michael@0 | 50 | NS_strcmp(const char16_t *a, const char16_t *b); |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * "strdup" for char16_t strings, uses the NS_Alloc allocator. |
michael@0 | 54 | */ |
michael@0 | 55 | NS_COM_GLUE char16_t* |
michael@0 | 56 | NS_strdup(const char16_t *aString); |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * "strdup", but using the NS_Alloc allocator. |
michael@0 | 60 | */ |
michael@0 | 61 | NS_COM_GLUE char* |
michael@0 | 62 | NS_strdup(const char *aString); |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * strndup for char16_t strings... this function will ensure that the |
michael@0 | 66 | * new string is null-terminated. Uses the NS_Alloc allocator. |
michael@0 | 67 | */ |
michael@0 | 68 | NS_COM_GLUE char16_t* |
michael@0 | 69 | NS_strndup(const char16_t *aString, uint32_t aLen); |
michael@0 | 70 | |
michael@0 | 71 | // The following case-conversion methods only deal in the ascii repertoire |
michael@0 | 72 | // A-Z and a-z |
michael@0 | 73 | |
michael@0 | 74 | // semi-private data declarations... don't use these directly. |
michael@0 | 75 | class NS_COM_GLUE nsLowerUpperUtils { |
michael@0 | 76 | public: |
michael@0 | 77 | static const unsigned char kLower2Upper[256]; |
michael@0 | 78 | static const unsigned char kUpper2Lower[256]; |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | inline char NS_ToUpper(char aChar) |
michael@0 | 82 | { |
michael@0 | 83 | return (char)nsLowerUpperUtils::kLower2Upper[(unsigned char)aChar]; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | inline char NS_ToLower(char aChar) |
michael@0 | 87 | { |
michael@0 | 88 | return (char)nsLowerUpperUtils::kUpper2Lower[(unsigned char)aChar]; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | NS_COM_GLUE bool NS_IsUpper(char aChar); |
michael@0 | 92 | NS_COM_GLUE bool NS_IsLower(char aChar); |
michael@0 | 93 | |
michael@0 | 94 | NS_COM_GLUE bool NS_IsAscii(char16_t aChar); |
michael@0 | 95 | NS_COM_GLUE bool NS_IsAscii(const char16_t* aString); |
michael@0 | 96 | NS_COM_GLUE bool NS_IsAsciiAlpha(char16_t aChar); |
michael@0 | 97 | NS_COM_GLUE bool NS_IsAsciiDigit(char16_t aChar); |
michael@0 | 98 | NS_COM_GLUE bool NS_IsAsciiWhitespace(char16_t aChar); |
michael@0 | 99 | NS_COM_GLUE bool NS_IsAscii(const char* aString); |
michael@0 | 100 | NS_COM_GLUE bool NS_IsAscii(const char* aString, uint32_t aLength); |
michael@0 | 101 | |
michael@0 | 102 | #ifndef XPCOM_GLUE_AVOID_NSPR |
michael@0 | 103 | NS_COM_GLUE void NS_MakeRandomString(char *buf, int32_t bufLen); |
michael@0 | 104 | #endif |
michael@0 | 105 | |
michael@0 | 106 | #define FF '\f' |
michael@0 | 107 | #define TAB '\t' |
michael@0 | 108 | |
michael@0 | 109 | #define CRSTR "\015" |
michael@0 | 110 | #define LFSTR "\012" |
michael@0 | 111 | #define CRLF "\015\012" /* A CR LF equivalent string */ |
michael@0 | 112 | |
michael@0 | 113 | // We use the most restrictive filesystem as our default set of illegal filename |
michael@0 | 114 | // characters. This is currently Windows. |
michael@0 | 115 | #define OS_FILE_ILLEGAL_CHARACTERS "/:*?\"<>|" |
michael@0 | 116 | // We also provide a list of all known file path separators for all filesystems. |
michael@0 | 117 | // This can be used in replacement of FILE_PATH_SEPARATOR when you need to |
michael@0 | 118 | // identify or replace all known path separators. |
michael@0 | 119 | #define KNOWN_PATH_SEPARATORS "\\/" |
michael@0 | 120 | |
michael@0 | 121 | #if defined(XP_MACOSX) |
michael@0 | 122 | #define FILE_PATH_SEPARATOR "/" |
michael@0 | 123 | #elif defined(XP_WIN) |
michael@0 | 124 | #define FILE_PATH_SEPARATOR "\\" |
michael@0 | 125 | #elif defined(XP_UNIX) |
michael@0 | 126 | #define FILE_PATH_SEPARATOR "/" |
michael@0 | 127 | #else |
michael@0 | 128 | #error need_to_define_your_file_path_separator_and_maybe_illegal_characters |
michael@0 | 129 | #endif |
michael@0 | 130 | |
michael@0 | 131 | // Not all these control characters are illegal in all OSs, but we don't really |
michael@0 | 132 | // want them appearing in filenames |
michael@0 | 133 | #define CONTROL_CHARACTERS "\001\002\003\004\005\006\007" \ |
michael@0 | 134 | "\010\011\012\013\014\015\016\017" \ |
michael@0 | 135 | "\020\021\022\023\024\025\026\027" \ |
michael@0 | 136 | "\030\031\032\033\034\035\036\037" |
michael@0 | 137 | |
michael@0 | 138 | #define FILE_ILLEGAL_CHARACTERS CONTROL_CHARACTERS OS_FILE_ILLEGAL_CHARACTERS |
michael@0 | 139 | |
michael@0 | 140 | #endif // nsCRTGlue_h__ |