int len = 0;
const char *method;
int send_expect_100 = 0;
+ int ret;
/* send http header */
post = h->flags & AVIO_FLAG_WRITE;
if (s->headers)
av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
- snprintf(s->buffer, sizeof(s->buffer),
+ ret = snprintf(s->buffer, sizeof(s->buffer),
"%s %s HTTP/1.1\r\n"
"%s"
"%s"
av_log(h, AV_LOG_DEBUG, "request: %s\n", s->buffer);
+ if (strlen(headers) + 1 == sizeof(headers) ||
+ ret >= sizeof(s->buffer)) {
+ av_log(h, AV_LOG_ERROR, "overlong headers\n");
+ err = AVERROR(EINVAL);
+ goto done;
+ }
+
+
if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
goto done;
{
HTTPContext *s = h->priv_data;
int len;
+
+ if (s->chunksize != UINT64_MAX) {
+ if (!s->chunksize) {
+ char line[32];
+ int err;
+
+ do {
+ if ((err = http_get_line(s, line, sizeof(line))) < 0)
+ return err;
+ } while (!*line); /* skip CR LF from last chunk */
+
+ s->chunksize = strtoull(line, NULL, 16);
+
+ av_log(h, AV_LOG_TRACE,
+ "Chunked encoding data size: %"PRIu64"'\n",
+ s->chunksize);
+
+ if (!s->chunksize)
+ return 0;
+ else if (s->chunksize == UINT64_MAX) {
+ av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n",
+ s->chunksize);
+ return AVERROR(EINVAL);
+ }
+ }
+ size = FFMIN(size, s->chunksize);
+ }
+
/* read bytes from input buffer first */
len = s->buf_end - s->buf_ptr;
if (len > 0) {
}
if (len > 0) {
s->off += len;
- if (s->chunksize > 0)
+ if (s->chunksize > 0) {
+ av_assert0(s->chunksize >= len);
s->chunksize -= len;
+ }
}
return len;
}
return err;
}
- if (s->chunksize != UINT64_MAX) {
- if (!s->chunksize) {
- char line[32];
-
- do {
- if ((err = http_get_line(s, line, sizeof(line))) < 0)
- return err;
- } while (!*line); /* skip CR LF from last chunk */
-
- s->chunksize = strtoull(line, NULL, 16);
-
- av_log(h, AV_LOG_TRACE,
- "Chunked encoding data size: %"PRIu64"'\n",
- s->chunksize);
-
- if (!s->chunksize)
- return 0;
- else if (s->chunksize == UINT64_MAX) {
- av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n",
- s->chunksize);
- return AVERROR(EINVAL);
- }
- }
- size = FFMIN(size, s->chunksize);
- }
#if CONFIG_ZLIB
if (s->compressed)
return http_buf_read_compressed(h, buf, size);
return ffurl_get_file_handle(s->hd);
}
+static int http_get_short_seek(URLContext *h)
+{
+ HTTPContext *s = h->priv_data;
+ return ffurl_get_short_seek(s->hd);
+}
+
#define HTTP_CLASS(flavor) \
static const AVClass flavor ## _context_class = { \
.class_name = # flavor, \
.url_seek = http_seek,
.url_close = http_close,
.url_get_file_handle = http_get_file_handle,
+ .url_get_short_seek = http_get_short_seek,
.url_shutdown = http_shutdown,
.priv_data_size = sizeof(HTTPContext),
.priv_data_class = &http_context_class,
.url_seek = http_seek,
.url_close = http_close,
.url_get_file_handle = http_get_file_handle,
+ .url_get_short_seek = http_get_short_seek,
.url_shutdown = http_shutdown,
.priv_data_size = sizeof(HTTPContext),
.priv_data_class = &https_context_class,