Summary: | ASTERISK-10953: duplicate values when rewriting templated config files | ||
Reporter: | Tzafrir Cohen (tzafrir) | Labels: | |
Date Opened: | 2007-12-03 06:02:01.000-0600 | Date Closed: | 2008-03-19 11:41:59 |
Priority: | Minor | Regression? | No |
Status: | Closed/Complete | Components: | Core/Configuration |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ( 0) 11442.patch | |
Description: | I'm trying to generate slimmer config files using templates. I use something of the sort of: [master-template](!) mastervar = bar [template](!,master-template) tvar = value [cat](template) catvar = val I do not expect full transparent rewrite support of this. I do hope to get at least some "flattening" of the templates that will preserve the values: [cat] mastervar = bar tvar = value catvar = val What I actually get is: After first save/rewrite: [master-template](!) mastervar = bar [template](!)(master-template) mastervar = bar tvar = value [cat](template) mastervar = bar tvar = value catvar = val And then after the second time those values get rewritten to the configuration file by Asterisk, they end up as: [master-template](!) mastervar = bar [template](!) mastervar = bar tvar = value [cat](template) mastervar = bar tvar = value mastervar = bar tvar = value catvar = val | ||
Comments: | By: jmls (jmls) 2008-02-06 04:10:47.000-0600 is this still an issue ? By: Steve Murphy (murf) 2008-03-18 21:57:35 OK, I'm diving into this one. It looks like, in the first read of that config data, it was correctly input, but when saved, the output algorithm is wrong, and wrote the data as: [template](!)(master-template) instead of: [template](!,master-template) Since the output category header is syntactically incorrect, then information is lost when it is read back in.... thus your second reading has different results than the first. I've just corrected this in 1.4, and will propagate this thru trunk and 1.6. Due to the use of inherit_category, categories inheriting from templates will copy the template vars into the current category. An initial reading of the code seems to indicate that if the category being referenced hasn't been defined yet, you might not get the inheritance. Of course then, since the config file reader explodes the hierarchy upon reading, then if the explosion does not occur, then you don't get the variables either... I will have to research this. The other problem is, that I could filter any var=val entry that already appears in a referenced template, dropping it if var=val is found; but there is code in the config_text_file_save() routine to do this already. I'll see why it doesn't appear to be working... More to come By: Steve Murphy (murf) 2008-03-19 01:41:56 Tzafrir-- OK, I've attached a patch for 1.4; I think it solves all the problems you presented: 1. Bad syntax in printing the category template references; does not do multiple sets of (<whatever>); it now does [catname](!,whatever,whatnot) instead. 2. There was code there to search the template refs for the same var=val decl. But it didn't work because the underlying code was built to ignore categories marked ignore (!). So, I coded around that. Please try out the patch, and maybe tomorrow I can commit it to 1.4, trunk, and 1.6. My own tests using your examples works OK... By: Digium Subversion (svnbot) 2008-03-19 10:36:56 Repository: asterisk Revision: 109908 U branches/1.4/main/config.c ------------------------------------------------------------------------ r109908 | murf | 2008-03-19 10:36:54 -0500 (Wed, 19 Mar 2008) | 72 lines (closes issue ASTERISK-10953) Reported by: tzafrir Patches: 11442.patch uploaded by murf (license 17) Tested by: murf I didn't give tzafrir very much time to test this, but if he does still have remaining issues, he is welcome to re-open this bug, and we'll do what is called for. I reproduced the problem, and tested the fix, so I hope I am not jumping by just going ahead and committing the fix. The problem was with what file_save does with templates; firstly, it tended to print out multiple options: [my_category](!)(templateref) instead of [my_category](!,templateref) which is fixed by this patch. Nextly, the code to suppress output of duplicate declarations that would occur because the reader copies inherited declarations down the hierarchy, was not working. Thus: [master-template](!) mastervar = bar [template](!,master-template) tvar = value [cat](template) catvar = val would be rewritten as: ;! ;! Automatically generated configuration file ;! Filename: experiment.conf (/etc/asterisk/experiment.conf) ;! Generator: Manager ;! Creation Date: Tue Mar 18 23:17:46 2008 ;! [master-template](!) mastervar = bar [template](!,master-template) mastervar = bar tvar = value [cat](template) mastervar = bar tvar = value catvar = val This has been fixed. Since the config reader 'explodes' inherited vars into the category, users may, in certain circumstances, see output different from what they originally entered, but it should be both correct and equivalent. ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=109908 By: Digium Subversion (svnbot) 2008-03-19 11:20:45 Repository: asterisk Revision: 109942 _U trunk/ U trunk/main/config.c ------------------------------------------------------------------------ r109942 | murf | 2008-03-19 11:20:44 -0500 (Wed, 19 Mar 2008) | 80 lines Merged revisions 109908 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r109908 | murf | 2008-03-19 09:41:13 -0600 (Wed, 19 Mar 2008) | 72 lines (closes issue ASTERISK-10953) Reported by: tzafrir Patches: 11442.patch uploaded by murf (license 17) Tested by: murf I didn't give tzafrir very much time to test this, but if he does still have remaining issues, he is welcome to re-open this bug, and we'll do what is called for. I reproduced the problem, and tested the fix, so I hope I am not jumping by just going ahead and committing the fix. The problem was with what file_save does with templates; firstly, it tended to print out multiple options: [my_category](!)(templateref) instead of [my_category](!,templateref) which is fixed by this patch. Nextly, the code to suppress output of duplicate declarations that would occur because the reader copies inherited declarations down the hierarchy, was not working. Thus: [master-template](!) mastervar = bar [template](!,master-template) tvar = value [cat](template) catvar = val would be rewritten as: ;! ;! Automatically generated configuration file ;! Filename: experiment.conf (/etc/asterisk/experiment.conf) ;! Generator: Manager ;! Creation Date: Tue Mar 18 23:17:46 2008 ;! [master-template](!) mastervar = bar [template](!,master-template) mastervar = bar tvar = value [cat](template) mastervar = bar tvar = value catvar = val This has been fixed. Since the config reader 'explodes' inherited vars into the category, users may, in certain circumstances, see output different from what they originally entered, but it should be both correct and equivalent. ........ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=109942 By: Digium Subversion (svnbot) 2008-03-19 11:41:59 Repository: asterisk Revision: 109969 _U branches/1.6.0/ U branches/1.6.0/main/config.c ------------------------------------------------------------------------ r109969 | murf | 2008-03-19 11:41:59 -0500 (Wed, 19 Mar 2008) | 88 lines Merged revisions 109942 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ................ r109942 | murf | 2008-03-19 10:24:51 -0600 (Wed, 19 Mar 2008) | 80 lines Merged revisions 109908 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r109908 | murf | 2008-03-19 09:41:13 -0600 (Wed, 19 Mar 2008) | 72 lines (closes issue ASTERISK-10953) Reported by: tzafrir Patches: 11442.patch uploaded by murf (license 17) Tested by: murf I didn't give tzafrir very much time to test this, but if he does still have remaining issues, he is welcome to re-open this bug, and we'll do what is called for. I reproduced the problem, and tested the fix, so I hope I am not jumping by just going ahead and committing the fix. The problem was with what file_save does with templates; firstly, it tended to print out multiple options: [my_category](!)(templateref) instead of [my_category](!,templateref) which is fixed by this patch. Nextly, the code to suppress output of duplicate declarations that would occur because the reader copies inherited declarations down the hierarchy, was not working. Thus: [master-template](!) mastervar = bar [template](!,master-template) tvar = value [cat](template) catvar = val would be rewritten as: ;! ;! Automatically generated configuration file ;! Filename: experiment.conf (/etc/asterisk/experiment.conf) ;! Generator: Manager ;! Creation Date: Tue Mar 18 23:17:46 2008 ;! [master-template](!) mastervar = bar [template](!,master-template) mastervar = bar tvar = value [cat](template) mastervar = bar tvar = value catvar = val This has been fixed. Since the config reader 'explodes' inherited vars into the category, users may, in certain circumstances, see output different from what they originally entered, but it should be both correct and equivalent. ........ ................ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=109969 |