LibConfig - 如何获取容器列表

LibConfig - How to get container list

我有以下配置,我知道如何使用 config_lookup() 遍历每个部分,但我不知道如何找到每个部分的名称!

downloads = {

    john = {

        configid = 1;
        status = 1;
        configname = "John's File Server";
        configtype = 0;
        ipaddress = "192.168.1.100";
        username = "test";
        password = "test";
    };

    jill = {

        configid = 3;
        status = 1;
        configname = "Jill's file server";
        configtype = 0;
        ipaddress = "10.10.20.50";
        username = "test";
        password = "test";
    };
};

我想知道如何使用 libconfig 获取节名称,即 jack & jill。我知道如何获取 jack 和 jill 中的值,因为我事先知道参数名称,但 jack 和 jill 是用户配置的。缩短的代码是这样的-

config_t cfg;
config_setting_t *setting;
int i = 0, count = 0;

if(!config_read_file(&cfg, filename))
    return false;

if((setting = config_lookup(&cfg, "downloads")) != NULL)
{
    count = config_setting_length(setting);

    for(i = 0; i < count; ++i)
    {
        // do stuff
    }
}

config_destroy(&cfg);

知道怎么做吗?提前致谢

好的,既然 Ian 没有 post 回答,我就是。感谢 Ian。

config_t cfg;
config_setting_t *setting;
int i = 0, count = 0;

if(!config_read_file(&cfg, filename))
    return false;

if((setting = config_lookup(&cfg, "downloads")) != NULL)
{
    count = config_setting_length(setting);

    for(i = 0; i < count; ++i)
    {
        config_setting_t *nodes = config_setting_get_elem(setting, i);
        const char *section_name = = config_setting_name(nodes); // Section name, no need to free, the library manages that;
    }
}

config_destroy(&cfg);