rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply,

                 unsigned char **content_ptr, int return_on_interleaved_data)

{

    RTSPState *rt = s->priv_data;

    char buf[4096], buf1[1024], *q;

    unsigned char ch;

    const char *p;

    int ret, content_length, line_count = 0;

    unsigned char *content = NULL;



    memset(reply, 0, sizeof(*reply));



    /* parse reply (XXX: use buffers) */

    rt->last_reply[0] = '\0';

    for(;;) {

        q = buf;

        for(;;) {

            ret = url_read_complete(rt->rtsp_hd, &ch, 1);

#ifdef DEBUG_RTP_TCP

            dprintf(s, "ret=%d c=%02x [%c]\n", ret, ch, ch);

#endif

            if (ret != 1)

                return -1;

            if (ch == '\n')

                break;

            if (ch == '$') {

                /* XXX: only parse it if first char on line ? */

                if (return_on_interleaved_data) {

                    return 1;

                } else

                rtsp_skip_packet(s);

            } else if (ch != '\r') {

                if ((q - buf) < sizeof(buf) - 1)

                    *q++ = ch;

            }

        }

        *q = '\0';



        dprintf(s, "line='%s'\n", buf);



        /* test if last line */

        if (buf[0] == '\0')

            break;

        p = buf;

        if (line_count == 0) {

            /* get reply code */

            get_word(buf1, sizeof(buf1), &p);

            get_word(buf1, sizeof(buf1), &p);

            reply->status_code = atoi(buf1);

        } else {

            rtsp_parse_line(reply, p);

            av_strlcat(rt->last_reply, p,    sizeof(rt->last_reply));

            av_strlcat(rt->last_reply, "\n", sizeof(rt->last_reply));

        }

        line_count++;

    }



    if (rt->session_id[0] == '\0' && reply->session_id[0] != '\0')

        av_strlcpy(rt->session_id, reply->session_id, sizeof(rt->session_id));



    content_length = reply->content_length;

    if (content_length > 0) {

        /* leave some room for a trailing '\0' (useful for simple parsing) */

        content = av_malloc(content_length + 1);

        (void)url_read_complete(rt->rtsp_hd, content, content_length);

        content[content_length] = '\0';

    }

    if (content_ptr)

        *content_ptr = content;

    else

        av_free(content);



    /* EOS */

    if (reply->notice == 2101 /* End-of-Stream Reached */      ||

        reply->notice == 2104 /* Start-of-Stream Reached */    ||

        reply->notice == 2306 /* Continuous Feed Terminated */)

        rt->state = RTSP_STATE_IDLE;

    else if (reply->notice >= 4400 && reply->notice < 5500)

        return AVERROR(EIO); /* data or server error */

    else if (reply->notice == 2401 /* Ticket Expired */ ||

             (reply->notice >= 5500 && reply->notice < 5600) /* end of term */ )

        return AVERROR(EPERM);



    return 0;

}

rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply,

                 unsigned char **content_ptr, int return_on_interleaved_data)

{

    RTSPState *rt = s->priv_data;

    char buf[4096], buf1[1024], *q;

    unsigned char ch;

    const char *p;

    int ret, content_length, line_count = 0;

    unsigned char *content = NULL;



    memset(reply, 0, sizeof(*reply));



    

    rt->last_reply[0] = '\0';

    for(;;) {

        q = buf;

        for(;;) {

            ret = url_read_complete(rt->rtsp_hd, &ch, 1);

#ifdef DEBUG_RTP_TCP

            dprintf(s, "ret=%d c=%02x [%c]\n", ret, ch, ch);

#endif

            if (ret != 1)

                return -1;

            if (ch == '\n')

                break;

            if (ch == '$') {

                

                if (return_on_interleaved_data) {

                    return 1;

                } else

                rtsp_skip_packet(s);

            } else if (ch != '\r') {

                if ((q - buf) < sizeof(buf) - 1)

                    *q++ = ch;

            }

        }

        *q = '\0';



        dprintf(s, "line='%s'\n", buf);



        

        if (buf[0] == '\0')

            break;

        p = buf;

        if (line_count == 0) {

            

            get_word(buf1, sizeof(buf1), &p);

            get_word(buf1, sizeof(buf1), &p);

            reply->status_code = atoi(buf1);

        } else {

            rtsp_parse_line(reply, p);

            av_strlcat(rt->last_reply, p,    sizeof(rt->last_reply));

            av_strlcat(rt->last_reply, "\n", sizeof(rt->last_reply));

        }

        line_count++;

    }



    if (rt->session_id[0] == '\0' && reply->session_id[0] != '\0')

        av_strlcpy(rt->session_id, reply->session_id, sizeof(rt->session_id));



    content_length = reply->content_length;

    if (content_length > 0) {

        

        content = av_malloc(content_length + 1);

        (void)url_read_complete(rt->rtsp_hd, content, content_length);

        content[content_length] = '\0';

    }

    if (content_ptr)

        *content_ptr = content;

    else

        av_free(content);



    

    if (reply->notice == 2101       ||

        reply->notice == 2104     ||

        reply->notice == 2306 )

        rt->state = RTSP_STATE_IDLE;

    else if (reply->notice >= 4400 && reply->notice < 5500)

        return AVERROR(EIO); 

    else if (reply->notice == 2401  ||

             (reply->notice >= 5500 && reply->notice < 5600)  )

        return AVERROR(EPERM);



    return 0;

}

FUNC_0 (AVFormatContext *VAR_0, RTSPMessageHeader *VAR_1,

                 unsigned char **VAR_2, int VAR_3)

{

    RTSPState *rt = VAR_0->priv_data;

    char VAR_4[4096], VAR_5[1024], *VAR_6;

    unsigned char VAR_7;

    const char *VAR_8;

    int VAR_9, VAR_10, VAR_11 = 0;

    unsigned char *VAR_12 = NULL;



    memset(VAR_1, 0, sizeof(*VAR_1));



    

    rt->last_reply[0] = '\0';

    for(;;) {

        VAR_6 = VAR_4;

        for(;;) {

            VAR_9 = url_read_complete(rt->rtsp_hd, &VAR_7, 1);

#ifdef DEBUG_RTP_TCP

            dprintf(VAR_0, "VAR_9=%d c=%02x [%c]\n", VAR_9, VAR_7, VAR_7);

#endif

            if (VAR_9 != 1)

                return -1;

            if (VAR_7 == '\n')

                break;

            if (VAR_7 == '$') {

                

                if (VAR_3) {

                    return 1;

                } else

                rtsp_skip_packet(VAR_0);

            } else if (VAR_7 != '\r') {

                if ((VAR_6 - VAR_4) < sizeof(VAR_4) - 1)

                    *VAR_6++ = VAR_7;

            }

        }

        *VAR_6 = '\0';



        dprintf(VAR_0, "line='%VAR_0'\n", VAR_4);



        

        if (VAR_4[0] == '\0')

            break;

        VAR_8 = VAR_4;

        if (VAR_11 == 0) {

            

            get_word(VAR_5, sizeof(VAR_5), &VAR_8);

            get_word(VAR_5, sizeof(VAR_5), &VAR_8);

            VAR_1->status_code = atoi(VAR_5);

        } else {

            rtsp_parse_line(VAR_1, VAR_8);

            av_strlcat(rt->last_reply, VAR_8,    sizeof(rt->last_reply));

            av_strlcat(rt->last_reply, "\n", sizeof(rt->last_reply));

        }

        VAR_11++;

    }



    if (rt->session_id[0] == '\0' && VAR_1->session_id[0] != '\0')

        av_strlcpy(rt->session_id, VAR_1->session_id, sizeof(rt->session_id));



    VAR_10 = VAR_1->VAR_10;

    if (VAR_10 > 0) {

        

        VAR_12 = av_malloc(VAR_10 + 1);

        (void)url_read_complete(rt->rtsp_hd, VAR_12, VAR_10);

        VAR_12[VAR_10] = '\0';

    }

    if (VAR_2)

        *VAR_2 = VAR_12;

    else

        av_free(VAR_12);



    

    if (VAR_1->notice == 2101       ||

        VAR_1->notice == 2104     ||

        VAR_1->notice == 2306 )

        rt->state = RTSP_STATE_IDLE;

    else if (VAR_1->notice >= 4400 && VAR_1->notice < 5500)

        return AVERROR(EIO); 

    else if (VAR_1->notice == 2401  ||

             (VAR_1->notice >= 5500 && VAR_1->notice < 5600)  )

        return AVERROR(EPERM);



    return 0;

}

FUNC_0 (AVFormatContext *VAR_0, RTSPMessageHeader *VAR_1,
unsigned char **VAR_2, int VAR_3)
{ RTSPState *rt = VAR_0->priv_data; char VAR_4[4096], VAR_5[1024], *VAR_6; unsigned char VAR_7; const char *VAR_8; int VAR_9, VAR_10, VAR_11 = 0; unsigned char *VAR_12 = NULL; memset(VAR_1, 0, sizeof(*VAR_1)); rt->last_reply[0] = '\0'; for(;;) { VAR_6 = VAR_4; for(;;) { VAR_9 = url_read_complete(rt->rtsp_hd, &VAR_7, 1); #ifdef DEBUG_RTP_TCP
dprintf(VAR_0, "VAR_9=%d c=%02x [%c]\n", VAR_9, VAR_7, VAR_7); #endif
if (VAR_9 != 1)
return -1; if (VAR_7 == '\n')
break; if (VAR_7 == '$') { if (VAR_3) { return 1; } else rtsp_skip_packet(VAR_0); } else if (VAR_7 != '\r') { if ((VAR_6 - VAR_4) < sizeof(VAR_4) - 1)
*VAR_6++ = VAR_7; } } *VAR_6 = '\0'; dprintf(VAR_0, "line='%VAR_0'\n", VAR_4); if (VAR_4[0] == '\0')
break; VAR_8 = VAR_4; if (VAR_11 == 0) { get_word(VAR_5, sizeof(VAR_5), &VAR_8); get_word(VAR_5, sizeof(VAR_5), &VAR_8); VAR_1->status_code = atoi(VAR_5); } else { rtsp_parse_line(VAR_1, VAR_8); av_strlcat(rt->last_reply, VAR_8,    sizeof(rt->last_reply)); av_strlcat(rt->last_reply, "\n", sizeof(rt->last_reply)); } VAR_11++; } if (rt->session_id[0] == '\0' && VAR_1->session_id[0] != '\0')
av_strlcpy(rt->session_id, VAR_1->session_id, sizeof(rt->session_id)); VAR_10 = VAR_1->VAR_10; if (VAR_10 > 0) { VAR_12 = av_malloc(VAR_10 + 1); (void)url_read_complete(rt->rtsp_hd, VAR_12, VAR_10); VAR_12[VAR_10] = '\0'; } if (VAR_2)
*VAR_2 = VAR_12; else
av_free(VAR_12); if (VAR_1->notice == 2101       ||
VAR_1->notice == 2104     ||
VAR_1->notice == 2306 )
rt->state = RTSP_STATE_IDLE; else if (VAR_1->notice >= 4400 && VAR_1->notice < 5500)
return AVERROR(EIO); else if (VAR_1->notice == 2401  ||
(VAR_1->notice >= 5500 && VAR_1->notice < 5600)  )
return AVERROR(EPERM); return 0; }