Tono Nam
Tono Nam

Reputation: 36050

Duplicate channel variables after transfer in Asterisk

with an (attended) transfer i see the following happening:

1) A calls B1
2) B2 calls C
3) B2 transfers call to A
4) A talks to C

At step 3, the channel A is connected to channel C and B1 and B2 are hung up. In the h extension for channel B2, the channel is renamed to B2 and i see that the channel variables of A have been merged into B2. If there were duplicate names for variables, the channel now has those variables doubled. The DumpChan() application called from the h extension confirms this.

In my case the channels are all SIP channels and in the h extension I want to access the SIPCALLID variable of the A channel. Every access to it gives me the wrong value namely that of channel B1. How do i access the second variable named SIPCALLID in the channel?


Ugly solution:

A solution I have found is to go from:

same => n,Set(myVariable=10) 
same => n,NoOp(The value of myVariable is ${myVariable})

to:

same => n,Set(${CHANNEL:6:8}myVariable=10) 
same => n,NoOp(The value of myVariable is ${${CHANNEL:6:8}myVariable})

With this trick I am appending the id of the channel to all the variables. I have to use the 6:8 because once I transfer the call the channel id now contains <ZOMBIE>. I do not want to append ${CHANNEL:6:8} to all my variables. What do you guys recommend?

Upvotes: 1

Views: 1230

Answers (1)

arheops
arheops

Reputation: 15259

You can use function SHARED

pro-sip*CLI> core show function SHARED

  -= Info about function 'SHARED' =- 

[Synopsis]
Gets or sets the shared variable specified. 

[Description]
Implements a shared variable area, in which you may share variables between
channels.
The variables used in this space are separate from the general namespace
of the channel and thus ${SHARED(foo)} and ${foo}  represent two completely
different variables, despite sharing the same name.
Finally, realize that there is an inherent race between channels operating
at the same time, fiddling with each others' internal variables, which is
why this special variable namespace exists; it is to remind you that variables
in the SHARED namespace may change at any time, without warning.  You should
therefore take special care to ensure that when using the SHARED namespace,
you retrieve the variable and store it in a regular channel variable before
using it in a set of calculations (or you might be surprised by the
result).

[Syntax]
SHARED(varname[,channel])

[Arguments]
varname
    Variable name
channel
    If not specified will default to current channel. It is the complete
    channel name: 'SIP/12-abcd1234' or the prefix only 'SIP/12'.

[See Also]
Not available

Upvotes: 1

Related Questions