Commit 66df66da authored by Jan Schmidt's avatar Jan Schmidt

gst/rtsp/: Implement simple Basic Authentication support so that urls like...

gst/rtsp/: Implement simple Basic Authentication support so that urls like rtsp://user:pass@hostname/rtspstream work ...

Original commit message from CVS:
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_finalize),
(gst_rtspsrc_create_stream), (rtsp_auth_method_to_string),
(gst_rtspsrc_parse_auth_hdr), (gst_rtspsrc_setup_auth),
(gst_rtspsrc_send), (gst_rtspsrc_try_send), (gst_rtspsrc_open),
(gst_rtspsrc_close), (gst_rtspsrc_play), (gst_rtspsrc_pause),
(gst_rtspsrc_uri_set_uri):
* gst/rtsp/gstrtspsrc.h:
* gst/rtsp/rtspconnection.c: (rtsp_connection_create),
(append_auth_header), (rtsp_connection_send),
(rtsp_connection_free), (rtsp_connection_set_auth):
* gst/rtsp/rtspconnection.h:
* gst/rtsp/rtspdefs.h:
* gst/rtsp/rtspurl.c: (rtsp_url_get_request_uri):
* gst/rtsp/rtspurl.h:
Implement simple Basic Authentication support so that urls like
rtsp://user:pass@hostname/rtspstream work on hosts that require
authentication.
parent fff672f9
2007-02-23 Jan Schmidt <thaytan@mad.scientist.com>
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_finalize),
(gst_rtspsrc_create_stream), (rtsp_auth_method_to_string),
(gst_rtspsrc_parse_auth_hdr), (gst_rtspsrc_setup_auth),
(gst_rtspsrc_send), (gst_rtspsrc_try_send), (gst_rtspsrc_open),
(gst_rtspsrc_close), (gst_rtspsrc_play), (gst_rtspsrc_pause),
(gst_rtspsrc_uri_set_uri):
* gst/rtsp/gstrtspsrc.h:
* gst/rtsp/rtspconnection.c: (rtsp_connection_create),
(append_auth_header), (rtsp_connection_send),
(rtsp_connection_free), (rtsp_connection_set_auth):
* gst/rtsp/rtspconnection.h:
* gst/rtsp/rtspdefs.h:
* gst/rtsp/rtspurl.c: (rtsp_url_get_request_uri):
* gst/rtsp/rtspurl.h:
Implement simple Basic Authentication support so that urls like
rtsp://user:pass@hostname/rtspstream work on hosts that require
authentication.
2007-02-22 Edgard Lima <edgard.lima@indt.org.br>
* sys/v4l2/gstv4l2object.c:
......
This diff is collapsed.
......@@ -130,6 +130,7 @@ struct _GstRTSPSrc {
/* properties */
gchar *location;
gchar *req_location; /* Sanitised URL to use in network requests */
RTSPUrl *url;
RTSPLowerTrans protocols;
gboolean debug;
......@@ -139,6 +140,7 @@ struct _GstRTSPSrc {
/* state */
gchar *content_base;
RTSPLowerTrans cur_protocols;
gboolean tried_url_auth;
/* supported methods */
gint methods;
......
......@@ -143,6 +143,10 @@ rtsp_connection_create (RTSPUrl * url, RTSPConnection ** conn)
newconn->session_id[0] = 0;
newconn->state = RTSP_STATE_INIT;
newconn->auth_method = RTSP_AUTH_NONE;
newconn->username = NULL;
newconn->passwd = NULL;
*conn = newconn;
return RTSP_OK;
......@@ -231,6 +235,30 @@ append_header (gint key, gchar * value, GString * str)
g_string_append_printf (str, "%s: %s\r\n", keystr, value);
}
static void
append_auth_header (RTSPConnection * conn, RTSPMessage * message, GString * str)
{
switch (conn->auth_method) {
case RTSP_AUTH_BASIC:{
gchar *user_pass =
g_strdup_printf ("%s:%s", conn->username, conn->passwd);
gchar *user_pass64 =
g_base64_encode ((guchar *) user_pass, strlen (user_pass));
gchar *auth_string = g_strdup_printf ("Basic %s", user_pass64);
append_header (RTSP_HDR_AUTHORIZATION, auth_string, str);
g_free (user_pass);
g_free (user_pass64);
g_free (auth_string);
break;
}
default:
/* Nothing to do */
break;
}
}
RTSPResult
rtsp_connection_send (RTSPConnection * conn, RTSPMessage * message)
{
......@@ -278,12 +306,15 @@ rtsp_connection_send (RTSPConnection * conn, RTSPMessage * message)
/* append session id if we have one */
if (conn->session_id[0] != '\0') {
rtsp_message_add_header (message, RTSP_HDR_SESSION, conn->session_id);
append_header (RTSP_HDR_SESSION, conn->session_id, str);
}
/* append headers */
g_hash_table_foreach (message->hdr_fields, (GHFunc) append_header, str);
/* Append any authentication headers */
append_auth_header (conn, message, str);
/* append Content-Length and body if needed */
if (message->body != NULL && message->body_size > 0) {
gchar *len;
......@@ -786,6 +817,9 @@ rtsp_connection_free (RTSPConnection * conn)
WSACleanup ();
#endif
g_free (conn->username);
g_free (conn->passwd);
g_free (conn);
return RTSP_OK;
......@@ -812,3 +846,29 @@ rtsp_connection_flush (RTSPConnection * conn, gboolean flush)
}
return RTSP_OK;
}
RTSPResult
rtsp_connection_set_auth (RTSPConnection * conn, RTSPAuthMethod method,
gchar * user, gchar * pass)
{
/* Digest isn't implemented yet */
if (method == RTSP_AUTH_DIGEST)
return RTSP_ENOTIMPL;
/* Make sure the username and passwd are being set for authentication */
if (method == RTSP_AUTH_NONE && (user == NULL || pass == NULL))
return RTSP_EINVAL;
/* ":" chars are not allowed in usernames for basic auth */
if (method == RTSP_AUTH_BASIC && g_strrstr (user, ":") != NULL)
return RTSP_EINVAL;
g_free (conn->username);
g_free (conn->passwd);
conn->auth_method = method;
conn->username = g_strdup (user);
conn->passwd = g_strdup (pass);
return RTSP_OK;
}
......@@ -64,6 +64,11 @@ typedef struct _RTSPConnection
RTSPState state;
gint cseq; /* sequence number */
gchar session_id[512]; /* session id */
/* Authentication */
RTSPAuthMethod auth_method;
gchar *username;
gchar *passwd;
} RTSPConnection;
/* opening/closing a connection */
......@@ -78,6 +83,10 @@ RTSPResult rtsp_connection_receive (RTSPConnection *conn, RTSPMessage *mess
RTSPResult rtsp_connection_flush (RTSPConnection *conn, gboolean flush);
/* Configure Authentication data */
RTSPResult rtsp_connection_set_auth (RTSPConnection *conn,
RTSPAuthMethod method, gchar *user, gchar *pass);
G_END_DECLS
#endif /* __RTSP_CONNECTION_H__ */
......@@ -99,6 +99,16 @@ typedef enum {
RTSP_TEARDOWN = (1 << 10),
} RTSPMethod;
/* Authentication methods, ordered by strength */
typedef enum {
RTSP_AUTH_NONE = 0x00,
RTSP_AUTH_BASIC = 0x01,
RTSP_AUTH_DIGEST = 0x02
} RTSPAuthMethod;
/* Strongest available authentication method */
#define RTSP_AUTH_MAX RTSP_AUTH_DIGEST
typedef enum {
RTSP_HDR_INVALID,
......
......@@ -177,3 +177,20 @@ rtsp_url_get_port (RTSPUrl * url, guint16 * port)
return RTSP_OK;
}
gchar *
rtsp_url_get_request_uri (RTSPUrl * url)
{
gchar *uri;
g_return_val_if_fail (url != NULL, NULL);
if (url->port != 0) {
uri = g_strdup_printf ("rtsp://%s:%u/%s", url->host, url->port,
url->abspath);
} else {
uri = g_strdup_printf ("rtsp://%s/%s", url->host, url->abspath);
}
return uri;
}
......@@ -64,6 +64,7 @@ typedef struct _RTSPUrl {
RTSPResult rtsp_url_parse (const gchar *urlstr, RTSPUrl **url);
void rtsp_url_free (RTSPUrl *url);
gchar *rtsp_url_get_request_uri (RTSPUrl *url);
RTSPResult rtsp_url_set_port (RTSPUrl *url, guint16 port);
RTSPResult rtsp_url_get_port (RTSPUrl *url, guint16 *port);
......
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