chiark
/
gitweb
/
~mdw
/
disorder
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge tag 'branchpoint-5.1' into release
[disorder]
/
server
/
schedule.c
diff --git
a/server/schedule.c
b/server/schedule.c
index 6092fb5b227e9dc95b896ae268befc1ea989e387..219fc14b50de3f74179d9c0af61d4c713ef5e69c 100644
(file)
--- a/
server/schedule.c
+++ b/
server/schedule.c
@@
-1,21
+1,19
@@
/*
* This file is part of DisOrder
/*
* This file is part of DisOrder
- * Copyright (C) 2008 Richard Kettlewell
+ * Copyright (C) 2008
-2010
Richard Kettlewell
*
*
- * This program is free software
;
you can redistribute it and/or modify
+ * 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
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation
; either version 2
of the License, or
+ * the Free Software Foundation
, either version 3
of the License, or
* (at your option) any later version.
*
* (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.
- *
+ * 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
+ * G
NU G
eneral Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
* 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file server/schedule.c
*/
/** @file server/schedule.c
@@
-97,6
+95,9
@@
static const char *const schedule_required[] = {"when", "who", "action"};
/** @brief Parse a scheduled event key and data
* @param k Pointer to key
/** @brief Parse a scheduled event key and data
* @param k Pointer to key
+ * @param d Pointer to data
+ * @param idp Where to store event ID
+ * @param actiondatap Where to store parsed data
* @param whenp Where to store timestamp
* @return 0 on success, non-0 on error
*
* @param whenp Where to store timestamp
* @return 0 on success, non-0 on error
*
@@
-113,7
+114,8
@@
static int schedule_parse(const DBT *k,
/* Reject bogus keys */
if(!k->size || k->size > 128) {
/* Reject bogus keys */
if(!k->size || k->size > 128) {
- error(0, "bogus schedule.db key (%lu bytes)", (unsigned long)k->size);
+ disorder_error(0, "bogus schedule.db key (%lu bytes)",
+ (unsigned long)k->size);
return -1;
}
id = xstrndup(k->data, k->size);
return -1;
}
id = xstrndup(k->data, k->size);
@@
-121,8
+123,8
@@
static int schedule_parse(const DBT *k,
/* Reject items without the required fields */
for(n = 0; n < NREQUIRED; ++n) {
if(!kvp_get(actiondata, schedule_required[n])) {
/* Reject items without the required fields */
for(n = 0; n < NREQUIRED; ++n) {
if(!kvp_get(actiondata, schedule_required[n])) {
- error(0, "scheduled event %s: missing required field '%s'",
- id, schedule_required[n]);
+
disorder_
error(0, "scheduled event %s: missing required field '%s'",
+
id, schedule_required[n]);
return -1;
}
}
return -1;
}
}
@@
-145,10
+147,10
@@
static int cdel(DBC *cursor) {
case 0:
break;
case DB_LOCK_DEADLOCK:
case 0:
break;
case DB_LOCK_DEADLOCK:
- error(0, "error deleting from schedule.db: %s", db_strerror(err));
+
disorder_
error(0, "error deleting from schedule.db: %s", db_strerror(err));
break;
default:
break;
default:
- fatal(0, "error deleting from schedule.db: %s", db_strerror(err));
+
disorder_
fatal(0, "error deleting from schedule.db: %s", db_strerror(err));
}
return err;
}
}
return err;
}
@@
-181,13
+183,13
@@
static int schedule_init_tid(ev_source *ev,
}
when.tv_usec = 0;
/* The action might be in the past */
}
when.tv_usec = 0;
/* The action might be in the past */
- if(when.tv_sec < time(0)) {
+ if(when.tv_sec <
x
time(0)) {
const char *priority = kvp_get(actiondata, "priority");
if(priority && !strcmp(priority, "junk")) {
/* Junk actions that are in the past are discarded during startup */
/* TODO recurring events should be handled differently here */
const char *priority = kvp_get(actiondata, "priority");
if(priority && !strcmp(priority, "junk")) {
/* Junk actions that are in the past are discarded during startup */
/* TODO recurring events should be handled differently here */
- info("junk event %s is in the past, discarding", id);
+
disorder_
info("junk event %s is in the past, discarding", id);
if(cdel(cursor))
goto deadlocked;
/* Skip this time */
if(cdel(cursor))
goto deadlocked;
/* Skip this time */
@@
-202,10
+204,10
@@
static int schedule_init_tid(ev_source *ev,
err = 0;
break;
case DB_LOCK_DEADLOCK:
err = 0;
break;
case DB_LOCK_DEADLOCK:
- error(0, "error querying schedule.db: %s", db_strerror(err));
+
disorder_
error(0, "error querying schedule.db: %s", db_strerror(err));
break;
default:
break;
default:
- fatal(0, "error querying schedule.db: %s", db_strerror(err));
+
disorder_
fatal(0, "error querying schedule.db: %s", db_strerror(err));
}
deadlocked:
if(trackdb_closecursor(cursor))
}
deadlocked:
if(trackdb_closecursor(cursor))
@@
-227,8
+229,9
@@
void schedule_init(ev_source *ev) {
/******************************************************************************/
/** @brief Create a scheduled event
/******************************************************************************/
/** @brief Create a scheduled event
- * @param
ev Event loop
+ * @param
id Event ID
* @param actiondata Action data
* @param actiondata Action data
+ * @param tid Containing transaction
*/
static int schedule_add_tid(const char *id,
struct kvp *actiondata,
*/
static int schedule_add_tid(const char *id,
struct kvp *actiondata,
@@
-245,12
+248,12
@@
static int schedule_add_tid(const char *id,
case 0:
break;
case DB_LOCK_DEADLOCK:
case 0:
break;
case DB_LOCK_DEADLOCK:
- error(0, "error updating schedule.db: %s", db_strerror(err));
+
disorder_
error(0, "error updating schedule.db: %s", db_strerror(err));
return err;
case DB_KEYEXIST:
return err;
default:
return err;
case DB_KEYEXIST:
return err;
default:
- fatal(0, "error updating schedule.db: %s", db_strerror(err));
+
disorder_
fatal(0, "error updating schedule.db: %s", db_strerror(err));
}
return 0;
}
}
return 0;
}
@@
-274,8
+277,8
@@
const char *schedule_add(ev_source *ev,
/* Check that the required field are present */
for(n = 0; n < NREQUIRED; ++n) {
if(!kvp_get(actiondata, schedule_required[n])) {
/* Check that the required field are present */
for(n = 0; n < NREQUIRED; ++n) {
if(!kvp_get(actiondata, schedule_required[n])) {
- error(0, "new scheduled event is missing required field '%s'",
- schedule_required[n]);
+
disorder_
error(0, "new scheduled event is missing required field '%s'",
+
schedule_required[n]);
return 0;
}
}
return 0;
}
}
@@
-285,8
+288,8
@@
const char *schedule_add(ev_source *ev,
when.tv_sec = atoll(kvp_get(actiondata, "when"));
when.tv_usec = 0;
/* Reject events in the past */
when.tv_sec = atoll(kvp_get(actiondata, "when"));
when.tv_usec = 0;
/* Reject events in the past */
- if(when.tv_sec <= time(0)) {
- error(0, "new scheduled event is in the past");
+ if(when.tv_sec <=
x
time(0)) {
+
disorder_
error(0, "new scheduled event is in the past");
return 0;
}
do {
return 0;
}
do {
@@
-311,8
+314,8
@@
struct kvp *schedule_get(const char *id) {
/* Check that the required field are present */
for(n = 0; n < NREQUIRED; ++n) {
if(!kvp_get(actiondata, schedule_required[n])) {
/* Check that the required field are present */
for(n = 0; n < NREQUIRED; ++n) {
if(!kvp_get(actiondata, schedule_required[n])) {
- error(0, "scheduled event %s is missing required field '%s'",
- id, schedule_required[n]);
+
disorder_
error(0, "scheduled event %s is missing required field '%s'",
+
id, schedule_required[n]);
return 0;
}
}
return 0;
}
}
@@
-360,19
+363,19
@@
static void schedule_play(ev_source *ev,
/* This stuff has rather a lot in common with c_play() */
if(!track) {
/* This stuff has rather a lot in common with c_play() */
if(!track) {
- error(0, "scheduled event %s: no track field", id);
+
disorder_
error(0, "scheduled event %s: no track field", id);
return;
}
if(!trackdb_exists(track)) {
return;
}
if(!trackdb_exists(track)) {
- error(0, "scheduled event %s: no such track as %s", id, track);
+
disorder_
error(0, "scheduled event %s: no such track as %s", id, track);
return;
}
if(!(track = trackdb_resolve(track))) {
return;
}
if(!(track = trackdb_resolve(track))) {
- error(0, "scheduled event %s: cannot resolve track %s", id, track);
+
disorder_
error(0, "scheduled event %s: cannot resolve track %s", id, track);
return;
}
return;
}
- info("scheduled event %s: %s play %s", id, who, track);
- q = queue_add(track, who, WHERE_START);
+
disorder_
info("scheduled event %s: %s play %s", id, who, track);
+ q = queue_add(track, who, WHERE_START
, NULL, origin_scheduled
);
queue_write();
if(q == qhead.next && playing)
prepare(ev, q);
queue_write();
if(q == qhead.next && playing)
prepare(ev, q);
@@
-387,18
+390,19
@@
static void schedule_set_global(ev_source attribute((unused)) *ev,
const char *value = kvp_get(actiondata, "value");
if(!key) {
const char *value = kvp_get(actiondata, "value");
if(!key) {
- error(0, "scheduled event %s: no key field", id);
+
disorder_
error(0, "scheduled event %s: no key field", id);
return;
}
if(key[0] == '_') {
return;
}
if(key[0] == '_') {
- error(0, "scheduled event %s: cannot set internal global preferences (%s)",
- id, key);
+
disorder_
error(0, "scheduled event %s: cannot set internal global preferences (%s)",
+
id, key);
return;
}
if(value)
return;
}
if(value)
- info("scheduled event %s: %s set-global %s=%s", id, who, key, value);
+ disorder_info("scheduled event %s: %s set-global %s=%s",
+ id, who, key, value);
else
else
- info("scheduled event %s: %s set-global %s unset", id, who, key);
+
disorder_
info("scheduled event %s: %s set-global %s unset", id, who, key);
trackdb_set_global(key, value, who);
}
trackdb_set_global(key, value, who);
}
@@
-418,6
+422,7
@@
static struct {
};
/** @brief Look up a scheduled event
};
/** @brief Look up a scheduled event
+ * @param id Event ID
* @param actiondata Event description
* @return index in schedule_actions[] on success, -1 on error
*
* @param actiondata Event description
* @return index in schedule_actions[] on success, -1 on error
*
@@
-435,27
+440,28
@@
static int schedule_lookup(const char *id,
/* Look up the action */
n = TABLE_FIND(schedule_actions, name, action);
if(n < 0) {
/* Look up the action */
n = TABLE_FIND(schedule_actions, name, action);
if(n < 0) {
- error(0, "scheduled event %s: unrecognized action '%s'", id, action);
+ disorder_error(0, "scheduled event %s: unrecognized action '%s'",
+ id, action);
return -1;
}
/* Find the user */
if(!(userinfo = trackdb_getuserinfo(who))) {
return -1;
}
/* Find the user */
if(!(userinfo = trackdb_getuserinfo(who))) {
- error(0, "scheduled event %s: user '%s' does not exist", id, who);
+
disorder_
error(0, "scheduled event %s: user '%s' does not exist", id, who);
return -1;
}
/* Check that they have suitable rights */
if(!(rights = kvp_get(userinfo, "rights"))) {
return -1;
}
/* Check that they have suitable rights */
if(!(rights = kvp_get(userinfo, "rights"))) {
- error(0, "scheduled event %s: user %s' has no rights???", id, who);
+
disorder_
error(0, "scheduled event %s: user %s' has no rights???", id, who);
return -1;
}
if(parse_rights(rights, &r, 1)) {
return -1;
}
if(parse_rights(rights, &r, 1)) {
- error(0, "scheduled event %s: user %s has invalid rights '%s'",
- id, who, rights);
+
disorder_
error(0, "scheduled event %s: user %s has invalid rights '%s'",
+
id, who, rights);
return -1;
}
if(!(r & schedule_actions[n].right)) {
return -1;
}
if(!(r & schedule_actions[n].right)) {
- error(0, "scheduled event %s: user %s lacks rights for action %s",
- id, who, action);
+
disorder_
error(0, "scheduled event %s: user %s lacks rights for action %s",
+
id, who, action);
return -1;
}
return n;
return -1;
}
return n;
@@
-465,14
+471,12
@@
static int schedule_lookup(const char *id,
static int schedule_trigger(ev_source *ev,
const struct timeval attribute((unused)) *now,
void *u) {
static int schedule_trigger(ev_source *ev,
const struct timeval attribute((unused)) *now,
void *u) {
- const char *
action, *
id = u;
+ const char *id = u;
struct kvp *actiondata = schedule_get(id);
int n;
if(!actiondata)
return 0;
struct kvp *actiondata = schedule_get(id);
int n;
if(!actiondata)
return 0;
- /* schedule_get() enforces these being present */
- action = kvp_get(actiondata, "action");
/* Look up the action */
n = schedule_lookup(id, actiondata);
if(n < 0)
/* Look up the action */
n = schedule_lookup(id, actiondata);
if(n < 0)