2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
// <pre>
|
|
|
|
*/
|
|
|
|
#ifndef PREFAPI_H
|
|
|
|
#define PREFAPI_H
|
|
|
|
|
2003-09-23 21:57:22 +04:00
|
|
|
#include "nscore.h"
|
2001-12-04 04:52:44 +03:00
|
|
|
#include "pldhash.h"
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2012-10-01 06:10:22 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2014-01-22 00:51:05 +04:00
|
|
|
// 1 MB should be enough for everyone.
|
|
|
|
static const uint32_t MAX_PREF_LENGTH = 1 * 1024 * 1024;
|
|
|
|
// Actually, 4kb should be enough for everyone.
|
|
|
|
static const uint32_t MAX_ADVISABLE_PREF_LENGTH = 4 * 1024;
|
|
|
|
|
2001-12-04 04:52:44 +03:00
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
char* stringVal;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t intVal;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool boolVal;
|
2001-12-04 04:52:44 +03:00
|
|
|
} PrefValue;
|
|
|
|
|
|
|
|
struct PrefHashEntry : PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
const char *key;
|
|
|
|
PrefValue defaultPref;
|
|
|
|
PrefValue userPref;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t flags;
|
2001-12-04 04:52:44 +03:00
|
|
|
};
|
1999-01-13 05:32:09 +03:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/*
|
|
|
|
// <font color=blue>
|
2003-09-23 21:57:22 +04:00
|
|
|
// The Init function initializes the preference context and creates
|
|
|
|
// the preference hashtable.
|
1998-03-28 05:44:41 +03:00
|
|
|
// </font>
|
|
|
|
*/
|
2015-02-11 01:39:49 +03:00
|
|
|
nsresult PREF_Init();
|
1999-01-13 05:32:09 +03:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/*
|
|
|
|
// Cleanup should be called at program exit to free the
|
|
|
|
// list of registered callbacks.
|
|
|
|
*/
|
2003-09-23 21:57:22 +04:00
|
|
|
void PREF_Cleanup();
|
|
|
|
void PREF_CleanupPrefs();
|
1999-01-13 05:32:09 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
// <font color=blue>
|
|
|
|
// Preference flags, including the native type of the preference
|
|
|
|
// </font>
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum { PREF_INVALID = 0,
|
|
|
|
PREF_LOCKED = 1, PREF_USERSET = 2, PREF_CONFIG = 4, PREF_REMOTE = 8,
|
2011-08-23 06:15:52 +04:00
|
|
|
PREF_LILOCAL = 16, PREF_STRING = 32, PREF_INT = 64, PREF_BOOL = 128,
|
|
|
|
PREF_HAS_DEFAULT = 256,
|
2015-04-30 10:13:40 +03:00
|
|
|
// pref is default pref with "sticky" semantics
|
|
|
|
PREF_STICKY_DEFAULT = 512,
|
2011-08-23 06:15:52 +04:00
|
|
|
PREF_VALUETYPE_MASK = (PREF_STRING | PREF_INT | PREF_BOOL)
|
|
|
|
} PrefType;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
// <font color=blue>
|
|
|
|
// Set the various types of preferences. These functions take a dotted
|
|
|
|
// notation of the preference name (e.g. "browser.startup.homepage").
|
|
|
|
// Note that this will cause the preference to be saved to the file if
|
|
|
|
// it is different from the default. In other words, these are used
|
|
|
|
// to set the _user_ preferences.
|
2003-09-23 21:57:22 +04:00
|
|
|
//
|
2011-10-17 18:59:28 +04:00
|
|
|
// If set_default is set to true however, it sets the default value.
|
1998-03-28 05:44:41 +03:00
|
|
|
// This will only affect the program behavior if the user does not have a value
|
|
|
|
// saved over it for the particular preference. In addition, these will never
|
|
|
|
// be saved out to disk.
|
2003-09-23 21:57:22 +04:00
|
|
|
//
|
|
|
|
// Each set returns PREF_VALUECHANGED if the user value changed
|
|
|
|
// (triggering a callback), or PREF_NOERROR if the value was unchanged.
|
1998-03-28 05:44:41 +03:00
|
|
|
// </font>
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult PREF_SetCharPref(const char *pref,const char* value, bool set_default = false);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult PREF_SetIntPref(const char *pref,int32_t value, bool set_default = false);
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult PREF_SetBoolPref(const char *pref,bool value, bool set_default = false);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool PREF_HasUserPref(const char* pref_name);
|
2000-05-05 04:22:20 +04:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/*
|
|
|
|
// <font color=blue>
|
|
|
|
// Get the various types of preferences. These functions take a dotted
|
|
|
|
// notation of the preference name (e.g. "browser.startup.homepage")
|
|
|
|
//
|
|
|
|
// They also take a pointer to fill in with the return value and return an
|
|
|
|
// error value. At the moment, this is simply an int but it may
|
|
|
|
// be converted to an enum once the global error strategy is worked out.
|
|
|
|
//
|
|
|
|
// They will perform conversion if the type doesn't match what was requested.
|
|
|
|
// (if it is reasonably possible)
|
|
|
|
// </font>
|
|
|
|
*/
|
2003-09-23 21:57:22 +04:00
|
|
|
nsresult PREF_GetIntPref(const char *pref,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t * return_int, bool get_default);
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult PREF_GetBoolPref(const char *pref, bool * return_val, bool get_default);
|
1998-03-28 05:44:41 +03:00
|
|
|
/*
|
|
|
|
// <font color=blue>
|
|
|
|
// These functions are similar to the above "Get" version with the significant
|
|
|
|
// difference that the preference module will alloc the memory (e.g. XP_STRDUP) and
|
|
|
|
// the caller will need to be responsible for freeing it...
|
|
|
|
// </font>
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult PREF_CopyCharPref(const char *pref, char ** return_buf, bool get_default);
|
1998-03-28 05:44:41 +03:00
|
|
|
/*
|
|
|
|
// <font color=blue>
|
2011-09-29 10:19:26 +04:00
|
|
|
// bool function that returns whether or not the preference is locked and therefore
|
1998-03-28 05:44:41 +03:00
|
|
|
// cannot be changed.
|
|
|
|
// </font>
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool PREF_PrefIsLocked(const char *pref_name);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2003-09-23 21:57:22 +04:00
|
|
|
/*
|
|
|
|
// <font color=blue>
|
|
|
|
// Function that sets whether or not the preference is locked and therefore
|
|
|
|
// cannot be changed.
|
|
|
|
// </font>
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult PREF_LockPref(const char *key, bool lockIt);
|
2003-09-23 21:57:22 +04:00
|
|
|
|
2000-05-09 09:58:29 +04:00
|
|
|
PrefType PREF_GetPrefType(const char *pref_name);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a branch of the tree
|
|
|
|
*/
|
2003-09-23 21:57:22 +04:00
|
|
|
nsresult PREF_DeleteBranch(const char *branch_name);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clears the given pref (reverts it to its default value)
|
|
|
|
*/
|
2003-09-23 21:57:22 +04:00
|
|
|
nsresult PREF_ClearUserPref(const char *pref_name);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2001-01-10 23:25:52 +03:00
|
|
|
/*
|
|
|
|
* Clears all user prefs
|
|
|
|
*/
|
2003-09-23 21:57:22 +04:00
|
|
|
nsresult PREF_ClearAllUserPrefs();
|
2001-01-10 23:25:52 +03:00
|
|
|
|
1998-06-23 01:21:28 +04:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/*
|
|
|
|
// <font color=blue>
|
|
|
|
// The callback function will get passed the pref_node which triggered the call
|
|
|
|
// and the void * instance_data which was passed to the register callback function.
|
2003-09-23 21:57:22 +04:00
|
|
|
// Return a non-zero result (nsresult) to pass an error up to the caller.
|
1998-03-28 05:44:41 +03:00
|
|
|
// </font>
|
|
|
|
*/
|
1999-01-28 06:51:22 +03:00
|
|
|
/* Temporarily conditionally compile PrefChangedFunc typedef.
|
|
|
|
** During migration from old libpref to nsIPref we need it in
|
|
|
|
** both header files. Eventually prefapi.h will become a private
|
|
|
|
** file. The two types need to be in sync for now. Certain
|
|
|
|
** compilers were having problems with multiple definitions.
|
|
|
|
*/
|
2001-04-26 22:41:11 +04:00
|
|
|
#ifndef have_PrefChangedFunc_typedef
|
2013-12-11 03:10:01 +04:00
|
|
|
typedef void (*PrefChangedFunc) (const char *, void *);
|
2001-04-26 22:41:11 +04:00
|
|
|
#define have_PrefChangedFunc_typedef
|
|
|
|
#endif
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
// <font color=blue>
|
|
|
|
// Register a callback. This takes a node in the preference tree and will
|
|
|
|
// call the callback function if anything below that node is modified.
|
|
|
|
// Unregister returns PREF_NOERROR if a callback was found that
|
|
|
|
// matched all the parameters; otherwise it returns PREF_ERROR.
|
|
|
|
// </font>
|
|
|
|
*/
|
2000-05-09 09:58:29 +04:00
|
|
|
void PREF_RegisterCallback( const char* domain,
|
1998-03-28 05:44:41 +03:00
|
|
|
PrefChangedFunc callback, void* instance_data );
|
2003-09-23 21:57:22 +04:00
|
|
|
nsresult PREF_UnregisterCallback( const char* domain,
|
1998-03-28 05:44:41 +03:00
|
|
|
PrefChangedFunc callback, void* instance_data );
|
|
|
|
|
2003-09-23 21:57:22 +04:00
|
|
|
/*
|
|
|
|
* Used by nsPrefService as the callback function of the 'pref' parser
|
|
|
|
*/
|
|
|
|
void PREF_ReaderCallback( void *closure,
|
|
|
|
const char *pref,
|
|
|
|
PrefValue value,
|
|
|
|
PrefType type,
|
2015-04-30 10:13:40 +03:00
|
|
|
bool isDefault,
|
|
|
|
bool isStickyDefault);
|
2003-09-23 21:57:22 +04:00
|
|
|
|
2012-10-01 06:10:22 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
1998-03-28 05:44:41 +03:00
|
|
|
#endif
|