[FFmpeg-devel] [PATCH] http: handle URLs with spaces
wm4
nfxjfg at googlemail.com
Fri Jan 31 16:44:07 CET 2014
On Fri, 31 Jan 2014 15:58:48 +0100
Nicolas George <george at nsup.org> wrote:
> Le duodi 12 pluviôse, an CCXXII, wm4 a écrit :
> > This fixes making HTTP requests with URLs that contain spaces.
>
> HTTP requests should not contain spaces: how do you encounter them, and why
> do you not just reject them with EINVAL?
Because users want to play URLs that have spaces in them. Something got
to escape the spaces. Most software does this automatically, so should
libavformat.
> > ---
> > libavformat/http.c | 26 +++++++++++++++++++++++++-
> > 1 file changed, 25 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/http.c b/libavformat/http.c
> > index 69c4d6d..ae4c499 100644
> > --- a/libavformat/http.c
> > +++ b/libavformat/http.c
> > @@ -597,6 +597,27 @@ static int http_read_header(URLContext *h, int *new_location)
> > return err;
> > }
> >
> > +static void escape_spaces(char *dst, size_t dst_size, const char *src)
> > +{
> > + size_t src_pos = 0;
> > + size_t dst_pos = 0;
> > + if (dst_size < 1)
> > + return;
> > + while (dst_pos + 1 < dst_size && src[src_pos]) {
> > + if (src[src_pos] == ' ') {
>
> > + if (dst_pos + 3 >= dst_size)
> > + break;
>
> Missing error check.
This does the same "error checking" as the code did before: truncate if
the buffer is too small. Feel free to fix it with a separate patch, but
you'll have to touch much more code. In fact, you'll have to rewrite
the whole http_connect function.
> > + dst[dst_pos++] = '%';
> > + dst[dst_pos++] = '2';
> > + dst[dst_pos++] = '0';
> > + } else {
> > + dst[dst_pos++] = src[src_pos];
> > + }
> > + src_pos++;
> > + }
> > + dst[dst_pos] = '\0';
> > +}
> > +
> > static int http_connect(URLContext *h, const char *path, const char *local_path,
> > const char *hoststr, const char *auth,
> > const char *proxyauth, int *new_location)
> > @@ -604,6 +625,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
> > HTTPContext *s = h->priv_data;
> > int post, err;
> > char headers[4096] = "";
> > + char url[MAX_URL_SIZE];
> > char *authstr = NULL, *proxyauthstr = NULL;
> > int64_t off = s->off;
> > int len = 0;
> > @@ -697,6 +719,8 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
> > if (s->headers)
> > av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
> >
> > + escape_spaces(url, sizeof(url), path);
> > +
> > snprintf(s->buffer, sizeof(s->buffer),
> > "%s %s HTTP/1.1\r\n"
> > "%s"
> > @@ -705,7 +729,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
> > "%s%s"
> > "\r\n",
> > method,
> > - path,
> > + url,
> > post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : "",
> > headers,
> > authstr ? authstr : "",
>
> Regards,
>
More information about the ffmpeg-devel
mailing list