Commit | Line | Data |
---|---|---|
448d3570 RK |
1 | /* |
2 | * This file is part of DisOrder. | |
3 | * Copyright (C) 2004-2008 Richard Kettlewell | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
18 | * USA | |
19 | */ | |
20 | /** @file server/macros-disorder.c | |
21 | * @brief DisOrder-specific expansions | |
22 | */ | |
23 | ||
24 | #include <config.h> | |
25 | #include "types.h" | |
26 | ||
27 | #include "sink.h" | |
28 | #include "client.h" | |
29 | #include "lookup.h" | |
30 | #include "cgi.h" | |
31 | ||
32 | /** @brief Client used by CGI | |
33 | * | |
34 | * The caller should arrange for this to be created before any of | |
35 | * these expansions are used (if it cannot connect then it's safe to | |
36 | * leave it as NULL). | |
37 | */ | |
38 | disorder_client *client; | |
39 | ||
40 | /** @brief Cached data */ | |
41 | static unsigned flags; | |
42 | ||
43 | struct queue_entry *queue; | |
44 | struct queue_entry *playing; | |
45 | struct queue_entry *recent; | |
46 | ||
47 | int volume_left; | |
48 | int volume_right; | |
49 | ||
50 | char **files; | |
51 | int nfiles; | |
52 | ||
53 | char **dirs; | |
54 | int ndirs; | |
55 | ||
56 | char **new; | |
57 | int nnew; | |
58 | ||
59 | rights_type rights; | |
60 | ||
61 | int enabled; | |
62 | int random_enabled; | |
63 | ||
64 | /** @brief Fetch cachable data */ | |
65 | static void lookup(unsigned want) { | |
66 | unsigned need = want ^ (flags & want); | |
67 | struct queue_entry *r, *rnext; | |
68 | const char *dir, *re; | |
69 | char *rights; | |
70 | ||
71 | if(!client || !need) | |
72 | return; | |
73 | if(need & DC_QUEUE) | |
74 | disorder_queue(client, &queue); | |
75 | if(need & DC_PLAYING) | |
76 | disorder_playing(client, &playing); | |
77 | if(need & DC_NEW) | |
78 | disorder_new_tracks(client, &new, &nnew, 0); | |
79 | if(need & DC_RECENT) { | |
80 | /* we need to reverse the order of the list */ | |
81 | disorder_recent(client, &r); | |
82 | while(r) { | |
83 | rnext = r->next; | |
84 | r->next = recent; | |
85 | recent = r; | |
86 | r = rnext; | |
87 | } | |
88 | } | |
89 | if(need & DC_VOLUME) | |
90 | disorder_get_volume(client, | |
91 | &volume_left, &volume_right); | |
92 | /* DC_FILES and DC_DIRS are looking obsolete now */ | |
93 | if(need & (DC_FILES|DC_DIRS)) { | |
94 | if(!(dir = cgi_get("directory"))) | |
95 | dir = ""; | |
96 | re = cgi_get("regexp"); | |
97 | if(need & DC_DIRS) | |
98 | if(disorder_directories(client, dir, re, | |
99 | &dirs, &ndirs)) | |
100 | ndirs = 0; | |
101 | if(need & DC_FILES) | |
102 | if(disorder_files(client, dir, re, | |
103 | &files, &nfiles)) | |
104 | nfiles = 0; | |
105 | } | |
106 | if(need & DC_RIGHTS) { | |
107 | rights = RIGHT_READ; /* fail-safe */ | |
108 | if(!disorder_userinfo(client, disorder_user(client), | |
109 | "rights", &rights)) | |
110 | parse_rights(rights, &rights, 1); | |
111 | } | |
112 | if(need & DC_ENABLED) | |
113 | disorder_enabled(client, &enabled); | |
114 | if(need & DC_RANDOM_ENABLED) | |
115 | disorder_random_enabled(client, &random_enabled); | |
116 | if(need & DC_RANDOM_ENABLED) | |
117 | flags |= need; | |
118 | } | |
119 | ||
120 | /* | |
121 | Local Variables: | |
122 | c-basic-offset:2 | |
123 | comment-column:40 | |
124 | fill-column:79 | |
125 | indent-tabs-mode:nil | |
126 | End: | |
127 | */ |