static int rtsp_parse_request(HTTPContext *c)

{

    const char *p, *p1, *p2;

    char cmd[32];

    char url[1024];

    char protocol[32];

    char line[1024];

    int len;

    RTSPMessageHeader header1, *header = &header1;



    c->buffer_ptr[0] = '\0';

    p = c->buffer;



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

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

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



    av_strlcpy(c->method, cmd, sizeof(c->method));

    av_strlcpy(c->url, url, sizeof(c->url));

    av_strlcpy(c->protocol, protocol, sizeof(c->protocol));



    if (url_open_dyn_buf(&c->pb) < 0) {

        /* XXX: cannot do more */

        c->pb = NULL; /* safety */

        return -1;

    }



    /* check version name */

    if (strcmp(protocol, "RTSP/1.0") != 0) {

        rtsp_reply_error(c, RTSP_STATUS_VERSION);

        goto the_end;

    }



    /* parse each header line */

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

    /* skip to next line */

    while (*p != '\n' && *p != '\0')

        p++;

    if (*p == '\n')

        p++;

    while (*p != '\0') {

        p1 = strchr(p, '\n');

        if (!p1)

            break;

        p2 = p1;

        if (p2 > p && p2[-1] == '\r')

            p2--;

        /* skip empty line */

        if (p2 == p)

            break;

        len = p2 - p;

        if (len > sizeof(line) - 1)

            len = sizeof(line) - 1;

        memcpy(line, p, len);

        line[len] = '\0';

        ff_rtsp_parse_line(header, line, NULL);

        p = p1 + 1;

    }



    /* handle sequence number */

    c->seq = header->seq;



    if (!strcmp(cmd, "DESCRIBE"))

        rtsp_cmd_describe(c, url);

    else if (!strcmp(cmd, "OPTIONS"))

        rtsp_cmd_options(c, url);

    else if (!strcmp(cmd, "SETUP"))

        rtsp_cmd_setup(c, url, header);

    else if (!strcmp(cmd, "PLAY"))

        rtsp_cmd_play(c, url, header);

    else if (!strcmp(cmd, "PAUSE"))

        rtsp_cmd_pause(c, url, header);

    else if (!strcmp(cmd, "TEARDOWN"))

        rtsp_cmd_teardown(c, url, header);

    else

        rtsp_reply_error(c, RTSP_STATUS_METHOD);



 the_end:

    len = url_close_dyn_buf(c->pb, &c->pb_buffer);

    c->pb = NULL; /* safety */

    if (len < 0) {

        /* XXX: cannot do more */

        return -1;

    }

    c->buffer_ptr = c->pb_buffer;

    c->buffer_end = c->pb_buffer + len;

    c->state = RTSPSTATE_SEND_REPLY;

    return 0;

}

static int rtsp_parse_request(HTTPContext *c)

{

    const char *p, *p1, *p2;

    char cmd[32];

    char url[1024];

    char protocol[32];

    char line[1024];

    int len;

    RTSPMessageHeader header1, *header = &header1;



    c->buffer_ptr[0] = '\0';

    p = c->buffer;



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

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

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



    av_strlcpy(c->method, cmd, sizeof(c->method));

    av_strlcpy(c->url, url, sizeof(c->url));

    av_strlcpy(c->protocol, protocol, sizeof(c->protocol));



    if (url_open_dyn_buf(&c->pb) < 0) {

        

        c->pb = NULL; 

        return -1;

    }



    

    if (strcmp(protocol, "RTSP/1.0") != 0) {

        rtsp_reply_error(c, RTSP_STATUS_VERSION);

        goto the_end;

    }



    

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

    

    while (*p != '\n' && *p != '\0')

        p++;

    if (*p == '\n')

        p++;

    while (*p != '\0') {

        p1 = strchr(p, '\n');

        if (!p1)

            break;

        p2 = p1;

        if (p2 > p && p2[-1] == '\r')

            p2--;

        

        if (p2 == p)

            break;

        len = p2 - p;

        if (len > sizeof(line) - 1)

            len = sizeof(line) - 1;

        memcpy(line, p, len);

        line[len] = '\0';

        ff_rtsp_parse_line(header, line, NULL);

        p = p1 + 1;

    }



    

    c->seq = header->seq;



    if (!strcmp(cmd, "DESCRIBE"))

        rtsp_cmd_describe(c, url);

    else if (!strcmp(cmd, "OPTIONS"))

        rtsp_cmd_options(c, url);

    else if (!strcmp(cmd, "SETUP"))

        rtsp_cmd_setup(c, url, header);

    else if (!strcmp(cmd, "PLAY"))

        rtsp_cmd_play(c, url, header);

    else if (!strcmp(cmd, "PAUSE"))

        rtsp_cmd_pause(c, url, header);

    else if (!strcmp(cmd, "TEARDOWN"))

        rtsp_cmd_teardown(c, url, header);

    else

        rtsp_reply_error(c, RTSP_STATUS_METHOD);



 the_end:

    len = url_close_dyn_buf(c->pb, &c->pb_buffer);

    c->pb = NULL; 

    if (len < 0) {

        

        return -1;

    }

    c->buffer_ptr = c->pb_buffer;

    c->buffer_end = c->pb_buffer + len;

    c->state = RTSPSTATE_SEND_REPLY;

    return 0;

}

        p1 = strchr(p, '\n');
static int FUNC_0(HTTPContext *VAR_0)

{

    const char *VAR_1, *VAR_2, *VAR_3;

    char VAR_4[32];

    char VAR_5[1024];

    char VAR_6[32];

    char VAR_7[1024];

    int VAR_8;

    RTSPMessageHeader header1, *header = &header1;



    VAR_0->buffer_ptr[0] = '\0';

    VAR_1 = VAR_0->buffer;



    get_word(VAR_4, sizeof(VAR_4), &VAR_1);

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

    get_word(VAR_6, sizeof(VAR_6), &VAR_1);



    av_strlcpy(VAR_0->method, VAR_4, sizeof(VAR_0->method));

    av_strlcpy(VAR_0->VAR_5, VAR_5, sizeof(VAR_0->VAR_5));

    av_strlcpy(VAR_0->VAR_6, VAR_6, sizeof(VAR_0->VAR_6));



    if (url_open_dyn_buf(&VAR_0->pb) < 0) {

        

        VAR_0->pb = NULL; 

        return -1;

    }



    

    if (strcmp(VAR_6, "RTSP/1.0") != 0) {

        rtsp_reply_error(VAR_0, RTSP_STATUS_VERSION);

        goto the_end;

    }



    

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

    

    while (*VAR_1 != '\n' && *VAR_1 != '\0')

        VAR_1++;

    if (*VAR_1 == '\n')

        VAR_1++;

    while (*VAR_1 != '\0') {

        VAR_2 = strchr(VAR_1, '\n');

        if (!VAR_2)

            break;

        VAR_3 = VAR_2;

        if (VAR_3 > VAR_1 && VAR_3[-1] == '\r')

            VAR_3--;

        

        if (VAR_3 == VAR_1)

            break;

        VAR_8 = VAR_3 - VAR_1;

        if (VAR_8 > sizeof(VAR_7) - 1)

            VAR_8 = sizeof(VAR_7) - 1;

        memcpy(VAR_7, VAR_1, VAR_8);

        VAR_7[VAR_8] = '\0';

        ff_rtsp_parse_line(header, VAR_7, NULL);

        VAR_1 = VAR_2 + 1;

    }



    

    VAR_0->seq = header->seq;



    if (!strcmp(VAR_4, "DESCRIBE"))

        rtsp_cmd_describe(VAR_0, VAR_5);

    else if (!strcmp(VAR_4, "OPTIONS"))

        rtsp_cmd_options(VAR_0, VAR_5);

    else if (!strcmp(VAR_4, "SETUP"))

        rtsp_cmd_setup(VAR_0, VAR_5, header);

    else if (!strcmp(VAR_4, "PLAY"))

        rtsp_cmd_play(VAR_0, VAR_5, header);

    else if (!strcmp(VAR_4, "PAUSE"))

        rtsp_cmd_pause(VAR_0, VAR_5, header);

    else if (!strcmp(VAR_4, "TEARDOWN"))

        rtsp_cmd_teardown(VAR_0, VAR_5, header);

    else

        rtsp_reply_error(VAR_0, RTSP_STATUS_METHOD);



 the_end:

    VAR_8 = url_close_dyn_buf(VAR_0->pb, &VAR_0->pb_buffer);

    VAR_0->pb = NULL; 

    if (VAR_8 < 0) {

        

        return -1;

    }

    VAR_0->buffer_ptr = VAR_0->pb_buffer;

    VAR_0->buffer_end = VAR_0->pb_buffer + VAR_8;

    VAR_0->state = RTSPSTATE_SEND_REPLY;

    return 0;

}

static int FUNC_0(HTTPContext *VAR_0)
{ const char *VAR_1, *VAR_2, *VAR_3; char VAR_4[32]; char VAR_5[1024]; char VAR_6[32]; char VAR_7[1024]; int VAR_8; RTSPMessageHeader header1, *header = &header1; VAR_0->buffer_ptr[0] = '\0'; VAR_1 = VAR_0->buffer; get_word(VAR_4, sizeof(VAR_4), &VAR_1); get_word(VAR_5, sizeof(VAR_5), &VAR_1); get_word(VAR_6, sizeof(VAR_6), &VAR_1); av_strlcpy(VAR_0->method, VAR_4, sizeof(VAR_0->method)); av_strlcpy(VAR_0->VAR_5, VAR_5, sizeof(VAR_0->VAR_5)); av_strlcpy(VAR_0->VAR_6, VAR_6, sizeof(VAR_0->VAR_6)); if (url_open_dyn_buf(&VAR_0->pb) < 0) { VAR_0->pb = NULL; return -1; } if (strcmp(VAR_6, "RTSP/1.0") != 0) { rtsp_reply_error(VAR_0, RTSP_STATUS_VERSION); goto the_end; } memset(header, 0, sizeof(*header)); while (*VAR_1 != '\n' && *VAR_1 != '\0')
VAR_1++; if (*VAR_1 == '\n')
VAR_1++; while (*VAR_1 != '\0') { VAR_2 = strchr(VAR_1, '\n'); if (!VAR_2)
break; VAR_3 = VAR_2; if (VAR_3 > VAR_1 && VAR_3[-1] == '\r')
VAR_3--; if (VAR_3 == VAR_1)
break; VAR_8 = VAR_3 - VAR_1; if (VAR_8 > sizeof(VAR_7) - 1)
VAR_8 = sizeof(VAR_7) - 1; memcpy(VAR_7, VAR_1, VAR_8); VAR_7[VAR_8] = '\0'; ff_rtsp_parse_line(header, VAR_7, NULL); VAR_1 = VAR_2 + 1; } VAR_0->seq = header->seq; if (!strcmp(VAR_4, "DESCRIBE"))
rtsp_cmd_describe(VAR_0, VAR_5); else if (!strcmp(VAR_4, "OPTIONS"))
rtsp_cmd_options(VAR_0, VAR_5); else if (!strcmp(VAR_4, "SETUP"))
rtsp_cmd_setup(VAR_0, VAR_5, header); else if (!strcmp(VAR_4, "PLAY"))
rtsp_cmd_play(VAR_0, VAR_5, header); else if (!strcmp(VAR_4, "PAUSE"))
rtsp_cmd_pause(VAR_0, VAR_5, header); else if (!strcmp(VAR_4, "TEARDOWN"))
rtsp_cmd_teardown(VAR_0, VAR_5, header); else
rtsp_reply_error(VAR_0, RTSP_STATUS_METHOD); the_end:
VAR_8 = url_close_dyn_buf(VAR_0->pb, &VAR_0->pb_buffer); VAR_0->pb = NULL; if (VAR_8 < 0) { return -1; } VAR_0->buffer_ptr = VAR_0->pb_buffer; VAR_0->buffer_end = VAR_0->pb_buffer + VAR_8; VAR_0->state = RTSPSTATE_SEND_REPLY; return 0; }