]> jfr.im git - irc/quakenet/newserv.git/blame - regexgline/regexgline.h
merge
[irc/quakenet/newserv.git] / regexgline / regexgline.h
CommitLineData
1e0c4014
CP
1#ifndef __regexgline_H
2#define __regexgline_H
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <stdarg.h>
1e0c4014
CP
7#include <errno.h>
8#include <pcre.h>
9#include <string.h>
4ad1cf7a 10#include <strings.h>
1e0c4014
CP
11
12#include "../core/config.h"
13#include "../control/control.h"
14#include "../lib/irc_string.h"
15#include "../localuser/localuserchannel.h"
16#include "../lib/sstring.h"
17#include "../core/schedule.h"
18
19#define RG_QUERY_BUF_SIZE 5120
20#define RG_MAX_CASUALTIES_DEFAULT 5000
21#define RG_MAX_SPEW_DEFAULT 300
22#define RG_REGEXGLINE_MAX 512
23#define RG_REASON_MAX 255
24#define RG_EXPIRY_BUFFER 200
25#define RG_MASKLEN HOSTLEN + USERLEN + NICKLEN + REALLEN + 5 /* includes NULL terminator */
26#define RG_PCREFLAGS PCRE_CASELESS
27#define RG_MIN_MASK_LEN 5
28#define RG_MAX_PER_GLINE_DEFAULT 5
5f3eb6fa
CP
29#define RG_MINIMUM_DELAY_TIME 5
30#define RG_MAXIMUM_RAND_TIME 15
1e0c4014 31#define RG_EXPIRY_TIME_DEFAULT 1800
481738a4 32#define RG_NETWORK_WIDE_MAX_GLINES_PER_8_SEC 625*8 /* 5000 / 8 */
1e0c4014
CP
33
34#define RGStringise(x) #x
d28e0741 35#define RGBuildHostname(buf, np) snprintf(buf, sizeof(buf), "%s!%s@%s\r%s", np->nick, np->ident, np->host->name->content, np->realname->name->content);
1e0c4014
CP
36#define RGMasksEqual(a, b) !strcasecmp(a, b)
37
1e0c4014
CP
38typedef struct rg_struct {
39 int id; /* database id */
40 sstring *mask; /* gline mask */
41 sstring *setby; /* who it's set by */
42 sstring *reason; /* reason for gline */
43 time_t expires; /* when it expires */
44 int type; /* gline type (user@ip or *@ip) */
45 pcre *regex; /* pcre expression */
46 pcre_extra *hint; /* pcre hint */
47 long glineid; /* gline ID */
86178656 48 const char *class; /* class of gline */
01d1f71c 49 unsigned long hits; /* hits since we were loaded */
c4d6944b
CP
50 unsigned long hitssaved; /* hits (persistent) */
51 unsigned int marker; /* newserv style marker */
52 time_t lastseen; /* ... */
53 short dirty; /* whether or not we need to flush to the db */
1e0c4014
CP
54 struct rg_struct *next; /* ... pointer to next item */
55} rg_struct;
56
1e0c4014
CP
57struct rg_struct *rg_list = NULL;
58
59int rg_max_casualties, rg_max_spew, rg_expiry_time, rg_max_per_gline;
1e0c4014
CP
60void *rg_schedule = NULL;
61
62void rg_nick(int hooknum, void *arg);
5f3eb6fa 63void rg_lostnick(int hooknum, void *arg);
1e0c4014
CP
64void rg_startup(void);
65
66int rg_gline(void *source, int cargc, char **cargv);
67int rg_delgline(void *source, int cargc, char **cargv);
68int rg_glist(void *source, int cargc, char **cargv);
69int rg_idlist(void *source, int cargc, char **cargv);
70int rg_spew(void *source, int cargc, char **cargv);
71int rg_sanitycheck(char *mask, int *count);
72
73int rg_dbconnect(void);
eba15ac4 74void rg_dbload(void);
1e0c4014
CP
75
76void rg_freestruct(struct rg_struct *rp);
77struct rg_struct *rg_newstruct(time_t expires);
c4d6944b 78struct rg_struct *rg_newsstruct(unsigned long id, char *mask, char *setby, char *reason, char *expires, char *type, time_t iexpires, char *class, time_t lastseen, unsigned int hitssaved);
1e0c4014 79
c4d6944b 80void rg_displaygline(nick *np, struct rg_struct *rp, int longest);
1e0c4014 81
1e0c4014
CP
82void rg_checkexpiry(void *arg);
83
bb4b25ee 84void rg_logevent(nick *np, char *event, char *details, ...) __attribute__ ((format (printf, 3, 4)));
d28e0741 85void rg_loggline(struct rg_struct *rg, nick *np);
1e0c4014
CP
86
87unsigned char rc_hexlookup[256] = {
88 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
89 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
90 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
91 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
92 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01,
93 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xff, 0xff,
94 0xff, 0xff, 0xff, 0xff, 0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
95 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
96 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
97 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0a, 0x0b, 0x0c,
98 0x0d, 0x0e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
99 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
100 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
101 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
102 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
103 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
104 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
105 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
106 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
107 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
108 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
109 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
110 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
111 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
112 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
113 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
114 };
115
116#endif