[7fe24a]: clients.c Maximize Restore History

Download this file

clients.c    302 lines (263 with data), 6.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/* MiniDLNA media server
* Copyright (C) 2013 NETGEAR
*
* This file is part of MiniDLNA.
*
* MiniDLNA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* MiniDLNA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MiniDLNA. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "clients.h"
#include "getifaddr.h"
#include "log.h"
struct client_type_s client_types[] =
{
{ 0,
0,
"Unknown",
NULL,
EMatchNone
},
{ EXbox,
FLAG_MIME_AVI_AVI | FLAG_MS_PFS,
"Xbox 360",
"Xbox/",
EUserAgent
},
{ EPS3,
FLAG_DLNA | FLAG_MIME_AVI_DIVX,
"PLAYSTATION 3",
"PLAYSTATION",
EUserAgent
},
{ EPS3,
FLAG_DLNA | FLAG_MIME_AVI_DIVX,
"PLAYSTATION 3",
"PLAYSTATION 3",
EXAVClientInfo
},
/* Samsung Series [CDE] BDPs and TVs must be separated, or some of our
* advertised extra features trigger a folder browsing bug on BDPs. */
/* User-Agent: DLNADOC/1.50 SEC_HHP_BD-D5100/1.0 */
{ ESamsungSeriesCDEBDP,
FLAG_SAMSUNG | FLAG_DLNA | FLAG_NO_RESIZE,
"Samsung Series [CDEF] BDP",
"SEC_HHP_BD",
EUserAgent
},
/* User-Agent: DLNADOC/1.50 SEC_HHP_[TV]UE40D7000/1.0 */
/* User-Agent: DLNADOC/1.50 SEC_HHP_ Family TV/1.0 */
{ ESamsungSeriesCDE,
FLAG_SAMSUNG | FLAG_DLNA | FLAG_NO_RESIZE,
"Samsung Series [CDEF]",
"SEC_HHP_",
EUserAgent
},
{ ESamsungSeriesA,
FLAG_SAMSUNG | FLAG_DLNA | FLAG_NO_RESIZE,
"Samsung Series A",
"SamsungWiselinkPro",
EUserAgent
},
{ ESamsungSeriesB,
FLAG_SAMSUNG | FLAG_DLNA | FLAG_NO_RESIZE,
"Samsung Series B",
"Samsung DTV DMR",
EModelName
},
/* User-Agent: Panasonic MIL DLNA CP UPnP/1.0 DLNADOC/1.50 */
{ EPanasonic,
FLAG_DLNA | FLAG_FORCE_SORT,
"Panasonic",
"Panasonic",
EUserAgent
},
/* User-Agent: IPI/1.0 UPnP/1.0 DLNADOC/1.50 */
{ ENetFrontLivingConnect,
FLAG_DLNA | FLAG_FORCE_SORT | FLAG_CAPTION_RES,
"NetFront Living Connect",
"IPI/1",
EUserAgent
},
{ EDenonReceiver,
FLAG_DLNA,
"Denon Receiver",
"bridgeCo-DMP/3",
EUserAgent
},
{ EFreeBox,
FLAG_RESIZE_THUMBS,
"FreeBox",
"fbxupnpav/",
EUserAgent
},
{ EPopcornHour,
FLAG_MIME_FLAC_FLAC,
"Popcorn Hour",
"SMP8634",
EUserAgent
},
/* X-AV-Client-Info: av=5.0; cn="Sony Corporation"; mn="Blu-ray Disc Player"; mv="2.0" */
/* X-AV-Client-Info: av=5.0; cn="Sony Corporation"; mn="BLU-RAY HOME THEATRE SYSTEM"; mv="2.0"; */
/* Sony SMP-100 needs the same treatment as their BDP-S370 */
/* X-AV-Client-Info: av=5.0; cn="Sony Corporation"; mn="Media Player"; mv="2.0" */
{ ESonyBDP,
FLAG_DLNA,
"Sony BDP",
"mv=\"2.0\"",
EXAVClientInfo
},
/* User-Agent: Linux/2.6.31-1.0 UPnP/1.0 DLNADOC/1.50 INTEL_NMPR/2.0 LGE_DLNA_SDK/1.5.0 */
{ ELGDevice,
FLAG_DLNA | FLAG_CAPTION_RES,
"LG",
"LGE_DLNA_SDK",
EUserAgent
},
/* X-AV-Client-Info: av=5.0; cn="Sony Corporation"; mn="BRAVIA KDL-40EX503"; mv="1.7"; */
{ ESonyBravia,
FLAG_DLNA,
"Sony Bravia",
"BRAVIA",
EXAVClientInfo
},
/* X-AV-Client-Info: av=5.0; hn=""; cn="Sony Corporation"; mn="INTERNET TV NSX-40GT 1"; mv="0.1"; */
{ ESonyInternetTV,
FLAG_DLNA,
"Sony Internet TV",
"INTERNET TV",
EXAVClientInfo
},
{ ENetgearEVA2000,
FLAG_MS_PFS | FLAG_RESIZE_THUMBS,
"EVA2000",
"Verismo,",
EUserAgent
},
{ EDirecTV,
FLAG_RESIZE_THUMBS,
"DirecTV",
"DIRECTV ",
EUserAgent
},
{ EToshibaTV,
FLAG_DLNA,
"Toshiba TV",
"UPnP/1.0 DLNADOC/1.50 Intel_SDK_for_UPnP_devices/1.2",
EUserAgent
},
{ ERokuSoundBridge,
FLAG_MS_PFS | FLAG_AUDIO_ONLY | FLAG_MIME_WAV_WAV | FLAG_FORCE_SORT,
"Roku SoundBridge",
"Roku SoundBridge",
EModelName
},
{ EMarantzDMP,
FLAG_DLNA | FLAG_MIME_WAV_WAV,
"marantz DMP",
"marantz DMP",
EFriendlyNameSSDP
},
{ EMediaRoom,
FLAG_MS_PFS,
"MS MediaRoom",
"Microsoft-IPTV-Client",
EUserAgent
},
{ ELifeTab,
FLAG_MS_PFS,
"LIFETAB",
"LIFETAB",
EFriendlyName
},
{ EAsusOPlay,
FLAG_DLNA | FLAG_MIME_AVI_AVI | FLAG_CAPTION_RES,
"Asus OPlay Mini/Mini+",
"O!Play",
EUserAgent
},
{ EBubbleUPnP,
FLAG_CAPTION_RES,
"BubbleUPnP",
"BubbleUPnP",
EUserAgent
},
{ EStandardDLNA150,
FLAG_DLNA | FLAG_MIME_AVI_AVI,
"Generic DLNA 1.5",
"DLNADOC/1.50",
EUserAgent
},
{ EStandardUPnP,
0,
"Generic UPnP 1.0",
"UPnP/1.0",
EUserAgent
},
{ 0, 0, NULL, 0 }
};
struct client_cache_s clients[CLIENT_CACHE_SLOTS];
struct client_cache_s *
SearchClientCache(struct in_addr addr, int quiet)
{
int i;
for (i = 0; i < CLIENT_CACHE_SLOTS; i++)
{
if (clients[i].addr.s_addr == addr.s_addr)
{
/* Invalidate this client cache if it's older than 1 hour */
if ((time(NULL) - clients[i].age) > 3600)
{
unsigned char mac[6];
if (get_remote_mac(addr, mac) == 0 &&
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. */
clients[i].age = time(NULL);
}
else
{
memset(&clients[i], 0, sizeof(struct client_cache_s));
return NULL;
}
}
if (!quiet)
DPRINTF(E_DEBUG, L_HTTP, "Client found in cache. [%s/entry %d]\n",
clients[i].type->name, i);
return &clients[i];
}
}
return NULL;
}
struct client_cache_s *
AddClientCache(struct in_addr addr, int type)
{
int i;
for (i = 0; i < CLIENT_CACHE_SLOTS; i++)
{
if (clients[i].addr.s_addr)
continue;
get_remote_mac(addr, clients[i].mac);
clients[i].addr = addr;
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 &clients[i];
}
return NULL;
}