<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
    <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="https://reviewboard.asterisk.org/r/1985/">https://reviewboard.asterisk.org/r/1985/</a>
     </td>
    </tr>
   </table>
   <br />








<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
 <p style="margin-top: 0;">On June 14th, 2012, 10:24 a.m., <b>rmudgett</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  



<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; border-collapse: collapse; margin: 2px padding: 2px;">
 <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; font-size: 9pt; padding: 4px 8px; text-align: left;">
    <a href="https://reviewboard.asterisk.org/r/1985/diff/2/?file=28868#file28868line577" style="color: black; font-weight: bold; text-decoration: underline;">/branches/1.8/channels/chan_local.c</a>
    <span style="font-weight: normal;">

     (Diff revision 2)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">static void check_bridge(struct ast_channel *ast, struct local_pvt *p)</pre></td>

  </tr>
 </tbody>




 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">577</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="cm">/* Preserve user defined CDR information */</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">578</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">ast_strlen_zero</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">owner</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">userfield</span><span class="p">))</span> <span class="p">{</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">579</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                <span class="n">strcpy</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">chan</span><span class="o">-&gt;</span><span class="n">_bridge</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">userfield</span><span class="p">,</span> <span class="n">p</span><span class="o">-&gt;</span><span class="n">owner</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">userfield</span><span class="p">);</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">580</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="p">}</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">581</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">ast_strlen_zero</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">owner</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">accountcode</span><span class="p">))</span> <span class="p">{</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">582</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                <span class="n">strcpy</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">chan</span><span class="o">-&gt;</span><span class="n">_bridge</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">accountcode</span><span class="p">,</span> <span class="n">p</span><span class="o">-&gt;</span><span class="n">owner</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">accountcode</span><span class="p">);</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">583</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="p">}</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">584</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="k">if</span> <span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">owner</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">amaflags</span><span class="p">)</span> <span class="p">{</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">585</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                <span class="n">p</span><span class="o">-&gt;</span><span class="n">chan</span><span class="o">-&gt;</span><span class="n">_bridge</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">amaflags</span> <span class="o">=</span> <span class="n">p</span><span class="o">-&gt;</span><span class="n">owner</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="o">-&gt;</span><span class="n">amaflags</span><span class="p">;</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">586</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="p">}</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">587</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="n">ast_cdr_copy_vars</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">chan</span><span class="o">-&gt;</span><span class="n">_bridge</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="p">,</span> <span class="n">p</span><span class="o">-&gt;</span><span class="n">owner</span><span class="o">-&gt;</span><span class="n">cdr</span><span class="p">);</span></pre></td>
  </tr>

 </tbody>

</table>

  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">You should check if the cdr ptr is not NULL.
If the owner cdr is not null and the _bridge cdr is null, move the owner cdr to the _bridge cdr.
If the owner cdr is NULL do nothing.</pre>
 </blockquote>



 <p>On June 14th, 2012, 2:13 p.m., <b>Matt Jordan</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">As we discussed, this can probably just be replaced with a swap of the channel&#39;s cdrs.</pre>
 </blockquote>







</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">...And, after some further testing, I don&#39;t think I&#39;m right that this can be replaced.

Swapping the CDR structures preserves more then just the user defined fields.  If you swap the entire CDR structure, then things such as the channel name that is being masqueraded away is also preserved, which wouldn&#39;t be desired.

For example, assume that SIP/phone_b is being masqueraded into Local/1@default;1.  With a CDR swap, this will result in the user defined fields being preserved, but you&#39;ll also end up with something like the following:

&quot;&quot;,&quot;1&quot;,&quot;2&quot;,&quot;default&quot;,&quot;1&quot;,&quot;Local/1@default-5c20;1&quot;,&quot;SIP/phone_a-00000001&quot;,&quot;Dial&quot;,&quot;SIP/phone_a&quot;,&quot;2012-06-14 19:16:32&quot;,&quot;2012-06-14 19:16:35&quot;,&quot;2012-06-14 19:16:36&quot;,4,1,&quot;ANSWERED&quot;,&quot;DOCUMENTATION&quot;,&quot;1339701392.0&quot;,&quot;foo&quot;

In this case, Local/1@default-5c20;1 should have been replaced with the name of the SIP channel that masqueraded into the Local channel, e.g., SIP/phone_b-00000001.

Going back to your finding, then, this does need:

1) If the owner cdr pointer is NULL, do nothing
2) If the owner cdr pointer is not NULL, copy over the user defined data, destroy the _bridge-&gt;cdr variables, and replace them with the owner-&gt;cdr variables</pre>
<br />




<p>- Matt</p>


<br />
<p>On June 11th, 2012, 4:14 p.m., Matt Jordan wrote:</p>






<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/media/rb/images/review_request_box_top_bg.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
 <tr>
  <td>

<div>Review request for Asterisk Developers, Terry Wilson, Tilghman Lesher, and rmudgett.</div>
<div>By Matt Jordan.</div>


<p style="color: grey;"><i>Updated June 11, 2012, 4:14 p.m.</i></p>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This patch preserves CDR information that was set on a Local channel before it is masqueraded into by another channel.  This includes accountcode, peeraccount, userfield, amaflags, and any variables that were set.

Consider a scenario in which a Local channel bridges two SIP channels (possibly the result of a channel originate Local/foo@default extension bar@default).  This would look something like the following:

SIP/A &lt;--&gt; Local;1 &lt;&gt; Local;2 &lt;--&gt; SIP/B

In this scenario, currently, the only opportunity for setting CDR information on the resulting call occurs on the Local channels - both SIP channels are created as the result of outbound calls.  As a result, it is desirable to have the CDR information that was set on the Local channel, i.e., Local;2, persist through the masquerade.  At the same time, most of the CDR information, e.g., caller ID information, channel information, etc., should be swapped with the channel being masqueraded away.

This patch does this by copying over the information in local_fixup - this is only an improvement that should be done with respect to local channels.  This should prevent impacting other masquerade operations (such as on SIP transfers).</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Tested the following scenario:

exten =&gt; 100,1,NoOp()
     same =&gt; n,Set(CDR(userfield)=foo)
     same =&gt; n,Dial(SIP/A)

exten =&gt; 101,1,NoOp()
     same =&gt; n,Set(CDR(userfield)=bar)
     same =&gt; n,Dial(SIP/B)

Performing &quot;channel originate Local/100@default extension 101@default&quot; prior to the patch would produce the following CDR record:

&quot;&quot;,&quot;&quot;,&quot;100&quot;,&quot;default&quot;,&quot;&quot;,&quot;Local/100@default-5160,2&quot;,&quot;SIP/A-00000000&quot;,&quot;Dial&quot;,&quot;SIP/A&quot;,&quot;2012-06-11 19:10:40&quot;,&quot;2012-06-11 19:10:42&quot;,&quot;2012-06-11 19:10:42&quot;,2,0,&quot;ANSWERED&quot;,&quot;DOCUMENTATION&quot;,&quot;1339441840.1&quot;,&quot;foo&quot;
&quot;&quot;,&quot;100&quot;,&quot;101&quot;,&quot;default&quot;,&quot;100&quot;,&quot;SIP/A-00000000&quot;,&quot;SIP/B-00000001&quot;,&quot;Dial&quot;,&quot;SIP/B&quot;,&quot;2012-06-11 19:10:42&quot;,&quot;2012-06-11 19:10:43&quot;,&quot;2012-06-11 19:10:45&quot;,3,2,&quot;ANSWERED&quot;,&quot;DOCUMENTATION&quot;,&quot;1339441840.2&quot;,&quot;&quot;

Performing the same post patch produces the following CDR:

&quot;&quot;,&quot;&quot;,&quot;100&quot;,&quot;default&quot;,&quot;&quot;,&quot;Local/100@default-5160,2&quot;,&quot;SIP/A-00000000&quot;,&quot;Dial&quot;,&quot;SIP/A&quot;,&quot;2012-06-11 19:10:40&quot;,&quot;2012-06-11 19:10:42&quot;,&quot;2012-06-11 19:10:42&quot;,2,0,&quot;ANSWERED&quot;,&quot;DOCUMENTATION&quot;,&quot;1339441840.1&quot;,&quot;foo&quot;
&quot;&quot;,&quot;100&quot;,&quot;101&quot;,&quot;default&quot;,&quot;100&quot;,&quot;SIP/A-00000000&quot;,&quot;SIP/B-00000001&quot;,&quot;Dial&quot;,&quot;SIP/B&quot;,&quot;2012-06-11 19:10:42&quot;,&quot;2012-06-11 19:10:43&quot;,&quot;2012-06-11 19:10:45&quot;,3,2,&quot;ANSWERED&quot;,&quot;DOCUMENTATION&quot;,&quot;1339441840.2&quot;,&quot;bar&quot;</pre>
  </td>
 </tr>
</table>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>/branches/1.8/channels/chan_local.c <span style="color: grey">(368780)</span></li>

</ul>

<p><a href="https://reviewboard.asterisk.org/r/1985/diff/" style="margin-left: 3em;">View Diff</a></p>




  </td>
 </tr>
</table>








  </div>
 </body>
</html>