<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:12pt"><div><span>Hello Jijo,</span></div><div><span><br></span></div><div>About the example I pointed, the parse_accept_body will fail and let me explain why.</div><div>For the second invocation, 'some value' is not a valid mime type (a mime type is of form 'type/subtype'). When decode_mime_type will not find the '/' separator (see parse_content.c:310) it will fail, making parse_accept_body to fail too.</div><div><br></div><div>If you want to test, just call parse_accept_body with the example I pointed, and you will see it returns -1 for my example (a valid accept header). This is, of course, bad behavior.</div><div><br></div><div>Best regards,</div><div>Marius</div><div><br></div><div style="font-size: 12pt; font-family: arial, helvetica, sans-serif; "><div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "><font
 size="2" face="Arial"><hr size="1"><b><span style="font-weight:bold;">From:</span></b> Jijo &lt;realjijo@gmail.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> Bucur Marius &lt;bucur_marius_ovidiu@yahoo.com&gt;; sr-users@lists.sip-router.org<br><b><span style="font-weight: bold;">Sent:</span></b> Friday, August 19, 2011 11:17 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [SR-Users] decode_mime_type error<br></font><br><div id="yiv90897014">Hi Marius,<br><br>The existing implementation is done considering the limitation of decode_mime_type but somehow missed the change in parse_content_type_hdr. I agree with you that its better to do the change in decode_mime_type as it is common for lot of other callers..<br>
<br>Regarding the example you pointed,<br>According to my understanding from the code, I believe that existing implementation for parse_accept_body shall work as the mime types are predefined. So in the example you pointed for second invocation 'some value' is not a defined mime type as it not matching with predefined types. The decode_mime_type returns end pointer and parse_accept_body shall process only with the valid mime type text/plain.<br>
<br>another&nbsp; example with multiple mime types.., <br>Accept: text/html, multipart/mixed<br>In this case parse_accept_body returns 2 mime types as both are predefined in the list.<br><br>Thanks<br>Jijo<br><br><br><div class="yiv90897014gmail_quote">
On Thu, Aug 18, 2011 at 5:58 PM, Bucur Marius <span dir="ltr">&lt;<a rel="nofollow" ymailto="mailto:bucur_marius_ovidiu@yahoo.com" target="_blank" href="mailto:bucur_marius_ovidiu@yahoo.com">bucur_marius_ovidiu@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote class="yiv90897014gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex;">Hi Jijo,<br>
<br>
In my opinion, decode_mime_type is broken, and parse_accept_body does not work as expected.<br>
For example, this is a valid accept header:<br>
<br>
accept:&nbsp;text/plain;param=",some value".<br>
<br>
but the parse_accept_body will return -1 because the first return value of decode_mime_type is ",some value\"". The second invocation will think "some value\"" is a mime type, which obviously isn't.<br>


<br>
I must say I never saw such an accept header, but the standard permits it.<br>
Indeed, a quick fix would be to ignore the return code when comma is found.<br>
This must be done for other functions that call decode_mime_type like&nbsp;has_body(mime)&nbsp;in textops.<br>
<br>
This is just my opinion, but I think this solution is a bit hackish since the convention, the "promise" that decode_mime_type should respect is to return a non-NULL, non-end pointer ONLY when there are more mime types in the body. And it doesn't.<br>


A lot of functions that call it rely on this. I think it is easier/more elegant to fix the bug in the decode_mime_type then to change the function convention in all callers.<br>
Also, this might work for most callers, but parse_accept_body will still be buggy, as I explained in the example above.<br>
<div><br>
Cheers,<br>
Marius<br>
<br>
________________________________<br>
From: Jijo &lt;<a rel="nofollow" ymailto="mailto:realjijo@gmail.com" target="_blank" href="mailto:realjijo@gmail.com">realjijo@gmail.com</a>&gt;<br>
To: Bucur Marius &lt;<a rel="nofollow" ymailto="mailto:bucur_marius_ovidiu@yahoo.com" target="_blank" href="mailto:bucur_marius_ovidiu@yahoo.com">bucur_marius_ovidiu@yahoo.com</a>&gt;<br>
</div>Sent: Thursday, August 18, 2011 10:48 AM<br>
<div><div>Subject: Re: [SR-Users] decode_mime_type error<br>
<br>
<br>
Hi Marius,<br>
<br>
Right, the same function is used for Accept and&nbsp;&nbsp;Content-Type.<br>
<br>
I don't think there is any change required for parsing Accept. In case of Accept the function decode_mime_type is called in a loop until it find all the media types. On the returning from decode_mime_type(), the main function parse_accept_xxx() checks the pointer is 'comma' or not. if its comma, then the function&nbsp; decode_mime_type called again and find the remaining media types. So i&nbsp; think the existing implementation for Parsing Accept is fine.<br>


<br>
The only change required here is not return error for comma while parsing the Content-Type.<br>
<br>
Thanks<br>
Jijo<br>
<br>
<br>
On Thu, Aug 18, 2011 at 12:32 PM, Bucur Marius &lt;<a rel="nofollow" ymailto="mailto:bucur_marius_ovidiu@yahoo.com" target="_blank" href="mailto:bucur_marius_ovidiu@yahoo.com">bucur_marius_ovidiu@yahoo.com</a>&gt; wrote:<br>
<br>
Hello Jijo,<br>
&gt;<br>
&gt;You are right, multiple mime-types are not allowed. But it seems like decode_mime_type had the purpose of also parsing the Accept header:<br>
&gt;<br>
&gt;Accept: text/html, image/jpeg, multipart<br>
&gt;<br>
&gt;hence the search for commas :).<br>
&gt;The only function that uses this feature and calls decode_mime_type in a loop is&nbsp;parse_accept_body. The other functions that call decode_mime_type just fail when returning ret != end, and since multiple mime types in content-type are not allowed the behavior is fine.<br>


&gt;The bad thing is the Accept header can have mime parameters too (which can contain comma).<br>
&gt;<br>
&gt;Accept &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&nbsp;&nbsp;"Accept" HCOLON [ accept-range *(COMMA accept-range) ]<br>
&gt;accept-range&nbsp;&nbsp; =&nbsp;&nbsp;media-range *(SEMI accept-param)<br>
&gt;media-range&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;( "*/*" / ( m-type SLASH "*" ) / ( m-type SLASH m-subtype ) ) *( SEMI m-parameter )<br>
&gt;<br>
&gt;So I think the best thing would be to change decode_mime_type so that it does a more thorough parsing (e.g. check for parameter) hence a parameter value can contain commas (only if quoted).<br>
&gt;<br>
&gt;<br>
&gt;Cheers,<br>
&gt;<br>
&gt;Marius<br>
&gt;________________________________<br>
&gt;From: Jijo &lt;<a rel="nofollow" ymailto="mailto:realjijo@gmail.com" target="_blank" href="mailto:realjijo@gmail.com">realjijo@gmail.com</a>&gt;<br>
&gt;To: Bucur Marius &lt;<a rel="nofollow" ymailto="mailto:bucur_marius_ovidiu@yahoo.com" target="_blank" href="mailto:bucur_marius_ovidiu@yahoo.com">bucur_marius_ovidiu@yahoo.com</a>&gt;; SIP Router - Kamailio (OpenSER) and SIP Express Router (SER) - Users Mailing List &lt;<a rel="nofollow" ymailto="mailto:sr-users@lists.sip-router.org" target="_blank" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>&gt;<br>


&gt;Sent: Thursday, August 18, 2011 8:04 AM<br>
&gt;Subject: Re: [SR-Users] decode_mime_type error<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;Hi Marius,<br>
&gt;<br>
&gt;Thanks for the response.. I checked the other functions, but they don't have the check for ret !=end, but they check the pointer and if it is comma then loop through again until it find all the media types.<br>
&gt;<br>
&gt;As per the RFC3261 multiple media-types are not supoorted in the Content-Type. So I'm not sure why the author used comma to determine multiple media types . Probably just followed like Route or Record-Route headers..??<br>


&gt;<br>
&gt;Content-Type =&nbsp;&nbsp;( "Content-Type" / "c" ) HCOLON media-type<br>
&gt;media-type =&nbsp;&nbsp;m-type SLASH m-subtype *(SEMI m-parameter)<br>
&gt;m-type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;discrete-type / composite-type<br>
&gt;discrete-type&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;"text" / "image" / "audio" / "video"<br>
&gt;/ "application" / extension-token<br>
&gt;composite-type&nbsp;&nbsp; =&nbsp;&nbsp;"message" / "multipart" / extension-token<br>
&gt;<br>
&gt;Record-Route&nbsp;&nbsp;=&nbsp;&nbsp;"Record-Route" HCOLON rec-route *(COMMA rec-route)<br>
&gt;<br>
&gt;Thanks<br>
&gt;Jijo<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;On Thu, Aug 18, 2011 at 2:23 AM, Bucur Marius &lt;<a rel="nofollow" ymailto="mailto:bucur_marius_ovidiu@yahoo.com" target="_blank" href="mailto:bucur_marius_ovidiu@yahoo.com">bucur_marius_ovidiu@yahoo.com</a>&gt; wrote:<br>
&gt;<br>
&gt;Hello Jijo,<br>
&gt;&gt;<br>
&gt;&gt;It seems like the&nbsp;decode_mime_type is a somehow broken. The comma is very well allowed in boundary, as you said. The BNF specified in RFC2046 permits it.<br>
&gt;&gt;But, the decode_mime_type function ignores everything coming after comma. More than that, it notifies the function caller that this content type has multiple mime types.<br>
&gt;&gt;I think the author of the function thought of something like:<br>
&gt;&gt;<br>
&gt;&gt;Content-Type: text/html, image/jpeg // very weird, though<br>
&gt;&gt;<br>
&gt;&gt;This is wrong, hence the comma can be in a parameter (like in your case).<br>
&gt;&gt;I think the best fix, as you said is to remove that check, hence a non-NULL return value doesn't mean anything (that the content type has multiple mime types).<br>
&gt;&gt;Another fix is to write a "good" decode_mime_type, that checks if the comma is inside a parameter. I don't know if effort is worth it.<br>
&gt;&gt;<br>
&gt;&gt;One thing we need to do is to check if there are any functions in Kamailio that call&nbsp;decode_mime_type and also perform this check (ret != end).<br>
&gt;&gt;<br>
&gt;&gt;Cheers,<br>
&gt;&gt;Marius<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;________________________________<br>
&gt;&gt;From: Jijo &lt;<a rel="nofollow" ymailto="mailto:realjijo@gmail.com" target="_blank" href="mailto:realjijo@gmail.com">realjijo@gmail.com</a>&gt;<br>
&gt;&gt;To: <a rel="nofollow" ymailto="mailto:sr-users@lists.sip-router.org" target="_blank" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>; <a rel="nofollow" ymailto="mailto:sr-dev@lists.sip-router.org" target="_blank" href="mailto:sr-dev@lists.sip-router.org">sr-dev@lists.sip-router.org</a><br>
&gt;&gt;Sent: Wednesday, August 17, 2011 10:54 AM<br>
&gt;&gt;Subject: [SR-Users] decode_mime_type error<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;Hi All,<br>
&gt;&gt;<br>
&gt;&gt;The function parse_content_type_hdr() is failing in decode_mime_type() when Content-Type parameter "boundary" has value comma as below. The error message is "ERROR:parse_content_type_hdr: CONTENT_TYPE hdr contains "<br>


&gt;&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "more then one mime type :-(!<br>
&gt;&gt;<br>
&gt;&gt;Content Type Header is as below, It works fine if the boundary value is without comma.<br>
&gt;&gt;<br>
&gt;&gt;Content-Type: multipart/mixed;boundary=",AW"<br>
&gt;&gt;<br>
&gt;&gt;The parse_content_type_hdr() is failing in the following code,<br>
&gt;&gt;<br>
&gt;&gt;&nbsp;&nbsp;&nbsp; ret = decode_mime_type(msg-&gt;content_type-&gt;body.s, end , &amp;mime);<br>
&gt;&gt;&nbsp;&nbsp;&nbsp; if (ret==0)<br>
&gt;&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; goto error;<br>
&gt;&gt;&nbsp;&nbsp;&nbsp; if (ret!=end) {<br>
&gt;&gt;<br>
&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LOG(L_INFO,"ERROR:parse_content_type_hdr: CONTENT_TYPE hdr contains "<br>
&gt;&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "more then one mime type :-(!\n");<br>
&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; goto error ;<br>
&gt;&gt;&nbsp;&nbsp;&nbsp; }<br>
&gt;&gt;<br>
&gt;&gt;I thought of fixing this issue by commenting the code for condition ret !=end. I'm&nbsp; not sure why we we need that check, as mime variable has the information to process the content.<br>
&gt;&gt;<br>
&gt;&gt;Please let me know if you see any impact.<br>
&gt;&gt;<br>
&gt;&gt;Thanks<br>
&gt;&gt;Jijo<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;_______________________________________________<br>
&gt;&gt;SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list<br>
&gt;&gt;<a rel="nofollow" ymailto="mailto:sr-users@lists.sip-router.org" target="_blank" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a><br>
&gt;&gt;<a rel="nofollow" target="_blank" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a><br>
&gt;&gt;<br>
&gt;&gt;_______________________________________________<br>
&gt;&gt;SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list<br>
&gt;&gt;<a rel="nofollow" ymailto="mailto:sr-users@lists.sip-router.org" target="_blank" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a><br>
&gt;&gt;<a rel="nofollow" target="_blank" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a><br>
&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&gt;<br>
</div></div></blockquote></div><br>
</div><br><br></div></div></div></body></html>