]>
Commit | Line | Data |
---|---|---|
71ad10f8 IB |
1 | /* |
2 | * services functionality | |
3 | */ | |
4 | ||
5 | #include "newsearch.h" | |
6 | ||
7 | #include <stdio.h> | |
8 | #include <stdlib.h> | |
9 | ||
c8be5183 CP |
10 | void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); |
11 | void services_free(searchCtx *ctx, struct searchNode *thenode); | |
71ad10f8 | 12 | |
f33f3f52 | 13 | struct searchNode *services_parse(searchCtx *ctx, int argc, char **argv) { |
71ad10f8 IB |
14 | struct searchNode *thenode; |
15 | ||
71ad10f8 IB |
16 | if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) { |
17 | /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */ | |
18 | parseError = "malloc: could not allocate memory for this search."; | |
71ad10f8 IB |
19 | return NULL; |
20 | } | |
21 | ||
c7f7a584 | 22 | thenode->returntype = RETURNTYPE_INT; |
23 | thenode->localdata = NULL; | |
71ad10f8 IB |
24 | thenode->exe = services_exe; |
25 | thenode->free = services_free; | |
26 | ||
27 | return thenode; | |
28 | } | |
29 | ||
c8be5183 | 30 | void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
71ad10f8 IB |
31 | chanindex *cip = (chanindex *)theinput; |
32 | nick *np; | |
71ad10f8 | 33 | int i; |
c7f7a584 | 34 | unsigned long count=0; |
35 | ||
71ad10f8 | 36 | if (cip->channel == NULL) |
c7f7a584 | 37 | return (void *)0; |
71ad10f8 IB |
38 | |
39 | for(i=0;i<cip->channel->users->hashsize;i++) { | |
40 | if (cip->channel->users->content[i]==nouser) | |
41 | continue; | |
42 | ||
43 | if (!(np=getnickbynumeric(cip->channel->users->content[i]))) | |
44 | continue; | |
c7f7a584 | 45 | |
46 | if (IsService(np)) | |
47 | count++; | |
71ad10f8 IB |
48 | } |
49 | ||
c7f7a584 | 50 | return (void *)count; |
71ad10f8 IB |
51 | } |
52 | ||
c8be5183 | 53 | void services_free(searchCtx *ctx, struct searchNode *thenode) { |
71ad10f8 IB |
54 | free(thenode); |
55 | } | |
56 |