diff options
author | Dmitri Pal <dpal@redhat.com> | 2012-09-25 16:05:12 -0400 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-10-17 14:02:52 +0200 |
commit | d18cb68d460e377716e9cc510ce6802403f933a5 (patch) | |
tree | 366e7d33115a1ece41485526be1ca3a7d9604e61 | |
parent | f4ee2d445f96272726c7ff91a64fbe806691a3f9 (diff) | |
download | ding-libs2-d18cb68d460e377716e9cc510ce6802403f933a5.tar.gz ding-libs2-d18cb68d460e377716e9cc510ce6802403f933a5.tar.xz ding-libs2-d18cb68d460e377716e9cc510ce6802403f933a5.zip |
Add a search state to the config object
The search state allows one to search a configuration object
for the same key in the cases when a key permits more
than one value scattered across the config file.
The state needs to be stored, initialized and properly cleaned.
-rw-r--r-- | ini/ini_config_priv.h | 7 | ||||
-rw-r--r-- | ini/ini_configobj.c | 33 |
2 files changed, 40 insertions, 0 deletions
diff --git a/ini/ini_config_priv.h b/ini/ini_config_priv.h index e714774..5d994f9 100644 --- a/ini/ini_config_priv.h +++ b/ini/ini_config_priv.h @@ -33,6 +33,13 @@ struct ini_cfgobj { struct collection_item *cfg; /* Boundary */ uint32_t boundary; + /* Last search state */ + char *section; + char *name; + int section_len; + int name_len; + struct collection_iterator *iterator; + /*... */ /* Statistics? Timestamps? When created? Modified? - TBD */ /*... */ diff --git a/ini/ini_configobj.c b/ini/ini_configobj.c index 538541f..193474b 100644 --- a/ini/ini_configobj.c +++ b/ini/ini_configobj.c @@ -56,11 +56,34 @@ void ini_cleanup_cb(const char *property, TRACE_FLOW_EXIT(); } +/* Clean the search state */ +void ini_config_clean_state(struct ini_cfgobj *ini_config) +{ + TRACE_FLOW_ENTRY(); + + if (ini_config) { + if (ini_config->iterator) col_unbind_iterator(ini_config->iterator); + ini_config->iterator = NULL; + free(ini_config->section); + ini_config->section = NULL; + free(ini_config->name); + ini_config->name = NULL; + ini_config->section_len = 0; + ini_config->name_len = 0; + } + + TRACE_FLOW_EXIT(); +} + + + /* Traverse the collection and clean the object */ void ini_config_destroy(struct ini_cfgobj *ini_config) { TRACE_FLOW_ENTRY(); + ini_config_clean_state(ini_config); + if (ini_config) { if(ini_config->cfg) { @@ -97,6 +120,11 @@ int ini_config_create(struct ini_cfgobj **ini_config) new_co->cfg = NULL; new_co->boundary = INI_WRAP_BOUNDARY; + new_co->section = NULL; + new_co->name = NULL; + new_co->section_len = 0; + new_co->name_len = 0; + new_co->iterator = NULL; /* Create a collection to hold configuration data */ error = col_create_collection(&(new_co->cfg), @@ -235,6 +263,11 @@ int ini_config_copy(struct ini_cfgobj *ini_config, new_co->cfg = NULL; new_co->boundary = ini_config->boundary; + new_co->section = NULL; + new_co->name = NULL; + new_co->section_len = 0; + new_co->name_len = 0; + new_co->iterator = NULL; error = col_copy_collection_with_cb(&(new_co->cfg), ini_config->cfg, |