]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/db-migration.c
fix indentation
[irc/quakenet/newserv.git] / trusts / db-migration.c
index 62b472aef82af5e3c26b25abe5ffe0fb98f66a83..6ef93afe1c68b6744e73bd570a0b840fcd3e3ad1 100644 (file)
@@ -1,5 +1,6 @@
 #include "../dbapi2/dbapi2.h"
 #include "../core/error.h"
+#include "../core/nsmalloc.h"
 #include "trusts.h"
 
 extern DBAPIConn *trustsdb;
@@ -25,7 +26,7 @@ int trusts_migration_start(TrustDBMigrationCallback callback, void *tag) {
   if(migration)
     return 1;
 
-  cbd = malloc(sizeof(struct callbackdata));
+  cbd = nsmalloc(POOL_TRUSTS, sizeof(struct callbackdata));
   if(!cbd)
     return 2;
 
@@ -39,7 +40,7 @@ int trusts_migration_start(TrustDBMigrationCallback callback, void *tag) {
 
   migration = migration_start(tm_group, tm_host, tm_final, cbd);
   if(!migration) {
-    free(cbd);
+    nsfree(POOL_TRUSTS, cbd);
     return 3;
   }
 
@@ -81,7 +82,7 @@ static void tm_complete(const DBAPIResult *r, void *tag) {
   } else {
     if(!r->success) {
       Error("trusts", ERR_ERROR, "A error occured executing the rename table query.");
-      errcode = 100;
+      errcode = MIGRATION_LASTERROR;
     } else {
       Error("trusts", ERR_INFO, "Migration table copying complete.");
     }
@@ -91,7 +92,7 @@ static void tm_complete(const DBAPIResult *r, void *tag) {
   if(cbd->callback)
     cbd->callback(errcode, cbd->tag);
 
-  free(cbd);
+  nsfree(POOL_TRUSTS, cbd);
 }
 
 static void tm_final(void *tag, int errcode) {
@@ -102,25 +103,13 @@ static void tm_final(void *tag, int errcode) {
     Error("trusts", ERR_ERROR, "Migration error: %d", errcode);
     if(cbd) {
       cbd->callback(errcode, cbd->tag);
-      free(cbd);
+      nsfree(POOL_TRUSTS, cbd);
     }
   } else {
+    trusts_closedb(0);
+
     Error("trusts", ERR_INFO, "Migration completed, copying tables...");
-/*
-    trustsdb->query(trustsdb, cbd?tm_complete:NULL, cbd,
-                    "BEGIN TRANSACTION; DROP TABLE ?; ALTER TABLE ? RENAME TO ?; DROP TABLE ?; ALTER TABLE ? RENAME TO ?; COMMIT;",
-                    "TTsTTs", "groups", "migration_groups", "groups", "hosts", "migration_hosts", "hosts");
-*/
-/*
-    trustsdb->query(trustsdb, cbd?tm_complete:NULL, cbd,
-                    "BEGIN TRANSACTION; DELETE FROM ?; INSERT INTO ? SELECT * FROM ?; DELETE FROM ?; INSERT INTO ? SELECT * FROM ?; COMMIT;",
-                    "TTTTTT", "groups", "groups", "migration_groups", "hosts", "hosts", "migration_hosts");
-*/
-/*
-    trustsdb->query(trustsdb, cbd?tm_complete:NULL, cbd,
-                    "DELETE FROM ?; INSERT INTO ? SELECT * FROM ?; DELETE FROM ?; INSERT INTO ? SELECT * FROM ?;",
-                    "TTTTTT", "groups", "groups", "migration_groups", "hosts", "hosts", "migration_hosts");
-*/
+
     trustsdb->squery(trustsdb, "BEGIN TRANSACTION", "");
     trustsdb->squery(trustsdb, "DROP TABLE ?", "T", "groups");
     trustsdb->squery(trustsdb, "ALTER TABLE ? RENAME TO ?", "Ts", "migration_groups", "groups");