]>
Commit | Line | Data |
---|---|---|
be2823bc CP |
1 | #include "../control/control.h" |
2 | #include "../nick/nick.h" | |
3 | #include "trusts.h" | |
4 | ||
5 | int trusts_migration_start(TrustDBMigrationCallback, void *); | |
6 | void trusts_migration_stop(void); | |
7 | static void registercommands(void); | |
8 | static void deregistercommands(void); | |
9 | ||
10 | static int commandsregistered; | |
11 | ||
12 | static void migrate_status(int errcode, void *tag) { | |
13 | long sender = (long)tag; | |
14 | nick *np = getnickbynumeric(sender); | |
15 | ||
16 | if(!np) | |
17 | return; | |
18 | ||
19 | if(!errcode) { | |
20 | controlreply(np, "Migration complete."); | |
21 | trusts_reloaddb(); | |
22 | } else { | |
23 | controlreply(np, "Error %d occured during migration.", errcode); | |
24 | registercommands(); | |
25 | } | |
26 | } | |
27 | ||
28 | static int trusts_cmdmigrate(void *source, int cargc, char **cargv) { | |
29 | nick *sender = source; | |
30 | int ret; | |
31 | ||
32 | /* iffy but temporary */ | |
33 | ret = trusts_migration_start(migrate_status, (void *)(sender->numeric)); | |
34 | if(!ret) { | |
35 | controlreply(sender, "Migration started."); | |
36 | deregistercommands(); | |
37 | } else { | |
38 | controlreply(sender, "Error %d starting migration.", ret); | |
39 | } | |
40 | ||
41 | return CMD_OK; | |
42 | } | |
43 | ||
44 | static void dbloaded(int hooknum, void *arg) { | |
45 | registercommands(); | |
46 | } | |
47 | ||
48 | void _init(void) { | |
49 | registerhook(HOOK_TRUSTS_DB_LOADED, dbloaded); | |
50 | ||
51 | if(trustsdbloaded) | |
52 | registercommands(); | |
53 | } | |
54 | ||
55 | void _fini(void) { | |
56 | deregisterhook(HOOK_TRUSTS_DB_LOADED, dbloaded); | |
57 | deregistercommands(); | |
58 | ||
59 | trusts_migration_stop(); | |
60 | } | |
61 | ||
62 | static void registercommands(void) { | |
63 | if(!trustsdbloaded || commandsregistered) | |
64 | return; | |
65 | ||
66 | commandsregistered = 1; | |
67 | registercontrolhelpcmd("trustmigrate", NO_OPER, 0, trusts_cmdmigrate, "Usage: trustmigrate\nCopies trust data from O and reloads the database."); | |
68 | } | |
69 | ||
70 | static void deregistercommands(void) { | |
71 | if(!commandsregistered) | |
72 | return; | |
73 | ||
74 | deregistercontrolcmd("trustmigrate", trusts_cmdmigrate); | |
75 | commandsregistered = 0; | |
76 | } |