]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Merge.
authorChris Porter <redacted>
Sat, 4 Oct 2008 00:25:08 +0000 (01:25 +0100)
committerChris Porter <redacted>
Sat, 4 Oct 2008 00:25:08 +0000 (01:25 +0100)
1  2 
trusts/trusts_commands.c

index fcc32fed02abdab94b749f172fd2005eefb899dc,fae479704cc73bfc309ba2f13da50925507b3577..128e03b5c734a5be8d2e050628e02666e78afab5
  #include <stdio.h>
 +#include <string.h>
  #include "../control/control.h"
  #include "../lib/irc_string.h"
 +#include "../lib/strlfunc.h"
  #include "trusts.h"
  
- int trusts_migration_start(TrustDBMigrationCallback, void *);
- void trusts_migration_stop(void);
  static void registercommands(int, void *);
  static void deregistercommands(int, void *);
  
- static void migrate_status(int errcode, void *tag) {
-   long sender = (long)tag;
-   nick *np = getnickbynumeric(sender);
-   if(!np)
-     return;
-   if(!errcode || errcode == MIGRATION_LASTERROR) {
-     if(!errcode) {
-        controlreply(np, "Migration complete.");
-        controlreply(np, "Attempting to reload database. . .");
-     } else {
-       controlreply(np, "An error occured after the database was unloaded, attempting reload. . .");
-     }
-     if(trusts_loaddb()) {
-       controlreply(np, "Database reloaded successfully.");
-     } else {
-       controlreply(np, "An error occured, please reload the module manually.");
-     }
-   } else {
-     controlreply(np, "Error %d occured during migration, commands reregistered.", errcode);
-     registercommands(0, NULL);
-   }
- }
- static int trusts_cmdmigrate(void *source, int cargc, char **cargv) {
-   nick *sender = source;
-   int ret;
-   /* iffy but temporary */
-   ret = trusts_migration_start(migrate_status, (void *)(sender->numeric));
-   if(!ret) {
-     controlreply(sender, "Migration started, commands deregistered.");
-     deregistercommands(0, NULL);
-   } else {
-     controlreply(sender, "Error %d starting migration.", ret);
-   }
-   return CMD_OK;
- }
 +void calculatespaces(int spaces, int width, char *str, char **_prebuf, char **_postbuf) {
 +  static char prebuf[512], postbuf[512];
 +  int spacelen;
 +
 +  if(spaces + 5 >= sizeof(prebuf)) {
 +    prebuf[0] = prebuf[1] = '\0';
 +  } else {
 +    memset(prebuf, ' ', spaces);
 +    prebuf[spaces] = '\0';
 +  }
 +
 +  spacelen = width - (strlen(str) + spaces);
 +  if(spacelen <= 0 || spacelen + 5 >= sizeof(postbuf)) {
 +    postbuf[0] = postbuf[1] = '\0';
 +  } else {
 +    memset(postbuf, ' ', spacelen);
 +    postbuf[spacelen] = '\0';
 +  }
 +
 +  *_prebuf = prebuf;
 +  *_postbuf = postbuf;
 +}
 +
 +static void traverseandmark(unsigned int marker, trusthost *th) {
 +  th->marker = marker;
 +
 +  for(th=th->children;th;th=th->nextbychild) {
 +    th->marker = marker;
 +    traverseandmark(marker, th);
 +  }
 +}
 +
 +static void marktree(array *parents, unsigned int marker, trusthost *th) {
 +  trusthost *pth;
 +
 +  for(pth=th->parent;pth;pth=pth->next) {
 +    trusthost **p2 = (trusthost **)(parents->content);
 +    int i;
 +
 +    /* this eliminates common subtrees */
 +    for(i=0;i<parents->cursi;i++)
 +      if(p2[i] == pth)
 +        break;
 +
 +    if(i == parents->cursi) {
 +      int pos = array_getfreeslot(parents);
 +      ((trusthost **)(parents->content))[pos] = pth;
 +    }
 +
 +    pth->marker = marker;
 +  }
 +
 +  /* sadly we need to recurse down */
 +  traverseandmark(marker, th);
 +}
 +
 +static void outputtree(nick *np, unsigned int marker, trustgroup *originalgroup, trusthost *th, int depth) {
 +  char *cidrstr, *prespacebuf, *postspacebuf, parentbuf[512];
 +
 +  if(th->marker != marker)
 +    return;
 +
 +  cidrstr = trusts_cidr2str(th->ip, th->mask);
 +  calculatespaces(depth + 1, 20 + 1, cidrstr, &prespacebuf, &postspacebuf);
 +
 +  if(th->group == originalgroup) {
 +    prespacebuf[0] = '>';
 +
 +    parentbuf[0] = '\0';
 +  } else {
 +    /* show the ids of other groups */
 +
 +    snprintf(parentbuf, sizeof(parentbuf), "%-10d %s", th->group->id, th->group->name->content);
 +  }
 +
 +  controlreply(np, "%s%s%s %-10d %-10d %-20s%s", prespacebuf, cidrstr, postspacebuf, th->count, th->maxusage, (th->count>0)?"(now)":((th->lastseen>0)?trusts_timetostr(th->lastseen):"(never)"), parentbuf);  
 +
 +  for(th=th->children;th;th=th->nextbychild)
 +    outputtree(np, marker, originalgroup, th, depth + 1);
 +}
 +
  static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) {
    nick *sender = source;
    trustgroup *tg;