parse http request and prepare header */
| 1450 | |
| 1451 | /* parse http request and prepare header */ |
| 1452 | static int http_parse_request(HTTPContext *c) |
| 1453 | { |
| 1454 | char *p; |
| 1455 | enum RedirType redir_type; |
| 1456 | char cmd[32]; |
| 1457 | char info[1024], filename[1024]; |
| 1458 | char url[1024], *q; |
| 1459 | char protocol[32]; |
| 1460 | char msg[1024]; |
| 1461 | const char *mime_type; |
| 1462 | FFStream *stream; |
| 1463 | int i; |
| 1464 | char ratebuf[32]; |
| 1465 | char *useragent = 0; |
| 1466 | |
| 1467 | p = c->buffer; |
| 1468 | get_word(cmd, sizeof(cmd), (const char **)&p); |
| 1469 | av_strlcpy(c->method, cmd, sizeof(c->method)); |
| 1470 | |
| 1471 | if (!strcmp(cmd, "GET")) |
| 1472 | c->post = 0; |
| 1473 | else if (!strcmp(cmd, "POST")) |
| 1474 | c->post = 1; |
| 1475 | else |
| 1476 | return -1; |
| 1477 | |
| 1478 | get_word(url, sizeof(url), (const char **)&p); |
| 1479 | av_strlcpy(c->url, url, sizeof(c->url)); |
| 1480 | |
| 1481 | get_word(protocol, sizeof(protocol), (const char **)&p); |
| 1482 | if (strcmp(protocol, "HTTP/1.0") && strcmp(protocol, "HTTP/1.1")) |
| 1483 | return -1; |
| 1484 | |
| 1485 | av_strlcpy(c->protocol, protocol, sizeof(c->protocol)); |
| 1486 | |
| 1487 | if (ffserver_debug) |
| 1488 | http_log("%s - - New connection: %s %s\n", inet_ntoa(c->from_addr.sin_addr), cmd, url); |
| 1489 | |
| 1490 | /* find the filename and the optional info string in the request */ |
| 1491 | p = strchr(url, '?'); |
| 1492 | if (p) { |
| 1493 | av_strlcpy(info, p, sizeof(info)); |
| 1494 | *p = '\0'; |
| 1495 | } else |
| 1496 | info[0] = '\0'; |
| 1497 | |
| 1498 | av_strlcpy(filename, url + ((*url == '/') ? 1 : 0), sizeof(filename)-1); |
| 1499 | |
| 1500 | for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { |
| 1501 | if (strncasecmp(p, "User-Agent:", 11) == 0) { |
| 1502 | useragent = p + 11; |
| 1503 | if (*useragent && *useragent != '\n' && isspace(*useragent)) |
| 1504 | useragent++; |
| 1505 | break; |
| 1506 | } |
| 1507 | p = strchr(p, '\n'); |
| 1508 | if (!p) |
| 1509 | break; |
no test coverage detected