chiark
/
gitweb
/
~mdw
/
disorder
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
server/*.c: Don't try reading per-user configuration.
[disorder]
/
server
/
server-queue.c
diff --git
a/server/server-queue.c
b/server/server-queue.c
index a1fa18109e204e2cf40bbbf8f10aa3d72097047e..763f4f3a65923213a9feadd2672975d833f6dd3a 100644
(file)
--- a/
server/server-queue.c
+++ b/
server/server-queue.c
@@
-1,6
+1,6
@@
/*
* This file is part of DisOrder.
/*
* This file is part of DisOrder.
- * Copyright (C) 2004-200
8
Richard Kettlewell
+ * Copyright (C) 2004-200
9
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
*
* 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
@@
-15,14
+15,23
@@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/** @file server/server-queue.c
+ * @brief Server-specific track queue support
+ */
#include "disorder-server.h"
/* the head of the queue is played next, so normally we add to the tail */
#include "disorder-server.h"
/* the head of the queue is played next, so normally we add to the tail */
-struct queue_entry qhead = { &qhead, &qhead, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+struct queue_entry qhead = {
+ .next = &qhead,
+ .prev = &qhead
+};
/* the head of the recent list is the oldest thing, the tail the most recently
* played */
/* the head of the recent list is the oldest thing, the tail the most recently
* played */
-struct queue_entry phead = { &phead, &phead, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+struct queue_entry phead = {
+ .next = &phead,
+ .prev = &phead
+};
long pcount;
long pcount;
@@
-41,41
+50,66
@@
void queue_fix_sofar(struct queue_entry *q) {
if(q->uptopause == -1) /* Don't know how far thru. */
sofar = -1;
else if(q->lastresumed) /* Has been paused and resumed. */
if(q->uptopause == -1) /* Don't know how far thru. */
sofar = -1;
else if(q->lastresumed) /* Has been paused and resumed. */
- sofar = q->uptopause + time(0) - q->lastresumed;
+ sofar = q->uptopause +
x
time(0) - q->lastresumed;
else /* Currently paused. */
sofar = q->uptopause;
} else /* Never been paused. */
else /* Currently paused. */
sofar = q->uptopause;
} else /* Never been paused. */
- sofar = time(0) - q->played;
+ sofar =
x
time(0) - q->played;
q->sofar = sofar;
}
}
static void queue_read_error(const char *msg,
void *u) {
q->sofar = sofar;
}
}
static void queue_read_error(const char *msg,
void *u) {
- fatal(0, "error parsing queue %s: %s", (const char *)u, msg);
+
disorder_
fatal(0, "error parsing queue %s: %s", (const char *)u, msg);
}
static void queue_do_read(struct queue_entry *head, const char *path) {
char *buffer;
FILE *fp;
struct queue_entry *q;
}
static void queue_do_read(struct queue_entry *head, const char *path) {
char *buffer;
FILE *fp;
struct queue_entry *q;
+ int ver = 0;
if(!(fp = fopen(path, "r"))) {
if(errno == ENOENT)
return; /* no queue */
if(!(fp = fopen(path, "r"))) {
if(errno == ENOENT)
return; /* no queue */
- fatal(errno, "error opening %s", path);
+
disorder_
fatal(errno, "error opening %s", path);
}
head->next = head->prev = head;
while(!inputline(path, fp, &buffer, '\n')) {
}
head->next = head->prev = head;
while(!inputline(path, fp, &buffer, '\n')) {
+ if(buffer[0] == '#') {
+ /* Version indicator */
+ ver = atoi(buffer + 1);
+ continue;
+ }
q = xmalloc(sizeof *q);
queue_unmarshall(q, buffer, queue_read_error, (void *)path);
q = xmalloc(sizeof *q);
queue_unmarshall(q, buffer, queue_read_error, (void *)path);
+ if(ver < 1) {
+ /* Fix up origin field as best we can; will be wrong in some cases but
+ * hopefully not too horribly so. */
+ q->origin = q->submitter ? origin_picked : origin_random;
+ /* Eliminated obsolete states, since they are assumed elsewhere not to be
+ * set. */
+ switch(q->state) {
+ case playing_isscratch:
+ q->origin = origin_scratch;
+ q->state = playing_unplayed;
+ break;
+ case playing_random:
+ q->state = playing_unplayed;
+ break;
+ default:
+ break;
+ }
+ }
if(head == &qhead
&& (!q->track
|| !q->when))
if(head == &qhead
&& (!q->track
|| !q->when))
- fatal(0, "incomplete queue entry in %s", path);
+
disorder_
fatal(0, "incomplete queue entry in %s", path);
queue_insert_entry(head->prev, q);
}
queue_insert_entry(head->prev, q);
}
- if(ferror(fp)) fatal(errno, "error reading %s", path);
+ if(ferror(fp))
+ disorder_fatal(errno, "error reading %s", path);
fclose(fp);
}
fclose(fp);
}
@@
-102,12
+136,15
@@
static void queue_do_write(const struct queue_entry *head, const char *path) {
struct queue_entry *q;
byte_xasprintf(&tmp, "%s.new", path);
struct queue_entry *q;
byte_xasprintf(&tmp, "%s.new", path);
- if(!(fp = fopen(tmp, "w"))) fatal(errno, "error opening %s", tmp);
+ if(!(fp = fopen(tmp, "w"))) disorder_fatal(errno, "error opening %s", tmp);
+ /* Save version indicator */
+ if(fprintf(fp, "#1\n") < 0)
+ disorder_fatal(errno, "error writing %s", tmp);
for(q = head->next; q != head; q = q->next)
if(fprintf(fp, "%s\n", queue_marshall(q)) < 0)
for(q = head->next; q != head; q = q->next)
if(fprintf(fp, "%s\n", queue_marshall(q)) < 0)
- fatal(errno, "error writing %s", tmp);
- if(fclose(fp) < 0) fatal(errno, "error closing %s", tmp);
- if(rename(tmp, path) < 0) fatal(errno, "error replacing %s", path);
+
disorder_
fatal(errno, "error writing %s", tmp);
+ if(fclose(fp) < 0)
disorder_
fatal(errno, "error closing %s", tmp);
+ if(rename(tmp, path) < 0)
disorder_
fatal(errno, "error replacing %s", path);
}
void queue_write(void) {
}
void queue_write(void) {