-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
containers.c
195 lines (174 loc) · 6.25 KB
/
containers.c
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
/* MiniDLNA media server
* Copyright (C) 2014 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 <string.h>
#include "clients.h"
#include "minidlnatypes.h"
#include "scanner.h"
#include "upnpglobalvars.h"
#include "containers.h"
#include "log.h"
#define NINETY_DAYS "7776000"
const char *music_id = MUSIC_ID;
const char *music_all_id = MUSIC_ALL_ID;
const char *music_genre_id = MUSIC_GENRE_ID;
const char *music_artist_id = MUSIC_ARTIST_ID;
const char *music_album_id = MUSIC_ALBUM_ID;
const char *music_plist_id = MUSIC_PLIST_ID;
const char *music_dir_id = MUSIC_DIR_ID;
const char *video_id = VIDEO_ID;
const char *video_all_id = VIDEO_ALL_ID;
const char *video_dir_id = VIDEO_DIR_ID;
const char *image_id = IMAGE_ID;
const char *image_all_id = IMAGE_ALL_ID;
const char *image_date_id = IMAGE_DATE_ID;
const char *image_camera_id = IMAGE_CAMERA_ID;
const char *image_dir_id = IMAGE_DIR_ID;
struct magic_container_s magic_containers[] =
{
/* Alternate root container */
{ NULL,
"0",
&runtime_vars.root_container,
NULL,
"0",
NULL,
NULL,
NULL,
NULL,
-1,
0,
},
/* Recent 50 audio items */
{ "Recently Added",
"1$FF0",
NULL,
"\"1$FF0$\" || OBJECT_ID",
"\"1$FF0\"",
"o.OBJECT_ID",
"(select null from DETAILS where MIME glob 'a*' and timestamp > (strftime('%s','now') - "NINETY_DAYS") limit 50)",
"MIME glob 'a*' and REF_ID is NULL and timestamp > (strftime('%s','now') - "NINETY_DAYS")",
"order by TIMESTAMP DESC",
50,
0,
},
/* Recent 50 video items */
{ "Recently Added",
"2$FF0",
NULL,
"\"2$FF0$\" || OBJECT_ID",
"\"2$FF0\"",
"o.OBJECT_ID",
"(select null from DETAILS where MIME glob 'v*' and timestamp > (strftime('%s','now') - "NINETY_DAYS") limit 50)",
"MIME glob 'v*' and REF_ID is NULL and timestamp > (strftime('%s','now') - "NINETY_DAYS")",
"order by TIMESTAMP DESC",
50,
0,
},
/* Recent 50 image items */
{ "Recently Added",
"3$FF0",
NULL,
"\"3$FF0$\" || OBJECT_ID",
"\"3$FF0\"",
"o.OBJECT_ID",
"(select null from DETAILS where MIME glob 'i*' and timestamp > (strftime('%s','now') - "NINETY_DAYS") limit 50)",
"MIME glob 'i*' and REF_ID is NULL and timestamp > (strftime('%s','now') - "NINETY_DAYS")",
"order by TIMESTAMP DESC",
50,
0,
},
/* Microsoft PlaysForSure containers */
{ NULL, "4", &music_all_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "5", &music_genre_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "6", &music_artist_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "7", &music_album_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "8", &video_all_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "B", &image_all_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "C", &image_date_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "F", &music_plist_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "14", &music_dir_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "15", &video_dir_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "16", &image_dir_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
{ NULL, "D2", &image_camera_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_MS_PFS },
/* Samsung DCM10 containers for Series E(?) */
{ NULL, "I", &image_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_SAMSUNG_DCM10 },
{ NULL, "A", &music_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_SAMSUNG_DCM10 },
{ NULL, "V", &video_id, NULL, NULL, NULL, NULL, NULL, NULL, -1, FLAG_SAMSUNG_DCM10 },
/* Jump straight to Music on audio-only devices */
{ NULL, "0", &music_id, NULL, "0", NULL, NULL, NULL, NULL, -1, FLAG_AUDIO_ONLY },
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0 }
};
struct magic_container_s *
in_magic_container(const char *id, int flags, const char **real_id)
{
size_t len;
int i;
if (check_password_container(id)) return NULL;
for (i = 0; magic_containers[i].objectid_match; i++)
{
if (magic_containers[i].required_flags && !(flags & magic_containers[i].required_flags))
continue;
if (magic_containers[i].objectid && !(*magic_containers[i].objectid))
continue;
DPRINTF(E_MAXDEBUG, L_HTTP, "Checking magic container %d [%s]\n", i, magic_containers[i].objectid_match);
len = strlen(magic_containers[i].objectid_match);
if (strncmp(id, magic_containers[i].objectid_match, len) == 0)
{
if (*(id+len) == '$')
*real_id = id+len+1;
else if (*(id+len) == '\0')
*real_id = id;
else
continue;
DPRINTF(E_DEBUG, L_HTTP, "Found magic container %d [%s]\n", i, magic_containers[i].objectid_match);
return &magic_containers[i];
}
}
return NULL;
}
struct magic_container_s *
check_magic_container(const char *id, int flags)
{
int i;
if (check_password_container(id)) return NULL;
for (i = 0; magic_containers[i].objectid_match; i++)
{
if (magic_containers[i].required_flags && !(flags & magic_containers[i].required_flags))
continue;
if (magic_containers[i].objectid && !(*magic_containers[i].objectid))
continue;
DPRINTF(E_MAXDEBUG, L_HTTP, "Checking magic container %d [%s]\n", i, magic_containers[i].objectid_match);
if (strcmp(id, magic_containers[i].objectid_match) == 0)
{
DPRINTF(E_DEBUG, L_HTTP, "Found magic container %d [%s]\n", i, magic_containers[i].objectid_match);
return &magic_containers[i];
}
}
return NULL;
}
int check_password_container(const char *id)
{
int i, len, match=1;
len = strlen(PASSWORD_CONTAINER);
if (strlen(id) < len) return 0;
for (i=0;i<len && match;i++) {
if (PASSWORD_CONTAINER[i] != id[i]) match = 0;
}
if (match && (id[len] == 0 || id[len] == '$')) return 1;
return 0;
}