[PATCH] Make ff_url_split() and ff_url_join() public.

Stefano Sabatini stefano.sabatini-lala
Sat May 22 21:55:08 CEST 2010


Both functions are never referenced outside from libavformat, so it
should be safe to remove them. ff_url_split() is retained though, as
it was used by ffserver, this avoids to break ABI compatibility with
it.

The new public functions are named av_url_split() and av_url_join().
---
 ffserver.c              |    6 ++--
 libavformat/avformat.h  |   49 +++++++++++++++++++++++++++++++++++++++++++
 libavformat/gopher.c    |    4 +-
 libavformat/http.c      |    8 +++---
 libavformat/internal.h  |   53 -----------------------------------------------
 libavformat/rtmpproto.c |    6 ++--
 libavformat/rtpproto.c  |   10 ++++----
 libavformat/rtsp.c      |   18 ++++++++--------
 libavformat/sdp.c       |    2 +-
 libavformat/tcp.c       |    2 +-
 libavformat/udp.c       |    6 ++--
 libavformat/utils.c     |   30 +++++++++++++++++++++++++-
 12 files changed, 109 insertions(+), 85 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index 3cdcd88..9b5316f 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -2978,7 +2978,7 @@ static void rtsp_cmd_describe(HTTPContext *c, const char *url)
     struct sockaddr_in my_addr;
 
     /* find which url is asked */
-    ff_url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
+    av_url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
     path = path1;
     if (*path == '/')
         path++;
@@ -3053,7 +3053,7 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url,
     RTSPActionServerSetup setup;
 
     /* find which url is asked */
-    ff_url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
+    av_url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
     path = path1;
     if (*path == '/')
         path++;
@@ -3196,7 +3196,7 @@ static HTTPContext *find_rtp_session_with_url(const char *url,
         return NULL;
 
     /* find which url is asked */
-    ff_url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
+    av_url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
     path = path1;
     if (*path == '/')
         path++;
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 91d6911..17cac71 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1185,6 +1185,55 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index,
 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
 
 /**
+ * Splits an URL string into components. To reassemble components back into
+ * a URL, use av_url_join() instead of using snprintf() directly.
+ *
+ * The pointers to buffers for storing individual components may be null,
+ * in order to ignore that component. Buffers for components not found are
+ * set to empty strings. If the port is not found, it is set to a negative
+ * value.
+ *
+ * @param proto the buffer for the protocol
+ * @param proto_size the size of the proto buffer
+ * @param authorization the buffer for the authorization
+ * @param authorization_size the size of the authorization buffer
+ * @param hostname the buffer for the host name
+ * @param hostname_size the size of the hostname buffer
+ * @param port_ptr a pointer to store the port number in
+ * @param path the buffer for the path
+ * @param path_size the size of the path buffer
+ * @param url the URL to split
+ */
+void av_url_split(char *proto,         int proto_size,
+                  char *authorization, int authorization_size,
+                  char *hostname,      int hostname_size,
+                  int *port_ptr,
+                  char *path,          int path_size,
+                  const char *url);
+
+/**
+ * Assembles an URL string from components. This is the reverse operation
+ * of av_url_split().
+ *
+ * Note, this requires networking to be initialized, so the caller
+ * must ensure ff_network_init() has been called.
+ *
+ * @param buf the buffer to fill with the url
+ * @param buf_size the size in bytes of the buf buffer
+ * @param proto the protocol identifier. If null, the separator
+ *              after the identifier is left out, too.
+ * @param authorization an optional authorization string, may be null
+ * @param hostname the host name string
+ * @param port the port number, left out from the string if negative
+ * @param fmt a generic format string for everything to add after the
+ *            host/port, may be null
+ * @return the number of characters written to the destination buffer
+ */
+int av_url_join(char *buf, int buf_size, const char *proto,
+                const char *authorization, const char *hostname,
+                int port, const char *fmt, ...);
+
+/**
  * Allocates the stream private data and writes the stream header to an
  * output media file.
  *
diff --git a/libavformat/gopher.c b/libavformat/gopher.c
index f5bb4a3..563a0d7 100644
--- a/libavformat/gopher.c
+++ b/libavformat/gopher.c
@@ -90,13 +90,13 @@ static int gopher_open(URLContext *h, const char *uri, int flags)
     h->priv_data = s;
 
     /* needed in any case to build the host string */
-    ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
+    av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
                  path, sizeof(path), uri);
 
     if (port < 0)
         port = 70;
 
-    ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
+    av_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
 
     s->hd = NULL;
     err = url_open(&s->hd, buf, URL_RDWR);
diff --git a/libavformat/http.c b/libavformat/http.c
index e697578..82234e0 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -72,12 +72,12 @@ static int http_open_cnx(URLContext *h)
     /* fill the dest addr */
  redo:
     /* needed in any case to build the host string */
-    ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
+    av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
                  path1, sizeof(path1), s->location);
-    ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
+    av_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
 
     if (use_proxy) {
-        ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
+        av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
                      NULL, 0, proxy_path);
         path = s->location;
     } else {
@@ -89,7 +89,7 @@ static int http_open_cnx(URLContext *h)
     if (port < 0)
         port = 80;
 
-    ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
+    av_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
     err = url_open(&hd, buf, URL_RDWR);
     if (err < 0)
         goto fail;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 358959c..f43c205 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -90,59 +90,6 @@ int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt,
                           unsigned int offset, unsigned int max_probe_size);
 
 /**
- * Splits a URL string into components. To reassemble components back into
- * a URL, use ff_url_join instead of using snprintf directly.
- *
- * The pointers to buffers for storing individual components may be null,
- * in order to ignore that component. Buffers for components not found are
- * set to empty strings. If the port isn't found, it is set to a negative
- * value.
- *
- * @see ff_url_join
- *
- * @param proto the buffer for the protocol
- * @param proto_size the size of the proto buffer
- * @param authorization the buffer for the authorization
- * @param authorization_size the size of the authorization buffer
- * @param hostname the buffer for the host name
- * @param hostname_size the size of the hostname buffer
- * @param port_ptr a pointer to store the port number in
- * @param path the buffer for the path
- * @param path_size the size of the path buffer
- * @param url the URL to split
- */
-void ff_url_split(char *proto, int proto_size,
-                  char *authorization, int authorization_size,
-                  char *hostname, int hostname_size,
-                  int *port_ptr,
-                  char *path, int path_size,
-                  const char *url);
-
-/**
- * Assembles a URL string from components. This is the reverse operation
- * of ff_url_split.
- *
- * Note, this requires networking to be initialized, so the caller must
- * ensure ff_network_init has been called.
- *
- * @see ff_url_split
- *
- * @param str the buffer to fill with the url
- * @param size the size of the str buffer
- * @param proto the protocol identifier, if null, the separator
- *              after the identifier is left out, too
- * @param authorization an optional authorization string, may be null
- * @param hostname the host name string
- * @param port the port number, left out from the string if negative
- * @param fmt a generic format string for everything to add after the
- *            host/port, may be null
- * @return the number of characters written to the destination buffer
- */
-int ff_url_join(char *str, int size, const char *proto,
-                const char *authorization, const char *hostname,
-                int port, const char *fmt, ...);
-
-/**
  * Appends the media-specific SDP fragment for the media stream c
  * to the buffer buff.
  *
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 4edbffa..94ae6b9 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -114,7 +114,7 @@ static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto,
     ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 4096);
     p = pkt.data;
 
-    ff_url_join(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app);
+    av_url_join(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app);
     ff_amf_write_string(&p, "connect");
     ff_amf_write_number(&p, 1.0);
     ff_amf_write_object_start(&p);
@@ -813,12 +813,12 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
     s->priv_data = rt;
     rt->is_input = !(flags & URL_WRONLY);
 
-    ff_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
+    av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
                  path, sizeof(path), s->filename);
 
     if (port < 0)
         port = RTMP_DEFAULT_PORT;
-    ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
+    av_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
 
     if (url_open(&rt->stream, buf, URL_RDWR) < 0) {
         av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf);
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 754908c..4472fe9 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -66,13 +66,13 @@ int rtp_set_remote_url(URLContext *h, const char *uri)
     char buf[1024];
     char path[1024];
 
-    ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
+    av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
                  path, sizeof(path), uri);
 
-    ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path);
+    av_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path);
     udp_set_remote_url(s->rtp_hd, buf);
 
-    ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port + 1, "%s", path);
+    av_url_join(buf, sizeof(buf), "udp", NULL, hostname, port + 1, "%s", path);
     udp_set_remote_url(s->rtcp_hd, buf);
     return 0;
 }
@@ -103,7 +103,7 @@ static void build_udp_url(char *buf, int buf_size,
                           int local_port, int ttl,
                           int max_packet_size)
 {
-    ff_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL);
+    av_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL);
     if (local_port >= 0)
         url_add_option(buf, buf_size, "localport=%d", local_port);
     if (ttl >= 0)
@@ -146,7 +146,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
         return AVERROR(ENOMEM);
     h->priv_data = s;
 
-    ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
+    av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
                  path, sizeof(path), uri);
     /* extract parameters */
     ttl = -1;
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 6dbd796..e248ec5 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -450,7 +450,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
             rtsp_st = st->priv_data;
 
             /* XXX: may need to add full url resolution */
-            ff_url_split(proto, sizeof(proto), NULL, 0, NULL, 0,
+            av_url_split(proto, sizeof(proto), NULL, 0, NULL, 0,
                          NULL, NULL, 0, p);
             if (proto[0] == '\0') {
                 /* relative control URL */
@@ -1139,7 +1139,7 @@ static int make_setup_request(AVFormatContext *s, const char *host, int port,
             /* first try in specified port range */
             if (RTSP_RTP_PORT_MIN != 0) {
                 while (j <= RTSP_RTP_PORT_MAX) {
-                    ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,
+                    av_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,
                                 "?localport=%d", j);
                     /* we will use two ports per rtp stream (rtp and rtcp) */
                     j += 2;
@@ -1249,7 +1249,7 @@ static int make_setup_request(AVFormatContext *s, const char *host, int port,
             char url[1024];
 
             /* XXX: also use address if specified */
-            ff_url_join(url, sizeof(url), "rtp", NULL, host,
+            av_url_join(url, sizeof(url), "rtp", NULL, host,
                         reply->transports[0].server_port_min, NULL);
             if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) &&
                 rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {
@@ -1278,7 +1278,7 @@ static int make_setup_request(AVFormatContext *s, const char *host, int port,
                 port      = rtsp_st->sdp_port;
                 ttl       = rtsp_st->sdp_ttl;
             }
-            ff_url_join(url, sizeof(url), "rtp", NULL, inet_ntoa(in),
+            av_url_join(url, sizeof(url), "rtp", NULL, inet_ntoa(in),
                         port, "?ttl=%d", ttl);
             if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
                 err = AVERROR_INVALIDDATA;
@@ -1417,7 +1417,7 @@ static int rtsp_setup_output_streams(AVFormatContext *s, const char *addr)
      * flexible SDP creation interface.
      */
     sdp_ctx = *s;
-    ff_url_join(sdp_ctx.filename, sizeof(sdp_ctx.filename),
+    av_url_join(sdp_ctx.filename, sizeof(sdp_ctx.filename),
                 "rtsp", NULL, addr, -1, NULL);
     ctx_array[0] = &sdp_ctx;
     if (avf_sdp_create(ctx_array, 1, sdp, 8192)) {
@@ -1471,7 +1471,7 @@ int ff_rtsp_connect(AVFormatContext *s)
         return AVERROR(EIO);
 redirect:
     /* extract hostname and port */
-    ff_url_split(NULL, 0, auth, sizeof(auth),
+    av_url_split(NULL, 0, auth, sizeof(auth),
                  host, sizeof(host), &port, path, sizeof(path), s->filename);
     if (*auth) {
         av_strlcpy(rt->auth, auth, sizeof(rt->auth));
@@ -1529,11 +1529,11 @@ redirect:
     /* Construct the URI used in request; this is similar to s->filename,
      * but with authentication credentials removed and RTSP specific options
      * stripped out. */
-    ff_url_join(rt->control_uri, sizeof(rt->control_uri), "rtsp", NULL,
+    av_url_join(rt->control_uri, sizeof(rt->control_uri), "rtsp", NULL,
                 host, port, "%s", path);
 
     /* open the tcp connexion */
-    ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
+    av_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
     if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) {
         err = AVERROR(EIO);
         goto fail;
@@ -2055,7 +2055,7 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap)
     for (i = 0; i < rt->nb_rtsp_streams; i++) {
         rtsp_st = rt->rtsp_streams[i];
 
-        ff_url_join(url, sizeof(url), "rtp", NULL,
+        av_url_join(url, sizeof(url), "rtp", NULL,
                     inet_ntoa(rtsp_st->sdp_ip), rtsp_st->sdp_port,
                     "?localport=%d&ttl=%d", rtsp_st->sdp_port,
                     rtsp_st->sdp_ttl);
diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index 6bf05db..5af6908 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -109,7 +109,7 @@ static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url)
     const char *p;
     char proto[32];
 
-    ff_url_split(proto, sizeof(proto), NULL, 0, dest_addr, size, &port, NULL, 0, url);
+    av_url_split(proto, sizeof(proto), NULL, 0, dest_addr, size, &port, NULL, 0, url);
 
     *ttl = 0;
 
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 79cabdf..db8e828 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -45,7 +45,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
     char hostname[1024],proto[1024],path[1024];
     char portstr[10];
 
-    ff_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
+    av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
         &port, path, sizeof(path), uri);
     if (strcmp(proto,"tcp") || port <= 0 || port >= 65536)
         return AVERROR(EINVAL);
diff --git a/libavformat/udp.c b/libavformat/udp.c
index a11f4c3..140306d 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -266,7 +266,7 @@ int udp_set_remote_url(URLContext *h, const char *uri)
     char hostname[256];
     int port;
 
-    ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
+    av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
 
     /* set the destination address */
     s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port);
@@ -347,9 +347,9 @@ static int udp_open(URLContext *h, const char *uri, int flags)
     }
 
     /* fill the dest addr */
-    ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
+    av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
 
-    /* XXX: fix ff_url_split */
+    /* XXX: fix av_url_split */
     if (hostname[0] == '\0' || hostname[0] == '?') {
         /* only accepts null hostname if input */
         if (flags & URL_WRONLY)
diff --git a/libavformat/utils.c b/libavformat/utils.c
index e5a6ce1..85e4e91 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3450,6 +3450,18 @@ void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload)
     pkt_dump_internal(avcl, NULL, level, pkt, dump_payload);
 }
 
+#if LIBAVFORMAT_VERSION_MAJOR < 53
+/**
+ * @deprecated Use av_url_split() instead.
+ */
+attribute_deprecated
+void ff_url_split(char *proto, int proto_size,
+                  char *authorization, int authorization_size,
+                  char *hostname, int hostname_size,
+                  int *port_ptr,
+                  char *path, int path_size,
+                  const char *url);
+
 void ff_url_split(char *proto, int proto_size,
                   char *authorization, int authorization_size,
                   char *hostname, int hostname_size,
@@ -3457,6 +3469,22 @@ void ff_url_split(char *proto, int proto_size,
                   char *path, int path_size,
                   const char *url)
 {
+    av_url_split(proto, proto_size,
+                 authorization, authorization_size,
+                 hostname, hostname_size,
+                 port_ptr,
+                 path, path_size,
+                 url);
+}
+#endif
+
+void av_url_split(char *proto, int proto_size,
+                  char *authorization, int authorization_size,
+                  char *hostname, int hostname_size,
+                  int *port_ptr,
+                  char *path, int path_size,
+                  const char *url)
+{
     const char *p, *ls, *at, *col, *brk;
 
     if (port_ptr)               *port_ptr = -1;
@@ -3547,7 +3575,7 @@ void av_set_pts_info(AVStream *s, int pts_wrap_bits,
         s->time_base.num= s->time_base.den= 0;
 }
 
-int ff_url_join(char *str, int size, const char *proto,
+int av_url_join(char *str, int size, const char *proto,
                 const char *authorization, const char *hostname,
                 int port, const char *fmt, ...)
 {
-- 
1.7.1


--61jdw2sOBCFtR2d/--



More information about the ffmpeg-devel mailing list