Bumping manifests a=b2g-bump
[gecko.git] / xpcom / glue / nsINIParser.h
blobef3e56b73411e7c76d786eebc199d3a7bc713804
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // This file was shamelessly copied from mozilla/xpinstall/wizard/unix/src2
9 #ifndef nsINIParser_h__
10 #define nsINIParser_h__
12 #ifdef MOZILLA_INTERNAL_API
13 #define nsINIParser nsINIParser_internal
14 #endif
16 #include "nscore.h"
17 #include "nsClassHashtable.h"
18 #include "nsAutoPtr.h"
20 #include <stdio.h>
22 class nsIFile;
24 class nsINIParser
26 public:
27 nsINIParser() {}
28 ~nsINIParser() {}
30 /**
31 * Initialize the INIParser with a nsIFile. If this method fails, no
32 * other methods should be called. This method reads and parses the file,
33 * the class does not hold a file handle open. An instance must only be
34 * initialized once.
36 nsresult Init(nsIFile* aFile);
38 /**
39 * Initialize the INIParser with a file path. If this method fails, no
40 * other methods should be called. This method reads and parses the file,
41 * the class does not hold a file handle open. An instance must only
42 * be initialized once.
44 nsresult Init(const char* aPath);
46 /**
47 * Callback for GetSections
48 * @return false to stop enumeration, or true to continue.
50 typedef bool (*INISectionCallback)(const char* aSection, void* aClosure);
52 /**
53 * Enumerate the sections within the INI file.
55 nsresult GetSections(INISectionCallback aCB, void* aClosure);
57 /**
58 * Callback for GetStrings
59 * @return false to stop enumeration, or true to continue
61 typedef bool (*INIStringCallback)(const char* aString, const char* aValue,
62 void* aClosure);
64 /**
65 * Enumerate the strings within a section. If the section does
66 * not exist, this function will silently return.
68 nsresult GetStrings(const char* aSection,
69 INIStringCallback aCB, void* aClosure);
71 /**
72 * Get the value of the specified key in the specified section
73 * of the INI file represented by this instance.
75 * @param aSection section name
76 * @param aKey key name
77 * @param aResult the value found
78 * @throws NS_ERROR_FAILURE if the specified section/key could not be
79 * found.
81 nsresult GetString(const char* aSection, const char* aKey,
82 nsACString& aResult);
84 /**
85 * Alternate signature of GetString that uses a pre-allocated buffer
86 * instead of a nsACString (for use in the standalone glue before
87 * the glue is initialized).
89 * @throws NS_ERROR_LOSS_OF_SIGNIFICANT_DATA if the aResult buffer is not
90 * large enough for the data. aResult will be filled with as
91 * much data as possible.
93 * @see GetString [1]
95 nsresult GetString(const char* aSection, const char* aKey,
96 char* aResult, uint32_t aResultLen);
98 private:
99 struct INIValue
101 INIValue(const char* aKey, const char* aValue)
102 : key(aKey)
103 , value(aValue)
107 const char* key;
108 const char* value;
109 nsAutoPtr<INIValue> next;
112 struct GSClosureStruct
114 INISectionCallback usercb;
115 void* userclosure;
118 nsClassHashtable<nsDepCharHashKey, INIValue> mSections;
119 nsAutoArrayPtr<char> mFileContents;
121 nsresult InitFromFILE(FILE* aFd);
123 static PLDHashOperator GetSectionsCB(const char* aKey,
124 INIValue* aData, void* aClosure);
127 #endif /* nsINIParser_h__ */