xpcom/glue/nsINIParser.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.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 // This file was shamelessly copied from mozilla/xpinstall/wizard/unix/src2
     8 #ifndef nsINIParser_h__
     9 #define nsINIParser_h__
    11 #ifdef MOZILLA_INTERNAL_API
    12 #define nsINIParser nsINIParser_internal
    13 #endif
    15 #include "nscore.h"
    16 #include "nsClassHashtable.h"
    17 #include "nsAutoPtr.h"
    19 #include <stdio.h>
    21 class nsIFile;
    23 class NS_COM_GLUE nsINIParser
    24 {
    25 public:
    26     nsINIParser() { }
    27     ~nsINIParser() { }
    29     /**
    30      * Initialize the INIParser with a nsIFile. If this method fails, no
    31      * other methods should be called. This method reads and parses the file,
    32      * the class does not hold a file handle open. An instance must only be
    33      * initialized once.
    34      */
    35     nsresult Init(nsIFile* aFile);
    37     /**
    38      * Initialize the INIParser with a file path. If this method fails, no
    39      * other methods should be called. This method reads and parses the file,
    40      * the class does not hold a file handle open. An instance must only
    41      * be initialized once.
    42      */
    43     nsresult Init(const char *aPath);
    45     /**
    46      * Callback for GetSections
    47      * @return false to stop enumeration, or true to continue.
    48      */
    49     typedef bool
    50     (* INISectionCallback)(const char *aSection, void *aClosure);
    52     /**
    53      * Enumerate the sections within the INI file.
    54      */
    55     nsresult GetSections(INISectionCallback aCB, void *aClosure);
    57     /**
    58      * Callback for GetStrings
    59      * @return false to stop enumeration, or true to continue
    60      */
    61     typedef bool
    62     (* INIStringCallback)(const char *aString, const char *aValue,
    63                           void *aClosure);
    65     /**
    66      * Enumerate the strings within a section. If the section does
    67      * not exist, this function will silently return.
    68      */
    69     nsresult GetStrings(const char *aSection,
    70                         INIStringCallback aCB, void *aClosure);
    72     /**
    73      * Get the value of the specified key in the specified section
    74      * of the INI file represented by this instance.
    75      *
    76      * @param aSection      section name
    77      * @param aKey          key name
    78      * @param aResult       the value found
    79      * @throws NS_ERROR_FAILURE if the specified section/key could not be
    80      *                          found.
    81      */
    82     nsresult GetString(const char *aSection, const char *aKey, 
    83                        nsACString &aResult);
    85     /**
    86      * Alternate signature of GetString that uses a pre-allocated buffer
    87      * instead of a nsACString (for use in the standalone glue before
    88      * the glue is initialized).
    89      *
    90      * @throws NS_ERROR_LOSS_OF_SIGNIFICANT_DATA if the aResult buffer is not
    91      *         large enough for the data. aResult will be filled with as
    92      *         much data as possible.
    93      *         
    94      * @see GetString [1]
    95      */
    96     nsresult GetString(const char *aSection, const char* aKey,
    97                        char *aResult, uint32_t aResultLen);
    99 private:
   100     struct INIValue
   101     {
   102         INIValue(const char *aKey, const char *aValue)
   103             : key(aKey), value(aValue) { }
   105         const char *key;
   106         const char *value;
   107         nsAutoPtr<INIValue> next;
   108     };
   110     struct GSClosureStruct
   111     {
   112         INISectionCallback  usercb;
   113         void               *userclosure;
   114     };
   116     nsClassHashtable<nsDepCharHashKey, INIValue> mSections;
   117     nsAutoArrayPtr<char> mFileContents;    
   119     nsresult InitFromFILE(FILE *fd);
   121     static PLDHashOperator GetSectionsCB(const char *aKey,
   122                                          INIValue *aData, void *aClosure);
   123 };
   125 #endif /* nsINIParser_h__ */

mercurial