modules/libpref/src/prefapi.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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
michael@0 6 /*
michael@0 7 // <pre>
michael@0 8 */
michael@0 9 #ifndef PREFAPI_H
michael@0 10 #define PREFAPI_H
michael@0 11
michael@0 12 #include "nscore.h"
michael@0 13 #include "pldhash.h"
michael@0 14
michael@0 15 #ifdef __cplusplus
michael@0 16 extern "C" {
michael@0 17 #endif
michael@0 18
michael@0 19 // 1 MB should be enough for everyone.
michael@0 20 static const uint32_t MAX_PREF_LENGTH = 1 * 1024 * 1024;
michael@0 21 // Actually, 4kb should be enough for everyone.
michael@0 22 static const uint32_t MAX_ADVISABLE_PREF_LENGTH = 4 * 1024;
michael@0 23
michael@0 24 typedef union
michael@0 25 {
michael@0 26 char* stringVal;
michael@0 27 int32_t intVal;
michael@0 28 bool boolVal;
michael@0 29 } PrefValue;
michael@0 30
michael@0 31 struct PrefHashEntry : PLDHashEntryHdr
michael@0 32 {
michael@0 33 const char *key;
michael@0 34 PrefValue defaultPref;
michael@0 35 PrefValue userPref;
michael@0 36 uint16_t flags;
michael@0 37 };
michael@0 38
michael@0 39 /*
michael@0 40 // <font color=blue>
michael@0 41 // The Init function initializes the preference context and creates
michael@0 42 // the preference hashtable.
michael@0 43 // </font>
michael@0 44 */
michael@0 45 nsresult PREF_Init();
michael@0 46
michael@0 47 /*
michael@0 48 // Cleanup should be called at program exit to free the
michael@0 49 // list of registered callbacks.
michael@0 50 */
michael@0 51 void PREF_Cleanup();
michael@0 52 void PREF_CleanupPrefs();
michael@0 53
michael@0 54 /*
michael@0 55 // <font color=blue>
michael@0 56 // Preference flags, including the native type of the preference
michael@0 57 // </font>
michael@0 58 */
michael@0 59
michael@0 60 typedef enum { PREF_INVALID = 0,
michael@0 61 PREF_LOCKED = 1, PREF_USERSET = 2, PREF_CONFIG = 4, PREF_REMOTE = 8,
michael@0 62 PREF_LILOCAL = 16, PREF_STRING = 32, PREF_INT = 64, PREF_BOOL = 128,
michael@0 63 PREF_HAS_DEFAULT = 256,
michael@0 64 PREF_VALUETYPE_MASK = (PREF_STRING | PREF_INT | PREF_BOOL)
michael@0 65 } PrefType;
michael@0 66
michael@0 67 /*
michael@0 68 // <font color=blue>
michael@0 69 // Set the various types of preferences. These functions take a dotted
michael@0 70 // notation of the preference name (e.g. "browser.startup.homepage").
michael@0 71 // Note that this will cause the preference to be saved to the file if
michael@0 72 // it is different from the default. In other words, these are used
michael@0 73 // to set the _user_ preferences.
michael@0 74 //
michael@0 75 // If set_default is set to true however, it sets the default value.
michael@0 76 // This will only affect the program behavior if the user does not have a value
michael@0 77 // saved over it for the particular preference. In addition, these will never
michael@0 78 // be saved out to disk.
michael@0 79 //
michael@0 80 // Each set returns PREF_VALUECHANGED if the user value changed
michael@0 81 // (triggering a callback), or PREF_NOERROR if the value was unchanged.
michael@0 82 // </font>
michael@0 83 */
michael@0 84 nsresult PREF_SetCharPref(const char *pref,const char* value, bool set_default = false);
michael@0 85 nsresult PREF_SetIntPref(const char *pref,int32_t value, bool set_default = false);
michael@0 86 nsresult PREF_SetBoolPref(const char *pref,bool value, bool set_default = false);
michael@0 87
michael@0 88 bool PREF_HasUserPref(const char* pref_name);
michael@0 89
michael@0 90 /*
michael@0 91 // <font color=blue>
michael@0 92 // Get the various types of preferences. These functions take a dotted
michael@0 93 // notation of the preference name (e.g. "browser.startup.homepage")
michael@0 94 //
michael@0 95 // They also take a pointer to fill in with the return value and return an
michael@0 96 // error value. At the moment, this is simply an int but it may
michael@0 97 // be converted to an enum once the global error strategy is worked out.
michael@0 98 //
michael@0 99 // They will perform conversion if the type doesn't match what was requested.
michael@0 100 // (if it is reasonably possible)
michael@0 101 // </font>
michael@0 102 */
michael@0 103 nsresult PREF_GetIntPref(const char *pref,
michael@0 104 int32_t * return_int, bool get_default);
michael@0 105 nsresult PREF_GetBoolPref(const char *pref, bool * return_val, bool get_default);
michael@0 106 /*
michael@0 107 // <font color=blue>
michael@0 108 // These functions are similar to the above "Get" version with the significant
michael@0 109 // difference that the preference module will alloc the memory (e.g. XP_STRDUP) and
michael@0 110 // the caller will need to be responsible for freeing it...
michael@0 111 // </font>
michael@0 112 */
michael@0 113 nsresult PREF_CopyCharPref(const char *pref, char ** return_buf, bool get_default);
michael@0 114 /*
michael@0 115 // <font color=blue>
michael@0 116 // bool function that returns whether or not the preference is locked and therefore
michael@0 117 // cannot be changed.
michael@0 118 // </font>
michael@0 119 */
michael@0 120 bool PREF_PrefIsLocked(const char *pref_name);
michael@0 121
michael@0 122 /*
michael@0 123 // <font color=blue>
michael@0 124 // Function that sets whether or not the preference is locked and therefore
michael@0 125 // cannot be changed.
michael@0 126 // </font>
michael@0 127 */
michael@0 128 nsresult PREF_LockPref(const char *key, bool lockIt);
michael@0 129
michael@0 130 PrefType PREF_GetPrefType(const char *pref_name);
michael@0 131
michael@0 132 /*
michael@0 133 * Delete a branch of the tree
michael@0 134 */
michael@0 135 nsresult PREF_DeleteBranch(const char *branch_name);
michael@0 136
michael@0 137 /*
michael@0 138 * Clears the given pref (reverts it to its default value)
michael@0 139 */
michael@0 140 nsresult PREF_ClearUserPref(const char *pref_name);
michael@0 141
michael@0 142 /*
michael@0 143 * Clears all user prefs
michael@0 144 */
michael@0 145 nsresult PREF_ClearAllUserPrefs();
michael@0 146
michael@0 147
michael@0 148 /*
michael@0 149 // <font color=blue>
michael@0 150 // The callback function will get passed the pref_node which triggered the call
michael@0 151 // and the void * instance_data which was passed to the register callback function.
michael@0 152 // Return a non-zero result (nsresult) to pass an error up to the caller.
michael@0 153 // </font>
michael@0 154 */
michael@0 155 /* Temporarily conditionally compile PrefChangedFunc typedef.
michael@0 156 ** During migration from old libpref to nsIPref we need it in
michael@0 157 ** both header files. Eventually prefapi.h will become a private
michael@0 158 ** file. The two types need to be in sync for now. Certain
michael@0 159 ** compilers were having problems with multiple definitions.
michael@0 160 */
michael@0 161 #ifndef have_PrefChangedFunc_typedef
michael@0 162 typedef void (*PrefChangedFunc) (const char *, void *);
michael@0 163 #define have_PrefChangedFunc_typedef
michael@0 164 #endif
michael@0 165
michael@0 166 /*
michael@0 167 // <font color=blue>
michael@0 168 // Register a callback. This takes a node in the preference tree and will
michael@0 169 // call the callback function if anything below that node is modified.
michael@0 170 // Unregister returns PREF_NOERROR if a callback was found that
michael@0 171 // matched all the parameters; otherwise it returns PREF_ERROR.
michael@0 172 // </font>
michael@0 173 */
michael@0 174 void PREF_RegisterCallback( const char* domain,
michael@0 175 PrefChangedFunc callback, void* instance_data );
michael@0 176 nsresult PREF_UnregisterCallback( const char* domain,
michael@0 177 PrefChangedFunc callback, void* instance_data );
michael@0 178
michael@0 179 /*
michael@0 180 * Used by nsPrefService as the callback function of the 'pref' parser
michael@0 181 */
michael@0 182 void PREF_ReaderCallback( void *closure,
michael@0 183 const char *pref,
michael@0 184 PrefValue value,
michael@0 185 PrefType type,
michael@0 186 bool isDefault);
michael@0 187
michael@0 188 #ifdef __cplusplus
michael@0 189 }
michael@0 190 #endif
michael@0 191 #endif

mercurial