[FFmpeg-devel] [PATCH] Handling special characters in a URL.
Stefano Sabatini
stefasab at gmail.com
Wed Feb 6 01:36:02 CET 2013
On date Monday 2013-02-04 01:25:01 +0530, Senthilnathan Maadasamy encoded:
> Implements Percent Encoding of URLs based on RFC 3986.
> Fixes Ticket 2031
>
> Signed-off-by: Senthilnathan M <senthilnathan.maadasamy at gmail.com>
> ---
> libavformat/avformat.h | 9 +++++++++
> libavformat/utils.c | 28 ++++++++++++++++++++++++++++
> 2 files changed, 37 insertions(+)
>
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 8330c6b..1b1d86e 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1963,6 +1963,15 @@ int av_index_search_timestamp(AVStream *st, int64_t
> timestamp, int flags);
> int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
> int size, int distance, int flags);
>
> +/**
> + * Percent encodes parts of a URL string based on RFC 3986. Encodes the
> + * component string in place.
Percent encode ... . Encode ...
> + *
> + * @param component portion of a URL (e.g. protocol, hostname, path)
> + * @param allowed These extra permissible characters do not get encoded
string containing the extra-permissible characters which must not be encoded
?
Also mention that it may be NULL.
> + * @param comp_size the size of the component buffer
> + */
> +void av_url_percent_encode(char *component, const char *allowed, int
> comp_size);
comp_size -> component_size (comp is usually read as "compressed")
also it could be a size_t
> /**
> * Split a URL string into components.
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 97d6558..a51b867 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -3751,6 +3751,32 @@ 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);
> }
>
> +void av_url_percent_encode(char *component, const char *allowed, int
> comp_size)
you could make use of a return value to give added information
(e.g. an error code or the size of the encoded string)
Also I dislike the fact that the function is destructive and there is
no way to check that the encoded string was truncated.
For example it could be:
size_t av_url_percent_encode(char *dst, const char *src, const char *allowed, int dst_size)
Note also that you could make the function internal so you have not to
worry about a public interface.
> +{
> + char enc[MAX_URL_SIZE], c;
> + const char *src = component;
> + int enc_len = 0;
> +
> + if (!src) return;
> +
> + while (c = *src) {
> + if (isalnum(c)
> + || c == '-' || c == '.' || c == '_' || c == '~' || c == '%'
nit: strchr("-._~%", c) ?
> + || (allowed && strchr(allowed, c))) {
> + if (enc_len+1 >= MAX_URL_SIZE) break;
> + enc[enc_len] = c;
> + enc_len++;
> + } else {
> + if (enc_len+3 >= MAX_URL_SIZE) break;
> + snprintf(&enc[enc_len], 4, "%%%02x", c);
> + enc_len+=3;
> + }
> + src++;
> + }
> + enc[enc_len] = '\0';
> + av_strlcpy(component, enc, comp_size);
> +}
> +
[...]
--
FFmpeg = Formidable & Fundamentalist Merciful Portable Evil Gymnast
More information about the ffmpeg-devel
mailing list