]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-size.c
b878d327dd2961bb05c52807022eb8aeec4bf101
[irc/quakenet/newserv.git] / newsearch / ns-size.c
1 /*
2 * size functionality
3 */
4
5 #include "newsearch.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 void *size_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
11 void size_free(searchCtx *ctx, struct searchNode *thenode);
12
13 struct searchNode *size_parse(searchCtx *ctx, int type, int argc, char **argv) {
14 struct searchNode *thenode;
15
16 if (type != SEARCHTYPE_CHANNEL) {
17 parseError = "size: this function is only valid for channel searches.";
18 return NULL;
19 }
20
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.";
24 return NULL;
25 }
26
27 thenode->returntype = RETURNTYPE_INT;
28 thenode->localdata = NULL;
29 thenode->exe = size_exe;
30 thenode->free = size_free;
31
32 return thenode;
33 }
34
35 void *size_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
36 chanindex *cip = (chanindex *)theinput;
37
38 if (cip->channel==NULL)
39 return (void *)0;
40
41 return (void *)((unsigned long)cip->channel->users->totalusers);
42 }
43
44 void size_free(searchCtx *ctx, struct searchNode *thenode) {
45 free(thenode);
46 }