]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-age.c
LUA: port luadb to dbapi2 to drop postgres dependency
[irc/quakenet/newserv.git] / newsearch / ns-age.c
1 /*
2 * age functionality
3 */
4
5 #include "../irc/irc.h"
6 #include "newsearch.h"
7
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 void *age_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
12 void age_free(searchCtx *ctx, struct searchNode *thenode);
13
14 struct searchNode *age_parse(searchCtx *ctx, int argc, char **argv) {
15 struct searchNode *thenode;
16
17 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
18 parseError = "malloc: could not allocate memory for this search.";
19 return NULL;
20 }
21
22 thenode->returntype = RETURNTYPE_INT;
23 thenode->localdata = NULL;
24 thenode->exe = age_exe;
25 thenode->free = age_free;
26
27 return thenode;
28 }
29
30 void *age_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
31 nick *np = (nick *)theinput;
32 whowas *ww;
33 time_t ts;
34
35 if (ctx->searchcmd == reg_nicksearch)
36 ts = np->timestamp;
37 else {
38 ww = (whowas *)np->next;
39 ts = ww->timestamp;
40 }
41
42 return (void *)(getnettime() - ts);
43 }
44
45 void age_free(searchCtx *ctx, struct searchNode *thenode) {
46 free(thenode);
47 }
48