Another small thing: continuation lines can start with horizontal tab in 
addition to space.

Anders

Frank W. Miller wrote:
> 
> I've been following this discussion for a bit.  I agree that the grammar is
> probably overly permissive but it is what it is.  Just for fun, I decided to
> contribute a bit here.  In my implementation, I run the following little
> preprocessor bit over all incoming messages.  The idea is to try to put the
> message in a little bit more "normal" form prior to parsing.  This code is
> part of the Asterisk implementation as well when the "pendantic" option is
> turned on.  It does a single pass over the message and collapses it
> "in-place" in the provided buffer.  It can probably be improved so I'm
> interested in any and all comments.  No license on this, use it as you
> will...
> 
> 
> 
> #include <ctype.h>
> #include <stdlib.h>
> 
> int
> lws2sws(char *msgbuf, int len)
> {
>       int h = 0, t = 0;
>       int lws = 0;
> 
>       if (msgbuf == NULL)
>               return (-1);
> 
>       for (; h < len;) {
>               /* Eliminate all CRs */
>               if (msgbuf[h] == '\r') {
>                       h++;
>                       continue;
>               }
>               /* Check for end-of-line */
>               if (msgbuf[h] == '\n') {
>                       /* Check for end-of-message */
>                       if (h + 1 == len)
>                               break;
> 
>                       /* Check for a continuation line */
>                       if (msgbuf[h + 1] == ' ') {
>                               /* Merge continuation line */
>                               h++;
>                               continue;
>                       }
>                       /* Propagate LF and start new line */
>                       msgbuf[t++] = msgbuf[h++];
>                       lws = 0;
>                       continue;
>               }
>               if (msgbuf[h] == ' ' || msgbuf[h] == '\t') {
>                       if (lws) {
>                               h++;
>                               continue;
>                       }
>                       msgbuf[t++] = msgbuf[h++];
>                       lws = 1;
>                       continue;
>               }
>               msgbuf[t++] = msgbuf[h++];
>               if (lws)
>                       lws = 0;
>       }
>       msgbuf[t] = '\0';
>       return t;
> }
> 
> 
> 
> 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Iñaki
> Baz Castillo
> Sent: Saturday, March 29, 2008 4:26 PM
> To: [email protected]
> Subject: Re: [Sip-implementors] Why SIP abnf is so permissive???
> 
> El Sábado, 29 de Marzo de 2008, Valentin Nechayev escribió:
>> Your example
>> (b) is too radical, it's better to compare with something like:
>>
>> === c)
>> INVITE sip:[EMAIL PROTECTED] SIP/2.0
>> From                    : alice <[EMAIL PROTECTED]>;             tag=1
>> To                      : white rabbit <[EMAIL PROTECTED]>;     tag=2
>> i                       : [EMAIL PROTECTED]
>> ===
>>
>> which isn't much worse than non-spaced form.
> 
> Sure it's not so bad, but for example I know some SIP devices/softphones
> that 
> fail parsing a message with SP / HTAB between header field name and COLON.
> Probably no SIP implementation adds unnecesary SP / HTAB after COLON, so
> most 
> of them can interoperate, but the risk is there.
> 
> 
> 
>>> Ok, I understand that SIP was born from HTTP and so, but anyway I hope
> in
>>> a future SIP/X.0 appears eliminating so many and innecesary permissive
>>> syntax.
>> If to invent such, this already won't be text format
> 
> Why not? I like SIP format, it's human readable (AFAIK one of its success 
> cause) but IMHO a no so much flexible grammar could be nicer (no so much 
> space allowed, no line folding... ) just it, I wouldn't like to see a binary
> 
> format ;)
> 
> Thanks a lot for your comment and explanation. Best regards.
> 
> 
_______________________________________________
Sip-implementors mailing list
[email protected]
https://lists.cs.columbia.edu/cucslists/listinfo/sip-implementors

Reply via email to