1 |
/* Header for common mask data structure. |
2 |
* |
3 |
* IRC Services is copyright (c) 1996-2009 Andrew Church. |
4 |
* E-mail: <achurch@achurch.org> |
5 |
* Parts written by Andrew Kempe and others. |
6 |
* This program is free but copyrighted software; see the file GPL.txt for |
7 |
* details. |
8 |
*/ |
9 |
|
10 |
#ifndef MASKDATA_H |
11 |
#define MASKDATA_H |
12 |
|
13 |
/*************************************************************************/ |
14 |
|
15 |
/* This structure and the corresponding functions are used by the autokill, |
16 |
* exception, and S-line modules. |
17 |
*/ |
18 |
|
19 |
typedef struct maskdata_ MaskData; |
20 |
struct maskdata_ { |
21 |
MaskData *next, *prev; |
22 |
int usecount; |
23 |
|
24 |
uint8 type; |
25 |
int num; /* Index number */ |
26 |
char *mask; |
27 |
int16 limit; /* For exceptions only */ |
28 |
char *reason; |
29 |
char who[NICKMAX]; |
30 |
time_t time; |
31 |
time_t expires; /* Or 0 for no expiry */ |
32 |
time_t lastused; /* Last time used, 0 if never used */ |
33 |
}; |
34 |
|
35 |
/* Types of mask data: */ |
36 |
#define MD_AKILL 0 |
37 |
#define MD_EXCLUDE 1 |
38 |
#define MD_EXCEPTION 2 |
39 |
#define MD_SGLINE 'G' /* DO NOT CHANGE: some code relies on */ |
40 |
#define MD_SQLINE 'Q' /* these values being the same as the */ |
41 |
#define MD_SZLINE 'Z' /* corresponding S-line letter */ |
42 |
|
43 |
/* Maximum number of mask data items for a single type: */ |
44 |
#define MAX_MASKDATA 32767 |
45 |
|
46 |
/* Maximum value for `limit' field of an entry: */ |
47 |
#define MAX_MASKDATA_LIMIT 32767 |
48 |
|
49 |
/*************************************************************************/ |
50 |
|
51 |
/* Database functions: */ |
52 |
|
53 |
E MaskData *add_maskdata(uint8 type, MaskData *data); |
54 |
E void del_maskdata(uint8 type, MaskData *data); |
55 |
E MaskData *get_maskdata(uint8 type, const char *mask); |
56 |
E MaskData *get_matching_maskdata(uint8 type, const char *str); |
57 |
E MaskData *put_maskdata(MaskData *data); |
58 |
E MaskData *first_maskdata(uint8 type); |
59 |
E MaskData *next_maskdata(uint8 type); |
60 |
E int maskdata_count(uint8 type); |
61 |
E MaskData *get_exception_by_num(int num); |
62 |
E MaskData *move_exception(MaskData *except, int newnum); |
63 |
|
64 |
/*************************************************************************/ |
65 |
/*************************************************************************/ |
66 |
|
67 |
/* OperServ internal stuff. */ |
68 |
|
69 |
/*************************************************************************/ |
70 |
|
71 |
/* Data structure for MaskData-related commands: */ |
72 |
|
73 |
typedef struct { |
74 |
const char *name; /* Command name */ |
75 |
uint8 md_type; /* MaskData type */ |
76 |
time_t *def_expiry_ptr; /* Pointer to default expiry time */ |
77 |
|
78 |
/* Various messages. sprintf() parameters are given in order in |
79 |
* parentheses. */ |
80 |
|
81 |
/* Syntax message (%s: command name) */ |
82 |
/* Message for adding to a full list (%s: command name) */ |
83 |
int msg_add_too_many; |
84 |
/* Message for adding a duplicate record (%s: mask, %s: command name) */ |
85 |
int msg_add_exists; |
86 |
/* Message for successful add (%s: mask, %s: command name) */ |
87 |
int msg_added; |
88 |
/* Message for no record found on delete (%s: mask, %s: command name) */ |
89 |
int msg_del_not_found; |
90 |
/* Message for successful delete (%s: mask, %s: command name) */ |
91 |
int msg_deleted; |
92 |
/* Message for successful clear (%s: command name) */ |
93 |
int msg_cleared; |
94 |
/* Message for list header (%s: command name) */ |
95 |
int msg_list_header; |
96 |
/* Message for LIST on empty list (%s: command name) */ |
97 |
int msg_list_empty; |
98 |
/* Message for LIST with no matching records (%s: command name) */ |
99 |
int msg_list_no_match; |
100 |
/* Message for no match on CHECK (%s: mask, %s: command name) */ |
101 |
int msg_check_no_match; |
102 |
/* Message for CHECK response header (%s: mask, %s: command name) */ |
103 |
int msg_check_header; |
104 |
/* Message for CHECK response trailer (%d: count of matches) */ |
105 |
int msg_check_count; |
106 |
/* Message for record count (%d: count, %s: command name) */ |
107 |
int msg_count; |
108 |
|
109 |
/* Helper functions called by do_maskdata_cmd(). */ |
110 |
|
111 |
/* Make any alterations to the mask necessary for addition or deletion; |
112 |
* if not NULL, called before any other checks (other than for NULL) |
113 |
* are performed. */ |
114 |
void (*mangle_mask)(char *mask); |
115 |
/* Check whether the mask is appropriate; return 1 if OK, else 0. |
116 |
* The mask and expiry time may be modified. If NULL, any mask and |
117 |
* expiry time are accepted. */ |
118 |
int (*check_add_mask)(const User *u, uint8 type, char *mask, |
119 |
time_t *expiry_ptr); |
120 |
/* Operations to perform on mask addition. If NULL, nothing is done. */ |
121 |
void (*do_add_mask)(const User *u, uint8 type, MaskData *md); |
122 |
/* Operations to perform on mask deletion. If NULL, nothing is done. */ |
123 |
void (*do_del_mask)(const User *u, uint8 type, MaskData *md); |
124 |
/* Handler for unknown commands; should return 1 if the command was |
125 |
* handled, 0 otherwise. */ |
126 |
int (*do_unknown_cmd)(const User *u, const char *cmd, char *mask); |
127 |
} MaskDataCmdInfo; |
128 |
|
129 |
/*************************************************************************/ |
130 |
|
131 |
/* MaskData command related functions: */ |
132 |
|
133 |
E void do_maskdata_cmd(const MaskDataCmdInfo *info, const User *u); |
134 |
E char *make_reason(const char *format, const MaskData *data); |
135 |
|
136 |
/* Other functions: */ |
137 |
|
138 |
E void *new_maskdata(void); |
139 |
E void free_maskdata(void *record); |
140 |
E int init_maskdata(void); |
141 |
E void exit_maskdata(void); |
142 |
|
143 |
/*************************************************************************/ |
144 |
|
145 |
#endif /* MASKDATA_H */ |
146 |
|
147 |
/* |
148 |
* Local variables: |
149 |
* c-file-style: "stroustrup" |
150 |
* c-file-offsets: ((case-label . *) (statement-case-intro . *)) |
151 |
* indent-tabs-mode: nil |
152 |
* End: |
153 |
* |
154 |
* vim: expandtab shiftwidth=4: |
155 |
*/ |