Commit 50b86893 authored by mstorsjo's avatar mstorsjo

Make RTSP use the generic http authentication code

Still hardcoded to use Basic auth, without parsing the reply headers


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@22676 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 1873543e
...@@ -215,8 +215,8 @@ OBJS-$(CONFIG_RTP_MUXER) += rtp.o \ ...@@ -215,8 +215,8 @@ OBJS-$(CONFIG_RTP_MUXER) += rtp.o \
rtpenc.o \ rtpenc.o \
rtpenc_h264.o \ rtpenc_h264.o \
avc.o avc.o
OBJS-$(CONFIG_RTSP_DEMUXER) += rtsp.o OBJS-$(CONFIG_RTSP_DEMUXER) += rtsp.o httpauth.o
OBJS-$(CONFIG_RTSP_MUXER) += rtsp.o rtspenc.o OBJS-$(CONFIG_RTSP_MUXER) += rtsp.o rtspenc.o httpauth.o
OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o \ OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o \
rdt.o \ rdt.o \
rtp.o \ rtp.o \
......
...@@ -612,7 +612,6 @@ void ff_rtsp_close_streams(AVFormatContext *s) ...@@ -612,7 +612,6 @@ void ff_rtsp_close_streams(AVFormatContext *s)
av_close_input_stream (rt->asf_ctx); av_close_input_stream (rt->asf_ctx);
rt->asf_ctx = NULL; rt->asf_ctx = NULL;
} }
av_freep(&rt->auth_b64);
} }
static void *rtsp_rtp_mux_open(AVFormatContext *s, AVStream *st, static void *rtsp_rtp_mux_open(AVFormatContext *s, AVStream *st,
...@@ -1013,10 +1012,13 @@ void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s, ...@@ -1013,10 +1012,13 @@ void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,
snprintf(buf1, sizeof(buf1), "Session: %s\r\n", rt->session_id); snprintf(buf1, sizeof(buf1), "Session: %s\r\n", rt->session_id);
av_strlcat(buf, buf1, sizeof(buf)); av_strlcat(buf, buf1, sizeof(buf));
} }
if (rt->auth_b64) if (rt->auth[0]) {
av_strlcatf(buf, sizeof(buf), char *str = ff_http_auth_create_response(&rt->auth_state,
"Authorization: Basic %s\r\n", rt->auth, url, method);
rt->auth_b64); if (str)
av_strlcat(buf, str, sizeof(buf));
av_free(str);
}
if (send_content_length > 0 && send_content) if (send_content_length > 0 && send_content)
av_strlcatf(buf, sizeof(buf), "Content-Length: %d\r\n", send_content_length); av_strlcatf(buf, sizeof(buf), "Content-Length: %d\r\n", send_content_length);
av_strlcat(buf, "\r\n", sizeof(buf)); av_strlcat(buf, "\r\n", sizeof(buf));
...@@ -1437,14 +1439,8 @@ redirect: ...@@ -1437,14 +1439,8 @@ redirect:
ff_url_split(NULL, 0, auth, sizeof(auth), ff_url_split(NULL, 0, auth, sizeof(auth),
host, sizeof(host), &port, path, sizeof(path), s->filename); host, sizeof(host), &port, path, sizeof(path), s->filename);
if (*auth) { if (*auth) {
int auth_len = strlen(auth), b64_len = ((auth_len + 2) / 3) * 4 + 1; av_strlcpy(rt->auth, auth, sizeof(rt->auth));
rt->auth_state.auth_type = HTTP_AUTH_BASIC;
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) if (port < 0)
port = RTSP_DEFAULT_PORT; port = RTSP_DEFAULT_PORT;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "rtspcodes.h" #include "rtspcodes.h"
#include "rtpdec.h" #include "rtpdec.h"
#include "network.h" #include "network.h"
#include "httpauth.h"
/** /**
* Network layer over which RTP/etc packet data will be transported. * Network layer over which RTP/etc packet data will be transported.
...@@ -232,8 +233,11 @@ typedef struct RTSPState { ...@@ -232,8 +233,11 @@ typedef struct RTSPState {
* of RTSPMessageHeader->real_challenge */ * of RTSPMessageHeader->real_challenge */
enum RTSPServerType server_type; enum RTSPServerType server_type;
/** base64-encoded authorization lines (username:password) */ /** plaintext authorization line (username:password) */
char *auth_b64; char auth[128];
/** authentication state */
HTTPAuthState auth_state;
/** The last reply of the server to a RTSP command */ /** The last reply of the server to a RTSP command */
char last_reply[2048]; /* XXX: allocate ? */ char last_reply[2048]; /* XXX: allocate ? */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment