[MPlayer-cvslog] r20543 - in trunk/stream: librtsp/rtsp_session.c librtsp/rtsp_session.h realrtsp/real.c realrtsp/real.h stream_rtsp.c
rtogni
subversion at mplayerhq.hu
Mon Oct 30 22:55:59 CET 2006
Author: rtogni
Date: Mon Oct 30 22:55:58 2006
New Revision: 20543
Modified:
trunk/stream/librtsp/rtsp_session.c
trunk/stream/librtsp/rtsp_session.h
trunk/stream/realrtsp/real.c
trunk/stream/realrtsp/real.h
trunk/stream/stream_rtsp.c
Log:
Realrtsp authentication
Modified: trunk/stream/librtsp/rtsp_session.c
==============================================================================
--- trunk/stream/librtsp/rtsp_session.c (original)
+++ trunk/stream/librtsp/rtsp_session.c Mon Oct 30 22:55:58 2006
@@ -74,7 +74,8 @@
};
//rtsp_session_t *rtsp_session_start(char *mrl) {
-rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host, int port, int *redir, uint32_t bandwidth) {
+rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host,
+ int port, int *redir, uint32_t bandwidth, char *user, char *pass) {
rtsp_session_t *rtsp_session = NULL;
char *server;
@@ -111,7 +112,7 @@
{
/* we are talking to a real server ... */
- h=real_setup_and_get_header(rtsp_session->s, bandwidth);
+ h=real_setup_and_get_header(rtsp_session->s, bandwidth, user, pass);
if (!h) {
/* got an redirect? */
if (rtsp_search_answers(rtsp_session->s, RTSP_OPTIONS_LOCATION))
Modified: trunk/stream/librtsp/rtsp_session.h
==============================================================================
--- trunk/stream/librtsp/rtsp_session.h (original)
+++ trunk/stream/librtsp/rtsp_session.h Mon Oct 30 22:55:58 2006
@@ -33,7 +33,8 @@
typedef struct rtsp_session_s rtsp_session_t;
-rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host, int port, int *redir, uint32_t bandwidth);
+rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host,
+ int port, int *redir, uint32_t bandwidth, char *user, char *pass);
int rtsp_session_read(rtsp_session_t *session, char *data, int len);
Modified: trunk/stream/realrtsp/real.c
==============================================================================
--- trunk/stream/realrtsp/real.c (original)
+++ trunk/stream/realrtsp/real.c Mon Oct 30 22:55:58 2006
@@ -41,6 +41,8 @@
#else
#include "libavutil/md5.h"
#endif
+#include "../http.h"
+#include "mp_msg.h"
/*
#define LOG
@@ -436,7 +438,8 @@
//! maximum size of the rtsp description, must be < INT_MAX
#define MAX_DESC_BUF (20 * 1024 * 1024)
-rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth) {
+rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth,
+ char *username, char *password) {
char *description=NULL;
char *session_id=NULL;
@@ -450,6 +453,7 @@
unsigned int size;
int status;
uint32_t maxbandwidth = bandwidth;
+ char* authfield = NULL;
/* get challenge */
challenge1=strdup(rtsp_search_answers(rtsp_session,"RealChallenge1"));
@@ -462,6 +466,7 @@
bandwidth = 10485800;
/* request stream description */
+rtsp_send_describe:
rtsp_schedule_field(rtsp_session, "Accept: application/sdp");
sprintf(buf, "Bandwidth: %u", bandwidth);
rtsp_schedule_field(rtsp_session, buf);
@@ -471,8 +476,50 @@
rtsp_schedule_field(rtsp_session, "SupportsMaximumASMBandwidth: 1");
rtsp_schedule_field(rtsp_session, "Language: en-US");
rtsp_schedule_field(rtsp_session, "Require: com.real.retain-entity-for-setup");
+ if(authfield)
+ rtsp_schedule_field(rtsp_session, authfield);
status=rtsp_request_describe(rtsp_session,NULL);
+ if (status == 401) {
+ int authlen, b64_authlen;
+ char *authreq;
+ char* authstr = NULL;
+
+ if (authfield) {
+ mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: authorization failed, check your credentials\n");
+ goto autherr;
+ }
+ if (!(authreq = rtsp_search_answers(rtsp_session,"WWW-Authenticate"))) {
+ mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: 401 but no auth request, aborting\n");
+ goto autherr;
+ }
+ if (!username) {
+ mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: auth required but no username supplied\n");
+ goto autherr;
+ }
+ if (!strstr(authreq, "Basic")) {
+ mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: authenticator not supported (%s)\n", authreq);
+ goto autherr;
+ }
+ authlen = strlen(username) + (password ? strlen(password) : 0) + 2;
+ authstr = malloc(authlen);
+ sprintf(authstr, "%s:%s", username, password ? password : "");
+ authfield = malloc(authlen*2+22);
+ strcpy(authfield, "Authorization: Basic ");
+ b64_authlen = base64_encode(authstr, authlen, authfield+21, authlen*2);
+ free(authstr);
+ if (b64_authlen < 0) {
+ mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: base64 output overflow, this should never happen\n");
+ goto autherr;
+ }
+ authfield[b64_authlen+21] = 0;
+ goto rtsp_send_describe;
+ }
+autherr:
+
+ if (authfield)
+ free(authfield);
+
if ( status<200 || status>299 )
{
char *alert=rtsp_search_answers(rtsp_session,"Alert");
Modified: trunk/stream/realrtsp/real.h
==============================================================================
--- trunk/stream/realrtsp/real.h (original)
+++ trunk/stream/realrtsp/real.h Mon Oct 30 22:55:58 2006
@@ -48,7 +48,8 @@
};
int real_get_rdt_chunk(rtsp_t *rtsp_session, char **buffer);
-rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth);
+rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth,
+ char *username, char *password);
struct real_rtsp_session_t *init_real_rtsp_session (void);
void free_real_rtsp_session (struct real_rtsp_session_t* real_session);
Modified: trunk/stream/stream_rtsp.c
==============================================================================
--- trunk/stream/stream_rtsp.c (original)
+++ trunk/stream/stream_rtsp.c Mon Oct 30 22:55:58 2006
@@ -96,7 +96,9 @@
rtsp = rtsp_session_start (fd, &mrl, file,
stream->streaming_ctrl->url->hostname,
port, &redirected,
- stream->streaming_ctrl->bandwidth);
+ stream->streaming_ctrl->bandwidth,
+ stream->streaming_ctrl->url->username,
+ stream->streaming_ctrl->url->password);
if (redirected == 1)
{
More information about the MPlayer-cvslog
mailing list