# HG changeset patch # User mstorsjo # Date 1267828521 0 # Node ID 7c7fe75728dd7512402fbf06db29f77ce72eb4ea # Parent dbc61b2840eb9dbca56daec098eaa5257fadde0d Use ff_url_join for assembling URLs, instead of snprintf This ensures proper escaping of numerical IPv6 addresses. The RTSP (de)muxer needs its own network initialization, since it isn't a protocol and url_open hasn't been called yet. diff -r dbc61b2840eb -r 7c7fe75728dd gopher.c --- a/gopher.c Fri Mar 05 22:31:45 2010 +0000 +++ b/gopher.c Fri Mar 05 22:35:21 2010 +0000 @@ -95,7 +95,7 @@ if (port < 0) port = 70; - snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port); + ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); s->hd = NULL; err = url_open(&s->hd, buf, URL_RDWR); diff -r dbc61b2840eb -r 7c7fe75728dd http.c --- a/http.c Fri Mar 05 22:31:45 2010 +0000 +++ b/http.c Fri Mar 05 22:35:21 2010 +0000 @@ -71,11 +71,7 @@ /* needed in any case to build the host string */ url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, path1, sizeof(path1), s->location); - if (port > 0) { - snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port); - } else { - av_strlcpy(hoststr, hostname, sizeof(hoststr)); - } + ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); if (use_proxy) { url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, @@ -90,7 +86,7 @@ if (port < 0) port = 80; - snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port); + ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); err = url_open(&hd, buf, URL_RDWR); if (err < 0) goto fail; diff -r dbc61b2840eb -r 7c7fe75728dd rtmpproto.c --- a/rtmpproto.c Fri Mar 05 22:31:45 2010 +0000 +++ b/rtmpproto.c Fri Mar 05 22:35:21 2010 +0000 @@ -113,7 +113,7 @@ ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 4096); p = pkt.data; - snprintf(tcurl, sizeof(tcurl), "%s://%s:%d/%s", proto, host, port, rt->app); + ff_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); @@ -817,7 +817,7 @@ if (port < 0) port = RTMP_DEFAULT_PORT; - snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port); + ff_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 -r dbc61b2840eb -r 7c7fe75728dd rtpproto.c --- a/rtpproto.c Fri Mar 05 22:31:45 2010 +0000 +++ b/rtpproto.c Fri Mar 05 22:35:21 2010 +0000 @@ -67,10 +67,10 @@ url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), uri); - snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port, path); + ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path); udp_set_remote_url(s->rtp_hd, buf); - snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port + 1, path); + ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port + 1, "%s", path); udp_set_remote_url(s->rtcp_hd, buf); return 0; } @@ -101,7 +101,7 @@ int local_port, int ttl, int max_packet_size) { - snprintf(buf, buf_size, "udp://%s:%d", hostname, port); + ff_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) diff -r dbc61b2840eb -r 7c7fe75728dd rtsp.c --- a/rtsp.c Fri Mar 05 22:31:45 2010 +0000 +++ b/rtsp.c Fri Mar 05 22:35:21 2010 +0000 @@ -1090,8 +1090,8 @@ /* first try in specified port range */ if (RTSP_RTP_PORT_MIN != 0) { while (j <= RTSP_RTP_PORT_MAX) { - snprintf(buf, sizeof(buf), "rtp://%s?localport=%d", - host, j); + ff_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; if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) @@ -1201,8 +1201,8 @@ char url[1024]; /* XXX: also use address if specified */ - snprintf(url, sizeof(url), "rtp://%s:%d", - host, reply->transports[0].server_port_min); + ff_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) { err = AVERROR_INVALIDDATA; @@ -1230,8 +1230,8 @@ port = rtsp_st->sdp_port; ttl = rtsp_st->sdp_ttl; } - snprintf(url, sizeof(url), "rtp://%s:%d?ttl=%d", - inet_ntoa(in), port, ttl); + ff_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; goto fail; @@ -1388,6 +1388,9 @@ RTSPMessageHeader reply1, *reply = &reply1; int lower_transport_mask = 0; char real_challenge[64]; + + if (!ff_network_init()) + return AVERROR(EIO); redirect: /* extract hostname and port */ url_split(NULL, 0, auth, sizeof(auth), @@ -1447,7 +1450,7 @@ } /* open the tcp connexion */ - snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port); + ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL); if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) { err = AVERROR(EIO); goto fail; @@ -1531,6 +1534,7 @@ s->filename); goto redirect; } + ff_network_close(); return err; } #endif @@ -1886,6 +1890,7 @@ ff_rtsp_close_streams(s); url_close(rt->rtsp_hd); + ff_network_close(); return 0; } @@ -1933,6 +1938,9 @@ char *content; char url[1024]; + if (!ff_network_init()) + return AVERROR(EIO); + /* read the whole sdp file */ /* XXX: better loading */ content = av_malloc(SDP_MAX_SIZE); @@ -1950,11 +1958,10 @@ for (i = 0; i < rt->nb_rtsp_streams; i++) { rtsp_st = rt->rtsp_streams[i]; - snprintf(url, sizeof(url), "rtp://%s:%d?localport=%d&ttl=%d", - inet_ntoa(rtsp_st->sdp_ip), - rtsp_st->sdp_port, - rtsp_st->sdp_port, - rtsp_st->sdp_ttl); + ff_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); if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { err = AVERROR_INVALIDDATA; goto fail; @@ -1965,12 +1972,14 @@ return 0; fail: ff_rtsp_close_streams(s); + ff_network_close(); return err; } static int sdp_read_close(AVFormatContext *s) { ff_rtsp_close_streams(s); + ff_network_close(); return 0; } diff -r dbc61b2840eb -r 7c7fe75728dd rtspenc.c --- a/rtspenc.c Fri Mar 05 22:31:45 2010 +0000 +++ b/rtspenc.c Fri Mar 05 22:35:21 2010 +0000 @@ -116,6 +116,7 @@ ff_rtsp_close_streams(s); url_close(rt->rtsp_hd); + ff_network_close(); return 0; }