<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/2496/">https://reviewboard.asterisk.org/r/2496/</a>
     </td>
    </tr>
   </table>
   <br />










<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
 <p style="margin-top: 0;">On May 7th, 2013, 8 p.m. UTC, <b>David Lee</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/2496/diff/1/?file=37181#file37181line696" style="color: black; font-weight: bold; text-decoration: underline;">/trunk/main/security_events.c</a>
    <span style="font-weight: normal;">

     (Diff revision 1)

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



 
 

 <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">670</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="n">json_temp</span> <span class="o">=</span> <span class="n">ast_json_stringf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span> <span class="n">sec</span><span class="o">-&gt;</span><span class="n">event_type</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">671</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="k">if</span> <span class="p">(</span><span class="n">json_temp</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">672</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="tb">        </span><span class="n">ast_json_object_set</span><span class="p">(</span><span class="n">json_object</span><span class="p">,</span> <span class="n">ast_event_get_ie_type_name</span><span class="p">(</span><span class="n">AST_EVENT_IE_SECURITY_EVENT</span><span class="p">),</span> <span class="n">json_temp</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">673</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </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;">I added an example in the file comment in json.h in trunk to better explain how to handle ast_json references properly. Hope that helps!</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;">I notice these reviews are against revision 1.  The code here has changed a bit, but it&#39;s worth noting that there isn&#39;t any need to bump the reference to the json_temp here since if it succeeds, we immediately set json_temp to be a new json object and if it fails we break out of the function entirely.

I do notice now though that if it fails, when the function exits it will try to unref json_temp which will at this point be a stale pointer... that&#39;s no good. I&#39;ll fix it by setting json_temp to NULL here.</pre>
<br />

<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
 <p style="margin-top: 0;">On May 7th, 2013, 8 p.m. UTC, <b>David Lee</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/2496/diff/1/?file=37182#file37182line126" style="color: black; font-weight: bold; text-decoration: underline;">/trunk/res/res_security_log.c</a>
    <span style="font-weight: normal;">

     (Diff revision 1)

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



 
 

 <tbody>

  <tr>
    <th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">116</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="p">(</span><span class="n">str</span> <span class="o">=</span> <span class="n">ast_str_thread_get</span><span class="p">(</span><span class="o">&amp;</span><span class="n">security_event_buf</span><span class="p">,</span></pre></td>
    <th bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">99</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="n">event_type_json</span> <span class="o">=</span> <span class="n">ast_json_object_get</span><span class="p">(</span><span class="n">json</span><span class="p">,</span> <span class="s">&quot;SecurityEvent&quot;</span><span class="p">);</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">117</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="tb">        </span><span class="tb">        </span><span class="n">SECURITY_EVENT_BUF_INIT_LEN</span><span class="p">)))</span> <span class="p">{</span></pre></td>
    <th bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">100</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="n">event_type_str</span> <span class="o">=</span> <span class="n">ast_json_string_get</span><span class="p">(</span><span class="n">event_type_json</span><span class="p">);</span></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">101</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></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">102</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">event_type_str</span><span class="p">,</span> <span class="s">&quot;%u&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">event_type</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span></pre></td>
  </tr>

 </tbody>


 
 

 <tbody>

  <tr>
    <th bgcolor="#f0f0f0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">118</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="tb">        </span><span class="k">return</span><span class="p">;</span></pre></td>
    <th bgcolor="#f0f0f0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">103</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="tb">        </span><span class="k">return</span><span class="p">;</span></pre></td>
  </tr>

  <tr>
    <th bgcolor="#f0f0f0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">119</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </span><span class="p">}</span></pre></td>
    <th bgcolor="#f0f0f0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">104</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="tb">        </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;">If the event_type_json is an int, why not make it an ast_json_integer?</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;">Yeah, that seems more appropriate. I thought I&#39;d need it as a string for some reason, but after giving it another look it&#39;s pretty obvious that I don&#39;t.</pre>
<br />




<p>- jrose</p>


<br />
<p>On May 6th, 2013, 5:21 p.m. UTC, jrose wrote:</p>








<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/static/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, David Lee, kmoore, and Matt Jordan.</div>
<div>By jrose.</div>


<p style="color: grey;"><i>Updated May 6, 2013, 5:21 p.m.</i></p>







<div style="margin-top: 1.5em;">
 <b style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Bugs: </b>


 <a href="https://issues.asterisk.org/jira/browse/ASTERISK-21103">ASTERISK-21103</a>


</div>



<div style="margin-top: 1.5em;">
 <b style="color: #575012; font-size: 10pt;">Repository: </b>
Asterisk
</div>


<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;">Stage 3/3 of ASTERISK-21103. In order to convert this set of messages I had to change all of the event blob stuff into JSON strings inside of a JSON blob loaded onto a JSON payload and sent out over stasis to the security topic where it is then consumed by stasis and read into a log message in the appropriate fashion with the fields in the right order to catch the bird to catch the spider to catch the fly.</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;">Made sure that the security messages were being generated in the same way as they were prior to the stasis change by using the following CLI command:

securityevents test generation



Examples Before:
[May  3 14:40:28] SECURITY[1305]: res_security_log.c:134 security_event_cb: SecurityEvent=&quot;FailedACL&quot;,EventTV=&quot;1367610028-869814&quot;,Severity=&quot;Error&quot;,Service=&quot;TEST&quot;,EventVersion=&quot;1&quot;,AccountID=&quot;Username&quot;,SessionID=&quot;Session123&quot;,LocalAddress=&quot;IPV4/UDP/192.168.1.1/12121&quot;,RemoteAddress=&quot;IPV4/UDP/192.168.1.2/12345&quot;,Module=&quot;test_security_events&quot;,ACLName=&quot;TEST_ACL&quot;,SessionTV=&quot;1367610028-869754&quot;
[May  3 14:40:28] SECURITY[1305]: res_security_log.c:134 security_event_cb: SecurityEvent=&quot;InvalidAccountID&quot;,EventTV=&quot;1367610028-869895&quot;,Severity=&quot;Error&quot;,Service=&quot;TEST&quot;,EventVersion=&quot;1&quot;,AccountID=&quot;FakeUser&quot;,SessionID=&quot;Session456&quot;,LocalAddress=&quot;IPV4/TCP/10.1.2.3/4321&quot;,RemoteAddress=&quot;IPV4/TCP/10.1.2.4/123&quot;,Module=&quot;test_security_events&quot;,SessionTV=&quot;1367610028-869854&quot;
[May  3 14:40:28] SECURITY[1305]: res_security_log.c:134 security_event_cb: SecurityEvent=&quot;SessionLimit&quot;,EventTV=&quot;1367610028-869960&quot;,Severity=&quot;Error&quot;,Service=&quot;TEST&quot;,EventVersion=&quot;1&quot;,AccountID=&quot;Jenny&quot;,SessionID=&quot;8675309&quot;,LocalAddress=&quot;IPV4/TLS/10.5.4.3/4444&quot;,RemoteAddress=&quot;IPV4/TLS/10.5.4.2/3333&quot;,Module=&quot;test_security_events&quot;,SessionTV=&quot;1367610028-869923&quot;


Examples After:
[May  3 14:33:35] SECURITY[31607]: res_security_log.c:122 security_event_stasis_cb: SecurityEvent=&quot;FailedACL&quot;,EventTV=&quot;1367609615-957822&quot;,Severity=&quot;Error&quot;,Service=&quot;TEST&quot;,EventVersion=&quot;1&quot;,AccountID=&quot;Username&quot;,SessionID=&quot;Session123&quot;,LocalAddress=&quot;IPV4/UDP/192.168.1.1/12121&quot;,RemoteAddress=&quot;IPV4/UDP/192.168.1.2/12345&quot;,Module=&quot;test_security_events&quot;,ACLName=&quot;TEST_ACL&quot;,SessionTV=&quot;1367609615-957750&quot;
[May  3 14:33:35] SECURITY[31608]: res_security_log.c:122 security_event_stasis_cb: SecurityEvent=&quot;InvalidAccountID&quot;,EventTV=&quot;1367609615-958101&quot;,Severity=&quot;Error&quot;,Service=&quot;TEST&quot;,EventVersion=&quot;1&quot;,AccountID=&quot;FakeUser&quot;,SessionID=&quot;Session456&quot;,LocalAddress=&quot;IPV4/TCP/10.1.2.3/4321&quot;,RemoteAddress=&quot;IPV4/TCP/10.1.2.4/123&quot;,Module=&quot;test_security_events&quot;,SessionTV=&quot;1367609615-957969&quot;
[May  3 14:33:35] SECURITY[31608]: res_security_log.c:122 security_event_stasis_cb: SecurityEvent=&quot;SessionLimit&quot;,EventTV=&quot;1367609615-958404&quot;,Severity=&quot;Error&quot;,Service=&quot;TEST&quot;,EventVersion=&quot;1&quot;,AccountID=&quot;Jenny&quot;,SessionID=&quot;8675309&quot;,LocalAddress=&quot;IPV4/TLS/10.5.4.3/4444&quot;,RemoteAddress=&quot;IPV4/TLS/10.5.4.2/3333&quot;,Module=&quot;test_security_events&quot;,SessionTV=&quot;1367609615-958360&quot;


As you can see it&#39;s basically identical aside from things that are expected to change between runs and the name of the function generating the messages.</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>/trunk/channels/chan_iax2.c <span style="color: grey">(387749)</span></li>

 <li>/trunk/channels/chan_sip.c <span style="color: grey">(387749)</span></li>

 <li>/trunk/include/asterisk/acl.h <span style="color: grey">(387749)</span></li>

 <li>/trunk/include/asterisk/security_events.h <span style="color: grey">(387749)</span></li>

 <li>/trunk/main/asterisk.c <span style="color: grey">(387749)</span></li>

 <li>/trunk/main/manager.c <span style="color: grey">(387749)</span></li>

 <li>/trunk/main/named_acl.c <span style="color: grey">(387749)</span></li>

 <li>/trunk/main/security_events.c <span style="color: grey">(387749)</span></li>

 <li>/trunk/res/res_security_log.c <span style="color: grey">(387749)</span></li>

</ul>

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







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








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