]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-services.c
SearchCtx should contain 'type' - this is to make life easier when defining new searc...
[irc/quakenet/newserv.git] / newsearch / ns-services.c
1 /*
2 * services functionality
3 */
4
5 #include "newsearch.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
11 void services_free(searchCtx *ctx, struct searchNode *thenode);
12
13 struct searchNode *services_parse(searchCtx *ctx, int argc, char **argv) {
14 struct searchNode *thenode;
15
16 if (ctx->type != SEARCHTYPE_CHANNEL) {
17 parseError = "services: 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 = services_exe;
30 thenode->free = services_free;
31
32 return thenode;
33 }
34
35 void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
36 chanindex *cip = (chanindex *)theinput;
37 nick *np;
38 int i;
39 unsigned long count=0;
40
41 if (cip->channel == NULL)
42 return (void *)0;
43
44 for(i=0;i<cip->channel->users->hashsize;i++) {
45 if (cip->channel->users->content[i]==nouser)
46 continue;
47
48 if (!(np=getnickbynumeric(cip->channel->users->content[i])))
49 continue;
50
51 if (IsService(np))
52 count++;
53 }
54
55 return (void *)count;
56 }
57
58 void services_free(searchCtx *ctx, struct searchNode *thenode) {
59 free(thenode);
60 }
61