modules/libpref/src/prefread.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef prefread_h__
     6 #define prefread_h__
     8 #include "prefapi.h"
    10 #ifdef __cplusplus
    11 extern "C" {
    12 #endif
    14 /**
    15  * Callback function used to notify consumer of preference name value pairs.
    16  * The pref name and value must be copied by the implementor of the callback
    17  * if they are needed beyond the scope of the callback function.
    18  *
    19  * @param closure
    20  *        user data passed to PREF_InitParseState
    21  * @param pref
    22  *        preference name
    23  * @param val
    24  *        preference value
    25  * @param type
    26  *        preference type (PREF_STRING, PREF_INT, or PREF_BOOL)
    27  * @param defPref
    28  *        preference type (true: default, false: user preference)
    29  */
    30 typedef void (*PrefReader)(void       *closure,
    31                            const char *pref,
    32                            PrefValue   val,
    33                            PrefType    type,
    34                            bool        defPref);
    36 /* structure fields are private */
    37 typedef struct PrefParseState {
    38     PrefReader  reader;
    39     void       *closure;
    40     int         state;      /* PREF_PARSE_...                */
    41     int         nextstate;  /* sometimes used...             */
    42     const char *smatch;     /* string to match               */
    43     int         sindex;     /* next char of smatch to check  */
    44                             /* also, counter in \u parsing   */
    45     char16_t   utf16[2];   /* parsing UTF16  (\u) escape    */
    46     int         esclen;     /* length in esctmp              */
    47     char        esctmp[6];  /* raw escape to put back if err */
    48     char        quotechar;  /* char delimiter for quotations */
    49     char       *lb;         /* line buffer (only allocation) */
    50     char       *lbcur;      /* line buffer cursor            */
    51     char       *lbend;      /* line buffer end               */
    52     char       *vb;         /* value buffer (ptr into lb)    */
    53     PrefType    vtype;      /* PREF_STRING,INT,BOOL          */
    54     bool        fdefault;   /* true if (default) pref     */
    55 } PrefParseState;
    57 /**
    58  * PREF_InitParseState
    59  *
    60  * Called to initialize a PrefParseState instance.
    61  * 
    62  * @param ps
    63  *        PrefParseState instance.
    64  * @param reader
    65  *        PrefReader callback function, which will be called once for each
    66  *        preference name value pair extracted.
    67  * @param closure
    68  *        PrefReader closure.
    69  */
    70 void PREF_InitParseState(PrefParseState *ps, PrefReader reader, void *closure);
    72 /**
    73  * PREF_FinalizeParseState
    74  *
    75  * Called to release any memory in use by the PrefParseState instance.
    76  *
    77  * @param ps
    78  *        PrefParseState instance.
    79  */        
    80 void PREF_FinalizeParseState(PrefParseState *ps);
    82 /**
    83  * PREF_ParseBuf
    84  *
    85  * Called to parse a buffer containing some portion of a preference file.  This
    86  * function may be called repeatedly as new data is made available.  The
    87  * PrefReader callback function passed PREF_InitParseState will be called as
    88  * preference name value pairs are extracted from the data.
    89  *
    90  * @param ps
    91  *        PrefParseState instance.  Must have been initialized.
    92  * @param buf
    93  *        Raw buffer containing data to be parsed.
    94  * @param bufLen
    95  *        Length of buffer.
    96  *
    97  * @return false if buffer contains malformed content.
    98  */
    99 bool PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen);
   101 #ifdef __cplusplus
   102 }
   103 #endif
   104 #endif /* prefread_h__ */

mercurial