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
37 /** @brief Client used by CGI
39 * The caller should arrange for this to be created before any of
40 * these expansions are used (if it cannot connect then it's safe to
43 disorder_client *client;
45 /** @brief Cached data */
46 static unsigned flags;
48 struct queue_entry *queue;
49 struct queue_entry *playing;
50 struct queue_entry *recent;
69 /** @brief Fetch cachable data */
70 void lookup(unsigned want) {
71 unsigned need = want ^ (flags & want);
72 struct queue_entry *r, *rnext;
79 disorder_queue(client, &queue);
81 disorder_playing(client, &playing);
83 disorder_new_tracks(client, &new, &nnew, 0);
84 if(need & DC_RECENT) {
85 /* we need to reverse the order of the list */
86 disorder_recent(client, &r);
95 disorder_get_volume(client,
96 &volume_left, &volume_right);
97 /* DC_FILES and DC_DIRS are looking obsolete now */
98 if(need & (DC_FILES|DC_DIRS)) {
99 if(!(dir = cgi_get("directory")))
101 re = cgi_get("regexp");
103 if(disorder_directories(client, dir, re,
107 if(disorder_files(client, dir, re,
111 if(need & DC_RIGHTS) {
112 rights = RIGHT_READ; /* fail-safe */
113 if(!disorder_userinfo(client, disorder_user(client),
114 "rights", &rights_string))
115 parse_rights(rights_string, &rights, 1);
117 if(need & DC_ENABLED)
118 disorder_enabled(client, &enabled);
119 if(need & DC_RANDOM_ENABLED)
120 disorder_random_enabled(client, &random_enabled);
121 if(need & DC_RANDOM_ENABLED)
125 void lookup_reset(void) {
126 /* Junk the old connection if there is one */
128 disorder_close(client);
129 /* Create a new connection */
130 client = disorder_new(0);
131 /* Forget everything we knew */