]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-server.c
CHANSERV: fix issue where chanserv_relay doesn't wait for db to be loaded before...
[irc/quakenet/newserv.git] / newsearch / ns-server.c
index 7748cfb9f2cddc043b464892ca004bb6357257b7..eb44078657c3f58139700a1ca2f5308cc984c012 100644 (file)
 #include "../core/modules.h"
 #include "../server/server.h"
 
-void *server_exe(struct searchNode *thenode, void *theinput);
-void server_free(struct searchNode *thenode);
+void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void server_free(searchCtx *ctx, struct searchNode *thenode);
 
 int ext;
 
-struct searchNode *server_parse(int type, int argc, char **argv) {
+struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv) {
   struct searchNode *thenode;
   int i;
   long numeric;
 
-  if (type != SEARCHTYPE_NICK) {
-    parseError = "server: this function is only valid for nick searches.";
+  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+    parseError = "malloc: could not allocate memory for this search.";
     return NULL;
   }
 
-  if (argc<1) {
-    parseError = "server: usage: server <server name>";
-    return NULL;
-  }
+  if (argc>0) {
+    struct searchNode *servername;
+    char *p;
+    
+    if (!(servername=argtoconststr("server", ctx, argv[0], &p))) {
+      free(thenode);
+      return NULL;
+    }
+     
+    numeric = -1;
+    for(i=0;i<MAXSERVERS;i++) {
+      sstring *n = serverlist[i].name;
+      if(n && !strcmp(n->content, p)) {
+        numeric = i;
+        break;
+      }
+    }
 
-  numeric = -1;
-  for(i=0;i<MAXSERVERS;i++) {
-    sstring *n = serverlist[i].name;
-    if(n && !strcmp(n->content, argv[0])) {
-      numeric = i;
-      break;
+    (servername->free)(ctx, servername);
+    
+    if(numeric == -1) {
+      parseError = "server: server not found.";
+      free(thenode);
+      return NULL;
     }
-  }
 
-  if(numeric == -1) {
-    parseError = "server: server not found.";
-    return NULL;
+    thenode->returntype = RETURNTYPE_BOOL;
+    thenode->localdata = (void *)numeric;
+
+    thenode->exe = server_exe_bool;
+  } else {
+    thenode->returntype = RETURNTYPE_STRING;
+    thenode->localdata = NULL;
+
+    thenode->exe = server_exe_str;
   }
 
-  thenode->returntype = RETURNTYPE_BOOL;
-  thenode->localdata = (void *)numeric;
-  thenode->exe = server_exe;
   thenode->free = server_free;
 
   return thenode;
 }
 
-void *server_exe(struct searchNode *thenode, void *theinput) {
+void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
   long server = (long)thenode->localdata;
 
@@ -65,6 +81,16 @@ void *server_exe(struct searchNode *thenode, void *theinput) {
   return (void *)0;
 }
 
-void server_free(struct searchNode *thenode) {
+void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
+  nick *np = (nick *)theinput;
+  sstring *n = serverlist[homeserver(np->numeric)].name;
+
+  if(!n)
+    return "";
+
+  return n->content;
+}
+
+void server_free(searchCtx *ctx, struct searchNode *thenode) {
   free(thenode);
 }