]>
jfr.im git - irc/quakenet/newserv.git/blob - regexgline/regexgline.h
7 #include <mysql/mysql.h>
13 #include "../core/config.h"
14 #include "../control/control.h"
15 #include "../lib/irc_string.h"
16 #include "../localuser/localuserchannel.h"
17 #include "../lib/sstring.h"
18 #include "../core/schedule.h"
20 #define RG_QUERY_BUF_SIZE 5120
21 #define RG_MAX_CASUALTIES_DEFAULT 5000
22 #define RG_MAX_SPEW_DEFAULT 300
23 #define RG_REGEXGLINE_MAX 512
24 #define RG_REASON_MAX 255
25 #define RG_EXPIRY_BUFFER 200
26 #define RG_MASKLEN HOSTLEN + USERLEN + NICKLEN + REALLEN + 5 /* includes NULL terminator */
27 #define RG_PCREFLAGS PCRE_CASELESS
28 #define RG_MIN_MASK_LEN 5
29 #define RG_MAX_PER_GLINE_DEFAULT 5
30 #define RG_MINIMUM_DELAY_TIME 5
31 #define RG_MAXIMUM_RAND_TIME 15
32 #define RG_EXPIRY_TIME_DEFAULT 1800
33 #define RG_NETWORK_WIDE_MAX_GLINES_PER_8_SEC 625*8 /* 5000 / 8 */
35 #define RGStringise(x) #x
36 #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);
37 #define RGMasksEqual(a, b) !strcasecmp(a, b)
39 typedef MYSQL_RES
*rg_sqlresult
;
40 typedef MYSQL_ROW rg_sqlrow
;
41 typedef MYSQL rg_sqlconnection
;
43 typedef struct rg_struct
{
44 int id
; /* database id */
45 sstring
*mask
; /* gline mask */
46 sstring
*setby
; /* who it's set by */
47 sstring
*reason
; /* reason for gline */
48 time_t expires
; /* when it expires */
49 int type
; /* gline type (user@ip or *@ip) */
50 pcre
*regex
; /* pcre expression */
51 pcre_extra
*hint
; /* pcre hint */
52 long glineid
; /* gline ID */
53 struct rg_struct
*next
; /* ... pointer to next item */
56 rg_sqlconnection rg_sql
;
57 struct rg_struct
*rg_list
= NULL
;
59 int rg_max_casualties
, rg_max_spew
, rg_expiry_time
, rg_max_per_gline
;
60 int rg_sqlconnected
= 0;
61 void *rg_schedule
= NULL
;
63 void rg_nick(int hooknum
, void *arg
);
64 void rg_lostnick(int hooknum
, void *arg
);
65 void rg_startup(void);
67 int rg_gline(void *source
, int cargc
, char **cargv
);
68 int rg_delgline(void *source
, int cargc
, char **cargv
);
69 int rg_glist(void *source
, int cargc
, char **cargv
);
70 int rg_idlist(void *source
, int cargc
, char **cargv
);
71 int rg_spew(void *source
, int cargc
, char **cargv
);
72 int rg_sanitycheck(char *mask
, int *count
);
74 int rg_dbconnect(void);
77 int rg_sqlconnect(char *dbhost
, char *dbuser
, char *dbpass
, char *db
, unsigned int port
);
78 void rg_sqldisconnect(void);
79 void rg_sqlescape_string(char *dest
, char *source
, size_t length
);
80 int rg_sqlquery(char *format
, ...);
81 rg_sqlresult
rg_sqlstoreresult(void);
82 rg_sqlrow
rg_sqlgetrow(rg_sqlresult res
);
83 void rg_sqlfree(rg_sqlresult res
);
85 void rg_freestruct(struct rg_struct
*rp
);
86 struct rg_struct
*rg_newstruct(time_t expires
);
87 struct rg_struct
*rg_newsstruct(char *id
, char *mask
, char *setby
, char *reason
, char *expires
, char *type
, time_t iexpires
, int iid
);
89 void rg_displaygline(nick
*np
, struct rg_struct
*rp
);
91 void rg_checkexpiry(void *arg
);
93 void rg_logevent(nick
*np
, char *event
, char *details
, ...);
94 void rg_loggline(struct rg_struct
*rg
, nick
*np
);
96 unsigned char rc_hexlookup
[256] = {
97 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
98 0xff, 0xff, 0xff, 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, 0x00, 0x01,
102 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xff, 0xff,
103 0xff, 0xff, 0xff, 0xff, 0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
104 0x0f, 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, 0x0a, 0x0b, 0x0c,
107 0x0d, 0x0e, 0x0f, 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, 0xff, 0xff, 0xff, 0xff,
114 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
115 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
116 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
117 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
118 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
119 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
120 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
121 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
122 0xff, 0xff, 0xff, 0xff, 0xff, 0xff