]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-size.c
SearchCtx should contain 'type' - this is to make life easier when defining new searc...
[irc/quakenet/newserv.git] / newsearch / ns-size.c
CommitLineData
24f0affb
IB
1/*
2 * size functionality
3 */
4
5#include "newsearch.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9
c8be5183
CP
10void *size_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
11void size_free(searchCtx *ctx, struct searchNode *thenode);
24f0affb 12
f33f3f52 13struct searchNode *size_parse(searchCtx *ctx, int argc, char **argv) {
24f0affb
IB
14 struct searchNode *thenode;
15
f33f3f52 16 if (ctx->type != SEARCHTYPE_CHANNEL) {
24f0affb
IB
17 parseError = "size: this function is only valid for channel searches.";
18 return NULL;
19 }
20
24f0affb
IB
21 if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
22 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
23 parseError = "malloc: could not allocate memory for this search.";
24f0affb
IB
24 return NULL;
25 }
26
c7f7a584 27 thenode->returntype = RETURNTYPE_INT;
28 thenode->localdata = NULL;
24f0affb
IB
29 thenode->exe = size_exe;
30 thenode->free = size_free;
31
32 return thenode;
33}
34
c8be5183 35void *size_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
24f0affb 36 chanindex *cip = (chanindex *)theinput;
24f0affb 37
c7f7a584 38 if (cip->channel==NULL)
39 return (void *)0;
40
41 return (void *)((unsigned long)cip->channel->users->totalusers);
24f0affb
IB
42}
43
c8be5183 44void size_free(searchCtx *ctx, struct searchNode *thenode) {
24f0affb
IB
45 free(thenode);
46}