]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-hostmask.c
LUA: port luadb to dbapi2 to drop postgres dependency
[irc/quakenet/newserv.git] / newsearch / ns-hostmask.c
index ba4a6347d4c324eeb8087159817666c131e5897f..caa66e081c314d0d6b37c649945006ff99e34a31 100644 (file)
 #include "../lib/irc_string.h"
 
 void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
-void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *hostmask_exe_rn(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *hostmask_exe_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *hostmask_exe_rn_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput);
 void hostmask_free(searchCtx *ctx, struct searchNode *thenode);
 
-struct searchNode *hostmask_parse(searchCtx *ctx, int type, int argc, char **argv) {
+struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv) {
   struct searchNode *thenode;
-
-  if (type != SEARCHTYPE_NICK) {
-    parseError = "hostmask: this function is only valid for nick searches.";
-    return NULL;
+  int realhost = 0, realname = 0, i, error = 0;
+  
+  for(i=0;i<argc;i++) {
+    struct searchNode *convsn;
+    char *p;
+    
+    if (!(convsn=argtoconststr("hostmask", ctx, argv[i], &p)))
+      return NULL;
+    
+    if(!ircd_strcmp(p, "realhost")) {
+      realhost = 1;
+    } else if(!ircd_strcmp(p, "realname")) {
+      realname = 1;
+    } else {
+      error = 1;
+    }
+    convsn->free(ctx, convsn);
+    
+    if(error) {
+      parseError = "bad argument: use realhost and/or realname";
+      return NULL;
+    }
   }
 
   if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
@@ -34,13 +54,20 @@ struct searchNode *hostmask_parse(searchCtx *ctx, int type, int argc, char **arg
     free(thenode);
     return NULL;
   }
-  thenode->exe = hostmask_exe;
   thenode->free = hostmask_free;
 
-  /* Allow "hostmask real" to match realhost */
-
-  if (argc>0 && !ircd_strcmp(argv[0],"real")) {
-    thenode->exe = hostmask_exe_real;
+  if(realname) {
+    if(realhost) {
+      thenode->exe = hostmask_exe_rn_rh;
+    } else {
+      thenode->exe = hostmask_exe_rn;
+    }
+  } else {
+    if(realhost) {
+      thenode->exe = hostmask_exe_rh;
+    } else {
+      thenode->exe = hostmask_exe;
+    }
   }
 
   return thenode;
@@ -53,7 +80,16 @@ void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   return visiblehostmask(np, buf);
 }
 
-void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
+void *hostmask_exe_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
+  nick *np = (nick *)theinput;
+  char *buf = thenode->localdata;
+
+  sprintf(buf,"%s!%s@%s",np->nick,np->ident,np->host->name->content);
+
+  return buf;
+}
+
+void *hostmask_exe_rn_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
   char *buf = thenode->localdata;
 
@@ -62,6 +98,15 @@ void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinp
   return buf;
 }
 
+void *hostmask_exe_rn(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
+  nick *np = (nick *)theinput;
+  char *buf = thenode->localdata;
+
+  sprintf(buf,"%s\r%s",visiblehostmask(np, buf),np->realname->name->content);
+
+  return buf;
+}
+
 void hostmask_free(searchCtx *ctx, struct searchNode *thenode) {
   free(thenode->localdata);
   free(thenode);