]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-oppct.c
fix sstring leak if PROXYSCAN_MAIL is false
[irc/quakenet/newserv.git] / newsearch / ns-oppct.c
1 /*
2 * oppct functionality
3 */
4
5 #include "newsearch.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 void *oppct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
11 void oppct_free(searchCtx *ctx, struct searchNode *thenode);
12
13 struct searchNode *oppct_parse(searchCtx *ctx, int argc, char **argv) {
14 struct searchNode *thenode;
15
16 if (ctx->type != SEARCHTYPE_CHANNEL) {
17 parseError = "oppct: 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 = oppct_exe;
30 thenode->free = oppct_free;
31
32 return thenode;
33 }
34
35 void *oppct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
36 int i;
37 int ops;
38 chanindex *cip = (chanindex *)theinput;
39
40 if (cip->channel==NULL || cip->channel->users->totalusers==0)
41 return (void *)0;
42
43 ops=0;
44
45 for (i=0;i<cip->channel->users->hashsize;i++) {
46 if (cip->channel->users->content[i]!=nouser) {
47 if (!(cip->channel->users->content[i] & CUMODE_OP)) {
48 ops++;
49 }
50 }
51 }
52
53 return (void *)(long)((ops * 100) / cip->channel->users->totalusers);
54 }
55
56 void oppct_free(searchCtx *ctx, struct searchNode *thenode) {
57 free(thenode);
58 }
59