disorder_dbupgrade_DEPENDENCIES=../lib/libdisorder.a
disorder_cgi_SOURCES=macros-disorder.c macros-disorder.h lookup.c \
- lookup.h options.c options.h actions.c actions.h api.c \
+ lookup.h options.c options.h actions.c actions.h login.c \
+ login.h api.c \
api-client.c api-client.h cgimain.c exports.c
disorder_cgi_LDADD=../lib/libdisorder.a \
$(LIBPCRE) $(LIBGCRYPT) $(LIBDL) $(LIBDB)
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
+/** @file server/actions.c
+ * @brief DisOrder web actions
+ *
+ * Actions are anything that the web interface does beyond passive template
+ * expansion and inspection of state recieved from the server. This means
+ * playing tracks, editing prefs etc but also setting extra headers e.g. to
+ * auto-refresh the playing list.
+ */
-#include <config.h>
-#include "types.h"
-
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <time.h>
-#include <ctype.h>
-#include <stddef.h>
-
-#include "hash.h"
-#include "table.h"
-#include "client.h"
-#include "rights.h"
-#include "mem.h"
-#include "sink.h"
-#include "vector.h"
-#include "printf.h"
-#include "actions.h"
-#include "lookup.h"
-#include "url.h"
-#include "configuration.h"
-#include "cgi.h"
-#include "log.h"
-#include "queue.h"
-#include "macros.h"
-#include "macros-disorder.h"
-
-/** @brief Login cookie */
-char *login_cookie;
-
-/** @brief Return a Cookie: header */
-static char *cookie(void) {
- struct dynstr d[1];
- struct url u;
- char *s;
-
- memset(&u, 0, sizeof u);
- dynstr_init(d);
- parse_url(config->url, &u);
- if(login_cookie) {
- dynstr_append_string(d, "disorder=");
- dynstr_append_string(d, login_cookie);
- } else {
- /* Force browser to discard cookie */
- dynstr_append_string(d, "disorder=none;Max-Age=0");
- }
- if(u.path) {
- /* The default domain matches the request host, so we need not override
- * that. But the default path only goes up to the rightmost /, which would
- * cause the browser to expose the cookie to other CGI programs on the same
- * web server. */
- dynstr_append_string(d, ";Version=1;Path=");
- /* Formally we are supposed to quote the path, since it invariably has a
- * slash in it. However Safari does not parse quoted paths correctly, so
- * this won't work. Fortunately nothing else seems to care about proper
- * quoting of paths, so in practice we get with it. (See also
- * parse_cookie() where we are liberal about cookie paths on the way back
- * in.) */
- dynstr_append_string(d, u.path);
- }
- dynstr_terminate(d);
- byte_xasprintf(&s, "Set-Cookie: %s", d->vec);
- return s;
-}
+#include "disorder-cgi.h"
/** @brief Redirect to some other action or URL */
static void redirect(const char *url) {
}
if(printf("Location: %s\n"
"%s\n"
- "\n", url, cookie()) < 0)
+ "\n", url, dcgi_cookie_header()) < 0)
fatal(errno, "error writing to stdout");
}
char *url;
const char *action;
- lookup(DC_PLAYING|DC_QUEUE|DC_ENABLED|DC_RANDOM_ENABLED);
- if(playing
- && playing->state == playing_started /* i.e. not paused */
- && !disorder_length(client, playing->track, &length)
+ dcgi_lookup(DCGI_PLAYING|DCGI_QUEUE|DCGI_ENABLED|DCGI_RANDOM_ENABLED);
+ if(dcgi_playing
+ && dcgi_playing->state == playing_started /* i.e. not paused */
+ && !disorder_length(dcgi_client, dcgi_playing->track, &length)
&& length
- && playing->sofar >= 0) {
+ && dcgi_playing->sofar >= 0) {
/* Try to put the next refresh at the start of the next track. */
time(&now);
- fin = now + length - playing->sofar + config->gap;
+ fin = now + length - dcgi_playing->sofar + config->gap;
if(now + refresh > fin)
refresh = fin - now;
}
- if(queue && queue->state == playing_isscratch) {
+ if(dcgi_queue && dcgi_queue->state == playing_isscratch) {
/* next track is a scratch, don't leave more than the inter-track gap */
if(refresh > config->gap)
refresh = config->gap;
}
- if(!playing
- && ((queue
- && queue->state != playing_random)
- || random_enabled)
- && enabled) {
+ if(!dcgi_playing
+ && ((dcgi_queue
+ && dcgi_queue->state != playing_random)
+ || dcgi_random_enabled)
+ && dcgi_enabled) {
/* no track playing but playing is enabled and there is something coming
* up, must be in a gap */
if(refresh > config->gap)
"Refresh: %ld;url=%s\n"
"%s\n"
"\n",
- refresh, url, cookie()) < 0)
+ refresh, url, dcgi_cookie_header()) < 0)
fatal(errno, "error writing to stdout");
- disorder_cgi_expand(action ? action : "playing");
+ dcgi_expand(action ? action : "playing");
+}
+
+static void act_disable(void) {
+ if(dcgi_client)
+ disorder_disable(dcgi_client);
+ redirect(0);
+}
+
+static void act_enable(void) {
+ if(dcgi_client)
+ disorder_enable(dcgi_client);
+ redirect(0);
+}
+
+static void act_random_disable(void) {
+ if(dcgi_client)
+ disorder_random_disable(dcgi_client);
+ redirect(0);
+}
+
+static void act_random_enable(void) {
+ if(dcgi_client)
+ disorder_random_enable(dcgi_client);
+ redirect(0);
}
/** @brief Table of actions */
/** @brief Action handler */
void (*handler)(void);
} actions[] = {
-#if 0
- { "confirm", act_confirm },
{ "disable", act_disable },
- { "edituser", act_edituser },
{ "enable", act_enable },
- { "login", act_login },
- { "logout", act_logout },
{ "manage", act_playing },
- { "move", act_move },
- { "pause", act_pause },
- { "play", act_play },
-#endif
{ "playing", act_playing },
-#if 0
- { "prefs", act_prefs },
{ "random-disable", act_random_disable },
{ "random-enable", act_random_enable },
- { "register", act_register },
- { "reminder", act_reminder },
- { "remove", act_remove },
- { "resume", act_resume },
- { "scratch", act_scratch },
- { "volume", act_volume },
-#endif
};
/** @brief Expand a template
* @param name Base name of template, or NULL to consult CGI args
*/
-void disorder_cgi_expand(const char *name) {
+void dcgi_expand(const char *name) {
const char *p;
/* For unknown actions check that they aren't evil */
*
* If no recognized action is specified then 'playing' is assumed.
*/
-void disorder_cgi_action(const char *action) {
+void dcgi_action(const char *action) {
int n;
/* Consult CGI args if caller had no view */
/* Just expand the template */
if(printf("Content-Type: text/html\n"
"%s\n"
- "\n", cookie()) < 0)
+ "\n", dcgi_cookie_header()) < 0)
fatal(errno, "error writing to stdout");
- disorder_cgi_expand(action);
+ dcgi_expand(action);
}
}
/** @brief Generate an error page */
-void disorder_cgi_error(const char *msg, ...) {
+void dcgi_error(const char *msg, ...) {
va_list ap;
va_start(ap, msg);
- byte_xvasprintf(&error_string, msg, ap);
+ byte_xvasprintf(&dcgi_error_string, msg, ap);
va_end(ap);
- disorder_cgi_expand("error");
-}
-
-/** @brief Log in as the current user or guest if none */
-void disorder_cgi_login(void) {
- /* Junk old data */
- lookup_reset();
- /* Reconnect */
- if(disorder_connect_cookie(client, login_cookie)) {
- disorder_cgi_error("Cannot connect to server");
- exit(0);
- }
- /* If there was a cookie but it went bad, we forget it */
- if(login_cookie && !strcmp(disorder_user(client), "guest"))
- login_cookie = 0;
+ dcgi_expand("error");
}
/*
+++ /dev/null
-/*
- * This file is part of DisOrder.
- * Copyright (C) 2004-2008 Richard Kettlewell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-#ifndef ACTIONS_H
-#define ACTIONS_H
-
-extern char *login_cookie;
-
-void disorder_cgi_expand(const char *name);
-void disorder_cgi_action(const char *action);
-void disorder_cgi_error(const char *msg, ...);
-void disorder_cgi_login(void);
-
-#endif /* ACTIONS_H */
-
-/*
-Local Variables:
-c-basic-offset:2
-comment-column:40
-fill-column:79
-indent-tabs-mode:nil
-End:
-*/
* @brief DisOrder CGI
*/
-#include <config.h>
-#include "types.h"
-
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <locale.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "client.h"
-#include "sink.h"
-#include "hash.h"
-#include "mem.h"
-#include "log.h"
-#include "configuration.h"
-#include "disorder.h"
-#include "api-client.h"
-#include "mime.h"
-#include "printf.h"
-#include "url.h"
-#include "macros.h"
-#include "macros-disorder.h"
-#include "cgi.h"
-#include "actions.h"
-#include "defs.h"
+#include "disorder-cgi.h"
/** @brief Return true if @p a is better than @p b
*
best_cookie = n;
}
if(best_cookie != -1)
- login_cookie = cd.cookies[best_cookie].value;
+ dcgi_cookie = cd.cookies[best_cookie].value;
} else
error(0, "could not parse cookie field '%s'", cookie_env);
}
/* Register expansions */
mx_register_builtin();
- register_disorder_expansions();
+ dcgi_expansions();
/* Update search path. We look in the config directory first and the data
* directory second, so that the latter overrides the former. */
mx_search_path(pkgconfdir);
fatal(errno, "error writing to stdout");
/* Create the initial connection, trying the cookie if we found a suitable
* one. */
- disorder_cgi_login();
+ dcgi_login();
/* The main program... */
- disorder_cgi_action(NULL);
+ dcgi_action(NULL);
/* In practice if a write fails that probably means the web server went away,
* but we log it anyway. */
if(fclose(stdout) < 0)
--- /dev/null
+/*
+ * This file is part of DisOrder.
+ * Copyright (C) 2004-2008 Richard Kettlewell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+/** @file server/disorder-cgi.h
+ * @brief Shared header for DisOrder CGI program
+ */
+
+#ifndef DISORDER_CGI_H
+#define DISORDER_CGI_H
+
+#include <config.h>
+#include "types.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <time.h>
+#include <errno.h>
+#include <ctype.h>
+#include <stddef.h>
+
+#include "mem.h"
+#include "kvp.h"
+#include "queue.h"
+#include "rights.h"
+#include "sink.h"
+#include "client.h"
+#include "cgi.h"
+#include "hash.h"
+#include "macros.h"
+#include "printf.h"
+#include "defs.h"
+#include "configuration.h"
+#include "trackname.h"
+#include "table.h"
+#include "vector.h"
+#include "url.h"
+#include "log.h"
+#include "inputline.h"
+#include "split.h"
+#include "mime.h"
+
+extern disorder_client *dcgi_client;
+extern char *dcgi_cookie;
+extern char *dcgi_error_string;
+
+void dcgi_expand(const char *name);
+void dcgi_action(const char *action);
+void dcgi_error(const char *msg, ...);
+void dcgi_login(void);
+void dcgi_lookup(unsigned want);
+void dcgi_lookup_reset(void);
+void dcgi_expansions(void);
+char *dcgi_cookie_header(void);
+void dcgi_login(void);
+
+void option_set(const char *name, const char *value);
+const char *option_label(const char *key);
+int option_label_exists(const char *key);
+char **option_columns(const char *name, int *ncolumns);
+
+#define DCGI_QUEUE 0x0001
+#define DCGI_PLAYING 0x0002
+#define DCGI_RECENT 0x0004
+#define DCGI_VOLUME 0x0008
+#if 0
+#define DCGI_DIRS 0x0010
+#define DCGI_FILES 0x0020
+#endif
+#define DCGI_NEW 0x0040
+#define DCGI_RIGHTS 0x0080
+#define DCGI_ENABLED 0x0100
+#define DCGI_RANDOM_ENABLED 0x0200
+
+extern struct queue_entry *dcgi_queue;
+extern struct queue_entry *dcgi_playing;
+extern struct queue_entry *dcgi_recent;
+
+extern int dcgi_volume_left;
+extern int dcgi_volume_right;
+
+extern char **dcgi_new;
+extern int dcgi_nnew;
+
+extern rights_type dcgi_rights;
+
+extern int dcgi_enabled;
+extern int dcgi_random_enabled;
+
+#endif /* DISORDER_CGI_H */
+
+/*
+Local Variables:
+c-basic-offset:2
+comment-column:40
+fill-column:79
+indent-tabs-mode:nil
+End:
+*/
--- /dev/null
+/*
+ * This file is part of DisOrder.
+ * Copyright (C) 2008 Richard Kettlewell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "disorder-cgi.h"
+
+/** @brief Client used by CGI
+ *
+ * The caller should arrange for this to be created before any of
+ * these expansions are used (if it cannot connect then it's safe to
+ * leave it as NULL).
+ */
+disorder_client *dcgi_client;
+
+/** @brief Login cookie */
+char *dcgi_cookie;
+
+/** @brief Return a Cookie: header */
+char *dcgi_cookie_header(void) {
+ struct dynstr d[1];
+ struct url u;
+ char *s;
+
+ memset(&u, 0, sizeof u);
+ dynstr_init(d);
+ parse_url(config->url, &u);
+ if(dcgi_cookie) {
+ dynstr_append_string(d, "disorder=");
+ dynstr_append_string(d, dcgi_cookie);
+ } else {
+ /* Force browser to discard cookie */
+ dynstr_append_string(d, "disorder=none;Max-Age=0");
+ }
+ if(u.path) {
+ /* The default domain matches the request host, so we need not override
+ * that. But the default path only goes up to the rightmost /, which would
+ * cause the browser to expose the cookie to other CGI programs on the same
+ * web server. */
+ dynstr_append_string(d, ";Version=1;Path=");
+ /* Formally we are supposed to quote the path, since it invariably has a
+ * slash in it. However Safari does not parse quoted paths correctly, so
+ * this won't work. Fortunately nothing else seems to care about proper
+ * quoting of paths, so in practice we get with it. (See also
+ * parse_cookie() where we are liberal about cookie paths on the way back
+ * in.) */
+ dynstr_append_string(d, u.path);
+ }
+ dynstr_terminate(d);
+ byte_xasprintf(&s, "Set-Cookie: %s", d->vec);
+ return s;
+}
+
+/** @brief Log in as the current user or guest if none */
+void dcgi_login(void) {
+ /* Junk old data */
+ dcgi_lookup_reset();
+ /* Junk the old connection if there is one */
+ if(dcgi_client)
+ disorder_close(dcgi_client);
+ /* Create a new connection */
+ dcgi_client = disorder_new(0);
+ /* Reconnect */
+ if(disorder_connect_cookie(dcgi_client, dcgi_cookie)) {
+ dcgi_error("Cannot connect to server");
+ exit(0);
+ }
+ /* If there was a cookie but it went bad, we forget it */
+ if(dcgi_cookie && !strcmp(disorder_user(dcgi_client), "guest"))
+ dcgi_cookie = 0;
+}
+
+/*
+Local Variables:
+c-basic-offset:2
+comment-column:40
+fill-column:79
+indent-tabs-mode:nil
+End:
+*/
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
-/** @file server/macros-disorder.c
- * @brief DisOrder-specific expansions
- */
-
-#include <config.h>
-#include "types.h"
-
-#include <stdio.h>
-#include <string.h>
-
-#include "queue.h"
-#include "sink.h"
-#include "client.h"
-#include "rights.h"
-#include "lookup.h"
-#include "cgi.h"
-
-/** @brief Client used by CGI
+/** @file server/lookup.c
+ * @brief Server lookups
*
- * The caller should arrange for this to be created before any of
- * these expansions are used (if it cannot connect then it's safe to
- * leave it as NULL).
+ * To improve performance many server lookups are cached.
*/
-disorder_client *client;
+
+#include "disorder-cgi.h"
/** @brief Cached data */
static unsigned flags;
-struct queue_entry *queue;
-struct queue_entry *playing;
-struct queue_entry *recent;
-
-int volume_left;
-int volume_right;
-
-char **files;
-int nfiles;
+struct queue_entry *dcgi_queue;
+struct queue_entry *dcgi_playing;
+struct queue_entry *dcgi_recent;
-char **dirs;
-int ndirs;
+int dcgi_volume_left;
+int dcgi_volume_right;
-char **new;
-int nnew;
+char **dcgi_new;
+int dcgi_nnew;
-rights_type rights;
+rights_type dcgi_rights;
-int enabled;
-int random_enabled;
+int dcgi_enabled;
+int dcgi_random_enabled;
/** @brief Fetch cachable data */
-void lookup(unsigned want) {
+void dcgi_lookup(unsigned want) {
unsigned need = want ^ (flags & want);
struct queue_entry *r, *rnext;
+#if 0
const char *dir, *re;
- char *rights_string;
+#endif
+ char *rs;
- if(!client || !need)
+ if(!dcgi_client || !need)
return;
- if(need & DC_QUEUE)
- disorder_queue(client, &queue);
- if(need & DC_PLAYING)
- disorder_playing(client, &playing);
- if(need & DC_NEW)
- disorder_new_tracks(client, &new, &nnew, 0);
- if(need & DC_RECENT) {
+ if(need & DCGI_QUEUE)
+ disorder_queue(dcgi_client, &dcgi_queue);
+ if(need & DCGI_PLAYING)
+ disorder_playing(dcgi_client, &dcgi_playing);
+ if(need & DCGI_NEW)
+ disorder_new_tracks(dcgi_client, &dcgi_new, &dcgi_nnew, 0);
+ if(need & DCGI_RECENT) {
/* we need to reverse the order of the list */
- disorder_recent(client, &r);
+ disorder_recent(dcgi_client, &r);
while(r) {
rnext = r->next;
- r->next = recent;
- recent = r;
+ r->next = dcgi_recent;
+ dcgi_recent = r;
r = rnext;
}
}
- if(need & DC_VOLUME)
- disorder_get_volume(client,
- &volume_left, &volume_right);
- /* DC_FILES and DC_DIRS are looking obsolete now */
- if(need & (DC_FILES|DC_DIRS)) {
+ if(need & DCGI_VOLUME)
+ disorder_get_volume(dcgi_client,
+ &dcgi_volume_left, &dcgi_volume_right);
+#if 0
+ /* DCGI_FILES and DCGI_DIRS are looking obsolete now */
+ if(need & (DCGI_FILES|DCGI_DIRS)) {
if(!(dir = cgi_get("directory")))
dir = "";
re = cgi_get("regexp");
- if(need & DC_DIRS)
- if(disorder_directories(client, dir, re,
+ if(need & DCGI_DIRS)
+ if(disorder_directories(dcgi_client, dir, re,
&dirs, &ndirs))
ndirs = 0;
- if(need & DC_FILES)
- if(disorder_files(client, dir, re,
+ if(need & DCGI_FILES)
+ if(disorder_files(dcgi_client, dir, re,
&files, &nfiles))
nfiles = 0;
}
- if(need & DC_RIGHTS) {
- rights = RIGHT_READ; /* fail-safe */
- if(!disorder_userinfo(client, disorder_user(client),
- "rights", &rights_string))
- parse_rights(rights_string, &rights, 1);
+#endif
+ if(need & DCGI_RIGHTS) {
+ dcgi_rights = RIGHT_READ; /* fail-safe */
+ if(!disorder_userinfo(dcgi_client, disorder_user(dcgi_client),
+ "rights", &rs))
+ parse_rights(rs, &dcgi_rights, 1);
}
- if(need & DC_ENABLED)
- disorder_enabled(client, &enabled);
- if(need & DC_RANDOM_ENABLED)
- disorder_random_enabled(client, &random_enabled);
- if(need & DC_RANDOM_ENABLED)
+ if(need & DCGI_ENABLED)
+ disorder_enabled(dcgi_client, &dcgi_enabled);
+ if(need & DCGI_RANDOM_ENABLED)
+ disorder_random_enabled(dcgi_client, &dcgi_random_enabled);
flags |= need;
}
-void lookup_reset(void) {
- /* Junk the old connection if there is one */
- if(client)
- disorder_close(client);
- /* Create a new connection */
- client = disorder_new(0);
+void dcgi_lookup_reset(void) {
/* Forget everything we knew */
flags = 0;
+ dcgi_recent = 0;
+ dcgi_queue = 0;
+ dcgi_playing = 0;
+ dcgi_rights = 0;
+ dcgi_new = 0;
+ dcgi_nnew = 0;
+ dcgi_enabled = 0;
+ dcgi_random_enabled = 0;
+ dcgi_volume_left = dcgi_volume_right = 0;
}
+++ /dev/null
-/*
- * This file is part of DisOrder.
- * Copyright (C) 2008 Richard Kettlewell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-/** @file server/lookup.h
- * @brief Server lookup code for CGI
- */
-
-#ifndef LOOKUP_H
-#define LOOKUP_H
-
-extern disorder_client *client;
-
-#define DC_QUEUE 0x0001
-#define DC_PLAYING 0x0002
-#define DC_RECENT 0x0004
-#define DC_VOLUME 0x0008
-#define DC_DIRS 0x0010
-#define DC_FILES 0x0020
-#define DC_NEW 0x0040
-#define DC_RIGHTS 0x0080
-#define DC_ENABLED 0x0100
-#define DC_RANDOM_ENABLED 0x0200
-
-extern struct queue_entry *queue;
-extern struct queue_entry *playing;
-extern struct queue_entry *recent;
-
-extern int volume_left;
-extern int volume_right;
-
-extern char **files;
-extern int nfiles;
-
-extern char **dirs;
-extern int ndirs;
-
-extern char **new;
-extern int nnew;
-
-extern rights_type rights;
-
-extern int enabled;
-extern int random_enabled;
-
-void lookup(unsigned want);
-void lookup_reset(void);
-
-#endif /* LOOKUP_H */
-
-/*
-Local Variables:
-c-basic-offset:2
-comment-column:40
-fill-column:79
-indent-tabs-mode:nil
-End:
-*/
* @brief DisOrder-specific expansions
*/
-#include <config.h>
-#include "types.h"
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <time.h>
-
-#include "kvp.h"
-#include "queue.h"
-#include "rights.h"
-#include "sink.h"
-#include "client.h"
-#include "cgi.h"
-#include "hash.h"
-#include "macros.h"
-#include "macros-disorder.h"
-#include "lookup.h"
-#include "printf.h"
-#include "defs.h"
-#include "configuration.h"
-#include "trackname.h"
+#include "disorder-cgi.h"
/** @brief For error template */
-char *error_string;
+char *dcgi_error_string;
/** @brief Locate a track by ID */
static struct queue_entry *findtrack(const char *id) {
struct queue_entry *q;
- lookup(DC_PLAYING);
- if(playing && !strcmp(playing->id, id))
- return playing;
- lookup(DC_QUEUE);
- for(q = queue; q; q = q->next)
+ dcgi_lookup(DCGI_PLAYING);
+ if(dcgi_playing && !strcmp(dcgi_playing->id, id))
+ return dcgi_playing;
+ dcgi_lookup(DCGI_QUEUE);
+ for(q = dcgi_queue; q; q = q->next)
if(!strcmp(q->id, id))
return q;
- lookup(DC_RECENT);
- for(q = recent; q; q = q->next)
+ dcgi_lookup(DCGI_RECENT);
+ for(q = dcgi_recent; q; q = q->next)
if(!strcmp(q->id, id))
return q;
return NULL;
void attribute((unused)) *u) {
const char *v;
- if(client) {
- if(disorder_version(client, (char **)&v))
+ if(dcgi_client) {
+ if(disorder_version(dcgi_client, (char **)&v))
v = "(cannot get version)";
} else
v = "(server not running)";
void attribute((unused)) *u) {
const char *user;
- if(client && (user = disorder_user(client)))
+ if(dcgi_client && (user = disorder_user(dcgi_client)))
return sink_writes(output, cgi_sgmlquote(user)) < 0 ? -1 : 0;
return 0;
}
else
return 0;
}
- if(client
- && !disorder_part(client, &s,
+ if(dcgi_client
+ && !disorder_part(dcgi_client, &s,
track,
!strcmp(context, "short") ? "display" : context,
part))
return -1;
name = q->track;
}
- if(client && disorder_length(client, name, &length))
+ if(dcgi_client && disorder_length(dcgi_client, name, &length))
return sink_printf(output, "%ld:%02ld",
length / 60, length % 60) < 0 ? -1 : 0;
return sink_writes(output, " ") < 0 ? -1 : 0;
struct queue_entry *q = findtrack(args[0]);
/* TODO would be better to reject recent */
- if(!q || !client)
+ if(!q || !dcgi_client)
return mx_bool_result(output, 0);
- lookup(DC_RIGHTS);
+ dcgi_lookup(DCGI_RIGHTS);
return mx_bool_result(output,
- (q == playing ? right_scratchable : right_removable)
- (rights, disorder_user(client), q));
+ (q == dcgi_playing ? right_scratchable : right_removable)
+ (dcgi_rights, disorder_user(dcgi_client), q));
}
/* @movable{ID}
struct queue_entry *q = findtrack(args[0]);
/* TODO would be better to recent playing/recent */
- if(!q || !client)
+ if(!q || !dcgi_client)
return mx_bool_result(output, 0);
- lookup(DC_RIGHTS);
+ dcgi_lookup(DCGI_RIGHTS);
return mx_bool_result(output,
- right_movable(rights, disorder_user(client), q));
+ right_movable(dcgi_rights, disorder_user(dcgi_client), q));
}
/* @playing{TEMPLATE}
const struct mx_node **args,
struct sink *output,
void *u) {
- lookup(DC_PLAYING);
- if(!playing)
+ dcgi_lookup(DCGI_PLAYING);
+ if(!dcgi_playing)
return 0;
if(!nargs)
- return sink_writes(output, playing->id) < 0 ? -1 : 0;
+ return sink_writes(output, dcgi_playing->id) < 0 ? -1 : 0;
return mx_expand(mx_rewritel(args[0],
- "id", playing->id,
- "track", playing->track,
+ "id", dcgi_playing->id,
+ "track", dcgi_playing->track,
(char *)0),
output, u);
}
struct queue_entry *q;
int rc, i;
- lookup(DC_QUEUE);
- for(q = queue, i = 0; q; q = q->next, ++i)
+ dcgi_lookup(DCGI_QUEUE);
+ for(q = dcgi_queue, i = 0; q; q = q->next, ++i)
if((rc = mx_expand(mx_rewritel(args[0],
"id", q->id,
"track", q->track,
"index", make_index(i),
"parity", i % 2 ? "odd" : "even",
- "first", q == queue ? "true" : "false",
+ "first", q == dcgi_queue ? "true" : "false",
"last", q->next ? "false" : "true",
(char *)0),
output, u)))
struct queue_entry *q;
int rc, i;
- lookup(DC_RECENT);
- for(q = recent, i = 0; q; q = q->next, ++i)
+ dcgi_lookup(DCGI_RECENT);
+ for(q = dcgi_recent, i = 0; q; q = q->next, ++i)
if((rc = mx_expand(mx_rewritel(args[0],
"id", q->id,
"track", q->track,
"index", make_index(i),
"parity", i % 2 ? "odd" : "even",
- "first", q == recent ? "true" : "false",
+ "first", q == dcgi_recent ? "true" : "false",
"last", q->next ? "false" : "true",
(char *)0),
output, u)))
void *u) {
int rc, i;
- lookup(DC_NEW);
+ dcgi_lookup(DCGI_NEW);
/* TODO perhaps we should generate an ID value for tracks in the new list */
- for(i = 0; i < nnew; ++i)
+ for(i = 0; i < dcgi_nnew; ++i)
if((rc = mx_expand(mx_rewritel(args[0],
- "track", new[i],
+ "track", dcgi_new[i],
"index", make_index(i),
"parity", i % 2 ? "odd" : "even",
"first", i == 0 ? "true" : "false",
- "last", i == nnew - 1 ? "false" : "true",
+ "last", i == dcgi_nnew - 1 ? "false" : "true",
(char *)0),
output, u)))
return rc;
char **args,
struct sink *output,
void attribute((unused)) *u) {
- lookup(DC_VOLUME);
+ dcgi_lookup(DCGI_VOLUME);
return sink_printf(output, "%d",
!strcmp(args[0], "left")
- ? volume_left : volume_right) < 0 ? -1 : 0;
+ ? dcgi_volume_left : dcgi_volume_right) < 0 ? -1 : 0;
}
/* @isplaying
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- lookup(DC_PLAYING);
- return mx_bool_result(output, !!playing);
+ dcgi_lookup(DCGI_PLAYING);
+ return mx_bool_result(output, !!dcgi_playing);
}
/* @isqueue
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- lookup(DC_QUEUE);
- return mx_bool_result(output, !!queue);
+ dcgi_lookup(DCGI_QUEUE);
+ return mx_bool_result(output, !!dcgi_queue);
}
/* @isrecent@
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- lookup(DC_RECENT);
- return mx_bool_result(output, !!recent);
+ dcgi_lookup(DCGI_RECENT);
+ return mx_bool_result(output, !!dcgi_recent);
}
/* @isnew
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- lookup(DC_NEW);
- return mx_bool_result(output, !!nnew);
+ dcgi_lookup(DCGI_NEW);
+ return mx_bool_result(output, !!dcgi_nnew);
}
/* @pref{TRACK}{KEY}
void attribute((unused)) *u) {
char *value;
- if(client && !disorder_get(client, args[0], args[1], &value))
+ if(dcgi_client && !disorder_get(dcgi_client, args[0], args[1], &value))
return sink_writes(output, cgi_sgmlquote(value)) < 0 ? -1 : 0;
return 0;
}
if((rc = mx_expandstr(args[0], &track, u, "argument #0 (TRACK)")))
return rc;
- if(!client || disorder_prefs(client, track, &head))
+ if(!dcgi_client || disorder_prefs(dcgi_client, track, &head))
return 0;
for(k = head, i = 0; k; k = k->next, ++i)
if((rc = mx_expand(mx_rewritel(args[1],
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- int enabled = 0;
+ int e = 0;
- if(client)
- disorder_enabled(client, &enabled);
- return mx_bool_result(output, enabled);
+ if(dcgi_client)
+ disorder_enabled(dcgi_client, &e);
+ return mx_bool_result(output, e);
}
/* @random-enabled
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- int enabled = 0;
+ int e = 0;
- if(client)
- disorder_random_enabled(client, &enabled);
- return mx_bool_result(output, enabled);
+ if(dcgi_client)
+ disorder_random_enabled(dcgi_client, &e);
+ return mx_bool_result(output, e);
}
/* @trackstate{TRACK}
char *track;
struct queue_entry *q;
- if(!client)
+ if(!dcgi_client)
return 0;
- if(disorder_resolve(client, &track, args[0]))
+ if(disorder_resolve(dcgi_client, &track, args[0]))
return 0;
- lookup(DC_PLAYING);
- if(playing && !strcmp(track, playing->track))
+ dcgi_lookup(DCGI_PLAYING);
+ if(dcgi_playing && !strcmp(track, dcgi_playing->track))
return sink_writes(output, "playing") < 0 ? -1 : 0;
- lookup(DC_QUEUE);
- for(q = queue; q; q = q->next)
+ dcgi_lookup(DCGI_QUEUE);
+ for(q = dcgi_queue; q; q = q->next)
if(!strcmp(track, q->track))
return sink_writes(output, "queued") < 0 ? -1 : 0;
return 0;
void attribute((unused)) *u) {
char *r;
- if(client && !disorder_resolve(client, &r, args[0]))
+ if(dcgi_client && !disorder_resolve(dcgi_client, &r, args[0]))
return sink_writes(output, r) < 0 ? -1 : 0;
return 0;
}
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- lookup(DC_PLAYING);
- return mx_bool_result(output, playing && playing->state == playing_paused);
+ dcgi_lookup(DCGI_PLAYING);
+ return mx_bool_result(output, (dcgi_playing
+ && dcgi_playing->state == playing_paused));
}
/* @state{ID}@
rights_type r;
int rc;
- if(!client)
+ if(!dcgi_client)
return 0;
- lookup(DC_RIGHTS);
+ dcgi_lookup(DCGI_RIGHTS);
if((rc = mx_expandstr(args[0], &right, u, "argument #0 (RIGHT)")))
return rc;
if(parse_rights(right, &r, 1/*report*/))
return 0;
/* Single-argument form */
if(nargs == 1)
- return mx_bool_result(output, !!(r & rights));
+ return mx_bool_result(output, !!(r & dcgi_rights));
/* Multiple argument form */
- if(r & rights)
+ if(r & dcgi_rights)
return mx_expand(args[1], output, u);
if(nargs == 3)
return mx_expand(args[2], output, u);
void attribute((unused)) *u) {
char *v;
- if(client && !disorder_userinfo(client, disorder_user(client), args[0], &v))
+ if(dcgi_client
+ && !disorder_userinfo(dcgi_client, disorder_user(dcgi_client),
+ args[0], &v))
return sink_writes(output, v) < 0 ? -1 : 0;
return 0;
}
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- return sink_writes(output, cgi_sgmlquote(error_string)) < 0 ? -1 : 0;
+ return sink_writes(output, cgi_sgmlquote(dcgi_error_string)) < 0 ? -1 : 0;
}
/** @brief Register DisOrder-specific expansions */
-void register_disorder_expansions(void) {
+void dcgi_expansions(void) {
mx_register("arg", 1, 1, exp_arg);
mx_register("enabled", 0, 0, exp_enabled);
mx_register("error", 0, 0, exp_error);
+++ /dev/null
-/*
- * This file is part of DisOrder.
- * Copyright (C) 2008 Richard Kettlewell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-/** @file server/macros-disorder.h
- * @brief DisOrder-specific expansions
- */
-
-#ifndef MACROS_DISORDER_H
-#define MACROS_DISORDER_H
-
-extern disorder_client *client;
-extern char *error_string;
-void register_disorder_expansions(void);
-
-#endif /* MACROS_DISORDER_H */
-
-/*
-Local Variables:
-c-basic-offset:2
-comment-column:40
-fill-column:79
-indent-tabs-mode:nil
-End:
-*/
*/
/** @file server/options.c
* @brief CGI options
+ *
+ * Options represent an additional configuration system private to the
+ * CGI program.
*/
-#include <config.h>
-#include "types.h"
-
-#include <stdio.h>
-#include <stddef.h>
-#include <errno.h>
-#include <string.h>
-
-#include "mem.h"
-#include "hash.h"
-#include "macros.h"
-#include "options.h"
-#include "split.h"
-#include "table.h"
-#include "log.h"
-#include "inputline.h"
-#include "printf.h"
+#include "disorder-cgi.h"
struct column {
int ncolumns;
+++ /dev/null
-/*
- * This file is part of DisOrder.
- * Copyright (C) 2008 Richard Kettlewell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-/** @file server/options.ch
- * @brief CGI options
- */
-
-#ifndef OPTIONS_H
-#define OPTIONS_H
-
-void option_set(const char *name, const char *value);
-const char *option_label(const char *key);
-int option_label_exists(const char *key);
-char **option_columns(const char *name, int *ncolumns);
-
-#endif /* OPTIONS_H */
-
-/*
-Local Variables:
-c-basic-offset:2
-comment-column:40
-End:
-*/