| 1 |
|
/* |
| 2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
< |
* parse.h: A header for the message parser. |
| 2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
* |
| 4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 4 |
> |
* Copyright (c) 1997-2014 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 |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
|
* USA |
| 20 |
< |
* |
| 21 |
< |
* $Id$ |
| 20 |
> |
*/ |
| 21 |
> |
|
| 22 |
> |
/*! \file parse.h |
| 23 |
> |
* \brief A header for the message parser. |
| 24 |
> |
* \version $Id$ |
| 25 |
|
*/ |
| 26 |
|
|
| 27 |
|
#ifndef INCLUDED_parse_h |
| 28 |
|
#define INCLUDED_parse_h |
| 29 |
|
|
| 28 |
– |
struct Message; |
| 30 |
|
struct Client; |
| 31 |
|
|
| 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[]); |
| 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...). |
| 42 |
+ |
* |
| 43 |
+ |
* source_p is the source of the message, defined by the |
| 44 |
+ |
* prefix part of the message if present. If not |
| 45 |
+ |
* or prefix not found, then source_p==client_p. |
| 46 |
+ |
* |
| 47 |
+ |
* (!IsServer(client_p)) => (client_p == source_p), because |
| 48 |
+ |
* prefixes are taken *only* from servers... |
| 49 |
+ |
* |
| 50 |
+ |
* (IsServer(client_p)) |
| 51 |
+ |
* (source_p == client_p) => the message didn't |
| 52 |
+ |
* have the prefix. |
| 53 |
+ |
* |
| 54 |
+ |
* (source_p != client_p && IsServer(source_p) means |
| 55 |
+ |
* 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. |
| 90 |
+ |
*/ |
| 91 |
+ |
|
| 92 |
+ |
/* |
| 93 |
+ |
* MessageHandler |
| 94 |
+ |
*/ |
| 95 |
+ |
typedef enum HandlerType { |
| 96 |
+ |
UNREGISTERED_HANDLER, |
| 97 |
+ |
CLIENT_HANDLER, |
| 98 |
+ |
SERVER_HANDLER, |
| 99 |
+ |
ENCAP_HANDLER, |
| 100 |
+ |
OPER_HANDLER, |
| 101 |
+ |
DUMMY_HANDLER, |
| 102 |
+ |
LAST_HANDLER_TYPE |
| 103 |
+ |
} HandlerType; |
| 104 |
+ |
|
| 105 |
+ |
/* |
| 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 |
+ |
/* |
| 116 |
+ |
* Message table structure |
| 117 |
+ |
*/ |
| 118 |
+ |
struct Message |
| 119 |
+ |
{ |
| 120 |
+ |
const char *cmd; |
| 121 |
+ |
unsigned int count; /* number of times command used */ |
| 122 |
+ |
unsigned int rcount; /* number of times command used by server */ |
| 123 |
+ |
unsigned int args_min; /* at least this many args must be passed |
| 124 |
+ |
* or an error will be sent to the user |
| 125 |
+ |
* before the m_func is even called |
| 126 |
+ |
*/ |
| 127 |
+ |
unsigned int args_max; /* maximum permitted parameters */ |
| 128 |
+ |
unsigned int flags; /* bit 0 set means that this command is allowed |
| 129 |
+ |
* to be used only on the average of once per 2 |
| 130 |
+ |
* seconds -SRB |
| 131 |
+ |
*/ |
| 132 |
+ |
uint64_t bytes; /* bytes received for this message */ |
| 133 |
+ |
|
| 134 |
+ |
/* |
| 135 |
+ |
* client_p = Connected client ptr |
| 136 |
+ |
* source_p = Source client ptr |
| 137 |
+ |
* parc = parameter count |
| 138 |
+ |
* parv = parameter variable array |
| 139 |
+ |
*/ |
| 140 |
+ |
/* handlers: |
| 141 |
+ |
* UNREGISTERED, CLIENT, SERVER, ENCAP, OPER, DUMMY, LAST |
| 142 |
+ |
*/ |
| 143 |
+ |
MessageHandler handlers[LAST_HANDLER_TYPE]; |
| 144 |
+ |
}; |
| 145 |
+ |
|
| 146 |
+ |
/* |
| 147 |
+ |
* Constants |
| 148 |
+ |
*/ |
| 149 |
+ |
#define MFLG_SLOW 0x001 /* Command can be executed roughly |
| 150 |
+ |
* once per 2 seconds. |
| 151 |
+ |
*/ |
| 152 |
+ |
#define MAXPARA 15 |
| 153 |
+ |
|
| 154 |
|
extern void parse(struct Client *, char *, char *); |
| 32 |
– |
extern void clear_tree_parse(void); |
| 155 |
|
extern void mod_add_cmd(struct Message *); |
| 156 |
|
extern void mod_del_cmd(struct Message *); |
| 157 |
|
extern struct Message *find_command(const char *); |
| 158 |
|
extern void report_messages(struct Client *); |
| 159 |
|
|
| 160 |
+ |
/* generic handlers */ |
| 161 |
+ |
extern int m_ignore(struct Client *, struct Client *, int, char *[]); |
| 162 |
+ |
extern int m_not_oper(struct Client *, struct Client *, int, char *[]); |
| 163 |
+ |
extern int m_registered(struct Client *, struct Client *, int, char *[]); |
| 164 |
+ |
extern int m_unregistered(struct Client *, struct Client *, int, char *[]); |
| 165 |
|
#endif /* INCLUDED_parse_h */ |