| 1 |
|
/* |
| 2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
* |
| 4 |
< |
* Copyright (c) 1997-2014 ircd-hybrid development team |
| 4 |
> |
* Copyright (c) 1997-2018 ircd-hybrid development team |
| 5 |
|
* |
| 6 |
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
* it under the terms of the GNU General Public License as published by |
| 15 |
|
* |
| 16 |
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
|
* USA |
| 20 |
|
*/ |
| 21 |
|
|
| 32 |
|
|
| 33 |
|
/* |
| 34 |
|
* m_functions execute protocol messages on this server: |
| 35 |
< |
* int m_func(struct Client* client_p, struct Client* source_p, int parc, char* parv[]); |
| 35 |
> |
* int m_func(struct Client *source_p, int parc, char *parv[]); |
| 36 |
|
* |
| 37 |
< |
* client_p is always NON-NULL, pointing to a *LOCAL* client |
| 38 |
< |
* structure (with an open socket connected!). This |
| 39 |
< |
* identifies the physical socket where the message |
| 40 |
< |
* originated (or which caused the m_function to be |
| 41 |
< |
* executed--some m_functions may call others...). |
| 37 |
> |
* source_p is the source of the message, defined by the |
| 38 |
> |
* prefix part of the message if present. If not |
| 39 |
> |
* then it is the client of the physical connection. |
| 40 |
> |
* Note that prefixes are only taken from servers. |
| 41 |
|
* |
| 42 |
< |
* source_p is the source of the message, defined by the |
| 43 |
< |
* prefix part of the message if present. If not |
| 45 |
< |
* or prefix not found, then source_p==client_p. |
| 42 |
> |
* parc number of variable parameter strings (if zero, |
| 43 |
> |
* parv is allowed to be NULL) |
| 44 |
|
* |
| 45 |
< |
* (!IsServer(client_p)) => (client_p == source_p), because |
| 48 |
< |
* prefixes are taken *only* from servers... |
| 45 |
> |
* parv a NULL terminated list of parameter pointers, |
| 46 |
|
* |
| 47 |
< |
* (IsServer(client_p)) |
| 48 |
< |
* (source_p == client_p) => the message didn't |
| 49 |
< |
* have the prefix. |
| 47 |
> |
* parv[0] command |
| 48 |
> |
* parv[1]...parv[parc - 1] pointers to additional parameters |
| 49 |
> |
* parv[parc] == NULL, *always* |
| 50 |
|
* |
| 51 |
< |
* (source_p != client_p && IsServer(source_p) means |
| 52 |
< |
* the prefix specified servername. (?) |
| 56 |
< |
* |
| 57 |
< |
* (source_p != client_p && !IsServer(source_p) means |
| 58 |
< |
* that message originated from a remote |
| 59 |
< |
* user (not local). |
| 60 |
< |
* |
| 61 |
< |
* |
| 62 |
< |
* combining |
| 63 |
< |
* |
| 64 |
< |
* (!IsServer(source_p)) means that, source_p can safely |
| 65 |
< |
* taken as defining the target structure of the |
| 66 |
< |
* message in this server. |
| 67 |
< |
* |
| 68 |
< |
* *Always* true (if 'parse' and others are working correct): |
| 69 |
< |
* |
| 70 |
< |
* 1) source_p->from == client_p (note: client_p->from == client_p) |
| 71 |
< |
* |
| 72 |
< |
* 2) MyConnect(source_p) <=> source_p == client_p (e.g. source_p |
| 73 |
< |
* *cannot* be a local connection, unless it's |
| 74 |
< |
* actually client_p!). [MyConnect(x) should probably |
| 75 |
< |
* be defined as (x == x->from) --msa ] |
| 76 |
< |
* |
| 77 |
< |
* parc number of variable parameter strings (if zero, |
| 78 |
< |
* parv is allowed to be NULL) |
| 79 |
< |
* |
| 80 |
< |
* parv a NULL terminated list of parameter pointers, |
| 81 |
< |
* |
| 82 |
< |
* parv[0], sender (prefix string), if not present |
| 83 |
< |
* this points to an empty string. |
| 84 |
< |
* parv[1]...parv[parc-1] |
| 85 |
< |
* pointers to additional parameters |
| 86 |
< |
* parv[parc] == NULL, *always* |
| 87 |
< |
* |
| 88 |
< |
* note: it is guaranteed that parv[0]..parv[parc-1] are all |
| 89 |
< |
* non-NULL pointers. |
| 51 |
> |
* note: it is guaranteed that parv[0]..parv[parc - 1] are all |
| 52 |
> |
* non-NULL pointers. |
| 53 |
|
*/ |
| 54 |
|
|
| 55 |
|
/* |
| 56 |
|
* MessageHandler |
| 57 |
|
*/ |
| 58 |
< |
typedef enum HandlerType { |
| 58 |
> |
typedef enum HandlerType |
| 59 |
> |
{ |
| 60 |
|
UNREGISTERED_HANDLER, |
| 61 |
|
CLIENT_HANDLER, |
| 62 |
|
SERVER_HANDLER, |
| 63 |
|
ENCAP_HANDLER, |
| 64 |
|
OPER_HANDLER, |
| 101 |
– |
DUMMY_HANDLER, |
| 65 |
|
LAST_HANDLER_TYPE |
| 66 |
|
} HandlerType; |
| 67 |
|
|
| 68 |
|
/* |
| 106 |
– |
* MessageHandler function |
| 107 |
– |
* Params: |
| 108 |
– |
* struct Client* client_p - connection message originated from |
| 109 |
– |
* struct Client* source_p - source of message, may be different from client_p |
| 110 |
– |
* int parc - parameter count |
| 111 |
– |
* char* parv[] - parameter vector |
| 112 |
– |
*/ |
| 113 |
– |
typedef int (*MessageHandler)(struct Client *, struct Client *, int, char *[]); |
| 114 |
– |
|
| 115 |
– |
/* |
| 69 |
|
* Message table structure |
| 70 |
|
*/ |
| 71 |
|
struct Message |
| 72 |
|
{ |
| 73 |
|
const char *cmd; |
| 74 |
+ |
void *extra; |
| 75 |
|
unsigned int count; /* number of times command used */ |
| 76 |
|
unsigned int rcount; /* number of times command used by server */ |
| 77 |
|
unsigned int args_min; /* at least this many args must be passed |
| 79 |
|
* before the m_func is even called |
| 80 |
|
*/ |
| 81 |
|
unsigned int args_max; /* maximum permitted parameters */ |
| 82 |
< |
unsigned int flags; /* bit 0 set means that this command is allowed |
| 83 |
< |
* to be used only on the average of once per 2 |
| 130 |
< |
* seconds -SRB |
| 131 |
< |
*/ |
| 132 |
< |
uint64_t bytes; /* bytes received for this message */ |
| 82 |
> |
unsigned int flags; |
| 83 |
> |
uintmax_t bytes; /* bytes received for this message */ |
| 84 |
|
|
| 134 |
– |
/* |
| 135 |
– |
* client_p = Connected client ptr |
| 136 |
– |
* source_p = Source client ptr |
| 137 |
– |
* parc = parameter count |
| 138 |
– |
* parv = parameter variable array |
| 139 |
– |
*/ |
| 85 |
|
/* handlers: |
| 86 |
< |
* UNREGISTERED, CLIENT, SERVER, ENCAP, OPER, DUMMY, LAST |
| 86 |
> |
* UNREGISTERED, CLIENT, SERVER, ENCAP, OPER, LAST |
| 87 |
|
*/ |
| 88 |
< |
MessageHandler handlers[LAST_HANDLER_TYPE]; |
| 88 |
> |
int (*handlers[LAST_HANDLER_TYPE])(struct Client *, int, char *[]); |
| 89 |
|
}; |
| 90 |
|
|
| 91 |
|
/* |
| 92 |
|
* Constants |
| 93 |
|
*/ |
| 94 |
< |
#define MFLG_SLOW 0x001 /* Command can be executed roughly |
| 150 |
< |
* once per 2 seconds. |
| 151 |
< |
*/ |
| 94 |
> |
#define MFLG_EXTRA 0x00000001U |
| 95 |
|
#define MAXPARA 15 |
| 96 |
|
|
| 97 |
|
extern void parse(struct Client *, char *, char *); |
| 101 |
|
extern void report_messages(struct Client *); |
| 102 |
|
|
| 103 |
|
/* generic handlers */ |
| 104 |
< |
extern int m_ignore(struct Client *, struct Client *, int, char *[]); |
| 105 |
< |
extern int m_not_oper(struct Client *, struct Client *, int, char *[]); |
| 106 |
< |
extern int m_registered(struct Client *, struct Client *, int, char *[]); |
| 107 |
< |
extern int m_unregistered(struct Client *, struct Client *, int, char *[]); |
| 108 |
< |
#endif /* INCLUDED_parse_h */ |
| 104 |
> |
extern int m_ignore(struct Client *, int, char *[]); |
| 105 |
> |
extern int m_not_oper(struct Client *, int, char *[]); |
| 106 |
> |
extern int m_registered(struct Client *, int, char *[]); |
| 107 |
> |
extern int m_unregistered(struct Client *, int, char *[]); |
| 108 |
> |
#endif /* INCLUDED_parse_h */ |