Comment on attachment 8613433 Allow .js preference files to set locked prefs with lockPref()
>From b8015e0754742650a4877de9ebe7d6db2671970d Mon Sep 17 00:00:00 2001 >From: Mike Hommey <email address hidden> >Date: Sat, 21 Jun 2008 02:48:46 +0200 >Subject: [PATCH] Allow .js preference files to set locked prefs with > lockPref() > >--- > modules/libpref/prefapi.cpp | 5 ++++- > modules/libpref/prefapi.h | 3 ++- > modules/libpref/prefread.cpp | 12 +++++++++--- > modules/libpref/prefread.h | 4 +++- > 4 files changed, 18 insertions(+), 6 deletions(-) > >diff --git a/modules/libpref/prefapi.cpp b/modules/libpref/prefapi.cpp >index e898433..081c922 100644 >--- a/modules/libpref/prefapi.cpp >+++ b/modules/libpref/prefapi.cpp >@@ -1002,16 +1002,19 @@ static nsresult pref_DoCallback(const char* changed_pref) > return rv; > } > > void PREF_ReaderCallback(void *closure, > const char *pref, > PrefValue value, > PrefType type, > bool isDefault, >- bool isStickyDefault) >+ bool isStickyDefault, >+ bool isLocked) > { > uint32_t flags = isDefault ? kPrefSetDefault : kPrefForceSet; > if (isDefault && isStickyDefault) { > flags |= kPrefStickyDefault; > } > pref_HashPref(pref, value, type, flags); >+ if (isLocked) >+ PREF_LockPref(pref, true); > } >diff --git a/modules/libpref/prefapi.h b/modules/libpref/prefapi.h >index f1e412a..24618a7 100644 >--- a/modules/libpref/prefapi.h >+++ b/modules/libpref/prefapi.h >@@ -181,14 +181,15 @@ nsresult PREF_UnregisterCallback( const char* domain, > /* > * Used by nsPrefService as the callback function of the 'pref' parser > */ > void PREF_ReaderCallback( void *closure, > const char *pref, > PrefValue value, > PrefType type, > bool isDefault, >- bool isStickyDefault); >+ bool isStickyDefault, >+ bool isLocked); > > #ifdef __cplusplus > } > #endif > #endif >diff --git a/modules/libpref/prefread.cpp b/modules/libpref/prefread.cpp >index 6c4d339..16c5057 100644 >--- a/modules/libpref/prefread.cpp >+++ b/modules/libpref/prefread.cpp >@@ -38,16 +38,17 @@ enum { > PREF_PARSE_UNTIL_EOL > }; > > #define UTF16_ESC_NUM_DIGITS 4 > #define HEX_ESC_NUM_DIGITS 2 > #define BITS_PER_HEX_DIGIT 4 > > static const char kUserPref[] = "user_pref"; >+static const char kLockPref[] = "lockPref"; > static const char kPref[] = "pref"; > static const char kPrefSticky[] = "sticky_pref"; > static const char kTrue[] = "true"; > static const char kFalse[] = "false"; > > /** > * pref_GrowBuf > * >@@ -126,17 +127,17 @@ pref_DoCallback(PrefParseState *ps) > break; > case PREF_BOOL: > value.boolVal = (ps->vb == kTrue); > break; > default: > break; > } > (*ps->reader)(ps->closure, ps->lb, value, ps->vtype, ps->fdefault, >- ps->fstickydefault); >+ ps->fstickydefault, ps->flock); > return true; > } > > void > PREF_InitParseState(PrefParseState *ps, PrefReader reader, void *closure) > { > memset(ps, 0, sizeof(*ps)); > ps->reader = reader; >@@ -186,29 +187,32 @@ PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen) > /* initial state */ > case PREF_PARSE_INIT: > if (ps->lbcur != ps->lb) { /* reset state */ > ps->lbcur = ps->lb; > ps->vb = nullptr; > ps->vtype = PREF_INVALID; > ps->fdefault = false; > ps->fstickydefault = false; >+ ps->flock = false; > } > switch (c) { > case '/': /* begin comment block or line? */ > state = PREF_PARSE_COMMENT_MAYBE_START; > break; > case '#': /* accept shell style comments */ > state = PREF_PARSE_UNTIL_EOL; > break; > case 'u': /* indicating user_pref */ > case 'p': /* indicating pref */ > case 's': /* indicating sticky_pref */ >+ case 'l': /* indicating lockPref */ > ps->smatch = (c == 'u' ? kUserPref : >- (c == 's' ? kPrefSticky : kPref)); >+ (c == 's' ? kPrefSticky : >+ (c == 'p' ? kPref : kLockPref))); > ps->sindex = 1; > ps->nextstate = PREF_PARSE_UNTIL_OPEN_PAREN; > state = PREF_PARSE_MATCH_STRING; > break; > /* else skip char */ > } > break; > >@@ -242,18 +246,20 @@ PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen) > } > else > *ps->lbcur++ = c; > break; > > /* name parsing */ > case PREF_PARSE_UNTIL_NAME: > if (c == '\"' || c == '\'') { >- ps->fdefault = (ps->smatch == kPref || ps->smatch == kPrefSticky); >+ ps->fdefault = (ps->smatch == kPref || ps->smatch == kPrefSticky >+ || ps->smatch == kLockPref); > ps->fstickydefault = (ps->smatch == kPrefSticky); >+ ps->flock = (ps->smatch == kLockPref); > ps->quotechar = c; > ps->nextstate = PREF_PARSE_UNTIL_COMMA; /* return here when done */ > state = PREF_PARSE_QUOTED_STRING; > } > else if (c == '/') { /* allow embedded comment */ > ps->nextstate = state; /* return here when done with comment */ > state = PREF_PARSE_COMMENT_MAYBE_START; > } >diff --git a/modules/libpref/prefread.h b/modules/libpref/prefread.h >index 3c317ff..0c13057 100644 >--- a/modules/libpref/prefread.h >+++ b/modules/libpref/prefread.h >@@ -29,17 +29,18 @@ extern "C" { > * @param stickyPref > * default preference marked as a "sticky" pref > */ > typedef void (*PrefReader)(void *closure, > const char *pref, > PrefValue val, > PrefType type, > bool defPref, >- bool stickyPref); >+ bool stickyPref, >+ bool lockPref); > > /* structure fields are private */ > typedef struct PrefParseState { > PrefReader reader; > void *closure; > int state; /* PREF_PARSE_... */ > int nextstate; /* sometimes used... */ > const char *smatch; /* string to match */ >@@ -51,16 +52,17 @@ typedef struct PrefParseState { > char quotechar; /* char delimiter for quotations */ > char *lb; /* line buffer (only allocation) */ > char *lbcur; /* line buffer cursor */ > char *lbend; /* line buffer end */ > char *vb; /* value buffer (ptr into lb) */ > PrefType vtype; /* PREF_STRING,INT,BOOL */ > bool fdefault; /* true if (default) pref */ > bool fstickydefault; /* true if (sticky) pref */ >+ bool flock; /* true if pref to be locked */ > } PrefParseState; > > /** > * PREF_InitParseState > * > * Called to initialize a PrefParseState instance. > * > * @param ps >-- >2.4.0.2.g36460d1.dirty >
Comment on attachment 8613433
Allow .js preference files to set locked prefs with lockPref()
>From b8015e075474265 0a4877de9ebe7d6 db2671970d Mon Sep 17 00:00:00 2001 libpref/ prefapi. cpp | 5 ++++- libpref/ prefapi. h | 3 ++- libpref/ prefread. cpp | 12 +++++++++--- libpref/ prefread. h | 4 +++- libpref/ prefapi. cpp b/modules/ libpref/ prefapi. cpp libpref/ prefapi. cpp libpref/ prefapi. cpp (const char* changed_pref) back(void *closure, libpref/ prefapi. h b/modules/ libpref/ prefapi. h libpref/ prefapi. h libpref/ prefapi. h Callback( const char* domain, back( void *closure, libpref/ prefread. cpp b/modules/ libpref/ prefread. cpp libpref/ prefread. cpp libpref/ prefread. cpp UNTIL_EOL NUM_DIGITS 4 (PrefParseState *ps) (ps->closure, ps->lb, value, ps->vtype, ps->fdefault, ult); tate(PrefParseS tate *ps, PrefReader reader, void *closure) PrefParseState *ps, const char *buf, int bufLen) COMMENT_ MAYBE_START; UNTIL_EOL; UNTIL_OPEN_ PAREN; MATCH_STRING; PrefParseState *ps, const char *buf, int bufLen) UNTIL_NAME: UNTIL_COMMA; /* return here when done */ QUOTED_ STRING; COMMENT_ MAYBE_START; libpref/ prefread. h b/modules/ libpref/ prefread. h libpref/ prefread. h libpref/ prefread. h INT,BOOL */ 2.g36460d1. dirty
>From: Mike Hommey <email address hidden>
>Date: Sat, 21 Jun 2008 02:48:46 +0200
>Subject: [PATCH] Allow .js preference files to set locked prefs with
> lockPref()
>
>---
> modules/
> modules/
> modules/
> modules/
> 4 files changed, 18 insertions(+), 6 deletions(-)
>
>diff --git a/modules/
>index e898433..081c922 100644
>--- a/modules/
>+++ b/modules/
>@@ -1002,16 +1002,19 @@ static nsresult pref_DoCallback
> return rv;
> }
>
> void PREF_ReaderCall
> const char *pref,
> PrefValue value,
> PrefType type,
> bool isDefault,
>- bool isStickyDefault)
>+ bool isStickyDefault,
>+ bool isLocked)
> {
> uint32_t flags = isDefault ? kPrefSetDefault : kPrefForceSet;
> if (isDefault && isStickyDefault) {
> flags |= kPrefStickyDefault;
> }
> pref_HashPref(pref, value, type, flags);
>+ if (isLocked)
>+ PREF_LockPref(pref, true);
> }
>diff --git a/modules/
>index f1e412a..24618a7 100644
>--- a/modules/
>+++ b/modules/
>@@ -181,14 +181,15 @@ nsresult PREF_Unregister
> /*
> * Used by nsPrefService as the callback function of the 'pref' parser
> */
> void PREF_ReaderCall
> const char *pref,
> PrefValue value,
> PrefType type,
> bool isDefault,
>- bool isStickyDefault);
>+ bool isStickyDefault,
>+ bool isLocked);
>
> #ifdef __cplusplus
> }
> #endif
> #endif
>diff --git a/modules/
>index 6c4d339..16c5057 100644
>--- a/modules/
>+++ b/modules/
>@@ -38,16 +38,17 @@ enum {
> PREF_PARSE_
> };
>
> #define UTF16_ESC_
> #define HEX_ESC_NUM_DIGITS 2
> #define BITS_PER_HEX_DIGIT 4
>
> static const char kUserPref[] = "user_pref";
>+static const char kLockPref[] = "lockPref";
> static const char kPref[] = "pref";
> static const char kPrefSticky[] = "sticky_pref";
> static const char kTrue[] = "true";
> static const char kFalse[] = "false";
>
> /**
> * pref_GrowBuf
> *
>@@ -126,17 +127,17 @@ pref_DoCallback
> break;
> case PREF_BOOL:
> value.boolVal = (ps->vb == kTrue);
> break;
> default:
> break;
> }
> (*ps->reader)
>- ps->fstickydefa
>+ ps->fstickydefault, ps->flock);
> return true;
> }
>
> void
> PREF_InitParseS
> {
> memset(ps, 0, sizeof(*ps));
> ps->reader = reader;
>@@ -186,29 +187,32 @@ PREF_ParseBuf(
> /* initial state */
> case PREF_PARSE_INIT:
> if (ps->lbcur != ps->lb) { /* reset state */
> ps->lbcur = ps->lb;
> ps->vb = nullptr;
> ps->vtype = PREF_INVALID;
> ps->fdefault = false;
> ps->fstickydefault = false;
>+ ps->flock = false;
> }
> switch (c) {
> case '/': /* begin comment block or line? */
> state = PREF_PARSE_
> break;
> case '#': /* accept shell style comments */
> state = PREF_PARSE_
> break;
> case 'u': /* indicating user_pref */
> case 'p': /* indicating pref */
> case 's': /* indicating sticky_pref */
>+ case 'l': /* indicating lockPref */
> ps->smatch = (c == 'u' ? kUserPref :
>- (c == 's' ? kPrefSticky : kPref));
>+ (c == 's' ? kPrefSticky :
>+ (c == 'p' ? kPref : kLockPref)));
> ps->sindex = 1;
> ps->nextstate = PREF_PARSE_
> state = PREF_PARSE_
> break;
> /* else skip char */
> }
> break;
>
>@@ -242,18 +246,20 @@ PREF_ParseBuf(
> }
> else
> *ps->lbcur++ = c;
> break;
>
> /* name parsing */
> case PREF_PARSE_
> if (c == '\"' || c == '\'') {
>- ps->fdefault = (ps->smatch == kPref || ps->smatch == kPrefSticky);
>+ ps->fdefault = (ps->smatch == kPref || ps->smatch == kPrefSticky
>+ || ps->smatch == kLockPref);
> ps->fstickydefault = (ps->smatch == kPrefSticky);
>+ ps->flock = (ps->smatch == kLockPref);
> ps->quotechar = c;
> ps->nextstate = PREF_PARSE_
> state = PREF_PARSE_
> }
> else if (c == '/') { /* allow embedded comment */
> ps->nextstate = state; /* return here when done with comment */
> state = PREF_PARSE_
> }
>diff --git a/modules/
>index 3c317ff..0c13057 100644
>--- a/modules/
>+++ b/modules/
>@@ -29,17 +29,18 @@ extern "C" {
> * @param stickyPref
> * default preference marked as a "sticky" pref
> */
> typedef void (*PrefReader)(void *closure,
> const char *pref,
> PrefValue val,
> PrefType type,
> bool defPref,
>- bool stickyPref);
>+ bool stickyPref,
>+ bool lockPref);
>
> /* structure fields are private */
> typedef struct PrefParseState {
> PrefReader reader;
> void *closure;
> int state; /* PREF_PARSE_... */
> int nextstate; /* sometimes used... */
> const char *smatch; /* string to match */
>@@ -51,16 +52,17 @@ typedef struct PrefParseState {
> char quotechar; /* char delimiter for quotations */
> char *lb; /* line buffer (only allocation) */
> char *lbcur; /* line buffer cursor */
> char *lbend; /* line buffer end */
> char *vb; /* value buffer (ptr into lb) */
> PrefType vtype; /* PREF_STRING,
> bool fdefault; /* true if (default) pref */
> bool fstickydefault; /* true if (sticky) pref */
>+ bool flock; /* true if pref to be locked */
> } PrefParseState;
>
> /**
> * PREF_InitParseState
> *
> * Called to initialize a PrefParseState instance.
> *
> * @param ps
>--
>2.4.0.
>