]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-services.c
patricia trie changes
[irc/quakenet/newserv.git] / newsearch / ns-services.c
CommitLineData
71ad10f8
IB
1/*
2 * services functionality
3 */
4
5#include "newsearch.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9
c8be5183
CP
10void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
11void services_free(searchCtx *ctx, struct searchNode *thenode);
71ad10f8 12
c8be5183 13struct searchNode *services_parse(searchCtx *ctx, int type, int argc, char **argv) {
71ad10f8
IB
14 struct searchNode *thenode;
15
16 if (type != SEARCHTYPE_CHANNEL) {
17 parseError = "services: this function is only valid for channel searches.";
18 return NULL;
19 }
20
71ad10f8
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.";
71ad10f8
IB
24 return NULL;
25 }
26
c7f7a584 27 thenode->returntype = RETURNTYPE_INT;
28 thenode->localdata = NULL;
71ad10f8
IB
29 thenode->exe = services_exe;
30 thenode->free = services_free;
31
32 return thenode;
33}
34
c8be5183 35void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
71ad10f8
IB
36 chanindex *cip = (chanindex *)theinput;
37 nick *np;
71ad10f8 38 int i;
c7f7a584 39 unsigned long count=0;
40
71ad10f8 41 if (cip->channel == NULL)
c7f7a584 42 return (void *)0;
71ad10f8
IB
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;
c7f7a584 50
51 if (IsService(np))
52 count++;
71ad10f8
IB
53 }
54
c7f7a584 55 return (void *)count;
71ad10f8
IB
56}
57
c8be5183 58void services_free(searchCtx *ctx, struct searchNode *thenode) {
71ad10f8
IB
59 free(thenode);
60}
61