* HTTP protocol for ffmpeg client
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "http.h"
#include "os_support.h"
#include "httpauth.h"
-#include "libavcodec/opt.h"
+#include "libavutil/opt.h"
/* XXX: POST protocol is not completely implemented because ffmpeg uses
only a subset of it. */
/* used for protocol handling */
#define BUFFER_SIZE 1024
-#define URL_SIZE 4096
#define MAX_REDIRECTS 8
typedef struct {
int http_code;
int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */
int64_t off, filesize;
- char location[URL_SIZE];
+ char location[MAX_URL_SIZE];
HTTPAuthState auth_state;
unsigned char headers[BUFFER_SIZE];
int willclose; /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */
} else
goto fail;
}
- if ((s->http_code == 302 || s->http_code == 303) && location_changed == 1) {
+ if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)
+ && location_changed == 1) {
/* url moved, get next */
url_close(hd);
if (redirects++ >= MAX_REDIRECTS)
h->is_streamed = 1;
s->filesize = -1;
- av_strlcpy(s->location, uri, URL_SIZE);
+ av_strlcpy(s->location, uri, sizeof(s->location));
return http_open_cnx(h);
}
p++;
s->http_code = strtol(p, &end, 10);
- dprintf(NULL, "http_code=%d\n", s->http_code);
+ av_dlog(NULL, "http_code=%d\n", s->http_code);
/* error codes are 4xx and 5xx, but regard 401 as a success, so we
* don't abort until all headers have been parsed. */
p++;
while (isspace(*p))
p++;
- if (!strcmp(tag, "Location")) {
+ if (!strcasecmp(tag, "Location")) {
strcpy(s->location, p);
*new_location = 1;
- } else if (!strcmp (tag, "Content-Length") && s->filesize == -1) {
+ } else if (!strcasecmp (tag, "Content-Length") && s->filesize == -1) {
s->filesize = atoll(p);
- } else if (!strcmp (tag, "Content-Range")) {
+ } else if (!strcasecmp (tag, "Content-Range")) {
/* "bytes $from-$to/$document_size" */
const char *slash;
if (!strncmp (p, "bytes ", 6)) {
s->filesize = atoll(slash+1);
}
h->is_streamed = 0; /* we _can_ in fact seek */
- } else if (!strcmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) {
+ } else if (!strcasecmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) {
s->filesize = -1;
s->chunksize = 0;
- } else if (!strcmp (tag, "WWW-Authenticate")) {
+ } else if (!strcasecmp (tag, "WWW-Authenticate")) {
ff_http_auth_handle_header(&s->auth_state, tag, p);
- } else if (!strcmp (tag, "Authentication-Info")) {
+ } else if (!strcasecmp (tag, "Authentication-Info")) {
ff_http_auth_handle_header(&s->auth_state, tag, p);
- } else if (!strcmp (tag, "Connection")) {
+ } else if (!strcasecmp (tag, "Connection")) {
if (!strcmp(p, "close"))
s->willclose = 1;
}
if (http_get_line(s, line, sizeof(line)) < 0)
return AVERROR(EIO);
- dprintf(NULL, "header='%s'\n", line);
+ av_dlog(NULL, "header='%s'\n", line);
err = process_line(h, line, s->line_count, new_location);
if (err < 0)
s->chunksize = strtoll(line, NULL, 16);
- dprintf(NULL, "Chunked encoding data size: %"PRId64"'\n", s->chunksize);
+ av_dlog(NULL, "Chunked encoding data size: %"PRId64"'\n", s->chunksize);
if (!s->chunksize)
return 0;
return url_get_file_handle(s->hd);
}
-URLProtocol http_protocol = {
+URLProtocol ff_http_protocol = {
"http",
http_open,
http_read,