diff --git a/clients.c b/clients.c index 2d4143c..8d82ba2 100644 --- a/clients.c +++ b/clients.c @@ -240,7 +240,7 @@ struct client_type_s client_types[] = struct client_cache_s clients[CLIENT_CACHE_SLOTS]; -int +struct client_cache_s * SearchClientCache(struct in_addr addr, int quiet) { int i; @@ -263,20 +263,20 @@ SearchClientCache(struct in_addr addr, int quiet) else { memset(&clients[i], 0, sizeof(struct client_cache_s)); - return -1; + return NULL; } } if (!quiet) DPRINTF(E_DEBUG, L_HTTP, "Client found in cache. [%s/entry %d]\n", - client_types[clients[i].type].name, i); - return i; + clients[i].type->name, i); + return &clients[i]; } } - return -1; + return NULL; } -int +struct client_cache_s * AddClientCache(struct in_addr addr, int type) { int i; @@ -287,15 +287,15 @@ AddClientCache(struct in_addr addr, int type) continue; get_remote_mac(addr, clients[i].mac); clients[i].addr = addr; - clients[i].type = type; + clients[i].type = &client_types[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); - return 0; + return &clients[i]; } - return -1; + return NULL; } diff --git a/clients.h b/clients.h index 5b4cb5a..d904ed0 100644 --- a/clients.h +++ b/clients.h @@ -91,14 +91,14 @@ struct client_type_s { struct client_cache_s { struct in_addr addr; unsigned char mac[6]; - enum client_types type; + struct client_type_s *type; time_t age; }; extern struct client_type_s client_types[]; extern struct client_cache_s clients[CLIENT_CACHE_SLOTS]; -int SearchClientCache(struct in_addr addr, int quiet); -int AddClientCache(struct in_addr addr, int type); +struct client_cache_s *SearchClientCache(struct in_addr addr, int quiet); +struct client_cache_s *AddClientCache(struct in_addr addr, int type); #endif diff --git a/minissdp.c b/minissdp.c index 0ab7ab5..ba9a861 100644 --- a/minissdp.c +++ b/minissdp.c @@ -319,7 +319,7 @@ ParseUPnPClient(char *location) char *off = NULL, *p; int content_len = sizeof(buf); struct NameValueParserData xml; - int client; + struct client_cache_s *client; int type = 0; char *model, *serial, *name; @@ -458,14 +458,14 @@ close: return; /* Add this client to the cache if it's not there already. */ client = SearchClientCache(dest.sin_addr, 1); - if (client < 0) + if (!client) { AddClientCache(dest.sin_addr, type); } else { - clients[client].type = type; - clients[client].age = time(NULL); + client->type = &client_types[type]; + client->age = time(NULL); } } @@ -546,13 +546,13 @@ ProcessSSDPRequest(int s, unsigned short port) (strstrc(srv, "DigiOn DiXiM", '\r') != NULL)) /* Marantz Receiver */ { /* Check if the client is already in cache */ - i = SearchClientCache(sendername.sin_addr, 1); - if (i >= 0) + struct client_cache_s *client = SearchClientCache(sendername.sin_addr, 1); + if (client) { - if (clients[i].type < EStandardDLNA150 && - clients[i].type != ESamsungSeriesA) + if (client->type->type < EStandardDLNA150 && + client->type->type != ESamsungSeriesA) { - clients[i].age = time(NULL); + client->age = time(NULL); return; } } diff --git a/upnphttp.c b/upnphttp.c index 5834b03..d8b6d29 100644 --- a/upnphttp.c +++ b/upnphttp.c @@ -137,6 +137,7 @@ Delete_upnphttp(struct upnphttp * h) static void ParseHttpHeaders(struct upnphttp * h) { + int client = 0; char * line; char * colon; char * p; @@ -274,7 +275,7 @@ ParseHttpHeaders(struct upnphttp * h) { int i; /* Skip client detection if we already detected it. */ - if( h->req_client ) + if( client ) goto next_header; p = colon + 1; while(isspace(*p)) @@ -285,7 +286,7 @@ ParseHttpHeaders(struct upnphttp * h) continue; if (strstrc(p, client_types[i].match, '\r') != NULL) { - h->req_client = i; + client = i; break; } } @@ -294,7 +295,7 @@ ParseHttpHeaders(struct upnphttp * h) { int i; /* Skip client detection if we already detected it. */ - if( h->req_client && client_types[h->req_client].type < EStandardDLNA150 ) + if( client && client_types[client].type < EStandardDLNA150 ) goto next_header; p = colon + 1; while(isspace(*p)) @@ -305,7 +306,7 @@ ParseHttpHeaders(struct upnphttp * h) continue; if (strstrc(p, client_types[i].match, '\r') != NULL) { - h->req_client = i; + client = i; break; } } @@ -386,7 +387,7 @@ ParseHttpHeaders(struct upnphttp * h) continue; if (strstrc(p, client_types[i].match, '\r') != NULL) { - h->req_client = i; + client = i; break; } } @@ -432,29 +433,24 @@ next_header: /* If the client type wasn't found, search the cache. * 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); + h->req_client = SearchClientCache(h->clientaddr, 0); /* Add this client to the cache if it's not there already. */ - if( n < 0 ) + if (!h->req_client) { - AddClientCache(h->clientaddr, h->req_client); + h->req_client = AddClientCache(h->clientaddr, client); } - else if (h->req_client) + else if (client) { - enum client_types type = client_types[h->req_client].type; - enum client_types ctype = client_types[clients[n].type].type; + enum client_types type = client_types[client].type; + enum client_types ctype = client_types[n].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].type = &client_types[client]; clients[n].age = time(NULL); } - else - h->req_client = clients[n].type; } /* very minimalistic 400 error message */ @@ -625,7 +621,7 @@ SendResp_presentation(struct upnphttp * h) if (!clients[i].addr.s_addr) continue; strcatf(&str, "