#including sip file not inheriting templates

I am trying to clean up my config files by separating out the repetitious from the custom but ran into a snag.

if my sip.conf #includes another file - call it custom-sip.conf and sip.conf has sip templates, then asterisk will complain if custom-sip.conf references those templates - it cannot find them. If I add the template to custom-sip.conf then it is found.

Any ideas how to make this work?
Simple example below

sip.conf:
#include custom-sip.conf
[general]
;blah blah

template1
type=friend
context=abc

template2
type=friend
context=def

[authentication]
; this is empty so all accounts can go in custom-sip
;============================

custom-sip.conf:
[authentication]+ ; yes I added the + symbol

001
secret=123

;this does not work with asterisk complaining "inheritance requested but category template1 does not exist"

Move the include to after the templates.

Thanks that fixed it.
At first blush it would appear that if the user wants to add-to or replace an existing config then the best place to put this statement is at the end of the file not the beginning .

I do not remember seeing any notes about the signficance of the #include position.
Can you point me to something that describes this?

Please validate my guesses below:

  1. Configs with #includes are appended line by line so if config1 has an #include to a 100 line file at line 8 then that second file will be loaded as lines 8 ->108 and then it will continue to load Line 9 of config1

  2. Once everything has been appended into one big file then each [section] is inspected for duplicates starting at line 1. If a duplicate is found then it will completeley replace the previous version of [section] unless it has an + as in [section]+ in which case it will append its contents to [section]

  3. if [sections] are appended and there are duplicate fields in that section then the last field version wins.

  4. if there are multiple versions of [section] and some have + and the last one does not then the last [section] wins and none of the prevous copies are used at all

eg if the #include is at the top of sip.conf and the other file adds to [authentication], if the base sip.conf does NOT have a + as in [authentication]+ then none of the other files additions are used - correct?

Thanks

Bill

(3) The preferred behaviour is that the last instance wins, however this does actually vary between different parts of the code. For last definition to win, the code has to scan the whole section, looking up each key in a switch in the code. In some places, the code searches for each known key in the section, and the first match wins.

(4) I doubt that this is specified.

  • should be (+) and it is not used on the first occurence.