xpcom/glue/nsCRTGlue.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.

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

mercurial