diff --git a/ffserver.c b/ffserver.c index a2956d3df7058ecdcf901dd70e6be421fbd0e265..20ba890e4dde5c695dea096b5afe157c9c8a6e46 100644 --- a/ffserver.c +++ b/ffserver.c @@ -2135,10 +2135,10 @@ static int open_input_stream(HTTPContext *c, const char *info) strcpy(input_filename, c->stream->feed->feed_filename); buf_size = FFM_PACKET_SIZE; /* compute position (absolute time) */ - if (find_info_tag(buf, sizeof(buf), "date", info)) { + if (av_find_info_tag(buf, sizeof(buf), "date", info)) { if ((ret = av_parse_time(&stream_pos, buf, 0)) < 0) return ret; - } else if (find_info_tag(buf, sizeof(buf), "buffer", info)) { + } else if (av_find_info_tag(buf, sizeof(buf), "buffer", info)) { int prebuffer = strtol(buf, 0, 10); stream_pos = av_gettime() - prebuffer * (int64_t)1000000; } else @@ -2147,7 +2147,7 @@ static int open_input_stream(HTTPContext *c, const char *info) strcpy(input_filename, c->stream->feed_filename); buf_size = 0; /* compute position (relative time) */ - if (find_info_tag(buf, sizeof(buf), "date", info)) { + if (av_find_info_tag(buf, sizeof(buf), "date", info)) { if ((ret = av_parse_time(&stream_pos, buf, 1)) < 0) return ret; } else diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 7d69f510b00370b11333da95b8711000bc914301..8511a0366ee5d6d8c168028ae640f753b4576e2f 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1501,13 +1501,12 @@ int64_t ffm_read_write_index(int fd); int ffm_write_write_index(int fd, int64_t pos); void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size); +#if FF_API_FIND_INFO_TAG /** - * Attempt to find a specific tag in a URL. - * - * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. - * Return 1 if found. + * @deprecated use av_find_info_tag in libavutil instead. */ -int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); +attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); +#endif /** * Return in 'buf' the path with '%d' replaced by a number. diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index aa2cc37776d24034304520b0f3d5454a5b8343a4..dd5bc71c0e3cede3d08a66302bbf952b0d202630 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -24,6 +24,7 @@ * RTP protocol */ +#include "libavutil/parseutils.h" #include "libavutil/avstring.h" #include "avformat.h" #include "rtpdec.h" @@ -161,25 +162,25 @@ static int rtp_open(URLContext *h, const char *uri, int flags) p = strchr(uri, '?'); if (p) { - if (find_info_tag(buf, sizeof(buf), "ttl", p)) { + if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) { ttl = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "rtcpport", p)) { + if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) { rtcp_port = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "localport", p)) { + if (av_find_info_tag(buf, sizeof(buf), "localport", p)) { local_rtp_port = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "localrtpport", p)) { + if (av_find_info_tag(buf, sizeof(buf), "localrtpport", p)) { local_rtp_port = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "localrtcpport", p)) { + if (av_find_info_tag(buf, sizeof(buf), "localrtcpport", p)) { local_rtcp_port = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) { + if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) { max_packet_size = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "connect", p)) { + if (av_find_info_tag(buf, sizeof(buf), "connect", p)) { connect = strtol(buf, NULL, 10); } } diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c index 9bbacef6801c409a55b4076892399a9f3140f783..91c1f628c757318e5fdc597cecbbfafcf27ab355 100644 --- a/libavformat/sapenc.c +++ b/libavformat/sapenc.c @@ -20,6 +20,7 @@ */ #include "avformat.h" +#include "libavutil/parseutils.h" #include "libavutil/random_seed.h" #include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" @@ -87,16 +88,16 @@ static int sap_write_header(AVFormatContext *s) option_list = strrchr(path, '?'); if (option_list) { char buf[50]; - if (find_info_tag(buf, sizeof(buf), "announce_port", option_list)) { + if (av_find_info_tag(buf, sizeof(buf), "announce_port", option_list)) { port = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "same_port", option_list)) { + if (av_find_info_tag(buf, sizeof(buf), "same_port", option_list)) { same_port = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "ttl", option_list)) { + if (av_find_info_tag(buf, sizeof(buf), "ttl", option_list)) { ttl = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) { + if (av_find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) { av_strlcpy(announce_addr, buf, sizeof(announce_addr)); } } diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 872e76c5aee89ee58cbecb70b2450ac64aa1ec36..2a8821815a2d462e8ed3b157025774ea7d0c1844 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -21,6 +21,7 @@ #include #include "libavutil/avstring.h" #include "libavutil/base64.h" +#include "libavutil/parseutils.h" #include "libavcodec/xiph.h" #include "avformat.h" #include "internal.h" @@ -136,7 +137,7 @@ static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url) if (p) { char buff[64]; - if (find_info_tag(buff, sizeof(buff), "ttl", p)) { + if (av_find_info_tag(buff, sizeof(buff), "ttl", p)) { *ttl = strtol(buff, NULL, 10); } else { *ttl = 5; diff --git a/libavformat/udp.c b/libavformat/udp.c index 4c4db2a5891af5cd21e9b6513b3f47a433041207..6c1b37b59d7c8dc2042371571f361a19e0716fa1 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -27,6 +27,7 @@ #define _BSD_SOURCE /* Needed for using struct ip_mreq with recent glibc */ #define _DARWIN_C_SOURCE /* Needed for using IP_MULTICAST_TTL on OS X */ #include "avformat.h" +#include "libavutil/parseutils.h" #include #include "internal.h" #include "network.h" @@ -259,7 +260,7 @@ int udp_set_remote_url(URLContext *h, const char *uri) s->is_multicast = ff_is_multicast_address((struct sockaddr*) &s->dest_addr); p = strchr(uri, '?'); if (p) { - if (find_info_tag(buf, sizeof(buf), "connect", p)) { + if (av_find_info_tag(buf, sizeof(buf), "connect", p)) { int was_connected = s->is_connected; s->is_connected = strtol(buf, NULL, 10); if (s->is_connected && !was_connected) { @@ -330,7 +331,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) p = strchr(uri, '?'); if (p) { - if (find_info_tag(buf, sizeof(buf), "reuse", p)) { + if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) { const char *endptr=NULL; s->reuse_socket = strtol(buf, &endptr, 10); /* assume if no digits were found it is a request to enable it */ @@ -338,19 +339,19 @@ static int udp_open(URLContext *h, const char *uri, int flags) s->reuse_socket = 1; reuse_specified = 1; } - if (find_info_tag(buf, sizeof(buf), "ttl", p)) { + if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) { s->ttl = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "localport", p)) { + if (av_find_info_tag(buf, sizeof(buf), "localport", p)) { s->local_port = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) { + if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) { h->max_packet_size = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) { + if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) { s->buffer_size = strtol(buf, NULL, 10); } - if (find_info_tag(buf, sizeof(buf), "connect", p)) { + if (av_find_info_tag(buf, sizeof(buf), "connect", p)) { s->is_connected = strtol(buf, NULL, 10); } } diff --git a/libavformat/utils.c b/libavformat/utils.c index b9ec7fd0af408b13e7d82ace23ddbcfd32966221..3d58478591fa46dfe63fa29fdb496aec84f34051 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3391,44 +3391,14 @@ int64_t parse_date(const char *timestr, int duration) } #endif +#if FF_API_FIND_INFO_TAG +#include "libavutil/parseutils.h" + int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) { - const char *p; - char tag[128], *q; - - p = info; - if (*p == '?') - p++; - for(;;) { - q = tag; - while (*p != '\0' && *p != '=' && *p != '&') { - if ((q - tag) < sizeof(tag) - 1) - *q++ = *p; - p++; - } - *q = '\0'; - q = arg; - if (*p == '=') { - p++; - while (*p != '&' && *p != '\0') { - if ((q - arg) < arg_size - 1) { - if (*p == '+') - *q++ = ' '; - else - *q++ = *p; - } - p++; - } - } - *q = '\0'; - if (!strcmp(tag, tag1)) - return 1; - if (*p != '&') - break; - p++; - } - return 0; + return av_find_info_tag(arg, arg_size, tag1, info); } +#endif int av_get_frame_filename(char *buf, int buf_size, const char *path, int number) diff --git a/libavformat/version.h b/libavformat/version.h index 3663ec55b9046051e6db59ce7c8f16e0d559bec1..b4add73532349ad4ec77beb3218e3bf2a3938864 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -98,5 +98,8 @@ #ifndef FF_API_PARSE_DATE #define FF_API_PARSE_DATE (LIBAVFORMAT_VERSION_MAJOR < 54) #endif +#ifndef FF_API_FIND_INFO_TAG +#define FF_API_FIND_INFO_TAG (LIBAVFORMAT_VERSION_MAJOR < 54) +#endif #endif //AVFORMAT_VERSION_H diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 8e09dade62af34e7382cc1ad1af827e07bcca35c..d67d31bffe5942b1c7caa4438eb2a115599fe0ea 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -608,6 +608,45 @@ int av_parse_time(int64_t *timeval, const char *datestr, int duration) return 0; } +int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) +{ + const char *p; + char tag[128], *q; + + p = info; + if (*p == '?') + p++; + for(;;) { + q = tag; + while (*p != '\0' && *p != '=' && *p != '&') { + if ((q - tag) < sizeof(tag) - 1) + *q++ = *p; + p++; + } + *q = '\0'; + q = arg; + if (*p == '=') { + p++; + while (*p != '&' && *p != '\0') { + if ((q - arg) < arg_size - 1) { + if (*p == '+') + *q++ = ' '; + else + *q++ = *p; + } + p++; + } + } + *q = '\0'; + if (!strcmp(tag, tag1)) + return 1; + if (*p != '&') + break; + p++; + } + return 0; +} + #ifdef TEST #undef printf diff --git a/libavutil/parseutils.h b/libavutil/parseutils.h index 517f125a639d6479c6fb8e9f3b1c1c427e75a487..c3986af20c4bfede6aefcc7970e3c55bdedb73bb 100644 --- a/libavutil/parseutils.h +++ b/libavutil/parseutils.h @@ -106,4 +106,12 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, */ int av_parse_time(int64_t *timeval, const char *timestr, int duration); +/** + * Attempt to find a specific tag in a URL. + * + * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. + * Return 1 if found. + */ +int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); + #endif /* AVUTIL_PARSEUTILS_H */