int line_count;
int http_code;
/* Used if "Transfer-Encoding: chunked" otherwise -1. */
- int64_t chunksize;
- int64_t off, end_off, filesize;
+ uint64_t chunksize;
+ uint64_t off, end_off, filesize;
char *location;
HTTPAuthState auth_state;
HTTPAuthState proxy_auth_state;
int post_datalen;
int icy;
/* how much data was read since the last ICY metadata packet */
- int icy_data_read;
+ uint64_t icy_data_read;
/* after how many bytes of read data a new metadata packet will be found */
- int icy_metaint;
+ uint64_t icy_metaint;
char *icy_metadata_headers;
char *icy_metadata_packet;
AVDictionary *metadata;
h->is_streamed = 1;
- s->filesize = -1;
+ s->filesize = UINT64_MAX;
s->location = av_strdup(uri);
if (!s->location)
return AVERROR(ENOMEM);
if (!strncmp(p, "bytes ", 6)) {
p += 6;
- s->off = strtoll(p, NULL, 10);
+ s->off = strtoull(p, NULL, 10);
if ((slash = strchr(p, '/')) && strlen(slash) > 0)
- s->filesize = strtoll(slash + 1, NULL, 10);
+ s->filesize = strtoull(slash + 1, NULL, 10);
}
h->is_streamed = 0; /* we _can_ in fact seek */
}
if ((ret = parse_location(s, p)) < 0)
return ret;
*new_location = 1;
- } else if (!av_strcasecmp(tag, "Content-Length") && s->filesize == -1) {
- s->filesize = strtoll(p, NULL, 10);
+ } else if (!av_strcasecmp(tag, "Content-Length") &&
+ s->filesize == UINT64_MAX) {
+ s->filesize = strtoull(p, NULL, 10);
} else if (!av_strcasecmp(tag, "Content-Range")) {
parse_content_range(h, p);
} else if (!av_strcasecmp(tag, "Accept-Ranges") &&
h->is_streamed = 0;
} else if (!av_strcasecmp(tag, "Transfer-Encoding") &&
!av_strncasecmp(p, "chunked", 7)) {
- s->filesize = -1;
+ s->filesize = UINT64_MAX;
s->chunksize = 0;
} else if (!av_strcasecmp(tag, "WWW-Authenticate")) {
ff_http_auth_handle_header(&s->auth_state, tag, p);
av_free(s->mime_type);
s->mime_type = av_strdup(p);
} else if (!av_strcasecmp(tag, "Icy-MetaInt")) {
- s->icy_metaint = strtoll(p, NULL, 10);
+ s->icy_metaint = strtoull(p, NULL, 10);
} else if (!av_strncasecmp(tag, "Icy-", 4)) {
if ((ret = parse_icy(s, tag, p)) < 0)
return ret;
char line[MAX_URL_SIZE];
int err = 0;
- s->chunksize = -1;
+ s->chunksize = UINT64_MAX;
for (;;) {
if ((err = http_get_line(s, line, sizeof(line))) < 0)
int post, err;
char headers[HTTP_HEADERS_SIZE] = "";
char *authstr = NULL, *proxyauthstr = NULL;
- int64_t off = s->off;
+ uint64_t off = s->off;
int len = 0;
const char *method;
int send_expect_100 = 0;
// server supports seeking by analysing the reply headers.
if (!has_header(s->headers, "\r\nRange: ") && !post) {
len += av_strlcatf(headers + len, sizeof(headers) - len,
- "Range: bytes=%"PRId64"-", s->off);
+ "Range: bytes=%"PRIu64"-", s->off);
if (s->end_off)
len += av_strlcatf(headers + len, sizeof(headers) - len,
"%"PRId64, s->end_off - 1);
s->line_count = 0;
s->off = 0;
s->icy_data_read = 0;
- s->filesize = -1;
+ s->filesize = UINT64_MAX;
s->willclose = 0;
s->end_chunked_post = 0;
s->end_header = 0;
if (err < 0)
return err;
- return (off == s->off) ? 0 : -1;
+ return (off == s->off) ? 0 : UINT64_MAX;
}
static int http_buf_read(URLContext *h, uint8_t *buf, int size)
memcpy(buf, s->buf_ptr, len);
s->buf_ptr += len;
} else {
- int64_t target_end = s->end_off ? s->end_off : s->filesize;
- if ((!s->willclose || s->chunksize < 0) &&
- target_end >= 0 && s->off >= target_end)
+ uint64_t target_end = s->end_off ? s->end_off : s->filesize;
+ if ((!s->willclose || s->chunksize == UINT64_MAX) && s->off >= target_end)
return AVERROR_EOF;
len = ffurl_read(s->hd, buf, size);
- if (!len && (!s->willclose || s->chunksize < 0) &&
- target_end >= 0 && s->off < target_end) {
+ if (!len && (!s->willclose || s->chunksize == UINT64_MAX) && s->off < target_end) {
av_log(h, AV_LOG_ERROR,
- "Streams ends prematurly at %"PRId64", should be %"PRId64"\n",
+ "Streams ends prematurly at %"PRIu64", should be %"PRIu64"\n",
s->off, target_end
);
return AVERROR(EIO);
return err;
}
- if (s->chunksize >= 0) {
+ if (s->chunksize != UINT64_MAX) {
if (!s->chunksize) {
char line[32];
return err;
} while (!*line); /* skip CR LF from last chunk */
- s->chunksize = strtoll(line, NULL, 16);
+ s->chunksize = strtoull(line, NULL, 16);
- av_dlog(NULL, "Chunked encoding data size: %"PRId64"'\n",
+ av_log(h, AV_LOG_DEBUG,
+ "Chunked encoding data size: %"PRIu64"'\n",
s->chunksize);
- if (s->chunksize < 0)
- return AVERROR_INVALIDDATA;
- else if (!s->chunksize)
+ if (!s->chunksize)
return 0;
- break;
+ else if (s->chunksize == UINT64_MAX) {
+ av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n",
+ s->chunksize);
+ return AVERROR_INVALIDDATA;
+ }
}
}
size = FFMIN(size, s->chunksize);
}
+
#if CONFIG_ZLIB
if (s->compressed)
return http_buf_read_compressed(h, buf, size);
{
HTTPContext *s = h->priv_data;
/* until next metadata packet */
- int remaining = s->icy_metaint - s->icy_data_read;
+ uint64_t remaining;
- if (remaining < 0)
+ if (s->icy_metaint < s->icy_data_read)
return AVERROR_INVALIDDATA;
+ remaining = s->icy_metaint - s->icy_data_read;
if (!remaining) {
/* The metadata packet is variable sized. It has a 1 byte header
{
HTTPContext *s = h->priv_data;
URLContext *old_hd = s->hd;
- int64_t old_off = s->off;
+ uint64_t old_off = s->off;
uint8_t old_buf[BUFFER_SIZE];
int old_buf_size, ret;
AVDictionary *options = NULL;
else if ((whence == SEEK_CUR && off == 0) ||
(whence == SEEK_SET && off == s->off))
return s->off;
- else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed)
+ else if ((s->filesize == UINT64_MAX && whence == SEEK_END) || h->is_streamed)
return AVERROR(ENOSYS);
/* we save the old context in case the seek fails */
s->buf_ptr = s->buffer;
s->buf_end = s->buffer;
s->line_count = 0;
- s->filesize = -1;
+ s->filesize = UINT64_MAX;
cur_auth_type = s->proxy_auth_state.auth_type;
/* Note: This uses buffering, potentially reading more than the