[FFmpeg-cvslog] r22226 - in trunk/libavformat: gopher.c http.c rtmpproto.c rtpproto.c rtsp.c rtspenc.c
mstorsjo
subversion
Fri Mar 5 23:35:21 CET 2010
Author: mstorsjo
Date: Fri Mar 5 23:35:21 2010
New Revision: 22226
Log:
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.
Modified:
trunk/libavformat/gopher.c
trunk/libavformat/http.c
trunk/libavformat/rtmpproto.c
trunk/libavformat/rtpproto.c
trunk/libavformat/rtsp.c
trunk/libavformat/rtspenc.c
Modified: trunk/libavformat/gopher.c
==============================================================================
--- trunk/libavformat/gopher.c Fri Mar 5 23:31:45 2010 (r22225)
+++ trunk/libavformat/gopher.c Fri Mar 5 23:35:21 2010 (r22226)
@@ -95,7 +95,7 @@ static int gopher_open(URLContext *h, co
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);
Modified: trunk/libavformat/http.c
==============================================================================
--- trunk/libavformat/http.c Fri Mar 5 23:31:45 2010 (r22225)
+++ trunk/libavformat/http.c Fri Mar 5 23:35:21 2010 (r22226)
@@ -71,11 +71,7 @@ static int http_open_cnx(URLContext *h)
/* 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 @@ static int http_open_cnx(URLContext *h)
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;
Modified: trunk/libavformat/rtmpproto.c
==============================================================================
--- trunk/libavformat/rtmpproto.c Fri Mar 5 23:31:45 2010 (r22225)
+++ trunk/libavformat/rtmpproto.c Fri Mar 5 23:35:21 2010 (r22226)
@@ -113,7 +113,7 @@ static void gen_connect(URLContext *s, R
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 @@ static int rtmp_open(URLContext *s, cons
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);
Modified: trunk/libavformat/rtpproto.c
==============================================================================
--- trunk/libavformat/rtpproto.c Fri Mar 5 23:31:45 2010 (r22225)
+++ trunk/libavformat/rtpproto.c Fri Mar 5 23:35:21 2010 (r22226)
@@ -67,10 +67,10 @@ int rtp_set_remote_url(URLContext *h, co
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 @@ static void build_udp_url(char *buf, int
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)
Modified: trunk/libavformat/rtsp.c
==============================================================================
--- trunk/libavformat/rtsp.c Fri Mar 5 23:31:45 2010 (r22225)
+++ trunk/libavformat/rtsp.c Fri Mar 5 23:35:21 2010 (r22226)
@@ -1090,8 +1090,8 @@ static int make_setup_request(AVFormatCo
/* 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 @@ static int make_setup_request(AVFormatCo
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 @@ static int make_setup_request(AVFormatCo
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 @@ int ff_rtsp_connect(AVFormatContext *s)
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 @@ redirect:
}
/* 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 @@ redirect:
s->filename);
goto redirect;
}
+ ff_network_close();
return err;
}
#endif
@@ -1886,6 +1890,7 @@ static int rtsp_read_close(AVFormatConte
ff_rtsp_close_streams(s);
url_close(rt->rtsp_hd);
+ ff_network_close();
return 0;
}
@@ -1933,6 +1938,9 @@ static int sdp_read_header(AVFormatConte
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 @@ static int sdp_read_header(AVFormatConte
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 @@ static int sdp_read_header(AVFormatConte
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;
}
Modified: trunk/libavformat/rtspenc.c
==============================================================================
--- trunk/libavformat/rtspenc.c Fri Mar 5 23:31:45 2010 (r22225)
+++ trunk/libavformat/rtspenc.c Fri Mar 5 23:35:21 2010 (r22226)
@@ -116,6 +116,7 @@ static int rtsp_write_close(AVFormatCont
ff_rtsp_close_streams(s);
url_close(rt->rtsp_hd);
+ ff_network_close();
return 0;
}
More information about the ffmpeg-cvslog
mailing list