ircd: change MessageHandler to include a MsgBuf pointer at the front for tag access
This commit is contained in:
parent
8ace0906ad
commit
4a84a763cd
4 changed files with 50 additions and 50 deletions
|
@ -45,12 +45,13 @@ typedef enum HandlerType
|
||||||
}
|
}
|
||||||
HandlerType;
|
HandlerType;
|
||||||
|
|
||||||
/* struct Client* client_p - connection message originated from
|
/* struct MsgBuf* msgbuf_p - message buffer (including tags)
|
||||||
|
* struct Client* client_p - connection message originated from
|
||||||
* struct Client* source_p - source of message, may be different from client_p
|
* struct Client* source_p - source of message, may be different from client_p
|
||||||
* int parc - parameter count
|
* int parc - parameter count (from msgbuf_p)
|
||||||
* char* parv[] - parameter vector
|
* char* parv[] - parameter vector (from msgbuf_p)
|
||||||
*/
|
*/
|
||||||
typedef int (*MessageHandler) (struct Client *, struct Client *, int, const char *[]);
|
typedef int (*MessageHandler) (struct MsgBuf *, struct Client *, struct Client *, int, const char *[]);
|
||||||
|
|
||||||
struct MessageEntry
|
struct MessageEntry
|
||||||
{
|
{
|
||||||
|
@ -79,10 +80,10 @@ struct Message
|
||||||
#define MFLG_UNREG 0x02 /* available to unregistered clients */
|
#define MFLG_UNREG 0x02 /* available to unregistered clients */
|
||||||
|
|
||||||
/* generic handlers */
|
/* generic handlers */
|
||||||
extern int m_ignore(struct Client *, struct Client *, int, const char **);
|
extern int m_ignore(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
extern int m_not_oper(struct Client *, struct Client *, int, const char **);
|
extern int m_not_oper(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
extern int m_registered(struct Client *, struct Client *, int, const char **);
|
extern int m_registered(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
extern int m_unregistered(struct Client *, struct Client *, int, const char **);
|
extern int m_unregistered(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
|
|
||||||
#define mg_ignore { m_ignore, 0 }
|
#define mg_ignore { m_ignore, 0 }
|
||||||
#define mg_not_oper { m_not_oper, 0 }
|
#define mg_not_oper { m_not_oper, 0 }
|
||||||
|
|
|
@ -31,9 +31,10 @@
|
||||||
|
|
||||||
struct Message;
|
struct Message;
|
||||||
struct Client;
|
struct Client;
|
||||||
|
struct MsgBuf;
|
||||||
|
|
||||||
extern void parse(struct Client *, char *, char *);
|
extern void parse(struct Client *, char *, char *);
|
||||||
extern void handle_encap(struct Client *, struct Client *,
|
extern void handle_encap(struct MsgBuf *, struct Client *, struct Client *,
|
||||||
const char *, int, const char *parv[]);
|
const char *, int, const char *parv[]);
|
||||||
extern void clear_hash_parse(void);
|
extern void clear_hash_parse(void);
|
||||||
extern void mod_add_cmd(struct Message *msg);
|
extern void mod_add_cmd(struct Message *msg);
|
||||||
|
|
|
@ -65,17 +65,17 @@ int max_mods = MODS_INCREMENT;
|
||||||
|
|
||||||
static rb_dlink_list mod_paths;
|
static rb_dlink_list mod_paths;
|
||||||
|
|
||||||
static int mo_modload(struct Client *, struct Client *, int, const char **);
|
static int mo_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static int mo_modlist(struct Client *, struct Client *, int, const char **);
|
static int mo_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static int mo_modreload(struct Client *, struct Client *, int, const char **);
|
static int mo_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static int mo_modunload(struct Client *, struct Client *, int, const char **);
|
static int mo_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static int mo_modrestart(struct Client *, struct Client *, int, const char **);
|
static int mo_modrestart(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
|
|
||||||
static int me_modload(struct Client *, struct Client *, int, const char **);
|
static int me_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static int me_modlist(struct Client *, struct Client *, int, const char **);
|
static int me_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static int me_modreload(struct Client *, struct Client *, int, const char **);
|
static int me_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static int me_modunload(struct Client *, struct Client *, int, const char **);
|
static int me_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static int me_modrestart(struct Client *, struct Client *, int, const char **);
|
static int me_modrestart(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
|
|
||||||
static int do_modload(struct Client *, const char *);
|
static int do_modload(struct Client *, const char *);
|
||||||
static int do_modunload(struct Client *, const char *);
|
static int do_modunload(struct Client *, const char *);
|
||||||
|
@ -326,7 +326,7 @@ load_one_module(const char *path, int coremodule)
|
||||||
|
|
||||||
/* load a module .. */
|
/* load a module .. */
|
||||||
static int
|
static int
|
||||||
mo_modload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
mo_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!IsOperAdmin(source_p))
|
if(!IsOperAdmin(source_p))
|
||||||
{
|
{
|
||||||
|
@ -347,7 +347,7 @@ mo_modload(struct Client *client_p, struct Client *source_p, int parc, const cha
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
me_modload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
me_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
||||||
{
|
{
|
||||||
|
@ -381,7 +381,7 @@ do_modload(struct Client *source_p, const char *module)
|
||||||
|
|
||||||
/* unload a module .. */
|
/* unload a module .. */
|
||||||
static int
|
static int
|
||||||
mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
mo_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!IsOperAdmin(source_p))
|
if(!IsOperAdmin(source_p))
|
||||||
{
|
{
|
||||||
|
@ -402,7 +402,7 @@ mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const c
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
me_modunload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
me_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
||||||
{
|
{
|
||||||
|
@ -445,7 +445,7 @@ do_modunload(struct Client *source_p, const char *module)
|
||||||
|
|
||||||
/* unload and load in one! */
|
/* unload and load in one! */
|
||||||
static int
|
static int
|
||||||
mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
mo_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!IsOperAdmin(source_p))
|
if(!IsOperAdmin(source_p))
|
||||||
{
|
{
|
||||||
|
@ -466,7 +466,7 @@ mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const c
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
me_modreload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
me_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
||||||
{
|
{
|
||||||
|
@ -515,7 +515,7 @@ do_modreload(struct Client *source_p, const char *module)
|
||||||
|
|
||||||
/* list modules .. */
|
/* list modules .. */
|
||||||
static int
|
static int
|
||||||
mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
mo_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!IsOperAdmin(source_p))
|
if(!IsOperAdmin(source_p))
|
||||||
{
|
{
|
||||||
|
@ -536,7 +536,7 @@ mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const cha
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
me_modlist(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
me_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
||||||
{
|
{
|
||||||
|
@ -581,7 +581,7 @@ do_modlist(struct Client *source_p, const char *pattern)
|
||||||
|
|
||||||
/* unload and reload all modules */
|
/* unload and reload all modules */
|
||||||
static int
|
static int
|
||||||
mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
mo_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!IsOperAdmin(source_p))
|
if(!IsOperAdmin(source_p))
|
||||||
{
|
{
|
||||||
|
@ -602,7 +602,7 @@ mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
me_modrestart(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
me_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||||
{
|
{
|
||||||
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
||||||
{
|
{
|
||||||
|
|
40
ircd/parse.c
40
ircd/parse.c
|
@ -56,7 +56,7 @@ static void remove_unknown(struct Client *, const char *, char *);
|
||||||
static void do_numeric(int, struct Client *, struct Client *, int, const char **);
|
static void do_numeric(int, struct Client *, struct Client *, int, const char **);
|
||||||
static void do_alias(struct alias_entry *, struct Client *, char *);
|
static void do_alias(struct alias_entry *, struct Client *, char *);
|
||||||
|
|
||||||
static int handle_command(struct Message *, struct Client *, struct Client *, int, const char**);
|
static int handle_command(struct Message *, struct MsgBuf *, struct Client *, struct Client *);
|
||||||
|
|
||||||
static char buffer[1024];
|
static char buffer[1024];
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(handle_command(mptr, client_p, from, msgbuf.n_para, /* XXX discards const!!! */ (const char **)(void *) msgbuf.para) < -1)
|
if(handle_command(mptr, &msgbuf, client_p, from) < -1)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
for (p = pbuffer; p <= end; p += 8)
|
for (p = pbuffer; p <= end; p += 8)
|
||||||
|
@ -200,16 +200,14 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
|
||||||
* handle_command
|
* handle_command
|
||||||
*
|
*
|
||||||
* inputs - pointer to message block
|
* inputs - pointer to message block
|
||||||
|
* - pointer to message buffer
|
||||||
* - pointer to client
|
* - pointer to client
|
||||||
* - pointer to client message is from
|
* - pointer to client message is from
|
||||||
* - count of number of args
|
|
||||||
* - pointer to argv[] array
|
|
||||||
* output - -1 if error from server
|
* output - -1 if error from server
|
||||||
* side effects -
|
* side effects -
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
handle_command(struct Message *mptr, struct Client *client_p,
|
handle_command(struct Message *mptr, struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *from)
|
||||||
struct Client *from, int i, const char** hpara)
|
|
||||||
{
|
{
|
||||||
struct MessageEntry ehandler;
|
struct MessageEntry ehandler;
|
||||||
MessageHandler handler = 0;
|
MessageHandler handler = 0;
|
||||||
|
@ -240,8 +238,8 @@ handle_command(struct Message *mptr, struct Client *client_p,
|
||||||
handler = ehandler.handler;
|
handler = ehandler.handler;
|
||||||
|
|
||||||
/* check right amount of params is passed... --is */
|
/* check right amount of params is passed... --is */
|
||||||
if(i < ehandler.min_para ||
|
if(msgbuf_p->n_para < ehandler.min_para ||
|
||||||
(ehandler.min_para && EmptyString(hpara[ehandler.min_para - 1])))
|
(ehandler.min_para && EmptyString(msgbuf_p->para[ehandler.min_para - 1])))
|
||||||
{
|
{
|
||||||
if(!IsServer(client_p))
|
if(!IsServer(client_p))
|
||||||
{
|
{
|
||||||
|
@ -257,24 +255,24 @@ handle_command(struct Message *mptr, struct Client *client_p,
|
||||||
|
|
||||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||||
"Dropping server %s due to (invalid) command '%s'"
|
"Dropping server %s due to (invalid) command '%s'"
|
||||||
" with only %d arguments (expecting %d).",
|
" with only %zu arguments (expecting %d).",
|
||||||
client_p->name, mptr->cmd, i, ehandler.min_para);
|
client_p->name, mptr->cmd, msgbuf_p->n_para, ehandler.min_para);
|
||||||
ilog(L_SERVER,
|
ilog(L_SERVER,
|
||||||
"Insufficient parameters (%d < %d) for command '%s' from %s.",
|
"Insufficient parameters (%zu < %d) for command '%s' from %s.",
|
||||||
i, ehandler.min_para, mptr->cmd, client_p->name);
|
msgbuf_p->n_para, ehandler.min_para, mptr->cmd, client_p->name);
|
||||||
snprintf(squitreason, sizeof squitreason,
|
snprintf(squitreason, sizeof squitreason,
|
||||||
"Insufficient parameters (%d < %d) for command '%s'",
|
"Insufficient parameters (%zu < %d) for command '%s'",
|
||||||
i, ehandler.min_para, mptr->cmd);
|
msgbuf_p->n_para, ehandler.min_para, mptr->cmd);
|
||||||
exit_client(client_p, client_p, client_p, squitreason);
|
exit_client(client_p, client_p, client_p, squitreason);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
(*handler) (client_p, from, i, hpara);
|
(*handler) (msgbuf_p, client_p, from, msgbuf_p->n_para, msgbuf_p->para);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_encap(struct Client *client_p, struct Client *source_p,
|
handle_encap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
||||||
const char *command, int parc, const char *parv[])
|
const char *command, int parc, const char *parv[])
|
||||||
{
|
{
|
||||||
struct Message *mptr;
|
struct Message *mptr;
|
||||||
|
@ -293,7 +291,7 @@ handle_encap(struct Client *client_p, struct Client *source_p,
|
||||||
(ehandler.min_para && EmptyString(parv[ehandler.min_para - 1])))
|
(ehandler.min_para && EmptyString(parv[ehandler.min_para - 1])))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
(*handler) (client_p, source_p, parc, parv);
|
(*handler) (msgbuf_p, client_p, source_p, parc, parv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -618,14 +616,14 @@ static void do_alias(struct alias_entry *aptr, struct Client *source_p, char *te
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
m_not_oper(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
m_not_oper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||||
{
|
{
|
||||||
sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
|
sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
m_unregistered(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
m_unregistered(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||||
{
|
{
|
||||||
/* bit of a hack.
|
/* bit of a hack.
|
||||||
* I don't =really= want to waste a bit in a flag
|
* I don't =really= want to waste a bit in a flag
|
||||||
|
@ -642,14 +640,14 @@ m_unregistered(struct Client *client_p, struct Client *source_p, int parc, const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
m_registered(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
m_registered(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||||
{
|
{
|
||||||
sendto_one(client_p, form_str(ERR_ALREADYREGISTRED), me.name, source_p->name);
|
sendto_one(client_p, form_str(ERR_ALREADYREGISTRED), me.name, source_p->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
m_ignore(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
m_ignore(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue