Right now when I run it, its run over the entire message, there's no check for a body. The only bodies I deal with currently are SDP and PIDF. The former is line oriented and the latter is XML so I suppose it hasn't been an issue to date.
Good point on the quoted strings. Funny I've never run into that problem in all the testing I've done over several years. I'll put in an escape section for quoted strings. These are exactly the kind of comments I was hoping for! Thanks, FM -----Original Message----- From: Paul Kyzivat [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 01, 2008 12:10 PM To: Frank W. Miller Cc: 'Iñaki Baz Castillo'; sip-implementors@lists.cs.columbia.edu Subject: Re: [Sip-implementors] Why SIP abnf is so permissive??? Frank, You don't say whether the message this routine is passed included the body or not. But either way it is problematic. The whitespace rules for sip don't extend into quoted strings or the innards or URIs, or into the message body. The processing in this routine can make hash of all those things. Paul 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: sip-implementors@lists.cs.columbia.edu > 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 Sip-implementors@lists.cs.columbia.edu https://lists.cs.columbia.edu/cucslists/listinfo/sip-implementors