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





<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
 <p style="margin-top: 0;">On November 18th, 2010, 2:57 p.m., <b>Mark Michelson</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;">I think there&#39;s an edge case here that&#39;s not accounted for. When there are multiple SIP headers of a specific type, they can either be specified like the following:
Via: &lt;blah1&gt;
Via: &lt;blah2&gt;
Via: &lt;blah3&gt;
or they can be specified like the following:
Via: &lt;blah1&gt;,&lt;blah2&gt;,&lt;blah3&gt;
In the second case, I don&#39;t *think* that parse_request() will actually treat these as separate Via headers. If you are trying to fail a response due to its having multiple Via headers, then just using __get_header() won&#39;t do the trick.

The real fix for this would be to have parse_request recognize the second case as having multiple Via headers, thus allowing you to use __get_header() in order to iterate over each one. A temporary fix would be to use both __get_header() as well as a check to be sure that the Via line you initially found does not have another value on it as well.

Now, given the nature of how Vias are added to requests and removed from responses, it seems like a case where you will never actually see this occur. It&#39;s probably safe to just add what you have, especially since it wouldn&#39;t be adding any new breakage to the code.</pre>
 </blockquote>




 <p>On November 18th, 2010, 4:01 p.m., <b>Terry Wilson</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;">The problem with doing it in parse_request is that there are lots of headers that can be combined with a comma, and lots that can&#39;t. So you&#39;d end up having to do string comparisons while parsing, then modify the behavior accordingly. It is a serious pain to actually handle this correctly. I&#39;m a fan of SIP, but why they added things like this that have very little value is beyond me. Yes, compacting with commas can save a few bytes, but if that is the goal, why the hell would you use such a wordy protocol in the first place?

I hoped that I could just check for a comma, since the ABNF seemed to show that I couldn&#39;t have one except as the separator...until we get down to via-extension -&gt; generic-param -&gt; token [ EQUAL gen-value] -&gt; gen-value -&gt; token / host /quoted-string -&gt; quoted-string which screws you. So, you instead need to check for &quot;some or no whitespace followed by a comma followed by some or no whitespace followed by &#39;SIP&#39; (or some other token) followed by a slash followed by another token (protocol version) followed by a slash followed by by a transport (TCP, UDP, SCTP, or just a token).

So, yeah, parse_request is definitely where such a fix should be. It is just a lot of work as it requires making a list of every header that either does or doesn&#39;t support the whole join-with-commas thing, then figuring out the &quot;safe way&quot; to actually split on the comma for *each* header. Parsing gets a lot more expensive, but would be correct. And again, lots of work. So it is really just completely writing a parser from scratch to make it &quot;correct&quot;.

Of course, check_via() just does a strchr(via, &#39;,&#39;) when it does the check, so if there is some whacked via-extension like ;crazy=&quot;you,betcha&quot; things will break.

So, I suppose the moral of the story is &quot;we don&#39;t have a real SIP message parser.&quot; I&#39;m not sure how far I should go in fixing that problem. Anybody have any opinions on the matter?</pre>
 </blockquote>








</blockquote>

<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">&quot;The better is the enemy of the good.&quot; (Voltaire)

Ship it.</pre>
<br />








<p>- Simon</p>


<br />
<p>On November 18th, 2010, 2:34 p.m., Terry Wilson wrote:</p>






<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.orgrb/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 and David Vossel.</div>
<div>By Terry Wilson.</div>


<p style="color: grey;"><i>Updated 2010-11-18 14:34:42</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;">8.1.3.3 Vias

   If more than one Via header field value is present in a response, the
   UAC SHOULD discard the message.

      The presence of additional Via header field values that precede
      the originator of the request suggests that the message was
      misrouted or possibly corrupted.</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;">Used sipp to send a request with an extra via header; it was ignored. Valid responses still passed normally.</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.4/channels/chan_sip.c <span style="color: grey">(295442)</span></li>

</ul>

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




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








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