avserver.c:1518: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned64.

avserver.c:1453:1: <LHS trace>
1451. 
1452. /* parse http request and prepare header */
1453. static int http_parse_request(HTTPContext *c)
      ^
1454. {
1455.     char *p;

avserver.c:1453:1: Array declaration
1451. 
1452. /* parse http request and prepare header */
1453. static int http_parse_request(HTTPContext *c)
      ^
1454. {
1455.     char *p;

avserver.c:1499:5: Call
1497.         info[0] = '\0';
1498. 
1499.     av_strlcpy(filename, url + ((*url == '/') ? 1 : 0), sizeof(filename)-1);
          ^
1500. 
1501.     for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {

libavutil/avstring.c:64:1: Parameter `*dst`
  62. }
  63. 
  64. size_t av_strlcpy(char *dst, const char *src, size_t size)
      ^
  65. {
  66.     size_t len = 0;

avserver.c:1518:9: Binary operation: ([0, +oo] - 1):unsigned64
1516.     if (av_match_ext(filename, "asx")) {
1517.         redir_type = REDIR_ASX;
1518.         filename[strlen(filename)-1] = 'f';
              ^
1519.     } else if (av_match_ext(filename, "asf") &&
1520.         (!useragent || av_strncasecmp(useragent, "NSPlayer", 8) != 0)) {

static int http_parse_request(HTTPContext *c)
{
    char *p;
    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;
    FFStream *stream;
    int i;
    char ratebuf[32];
    char *useragent = 0;
    p = c->buffer;
    get_word(cmd, sizeof(cmd), (const char **)&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), (const char **)&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 (avserver_debug)
        http_log("%s - - New connection: %s %s\n", inet_ntoa(c->from_addr.sin_addr), cmd, url);
    p = strchr(url, '?');
    if (p) {
        av_strlcpy(info, p, sizeof(info));
        *p = '\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' && 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 = first_stream;
    while (stream != NULL) {
        if (!strcmp(stream->filename, filename) && validate_acl(stream, c))
            break;
        stream = stream->next;
    }
    if (stream == NULL) {
        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;
        q += 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);
        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 && max_bandwidth < current_bandwidth) {
        c->http_error = 503;
        q = c->buffer;
        q += 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, max_bandwidth);
        c->buffer_ptr = c->buffer;
        c->buffer_end = q;
        c->state = HTTPSTATE_SEND_HEADER;
        return 0;
    }
    if (redir_type != REDIR_NONE) {
        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 (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:
                        q += 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://%s/%s%s\"/></ENTRY>\r\n"
                                      "</ASX>\r\n", hostbuf, filename, info);
                        break;
                    case REDIR_RAM:
                        q += 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 avserver\r\n"
                                      "http://%s/%s%s\r\n", hostbuf, filename, info);
                        break;
                    case REDIR_ASF:
                        q += 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);
                        break;
                    case REDIR_RTSP:
                        {
                            char hostname[256], *p;
                            av_strlcpy(hostname, hostbuf, sizeof(hostname));
                            p = strrchr(hostname, ':');
                            if (p)
                                *p = '\0';
                            q += snprintf(q, c->buffer_size,
                                          "HTTP/1.0 200 RTSP Redirect follows\r\n"
                                          "Content-type: application/x-rtsp\r\n"
                                          "\r\n"
                                          "rtsp://%s:%d/%s\r\n", hostname, ntohs(my_rtsp_addr.sin_port), filename);
                        }
                        break;
                    case REDIR_SDP:
                        {
                            uint8_t *sdp_data;
                            int sdp_data_size, len;
                            struct sockaddr_in my_addr;
                            q += snprintf(q, c->buffer_size,
                                          "HTTP/1.0 200 OK\r\n"
                                          "Content-type: application/sdp\r\n"
                                          "\r\n");
                            len = sizeof(my_addr);
                            getsockname(c->fd, (struct sockaddr *)&my_addr, &len);
                            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) {
            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;
    }
    q = c->buffer;
    q += snprintf(q, q - (char *) 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";
    q += snprintf(q, q - (char *) 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);
        q += snprintf(q, q - (char *) 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);
    }
    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-Type: %s\r\n", mime_type);
    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
    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;
    q += 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);
    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 http_parse_request(HTTPContext *c)\n{\n    char *p;\n    enum RedirType redir_type;\n    char cmd[32];\n    char info[1024], filename[1024];\n    char url[1024], *q;\n    char protocol[32];\n    char msg[1024];\n    const char *mime_type;\n    FFStream *stream;\n    int i;\n    char ratebuf[32];\n    char *useragent = 0;\n    p = c->buffer;\n    get_word(cmd, sizeof(cmd), (const char **)&p);\n    av_strlcpy(c->method, cmd, sizeof(c->method));\n    if (!strcmp(cmd, "GET"))\n        c->post = 0;\n    else if (!strcmp(cmd, "POST"))\n        c->post = 1;\n    else\n        return -1;\n    get_word(url, sizeof(url), (const char **)&p);\n    av_strlcpy(c->url, url, sizeof(c->url));\n    get_word(protocol, sizeof(protocol), (const char **)&p);\n    if (strcmp(protocol, "HTTP/1.0") && strcmp(protocol, "HTTP/1.1"))\n        return -1;\n    av_strlcpy(c->protocol, protocol, sizeof(c->protocol));\n    if (avserver_debug)\n        http_log("%s - - New connection: %s %s\\n", inet_ntoa(c->from_addr.sin_addr), cmd, url);\n    p = strchr(url, \'?\');\n    if (p) {\n        av_strlcpy(info, p, sizeof(info));\n        *p = \'\\0\';\n    } else\n        info[0] = \'\\0\';\n    av_strlcpy(filename, url + ((*url == \'/\') ? 1 : 0), sizeof(filename)-1);\n    for (p = c->buffer; *p && *p != \'\\r\' && *p != \'\\n\'; ) {\n        if (av_strncasecmp(p, "User-Agent:", 11) == 0) {\n            useragent = p + 11;\n            if (*useragent && *useragent != \'\\n\' && isspace(*useragent))\n                useragent++;\n            break;\n        }\n        p = strchr(p, \'\\n\');\n        if (!p)\n            break;\n        p++;\n    }\n    redir_type = REDIR_NONE;\n    if (av_match_ext(filename, "asx")) {\n        redir_type = REDIR_ASX;\n        filename[strlen(filename)-1] = \'f\';\n    } else if (av_match_ext(filename, "asf") &&\n        (!useragent || av_strncasecmp(useragent, "NSPlayer", 8) != 0)) {\n        redir_type = REDIR_ASF;\n    } else if (av_match_ext(filename, "rpm,ram")) {\n        redir_type = REDIR_RAM;\n        strcpy(filename + strlen(filename)-2, "m");\n    } else if (av_match_ext(filename, "rtsp")) {\n        redir_type = REDIR_RTSP;\n        compute_real_filename(filename, sizeof(filename) - 1);\n    } else if (av_match_ext(filename, "sdp")) {\n        redir_type = REDIR_SDP;\n        compute_real_filename(filename, sizeof(filename) - 1);\n    }\n    if (!strlen(filename))\n        av_strlcpy(filename, "index.html", sizeof(filename) - 1);\n    stream = first_stream;\n    while (stream != NULL) {\n        if (!strcmp(stream->filename, filename) && validate_acl(stream, c))\n            break;\n        stream = stream->next;\n    }\n    if (stream == NULL) {\n        snprintf(msg, sizeof(msg), "File \'%s\' not found", url);\n        http_log("File \'%s\' not found\\n", url);\n        goto send_error;\n    }\n    c->stream = stream;\n    memcpy(c->feed_streams, stream->feed_streams, sizeof(c->feed_streams));\n    memset(c->switch_feed_streams, -1, sizeof(c->switch_feed_streams));\n    if (stream->stream_type == STREAM_TYPE_REDIRECT) {\n        c->http_error = 301;\n        q = c->buffer;\n        q += snprintf(q, c->buffer_size,\n                      "HTTP/1.0 301 Moved\\r\\n"\n                      "Location: %s\\r\\n"\n                      "Content-type: text/html\\r\\n"\n                      "\\r\\n"\n                      "<html><head><title>Moved</title></head><body>\\r\\n"\n                      "You should be <a href=\\"%s\\">redirected</a>.\\r\\n"\n                      "</body></html>\\r\\n", stream->feed_filename, stream->feed_filename);\n        c->buffer_ptr = c->buffer;\n        c->buffer_end = q;\n        c->state = HTTPSTATE_SEND_HEADER;\n        return 0;\n    }\n    if (extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) {\n        if (modify_current_stream(c, ratebuf)) {\n            for (i = 0; i < FF_ARRAY_ELEMS(c->feed_streams); i++) {\n                if (c->switch_feed_streams[i] >= 0)\n                    c->switch_feed_streams[i] = -1;\n            }\n        }\n    }\n    if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE)\n        current_bandwidth += stream->bandwidth;\n    if (stream->feed_opened) {\n        snprintf(msg, sizeof(msg), "This feed is already being received.");\n        http_log("Feed \'%s\' already being received\\n", stream->feed_filename);\n        goto send_error;\n    }\n    if (c->post == 0 && max_bandwidth < current_bandwidth) {\n        c->http_error = 503;\n        q = c->buffer;\n        q += snprintf(q, c->buffer_size,\n                      "HTTP/1.0 503 Server too busy\\r\\n"\n                      "Content-type: text/html\\r\\n"\n                      "\\r\\n"\n                      "<html><head><title>Too busy</title></head><body>\\r\\n"\n                      "<p>The server is too busy to serve your request at this time.</p>\\r\\n"\n                      "<p>The bandwidth being served (including your stream) is %"PRIu64"kbit/sec, "\n                      "and this exceeds the limit of %"PRIu64"kbit/sec.</p>\\r\\n"\n                      "</body></html>\\r\\n", current_bandwidth, max_bandwidth);\n        c->buffer_ptr = c->buffer;\n        c->buffer_end = q;\n        c->state = HTTPSTATE_SEND_HEADER;\n        return 0;\n    }\n    if (redir_type != REDIR_NONE) {\n        char *hostinfo = 0;\n        for (p = c->buffer; *p && *p != \'\\r\' && *p != \'\\n\'; ) {\n            if (av_strncasecmp(p, "Host:", 5) == 0) {\n                hostinfo = p + 5;\n                break;\n            }\n            p = strchr(p, \'\\n\');\n            if (!p)\n                break;\n            p++;\n        }\n        if (hostinfo) {\n            char *eoh;\n            char hostbuf[260];\n            while (isspace(*hostinfo))\n                hostinfo++;\n            eoh = strchr(hostinfo, \'\\n\');\n            if (eoh) {\n                if (eoh[-1] == \'\\r\')\n                    eoh--;\n                if (eoh - hostinfo < sizeof(hostbuf) - 1) {\n                    memcpy(hostbuf, hostinfo, eoh - hostinfo);\n                    hostbuf[eoh - hostinfo] = 0;\n                    c->http_error = 200;\n                    q = c->buffer;\n                    switch(redir_type) {\n                    case REDIR_ASX:\n                        q += snprintf(q, c->buffer_size,\n                                      "HTTP/1.0 200 ASX Follows\\r\\n"\n                                      "Content-type: video/x-ms-asf\\r\\n"\n                                      "\\r\\n"\n                                      "<ASX Version=\\"3\\">\\r\\n"\n                                      "<ENTRY><REF HREF=\\"http://%s/%s%s\\"/></ENTRY>\\r\\n"\n                                      "</ASX>\\r\\n", hostbuf, filename, info);\n                        break;\n                    case REDIR_RAM:\n                        q += snprintf(q, c->buffer_size,\n                                      "HTTP/1.0 200 RAM Follows\\r\\n"\n                                      "Content-type: audio/x-pn-realaudio\\r\\n"\n                                      "\\r\\n"\n                                      "# Autogenerated by avserver\\r\\n"\n                                      "http://%s/%s%s\\r\\n", hostbuf, filename, info);\n                        break;\n                    case REDIR_ASF:\n                        q += snprintf(q, c->buffer_size,\n                                      "HTTP/1.0 200 ASF Redirect follows\\r\\n"\n                                      "Content-type: video/x-ms-asf\\r\\n"\n                                      "\\r\\n"\n                                      "[Reference]\\r\\n"\n                                      "Ref1=http://%s/%s%s\\r\\n", hostbuf, filename, info);\n                        break;\n                    case REDIR_RTSP:\n                        {\n                            char hostname[256], *p;\n                            av_strlcpy(hostname, hostbuf, sizeof(hostname));\n                            p = strrchr(hostname, \':\');\n                            if (p)\n                                *p = \'\\0\';\n                            q += snprintf(q, c->buffer_size,\n                                          "HTTP/1.0 200 RTSP Redirect follows\\r\\n"\n                                          "Content-type: application/x-rtsp\\r\\n"\n                                          "\\r\\n"\n                                          "rtsp://%s:%d/%s\\r\\n", hostname, ntohs(my_rtsp_addr.sin_port), filename);\n                        }\n                        break;\n                    case REDIR_SDP:\n                        {\n                            uint8_t *sdp_data;\n                            int sdp_data_size, len;\n                            struct sockaddr_in my_addr;\n                            q += snprintf(q, c->buffer_size,\n                                          "HTTP/1.0 200 OK\\r\\n"\n                                          "Content-type: application/sdp\\r\\n"\n                                          "\\r\\n");\n                            len = sizeof(my_addr);\n                            getsockname(c->fd, (struct sockaddr *)&my_addr, &len);\n                            sdp_data_size = prepare_sdp_description(stream,\n                                                                    &sdp_data,\n                                                                    my_addr.sin_addr);\n                            if (sdp_data_size > 0) {\n                                memcpy(q, sdp_data, sdp_data_size);\n                                q += sdp_data_size;\n                                *q = \'\\0\';\n                                av_free(sdp_data);\n                            }\n                        }\n                        break;\n                    default:\n                        abort();\n                        break;\n                    }\n                    c->buffer_ptr = c->buffer;\n                    c->buffer_end = q;\n                    c->state = HTTPSTATE_SEND_HEADER;\n                    return 0;\n                }\n            }\n        }\n        snprintf(msg, sizeof(msg), "ASX/RAM file not handled");\n        goto send_error;\n    }\n    stream->conns_served++;\n    if (c->post) {\n        if (!stream->is_feed) {\n            char *logline = 0;\n            int client_id = 0;\n            for (p = c->buffer; *p && *p != \'\\r\' && *p != \'\\n\'; ) {\n                if (av_strncasecmp(p, "Pragma: log-line=", 17) == 0) {\n                    logline = p;\n                    break;\n                }\n                if (av_strncasecmp(p, "Pragma: client-id=", 18) == 0)\n                    client_id = strtol(p + 18, 0, 10);\n                p = strchr(p, \'\\n\');\n                if (!p)\n                    break;\n                p++;\n            }\n            if (logline) {\n                char *eol = strchr(logline, \'\\n\');\n                logline += 17;\n                if (eol) {\n                    if (eol[-1] == \'\\r\')\n                        eol--;\n                    http_log("%.*s\\n", (int) (eol - logline), logline);\n                    c->suppress_log = 1;\n                }\n            }\n#ifdef DEBUG\n            http_log("\\nGot request:\\n%s\\n", c->buffer);\n#endif\n            if (client_id && extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) {\n                HTTPContext *wmpc;\n                for (wmpc = first_http_ctx; wmpc; wmpc = wmpc->next) {\n                    if (wmpc->wmp_client_id == client_id)\n                        break;\n                }\n                if (wmpc && modify_current_stream(wmpc, ratebuf))\n                    wmpc->switch_pending = 1;\n            }\n            snprintf(msg, sizeof(msg), "POST command not handled");\n            c->stream = 0;\n            goto send_error;\n        }\n        if (http_start_receive_data(c) < 0) {\n            snprintf(msg, sizeof(msg), "could not open feed");\n            goto send_error;\n        }\n        c->http_error = 0;\n        c->state = HTTPSTATE_RECEIVE_DATA;\n        return 0;\n    }\n#ifdef DEBUG\n    if (strcmp(stream->filename + strlen(stream->filename) - 4, ".asf") == 0)\n        http_log("\\nGot request:\\n%s\\n", c->buffer);\n#endif\n    if (c->stream->stream_type == STREAM_TYPE_STATUS)\n        goto send_status;\n    if (open_input_stream(c, info) < 0) {\n        snprintf(msg, sizeof(msg), "Input stream corresponding to \'%s\' not found", url);\n        goto send_error;\n    }\n    q = c->buffer;\n    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 OK\\r\\n");\n    mime_type = c->stream->fmt->mime_type;\n    if (!mime_type)\n        mime_type = "application/x-octet-stream";\n    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Pragma: no-cache\\r\\n");\n    if (!strcmp(c->stream->fmt->name,"asf_stream")) {\n        c->wmp_client_id = av_lfg_get(&random_state);\n        q += snprintf(q, q - (char *) 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);\n    }\n    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-Type: %s\\r\\n", mime_type);\n    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\\r\\n");\n    c->http_error = 0;\n    c->buffer_ptr = c->buffer;\n    c->buffer_end = q;\n    c->state = HTTPSTATE_SEND_HEADER;\n    return 0;\n send_error:\n    c->http_error = 404;\n    q = c->buffer;\n    q += snprintf(q, c->buffer_size,\n                  "HTTP/1.0 404 Not Found\\r\\n"\n                  "Content-type: text/html\\r\\n"\n                  "\\r\\n"\n                  "<html>\\n"\n                  "<head><title>404 Not Found</title></head>\\n"\n                  "<body>%s</body>\\n"\n                  "</html>\\n", msg);\n    c->buffer_ptr = c->buffer;\n    c->buffer_end = q;\n    c->state = HTTPSTATE_SEND_HEADER;\n    return 0;\n send_status:\n    compute_status(c);\n    c->http_error = 200;\n    c->state = HTTPSTATE_SEND_HEADER;\n    return 0;\n}', 'size_t av_strlcpy(char *dst, const char *src, size_t size)\n{\n    size_t len = 0;\n    while (++len < size && *src)\n        *dst++ = *src++;\n    if (len <= size)\n        *dst = 0;\n    return len + strlen(src) - 1;\n}']