* This file is part of DisOrder
* Copyright (C) 2005-2008 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
- * 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.
- *
- * 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
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file lib/trackdb.c
* @brief Track database
#include "unicode.h"
#include "unidata.h"
#include "base64.h"
+#include "sendmail.h"
#define RESCAN "disorder-rescan"
#define DEADLOCK "disorder-deadlock"
/* generic db routines *******************************************************/
-/* fetch and decode a database entry. Returns 0, DB_NOTFOUND or
- * DB_LOCK_DEADLOCK. */
+/** @brief Fetch and decode a database entry
+ * @param db Database
+ * @param track Track name
+ * @param kp Where to put decoded list (or NULL if you don't care)
+ * @param tid Owning transaction
+ * @return 0, @c DB_NOTFOUND or @c DB_LOCK_DEADLOCK
+ */
int trackdb_getdata(DB *db,
const char *track,
struct kvp **kp,
switch(err = db->get(db, tid, make_key(&key, track),
prepare_data(&data), 0)) {
case 0:
- *kp = kvp_urldecode(data.data, data.size);
+ if(kp)
+ *kp = kvp_urldecode(data.data, data.size);
return 0;
case DB_NOTFOUND:
- *kp = 0;
+ if(kp)
+ *kp = 0;
return err;
case DB_LOCK_DEADLOCK:
error(0, "error querying database: %s", db_strerror(err));
* @param ev Event loop or 0 to block
* @param recheck 1 to recheck lengths, 0 to suppress check
* @param rescanned Called on completion (if not NULL)
- * @param u Passed to @p rescanned
+ * @param ru Passed to @p rescanned
*/
void trackdb_rescan(ev_source *ev, int recheck,
void (*rescanned)(void *ru),
* @return null-terminated array of track names, or NULL on deadlock
*
* The most recently added track is first in the array.
- *
- * TODO: exclude tracks that have been deleted again.
- *
*/
static char **trackdb_new_tid(int *ntracksp,
int maxtracks,
DBT k, d;
int err = 0;
struct vector tracks[1];
+ hash *h = hash_new(1);
vector_init(tracks);
c = trackdb_opencursor(trackdb_noticeddb, tid);
while((maxtracks <= 0 || tracks->nvec < maxtracks)
- && !(err = c->c_get(c, prepare_data(&k), prepare_data(&d), DB_PREV)))
- vector_append(tracks, xstrndup(d.data, d.size));
+ && !(err = c->c_get(c, prepare_data(&k), prepare_data(&d), DB_PREV))) {
+ char *const track = xstrndup(d.data, d.size);
+ /* Don't add any track more than once */
+ if(hash_add(h, track, "", HASH_INSERT))
+ continue;
+ /* See if the track still exists */
+ err = trackdb_getdata(trackdb_tracksdb, track, NULL/*kp*/, tid);
+ if(err == DB_NOTFOUND)
+ continue; /* It doesn't, skip it */
+ if(err == DB_LOCK_DEADLOCK)
+ break; /* Doh */
+ vector_append(tracks, track);
+ }
switch(err) {
case 0: /* hit maxtracks */
case DB_NOTFOUND: /* ran out of tracks */
}
} else if(!strcmp(key, "email")) {
if(*value) {
- if(!strchr(value, '@')) {
- error(0, "invalid email address '%s' for user '%s'", user, value);
+ if(!email_valid(value)) {
+ error(0, "invalid email address '%s' for user '%s'", value, user);
return -1;
}
} else