]> jfr.im git - irc/quakenet/newserv.git/commitdiff
trusts changes
authorPaul <redacted>
Thu, 1 Jan 2009 23:43:08 +0000 (23:43 +0000)
committerPaul <redacted>
Thu, 1 Jan 2009 23:43:08 +0000 (23:43 +0000)
--HG--
branch : paul

trusts_newsearch/Makefile.in
trusts_newsearch/formats.c
trusts_newsearch/trusts_newsearch.c
trusts_newsearch/trusts_newsearch.h
trusts_newsearch/trusts_searchcommands.c [new file with mode: 0644]
trusts_newsearch/tsns-istrusted.c [new file with mode: 0644]
trusts_newsearch/tsns-tbid.c [new file with mode: 0644]

index e40294e06a806445cbd699eaa73eb0246a3f3518..09cd21635ab2e712355bde39133e4756bb137f55 100644 (file)
@@ -8,5 +8,5 @@ LDFLAGS+=$(LIBDBAPI)
 
 all: trusts_newsearch.so
 
 
 all: trusts_newsearch.so
 
-trusts_newsearch.so: formats.o tsns-ownerid.o tsns-tgmaxperident.o tsns-thcreated.o tsns-thmodified.o trusts_newsearch.o tsns-tgcreated.o tsns-tgmaxperip.o tsns-thexpire.o tsns-thstartdate.o tsns-currenton.o tsns-tgexpire.o tsns-tgmaxusage.o tsns-thid.o tsns-trusted.o tsns-enforceident.o tsns-tgid.o tsns-tgmodified.o tsns-thlastused.o tsns-maxclones.o tsns-tglastused.o tsns-tgstartdate.o tsns-thmaxusage.o
+trusts_newsearch.so: formats.o tsns-ownerid.o tsns-tgmaxperident.o tsns-thcreated.o tsns-thmodified.o trusts_newsearch.o tsns-tgcreated.o tsns-tgmaxperip.o tsns-thexpire.o tsns-thstartdate.o tsns-currenton.o tsns-tgexpire.o tsns-tgmaxusage.o tsns-thid.o tsns-trusted.o tsns-enforceident.o tsns-tgid.o tsns-tgmodified.o tsns-thlastused.o tsns-maxclones.o tsns-tglastused.o tsns-tgstartdate.o tsns-thmaxusage.o tsns-tbid.o tsns-istrusted.o trusts_searchcommands.o
 
 
index 9595609051d6897c2a6bde64c7deb01e91ed533e..9504ad4f5435b5653a98c1bd3aec98bd0951c9ce 100644 (file)
@@ -11,9 +11,28 @@ void printtrust_group(searchCtx *ctx, nick *sender, patricia_node_t *node) {
 
   if (tgh) {
     tg = tgh->trustgroup;
 
   if (tgh) {
     tg = tgh->trustgroup;
-    ctx->reply(sender,"%s | [%lu] | %lu/%lu", IPtostr(node->prefix->sin), tg->id, tg->currenton, tg->maxusage); 
+    ctx->reply(sender,"%s/%d | [%lu] | %lu/%lu", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)), tg->id, tg->currenton, tg->maxusage); 
   } else { 
   } else { 
-    ctx->reply(sender,"%s | <none>", IPtostr(node->prefix->sin));
+    ctx->reply(sender,"%s/%d | <none>", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)));
   }
 }
 
   }
 }
 
+void printtrust_block(searchCtx *ctx, nick *sender, patricia_node_t *node) {
+  trustblock_t *tb = node->exts[tgb_ext];
+
+  if (tb) {
+    ctx->reply(sender,"%s/%d | [%lu] | %s", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)), tb->id, tb->reason_public ? tb->reason_public->content : "");
+  } else {
+    ctx->reply(sender,"%s/%d | <none>", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)));
+  } 
+}
+
+void printtrust_blockprivate(searchCtx *ctx, nick *sender, patricia_node_t *node) {
+  trustblock_t *tb = node->exts[tgb_ext];
+
+  if (tb) {
+    ctx->reply(sender,"%s/%d | [%lu] | %s", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)), tb->id, tb->reason_private ? tb->reason_private->content : "");
+  } else {
+    ctx->reply(sender,"%s/%d | <none>", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)));
+  }
+}
index 1499718158493fa68f7bce2e1a04b7200ee2b93d..ac52f9043f71c3c6a75110d97a0a847f7b325309 100644 (file)
@@ -3,11 +3,13 @@
 #include <stdarg.h>
 
 #include "trusts_newsearch.h"
 #include <stdarg.h>
 
 #include "trusts_newsearch.h"
-#include "../trusts/trusts.h"
+#include "../trusts2/trusts.h"
 
 
 void _init(void) {
   regdisp(reg_nodesearch, "tg", printtrust_group, 0, "");
 
 
 void _init(void) {
   regdisp(reg_nodesearch, "tg", printtrust_group, 0, "");
+  regdisp(reg_nodesearch, "tb", printtrust_block, 0, "");
+  regdisp(reg_nodesearch, "tbprivate", printtrust_blockprivate, 0, "");
 
   /* TRUSTGROUP */
   registersearchterm(reg_tgsearch, "tgid", tsns_tgid_parse, 0, "Trustgroup ID");
 
   /* TRUSTGROUP */
   registersearchterm(reg_tgsearch, "tgid", tsns_tgid_parse, 0, "Trustgroup ID");
@@ -54,10 +56,19 @@ void _init(void) {
   registersearchterm(reg_nodesearch, "thcreated", tsns_thcreated_parse, 0, "trust host creation timestamp (note: we also store a startdate timestamp)");
   registersearchterm(reg_nodesearch, "thmodified", tsns_thmodified_parse, 0, "trust host last modified timestamp");
 
   registersearchterm(reg_nodesearch, "thcreated", tsns_thcreated_parse, 0, "trust host creation timestamp (note: we also store a startdate timestamp)");
   registersearchterm(reg_nodesearch, "thmodified", tsns_thmodified_parse, 0, "trust host last modified timestamp");
 
+  registersearchterm(reg_nodesearch, "tbid", tsns_tbid_parse, 0, "Trust Block ID");
+
+  registersearchterm(reg_nicksearch, "istrusted", tsns_istrusted_parse, 0, "user is on a trusted host");
+
+  registercontrolhelpcmd("trustlist",10,1,tsns_dotrustlist, "Usage: trustlist <tgid>");
+  registercontrolhelpcmd("trustdenylist",10,1,tsns_dotrustdenylist, "Usage: trustdenylist <tgid>");
+
 }
 
 void _fini(void) {
   unregdisp(reg_nodesearch, "tg", printtrust_group);
 }
 
 void _fini(void) {
   unregdisp(reg_nodesearch, "tg", printtrust_group);
+  unregdisp(reg_nodesearch, "tb", printtrust_block);
+  unregdisp(reg_nodesearch, "tbprivate", printtrust_blockprivate);
 
   deregistersearchterm(reg_tgsearch, "tgid", tsns_tgid_parse);
   deregistersearchterm(reg_tgsearch, "tgstartdate", tsns_tgstartdate_parse);
 
   deregistersearchterm(reg_tgsearch, "tgid", tsns_tgid_parse);
   deregistersearchterm(reg_tgsearch, "tgstartdate", tsns_tgstartdate_parse);
@@ -103,5 +114,11 @@ void _fini(void) {
   deregistersearchterm(reg_nodesearch, "thcreated", tsns_thcreated_parse);
   deregistersearchterm(reg_nodesearch, "thmodified", tsns_thmodified_parse);
 
   deregistersearchterm(reg_nodesearch, "thcreated", tsns_thcreated_parse);
   deregistersearchterm(reg_nodesearch, "thmodified", tsns_thmodified_parse);
 
+  deregistersearchterm(reg_nodesearch, "tbid", tsns_tbid_parse);
+
+  deregistersearchterm(reg_nicksearch, "istrusted", tsns_istrusted_parse);
+
+  deregistercontrolcmd("trustlist",tsns_dotrustlist);
+
 }
 
 }
 
index 4d937de4c23fb05d2f429dc8a737e798b85c50b3..852c83514c93ccd4d5901864b4c07186515b7a6b 100644 (file)
@@ -2,10 +2,12 @@
 #define __TRUSTS_NEWSEARCH_H
 
 #include "../patriciasearch/patriciasearch.h"
 #define __TRUSTS_NEWSEARCH_H
 
 #include "../patriciasearch/patriciasearch.h"
-#include "../trusts/trusts.h"
+#include "../trusts2/trusts.h"
 #include "../trusts_search/trusts_search.h"
 
 void printtrust_group(searchCtx *ctx, nick *sender, patricia_node_t *node);
 #include "../trusts_search/trusts_search.h"
 
 void printtrust_group(searchCtx *ctx, nick *sender, patricia_node_t *node);
+void printtrust_block(searchCtx *ctx, nick *sender, patricia_node_t *node);
+void printtrust_blockprivate(searchCtx *ctx, nick *sender, patricia_node_t *node);
 
 struct searchNode *tsns_trusted_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *tsns_tgid_parse(searchCtx *ctx, int argc, char **argv);
 
 struct searchNode *tsns_trusted_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *tsns_tgid_parse(searchCtx *ctx, int argc, char **argv);
@@ -30,4 +32,11 @@ struct searchNode *tsns_thmaxusage_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *tsns_thmodified_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *tsns_thstartdate_parse(searchCtx *ctx, int argc, char **argv);
 
 struct searchNode *tsns_thmodified_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *tsns_thstartdate_parse(searchCtx *ctx, int argc, char **argv);
 
+struct searchNode *tsns_tbid_parse(searchCtx *ctx, int argc, char **argv);
+
+struct searchNode *tsns_istrusted_parse(searchCtx *ctx, int argc, char **argv);
+
+int tsns_dotrustlist(void *source, int cargc, char **cargv);
+int tsns_dotrustdenylist(void *source, int cargc, char **cargv);
+
 #endif
 #endif
diff --git a/trusts_newsearch/trusts_searchcommands.c b/trusts_newsearch/trusts_searchcommands.c
new file mode 100644 (file)
index 0000000..fc3656a
--- /dev/null
@@ -0,0 +1,59 @@
+#include "trusts_newsearch.h"
+#include "../newsearch/newsearch.h"
+
+static void tsnsmessagewrapper(nick *np, char *format, ...) {
+  char buf[1024];
+  va_list ap;
+
+  va_start(ap, format);
+  vsnprintf(buf, sizeof(buf), format, ap);
+  va_end(ap);
+
+  controlreply(np, "%s", buf);
+}
+
+static void tsnswallwrapper(int level, char *format, ...) {
+  char buf[1024];
+  va_list ap;
+
+  va_start(ap, format);
+  vsnprintf(buf, sizeof(buf), format, ap);
+  va_end(ap);
+
+  controlwall(NO_OPER, level, "%s", buf);
+}
+
+int tsns_dotrustlist(void *source, int cargc, char **cargv) {
+  searchASTExpr tree;
+  searchASTExpr nodes[2];
+  
+  if(cargc < 1) {
+    controlreply(source,"Syntax: trustlist <#groupid>");
+    return CMD_ERROR;
+  }
+
+  if(cargv[0][0]== '#'){
+    tree = NSASTNode(eq_parse, NSASTNode(tsns_tgid_parse), NSASTLiteral(&cargv[0][1]));
+  } else {
+    tree = NSASTNode(eq_parse, NSASTNode(tsns_tgid_parse), NSASTLiteral(cargv[0]));
+  }
+
+//  nodes[0] = NSASTNode(tsns_tgid_parse);
+//  nodes[1] = cargv[0];
+//  tree =
+//      NSASTManualNode(eq_parse, 2, nodes 
+//    );
+  return ast_tgsearch(&tree, tsnsmessagewrapper , source, tsnswallwrapper, printtgfull, NULL, NULL, 1);
+}
+
+int tsns_dotrustdenylist(void *source, int cargc, char **cargv) {
+  searchASTExpr tree;
+
+  tree = NSASTNode(gt_parse, NSASTNode(tsns_tbid_parse), NSASTLiteral("0"));
+
+  if(cargc == 1){ /* just assume -private */
+    return ast_nodesearch(&tree, tsnsmessagewrapper , source, tsnswallwrapper, printtrust_blockprivate, NULL, NULL, 500);
+  } else {
+    return ast_nodesearch(&tree, tsnsmessagewrapper , source, tsnswallwrapper, printtrust_block, NULL, NULL, 500);
+  }
+}
diff --git a/trusts_newsearch/tsns-istrusted.c b/trusts_newsearch/tsns-istrusted.c
new file mode 100644 (file)
index 0000000..d9b51c6
--- /dev/null
@@ -0,0 +1,38 @@
+#include "trusts_newsearch.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void *tsns_istrusted_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void tsns_istrusted_free(searchCtx *ctx, struct searchNode *thenode);
+
+struct searchNode *tsns_istrusted_parse(searchCtx *ctx, int argc, char **argv) {
+  struct searchNode *thenode;
+
+  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+    parseError = "malloc: could not allocate memory for this search.";
+    return NULL;
+  }
+
+  thenode->returntype = RETURNTYPE_BOOL;
+  thenode->localdata = NULL;
+  thenode->exe = tsns_istrusted_exe;
+  thenode->free = tsns_istrusted_free;
+
+  return thenode;
+}
+
+void *tsns_istrusted_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
+  nick *np = theinput;
+
+  trusthost_t *tgh = np->exts[tgn_ext];
+
+  if (!tgh)
+    return (void *)0;
+
+  return (void *)1;
+}
+
+void tsns_istrusted_free(searchCtx *ctx, struct searchNode *thenode) {
+  free(thenode);
+}
diff --git a/trusts_newsearch/tsns-tbid.c b/trusts_newsearch/tsns-tbid.c
new file mode 100644 (file)
index 0000000..b5d1bee
--- /dev/null
@@ -0,0 +1,37 @@
+#include "trusts_newsearch.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void *tsns_tbid_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void tsns_tbid_free(searchCtx *ctx, struct searchNode *thenode);
+
+struct searchNode *tsns_tbid_parse(searchCtx *ctx, int argc, char **argv) {
+  struct searchNode *thenode;
+
+  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+    parseError = "malloc: could not allocate memory for this search.";
+    return NULL;
+  }
+
+  thenode->returntype = RETURNTYPE_INT;
+  thenode->localdata = NULL;
+  thenode->exe = tsns_tbid_exe;
+  thenode->free = tsns_tbid_free;
+
+  return thenode;
+}
+
+void *tsns_tbid_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
+  patricia_node_t *node;
+
+  node = (patricia_node_t *)theinput;
+  if (node->exts[tgb_ext] != NULL)
+    return (void *)(((trustblock_t *)node->exts[tgb_ext])->id);
+  else
+    return (void *)0; /* will cast to a FALSE */
+}
+
+void tsns_tbid_free(searchCtx *ctx, struct searchNode *thenode) {
+  free(thenode);
+}