]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-timestamp.c
Allow timestamp to search for channel timestamps as well.
[irc/quakenet/newserv.git] / newsearch / ns-timestamp.c
index 0598eb2c695e889e4b06dc2e0d09410056e82008..5cddecd120c3fd6c0532e23cfcb4ffd20e565cba 100644 (file)
 #include "../irc/irc_config.h"
 #include "../lib/irc_string.h"
 
-void *timestamp_exe(struct searchNode *thenode, void *theinput);
-void timestamp_free(struct searchNode *thenode);
+void *timestamp_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void timestamp_free(searchCtx *ctx, struct searchNode *thenode);
 
-struct searchNode *timestamp_parse(int type, int argc, char **argv) {
+struct searchNode *timestamp_parse(searchCtx *ctx, int type, int argc, char **argv) {
   struct searchNode *thenode;
 
-  if (type != SEARCHTYPE_NICK) {
-    parseError = "timestamp: this function is only valid for nick searches.";
+  if ((type != SEARCHTYPE_NICK) && (type != SEARCHTYPE_CHANNEL)){
+    parseError = "timestamp: this function is only valid for nick or channel searches.";
     return NULL;
   }
 
@@ -27,19 +27,27 @@ struct searchNode *timestamp_parse(int type, int argc, char **argv) {
   }
 
   thenode->returntype = RETURNTYPE_INT;
-  thenode->localdata = NULL;
+  thenode->localdata = (void *)type;
   thenode->exe = timestamp_exe;
   thenode->free = timestamp_free;
 
   return thenode;
 }
 
-void *timestamp_exe(struct searchNode *thenode, void *theinput) {
+void *timestamp_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
-
-  return (void *)np->timestamp;
+  chanindex *cip = (chanindex *)theinput;
+  
+  if ((int)thenode->localdata == SEARCHTYPE_NICK) {
+    return (void *)np->timestamp;
+  } else {
+    if (cip->channel)
+      return (void *)cip->channel->timestamp;
+    else
+      return 0;
+  }
 }
 
-void timestamp_free(struct searchNode *thenode) {
+void timestamp_free(searchCtx *ctx, struct searchNode *thenode) {
   free(thenode);
 }