This repository was archived by the owner on Jan 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainers.c
231 lines (210 loc) · 6.67 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
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
/* 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"
const struct container_s containers[] = {
{"0", "-1", "root"},
{MUSIC_ID, "0", "Music"},
{MUSIC_ALL_ID, MUSIC_ID, "All Music"},
{MUSIC_GENRE_ID, MUSIC_ID, "Genre"},
{MUSIC_ARTIST_ID, MUSIC_ID, "Artist"},
{MUSIC_ALBUM_ID, MUSIC_ID, "Album"},
{MUSIC_DIR_ID, MUSIC_ID, "Folders"},
{MUSIC_PLIST_ID, MUSIC_ID, "Playlists"},
{VIDEO_ID, "0", "Video"},
{VIDEO_ALL_ID, VIDEO_ID, "All Video"},
{VIDEO_DIR_ID, VIDEO_ID, "Folders"},
{IMAGE_ID, "0", "Pictures"},
{IMAGE_ALL_ID, IMAGE_ID, "All Pictures"},
{IMAGE_DATE_ID, IMAGE_ID, "Date Taken"},
{IMAGE_CAMERA_ID, IMAGE_ID, "Camera"},
{IMAGE_DIR_ID, IMAGE_ID, "Folders"},
{BROWSEDIR_ID, "0", "Browse Folders"},
{0, 0, 0}};
#define NINETY_DAYS "7776000"
static const char *music_id = MUSIC_ID;
static const char *music_all_id = MUSIC_ALL_ID;
static const char *music_genre_id = MUSIC_GENRE_ID;
static const char *music_artist_id = MUSIC_ARTIST_ID;
static const char *music_album_id = MUSIC_ALBUM_ID;
static const char *music_plist_id = MUSIC_PLIST_ID;
static const char *music_dir_id = MUSIC_DIR_ID;
static const char *video_id = VIDEO_ID;
static const char *video_all_id = VIDEO_ALL_ID;
static const char *video_dir_id = VIDEO_DIR_ID;
static const char *image_id = IMAGE_ID;
static const char *image_all_id = IMAGE_ALL_ID;
static const char *image_date_id = IMAGE_DATE_ID;
static const char *image_camera_id = IMAGE_CAMERA_ID;
static const char *image_dir_id = IMAGE_DIR_ID;
const 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}};
const struct magic_container_s *
in_magic_container(const char *id, int flags, const char **real_id)
{
size_t len;
int i;
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;
}
const struct magic_container_s *
check_magic_container(const char *id, int flags)
{
int i;
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;
}