2 * This file is part of DisOrder.
3 * Copyright (C) 2004-2008 Richard Kettlewell
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.
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.
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
20 /** @file server/macros-disorder.c
21 * @brief DisOrder-specific expansions
32 /** @brief Client used by CGI
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
38 disorder_client *client;
40 /** @brief Cached data */
41 static unsigned flags;
43 struct queue_entry *queue;
44 struct queue_entry *playing;
45 struct queue_entry *recent;
64 /** @brief Fetch cachable data */
65 static void lookup(unsigned want) {
66 unsigned need = want ^ (flags & want);
67 struct queue_entry *r, *rnext;
74 disorder_queue(client, &queue);
76 disorder_playing(client, &playing);
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);
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")))
96 re = cgi_get("regexp");
98 if(disorder_directories(client, dir, re,
102 if(disorder_files(client, dir, re,
106 if(need & DC_RIGHTS) {
107 rights = RIGHT_READ; /* fail-safe */
108 if(!disorder_userinfo(client, disorder_user(client),
110 parse_rights(rights, &rights, 1);
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)