/* needed by inet_aton() */
#define _SVID_SOURCE
+#include "libavutil/base64.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "avformat.h"
snprintf(buf1, sizeof(buf1), "Session: %s\r\n", rt->session_id);
av_strlcat(buf, buf1, sizeof(buf));
}
+ if (rt->auth_b64)
+ av_strlcatf(buf, sizeof(buf),
+ "Authorization: Basic %s\r\n",
+ rt->auth_b64);
av_strlcat(buf, "\r\n", sizeof(buf));
dprintf(s, "Sending:\n%s--\n", buf);
av_close_input_stream (rt->asf_ctx);
rt->asf_ctx = NULL;
}
+ av_freep(&rt->auth_b64);
}
static int
AVFormatParameters *ap)
{
RTSPState *rt = s->priv_data;
- char host[1024], path[1024], tcpname[1024], cmd[2048], *option_list, *option;
+ char host[1024], path[1024], tcpname[1024], cmd[2048], auth[128], *option_list, *option;
URLContext *rtsp_hd;
int port, ret, err;
RTSPMessageHeader reply1, *reply = &reply1;
char real_challenge[64];
/* extract hostname and port */
- url_split(NULL, 0, NULL, 0,
+ url_split(NULL, 0, auth, sizeof(auth),
host, sizeof(host), &port, path, sizeof(path), s->filename);
+ if (*auth) {
+ int auth_len = strlen(auth), b64_len = ((auth_len + 2) / 3) * 4 + 1;
+
+ if (!(rt->auth_b64 = av_malloc(b64_len)))
+ return AVERROR(ENOMEM);
+ if (!av_base64_encode(rt->auth_b64, b64_len, auth, auth_len)) {
+ err = AVERROR(EINVAL);
+ goto fail;
+ }
+ }
if (port < 0)
port = RTSP_DEFAULT_PORT;
/* open the tcp connexion */
snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port);
- if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0)
- return AVERROR(EIO);
+ if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) {
+ err = AVERROR(EIO);
+ goto fail;
+ }
rt->rtsp_hd = rtsp_hd;
rt->seq = 0;
rtsp_close_streams(rt);
av_freep(&content);
url_close(rt->rtsp_hd);
+ av_freep(&rt->auth_b64);
return err;
}