25 |
|
#ifndef INCLUDED_parse_h |
26 |
|
#define INCLUDED_parse_h |
27 |
|
|
28 |
– |
struct Message; |
28 |
|
struct Client; |
29 |
|
|
30 |
+ |
|
31 |
+ |
/* |
32 |
+ |
* m_functions execute protocol messages on this server: |
33 |
+ |
* int m_func(struct Client* client_p, struct Client* source_p, int parc, char* parv[]); |
34 |
+ |
* |
35 |
+ |
* client_p is always NON-NULL, pointing to a *LOCAL* client |
36 |
+ |
* structure (with an open socket connected!). This |
37 |
+ |
* identifies the physical socket where the message |
38 |
+ |
* originated (or which caused the m_function to be |
39 |
+ |
* executed--some m_functions may call others...). |
40 |
+ |
* |
41 |
+ |
* source_p is the source of the message, defined by the |
42 |
+ |
* prefix part of the message if present. If not |
43 |
+ |
* or prefix not found, then source_p==client_p. |
44 |
+ |
* |
45 |
+ |
* (!IsServer(client_p)) => (client_p == source_p), because |
46 |
+ |
* prefixes are taken *only* from servers... |
47 |
+ |
* |
48 |
+ |
* (IsServer(client_p)) |
49 |
+ |
* (source_p == client_p) => the message didn't |
50 |
+ |
* have the prefix. |
51 |
+ |
* |
52 |
+ |
* (source_p != client_p && IsServer(source_p) means |
53 |
+ |
* the prefix specified servername. (?) |
54 |
+ |
* |
55 |
+ |
* (source_p != client_p && !IsServer(source_p) means |
56 |
+ |
* that message originated from a remote |
57 |
+ |
* user (not local). |
58 |
+ |
* |
59 |
+ |
* |
60 |
+ |
* combining |
61 |
+ |
* |
62 |
+ |
* (!IsServer(source_p)) means that, source_p can safely |
63 |
+ |
* taken as defining the target structure of the |
64 |
+ |
* message in this server. |
65 |
+ |
* |
66 |
+ |
* *Always* true (if 'parse' and others are working correct): |
67 |
+ |
* |
68 |
+ |
* 1) source_p->from == client_p (note: client_p->from == client_p) |
69 |
+ |
* |
70 |
+ |
* 2) MyConnect(source_p) <=> source_p == client_p (e.g. source_p |
71 |
+ |
* *cannot* be a local connection, unless it's |
72 |
+ |
* actually client_p!). [MyConnect(x) should probably |
73 |
+ |
* be defined as (x == x->from) --msa ] |
74 |
+ |
* |
75 |
+ |
* parc number of variable parameter strings (if zero, |
76 |
+ |
* parv is allowed to be NULL) |
77 |
+ |
* |
78 |
+ |
* parv a NULL terminated list of parameter pointers, |
79 |
+ |
* |
80 |
+ |
* parv[0], sender (prefix string), if not present |
81 |
+ |
* this points to an empty string. |
82 |
+ |
* parv[1]...parv[parc-1] |
83 |
+ |
* pointers to additional parameters |
84 |
+ |
* parv[parc] == NULL, *always* |
85 |
+ |
* |
86 |
+ |
* note: it is guaranteed that parv[0]..parv[parc-1] are all |
87 |
+ |
* non-NULL pointers. |
88 |
+ |
*/ |
89 |
+ |
|
90 |
+ |
/* |
91 |
+ |
* MessageHandler |
92 |
+ |
*/ |
93 |
+ |
typedef enum HandlerType { |
94 |
+ |
UNREGISTERED_HANDLER, |
95 |
+ |
CLIENT_HANDLER, |
96 |
+ |
SERVER_HANDLER, |
97 |
+ |
ENCAP_HANDLER, |
98 |
+ |
OPER_HANDLER, |
99 |
+ |
DUMMY_HANDLER, |
100 |
+ |
LAST_HANDLER_TYPE |
101 |
+ |
} HandlerType; |
102 |
+ |
|
103 |
+ |
/* |
104 |
+ |
* MessageHandler function |
105 |
+ |
* Params: |
106 |
+ |
* struct Client* client_p - connection message originated from |
107 |
+ |
* struct Client* source_p - source of message, may be different from client_p |
108 |
+ |
* int parc - parameter count |
109 |
+ |
* char* parv[] - parameter vector |
110 |
+ |
*/ |
111 |
+ |
typedef void (*MessageHandler)(struct Client *, struct Client *, int, char *[]); |
112 |
+ |
|
113 |
+ |
/* |
114 |
+ |
* Message table structure |
115 |
+ |
*/ |
116 |
+ |
struct Message |
117 |
+ |
{ |
118 |
+ |
const char *cmd; |
119 |
+ |
unsigned int count; /* number of times command used */ |
120 |
+ |
unsigned int rcount; /* number of times command used by server */ |
121 |
+ |
unsigned int args_min; /* at least this many args must be passed |
122 |
+ |
* or an error will be sent to the user |
123 |
+ |
* before the m_func is even called |
124 |
+ |
*/ |
125 |
+ |
unsigned int args_max; /* maximum permitted parameters */ |
126 |
+ |
unsigned int flags; /* bit 0 set means that this command is allowed |
127 |
+ |
* to be used only on the average of once per 2 |
128 |
+ |
* seconds -SRB |
129 |
+ |
*/ |
130 |
+ |
uint64_t bytes; /* bytes received for this message */ |
131 |
+ |
|
132 |
+ |
/* |
133 |
+ |
* client_p = Connected client ptr |
134 |
+ |
* source_p = Source client ptr |
135 |
+ |
* parc = parameter count |
136 |
+ |
* parv = parameter variable array |
137 |
+ |
*/ |
138 |
+ |
/* handlers: |
139 |
+ |
* UNREGISTERED, CLIENT, SERVER, ENCAP, OPER, DUMMY, LAST |
140 |
+ |
*/ |
141 |
+ |
MessageHandler handlers[LAST_HANDLER_TYPE]; |
142 |
+ |
}; |
143 |
+ |
|
144 |
+ |
/* |
145 |
+ |
* Constants |
146 |
+ |
*/ |
147 |
+ |
#define MFLG_SLOW 0x001 /* Command can be executed roughly |
148 |
+ |
* once per 2 seconds. |
149 |
+ |
*/ |
150 |
+ |
#define MFLG_UNREG 0x002 /* Command available to unregistered |
151 |
+ |
* clients. |
152 |
+ |
*/ |
153 |
+ |
|
154 |
+ |
#define MAXPARA 15 |
155 |
+ |
|
156 |
|
extern void parse(struct Client *, char *, char *); |
157 |
|
extern void clear_tree_parse(void); |
158 |
|
extern void mod_add_cmd(struct Message *); |
160 |
|
extern struct Message *find_command(const char *); |
161 |
|
extern void report_messages(struct Client *); |
162 |
|
|
163 |
+ |
/* generic handlers */ |
164 |
+ |
extern void rfc1459_command_send_error(struct Client *, struct Client *,int, char *[]); |
165 |
+ |
extern void m_ignore(struct Client *, struct Client *, int, char *[]); |
166 |
+ |
extern void m_not_oper(struct Client *, struct Client *, int, char *[]); |
167 |
+ |
extern void m_registered(struct Client *, struct Client *, int, char *[]); |
168 |
+ |
extern void m_unregistered(struct Client *, struct Client *, int, char *[]); |
169 |
+ |
|
170 |
|
#endif /* INCLUDED_parse_h */ |