From e82e187f9b448f2e83d254734d727a1e6a34081d Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 19 Nov 2015 16:50:30 +0100 Subject: [PATCH] Added set overwrite flags for section for convenience --- coreapi/lpc2xml.c | 2 +- coreapi/lpconfig.c | 20 +++++++++++++++++++- coreapi/lpconfig.h | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/coreapi/lpc2xml.c b/coreapi/lpc2xml.c index 45fa76208..ed63669d0 100644 --- a/coreapi/lpc2xml.c +++ b/coreapi/lpc2xml.c @@ -102,7 +102,7 @@ static int processEntry(const char *section, const char *entry, xmlNode *node, l lpc2xml_log(ctx, LPC2XML_MESSAGE, "Set %s|%s = %s", section, entry, content); xmlNodeSetContent(node, (const xmlChar *) content); - if (lp_config_get_overwrite_flag_for_entry(ctx->lpc, section, entry)) { + if (lp_config_get_overwrite_flag_for_entry(ctx->lpc, section, entry) || lp_config_get_overwrite_flag_for_section(ctx->lpc, section)) { xmlSetProp(node, (const xmlChar *)"overwrite", (const xmlChar *) "true"); } return 0; diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index 6784585ed..9973bde9c 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -74,6 +74,7 @@ typedef struct _LpSection{ char *name; MSList *items; MSList *params; + bool_t overwrite; // If set to true, will add overwrite=true to all items of this section when converted to xml } LpSection; struct _LpConfig{ @@ -578,6 +579,15 @@ bool_t lp_config_get_overwrite_flag_for_entry(const LpConfig *lpconfig, const ch return 0; } +bool_t lp_config_get_overwrite_flag_for_section(const LpConfig *lpconfig, const char *section) { + LpSection *sec; + sec = lp_config_find_section(lpconfig, section); + if (sec != NULL){ + return sec->overwrite; + } + return 0; +} + void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *key, const char *value){ LpItem *item; LpSection *sec=lp_config_find_section(lpconfig,section); @@ -634,12 +644,20 @@ void lp_config_set_overwrite_flag_for_entry(LpConfig *lpconfig, const char *sect LpSection *sec; LpItem *item; sec = lp_config_find_section(lpconfig, section); - if (sec != NULL){ + if (sec != NULL) { item = lp_section_find_item(sec, key); if (item != NULL) item->overwrite = value; } } +void lp_config_set_overwrite_flag_for_section(LpConfig *lpconfig, const char *section, bool_t value) { + LpSection *sec; + sec = lp_config_find_section(lpconfig, section); + if (sec != NULL) { + sec->overwrite = value; + } +} + void lp_item_write(LpItem *item, FILE *file){ if (item->is_comment) fprintf(file,"%s\n",item->value); diff --git a/coreapi/lpconfig.h b/coreapi/lpconfig.h index 2d2e05be7..49e2bb50d 100644 --- a/coreapi/lpconfig.h +++ b/coreapi/lpconfig.h @@ -325,6 +325,20 @@ LINPHONE_PUBLIC bool_t lp_config_get_overwrite_flag_for_entry(const LpConfig *lp **/ LINPHONE_PUBLIC void lp_config_set_overwrite_flag_for_entry(LpConfig *lpconfig, const char *section, const char *key, bool_t value); +/** + * Retrieves the overwrite flag for a config section + * + * @ingroup misc +**/ +LINPHONE_PUBLIC bool_t lp_config_get_overwrite_flag_for_section(const LpConfig *lpconfig, const char *section); + +/** + * Sets the overwrite flag for a config section (used when dumping config as xml) + * + * @ingroup misc +**/ +LINPHONE_PUBLIC void lp_config_set_overwrite_flag_for_section(LpConfig *lpconfig, const char *section, bool_t value); + #ifdef __cplusplus } #endif