From a75bdadce18a4ce5cd45d4028ce4d71d702ca1ce Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Tue, 7 Jan 2014 10:14:26 -0800 Subject: [PATCH] Show client status on our basic presentation page. --- upnphttp.c | 77 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/upnphttp.c b/upnphttp.c index 2269472..9cf2fa4 100644 --- a/upnphttp.c +++ b/upnphttp.c @@ -577,31 +577,68 @@ sendXMLdesc(struct upnphttp * h, char * (f)(int *)) free(desc); } +#ifdef READYNAS +static void +SendResp_readynas_admin(struct upnphttp * h) +{ + char body[128]; + int l; + + h->respflags = FLAG_HTML; + l = snprintf(body, sizeof(body), "", + lan_addr[h->iface].str); + + BuildResp_upnphttp(h, body, l); + SendResp_upnphttp(h); + CloseSocket_upnphttp(h); +} +#endif + static void SendResp_presentation(struct upnphttp * h) { - char body[1024]; - int l; + struct string_s str; + char body[4096]; + int a, v, p, i; + + str.data = body; + str.size = sizeof(body); + str.off = 0; + h->respflags = FLAG_HTML; -#ifdef READYNAS - l = snprintf(body, sizeof(body), "", - lan_addr[h->iface].str); -#else - int a, v, p; a = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'a*'"); v = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'v*'"); p = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'i*'"); - l = snprintf(body, sizeof(body), + strcatf(&str, "" SERVER_NAME " " MINIDLNA_VERSION "" "
" - "

" SERVER_NAME " status

" - "Audio files: %d
" - "Video files: %d
" - "Image files: %d
" - "\r\n", a, v, p); -#endif - BuildResp_upnphttp(h, body, l); + "

" SERVER_NAME " status

"); + + strcatf(&str, + "

Media library

" + "" + "" + "" + "" + "
Audio files%d
Video files%d
Image files%d
", a, v, p); + + strcatf(&str, + "

Connected clients

" + "" + ""); + for (i = 0; i < CLIENT_CACHE_SLOTS; i++) + { + if (!clients[i].addr.s_addr) + continue; + strcatf(&str, "", + i, client_types[clients[i].type].name, inet_ntoa(clients[i].addr), + clients[i].mac[0], clients[i].mac[1], clients[i].mac[2], + clients[i].mac[3], clients[i].mac[4], clients[i].mac[5]); + } + strcatf(&str, "
IDTypeIP AddressHW Address
%d%s%s%02X:%02X:%02X:%02X:%02X:%02X
\r\n"); + + BuildResp_upnphttp(h, str.data, str.off); SendResp_upnphttp(h); CloseSocket_upnphttp(h); } @@ -954,10 +991,18 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h) { SendResp_caption(h, HttpUrl+10); } - else if(strcmp(HttpUrl, "/") == 0) + else if(strcmp(HttpUrl, "/status/") == 0) { SendResp_presentation(h); } + else if(strcmp(HttpUrl, "/") == 0) + { + #ifdef READYNAS + SendResp_readynas_admin(h); + #else + SendResp_presentation(h); + #endif + } else { DPRINTF(E_WARN, L_HTTP, "%s not found, responding ERROR 404\n", HttpUrl);