From be6d6b47b363676bc51beb2e5138ec92f2f517d7 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 27 Apr 2016 12:19:22 +0200 Subject: [PATCH] Added a way to not dump some chosen sections/entries when converting lpc to xml --- coreapi/lpc2xml.c | 14 +++++++++++++- coreapi/lpconfig.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- coreapi/lpconfig.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/coreapi/lpc2xml.c b/coreapi/lpc2xml.c index 605c65297..fbdb471ba 100644 --- a/coreapi/lpc2xml.c +++ b/coreapi/lpc2xml.c @@ -166,6 +166,11 @@ static void processSection_cb(const char *entry, struct __processSectionCtx *ctx ctx->ret = 0; return; } + + if (lp_config_get_skip_flag_for_entry(ctx->ctx->lpc, ctx->section, entry)) { + lpc2xml_log(ctx->ctx, LPC2XML_WARNING, "Skipped entry %s", entry); + return; + } node = xmlNewChild(ctx->node, NULL, (const xmlChar *)"entry", NULL); if(node == NULL) { @@ -200,8 +205,15 @@ struct __processConfigCtx { static void processConfig_cb(const char *section, struct __processConfigCtx *ctx) { if(ctx->ret == 0) { - xmlNode *node = xmlNewChild(ctx->node, NULL, (const xmlChar *)"section", NULL); + xmlNode *node; xmlAttr *name_attr; + + if (lp_config_get_skip_flag_for_section(ctx->ctx->lpc, section)) { + lpc2xml_log(ctx->ctx, LPC2XML_WARNING, "Skipped section %s", section); + return; + } + + node = xmlNewChild(ctx->node, NULL, (const xmlChar *)"section", NULL); if(node == NULL) { lpc2xml_log(ctx->ctx, LPC2XML_ERROR, "Can't create \"section\" element"); ctx->ret = -1; diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index cd036947e..69128eddb 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -63,6 +63,7 @@ typedef struct _LpItem{ char *value; int is_comment; bool_t overwrite; // If set to true, will add overwrite=true when converted to xml + bool_t skip; // If set to true, won't be dumped when converted to xml } LpItem; typedef struct _LpSectionParam{ @@ -75,6 +76,7 @@ typedef struct _LpSection{ 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 + bool_t skip; // If set to true, won't be dumped when converted to xml } LpSection; struct _LpConfig{ @@ -576,7 +578,7 @@ bool_t lp_config_get_overwrite_flag_for_entry(const LpConfig *lpconfig, const ch item = lp_section_find_item(sec, key); if (item != NULL) return item->overwrite; } - return 0; + return FALSE; } bool_t lp_config_get_overwrite_flag_for_section(const LpConfig *lpconfig, const char *section) { @@ -585,7 +587,27 @@ bool_t lp_config_get_overwrite_flag_for_section(const LpConfig *lpconfig, const if (sec != NULL){ return sec->overwrite; } - return 0; + return FALSE; +} + +bool_t lp_config_get_skip_flag_for_entry(const LpConfig *lpconfig, const char *section, const char *key) { + LpSection *sec; + LpItem *item; + sec = lp_config_find_section(lpconfig, section); + if (sec != NULL){ + item = lp_section_find_item(sec, key); + if (item != NULL) return item->skip; + } + return FALSE; +} + +bool_t lp_config_get_skip_flag_for_section(const LpConfig *lpconfig, const char *section) { + LpSection *sec; + sec = lp_config_find_section(lpconfig, section); + if (sec != NULL){ + return sec->skip; + } + return FALSE; } void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *key, const char *value){ @@ -658,6 +680,24 @@ void lp_config_set_overwrite_flag_for_section(LpConfig *lpconfig, const char *se } } +void lp_config_set_skip_flag_for_entry(LpConfig *lpconfig, const char *section, const char *key, bool_t value) { + LpSection *sec; + LpItem *item; + sec = lp_config_find_section(lpconfig, section); + if (sec != NULL) { + item = lp_section_find_item(sec, key); + if (item != NULL) item->skip = value; + } +} + +void lp_config_set_skip_flag_for_section(LpConfig *lpconfig, const char *section, bool_t value) { + LpSection *sec; + sec = lp_config_find_section(lpconfig, section); + if (sec != NULL) { + sec->skip = 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 c18af988a..d99264bed 100644 --- a/coreapi/lpconfig.h +++ b/coreapi/lpconfig.h @@ -348,6 +348,34 @@ LINPHONE_PUBLIC bool_t lp_config_get_overwrite_flag_for_section(const LpConfig * **/ LINPHONE_PUBLIC void lp_config_set_overwrite_flag_for_section(LpConfig *lpconfig, const char *section, bool_t value); +/** + * Retrieves the skip flag for a config item + * + * @ingroup misc +**/ +LINPHONE_PUBLIC bool_t lp_config_get_skip_flag_for_entry(const LpConfig *lpconfig, const char *section, const char *key); + +/** + * Sets the skip flag for a config item (used when dumping config as xml) + * + * @ingroup misc +**/ +LINPHONE_PUBLIC void lp_config_set_skip_flag_for_entry(LpConfig *lpconfig, const char *section, const char *key, bool_t value); + +/** + * Retrieves the skip flag for a config section + * + * @ingroup misc +**/ +LINPHONE_PUBLIC bool_t lp_config_get_skip_flag_for_section(const LpConfig *lpconfig, const char *section); + +/** + * Sets the skip flag for a config section (used when dumping config as xml) + * + * @ingroup misc +**/ +LINPHONE_PUBLIC void lp_config_set_skip_flag_for_section(LpConfig *lpconfig, const char *section, bool_t value); + #ifdef __cplusplus } #endif