From ea9a530a3aa17e24008c1b484dedfe8b24634806 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Wed, 26 Feb 2014 12:34:15 -0800 Subject: [PATCH] clients: keep generic device records Now that we display connected clients in the status page, it makes sense that we show all of them, instead of only recognized device types. --- clients.c | 17 ++++++++++++----- clients.h | 5 +++-- upnphttp.c | 43 +++++++++++++++++++------------------------ 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/clients.c b/clients.c index fb9f109..e15f3e0 100644 --- a/clients.c +++ b/clients.c @@ -49,7 +49,7 @@ struct client_type_s client_types[] = { EPS3, FLAG_DLNA | FLAG_MIME_AVI_DIVX, "PLAYSTATION 3", - "PLAYSTATION 3", + "PLAYSTATION 3", EXAVClientInfo }, @@ -194,6 +194,13 @@ struct client_type_s client_types[] = EUserAgent }, + { EStandardUPnP, + 0, + "Generic UPnP 1.0", + "UPnP/1.0", + EUserAgent + }, + { 0, 0, NULL, 0 } }; @@ -216,7 +223,7 @@ SearchClientCache(struct in_addr addr, int quiet) memcmp(mac, clients[i].mac, 6) == 0) { /* Same MAC as last time when we were able to identify the client, - * so extend the timeout by another hour. */ + * so extend the timeout by another hour. */ clients[i].age = time(NULL); } else @@ -249,9 +256,9 @@ AddClientCache(struct in_addr addr, int type) clients[i].type = type; clients[i].age = time(NULL); DPRINTF(E_DEBUG, L_HTTP, "Added client [%s/%s/%02X:%02X:%02X:%02X:%02X:%02X] to cache slot %d.\n", - client_types[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], i); + client_types[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], i); return 0; } diff --git a/clients.h b/clients.h index 706c00a..654e94b 100644 --- a/clients.h +++ b/clients.h @@ -21,7 +21,7 @@ #include #include -#define CLIENT_CACHE_SLOTS 20 +#define CLIENT_CACHE_SLOTS 25 #define FLAG_DLNA 0x00000001 #define FLAG_MIME_AVI_DIVX 0x00000002 @@ -66,7 +66,8 @@ enum client_types { ESonyBravia, ESonyInternetTV, EToshibaTV, - EStandardDLNA150 + EStandardDLNA150, + EStandardUPnP }; struct client_type_s { diff --git a/upnphttp.c b/upnphttp.c index 9cf2fa4..a139c36 100644 --- a/upnphttp.c +++ b/upnphttp.c @@ -427,33 +427,28 @@ next_header: * This is done because a lot of clients like to send a * different User-Agent with different types of requests. */ n = SearchClientCache(h->clientaddr, 0); - if( h->req_client ) + /* Add this client to the cache if it's not there already. */ + if( n < 0 ) { - /* Add this client to the cache if it's not there already. */ - if( n < 0 ) - { - AddClientCache(h->clientaddr, h->req_client); - } - else - { - enum client_types type = client_types[h->req_client].type; - enum client_types ctype = client_types[clients[n].type].type; - /* If we know the client and our new detection is generic, use our cached info */ - /* If we detected a Samsung Series B earlier, don't overwrite it with Series A info */ - if ((ctype < EStandardDLNA150 && type == EStandardDLNA150) || - (ctype == ESamsungSeriesB && type == ESamsungSeriesA)) - { - h->req_client = clients[n].type; - return; - } - clients[n].type = h->req_client; - clients[n].age = time(NULL); - } + AddClientCache(h->clientaddr, h->req_client); } - else if( n >= 0 ) + else if (h->req_client) { + enum client_types type = client_types[h->req_client].type; + enum client_types ctype = client_types[clients[n].type].type; + /* If we know the client and our new detection is generic, use our cached info */ + /* If we detected a Samsung Series B earlier, don't overwrite it with Series A info */ + if ((ctype && ctype < EStandardDLNA150 && type >= EStandardDLNA150) || + (ctype == ESamsungSeriesB && type == ESamsungSeriesA)) + { + h->req_client = clients[n].type; + return; + } + clients[n].type = h->req_client; + clients[n].age = time(NULL); + } + else h->req_client = clients[n].type; - } } /* very minimalistic 400 error message */ @@ -991,7 +986,7 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h) { SendResp_caption(h, HttpUrl+10); } - else if(strcmp(HttpUrl, "/status/") == 0) + else if(strncmp(HttpUrl, "/status", 7) == 0) { SendResp_presentation(h); }