]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * hostpct functionality | |
3 | */ | |
4 | ||
5 | #include "newsearch.h" | |
6 | ||
7 | #include <stdio.h> | |
8 | #include <stdlib.h> | |
9 | ||
10 | void *hostpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
11 | void hostpct_free(searchCtx *ctx, struct searchNode *thenode); | |
12 | ||
13 | struct searchNode *hostpct_parse(searchCtx *ctx, int argc, char **argv) { | |
14 | struct searchNode *thenode; | |
15 | ||
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."; | |
19 | return NULL; | |
20 | } | |
21 | ||
22 | thenode->returntype = RETURNTYPE_INT; | |
23 | thenode->localdata = NULL; | |
24 | thenode->exe = hostpct_exe; | |
25 | thenode->free = hostpct_free; | |
26 | ||
27 | return thenode; | |
28 | } | |
29 | ||
30 | void *hostpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { | |
31 | int i; | |
32 | unsigned int marker; | |
33 | unsigned int hosts=0; | |
34 | nick *np; | |
35 | chanindex *cip = (chanindex *)theinput; | |
36 | ||
37 | if (cip->channel==NULL) | |
38 | return (void *)0; | |
39 | ||
40 | marker=nexthostmarker(); | |
41 | ||
42 | for (i=0;i<cip->channel->users->hashsize;i++) { | |
43 | if (cip->channel->users->content[i]==nouser) | |
44 | continue; | |
45 | ||
46 | if (!(np=getnickbynumeric(cip->channel->users->content[i]))) | |
47 | continue; | |
48 | ||
49 | if (np->host->marker!=marker) { | |
50 | hosts++; | |
51 | np->host->marker=marker; | |
52 | } | |
53 | } | |
54 | ||
55 | return (void *)(long)((hosts * 100)/cip->channel->users->totalusers); | |
56 | } | |
57 | ||
58 | void hostpct_free(searchCtx *ctx, struct searchNode *thenode) { | |
59 | free(thenode); | |
60 | } | |
61 |