static int http_parse_request(HTTPContext *c)

{

    const char *p;

    char *p1;

    enum RedirType redir_type;

    char cmd[32];

    char info[1024], filename[1024];

    char url[1024], *q;

    char protocol[32];

    char msg[1024];

    const char *mime_type;

    FFServerStream *stream;

    int i;

    char ratebuf[32];

    const char *useragent = 0;



    p = c->buffer;

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

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



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

        c->post = 0;

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

        c->post = 1;

    else

        return -1;



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

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



    get_word(protocol, sizeof(protocol), (const char **)&p);

    if (strcmp(protocol, "HTTP/1.0") && strcmp(protocol, "HTTP/1.1"))

        return -1;



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



    if (config.debug)

        http_log("%s - - New connection: %s %s\n", inet_ntoa(c->from_addr.sin_addr), cmd, url);



    /* find the filename and the optional info string in the request */

    p1 = strchr(url, '?');

    if (p1) {

        av_strlcpy(info, p1, sizeof(info));

        *p1 = '\0';

    } else

        info[0] = '\0';



    av_strlcpy(filename, url + ((*url == '/') ? 1 : 0), sizeof(filename)-1);



    for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {

        if (av_strncasecmp(p, "User-Agent:", 11) == 0) {

            useragent = p + 11;

            if (*useragent && *useragent != '\n' && av_isspace(*useragent))

                useragent++;

            break;

        }

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

        if (!p)

            break;



        p++;

    }



    redir_type = REDIR_NONE;

    if (av_match_ext(filename, "asx")) {

        redir_type = REDIR_ASX;

        filename[strlen(filename)-1] = 'f';

    } else if (av_match_ext(filename, "asf") &&

        (!useragent || av_strncasecmp(useragent, "NSPlayer", 8) != 0)) {

        /* if this isn't WMP or lookalike, return the redirector file */

        redir_type = REDIR_ASF;

    } else if (av_match_ext(filename, "rpm,ram")) {

        redir_type = REDIR_RAM;

        strcpy(filename + strlen(filename)-2, "m");

    } else if (av_match_ext(filename, "rtsp")) {

        redir_type = REDIR_RTSP;

        compute_real_filename(filename, sizeof(filename) - 1);

    } else if (av_match_ext(filename, "sdp")) {

        redir_type = REDIR_SDP;

        compute_real_filename(filename, sizeof(filename) - 1);

    }



    // "redirect" / request to index.html

    if (!strlen(filename))

        av_strlcpy(filename, "index.html", sizeof(filename) - 1);



    stream = config.first_stream;

    while (stream) {

        if (!strcmp(stream->filename, filename) && validate_acl(stream, c))

            break;

        stream = stream->next;

    }

    if (!stream) {

        snprintf(msg, sizeof(msg), "File '%s' not found", url);

        http_log("File '%s' not found\n", url);

        goto send_error;

    }



    c->stream = stream;

    memcpy(c->feed_streams, stream->feed_streams, sizeof(c->feed_streams));

    memset(c->switch_feed_streams, -1, sizeof(c->switch_feed_streams));



    if (stream->stream_type == STREAM_TYPE_REDIRECT) {

        c->http_error = 301;

        q = c->buffer;

        snprintf(q, c->buffer_size,

                      "HTTP/1.0 301 Moved\r\n"

                      "Location: %s\r\n"

                      "Content-type: text/html\r\n"

                      "\r\n"

                      "<html><head><title>Moved</title></head><body>\r\n"

                      "You should be <a href=\"%s\">redirected</a>.\r\n"

                      "</body></html>\r\n", stream->feed_filename, stream->feed_filename);

        q += strlen(q);

        /* prepare output buffer */

        c->buffer_ptr = c->buffer;

        c->buffer_end = q;

        c->state = HTTPSTATE_SEND_HEADER;

        return 0;

    }



    /* If this is WMP, get the rate information */

    if (extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) {

        if (modify_current_stream(c, ratebuf)) {

            for (i = 0; i < FF_ARRAY_ELEMS(c->feed_streams); i++) {

                if (c->switch_feed_streams[i] >= 0)

                    c->switch_feed_streams[i] = -1;

            }

        }

    }



    if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE)

        current_bandwidth += stream->bandwidth;



    /* If already streaming this feed, do not let start another feeder. */

    if (stream->feed_opened) {

        snprintf(msg, sizeof(msg), "This feed is already being received.");

        http_log("Feed '%s' already being received\n", stream->feed_filename);

        goto send_error;

    }



    if (c->post == 0 && config.max_bandwidth < current_bandwidth) {

        c->http_error = 503;

        q = c->buffer;

        snprintf(q, c->buffer_size,

                      "HTTP/1.0 503 Server too busy\r\n"

                      "Content-type: text/html\r\n"

                      "\r\n"

                      "<html><head><title>Too busy</title></head><body>\r\n"

                      "<p>The server is too busy to serve your request at this time.</p>\r\n"

                      "<p>The bandwidth being served (including your stream) is %"PRIu64"kbit/sec, "

                      "and this exceeds the limit of %"PRIu64"kbit/sec.</p>\r\n"

                      "</body></html>\r\n", current_bandwidth, config.max_bandwidth);

        q += strlen(q);

        /* prepare output buffer */

        c->buffer_ptr = c->buffer;

        c->buffer_end = q;

        c->state = HTTPSTATE_SEND_HEADER;

        return 0;

    }



    if (redir_type != REDIR_NONE) {

        const char *hostinfo = 0;



        for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {

            if (av_strncasecmp(p, "Host:", 5) == 0) {

                hostinfo = p + 5;

                break;

            }

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

            if (!p)

                break;



            p++;

        }



        if (hostinfo) {

            char *eoh;

            char hostbuf[260];



            while (av_isspace(*hostinfo))

                hostinfo++;



            eoh = strchr(hostinfo, '\n');

            if (eoh) {

                if (eoh[-1] == '\r')

                    eoh--;



                if (eoh - hostinfo < sizeof(hostbuf) - 1) {

                    memcpy(hostbuf, hostinfo, eoh - hostinfo);

                    hostbuf[eoh - hostinfo] = 0;



                    c->http_error = 200;

                    q = c->buffer;

                    switch(redir_type) {

                    case REDIR_ASX:

                        snprintf(q, c->buffer_size,

                                      "HTTP/1.0 200 ASX Follows\r\n"

                                      "Content-type: video/x-ms-asf\r\n"

                                      "\r\n"

                                      "<ASX Version=\"3\">\r\n"

                                      //"<!-- Autogenerated by ffserver -->\r\n"

                                      "<ENTRY><REF HREF=\"http://%s/%s%s\"/></ENTRY>\r\n"

                                      "</ASX>\r\n", hostbuf, filename, info);

                        q += strlen(q);

                        break;

                    case REDIR_RAM:

                        snprintf(q, c->buffer_size,

                                      "HTTP/1.0 200 RAM Follows\r\n"

                                      "Content-type: audio/x-pn-realaudio\r\n"

                                      "\r\n"

                                      "# Autogenerated by ffserver\r\n"

                                      "http://%s/%s%s\r\n", hostbuf, filename, info);

                        q += strlen(q);

                        break;

                    case REDIR_ASF:

                        snprintf(q, c->buffer_size,

                                      "HTTP/1.0 200 ASF Redirect follows\r\n"

                                      "Content-type: video/x-ms-asf\r\n"

                                      "\r\n"

                                      "[Reference]\r\n"

                                      "Ref1=http://%s/%s%s\r\n", hostbuf, filename, info);

                        q += strlen(q);

                        break;

                    case REDIR_RTSP:

                        {

                            char hostname[256], *p;

                            /* extract only hostname */

                            av_strlcpy(hostname, hostbuf, sizeof(hostname));

                            p = strrchr(hostname, ':');

                            if (p)

                                *p = '\0';

                            snprintf(q, c->buffer_size,

                                          "HTTP/1.0 200 RTSP Redirect follows\r\n"

                                          /* XXX: incorrect MIME type ? */

                                          "Content-type: application/x-rtsp\r\n"

                                          "\r\n"

                                          "rtsp://%s:%d/%s\r\n", hostname, ntohs(config.rtsp_addr.sin_port), filename);

                            q += strlen(q);

                        }

                        break;

                    case REDIR_SDP:

                        {

                            uint8_t *sdp_data;

                            int sdp_data_size;

                            socklen_t len;

                            struct sockaddr_in my_addr;



                            snprintf(q, c->buffer_size,

                                          "HTTP/1.0 200 OK\r\n"

                                          "Content-type: application/sdp\r\n"

                                          "\r\n");

                            q += strlen(q);



                            len = sizeof(my_addr);



                            /* XXX: Should probably fail? */

                            if (getsockname(c->fd, (struct sockaddr *)&my_addr, &len))

                                http_log("getsockname() failed\n");



                            /* XXX: should use a dynamic buffer */

                            sdp_data_size = prepare_sdp_description(stream,

                                                                    &sdp_data,

                                                                    my_addr.sin_addr);

                            if (sdp_data_size > 0) {

                                memcpy(q, sdp_data, sdp_data_size);

                                q += sdp_data_size;

                                *q = '\0';

                                av_free(sdp_data);

                            }

                        }

                        break;

                    default:

                        abort();

                        break;

                    }



                    /* prepare output buffer */

                    c->buffer_ptr = c->buffer;

                    c->buffer_end = q;

                    c->state = HTTPSTATE_SEND_HEADER;

                    return 0;

                }

            }

        }



        snprintf(msg, sizeof(msg), "ASX/RAM file not handled");

        goto send_error;

    }



    stream->conns_served++;



    /* XXX: add there authenticate and IP match */



    if (c->post) {

        /* if post, it means a feed is being sent */

        if (!stream->is_feed) {

            /* However it might be a status report from WMP! Let us log the

             * data as it might come handy one day. */

            const char *logline = 0;

            int client_id = 0;



            for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {

                if (av_strncasecmp(p, "Pragma: log-line=", 17) == 0) {

                    logline = p;

                    break;

                }

                if (av_strncasecmp(p, "Pragma: client-id=", 18) == 0)

                    client_id = strtol(p + 18, 0, 10);

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

                if (!p)

                    break;



                p++;

            }



            if (logline) {

                char *eol = strchr(logline, '\n');



                logline += 17;



                if (eol) {

                    if (eol[-1] == '\r')

                        eol--;

                    http_log("%.*s\n", (int) (eol - logline), logline);

                    c->suppress_log = 1;

                }

            }



#ifdef DEBUG

            http_log("\nGot request:\n%s\n", c->buffer);

#endif



            if (client_id && extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) {

                HTTPContext *wmpc;



                /* Now we have to find the client_id */

                for (wmpc = first_http_ctx; wmpc; wmpc = wmpc->next) {

                    if (wmpc->wmp_client_id == client_id)

                        break;

                }



                if (wmpc && modify_current_stream(wmpc, ratebuf))

                    wmpc->switch_pending = 1;

            }



            snprintf(msg, sizeof(msg), "POST command not handled");

            c->stream = 0;

            goto send_error;

        }

        if (http_start_receive_data(c) < 0) {

            snprintf(msg, sizeof(msg), "could not open feed");

            goto send_error;

        }

        c->http_error = 0;

        c->state = HTTPSTATE_RECEIVE_DATA;

        return 0;

    }



#ifdef DEBUG

    if (strcmp(stream->filename + strlen(stream->filename) - 4, ".asf") == 0)

        http_log("\nGot request:\n%s\n", c->buffer);

#endif



    if (c->stream->stream_type == STREAM_TYPE_STATUS)

        goto send_status;



    /* open input stream */

    if (open_input_stream(c, info) < 0) {

        snprintf(msg, sizeof(msg), "Input stream corresponding to '%s' not found", url);

        goto send_error;

    }



    /* prepare HTTP header */

    c->buffer[0] = 0;

    av_strlcatf(c->buffer, c->buffer_size, "HTTP/1.0 200 OK\r\n");

    mime_type = c->stream->fmt->mime_type;

    if (!mime_type)

        mime_type = "application/x-octet-stream";

    av_strlcatf(c->buffer, c->buffer_size, "Pragma: no-cache\r\n");



    /* for asf, we need extra headers */

    if (!strcmp(c->stream->fmt->name,"asf_stream")) {

        /* Need to allocate a client id */



        c->wmp_client_id = av_lfg_get(&random_state);



        av_strlcatf(c->buffer, c->buffer_size, "Server: Cougar 4.1.0.3923\r\nCache-Control: no-cache\r\nPragma: client-id=%d\r\nPragma: features=\"broadcast\"\r\n", c->wmp_client_id);

    }

    av_strlcatf(c->buffer, c->buffer_size, "Content-Type: %s\r\n", mime_type);

    av_strlcatf(c->buffer, c->buffer_size, "\r\n");

    q = c->buffer + strlen(c->buffer);



    /* prepare output buffer */

    c->http_error = 0;

    c->buffer_ptr = c->buffer;

    c->buffer_end = q;

    c->state = HTTPSTATE_SEND_HEADER;

    return 0;

 send_error:

    c->http_error = 404;

    q = c->buffer;

    htmlstrip(msg);

    snprintf(q, c->buffer_size,

                  "HTTP/1.0 404 Not Found\r\n"

                  "Content-type: text/html\r\n"

                  "\r\n"

                  "<html>\n"

                  "<head><title>404 Not Found</title></head>\n"

                  "<body>%s</body>\n"

                  "</html>\n", msg);

    q += strlen(q);

    /* prepare output buffer */

    c->buffer_ptr = c->buffer;

    c->buffer_end = q;

    c->state = HTTPSTATE_SEND_HEADER;

    return 0;

 send_status:

    compute_status(c);

    c->http_error = 200; /* horrible : we use this value to avoid

                            going to the send data state */

    c->state = HTTPSTATE_SEND_HEADER;

    return 0;

}

static int http_parse_request(HTTPContext *c)

{

    const char *p;

    char *p1;

    enum RedirType redir_type;

    char cmd[32];

    char info[1024], filename[1024];

    char url[1024], *q;

    char protocol[32];

    char msg[1024];

    const char *mime_type;

    FFServerStream *stream;

    int i;

    char ratebuf[32];

    const char *useragent = 0;



    p = c->buffer;

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

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



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

        c->post = 0;

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

        c->post = 1;

    else

        return -1;



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

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



    get_word(protocol, sizeof(protocol), (const char **)&p);

    if (strcmp(protocol, "HTTP/1.0") && strcmp(protocol, "HTTP/1.1"))

        return -1;



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



    if (config.debug)

        http_log("%s - - New connection: %s %s\n", inet_ntoa(c->from_addr.sin_addr), cmd, url);



    

    p1 = strchr(url, '?');

    if (p1) {

        av_strlcpy(info, p1, sizeof(info));

        *p1 = '\0';

    } else

        info[0] = '\0';



    av_strlcpy(filename, url + ((*url == '/') ? 1 : 0), sizeof(filename)-1);



    for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {

        if (av_strncasecmp(p, "User-Agent:", 11) == 0) {

            useragent = p + 11;

            if (*useragent && *useragent != '\n' && av_isspace(*useragent))

                useragent++;

            break;

        }

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

        if (!p)

            break;



        p++;

    }



    redir_type = REDIR_NONE;

    if (av_match_ext(filename, "asx")) {

        redir_type = REDIR_ASX;

        filename[strlen(filename)-1] = 'f';

    } else if (av_match_ext(filename, "asf") &&

        (!useragent || av_strncasecmp(useragent, "NSPlayer", 8) != 0)) {

        

        redir_type = REDIR_ASF;

    } else if (av_match_ext(filename, "rpm,ram")) {

        redir_type = REDIR_RAM;

        strcpy(filename + strlen(filename)-2, "m");

    } else if (av_match_ext(filename, "rtsp")) {

        redir_type = REDIR_RTSP;

        compute_real_filename(filename, sizeof(filename) - 1);

    } else if (av_match_ext(filename, "sdp")) {

        redir_type = REDIR_SDP;

        compute_real_filename(filename, sizeof(filename) - 1);

    }



    

    if (!strlen(filename))

        av_strlcpy(filename, "index.html", sizeof(filename) - 1);



    stream = config.first_stream;

    while (stream) {

        if (!strcmp(stream->filename, filename) && validate_acl(stream, c))

            break;

        stream = stream->next;

    }

    if (!stream) {

        snprintf(msg, sizeof(msg), "File '%s' not found", url);

        http_log("File '%s' not found\n", url);

        goto send_error;

    }



    c->stream = stream;

    memcpy(c->feed_streams, stream->feed_streams, sizeof(c->feed_streams));

    memset(c->switch_feed_streams, -1, sizeof(c->switch_feed_streams));



    if (stream->stream_type == STREAM_TYPE_REDIRECT) {

        c->http_error = 301;

        q = c->buffer;

        snprintf(q, c->buffer_size,

                      "HTTP/1.0 301 Moved\r\n"

                      "Location: %s\r\n"

                      "Content-type: text/html\r\n"

                      "\r\n"

                      "<html><head><title>Moved</title></head><body>\r\n"

                      "You should be <a href=\"%s\">redirected</a>.\r\n"

                      "</body></html>\r\n", stream->feed_filename, stream->feed_filename);

        q += strlen(q);

        

        c->buffer_ptr = c->buffer;

        c->buffer_end = q;

        c->state = HTTPSTATE_SEND_HEADER;

        return 0;

    }



    

    if (extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) {

        if (modify_current_stream(c, ratebuf)) {

            for (i = 0; i < FF_ARRAY_ELEMS(c->feed_streams); i++) {

                if (c->switch_feed_streams[i] >= 0)

                    c->switch_feed_streams[i] = -1;

            }

        }

    }



    if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE)

        current_bandwidth += stream->bandwidth;



    

    if (stream->feed_opened) {

        snprintf(msg, sizeof(msg), "This feed is already being received.");

        http_log("Feed '%s' already being received\n", stream->feed_filename);

        goto send_error;

    }



    if (c->post == 0 && config.max_bandwidth < current_bandwidth) {

        c->http_error = 503;

        q = c->buffer;

        snprintf(q, c->buffer_size,

                      "HTTP/1.0 503 Server too busy\r\n"

                      "Content-type: text/html\r\n"

                      "\r\n"

                      "<html><head><title>Too busy</title></head><body>\r\n"

                      "<p>The server is too busy to serve your request at this time.</p>\r\n"

                      "<p>The bandwidth being served (including your stream) is %"PRIu64"kbit/sec, "

                      "and this exceeds the limit of %"PRIu64"kbit/sec.</p>\r\n"

                      "</body></html>\r\n", current_bandwidth, config.max_bandwidth);

        q += strlen(q);

        

        c->buffer_ptr = c->buffer;

        c->buffer_end = q;

        c->state = HTTPSTATE_SEND_HEADER;

        return 0;

    }



    if (redir_type != REDIR_NONE) {

        const char *hostinfo = 0;



        for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {

            if (av_strncasecmp(p, "Host:", 5) == 0) {

                hostinfo = p + 5;

                break;

            }

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

            if (!p)

                break;



            p++;

        }



        if (hostinfo) {

            char *eoh;

            char hostbuf[260];



            while (av_isspace(*hostinfo))

                hostinfo++;



            eoh = strchr(hostinfo, '\n');

            if (eoh) {

                if (eoh[-1] == '\r')

                    eoh--;



                if (eoh - hostinfo < sizeof(hostbuf) - 1) {

                    memcpy(hostbuf, hostinfo, eoh - hostinfo);

                    hostbuf[eoh - hostinfo] = 0;



                    c->http_error = 200;

                    q = c->buffer;

                    switch(redir_type) {

                    case REDIR_ASX:

                        snprintf(q, c->buffer_size,

                                      "HTTP/1.0 200 ASX Follows\r\n"

                                      "Content-type: video/x-ms-asf\r\n"

                                      "\r\n"

                                      "<ASX Version=\"3\">\r\n"

                                      

                                      "<ENTRY><REF HREF=\"http:

                                      "</ASX>\r\n", hostbuf, filename, info);

                        q += strlen(q);

                        break;

                    case REDIR_RAM:

                        snprintf(q, c->buffer_size,

                                      "HTTP/1.0 200 RAM Follows\r\n"

                                      "Content-type: audio/x-pn-realaudio\r\n"

                                      "\r\n"

                                      "# Autogenerated by ffserver\r\n"

                                      "http:

                        q += strlen(q);

                        break;

                    case REDIR_ASF:

                        snprintf(q, c->buffer_size,

                                      "HTTP/1.0 200 ASF Redirect follows\r\n"

                                      "Content-type: video/x-ms-asf\r\n"

                                      "\r\n"

                                      "[Reference]\r\n"

                                      "Ref1=http:

                        q += strlen(q);

                        break;

                    case REDIR_RTSP:

                        {

                            char hostname[256], *p;

                            

                            av_strlcpy(hostname, hostbuf, sizeof(hostname));

                            p = strrchr(hostname, ':');

                            if (p)

                                *p = '\0';

                            snprintf(q, c->buffer_size,

                                          "HTTP/1.0 200 RTSP Redirect follows\r\n"

                                          

                                          "Content-type: application/x-rtsp\r\n"

                                          "\r\n"

                                          "rtsp:

                            q += strlen(q);

                        }

                        break;

                    case REDIR_SDP:

                        {

                            uint8_t *sdp_data;

                            int sdp_data_size;

                            socklen_t len;

                            struct sockaddr_in my_addr;



                            snprintf(q, c->buffer_size,

                                          "HTTP/1.0 200 OK\r\n"

                                          "Content-type: application/sdp\r\n"

                                          "\r\n");

                            q += strlen(q);



                            len = sizeof(my_addr);



                            

                            if (getsockname(c->fd, (struct sockaddr *)&my_addr, &len))

                                http_log("getsockname() failed\n");



                            

                            sdp_data_size = prepare_sdp_description(stream,

                                                                    &sdp_data,

                                                                    my_addr.sin_addr);

                            if (sdp_data_size > 0) {

                                memcpy(q, sdp_data, sdp_data_size);

                                q += sdp_data_size;

                                *q = '\0';

                                av_free(sdp_data);

                            }

                        }

                        break;

                    default:

                        abort();

                        break;

                    }



                    

                    c->buffer_ptr = c->buffer;

                    c->buffer_end = q;

                    c->state = HTTPSTATE_SEND_HEADER;

                    return 0;

                }

            }

        }



        snprintf(msg, sizeof(msg), "ASX/RAM file not handled");

        goto send_error;

    }



    stream->conns_served++;



    



    if (c->post) {

        

        if (!stream->is_feed) {

            



            const char *logline = 0;

            int client_id = 0;



            for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {

                if (av_strncasecmp(p, "Pragma: log-line=", 17) == 0) {

                    logline = p;

                    break;

                }

                if (av_strncasecmp(p, "Pragma: client-id=", 18) == 0)

                    client_id = strtol(p + 18, 0, 10);

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

                if (!p)

                    break;



                p++;

            }



            if (logline) {

                char *eol = strchr(logline, '\n');



                logline += 17;



                if (eol) {

                    if (eol[-1] == '\r')

                        eol--;

                    http_log("%.*s\n", (int) (eol - logline), logline);

                    c->suppress_log = 1;

                }

            }



#ifdef DEBUG

            http_log("\nGot request:\n%s\n", c->buffer);

#endif



            if (client_id && extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) {

                HTTPContext *wmpc;



                

                for (wmpc = first_http_ctx; wmpc; wmpc = wmpc->next) {

                    if (wmpc->wmp_client_id == client_id)

                        break;

                }



                if (wmpc && modify_current_stream(wmpc, ratebuf))

                    wmpc->switch_pending = 1;

            }



            snprintf(msg, sizeof(msg), "POST command not handled");

            c->stream = 0;

            goto send_error;

        }

        if (http_start_receive_data(c) < 0) {

            snprintf(msg, sizeof(msg), "could not open feed");

            goto send_error;

        }

        c->http_error = 0;

        c->state = HTTPSTATE_RECEIVE_DATA;

        return 0;

    }



#ifdef DEBUG

    if (strcmp(stream->filename + strlen(stream->filename) - 4, ".asf") == 0)

        http_log("\nGot request:\n%s\n", c->buffer);

#endif



    if (c->stream->stream_type == STREAM_TYPE_STATUS)

        goto send_status;



    

    if (open_input_stream(c, info) < 0) {

        snprintf(msg, sizeof(msg), "Input stream corresponding to '%s' not found", url);

        goto send_error;

    }



    

    c->buffer[0] = 0;

    av_strlcatf(c->buffer, c->buffer_size, "HTTP/1.0 200 OK\r\n");

    mime_type = c->stream->fmt->mime_type;

    if (!mime_type)

        mime_type = "application/x-octet-stream";

    av_strlcatf(c->buffer, c->buffer_size, "Pragma: no-cache\r\n");



    

    if (!strcmp(c->stream->fmt->name,"asf_stream")) {

        



        c->wmp_client_id = av_lfg_get(&random_state);



        av_strlcatf(c->buffer, c->buffer_size, "Server: Cougar 4.1.0.3923\r\nCache-Control: no-cache\r\nPragma: client-id=%d\r\nPragma: features=\"broadcast\"\r\n", c->wmp_client_id);

    }

    av_strlcatf(c->buffer, c->buffer_size, "Content-Type: %s\r\n", mime_type);

    av_strlcatf(c->buffer, c->buffer_size, "\r\n");

    q = c->buffer + strlen(c->buffer);



    

    c->http_error = 0;

    c->buffer_ptr = c->buffer;

    c->buffer_end = q;

    c->state = HTTPSTATE_SEND_HEADER;

    return 0;

 send_error:

    c->http_error = 404;

    q = c->buffer;

    htmlstrip(msg);

    snprintf(q, c->buffer_size,

                  "HTTP/1.0 404 Not Found\r\n"

                  "Content-type: text/html\r\n"

                  "\r\n"

                  "<html>\n"

                  "<head><title>404 Not Found</title></head>\n"

                  "<body>%s</body>\n"

                  "</html>\n", msg);

    q += strlen(q);

    

    c->buffer_ptr = c->buffer;

    c->buffer_end = q;

    c->state = HTTPSTATE_SEND_HEADER;

    return 0;

 send_status:

    compute_status(c);

    c->http_error = 200; 



    c->state = HTTPSTATE_SEND_HEADER;

    return 0;

}

static int FUNC_0(HTTPContext *VAR_0)

{

    const char *VAR_19;

    char *VAR_2;

    enum RedirType VAR_3;

    char VAR_4[32];

    char VAR_5[1024], VAR_6[1024];

    char VAR_7[1024], *VAR_8;

    char VAR_9[32];

    char VAR_10[1024];

    const char *VAR_11;

    FFServerStream *stream;

    int VAR_12;

    char VAR_13[32];

    const char *VAR_14 = 0;



    VAR_19 = VAR_0->buffer;

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

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



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

        VAR_0->post = 0;

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

        VAR_0->post = 1;

    else

        return -1;



    get_word(VAR_7, sizeof(VAR_7), &VAR_19);

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



    get_word(VAR_9, sizeof(VAR_9), (const char **)&VAR_19);

    if (strcmp(VAR_9, "HTTP/1.0") && strcmp(VAR_9, "HTTP/1.1"))

        return -1;



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



    if (config.debug)

        http_log("%s - - New connection: %s %s\n", inet_ntoa(VAR_0->from_addr.sin_addr), VAR_4, VAR_7);



    

    VAR_2 = strchr(VAR_7, '?');

    if (VAR_2) {

        av_strlcpy(VAR_5, VAR_2, sizeof(VAR_5));

        *VAR_2 = '\0';

    } else

        VAR_5[0] = '\0';



    av_strlcpy(VAR_6, VAR_7 + ((*VAR_7 == '/') ? 1 : 0), sizeof(VAR_6)-1);



    for (VAR_19 = VAR_0->buffer; *VAR_19 && *VAR_19 != '\r' && *VAR_19 != '\n'; ) {

        if (av_strncasecmp(VAR_19, "User-Agent:", 11) == 0) {

            VAR_14 = VAR_19 + 11;

            if (*VAR_14 && *VAR_14 != '\n' && av_isspace(*VAR_14))

                VAR_14++;

            break;

        }

        VAR_19 = strchr(VAR_19, '\n');

        if (!VAR_19)

            break;



        VAR_19++;

    }



    VAR_3 = REDIR_NONE;

    if (av_match_ext(VAR_6, "asx")) {

        VAR_3 = REDIR_ASX;

        VAR_6[strlen(VAR_6)-1] = 'f';

    } else if (av_match_ext(VAR_6, "asf") &&

        (!VAR_14 || av_strncasecmp(VAR_14, "NSPlayer", 8) != 0)) {

        

        VAR_3 = REDIR_ASF;

    } else if (av_match_ext(VAR_6, "rpm,ram")) {

        VAR_3 = REDIR_RAM;

        strcpy(VAR_6 + strlen(VAR_6)-2, "m");

    } else if (av_match_ext(VAR_6, "rtsp")) {

        VAR_3 = REDIR_RTSP;

        compute_real_filename(VAR_6, sizeof(VAR_6) - 1);

    } else if (av_match_ext(VAR_6, "sdp")) {

        VAR_3 = REDIR_SDP;

        compute_real_filename(VAR_6, sizeof(VAR_6) - 1);

    }



    

    if (!strlen(VAR_6))

        av_strlcpy(VAR_6, "index.html", sizeof(VAR_6) - 1);



    stream = config.first_stream;

    while (stream) {

        if (!strcmp(stream->VAR_6, VAR_6) && validate_acl(stream, VAR_0))

            break;

        stream = stream->next;

    }

    if (!stream) {

        snprintf(VAR_10, sizeof(VAR_10), "File '%s' not found", VAR_7);

        http_log("File '%s' not found\n", VAR_7);

        goto send_error;

    }



    VAR_0->stream = stream;

    memcpy(VAR_0->feed_streams, stream->feed_streams, sizeof(VAR_0->feed_streams));

    memset(VAR_0->switch_feed_streams, -1, sizeof(VAR_0->switch_feed_streams));



    if (stream->stream_type == STREAM_TYPE_REDIRECT) {

        VAR_0->http_error = 301;

        VAR_8 = VAR_0->buffer;

        snprintf(VAR_8, VAR_0->buffer_size,

                      "HTTP/1.0 301 Moved\r\n"

                      "Location: %s\r\n"

                      "Content-type: text/html\r\n"

                      "\r\n"

                      "<html><head><title>Moved</title></head><body>\r\n"

                      "You should be <a href=\"%s\">redirected</a>.\r\n"

                      "</body></html>\r\n", stream->feed_filename, stream->feed_filename);

        VAR_8 += strlen(VAR_8);

        

        VAR_0->buffer_ptr = VAR_0->buffer;

        VAR_0->buffer_end = VAR_8;

        VAR_0->state = HTTPSTATE_SEND_HEADER;

        return 0;

    }



    

    if (extract_rates(VAR_13, sizeof(VAR_13), VAR_0->buffer)) {

        if (modify_current_stream(VAR_0, VAR_13)) {

            for (VAR_12 = 0; VAR_12 < FF_ARRAY_ELEMS(VAR_0->feed_streams); VAR_12++) {

                if (VAR_0->switch_feed_streams[VAR_12] >= 0)

                    VAR_0->switch_feed_streams[VAR_12] = -1;

            }

        }

    }



    if (VAR_0->post == 0 && stream->stream_type == STREAM_TYPE_LIVE)

        current_bandwidth += stream->bandwidth;



    

    if (stream->feed_opened) {

        snprintf(VAR_10, sizeof(VAR_10), "This feed is already being received.");

        http_log("Feed '%s' already being received\n", stream->feed_filename);

        goto send_error;

    }



    if (VAR_0->post == 0 && config.max_bandwidth < current_bandwidth) {

        VAR_0->http_error = 503;

        VAR_8 = VAR_0->buffer;

        snprintf(VAR_8, VAR_0->buffer_size,

                      "HTTP/1.0 503 Server too busy\r\n"

                      "Content-type: text/html\r\n"

                      "\r\n"

                      "<html><head><title>Too busy</title></head><body>\r\n"

                      "<VAR_19>The server is too busy to serve your request at this time.</VAR_19>\r\n"

                      "<VAR_19>The bandwidth being served (including your stream) is %"PRIu64"kbit/sec, "

                      "and this exceeds the limit of %"PRIu64"kbit/sec.</VAR_19>\r\n"

                      "</body></html>\r\n", current_bandwidth, config.max_bandwidth);

        VAR_8 += strlen(VAR_8);

        

        VAR_0->buffer_ptr = VAR_0->buffer;

        VAR_0->buffer_end = VAR_8;

        VAR_0->state = HTTPSTATE_SEND_HEADER;

        return 0;

    }



    if (VAR_3 != REDIR_NONE) {

        const char *VAR_15 = 0;



        for (VAR_19 = VAR_0->buffer; *VAR_19 && *VAR_19 != '\r' && *VAR_19 != '\n'; ) {

            if (av_strncasecmp(VAR_19, "Host:", 5) == 0) {

                VAR_15 = VAR_19 + 5;

                break;

            }

            VAR_19 = strchr(VAR_19, '\n');

            if (!VAR_19)

                break;



            VAR_19++;

        }



        if (VAR_15) {

            char *VAR_16;

            char VAR_17[260];



            while (av_isspace(*VAR_15))

                VAR_15++;



            VAR_16 = strchr(VAR_15, '\n');

            if (VAR_16) {

                if (VAR_16[-1] == '\r')

                    VAR_16--;



                if (VAR_16 - VAR_15 < sizeof(VAR_17) - 1) {

                    memcpy(VAR_17, VAR_15, VAR_16 - VAR_15);

                    VAR_17[VAR_16 - VAR_15] = 0;



                    VAR_0->http_error = 200;

                    VAR_8 = VAR_0->buffer;

                    switch(VAR_3) {

                    case REDIR_ASX:

                        snprintf(VAR_8, VAR_0->buffer_size,

                                      "HTTP/1.0 200 ASX Follows\r\n"

                                      "Content-type: video/x-ms-asf\r\n"

                                      "\r\n"

                                      "<ASX Version=\"3\">\r\n"

                                      

                                      "<ENTRY><REF HREF=\"http:

                                      "</ASX>\r\n", VAR_17, VAR_6, VAR_5);

                        VAR_8 += strlen(VAR_8);

                        break;

                    case REDIR_RAM:

                        snprintf(VAR_8, VAR_0->buffer_size,

                                      "HTTP/1.0 200 RAM Follows\r\n"

                                      "Content-type: audio/x-pn-realaudio\r\n"

                                      "\r\n"

                                      "# Autogenerated by ffserver\r\n"

                                      "http:

                        VAR_8 += strlen(VAR_8);

                        break;

                    case REDIR_ASF:

                        snprintf(VAR_8, VAR_0->buffer_size,

                                      "HTTP/1.0 200 ASF Redirect follows\r\n"

                                      "Content-type: video/x-ms-asf\r\n"

                                      "\r\n"

                                      "[Reference]\r\n"

                                      "Ref1=http:

                        VAR_8 += strlen(VAR_8);

                        break;

                    case REDIR_RTSP:

                        {

                            char VAR_18[256], *VAR_19;

                            

                            av_strlcpy(VAR_18, VAR_17, sizeof(VAR_18));

                            VAR_19 = strrchr(VAR_18, ':');

                            if (VAR_19)

                                *VAR_19 = '\0';

                            snprintf(VAR_8, VAR_0->buffer_size,

                                          "HTTP/1.0 200 RTSP Redirect follows\r\n"

                                          

                                          "Content-type: application/x-rtsp\r\n"

                                          "\r\n"

                                          "rtsp:

                            VAR_8 += strlen(VAR_8);

                        }

                        break;

                    case REDIR_SDP:

                        {

                            uint8_t *sdp_data;

                            int VAR_19;

                            socklen_t len;

                            struct sockaddr_in VAR_20;



                            snprintf(VAR_8, VAR_0->buffer_size,

                                          "HTTP/1.0 200 OK\r\n"

                                          "Content-type: application/sdp\r\n"

                                          "\r\n");

                            VAR_8 += strlen(VAR_8);



                            len = sizeof(VAR_20);



                            

                            if (getsockname(VAR_0->fd, (struct sockaddr *)&VAR_20, &len))

                                http_log("getsockname() failed\n");



                            

                            VAR_19 = prepare_sdp_description(stream,

                                                                    &sdp_data,

                                                                    VAR_20.sin_addr);

                            if (VAR_19 > 0) {

                                memcpy(VAR_8, sdp_data, VAR_19);

                                VAR_8 += VAR_19;

                                *VAR_8 = '\0';

                                av_free(sdp_data);

                            }

                        }

                        break;

                    default:

                        abort();

                        break;

                    }



                    

                    VAR_0->buffer_ptr = VAR_0->buffer;

                    VAR_0->buffer_end = VAR_8;

                    VAR_0->state = HTTPSTATE_SEND_HEADER;

                    return 0;

                }

            }

        }



        snprintf(VAR_10, sizeof(VAR_10), "ASX/RAM file not handled");

        goto send_error;

    }



    stream->conns_served++;



    



    if (VAR_0->post) {

        

        if (!stream->is_feed) {

            



            const char *VAR_21 = 0;

            int VAR_22 = 0;



            for (VAR_19 = VAR_0->buffer; *VAR_19 && *VAR_19 != '\r' && *VAR_19 != '\n'; ) {

                if (av_strncasecmp(VAR_19, "Pragma: log-line=", 17) == 0) {

                    VAR_21 = VAR_19;

                    break;

                }

                if (av_strncasecmp(VAR_19, "Pragma: client-id=", 18) == 0)

                    VAR_22 = strtol(VAR_19 + 18, 0, 10);

                VAR_19 = strchr(VAR_19, '\n');

                if (!VAR_19)

                    break;



                VAR_19++;

            }



            if (VAR_21) {

                char *VAR_23 = strchr(VAR_21, '\n');



                VAR_21 += 17;



                if (VAR_23) {

                    if (VAR_23[-1] == '\r')

                        VAR_23--;

                    http_log("%.*s\n", (int) (VAR_23 - VAR_21), VAR_21);

                    VAR_0->suppress_log = 1;

                }

            }



#ifdef DEBUG

            http_log("\nGot request:\n%s\n", VAR_0->buffer);

#endif



            if (VAR_22 && extract_rates(VAR_13, sizeof(VAR_13), VAR_0->buffer)) {

                HTTPContext *wmpc;



                

                for (wmpc = first_http_ctx; wmpc; wmpc = wmpc->next) {

                    if (wmpc->wmp_client_id == VAR_22)

                        break;

                }



                if (wmpc && modify_current_stream(wmpc, VAR_13))

                    wmpc->switch_pending = 1;

            }



            snprintf(VAR_10, sizeof(VAR_10), "POST command not handled");

            VAR_0->stream = 0;

            goto send_error;

        }

        if (http_start_receive_data(VAR_0) < 0) {

            snprintf(VAR_10, sizeof(VAR_10), "could not open feed");

            goto send_error;

        }

        VAR_0->http_error = 0;

        VAR_0->state = HTTPSTATE_RECEIVE_DATA;

        return 0;

    }



#ifdef DEBUG

    if (strcmp(stream->VAR_6 + strlen(stream->VAR_6) - 4, ".asf") == 0)

        http_log("\nGot request:\n%s\n", VAR_0->buffer);

#endif



    if (VAR_0->stream->stream_type == STREAM_TYPE_STATUS)

        goto send_status;



    

    if (open_input_stream(VAR_0, VAR_5) < 0) {

        snprintf(VAR_10, sizeof(VAR_10), "Input stream corresponding to '%s' not found", VAR_7);

        goto send_error;

    }



    

    VAR_0->buffer[0] = 0;

    av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "HTTP/1.0 200 OK\r\n");

    VAR_11 = VAR_0->stream->fmt->VAR_11;

    if (!VAR_11)

        VAR_11 = "application/x-octet-stream";

    av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "Pragma: no-cache\r\n");



    

    if (!strcmp(VAR_0->stream->fmt->name,"asf_stream")) {

        



        VAR_0->wmp_client_id = av_lfg_get(&random_state);



        av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "Server: Cougar 4.1.0.3923\r\nCache-Control: no-cache\r\nPragma: client-id=%d\r\nPragma: features=\"broadcast\"\r\n", VAR_0->wmp_client_id);

    }

    av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "Content-Type: %s\r\n", VAR_11);

    av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "\r\n");

    VAR_8 = VAR_0->buffer + strlen(VAR_0->buffer);



    

    VAR_0->http_error = 0;

    VAR_0->buffer_ptr = VAR_0->buffer;

    VAR_0->buffer_end = VAR_8;

    VAR_0->state = HTTPSTATE_SEND_HEADER;

    return 0;

 send_error:

    VAR_0->http_error = 404;

    VAR_8 = VAR_0->buffer;

    htmlstrip(VAR_10);

    snprintf(VAR_8, VAR_0->buffer_size,

                  "HTTP/1.0 404 Not Found\r\n"

                  "Content-type: text/html\r\n"

                  "\r\n"

                  "<html>\n"

                  "<head><title>404 Not Found</title></head>\n"

                  "<body>%s</body>\n"

                  "</html>\n", VAR_10);

    VAR_8 += strlen(VAR_8);

    

    VAR_0->buffer_ptr = VAR_0->buffer;

    VAR_0->buffer_end = VAR_8;

    VAR_0->state = HTTPSTATE_SEND_HEADER;

    return 0;

 send_status:

    compute_status(VAR_0);

    VAR_0->http_error = 200; 



    VAR_0->state = HTTPSTATE_SEND_HEADER;

    return 0;

}

static int FUNC_0(HTTPContext *VAR_0)
{ const char *VAR_19; char *VAR_2; enum RedirType VAR_3; char VAR_4[32]; char VAR_5[1024], VAR_6[1024]; char VAR_7[1024], *VAR_8; char VAR_9[32]; char VAR_10[1024]; const char *VAR_11; FFServerStream *stream; int VAR_12; char VAR_13[32]; const char *VAR_14 = 0; VAR_19 = VAR_0->buffer; get_word(VAR_4, sizeof(VAR_4), &VAR_19); av_strlcpy(VAR_0->method, VAR_4, sizeof(VAR_0->method)); if (!strcmp(VAR_4, "GET"))
VAR_0->post = 0; else if (!strcmp(VAR_4, "POST"))
VAR_0->post = 1; else
return -1; get_word(VAR_7, sizeof(VAR_7), &VAR_19); av_strlcpy(VAR_0->VAR_7, VAR_7, sizeof(VAR_0->VAR_7)); get_word(VAR_9, sizeof(VAR_9), (const char **)&VAR_19); if (strcmp(VAR_9, "HTTP/1.0") && strcmp(VAR_9, "HTTP/1.1"))
return -1; av_strlcpy(VAR_0->VAR_9, VAR_9, sizeof(VAR_0->VAR_9)); if (config.debug)
http_log("%s - - New connection: %s %s\n", inet_ntoa(VAR_0->from_addr.sin_addr), VAR_4, VAR_7); VAR_2 = strchr(VAR_7, '?'); if (VAR_2) { av_strlcpy(VAR_5, VAR_2, sizeof(VAR_5)); *VAR_2 = '\0'; } else VAR_5[0] = '\0'; av_strlcpy(VAR_6, VAR_7 + ((*VAR_7 == '/') ? 1 : 0), sizeof(VAR_6)-1); for (VAR_19 = VAR_0->buffer; *VAR_19 && *VAR_19 != '\r' && *VAR_19 != '\n'; ) { if (av_strncasecmp(VAR_19, "User-Agent:", 11) == 0) { VAR_14 = VAR_19 + 11; if (*VAR_14 && *VAR_14 != '\n' && av_isspace(*VAR_14))
VAR_14++; break; } VAR_19 = strchr(VAR_19, '\n'); if (!VAR_19)
break; VAR_19++; } VAR_3 = REDIR_NONE; if (av_match_ext(VAR_6, "asx")) { VAR_3 = REDIR_ASX; VAR_6[strlen(VAR_6)-1] = 'f'; } else if (av_match_ext(VAR_6, "asf") && (!VAR_14 || av_strncasecmp(VAR_14, "NSPlayer", 8) != 0)) { VAR_3 = REDIR_ASF; } else if (av_match_ext(VAR_6, "rpm,ram")) { VAR_3 = REDIR_RAM; strcpy(VAR_6 + strlen(VAR_6)-2, "m"); } else if (av_match_ext(VAR_6, "rtsp")) { VAR_3 = REDIR_RTSP; compute_real_filename(VAR_6, sizeof(VAR_6) - 1); } else if (av_match_ext(VAR_6, "sdp")) { VAR_3 = REDIR_SDP; compute_real_filename(VAR_6, sizeof(VAR_6) - 1); } if (!strlen(VAR_6))
av_strlcpy(VAR_6, "index.html", sizeof(VAR_6) - 1); stream = config.first_stream; while (stream) { if (!strcmp(stream->VAR_6, VAR_6) && validate_acl(stream, VAR_0))
break; stream = stream->next; } if (!stream) { snprintf(VAR_10, sizeof(VAR_10), "File '%s' not found", VAR_7); http_log("File '%s' not found\n", VAR_7); goto send_error; } VAR_0->stream = stream; memcpy(VAR_0->feed_streams, stream->feed_streams, sizeof(VAR_0->feed_streams)); memset(VAR_0->switch_feed_streams, -1, sizeof(VAR_0->switch_feed_streams)); if (stream->stream_type == STREAM_TYPE_REDIRECT) { VAR_0->http_error = 301; VAR_8 = VAR_0->buffer; snprintf(VAR_8, VAR_0->buffer_size,
"HTTP/1.0 301 Moved\r\n"
"Location: %s\r\n"
"Content-type: text/html\r\n"
"\r\n"
"<html><head><title>Moved</title></head><body>\r\n"
"You should be <a href=\"%s\">redirected</a>.\r\n"
"</body></html>\r\n", stream->feed_filename, stream->feed_filename); VAR_8 += strlen(VAR_8); VAR_0->buffer_ptr = VAR_0->buffer; VAR_0->buffer_end = VAR_8; VAR_0->state = HTTPSTATE_SEND_HEADER; return 0; } if (extract_rates(VAR_13, sizeof(VAR_13), VAR_0->buffer)) { if (modify_current_stream(VAR_0, VAR_13)) { for (VAR_12 = 0; VAR_12 < FF_ARRAY_ELEMS(VAR_0->feed_streams); VAR_12++) { if (VAR_0->switch_feed_streams[VAR_12] >= 0)
VAR_0->switch_feed_streams[VAR_12] = -1; } } } if (VAR_0->post == 0 && stream->stream_type == STREAM_TYPE_LIVE)
current_bandwidth += stream->bandwidth; if (stream->feed_opened) { snprintf(VAR_10, sizeof(VAR_10), "This feed is already being received."); http_log("Feed '%s' already being received\n", stream->feed_filename); goto send_error; } if (VAR_0->post == 0 && config.max_bandwidth < current_bandwidth) { VAR_0->http_error = 503; VAR_8 = VAR_0->buffer; snprintf(VAR_8, VAR_0->buffer_size,
"HTTP/1.0 503 Server too busy\r\n"
"Content-type: text/html\r\n"
"\r\n"
"<html><head><title>Too busy</title></head><body>\r\n"
"<VAR_19>The server is too busy to serve your request at this time.</VAR_19>\r\n"
"<VAR_19>The bandwidth being served (including your stream) is %"PRIu64"kbit/sec, "
"and this exceeds the limit of %"PRIu64"kbit/sec.</VAR_19>\r\n"
"</body></html>\r\n", current_bandwidth, config.max_bandwidth); VAR_8 += strlen(VAR_8); VAR_0->buffer_ptr = VAR_0->buffer; VAR_0->buffer_end = VAR_8; VAR_0->state = HTTPSTATE_SEND_HEADER; return 0; } if (VAR_3 != REDIR_NONE) { const char *VAR_15 = 0; for (VAR_19 = VAR_0->buffer; *VAR_19 && *VAR_19 != '\r' && *VAR_19 != '\n'; ) { if (av_strncasecmp(VAR_19, "Host:", 5) == 0) { VAR_15 = VAR_19 + 5; break; } VAR_19 = strchr(VAR_19, '\n'); if (!VAR_19)
break; VAR_19++; } if (VAR_15) { char *VAR_16; char VAR_17[260]; while (av_isspace(*VAR_15))
VAR_15++; VAR_16 = strchr(VAR_15, '\n'); if (VAR_16) { if (VAR_16[-1] == '\r')
VAR_16--; if (VAR_16 - VAR_15 < sizeof(VAR_17) - 1) { memcpy(VAR_17, VAR_15, VAR_16 - VAR_15); VAR_17[VAR_16 - VAR_15] = 0; VAR_0->http_error = 200; VAR_8 = VAR_0->buffer; switch(VAR_3) { case REDIR_ASX:
snprintf(VAR_8, VAR_0->buffer_size,
"HTTP/1.0 200 ASX Follows\r\n"
"Content-type: video/x-ms-asf\r\n"
"\r\n"
"<ASX Version=\"3\">\r\n"
"<ENTRY><REF HREF=\"http:
"</ASX>\r\n", VAR_17, VAR_6, VAR_5); VAR_8 += strlen(VAR_8); break; case REDIR_RAM:
snprintf(VAR_8, VAR_0->buffer_size,
"HTTP/1.0 200 RAM Follows\r\n"
"Content-type: audio/x-pn-realaudio\r\n"
"\r\n"
"# Autogenerated by ffserver\r\n"
"http:
VAR_8 += strlen(VAR_8); break; case REDIR_ASF:
snprintf(VAR_8, VAR_0->buffer_size,
"HTTP/1.0 200 ASF Redirect follows\r\n"
"Content-type: video/x-ms-asf\r\n"
"\r\n"
"[Reference]\r\n"
"Ref1=http:
VAR_8 += strlen(VAR_8); break; case REDIR_RTSP:
{ char VAR_18[256], *VAR_19; av_strlcpy(VAR_18, VAR_17, sizeof(VAR_18)); VAR_19 = strrchr(VAR_18, ':'); if (VAR_19)
*VAR_19 = '\0'; snprintf(VAR_8, VAR_0->buffer_size,
"HTTP/1.0 200 RTSP Redirect follows\r\n"
"Content-type: application/x-rtsp\r\n"
"\r\n"
"rtsp:
VAR_8 += strlen(VAR_8); } break; case REDIR_SDP:
{ uint8_t *sdp_data; int VAR_19; socklen_t len; struct sockaddr_in VAR_20; snprintf(VAR_8, VAR_0->buffer_size,
"HTTP/1.0 200 OK\r\n"
"Content-type: application/sdp\r\n"
"\r\n"); VAR_8 += strlen(VAR_8); len = sizeof(VAR_20); if (getsockname(VAR_0->fd, (struct sockaddr *)&VAR_20, &len))
http_log("getsockname() failed\n"); VAR_19 = prepare_sdp_description(stream,
&sdp_data,
VAR_20.sin_addr); if (VAR_19 > 0) { memcpy(VAR_8, sdp_data, VAR_19); VAR_8 += VAR_19; *VAR_8 = '\0'; av_free(sdp_data); } } break; default:
abort(); break; } VAR_0->buffer_ptr = VAR_0->buffer; VAR_0->buffer_end = VAR_8; VAR_0->state = HTTPSTATE_SEND_HEADER; return 0; } } } snprintf(VAR_10, sizeof(VAR_10), "ASX/RAM file not handled"); goto send_error; } stream->conns_served++; if (VAR_0->post) { if (!stream->is_feed) { const char *VAR_21 = 0; int VAR_22 = 0; for (VAR_19 = VAR_0->buffer; *VAR_19 && *VAR_19 != '\r' && *VAR_19 != '\n'; ) { if (av_strncasecmp(VAR_19, "Pragma: log-line=", 17) == 0) { VAR_21 = VAR_19; break; } if (av_strncasecmp(VAR_19, "Pragma: client-id=", 18) == 0)
VAR_22 = strtol(VAR_19 + 18, 0, 10); VAR_19 = strchr(VAR_19, '\n'); if (!VAR_19)
break; VAR_19++; } if (VAR_21) { char *VAR_23 = strchr(VAR_21, '\n'); VAR_21 += 17; if (VAR_23) { if (VAR_23[-1] == '\r')
VAR_23--; http_log("%.*s\n", (int) (VAR_23 - VAR_21), VAR_21); VAR_0->suppress_log = 1; } } #ifdef DEBUG
http_log("\nGot request:\n%s\n", VAR_0->buffer); #endif
if (VAR_22 && extract_rates(VAR_13, sizeof(VAR_13), VAR_0->buffer)) { HTTPContext *wmpc; for (wmpc = first_http_ctx; wmpc; wmpc = wmpc->next) { if (wmpc->wmp_client_id == VAR_22)
break; } if (wmpc && modify_current_stream(wmpc, VAR_13))
wmpc->switch_pending = 1; } snprintf(VAR_10, sizeof(VAR_10), "POST command not handled"); VAR_0->stream = 0; goto send_error; } if (http_start_receive_data(VAR_0) < 0) { snprintf(VAR_10, sizeof(VAR_10), "could not open feed"); goto send_error; } VAR_0->http_error = 0; VAR_0->state = HTTPSTATE_RECEIVE_DATA; return 0; } #ifdef DEBUG
if (strcmp(stream->VAR_6 + strlen(stream->VAR_6) - 4, ".asf") == 0)
http_log("\nGot request:\n%s\n", VAR_0->buffer); #endif
if (VAR_0->stream->stream_type == STREAM_TYPE_STATUS)
goto send_status; if (open_input_stream(VAR_0, VAR_5) < 0) { snprintf(VAR_10, sizeof(VAR_10), "Input stream corresponding to '%s' not found", VAR_7); goto send_error; } VAR_0->buffer[0] = 0; av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "HTTP/1.0 200 OK\r\n"); VAR_11 = VAR_0->stream->fmt->VAR_11; if (!VAR_11)
VAR_11 = "application/x-octet-stream"; av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "Pragma: no-cache\r\n"); if (!strcmp(VAR_0->stream->fmt->name,"asf_stream")) { VAR_0->wmp_client_id = av_lfg_get(&random_state); av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "Server: Cougar 4.1.0.3923\r\nCache-Control: no-cache\r\nPragma: client-id=%d\r\nPragma: features=\"broadcast\"\r\n", VAR_0->wmp_client_id); } av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "Content-Type: %s\r\n", VAR_11); av_strlcatf(VAR_0->buffer, VAR_0->buffer_size, "\r\n"); VAR_8 = VAR_0->buffer + strlen(VAR_0->buffer); VAR_0->http_error = 0; VAR_0->buffer_ptr = VAR_0->buffer; VAR_0->buffer_end = VAR_8; VAR_0->state = HTTPSTATE_SEND_HEADER; return 0; send_error:
VAR_0->http_error = 404; VAR_8 = VAR_0->buffer; htmlstrip(VAR_10); snprintf(VAR_8, VAR_0->buffer_size,
"HTTP/1.0 404 Not Found\r\n"
"Content-type: text/html\r\n"
"\r\n"
"<html>\n"
"<head><title>404 Not Found</title></head>\n"
"<body>%s</body>\n"
"</html>\n", VAR_10); VAR_8 += strlen(VAR_8); VAR_0->buffer_ptr = VAR_0->buffer; VAR_0->buffer_end = VAR_8; VAR_0->state = HTTPSTATE_SEND_HEADER; return 0; send_status:
compute_status(VAR_0); VAR_0->http_error = 200; VAR_0->state = HTTPSTATE_SEND_HEADER; return 0; }