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
15 * The Original Code is Mozilla Communicator client code, released
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.
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
51 #include "nsClassHashtable.h"
52 #include "nsAutoPtr.h"
58 class NS_COM_GLUE nsINIParser
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
70 nsresult
Init(nsILocalFile
* aFile
);
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
);
81 * Callback for GetSections
82 * @return PR_FALSE to stop enumeration, or PR_TRUE to continue.
85 (* PR_CALLBACK INISectionCallback
)(const char *aSection
,
89 * Enumerate the sections within the INI file.
91 nsresult
GetSections(INISectionCallback aCB
, void *aClosure
);
94 * Callback for GetStrings
95 * @return PR_FALSE to stop enumeration, or PR_TRUE to continue
98 (* PR_CALLBACK INIStringCallback
)(const char *aString
,
103 * Enumerate the strings within a section. If the section does
104 * not exist, this function will silently return.
106 nsresult
GetStrings(const char *aSection
,
107 INIStringCallback aCB
, void *aClosure
);
110 * Get the value of the specified key in the specified section
111 * of the INI file represented by this instance.
113 * @param aSection section name
114 * @param aKey key name
115 * @param aResult the value found
116 * @throws NS_ERROR_FAILURE if the specified section/key could not be
119 nsresult
GetString(const char *aSection
, const char *aKey
,
120 nsACString
&aResult
);
123 * Alternate signature of GetString that uses a pre-allocated buffer
124 * instead of a nsACString (for use in the standalone glue before
125 * the glue is initialized).
127 * @throws NS_ERROR_LOSS_OF_SIGNIFICANT_DATA if the aResult buffer is not
128 * large enough for the data. aResult will be filled with as
129 * much data as possible.
133 nsresult
GetString(const char *aSection
, const char* aKey
,
134 char *aResult
, PRUint32 aResultLen
);
139 INIValue(const char *aKey
, const char *aValue
)
140 : key(aKey
), value(aValue
) { }
144 nsAutoPtr
<INIValue
> next
;
147 struct GSClosureStruct
149 INISectionCallback usercb
;
153 nsClassHashtable
<nsDepCharHashKey
, INIValue
> mSections
;
154 nsAutoArrayPtr
<char> mFileContents
;
156 nsresult
InitFromFILE(FILE *fd
);
158 static PLDHashOperator
GetSectionsCB(const char *aKey
,
159 INIValue
*aData
, void *aClosure
);
162 #endif /* nsINIParser_h__ */