Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / xpcom / glue / nsINIParser.h
blob3fbb2aaa966fef71082313e9e4024897281e7f45
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Samir Gehani <sgehani@netscape.com>
25 * Benjamin Smedberg <bsmedberg@covad.net>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 // This file was shamelessly copied from mozilla/xpinstall/wizard/unix/src2
43 #ifndef nsINIParser_h__
44 #define nsINIParser_h__
46 #ifdef MOZILLA_INTERNAL_API
47 #define nsINIParser nsINIParser_internal
48 #endif
50 #include "nscore.h"
51 #include "nsClassHashtable.h"
52 #include "nsAutoPtr.h"
54 #include <stdio.h>
56 class nsILocalFile;
58 class NS_COM_GLUE nsINIParser
60 public:
61 nsINIParser() { }
62 ~nsINIParser() { }
64 /**
65 * Initialize the INIParser with a nsILocalFile. If this method fails, no
66 * other methods should be called. This method reads and parses the file,
67 * the class does not hold a file handle open. An instance must only be
68 * initialized once.
70 nsresult Init(nsILocalFile* aFile);
72 /**
73 * Initialize the INIParser with a file path. If this method fails, no
74 * other methods should be called. This method reads and parses the file,
75 * the class does not hold a file handle open. An instance must only
76 * be initialized once.
78 nsresult Init(const char *aPath);
80 /**
81 * Callback for GetSections
82 * @return PR_FALSE to stop enumeration, or PR_TRUE to continue.
84 typedef PRBool
85 (* INISectionCallback)(const char *aSection, void *aClosure);
87 /**
88 * Enumerate the sections within the INI file.
90 nsresult GetSections(INISectionCallback aCB, void *aClosure);
92 /**
93 * Callback for GetStrings
94 * @return PR_FALSE to stop enumeration, or PR_TRUE to continue
96 typedef PRBool
97 (* INIStringCallback)(const char *aString, const char *aValue,
98 void *aClosure);
101 * Enumerate the strings within a section. If the section does
102 * not exist, this function will silently return.
104 nsresult GetStrings(const char *aSection,
105 INIStringCallback aCB, void *aClosure);
108 * Get the value of the specified key in the specified section
109 * of the INI file represented by this instance.
111 * @param aSection section name
112 * @param aKey key name
113 * @param aResult the value found
114 * @throws NS_ERROR_FAILURE if the specified section/key could not be
115 * found.
117 nsresult GetString(const char *aSection, const char *aKey,
118 nsACString &aResult);
121 * Alternate signature of GetString that uses a pre-allocated buffer
122 * instead of a nsACString (for use in the standalone glue before
123 * the glue is initialized).
125 * @throws NS_ERROR_LOSS_OF_SIGNIFICANT_DATA if the aResult buffer is not
126 * large enough for the data. aResult will be filled with as
127 * much data as possible.
129 * @see GetString [1]
131 nsresult GetString(const char *aSection, const char* aKey,
132 char *aResult, PRUint32 aResultLen);
134 private:
135 struct INIValue
137 INIValue(const char *aKey, const char *aValue)
138 : key(aKey), value(aValue) { }
140 const char *key;
141 const char *value;
142 nsAutoPtr<INIValue> next;
145 struct GSClosureStruct
147 INISectionCallback usercb;
148 void *userclosure;
151 nsClassHashtable<nsDepCharHashKey, INIValue> mSections;
152 nsAutoArrayPtr<char> mFileContents;
154 nsresult InitFromFILE(FILE *fd);
156 static PLDHashOperator GetSectionsCB(const char *aKey,
157 INIValue *aData, void *aClosure);
160 #endif /* nsINIParser_h__ */