]>
jfr.im git - irc/quakenet/newserv.git/blob - patricia/patricia_commands.c
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"
16 #include "../lib/version.h"
20 int nc_cmd_dumptree ( void * source
, int cargc
, char ** cargv
);
21 int nc_cmd_usercount ( void * source
, int cargc
, char ** cargv
);
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" );
39 registercontrolhelpcmd ( "usercount" , NO_OPER
, 1 , & nc_cmd_usercount
, "Usage: usercount <ip|cidr> \n Displays number of users on a given ipv4/6 or cidr4/6" );
43 deregistercontrolcmd ( "dumptree" , & nc_cmd_dumptree
);
44 deregistercontrolcmd ( "usercount" , & nc_cmd_usercount
);
47 int nc_cmd_dumptree ( void * source
, int cargc
, char ** cargv
) {
48 nick
* np
=( nick
*) source
;
49 struct irc_in_addr sin
;
51 patricia_node_t
* head
, * node
;
59 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
60 controlreply ( np
, "Invalid mask." );
65 level
= strtoul ( cargv
[ 1 ], NULL
, 10 );
68 head
= refnode ( iptree
, & sin
, bits
);
71 PATRICIA_WALK ( head
, node
)
75 controlreply ( np
, " %p : %s " , node
, IPtostr ( node
-> prefix
-> sin
));
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
));
82 controlreply ( np
, " %p : bit: %d , usercount: %d , IP: %s " , node
, node
-> bit
, node
-> usercount
, IPtostr ( node
-> prefix
-> sin
));
85 controlreply ( np
, " %p : L: %p , R: %p P: %p " , node
, node
-> l
, node
-> r
, node
-> parent
);
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 ]);
92 if ( i
== 0 ) controlreply ( np
, "Invalid Level" );
95 controlreply ( np
, "too many... aborting..." );
101 PATRICIA_WALK_ALL ( head
, node
)
105 controlreply ( np
, " %p : prefix: %p %s " , node
, node
-> prefix
, node
-> prefix
? IPtostr ( node
-> prefix
-> sin
): "" );
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
));
112 controlreply ( np
, " %p : --" , node
);
115 controlreply ( np
, " %p : bit: %d , usercount: %d , IP: %s " , node
, node
-> bit
, node
-> usercount
, node
-> prefix
? IPtostr ( node
-> prefix
-> sin
): "" );
118 controlreply ( np
, " %p : L: %p , R: %p P: %p " , node
, node
-> l
, node
-> r
, node
-> parent
);
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 ]);
125 if ( i
== 0 ) controlreply ( np
, "Invalid Level" );
128 controlreply ( np
, "too many... aborting..." );
134 derefnode ( iptree
, head
);
138 int nc_cmd_usercount ( void * source
, int cargc
, char ** cargv
) {
139 nick
* np
= ( nick
*) source
;
140 struct irc_in_addr sin
;
142 patricia_node_t
* head
;
149 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
150 controlreply ( np
, "Invalid mask." );
155 head
= refnode ( iptree
, & sin
, bits
);
157 count
= head
-> usercount
;
159 derefnode ( iptree
, head
);
161 controlreply ( np
, " %d user(s) found." , count
);