txoffer (e.g. http://tori.aoi-chan.com/ ) redirects to the same URI on your
first request, and serves the actual file on the second. It's stupid, but AFAIK
technically compliant. We'd previously see the server not handing back a Range
header and return an error; now, instead, we see that there's a redirect and
keep track of the offset we want while trying again at the new URL.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
With this patch http can be used to listen for POST data to be used as an input stream.
Signed-off-by: Stephan Holljes <klaxa1337@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
In http_open_cnx, the patch restores the AVDictionary if connection needs to be re-tried
because of a authentication/redirect status code.
Previously, if a 401/407/30x status code was encountered, http_open_cnx would restart at the redo label, but any options
used by the underlying protocol would be missing because they were removed by the first attempt.
Signed-off-by: Brandon Lees <brandon@n-hega.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Previously, AVERROR(EIO) was returned on failure of
http_open_cnx_internal(). Now the value is passed to upper level, thus
it is possible to distinguish ECONNREFUSED, ETIMEDOUT, ENETUNREACH etc.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
int ff_http_averror(int status_code, int default_averror)
This helper function returns AVERROR_ value from 3-digit HTTP status
code.
Second argument, default_averror, is used if no specific AVERROR_ is
available. It is introduced because in different places of code
different return codes are used - -1, AVERROR(EIO), AVERROR_INVALIDDATA.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
The current code would use any unknown attribute-value pair
as the cookie value.
RFC 6265 states that the first key-value pair is the actual
cookie, and the attribute-value pairs only start after.
With the current code:
Set-Cookie: test=good_value; path=/; dummy=42
gives this:
Cookie: dummy=42
instead of this with the new code:
Cookie: test=good_value
* commit '7ccb847f0f1f28199fa254847b91b6e50fb92832':
http: Reduce scope of a variable in parse_content_encoding()
Merged-by: Michael Niedermayer <michaelni@gmx.at>
* commit '7601f9412a2d3387617a45966b65b452a632c27a':
http: export icecast metadata as an option with name "metadata".
Merged-by: Michael Niedermayer <michaelni@gmx.at>
The cur_*auth_type variables were set before the http_connect call
prior to 6a463e7fb - their sole purpose is to record the
authentication type used to do the latest request, since parsing
the http response sets the new type in the auth state.
CC: libav-stable@libav.org
Signed-off-by: Martin Storsjö <martin@martin.st>
* commit '8bf3bf69ad7333bf0c45f4d2797fc2c61bc8922f':
http: Stop reading after receiving the whole file for non-chunked transfers
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Previously this logic was only used if the server didn't
respond with Connection: close, but use it even for that case,
if the server response is non-chunked.
Originally the http code has relied on Connection: close to close
the socket when the file/stream is received - the http protocol
code just kept reading from the socket until the socket was closed.
In f240ed18 we added a check for the file size, because some
http servers didn't respond with Connection: close (and wouldn't
close the socket) even though we requested it, which meant that the
http protocol blocked for a long time at the end of files, waiting
for a socket level timeout.
When reading over tls, trying to read at the end of the connection,
when the peer has closed the connection, can produce spurious (but
harmless) warnings. Therefore always voluntarily stop reading when
the specified file size has been received, if not using a chunked
transfer encoding. (For chunked transfers, we already return 0
as soon as we get the chunk header indicating end of stream.)
Signed-off-by: Martin Storsjö <martin@martin.st>
Split return value handling from the actual opening.
Incidentally fixes the https -> http redirect issue reported by
Compn on behalf of rcombs.
CC: libav-stable@libav.org
* commit '7bdd2ff6825951f7a6a6008303acfce7c2a63532':
http: Use a constant for the supported header size
Conflicts:
libavformat/http.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
* commit '389380c27915b0505fed538cd54c035c891fabd9':
http: Do move the class instantiation in the conditional block
Merged-by: Michael Niedermayer <michaelni@gmx.at>
* commit '28df1d24112c6ad0763985df2faeeb198cfbad69':
http: Provide an option to override the HTTP method
Merged-by: Michael Niedermayer <michaelni@gmx.at>
The authstr memory allocations make it annoying to error in the middle
of the header setup code, so apply the usual C error handling idiom to
make it easier to error at any point.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
If a domain has some cookies set, but matching the cookie fails due to
the port being different, get_cookies() succeeds, but sets cookies to
NULL. The caller of get_cookies() didn't check for the NULL value.
This also avoids passing NULL to libc string functions, which is
undefined behavior
Fixes Ticket2180
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* commit 'e77a2ea9505863e50bf013706f66bf8b7325e524':
http: Declare more parameters as const where possible
Merged-by: Michael Niedermayer <michaelni@gmx.at>
The icy_metadata_headers string never gets initialized, so,
during the first call to av_strlcatf() in parse_icy(),
strlen() will be called on a pointer to uninitialized memory.
At best this causes some garbage data to be left at the
start of the string.
By initializing icy_metadata_headers to the empty string, the
first call to strlen() will always return 0, so that data is
appended from the start of the string.
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
* qatar/master:
http: Allow setting a Content-Type for POST requests
Conflicts:
libavformat/http.c
See: c01d1d4ddf
Merged-by: Michael Niedermayer <michaelni@gmx.at>
* commit '2ec33d27127251bbc45e1f88e60691ad59cf2319':
http: Add support for selecting a request range
Conflicts:
doc/protocols.texi
libavformat/http.c
See: d52882faef
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Export the metadata as a icy_metadata_packet avoption.
Based on the work of wm4 and Alessandro Ghedini.
Bug-Id: https://bugs.debian.org/739936
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Some http servers send an ICY stream in combination with chunked
transfer encoding. This case was handled incorrectly by the ICY code:
instead of handling chunked encoding before anything ICY related, both
were mixed.
Fix this by separating the ICY code from normal http reading. Move the
normal http reading to a new function http_read_stream(), while
http_read() handles ICY on top of http_read_stream().
The server identified itself as: cloudflare-nginx
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Add AVOptions for setting the initial offset and the ending offset, so
they can be used for setting an appropriate Range header.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
* commit 'be4edda6731a341d3fdeaa0e57753dc396790362':
http: Expose the content location via an AVOption
Conflicts:
libavformat/http.c
libavformat/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
* commit '76267ecc82e3018e1913a2483d5fc47d0949cbd8':
http: Remove an unrelated and mistakenly set AVOption unit name
Merged-by: Michael Niedermayer <michaelni@gmx.at>
These streams are reported as seekable, but all tests show they are not,
and the server merely pretends the streams are seekable. The server
responds with:
content-range: bytes 0-1999999999/2000000000
Range requests seem to be correctly answered, but the actual data
returned at the same offset is different. Assume this is a bug in the
server software. The server identifies itself as:
Server: MediaGateway 3.5.2-001
Add a hack that checks the server name, and disables seeking in this
case.
Test URL: http://8283.live.streamtheworld.com:80/CBC_R1_VCR_H_SC
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* qatar/master:
http: Check the auth string contents and not only the pointer
Conflicts:
libavformat/http.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
This makes sure we don't send the Except: 100-continue header
if no authentication credentials have been provided.
Signed-off-by: Martin Storsjö <martin@martin.st>
It appears this bug originates from a "work in progress" patch from
ffmpeg-devel that was heavily redesigned by and integrated in libav
And that patch even had a reply and review on the mailing list pointing
out that it had a bug.
This fixes a deadlock with ffserver
See: [FFmpeg-devel] [PATCH] Fix HTTP authentication problem for POST actions.
[FFmpeg-devel] [PATCH 1/3] Introduce auth_phase flag, which will be true if authorization needs to be sent, but the type of authorization is not known yet Partial fix#3036
[FFmpeg-devel] [PATCH 2/3] Only add Transfer-Encoding header when not in authorization phase, because server will wait (indefinitely) for data when receiving this header Partial fix#3036
[FFmpeg-devel] [PATCH 3/3] Only allow posting data and/or forcing a 200 code, enabling posting isml chunks, -after- we did a possible first request to get a 403 from the server telling us which type of authentication to apply Final part fix#3036
See: 71549a857b
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* commit '71549a857b13edf4c4f95037de6ed5bb4c4bd4af':
http: Support auth method detection for POST
Conflicts:
libavformat/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Inspired by a patch by Jakob van Bethlehem. But instead of doing
an empty POST first to trigger the WWW-Authenticate header (which
would succeed if no auth actually was required), add an Expect:
100-continue header, which is meant to be used exactly for
cases like this.
The header is added if doing a post, and the user has specified
authentication but we don't know the auth method yet.
Not all common HTTP servers support the Expect: 100-continue header,
though, so we only try to use it when it really is needed. The user
can request it to be added for other POST requests as well via
an option - which would allow the caller to know immediately that
the POST has failed (e.g. if no auth was provided but the server
required it, or if the target URL simply doesn't exist).
This is only done for write mode posts (e.g. posts without pre-set
post_data) - for posts with pre-set data, we can just redo the post
if it failed due to 401.
Signed-off-by: Martin Storsjö <martin@martin.st>
The default is to autodetect the auth method. This does require one
extra request (and also closing and reopening the http connection).
For some cases such as HTTP POST, the autodetection is not handled
properly (yet).
No option is added for digest, since this method requires getting
nonce parameters from the server first and can't be used straight
away like Basic.
Signed-off-by: Martin Storsjö <martin@martin.st>
* commit '5c53bf7aaf03748464cbf978bffe7ffdb71112b1':
http: Pass options through to the nested protocol
Conflicts:
libavformat/http.c
See: b6f435fbc8
Merged-by: Michael Niedermayer <michaelni@gmx.at>
When passing a dict to the nested protocol, it will consume
the used options from it, so a separate copy needs to be used
when reopening the connection multiple times.
Signed-off-by: Martin Storsjö <martin@martin.st>
Derived from VLC's http module.
Original authors:
Antoine Cellerier <dionoea@videolan.org>
Sébastien Escudier <sebastien-devel@celeos.eu>
Rémi Duraffort <ivoire@videolan.org>
Rémi Denis-Courmont <remi@remlab.net>
Francois Cartegnie <fcvlcdev@free.fr>
Normally, http servers shouldn't send this to us since we
don't advertise it with an Accept-Encoding header, but some
servers still do it anyway.
Signed-off-by: Martin Storsjö <martin@martin.st>
Allow applications to request reading streamcast metadata. This uses
AVOptions as API, and requires the application to explicitly request
and read metadata. Metadata can be updated mid-stream; if an
application is interested in that, it has to poll for the data by
reading the "icy_metadata_packet" option in regular intervals.
There doesn't seem to be a nice way to transfer the metadata in a nicer
way. Converting the metadata to ID3v2 tags might be a nice idea, but
the libavformat mp3 demuxer doesn't seem to read these tags mid-stream,
and even then we couldn't guarantee that tags are not inserted in the
middle of mp3 packet data.
This commit provides the minimum to enable applications to retrieve
this information at all.
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
It is notably known to break playback on http streaming servers who use
the user agent to guess if it's a browser (to display a summary) or a
player (to stream the audio data).
This reverts 1fabd95.
Fixes Ticket #2663.
As far as I can tell the code should not change behaviour
depending on locale in any of these places.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
* qatar/master:
lavf: Add a fate test for the noproxy pattern matching
lavf: Handle the environment variable no_proxy more properly
Conflicts:
libavformat/Makefile
libavformat/internal.h
libavformat/tls.c
libavformat/utils.c
libavformat/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
The handling of the environment variable no_proxy, present since
one of the initial commits (de6d9b6404), is inconsistent with
how many other applications and libraries interpret this
variable. Its bare presence does not indicate that the use of
proxies should be skipped, but it is some sort of pattern for
hosts that does not need using a proxy (e.g. for a local network).
As investigated by Rudolf Polzer, different libraries handle this
in different ways, some supporting IP address masks, some supporting
arbitrary globbing using *, some just checking that the pattern matches
the end of the hostname without regard for whether it actually is
the right domain or a domain that ends in the same string.
This simple logic should be pretty similar to the logic used by
lynx and curl.
Signed-off-by: Martin Storsjö <martin@martin.st>
* commit '6d0beefbf6ee6dbf8efb522a9307e54c6ed5f702':
swscale: Do not make ff_ symbols globally visible.
rtspdec: use av_strlcpy for writing into fixed size buffer
g722enc: fix size argument in memset
http: use av_strlcpy instead of strcpy() without size checks
avfilter: correct memcpy size avfilter_copy_buf_props()
lavc: split asv12 encoder/decoder
Conflicts:
libavcodec/asvdec.c
libavfilter/buffer.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Add an tri-state (seek, non seek, automatic detection) option to HTTP to control seekability (default: automatic).
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* qatar/master:
libopus: Remap channels using libopus' internal remapping.
Opus decoder using libopus
avcodec: document the use of AVCodecContext.delay for audio decoding
vc1dec: add flush function for WMV9 and VC-1 decoders
http: Increase buffer sizes to cope with longer URIs
nutenc: const correctness for ff_put_v_trace/put_s_trace function arguments
h264_refs: Fix debug tprintf argument types
golomb: const correctness for get_ue()/get_se() function arguments
get_bits: const correctness for get_bits_trace()/get_xbits_trace() arguments
Conflicts:
Changelog
libavcodec/Makefile
libavcodec/version.h
libavformat/http.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Use the MAX_URL_SIZE define where applicable. Increase buffer
sizes for all buffers that need to fit a long pathname - buffers
that need to fit only the hostname (and other short strings, but
not the pathname - such as "headers" in http_connect) are kept
at 1024 bytes for now.
Also increase the max line length in http_read_header, since it
might need to contain a full url for Location: redirects.
Signed-off-by: Martin Storsjö <martin@martin.st>
* qatar/master:
MS Screen 1 decoder
aacdec: Fix popping channel layouts.
av_gettime: support Win32 without gettimeofday()
Use av_gettime() in various places
Move av_gettime() to libavutil
dct-test: use emms_c() from libavutil instead of duplicating it
mov: fix operator precedence bug
mathematics.h: remove a couple of math defines
Remove unnecessary inclusions of [sys/]time.h
lavf: remove unnecessary inclusions of unistd.h
bfin: libswscale: add const where appropriate to fix warnings
bfin: libswscale: remove unnecessary #includes
udp: Properly check for invalid sockets
tcp: Check the return value from getsockopt
network: Use av_strerror for getting error messages
udp: Properly print error from getnameinfo
mmst: Use AVUNERROR() to convert error codes to the right range for strerror
network: Pass pointers of the right type to get/setsockopt/ioctlsocket on windows
rtmp: Reduce the number of idle posts sent by sleeping 50ms
Conflicts:
Changelog
configure
libavcodec/aacdec.c
libavcodec/allcodecs.c
libavcodec/avcodec.h
libavcodec/dct-test.c
libavcodec/version.h
libavformat/riff.c
libavformat/udp.c
libavutil/Makefile
libswscale/bfin/yuv2rgb_bfin.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
* qatar/master: (24 commits)
flvdec: remove incomplete, disabled seeking code
mem: add support for _aligned_malloc() as found on Windows
lavc: Extend the documentation for avcodec_init_packet
flvdec: remove incomplete, disabled seeking code
http: replace atoll() with strtoll()
mpegts: remove unused/incomplete/broken seeking code
af_amix: allow float planar sample format as input
af_amix: use AVFloatDSPContext.vector_fmac_scalar()
float_dsp: add x86-optimized functions for vector_fmac_scalar()
float_dsp: Move vector_fmac_scalar() from libavcodec to libavutil
lavr: Add x86-optimized function for flt to s32 conversion
lavr: Add x86-optimized function for flt to s16 conversion
lavr: Add x86-optimized functions for s32 to flt conversion
lavr: Add x86-optimized functions for s32 to s16 conversion
lavr: Add x86-optimized functions for s16 to flt conversion
lavr: Add x86-optimized function for s16 to s32 conversion
rtpenc: Support packetizing iLBC
rtpdec: Add a depacketizer for iLBC
Implement the iLBC storage file format
mov: Support muxing/demuxing iLBC
...
Conflicts:
Changelog
configure
libavcodec/avcodec.h
libavcodec/dsputil.c
libavcodec/version.h
libavformat/movenc.c
libavformat/mpegts.c
libavformat/version.h
libavutil/mem.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
* qatar/master:
lavr: add x86-optimized functions for mixing 1-to-2 s16p with flt coeffs
lavr: add x86-optimized functions for mixing 1-to-2 fltp with flt coeffs
Add Dolby/DPLII downmix support to libavresample
vorbisdec: replace div/mod in loop with a counter
fate: vorbis: add 5.1 surround test
rtpenc: Allow requesting H264 RTP packetization mode 0
configure: Sort the library listings in the help text alphabetically
dwt: remove variable-length arrays
RTMPT protocol support
http: Properly handle chunked transfer-encoding for replies to post data
http: Fail reading if the connection has gone away
amr: Mark an array const
amr: More space cleanup
rtpenc: Fix memory leaks in the muxer open function
Conflicts:
Changelog
configure
doc/APIchanges
libavformat/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
This can happen if doing a new request using the same socket,
but the new request failed, which clears the urlcontext.
Signed-off-by: Martin Storsjö <martin@martin.st>
* qatar/master:
http: Add the url_shutdown function for https, too
http: Simplify code by removing a local variable
http: Clear the old URLContext pointer when closed
tcp: Try enabling SO_REUSEADDR when listening
tcp: Check the return values from bind and accept
avisynth: Make sure the filename passed to avisynth is in the right code page
Conflicts:
libavformat/http.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
This fixes issues with opening http urls that have authentication
or redirects, introduced in commit e999b641.
Signed-off-by: Martin Storsjö <martin@martin.st>