]> jfr.im git - irc/quakenet/newserv.git/blame - patricia/patricia_commands.c
CHANSERV: tell user when they can't attempts to auth any more, and drop max attempts...
[irc/quakenet/newserv.git] / patricia / patricia_commands.c
CommitLineData
f9e9119b
P
1#include <stdio.h>
2#include <stdlib.h>
3#include <stdarg.h>
4#include <string.h>
5#include <time.h>
6
7#include "../nick/nick.h"
8#include "../localuser/localuserchannel.h"
9#include "../core/hooks.h"
10#include "../core/schedule.h"
11#include "../lib/array.h"
12#include "../lib/base64.h"
13#include "../lib/irc_string.h"
14#include "../lib/splitline.h"
15#include "../control/control.h"
5857b2db
P
16#include "../lib/version.h"
17
18MODULE_VERSION("")
f9e9119b 19
f9e9119b 20int nc_cmd_dumptree(void *source, int cargc, char **cargv);
49e374f9 21int nc_cmd_usercount(void *source, int cargc, char **cargv);
f9e9119b
P
22
23void _init() {
95ff6b03
P
24 registercontrolhelpcmd("dumptree", NO_DEVELOPER, 2, &nc_cmd_dumptree,
25 "Dumps diaganostic information on the patricia trie structure\n"
26 "Usage: dumptree <ipv4|ipv6|cidr4|cidr6> [int]\n"
27 "Nodes with prefixies Only:\n"
28 "No arguments - default prints: ptr, ip\n"
29 "1: ptr, prefixptr, bitlen, refcount, ip\n"
30 "2: ptr, bit, usercount, ip\n"
31 "3: ptr, leftptr, rightptr, parentptr\n"
32 "4: ptr, ext0, ext1, ext2, ext3, ext4\n"
33 "All Notes (inc no prefixies):\n"
34 "10: ptr, prefixptr, ip\n"
35 "11: ptr, prefixbitlen, refcount,ip\n"
36 "12: ptr, bitlen, usercount, ip\n"
37 "13: ptr, leftptr, rightptr, parentptr\n"
38 "14: ptr, ext0, ext1, ext2, ext3, ext4");
49e374f9 39 registercontrolhelpcmd("usercount", NO_OPER, 1, &nc_cmd_usercount, "Usage: usercount <ip|cidr>\nDisplays number of users on a given ipv4/6 or cidr4/6");
f9e9119b
P
40}
41
42void _fini() {
f9e9119b 43 deregistercontrolcmd("dumptree", &nc_cmd_dumptree);
49e374f9 44 deregistercontrolcmd("usercount", &nc_cmd_usercount);
f9e9119b
P
45}
46
47int nc_cmd_dumptree(void *source, int cargc, char **cargv) {
48 nick *np=(nick *)source;
49 struct irc_in_addr sin;
50 unsigned char bits;
51 patricia_node_t *head, *node;
52 unsigned int level=0;
53 int i = 0;
54
55 if (cargc < 1) {
49e374f9 56 return CMD_USAGE;
f9e9119b
P
57 }
58
59 if (ipmask_parse(cargv[0], &sin, &bits) == 0) {
60 controlreply(np, "Invalid mask.");
61 return CMD_OK;
62 }
63
64 if (cargc>1) {
65 level=strtoul(cargv[1],NULL,10);
66 }
67
68 head = refnode(iptree, &sin, bits);
69
70 if (level < 10) {
71 PATRICIA_WALK(head, node)
72 {
73 switch (level) {
74 case 0:
75 controlreply(np,"%p: %s", node, IPtostr(node->prefix->sin));
76 break;
77 case 1:
78 controlreply(np,"%p: prefix %p, bit %d, ref_count %d, IP: %s",node, node->prefix,
79 node->prefix->bitlen, node->prefix->ref_count, IPtostr(node->prefix->sin));
80 break;
81 case 2:
82 controlreply(np,"%p: bit: %d, usercount: %d, IP: %s", node, node->bit, node->usercount, IPtostr(node->prefix->sin));
83 break;
84 case 3:
96644df6 85 controlreply(np,"%p: L: %p, R: %p P: %p", node, node->l, node->r, node->parent);
f9e9119b
P
86 break;
87 case 4:
88 controlreply(np,"%p: 0: %p, 1: %p, 2: %p, 3: %p, 4: %p", node,
89 node->exts[0], node->exts[1], node->exts[2], node->exts[3], node->exts[4]);
90 break;
91 default:
92 if( i == 0 ) controlreply(np,"Invalid Level");
93 }
94 if ( i++ > 500) {
95 controlreply(np,"too many... aborting...");
96 break;
97 }
98 }
99 PATRICIA_WALK_END;
100 } else {
101 PATRICIA_WALK_ALL(head, node)
102 {
103 switch (level) {
104 case 10:
105 controlreply(np,"%p: prefix: %p %s", node, node->prefix, node->prefix?IPtostr(node->prefix->sin):"");
106 break;
107 case 11:
108 if(node->prefix)
109 controlreply(np,"%p: prefix bit: %d, ref_count %d, IP: %s",node,
110 node->prefix->bitlen, node->prefix->ref_count, IPtostr(node->prefix->sin));
111 else
112 controlreply(np,"%p: --", node);
113 break;
114 case 12:
115 controlreply(np,"%p: bit: %d, usercount: %d, IP: %s", node, node->bit, node->usercount, node->prefix?IPtostr(node->prefix->sin):"");
116 break;
117 case 13:
96644df6 118 controlreply(np,"%p: L: %p, R: %p P: %p", node, node->l, node->r, node->parent);
f9e9119b
P
119 break;
120 case 14:
121 controlreply(np,"%p%s 0: %p, 1: %p, 2: %p, 3: %p, 4: %p", node, node->prefix?"-":":",
122 node->exts[0], node->exts[1], node->exts[2], node->exts[3], node->exts[4]);
123 break;
124 default:
125 if ( i == 0 ) controlreply(np,"Invalid Level");
126 }
127 if ( i++ > 500) {
128 controlreply(np,"too many... aborting...");
129 break;
130 }
131 }
132 PATRICIA_WALK_END;
133 }
134 derefnode(iptree, head);
4ba87010 135 return CMD_OK;
f9e9119b
P
136}
137
49e374f9 138int nc_cmd_usercount(void *source, int cargc, char **cargv) {
f9e9119b
P
139 nick *np = (nick *)source;
140 struct irc_in_addr sin;
141 unsigned char bits;
129ef059 142 patricia_node_t *head;
f9e9119b
P
143 int count;
144
145 if (cargc < 1) {
49e374f9 146 return CMD_USAGE;
f9e9119b
P
147 }
148
149 if (ipmask_parse(cargv[0], &sin, &bits) == 0) {
150 controlreply(np, "Invalid mask.");
151
152 return CMD_OK;
153 }
154
155 head = refnode(iptree, &sin, bits);
156
96644df6 157 count = head->usercount;
f9e9119b
P
158
159 derefnode(iptree, head);
160
161 controlreply(np, "%d user(s) found.", count);
162
163 return CMD_OK;
164}
165