From: Jaroslav Kysela Date: Thu, 20 Sep 2018 14:49:05 +0000 (+0200) Subject: http: add http_username() and use it in webui, fixes #5214, fixes #5215 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b92134b992f8437d21af34445d54040b30457263;p=thirdparty%2Ftvheadend.git http: add http_username() and use it in webui, fixes #5214, fixes #5215 --- diff --git a/src/http.c b/src/http.c index 7407111f1..1a9df5069 100644 --- a/src/http.c +++ b/src/http.c @@ -1145,6 +1145,17 @@ http_access_verify_channel(http_connection_t *hc, int mask, return res; } +/** + * + */ +const char * +http_username(http_connection_t *hc) +{ + if (strempty(hc->hc_username) && hc->hc_access) + return hc->hc_access->aa_username; + return hc->hc_username; +} + /** * */ diff --git a/src/http.h b/src/http.h index c2a44a927..18c97c40e 100644 --- a/src/http.h +++ b/src/http.h @@ -215,6 +215,8 @@ static inline int http_args_empty(const http_arg_list_t *list) { return TAILQ_EM int http_tokenize(char *buf, char **vec, int vecsize, int delimiter); +const char * http_username(http_connection_t *hc); + void http_alive(http_connection_t *hc); void http_error(http_connection_t *hc, int error); diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c index cbde6f651..d0af82c8b 100644 --- a/src/satip/rtsp.c +++ b/src/satip/rtsp.c @@ -686,7 +686,7 @@ rtsp_start "SAT>IP", rs->prch.prch_flags | SUBSCRIPTION_STREAMING, - addrbuf, hc->hc_username, + addrbuf, http_username(hc), http_arg_get(&hc->hc_args, "User-Agent"), NULL); if (!rs->subs) @@ -1664,6 +1664,7 @@ rtsp_stream_status ( void *opaque, htsmsg_t *m ) { http_connection_t *hc = opaque; char buf[128]; + const char *username; struct session *rs = NULL; htsmsg_t *c, *tcp = NULL, *udp = NULL; int udpport, s32; @@ -1673,8 +1674,9 @@ rtsp_stream_status ( void *opaque, htsmsg_t *m ) tcp_get_str_from_ip(hc->hc_proxy_ip, buf, sizeof(buf)); htsmsg_add_str(m, "proxy", buf); } - if (hc->hc_username) - htsmsg_add_str(m, "user", hc->hc_username); + username = http_username(hc); + if (username) + htsmsg_add_str(m, "user", username); TAILQ_FOREACH(rs, &rtsp_sessions, link) { if (hc->hc_session && diff --git a/src/webui/webui.c b/src/webui/webui.c index 2ae59a49d..f1b2fa0c3 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -292,14 +292,16 @@ http_stream_status ( void *opaque, htsmsg_t *m ) { http_connection_t *hc = opaque; char buf[128]; + const char *username; htsmsg_add_str(m, "type", "HTTP"); if (hc->hc_proxy_ip) { tcp_get_str_from_ip(hc->hc_proxy_ip, buf, sizeof(buf)); htsmsg_add_str(m, "proxy", buf); } - if (hc->hc_username) - htsmsg_add_str(m, "user", hc->hc_username); + username = http_username(hc); + if (username) + htsmsg_add_str(m, "user", username); } static inline void * @@ -1070,7 +1072,7 @@ http_stream_service(http_connection_t *hc, service_t *service, int weight) prch.prch_flags | SUBSCRIPTION_STREAMING | eflags, hc->hc_peer_ipstr, - hc->hc_username, + http_username(hc), http_arg_get(&hc->hc_args, "User-Agent"), NULL); if(s) { @@ -1147,7 +1149,7 @@ http_stream_mux(http_connection_t *hc, mpegts_mux_t *mm, int weight) s = subscription_create_from_mux(&prch, NULL, weight ?: 10, "HTTP", prch.prch_flags | SUBSCRIPTION_STREAMING, - hc->hc_peer_ipstr, hc->hc_username, + hc->hc_peer_ipstr, http_username(hc), http_arg_get(&hc->hc_args, "User-Agent"), NULL); if (s) { @@ -1211,7 +1213,7 @@ http_stream_channel(http_connection_t *hc, channel_t *ch, int weight) s = subscription_create_from_channel(&prch, NULL, weight, "HTTP", prch.prch_flags | SUBSCRIPTION_STREAMING, - hc->hc_peer_ipstr, hc->hc_username, + hc->hc_peer_ipstr, http_username(hc), http_arg_get(&hc->hc_args, "User-Agent"), NULL); @@ -1620,7 +1622,7 @@ page_dvrfile_preop(http_connection_t *hc, off_t file_start, if (priv->tcp_id && !hc->hc_no_output && content_len > 64*1024) { priv->sub = subscription_create_from_file("HTTP", priv->charset, priv->fname, hc->hc_peer_ipstr, - hc->hc_username, + http_username(hc), http_arg_get(&hc->hc_args, "User-Agent")); if (priv->sub == NULL) { http_stream_postop(priv->tcp_id);