]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Add lt and gt operators, and timestamp function to newsearch.
authorChris Porter <redacted>
Wed, 8 Mar 2006 17:32:00 +0000 (17:32 +0000)
committerChris Porter <redacted>
Wed, 8 Mar 2006 17:32:00 +0000 (17:32 +0000)
newsearch/Makefile
newsearch/newsearch.c
newsearch/newsearch.h
newsearch/ns-gt.c [new file with mode: 0644]
newsearch/ns-lt.c [new file with mode: 0644]
newsearch/ns-timestamp.c [new file with mode: 0644]

index 30ce0b7c5936926ad8382d75c3f0cc4c0ce6d5eb..5d511bc06d30656e54249961414ca8278e21516b 100644 (file)
@@ -2,5 +2,5 @@
 .PHONY: all
 all: newsearch.so
 
-newsearch.so: newsearch.o ns-not.o ns-and.o ns-or.o ns-eq.o ns-match.o ns-hostmask.o ns-realname.o ns-modes.o ns-nick.o ns-ident.o ns-regex.o ns-host.o ns-channel.o
+newsearch.so: newsearch.o ns-not.o ns-and.o ns-or.o ns-eq.o ns-match.o ns-hostmask.o ns-realname.o ns-modes.o ns-nick.o ns-ident.o ns-regex.o ns-host.o ns-channel.o ns-lt.o ns-gt.o ns-timestamp.o
        ld -shared -Bdynamic $(LIBPCRE) -o $@ $^
index 85dd2bd823395520b91d83720d19528a489eae32..85ff1072dfc8db77b4a4640271664df3b34bda47 100644 (file)
@@ -29,8 +29,11 @@ void _init() {
   registersearchterm("and",and_parse);
   registersearchterm("not",not_parse);
   registersearchterm("or",or_parse);
-  
+
   registersearchterm("eq",eq_parse);
+
+  registersearchterm("lt",lt_parse);
+  registersearchterm("gt",gt_parse);
  
   /* String operations */
   registersearchterm("match",match_parse);
@@ -43,6 +46,7 @@ void _init() {
   registersearchterm("ident",ident_parse);
   registersearchterm("host",host_parse);
   registersearchterm("channel",channel_parse);
+  registersearchterm("timestamp",timestamp_parse);
 
   /* Nickname / channel operations */
   registersearchterm("modes",modes_parse);
index a2ac44a739a65c13ec0446c6f49a2bf646eff7b1..1519dd4e65310cb88938d5af79a49b0ab0609bf5 100644 (file)
@@ -20,6 +20,8 @@ struct searchNode *and_parse(int type, int argc, char **argv);
 struct searchNode *not_parse(int type, int argc, char **argv);
 struct searchNode *or_parse(int type, int argc, char **argv);
 struct searchNode *eq_parse(int type, int argc, char **argv);
+struct searchNode *lt_parse(int type, int argc, char **argv);
+struct searchNode *gt_parse(int type, int argc, char **argv);
 struct searchNode *match_parse(int type, int argc, char **argv);
 struct searchNode *regex_parse(int type, int argc, char **argv);
 struct searchNode *hostmask_parse(int type, int argc, char **argv);
@@ -29,6 +31,7 @@ struct searchNode *nick_parse(int type, int argc, char **argv);
 struct searchNode *ident_parse(int type, int argc, char **argv);
 struct searchNode *host_parse(int type, int argc, char **argv);
 struct searchNode *channel_parse(int type, int argc, char **argv);
+struct searchNode *timestamp_parse(int type, int argc, char **argv);
 
 
 struct searchNode *search_parse(int type, char *input);
diff --git a/newsearch/ns-gt.c b/newsearch/ns-gt.c
new file mode 100644 (file)
index 0000000..68888c8
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * GT functionality
+ */
+
+#include "newsearch.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+struct gt_localdata {
+  int count;
+  struct searchNode **nodes;
+};
+
+void gt_free(struct searchNode *thenode);
+void *gt_exe(struct searchNode *thenode, int type, void *theinput);
+
+struct searchNode *gt_parse(int type, int argc, char **argv) {
+  struct gt_localdata *localdata;
+  struct searchNode *thenode;
+  int i;
+
+  localdata = (struct gt_localdata *)malloc(sizeof(struct gt_localdata));
+  localdata->nodes = (struct searchNode **)malloc(sizeof(struct searchNode *) * argc);
+  localdata->count = 0;
+  
+  thenode = (struct searchNode *)malloc(sizeof(struct searchNode));
+  
+  thenode->localdata  = localdata;
+  thenode->returntype = RETURNTYPE_BOOL;
+  thenode->exe  = gt_exe;
+  thenode->free = gt_free;
+  
+  for (i=0;i<argc;i++) {
+    if (!(localdata->nodes[i] = search_parse(type, argv[i]))) {
+      gt_free(thenode);
+      return NULL;
+    }
+    localdata->count++;
+  }
+
+  return thenode;
+}
+
+void gt_free(struct searchNode *thenode) {
+  struct gt_localdata *localdata;
+  int i;
+
+  localdata=thenode->localdata;
+  
+  for (i=0;i<localdata->count;i++) {
+    (localdata->nodes[i]->free)(localdata->nodes[i]);
+  }
+  
+  free(localdata->nodes);
+  free(localdata);
+  free(thenode);
+}
+
+void *gt_exe(struct searchNode *thenode, int type, void *theinput) {
+  int i;
+  char *strval;
+  int intval;
+  int rval;
+  struct gt_localdata *localdata;
+  
+  localdata=thenode->localdata;
+  
+  if (localdata->count==0)
+    return trueval(type);
+
+  switch (localdata->nodes[0]->returntype & RETURNTYPE_TYPE) {
+  case RETURNTYPE_INT:
+    intval = (int)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_INT, theinput);
+    for (i=1;i<localdata->count;i++) {
+      if ((int)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_INT, theinput) > intval)
+       return falseval(type);
+    }
+
+    return trueval(type);
+    
+  case RETURNTYPE_STRING:
+    strval = (char *)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_STRING, theinput);
+    for (i=1;i<localdata->count;i++) {
+      if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_STRING, theinput)) > 0)
+       return falseval(type);
+    }
+    
+    return trueval(type);
+
+  default:
+    return falseval(type);
+  }
+}
+
diff --git a/newsearch/ns-lt.c b/newsearch/ns-lt.c
new file mode 100644 (file)
index 0000000..a1c727c
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * GT functionality
+ */
+
+#include "newsearch.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+struct lt_localdata {
+  int count;
+  struct searchNode **nodes;
+};
+
+void lt_free(struct searchNode *thenode);
+void *lt_exe(struct searchNode *thenode, int type, void *theinput);
+
+struct searchNode *lt_parse(int type, int argc, char **argv) {
+  struct lt_localdata *localdata;
+  struct searchNode *thenode;
+  int i;
+
+  localdata = (struct lt_localdata *)malloc(sizeof(struct lt_localdata));
+  localdata->nodes = (struct searchNode **)malloc(sizeof(struct searchNode *) * argc);
+  localdata->count = 0;
+  
+  thenode = (struct searchNode *)malloc(sizeof(struct searchNode));
+  
+  thenode->localdata  = localdata;
+  thenode->returntype = RETURNTYPE_BOOL;
+  thenode->exe  = lt_exe;
+  thenode->free = lt_free;
+  
+  for (i=0;i<argc;i++) {
+    if (!(localdata->nodes[i] = search_parse(type, argv[i]))) {
+      lt_free(thenode);
+      return NULL;
+    }
+    localdata->count++;
+  }
+
+  return thenode;
+}
+
+void lt_free(struct searchNode *thenode) {
+  struct lt_localdata *localdata;
+  int i;
+
+  localdata=thenode->localdata;
+  
+  for (i=0;i<localdata->count;i++) {
+    (localdata->nodes[i]->free)(localdata->nodes[i]);
+  }
+  
+  free(localdata->nodes);
+  free(localdata);
+  free(thenode);
+}
+
+void *lt_exe(struct searchNode *thenode, int type, void *theinput) {
+  int i;
+  char *strval;
+  int intval;
+  int rval;
+  struct lt_localdata *localdata;
+  
+  localdata=thenode->localdata;
+  
+  if (localdata->count==0)
+    return trueval(type);
+
+  switch (localdata->nodes[0]->returntype & RETURNTYPE_TYPE) {
+  case RETURNTYPE_INT:
+    intval = (int)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_INT, theinput);
+    for (i=1;i<localdata->count;i++) {
+      if ((int)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_INT, theinput) < intval)
+       return falseval(type);
+    }
+
+    return trueval(type);
+    
+  case RETURNTYPE_STRING:
+    strval = (char *)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_STRING, theinput);
+    for (i=1;i<localdata->count;i++) {
+      if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_STRING, theinput)) < 0)
+       return falseval(type);
+    }
+    
+    return trueval(type);
+
+  default:
+    return falseval(type);
+  }
+}
+
diff --git a/newsearch/ns-timestamp.c b/newsearch/ns-timestamp.c
new file mode 100644 (file)
index 0000000..97cdd79
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * TIMESTAMP functionality
+ */
+
+#include "newsearch.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../irc/irc_config.h"
+#include "../nick/nick.h"
+#include "../lib/irc_string.h"
+
+void *timestamp_exe(struct searchNode *thenode, int type, void *theinput);
+void *timestamp_exe_real(struct searchNode *thenode, int type, void *theinput);
+void timestamp_free(struct searchNode *thenode);
+
+struct searchNode *timestamp_parse(int type, int argc, char **argv) {
+  struct searchNode *thenode;
+
+  if (type != SEARCHTYPE_NICK) {
+    parseError = "timestamp: this function is only valid for nick searches.";
+    return NULL;
+  }
+
+  thenode=(struct searchNode *)malloc(sizeof (struct searchNode));
+
+  thenode->returntype = RETURNTYPE_INT;
+  thenode->localdata = NULL;
+  thenode->exe = timestamp_exe;
+  thenode->free = timestamp_free;
+
+  return thenode;
+}
+
+void *timestamp_exe(struct searchNode *thenode, int type, void *theinput) {
+  nick *np = (nick *)theinput;
+
+  if (type != RETURNTYPE_INT)
+    return (void *)1;
+
+  return (void *)np->timestamp;
+}
+
+void timestamp_free(struct searchNode *thenode) {
+  free(thenode);
+}