chiark / gitweb /
Concentrate knowledge about the `pcre' API in one place.
[disorder] / lib / trackdb.c
index 4afd9257929960eb168fb921d383a906a2968fd5..9e667e2a4ff09c999bcc046aa3b26731fb8bf9e6 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <db.h>
 #include <sys/socket.h>
-#include <pcre.h>
 #include <unistd.h>
 #include <errno.h>
 #include <stddef.h>
@@ -39,6 +38,7 @@
 
 #include "event.h"
 #include "mem.h"
+#include "regexp.h"
 #include "kvp.h"
 #include "log.h"
 #include "vector.h"
@@ -1182,6 +1182,7 @@ static int compute_alias(char **aliasp,
     }
     return 0;
   default:
+    *aliasp = 0;
     return err;
   }
 }
@@ -1253,7 +1254,7 @@ int trackdb_notice(const char *track,
   for(;;) {
     tid = trackdb_begin_transaction();
     err = trackdb_notice_tid(track, path, tid);
-    if((err == DB_LOCK_DEADLOCK)) goto fail;
+    if(err == DB_LOCK_DEADLOCK) goto fail;
     break;
   fail:
     trackdb_abort_transaction(tid);
@@ -1389,6 +1390,7 @@ int trackdb_obsolete(const char *track, DB_TXN *tid) {
 #define H(name) { #name, offsetof(DB_HASH_STAT, name) }
 #define B(name) { #name, offsetof(DB_BTREE_STAT, name) }
 
+/** @brief Table of libdb stats to return */
 static const struct statinfo {
   const char *name;
   size_t offset;
@@ -2237,18 +2239,19 @@ fail:
  * If @p re is NULL then always matches.
  */
 static int track_matches(size_t dl, const char *track, size_t tl,
-                        const pcre *re) {
-  int ovec[3], rc;
+                        const regexp *re) {
+  size_t ovec[3];
+  int rc;
 
   if(!re)
     return 1;
   track += dl + 1;
   tl -= (dl + 1);
-  switch(rc = pcre_exec(re, 0, track, tl, 0, 0, ovec, 3)) {
-  case PCRE_ERROR_NOMATCH: return 0;
+  switch(rc = regexp_match(re, track, tl, 0, ovec, 3)) {
+  case RXERR_NOMATCH: return 0;
   default:
     if(rc < 0) {
-      disorder_error(0, "pcre_exec returned %d, subject '%s'", rc, track);
+      disorder_error(0, "regexp_match returned %d, subject '%s'", rc, track);
       return 0;
     }
     return 1;
@@ -2264,7 +2267,7 @@ static int track_matches(size_t dl, const char *track, size_t tl,
  * @return 0 or DB_LOCK_DEADLOCK
  */
 static int do_list(struct vector *v, const char *dir,
-                   enum trackdb_listable what, const pcre *re, DB_TXN *tid) {
+                   enum trackdb_listable what, const regexp *re, DB_TXN *tid) {
   DBC *cursor;
   DBT k, d;
   size_t dl;
@@ -2362,7 +2365,7 @@ deadlocked:
  * @return List of tracks
  */
 char **trackdb_list(const char *dir, int *np, enum trackdb_listable what,
-                    const pcre *re) {
+                    const regexp *re) {
   DB_TXN *tid;
   int n;
   struct vector v;
@@ -3004,21 +3007,6 @@ void trackdb_gc(void) {
 
 /* user database *************************************************************/
 
-/** @brief Return true if @p user is trusted
- * @param user User to look up
- * @return Nonzero if they are in the 'trusted' list
- *
- * Now used only in upgrade from old versions.
- */
-static int trusted(const char *user) {
-  int n;
-
-  for(n = 0; (n < config->trust.n
-             && strcmp(config->trust.s[n], user)); ++n)
-    ;
-  return n < config->trust.n;
-}
-
 /** @brief Add a user
  * @param user Username
  * @param password Initial password or NULL
@@ -3061,75 +3049,6 @@ static int create_user(const char *user,
   return trackdb_putdata(trackdb_usersdb, user, k, tid, flags);
 }
 
-/** @brief Add one pre-existing user 
- * @param user Username
- * @param password password
- * @param tid Owning transaction
- * @return 0, DB_KEYEXIST or DB_LOCK_DEADLOCK
- *
- * Used only in upgrade from old versions.
- */
-static int one_old_user(const char *user, const char *password,
-                        DB_TXN *tid) {
-  const char *rights;
-
-  /* www-data doesn't get added */
-  if(!strcmp(user, "www-data")) {
-    disorder_info("not adding www-data to user database");
-    return 0;
-  }
-  /* pick rights */
-  if(!strcmp(user, "root"))
-    rights = "all";
-  else if(trusted(user)) {
-    rights_type r;
-
-    parse_rights(config->default_rights, &r, 1);
-    r &= ~(rights_type)(RIGHT_SCRATCH__MASK|RIGHT_MOVE__MASK|RIGHT_REMOVE__MASK);
-    r |= (RIGHT_ADMIN|RIGHT_RESCAN
-          |RIGHT_SCRATCH_ANY|RIGHT_MOVE_ANY|RIGHT_REMOVE_ANY);
-    rights = rights_string(r);
-  } else
-    rights = config->default_rights;
-  return create_user(user, password, rights, 0/*email*/, 0/*confirmation*/,
-                     tid, DB_NOOVERWRITE);
-}
-
-/** @brief Upgrade old users
- * @param tid Owning transaction
- * @return 0 or DB_LOCK_DEADLOCK
- */
-static int trackdb_old_users_tid(DB_TXN *tid) {
-  int n;
-
-  for(n = 0; n < config->allow.n; ++n) {
-    switch(one_old_user(config->allow.s[n].s[0], config->allow.s[n].s[1],
-                        tid)) {
-    case 0:
-      disorder_info("created user %s from 'allow' directive",
-                    config->allow.s[n].s[0]);
-      break;
-    case DB_KEYEXIST:
-      disorder_error(0, "user %s already exists, delete 'allow' directive",
-            config->allow.s[n].s[0]);
-          /* This won't ever become fatal - eventually 'allow' will be
-           * disabled. */
-      break;
-    case DB_LOCK_DEADLOCK:
-      return DB_LOCK_DEADLOCK;
-    }
-  }
-  return 0;
-}
-
-/** @brief Read old 'allow' directives and copy them to the users database */
-void trackdb_old_users(void) {
-  int e;
-
-  if(config->allow.n)
-    WITH_TRANSACTION(trackdb_old_users_tid(tid));
-}
-
 /** @brief Create a root user in the user database if there is none */
 void trackdb_create_root(void) {
   int e;