Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IPTV RTSP: add basic authentication
  • Loading branch information
perexg committed May 7, 2015
1 parent 128f3a3 commit 2916996
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/http.h
Expand Up @@ -320,6 +320,8 @@ struct http_client {
int hc_rtp_multicast:1;
long hc_rtsp_stream_id;
int hc_rtp_timeout;
char *hc_rtsp_user;
char *hc_rtsp_pass;

struct http_client_ssl *hc_ssl; /* ssl internals */

Expand All @@ -344,6 +346,8 @@ void http_client_close ( http_client_t *hc );
int http_client_send( http_client_t *hc, http_cmd_t cmd,
const char *path, const char *query,
http_arg_list_t *header, void *body, size_t body_size );
void http_client_basic_auth( http_client_t *hc, http_arg_list_t *h,
const char *user, const char *pass );
int http_client_simple( http_client_t *hc, const url_t *url);
int http_client_clear_state( http_client_t *hc );
int http_client_run( http_client_t *hc );
Expand Down
44 changes: 28 additions & 16 deletions src/httpc.c
Expand Up @@ -1036,6 +1036,31 @@ http_client_run( http_client_t *hc )
goto retry;
}

/*
*
*/
void
http_client_basic_auth( http_client_t *hc, http_arg_list_t *h,
const char *user, const char *pass )
{
if (user && user[0] && pass && pass[0]) {
#define BASIC "Basic "
size_t plen = strlen(pass);
size_t ulen = strlen(user);
size_t len = BASE64_SIZE(plen + ulen + 1) + 1;
char *buf = alloca(ulen + 1 + plen + 1);
char *cbuf = alloca(len + sizeof(BASIC) + 1);
strcpy(buf, user);
strcat(buf, ":");
strcat(buf, pass);
strcpy(cbuf, BASIC);
base64_encode(cbuf + sizeof(BASIC) - 1, len,
(uint8_t *)buf, ulen + 1 + plen);
http_arg_set(h, "Authorization", cbuf);
#undef BASIC
}
}

/*
* Redirected
*/
Expand All @@ -1060,22 +1085,7 @@ http_client_basic_args ( http_client_t *hc, http_arg_list_t *h, const url_t *url
}
if (!keepalive)
http_arg_set(h, "Connection", "close");
if (url->user && url->user[0] && url->pass && url->pass[0]) {
#define BASIC "Basic "
size_t plen = strlen(url->pass);
size_t ulen = strlen(url->user);
size_t len = BASE64_SIZE(plen + ulen + 1) + 1;
char *buf = alloca(ulen + 1 + plen + 1);
char *cbuf = alloca(len + sizeof(BASIC) + 1);
strcpy(buf, url->user);
strcat(buf, ":");
strcat(buf, url->pass);
strcpy(cbuf, BASIC);
base64_encode(cbuf + sizeof(BASIC) - 1, len,
(uint8_t *)buf, ulen + 1 + plen);
http_arg_set(h, "Authorization", cbuf);
#undef BASIC
}
http_client_basic_auth(hc, h, url->user, url->pass);
}

static int
Expand Down Expand Up @@ -1398,6 +1408,8 @@ http_client_close ( http_client_t *hc )
free(hc->hc_host);
free(hc->hc_scheme);
free(hc->hc_bindaddr);
free(hc->hc_rtsp_user);
free(hc->hc_rtsp_pass);
free(hc);
}

Expand Down
5 changes: 5 additions & 0 deletions src/input/mpegts/iptv/iptv_rtsp.c
Expand Up @@ -135,6 +135,11 @@ iptv_rtsp_start
u->host, u->port, NULL)))
return SM_CODE_TUNING_FAILED;

if (u->user)
hc->hc_rtsp_user = strdup(u->user);
if (u->pass)
hc->hc_rtsp_pass = strdup(u->pass);

if (udp_bind_double(&rtp, &rtpc,
"IPTV", "rtp", "rtcp",
NULL, 0, NULL,
Expand Down
1 change: 1 addition & 0 deletions src/rtsp.c
Expand Up @@ -46,6 +46,7 @@ rtsp_send( http_client_t *hc, http_cmd_t cmd,
}
http_arg_set(hdr, "Session", hc->hc_rtsp_session);
}
http_client_basic_auth(hc, hdr, hc->hc_rtsp_user, hc->hc_rtsp_pass);
if (hc->hc_port != 554)
snprintf(buf2, sizeof(buf2), ":%d", hc->hc_port);
else
Expand Down

0 comments on commit 2916996

Please sign in to comment.