]> jfr.im git - solanum.git/blob - include/msg.h
msgbuf: allow for an explicit target to be defined
[solanum.git] / include / msg.h
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * msg.h: A header for the message handler structure.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2004 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 * $Id: msg.h 6 2005-09-10 01:02:21Z nenolod $
25 */
26
27 #ifndef INCLUDED_msg_h
28 #define INCLUDED_msg_h
29
30 #include "config.h"
31 #include "msgbuf.h"
32
33 struct Client;
34
35 /* MessageHandler */
36 typedef enum HandlerType
37 {
38 UNREGISTERED_HANDLER,
39 CLIENT_HANDLER,
40 RCLIENT_HANDLER,
41 SERVER_HANDLER,
42 ENCAP_HANDLER,
43 OPER_HANDLER,
44 LAST_HANDLER_TYPE
45 }
46 HandlerType;
47
48 /* struct MsgBuf* msgbuf_p - message buffer (including tags)
49 * struct Client* client_p - connection message originated from
50 * struct Client* source_p - source of message, may be different from client_p
51 * int parc - parameter count (from msgbuf_p)
52 * char* parv[] - parameter vector (from msgbuf_p)
53 */
54 typedef int (*MessageHandler) (struct MsgBuf *, struct Client *, struct Client *, int, const char *[]);
55
56 struct MessageEntry
57 {
58 MessageHandler handler;
59 int min_para;
60 };
61
62 /* Message table structure */
63 struct Message
64 {
65 const char *cmd;
66 unsigned int count; /* number of times command used */
67 unsigned int rcount; /* number of times command used by server */
68 unsigned long bytes; /* bytes received for this message */
69 unsigned int flags;
70
71 /* handlers:
72 * UNREGISTERED, CLIENT, RCLIENT, SERVER, OPER, LAST
73 */
74 struct MessageEntry handlers[LAST_HANDLER_TYPE];
75 };
76
77 /* generic handlers */
78 extern int m_ignore(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
79 extern int m_not_oper(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
80 extern int m_registered(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
81 extern int m_unregistered(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
82
83 #define mg_ignore { m_ignore, 0 }
84 #define mg_not_oper { m_not_oper, 0 }
85 #define mg_reg { m_registered, 0 }
86 #define mg_unreg { m_unregistered, 0 }
87
88 /*
89 * m_functions execute protocol messages on this server:
90 * int m_func(struct Client* client_p, struct Client* source_p, int parc, char* parv[]);
91 *
92 * client_p is always NON-NULL, pointing to a *LOCAL* client
93 * structure (with an open socket connected!). This
94 * identifies the physical socket where the message
95 * originated (or which caused the m_function to be
96 * executed--some m_functions may call others...).
97 *
98 * source_p is the source of the message, defined by the
99 * prefix part of the message if present. If not
100 * or prefix not found, then source_p==client_p.
101 *
102 * (!IsServer(client_p)) => (client_p == source_p), because
103 * prefixes are taken *only* from servers...
104 *
105 * (IsServer(client_p))
106 * (source_p == client_p) => the message didn't
107 * have the prefix.
108 *
109 * (source_p != client_p && IsServer(source_p) means
110 * the prefix specified servername. (?)
111 *
112 * (source_p != client_p && !IsServer(source_p) means
113 * that message originated from a remote
114 * user (not local).
115 *
116 *
117 * combining
118 *
119 * (!IsServer(source_p)) means that, source_p can safely
120 * taken as defining the target structure of the
121 * message in this server.
122 *
123 * *Always* true (if 'parse' and others are working correct):
124 *
125 * 1) source_p->from == client_p (note: client_p->from == client_p)
126 *
127 * 2) MyConnect(source_p) <=> source_p == client_p (e.g. source_p
128 * *cannot* be a local connection, unless it's
129 * actually client_p!). [MyConnect(x) should probably
130 * be defined as (x == x->from) --msa ]
131 *
132 * parc number of variable parameter strings (if zero,
133 * parv is allowed to be NULL)
134 *
135 * parv a NULL terminated list of parameter pointers,
136 *
137 * parv[0], unused for historical reasons (formerly
138 * sender name)
139 * parv[1]...parv[parc-1]
140 * pointers to additional parameters
141 * parv[parc] == NULL, *always*
142 *
143 * note: it is guaranteed that parv[1]..parv[parc-1] are all
144 * non-NULL pointers.
145 */
146
147 #endif /* INCLUDED_msg_h */