[Bug 623844]

Mh+mozilla 623844 at bugs.launchpad.net
Tue Jul 2 01:16:05 UTC 2019


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 <glandium at debian.org>
>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
>

-- 
You received this bug notification because you are a member of Mozilla
Bugs, which is subscribed to Mozilla Thunderbird.
https://bugs.launchpad.net/bugs/623844

Title:
  lockpref not honored in /etc/thunderbird/pref/thunderbird.js

To manage notifications about this bug go to:
https://bugs.launchpad.net/thunderbird/+bug/623844/+subscriptions



More information about the Ubuntu-mozillateam-bugs mailing list