[Home]

Summary:ASTERISK-27438: Custom variable at endpoint definition are duplicated
Reporter:Alexander Rozes (Ramzes)Labels:NewSIP
Date Opened:2017-11-22 01:00:47.000-0600Date Closed:2017-11-22 11:51:35.000-0600
Priority:MinorRegression?Yes
Status:Closed/CompleteComponents:Channels/chan_pjsip
Versions:15.1.2 Frequency of
Occurrence
Constant
Related
Issues:
Environment:GNU/Linux 3.10.0-693.5.2.el7.x86_64 #1 SMP Attachments:( 0) extensions.conf.txt
( 1) full.txt
( 2) pjsip.conf.txt
Description:If you override a custom variable in pjsip.conf, it is duplicated instead of overriding the value.

{noformat}
;================================ ENDPOINT TEMPLATES ==

[phones-tpl](!)
type = endpoint
...
set_var=followme=0

[auth-tpl](!)
type = auth
auth_type = userpass

[aor-tpl](!)
type = aor
...
max_contacts = 1

;================================ ENDPOINT DEFINITIONS ==

;----- 101 -----
[101](phones-tpl)
aors = 101
auth = 101
callerid = 101 <101>

[101](aor-tpl)

[101](auth-tpl)
username = 101
password = fake_password

;----- 102 -----
[102](phones-tpl)
aors = 102
auth = 102
callerid = 102 <102>
set_var=followme=1

[102](aor-tpl)

[102](auth-tpl)
username = 102
password = fake_password

...
{noformat}

That's what happens:

{noformat}
aster*CLI> pjsip show endpoint 101
...
followme                           : 0
...
{noformat}
{noformat}
aster*CLI> pjsip show endpoint 102
...
followme                           : 0
followme                           : 1
...
{noformat}
Comments:By: Asterisk Team (asteriskteam) 2017-11-22 01:00:48.052-0600

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

By: Richard Mudgett (rmudgett) 2017-11-22 11:51:15.224-0600

This is not a bug.  Config templates act like text substitution.  So given the below templates and section using the templates:
{noformat}
[my_template](!)
set_var=my_var=0
my_setting=yes

[my_template2](!)
set_var=my_var=1
my_setting2=yes

[my_setup](my_template,my_template2)
set_var=my_var=2
{noformat}

The section expands as if you had explicitly written:
{noformat}
[my_setup]
set_var=my_var=0
my_setting=yes
set_var=my_var=1
my_setting2=yes
set_var=my_var=2
{noformat}

{quote}
*CLI> config show help res_pjsip endpoint set_var
\[endpoint]
set_var = \[Custom] (Default: ) (Regex: false)

Variable set on a channel involving the endpoint.

When a new channel is created using the endpoint set the specified variable(s)
on that channel. For multiple channel variables specify multiple 'set_var'(s).
{quote}
In your case, when the PJSIP channel is created the configured set_var variables are set in the order you specified.  Thus your followme channel variable winds up with the last set value of 1.  When you show the endpoint configuration it simply lists off the set_var's you configured.

By: Alexander Rozes (Ramzes) 2017-11-22 15:28:42.738-0600

What am I doing wrong?
Simple experiment.

Part of dialplan:
{noformat}
[phones]
include => test
...
[test]
exten => *10,1,NoOp(1,~~~~~ Test ~~~~~)
same => n,NoOp(1,~~~~~ 101 followme: ${PJSIP_ENDPOINT(101,followme)} ~~~~~~)
same => n,NoOp(1,~~~~~ 102 followme: ${PJSIP_ENDPOINT(102,followme)} ~~~~~~)
same => n,Hangup()
{noformat}

Part of console output:
{noformat}
aster*CLI>
 == Setting global variable 'SIPDOMAIN' to '192.168.100.41'
   -- Executing [*10@phones:1] NoOp("PJSIP/500-00000002", "1,~~~~~ Test ~~~~~") in new stack
   -- Executing [*10@phones:2] NoOp("PJSIP/500-00000002", "1,~~~~~ 101 followme: 0 ~~~~~~") in new stack
   -- Executing [*10@phones:3] NoOp("PJSIP/500-00000002", "1,~~~~~ 102 followme: 0 ~~~~~~") in new stack
   -- Executing [*10@phones:4] Hangup("PJSIP/500-00000002", "") in new stack
{noformat}


By: Asterisk Team (asteriskteam) 2017-11-22 15:28:42.954-0600

This issue has been reopened as a result of your commenting on it as the reporter. It will be triaged once again as applicable.

By: Richard Mudgett (rmudgett) 2017-11-22 18:04:25.198-0600

We appreciate the difficulties you are facing, however this does not appear to be a bug report and your request or comments would be better served in a different forum.

The Asterisk community provides support over IRC, mailing lists, and forums as described at http://asterisk.org/community. The Asterisk issue tracker is used specifically to track issues concerning bugs and documentation errors.

Please see the Asterisk Issue Guidelines [1] for instruction on the intended use of the Asterisk issue tracker.

Thanks!

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines

For one thing followme is *not* an endpoint field name.  It is a channel variable that is set on a PJSIP channel created for that endpoint.  See \[2].

\[2] https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_PJSIP_ENDPOINT


By: Alexander Rozes (Ramzes) 2017-11-23 06:38:55.900-0600

{quote}
In your case, when the PJSIP channel is created the configured set_var variables are set in the order you specified. Thus your followme channel variable winds up with the last set value of 1.
{quote}
But this is not true.
The experiment proves the opposite.

By: Asterisk Team (asteriskteam) 2017-11-23 06:38:56.273-0600

This issue has been reopened as a result of your commenting on it as the reporter. It will be triaged once again as applicable.

By: Richard Mudgett (rmudgett) 2017-11-23 13:08:52.235-0600

This is still not a bug.

The purpose of the endpoint {{set_var}} field is to set *channel variables* on channels created with that endpoint.  It does that.  It also sets the channel variables in the order you specify in the configuration in case there are any side effects depending upon order.  Setting the channel variables in order is important because those channel variable values can be the result of dialplan functions such as {{SHELL}} or {{EVAL}}.

What you are trying to do with {{set_var}} falls into undefined territory.  The fact that you can even get any {{set_var}} values using the dialplan function {{PJSIP_ENDPOINT}} is surprising as I was not expecting that to even work.

I have attached [^pjsip.conf.txt] and [^extensions.conf.txt] showing what you did and where the {{set_var}} values are expected to be available.  Originating a local channel to the 10, 11, 12, and 13 extensions in [^extensions.conf.txt] is shown in the [^full.txt] log file.  The log output shows that reading the {{followme}} channel variable on the PJSIP channels does work as intended.

I recently remembered there is another feature that seems to do what you apparently want.  This is expressed by my arbitrarily named field {{@fred}} in the attached [^pjsip.conf.txt] file and demonstrated in the [^full.txt] log output.  The field must be prefixed with the '@' symbol.

The feature is practically undocumented and only used by these three testsuite tests:
./tests/channels/pjsip/publish/presence_xpidf
./tests/channels/pjsip/publish/presence_pidf
./tests/channels/pjsip/publish/dialog_info_xml