From 56de48107fd68d234821d996c1893eba21ac2996 Mon Sep 17 00:00:00 2001 From: George Joseph Date: Wed, 7 Jan 2015 16:56:59 +0000 Subject: config: Add option to NOT preserve effective context when changing a template Let's say you have a template T with variable VAR1 = ON and you have a context C(T) that doesn't specify VAR1. If you read C, the effective value of VAR1 is ON. Now you change T VAR1 to OFF and call ast_config_text_file_save. The current behavior is that the file gets re-written with T/VAR1=OFF but C/VAR1=ON is added. Personally, I think this is a bug. It's preserving the effective state of C even though I didn't specify C/VAR1 in th first place. I believe the behavior should be that if I didn't specify C/VAR1 originally, then the effective value of C/VAR1 should continue to follow the inherited state. Now, if I DID explicitly specify C/VAR1, the it should be preserved even if the template changes. Even though I think the existing behavior is a bug, it's been that way forever so I'm not changing it. Instead, I've created ast_config_text_file_save2() that takes a bitmask of flags, one of which is to preserve the effective context (the current behavior). The original ast_config_text_file_save calls *2 with the preserve flag. If you want the new behavior, call *2 directly without a flag. I've also updated Manager UpdateConfig with a new parameter 'PreserveEffectiveContext' whose default is 'yes'. If you want the new behavior with UpdateConfig, set 'PreserveEffectiveContext: no'. Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4297/ ........ Merged revisions 430295 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430296 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/config.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'include/asterisk') diff --git a/include/asterisk/config.h b/include/asterisk/config.h index 7f0434d88..3b46982b2 100644 --- a/include/asterisk/config.h +++ b/include/asterisk/config.h @@ -47,6 +47,14 @@ enum { CONFIG_FLAG_NOREALTIME = (1 << 3), }; +/*! Flags for ast_config_text_file_save2() + */ +enum config_save_flags { + CONFIG_SAVE_FLAG_NONE = (0), + /*! Insure a context doesn't effectively change if a template changes (pre 13.2 behavior) */ + CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT = (1 << 0), +}; + #define CONFIG_STATUS_FILEMISSING (void *)0 #define CONFIG_STATUS_FILEUNCHANGED (void *)-1 #define CONFIG_STATUS_FILEINVALID (void *)-2 @@ -86,7 +94,8 @@ struct ast_variable { int lineno; int object; /*!< 0 for variable, 1 for object */ - int blanklines; /*!< Number of blanklines following entry */ + int blanklines; /*!< Number of blanklines following entry */ + int inherited; /*!< 1 for inherited from template or other base */ struct ast_comment *precomments; struct ast_comment *sameline; struct ast_comment *trailing; /*!< the last object in the list will get assigned any trailing comments when EOF is hit */ @@ -907,6 +916,28 @@ struct ast_variable *ast_variable_list_append_hint(struct ast_variable **head, s int ast_variable_update(struct ast_category *category, const char *variable, const char *value, const char *match, unsigned int object); +/*! + * \brief Save a config text file + * \since 13.2.0 + * + * \param filename Filename + * \param cfg ast_config + * \param generator generator + * \param flags List of config_save_flags + * + * \return 0 on success or -1 on failure. + */ +int ast_config_text_file_save2(const char *filename, const struct ast_config *cfg, const char *generator, uint32_t flags); + +/*! + * \brief Save a config text file preserving the pre 13.2 behavior + * + * \param filename Filename + * \param cfg ast_config + * \param generator generator + * + * \return 0 on success or -1 on failure. + */ int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator); int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator) __attribute__((deprecated)); -- cgit v1.2.3