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 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | |
michael@0 | 6 | // This file was shamelessly copied from mozilla/xpinstall/wizard/unix/src2 |
michael@0 | 7 | |
michael@0 | 8 | #ifndef nsINIParser_h__ |
michael@0 | 9 | #define nsINIParser_h__ |
michael@0 | 10 | |
michael@0 | 11 | #ifdef MOZILLA_INTERNAL_API |
michael@0 | 12 | #define nsINIParser nsINIParser_internal |
michael@0 | 13 | #endif |
michael@0 | 14 | |
michael@0 | 15 | #include "nscore.h" |
michael@0 | 16 | #include "nsClassHashtable.h" |
michael@0 | 17 | #include "nsAutoPtr.h" |
michael@0 | 18 | |
michael@0 | 19 | #include <stdio.h> |
michael@0 | 20 | |
michael@0 | 21 | class nsIFile; |
michael@0 | 22 | |
michael@0 | 23 | class NS_COM_GLUE nsINIParser |
michael@0 | 24 | { |
michael@0 | 25 | public: |
michael@0 | 26 | nsINIParser() { } |
michael@0 | 27 | ~nsINIParser() { } |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * Initialize the INIParser with a nsIFile. If this method fails, no |
michael@0 | 31 | * other methods should be called. This method reads and parses the file, |
michael@0 | 32 | * the class does not hold a file handle open. An instance must only be |
michael@0 | 33 | * initialized once. |
michael@0 | 34 | */ |
michael@0 | 35 | nsresult Init(nsIFile* aFile); |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * Initialize the INIParser with a file path. If this method fails, no |
michael@0 | 39 | * other methods should be called. This method reads and parses the file, |
michael@0 | 40 | * the class does not hold a file handle open. An instance must only |
michael@0 | 41 | * be initialized once. |
michael@0 | 42 | */ |
michael@0 | 43 | nsresult Init(const char *aPath); |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Callback for GetSections |
michael@0 | 47 | * @return false to stop enumeration, or true to continue. |
michael@0 | 48 | */ |
michael@0 | 49 | typedef bool |
michael@0 | 50 | (* INISectionCallback)(const char *aSection, void *aClosure); |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * Enumerate the sections within the INI file. |
michael@0 | 54 | */ |
michael@0 | 55 | nsresult GetSections(INISectionCallback aCB, void *aClosure); |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * Callback for GetStrings |
michael@0 | 59 | * @return false to stop enumeration, or true to continue |
michael@0 | 60 | */ |
michael@0 | 61 | typedef bool |
michael@0 | 62 | (* INIStringCallback)(const char *aString, const char *aValue, |
michael@0 | 63 | void *aClosure); |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * Enumerate the strings within a section. If the section does |
michael@0 | 67 | * not exist, this function will silently return. |
michael@0 | 68 | */ |
michael@0 | 69 | nsresult GetStrings(const char *aSection, |
michael@0 | 70 | INIStringCallback aCB, void *aClosure); |
michael@0 | 71 | |
michael@0 | 72 | /** |
michael@0 | 73 | * Get the value of the specified key in the specified section |
michael@0 | 74 | * of the INI file represented by this instance. |
michael@0 | 75 | * |
michael@0 | 76 | * @param aSection section name |
michael@0 | 77 | * @param aKey key name |
michael@0 | 78 | * @param aResult the value found |
michael@0 | 79 | * @throws NS_ERROR_FAILURE if the specified section/key could not be |
michael@0 | 80 | * found. |
michael@0 | 81 | */ |
michael@0 | 82 | nsresult GetString(const char *aSection, const char *aKey, |
michael@0 | 83 | nsACString &aResult); |
michael@0 | 84 | |
michael@0 | 85 | /** |
michael@0 | 86 | * Alternate signature of GetString that uses a pre-allocated buffer |
michael@0 | 87 | * instead of a nsACString (for use in the standalone glue before |
michael@0 | 88 | * the glue is initialized). |
michael@0 | 89 | * |
michael@0 | 90 | * @throws NS_ERROR_LOSS_OF_SIGNIFICANT_DATA if the aResult buffer is not |
michael@0 | 91 | * large enough for the data. aResult will be filled with as |
michael@0 | 92 | * much data as possible. |
michael@0 | 93 | * |
michael@0 | 94 | * @see GetString [1] |
michael@0 | 95 | */ |
michael@0 | 96 | nsresult GetString(const char *aSection, const char* aKey, |
michael@0 | 97 | char *aResult, uint32_t aResultLen); |
michael@0 | 98 | |
michael@0 | 99 | private: |
michael@0 | 100 | struct INIValue |
michael@0 | 101 | { |
michael@0 | 102 | INIValue(const char *aKey, const char *aValue) |
michael@0 | 103 | : key(aKey), value(aValue) { } |
michael@0 | 104 | |
michael@0 | 105 | const char *key; |
michael@0 | 106 | const char *value; |
michael@0 | 107 | nsAutoPtr<INIValue> next; |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | struct GSClosureStruct |
michael@0 | 111 | { |
michael@0 | 112 | INISectionCallback usercb; |
michael@0 | 113 | void *userclosure; |
michael@0 | 114 | }; |
michael@0 | 115 | |
michael@0 | 116 | nsClassHashtable<nsDepCharHashKey, INIValue> mSections; |
michael@0 | 117 | nsAutoArrayPtr<char> mFileContents; |
michael@0 | 118 | |
michael@0 | 119 | nsresult InitFromFILE(FILE *fd); |
michael@0 | 120 | |
michael@0 | 121 | static PLDHashOperator GetSectionsCB(const char *aKey, |
michael@0 | 122 | INIValue *aData, void *aClosure); |
michael@0 | 123 | }; |
michael@0 | 124 | |
michael@0 | 125 | #endif /* nsINIParser_h__ */ |