diff --git a/doc/xml/release.xml b/doc/xml/release.xml
index f859d5ab4..4d730ea17 100644
--- a/doc/xml/release.xml
+++ b/doc/xml/release.xml
@@ -32,6 +32,14 @@
Add uint64
variant type and supporting conversion functions.
+
+
+
+
+
+
+ Add iniSectionList()
to Ini
object and remove dead code.
+
diff --git a/src/common/ini.c b/src/common/ini.c
index 2b621e9e7..d614a1159 100644
--- a/src/common/ini.c
+++ b/src/common/ini.c
@@ -18,11 +18,10 @@ struct Ini
{
MemContext *memContext; // Context that contains the ini
KeyValue *store; // Key value store that contains the ini data
- String *fileName; // File name (if one has been set)
};
/***********************************************************************************************************************************
-Create a new string from a zero-terminated string
+Create a new Ini object
***********************************************************************************************************************************/
Ini *
iniNew()
@@ -99,8 +98,6 @@ iniGet(const Ini *this, const String *section, const String *key)
if (result == NULL)
THROW_FMT(FormatError, "section '%s', key '%s' does not exist", strPtr(section), strPtr(key));
- return result;
-
FUNCTION_TEST_RESULT(CONST_VARIANT, result);
}
@@ -152,7 +149,7 @@ iniSectionKeyList(const Ini *this, const String *section)
// Get the section
KeyValue *sectionKv = varKv(kvGet(this->store, varNewStr(section)));
- // Return key list of the section exists
+ // Return key list if the section exists
if (sectionKv != NULL)
result = strLstNewVarLst(kvKeyList(sectionKv));
// Otherwise return an empty list
@@ -166,6 +163,32 @@ iniSectionKeyList(const Ini *this, const String *section)
FUNCTION_TEST_RESULT(STRING_LIST, result);
}
+/***********************************************************************************************************************************
+Get a list of sections
+***********************************************************************************************************************************/
+StringList *
+iniSectionList(const Ini *this)
+{
+ FUNCTION_TEST_BEGIN();
+ FUNCTION_TEST_PARAM(INI, this);
+
+ FUNCTION_TEST_ASSERT(this != NULL);
+ FUNCTION_TEST_END();
+
+ StringList *result = NULL;
+
+ MEM_CONTEXT_TEMP_BEGIN()
+ {
+ // Get the sections from the keyList
+ result = strLstNewVarLst(kvKeyList(this->store));
+
+ strLstMove(result, MEM_CONTEXT_OLD());
+ }
+ MEM_CONTEXT_TEMP_END();
+
+ FUNCTION_TEST_RESULT(STRING_LIST, result);
+}
+
/***********************************************************************************************************************************
Parse ini from a string
***********************************************************************************************************************************/
@@ -248,36 +271,6 @@ iniParse(Ini *this, const String *content)
FUNCTION_TEST_RESULT_VOID();
}
-/***********************************************************************************************************************************
-Load ini from a file
-***********************************************************************************************************************************/
-void
-iniLoad(Ini *this, const String *fileName)
-{
- FUNCTION_TEST_BEGIN();
- FUNCTION_TEST_PARAM(INI, this);
- FUNCTION_TEST_PARAM(STRING, fileName);
-
- FUNCTION_TEST_ASSERT(this != NULL);
- FUNCTION_TEST_ASSERT(fileName != NULL);
- FUNCTION_TEST_END();
-
- MEM_CONTEXT_BEGIN(this->memContext)
- {
- // Set the filename
- this->fileName = strDup(fileName);
-
- MEM_CONTEXT_TEMP_BEGIN()
- {
- iniParse(this, strNewBuf(storageGetNP(storageNewReadNP(storageLocal(), this->fileName))));
- }
- MEM_CONTEXT_TEMP_END();
- }
- MEM_CONTEXT_END()
-
- FUNCTION_TEST_RESULT_VOID();
-}
-
/***********************************************************************************************************************************
Set an ini value
***********************************************************************************************************************************/
diff --git a/src/common/ini.h b/src/common/ini.h
index 42ea932e4..f5f3a2ef0 100644
--- a/src/common/ini.h
+++ b/src/common/ini.h
@@ -18,11 +18,12 @@ Ini *iniNew();
const Variant *iniGet(const Ini *this, const String *section, const String *key);
const Variant *iniGetDefault(const Ini *this, const String *section, const String *key, Variant *defaultValue);
StringList *iniSectionKeyList(const Ini *this, const String *section);
+StringList *iniSectionList(const Ini *this);
void iniParse(Ini *this, const String *content);
-void iniLoad(Ini *this, const String *fileName);
void iniSet(Ini *this, const String *section, const String *key, const Variant *value);
-
void iniFree(Ini *this);
+String *iniFileName(const Ini *this);
+bool iniFileExists(const Ini *this);
/***********************************************************************************************************************************
Macros for function logging
diff --git a/test/src/module/common/iniTest.c b/test/src/module/common/iniTest.c
index 36b1ed224..24fc942ae 100644
--- a/test/src/module/common/iniTest.c
+++ b/test/src/module/common/iniTest.c
@@ -23,7 +23,7 @@ testRun()
}
// *****************************************************************************************************************************
- if (testBegin("iniSet(), iniGet(), iniGetDefault(), and iniSectionKeyList()"))
+ if (testBegin("iniSet(), iniGet(), iniGetDefault(), iniSectionList(), and iniSectionKeyList()"))
{
Ini *ini = NULL;
@@ -44,11 +44,15 @@ testRun()
TEST_RESULT_INT(strLstSize(iniSectionKeyList(ini, strNew("bogus"))), 0, "get keys for missing section");
TEST_RESULT_STR(strPtr(strLstJoin(iniSectionKeyList(ini, strNew("section1")), "|")), "key1|key2", "get keys for section");
+ TEST_RESULT_VOID(iniSet(ini, strNew("section2"), strNew("key2"), varNewInt(2)), "set section2, key, int");
+ TEST_RESULT_INT(strLstSize(iniSectionList(ini)), 2, "number of sections");
+ TEST_RESULT_STR(strPtr(strLstJoin(iniSectionList(ini), "|")), "section1|section2", "get sections");
+
TEST_RESULT_VOID(iniFree(ini), "free ini");
}
// *****************************************************************************************************************************
- if (testBegin("iniParse() and iniLoad()"))
+ if (testBegin("iniParse()"))
{
Ini *ini = NULL;
String *content = NULL;
@@ -66,6 +70,7 @@ testRun()
content = strNew
(
+ "# Comment\n"
"[global] \n"
"compress=y \n"
"\n"
@@ -77,27 +82,6 @@ testRun()
TEST_RESULT_STR(strPtr(varStr(iniGet(ini, strNew("global"), strNew("compress")))), "y", "get compress");
TEST_RESULT_STR(strPtr(varStr(iniGet(ini, strNew("db"), strNew("pg1-path")))), "/path/to/pg", "get pg1-path");
-
- // -------------------------------------------------------------------------------------------------------------------------
- TEST_ASSIGN(ini, iniNew(), "new ini");
- String *fileName = strNewFmt("%s/test.ini", testPath());
-
- content = strNew
- (
- "# Comment\n"
- " [global]\n"
- " \n"
- " compress= y \n"
- "[db]\t\r\n"
- " pg1-path =/path/to/pg\n"
- "\n"
- );
-
- TEST_RESULT_VOID(storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), bufNewStr(content)), "put ini to file");
- TEST_RESULT_VOID(iniLoad(ini, fileName), "load ini from file");
-
- TEST_RESULT_STR(strPtr(varStr(iniGet(ini, strNew("global"), strNew("compress")))), "y", "get compress");
- TEST_RESULT_STR(strPtr(varStr(iniGet(ini, strNew("db"), strNew("pg1-path")))), "/path/to/pg", "get pg1-path");
}
FUNCTION_HARNESS_RESULT_VOID();