calejost / unimrcp

Automatically exported from code.google.com/p/unimrcp
Apache License 2.0
0 stars 0 forks source link

apt_text_line_read function #77

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I need to parse a body then I wrote the following code:

-------------

apt_text_stream_init(stream, request->body.buf, request->body.length);

while (apt_text_is_eos(stream) == FALSE)
{
    apt_str_t line;
    apt_text_line_read(stream,&line);

    // do sometinh with "line"

}

but if the body is not finished by a CR (or CR/LF) character(s), the last 
line is not parsed (empty "line" is returned).

Arsen, is it possible to "corect/modify" the "parser"  ?

Thks
Anthony

Original issue reported on code.google.com by amasse.a...@gmail.com on 11 Mar 2010 at 10:55

GoogleCodeExporter commented 8 years ago
a solution : 

else { /* end of stream is reached, do not advance stream pos, but set is_eos 
flag */
    stream->is_eos = TRUE;
    line->length = pos - line->buf;
}

Original comment by amasse.a...@gmail.com on 11 Mar 2010 at 11:01

GoogleCodeExporter commented 8 years ago
Hi Anthony,

Why not? Everything looks clear and straight. Function still returns FALSE for
malformed lines, but sets the length just in case ...
So I've just committed your suggestion to trunk (r1579).

Thanks,
Arsen

Original comment by achalo...@gmail.com on 11 Mar 2010 at 12:00

GoogleCodeExporter commented 8 years ago
In fact, I don't find my solution so pretty ;)

why do you say : "Function still returns FALSE for malformed lines". For you a 
stream 
must be finished by CF (LF or CRLF) ?

Original comment by amasse.a...@gmail.com on 11 Mar 2010 at 1:09

GoogleCodeExporter commented 8 years ago
> For you a stream must be finished by CF (LF or CRLF) ?
Sure, and I meant this function should return FALSE if line is not properly
terminated and I'll not look into the parsed "line" as before.

From other hand, I'm not sure where you're going to use it, but if it helps, 
why not...

Original comment by achalo...@gmail.com on 11 Mar 2010 at 1:26

GoogleCodeExporter commented 8 years ago
To parse the body of this request :

ANNOUNCE rtsp://192.168.1.34:1554/media/ASR RTSP/1.0
CSeq: 2
Session: 95bcb25cbaaa3646
Content-Type: application/mrcp
Content-Length: 154

DEFINE-GRAMMAR 1 MRCP/1.0
Content-Type: text/uri-list
Content-Id: request1@form-level.store
Content-Length: 37

http://www.site.com/jours/jours.grxml

Anthony

Original comment by amasse.a...@gmail.com on 11 Mar 2010 at 1:30

GoogleCodeExporter commented 8 years ago
Well, but shouldn't lines in text/uri-list be terminated with a <CRLF> as well.

See http://tools.ietf.org/html/rfc2483
   3) As for all text/* formats, lines are terminated with a CRLF pair.

I assume not all the implementations comply with this rule, though.

Original comment by achalo...@gmail.com on 11 Mar 2010 at 1:49

GoogleCodeExporter commented 8 years ago
Ok, It is also the case with "text/grammar-ref-list", but I prefere to manage 
this case 
for old mrcp client (no reference to rfc2483 on the MRCPv1 draft)

Thanks
Anthony

Original comment by amasse.a...@gmail.com on 11 Mar 2010 at 2:04