]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-match.c
CHANSERV: fix issue where chanserv_relay doesn't wait for db to be loaded before...
[irc/quakenet/newserv.git] / newsearch / ns-match.c
index b59c98c227f9c4301395105506db1453cb98049d..d77680c81dd9df7bc22a787d93ff16015bf3f6c2 100644 (file)
@@ -13,10 +13,10 @@ struct match_localdata {
   struct searchNode *patnode;
 };
 
-void *match_exe(struct searchNode *thenode, int type, void *theinput);
-void match_free(struct searchNode *thenode);
+void *match_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void match_free(searchCtx *ctx, struct searchNode *thenode);
 
-struct searchNode *match_parse(int type, int argc, char **argv) {
+struct searchNode *match_parse(searchCtx *ctx, int argc, char **argv) {
   struct match_localdata *localdata;
   struct searchNode *thenode;
   struct searchNode *targnode, *patnode;
@@ -26,16 +26,21 @@ struct searchNode *match_parse(int type, int argc, char **argv) {
     return NULL;
   }
 
-  if (!(targnode = search_parse(type, argv[0])))
+  /* @fixme check this works with new parsing semantics */
+  targnode = ctx->parser(ctx, argv[0]);
+  if (!(targnode = coerceNode(ctx,targnode, RETURNTYPE_STRING)))
     return NULL;
 
-  if (!(patnode = search_parse(type, argv[1]))) {
-    (targnode->free)(targnode);
+  patnode = ctx->parser(ctx, argv[1]);
+  if (!(patnode = coerceNode(ctx,patnode, RETURNTYPE_STRING))) {
+    (targnode->free)(ctx, targnode);
     return NULL;
   }
 
   if (!(localdata=(struct match_localdata *)malloc(sizeof (struct match_localdata)))) {
     parseError = "malloc: could not allocate memory for this search.";
+    (targnode->free)(ctx, targnode);
+    (patnode->free)(ctx, patnode);
     return NULL;
   }
     
@@ -45,6 +50,8 @@ struct searchNode *match_parse(int type, int argc, char **argv) {
   if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
     /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
     parseError = "malloc: could not allocate memory for this search.";
+    (targnode->free)(ctx, targnode);
+    (patnode->free)(ctx, patnode);
     free(localdata);
     return NULL;
   }
@@ -57,36 +64,25 @@ struct searchNode *match_parse(int type, int argc, char **argv) {
   return thenode;
 }
 
-void *match_exe(struct searchNode *thenode, int type, void *theinput) {
+void *match_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   struct match_localdata *localdata;
   char *pattern, *target;
-  int ret;
 
   localdata = thenode->localdata;
   
-  pattern = (char *)(localdata->patnode->exe) (localdata->patnode, RETURNTYPE_STRING, theinput);
-  target  = (char *)(localdata->targnode->exe)(localdata->targnode,RETURNTYPE_STRING, theinput);
+  pattern = (char *)(localdata->patnode->exe) (ctx, localdata->patnode, theinput);
+  target  = (char *)(localdata->targnode->exe)(ctx, localdata->targnode,theinput);
 
-  ret = match2strings(pattern, target);
-
-  switch(type) {
-  default:
-  case RETURNTYPE_INT:
-  case RETURNTYPE_BOOL:
-    return (void *)((long)ret);
-    
-  case RETURNTYPE_STRING:
-    return (ret ? "1" : "");
-  }
+  return (void *)(long)match2strings(pattern, target);
 }
 
-void match_free(struct searchNode *thenode) {
+void match_free(searchCtx *ctx, struct searchNode *thenode) {
   struct match_localdata *localdata;
 
   localdata=thenode->localdata;
 
-  (localdata->patnode->free)(localdata->patnode);
-  (localdata->targnode->free)(localdata->targnode);
+  (localdata->patnode->free)(ctx, localdata->patnode);
+  (localdata->targnode->free)(ctx, localdata->targnode);
   free(localdata);
   free(thenode);
 }