[FFmpeg-devel] [PATCH] Handling special characters in a URL.

Stefano Sabatini stefasab at gmail.com
Wed Feb 27 15:08:50 CET 2013


On date Tuesday 2013-02-26 08:07:46 +0530, Senthilnathan Maadasamy encoded:
> On Sat, Feb 23, 2013 at 12:14 AM, Stefano Sabatini <stefasab at gmail.com>wrote:
[...]
> From 4cce32a39623f920b68ea071710a599d9e92324f Mon Sep 17 00:00:00 2001
> From: Senthilnathan M <senthilnathan.maadasamy at gmail.com>
> Date: Sun, 10 Feb 2013 23:08:52 +0530
> Subject: [PATCH] Support for special characters in URL
> 
> Signed-off-by: Senthilnathan M <senthilnathan.maadasamy at gmail.com>
> ---
>  libavformat/utils.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 9bd2d0c..a3f69a3 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -3767,6 +3767,49 @@ void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
>      pkt_dump_internal(avcl, NULL, level, pkt, dump_payload, st->time_base);
>  }
>  
> +/**
> + * Percent encode part of an URL string according to RFC 3986.
> + *
> + * @param component portion of an URL (e.g. protocol, hostname, path) to
> + *            percent-encode.  This will be percent-encoded in place.
> + * @param allowed string containing the allowed characters which must not be
> + *                encoded. It may be NULL if there are no such characters.
> + * @param component_size size in bytes of the component buffer
> + * @return 0 on success, -1 on error
> + */
> +static int percent_encode_url(char *component,
> +                                    const char *allowed, size_t component_size)
> +{
> +    char enc[MAX_URL_SIZE], c;
> +    int enc_len = 0;
> +    char *src = component;
> +
> +    while (c = *src) {
> +        if (isalnum(c) || strchr("-._~%", c)
> +            || (allowed && strchr(allowed, c))) {
> +            if (enc_len+1 < MAX_URL_SIZE) enc[enc_len] = c;
> +            else break;
> +            enc_len++;
> +        } else {
> +            if (enc_len+3 < MAX_URL_SIZE) snprintf(&enc[enc_len], 4, "%%%02x", c);
> +            else break;
> +            enc_len += 3;
> +        }
> +        src++;
> +    }
> +
> +    enc[enc_len++] = '\0';
> +    if (enc_len <= component_size) {
> +        av_strlcpy(component, enc, component_size);
> +        return 0;
> +    } else {
> +        av_log(NULL, AV_LOG_ERROR,
> +            "Skipping percent-encoding for string '%s' since buffer is too small\n",
> +            component);
> +        return -1;
> +    }
> +}
> +
>  void av_url_split(char *proto, int proto_size,
>                    char *authorization, int authorization_size,
>                    char *hostname, int hostname_size,
> @@ -3830,6 +3873,9 @@ void av_url_split(char *proto, int proto_size,
>              av_strlcpy(hostname, p,
>                         FFMIN(ls + 1 - p, hostname_size));
>      }
> +
> +    percent_encode_url(hostname, NULL, hostname_size);
> +    percent_encode_url(path, "/?", path_size);

LGTM and thanks.

There are a few align issues but no need to send another patch. I'll
apply it soon if there are no comments from other devs.
-- 
FFmpeg = Fanciful & Fierce MultiPurpose Evangelical Gangster


More information about the ffmpeg-devel mailing list