| 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 |
| 29 |
|
#include "parse.h" |
| 30 |
|
#include "channel.h" |
| 31 |
|
#include "hash.h" |
| 32 |
+ |
#include "id.h" |
| 33 |
|
#include "irc_string.h" |
| 34 |
|
#include "ircd.h" |
| 35 |
|
#include "numeric.h" |
| 83 |
|
* For a small parser like this, this is a good compromise and does |
| 84 |
|
* make it somewhat faster. - Dianora |
| 85 |
|
*/ |
| 86 |
< |
#define MAXPTRLEN 32 |
| 86 |
> |
enum { MAXPTRLEN = 32 }; |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
static struct MessageTree |
| 119 |
|
{ |
| 120 |
|
sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE, |
| 121 |
|
"Unknown prefix (%s) from %s, Squitting %s", |
| 122 |
< |
lbuffer, get_client_name(client_p, SHOW_IP), lsender); |
| 122 |
> |
lbuffer, client_get_name(client_p, SHOW_IP), lsender); |
| 123 |
|
sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE, |
| 124 |
|
"Unknown prefix (%s) from %s, Squitting %s", |
| 125 |
< |
lbuffer, client_p->name, lsender); |
| 125 |
> |
lbuffer, client_get_name(client_p, MASK_IP), lsender); |
| 126 |
|
sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)", |
| 127 |
|
me.id, lsender, lbuffer, client_p->name); |
| 128 |
|
} |
| 176 |
|
else |
| 177 |
|
target_p = find_person(source_p, parv[1]); |
| 178 |
|
|
| 179 |
< |
if (((!target_p) || (target_p->from == source_p->from)) && !chptr) |
| 179 |
> |
if ((!target_p || target_p->from == source_p->from) && !chptr) |
| 180 |
|
return; |
| 181 |
|
|
| 182 |
|
/* |
| 196 |
|
/* Fake it for server hiding, if it's our client */ |
| 197 |
|
if ((ConfigServerHide.hide_servers || IsHidden(source_p)) && MyConnect(target_p) && |
| 198 |
|
!HasUMode(target_p, UMODE_OPER)) |
| 199 |
< |
sendto_one_numeric(target_p, &me, numeric|SND_EXPLICIT, "%s", parv[2]); |
| 199 |
> |
sendto_one_numeric(target_p, &me, numeric | SND_EXPLICIT, "%s", parv[2]); |
| 200 |
|
else |
| 201 |
< |
sendto_one_numeric(target_p, source_p, numeric|SND_EXPLICIT, "%s", parv[2]); |
| 201 |
> |
sendto_one_numeric(target_p, source_p, numeric | SND_EXPLICIT, "%s", parv[2]); |
| 202 |
|
} |
| 203 |
|
else |
| 204 |
|
sendto_channel_butone(source_p, source_p, chptr, 0, "%u %s %s", |
| 216 |
|
* side effects - |
| 217 |
|
*/ |
| 218 |
|
static void |
| 219 |
< |
parse_handle_command(struct Message *mptr, struct Client *source_p, |
| 219 |
> |
parse_handle_command(struct Message *message, struct Client *source_p, |
| 220 |
|
unsigned int i, char *para[]) |
| 221 |
|
{ |
| 222 |
|
if (IsServer(source_p->from)) |
| 223 |
< |
++mptr->rcount; |
| 223 |
> |
++message->rcount; |
| 224 |
|
|
| 225 |
< |
++mptr->count; |
| 225 |
> |
++message->count; |
| 226 |
|
|
| 227 |
|
/* Check right amount of parameters is passed... --is */ |
| 228 |
< |
if (i < mptr->args_min) |
| 229 |
< |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, mptr->cmd); |
| 228 |
> |
if (i < message->args_min) |
| 229 |
> |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, message->cmd); |
| 230 |
|
else |
| 231 |
< |
mptr->handlers[source_p->from->handler](source_p, i, para); |
| 231 |
> |
message->handlers[source_p->from->handler](source_p, i, para); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
/* |
| 240 |
|
parse(struct Client *client_p, char *pbuffer, char *bufend) |
| 241 |
|
{ |
| 242 |
|
struct Client *from = client_p; |
| 243 |
< |
struct Message *msg_ptr = NULL; |
| 243 |
> |
struct Message *message = NULL; |
| 244 |
|
char *para[MAXPARA + 2]; /* <command> + <parameters> + NULL */ |
| 245 |
|
char *ch = NULL; |
| 246 |
|
char *s = NULL; |
| 251 |
|
if (IsDefunct(client_p)) |
| 252 |
|
return; |
| 253 |
|
|
| 254 |
< |
assert(client_p->connection->fd.flags.open); |
| 254 |
> |
assert(client_p->connection); |
| 255 |
> |
assert(client_p->connection->fd); |
| 256 |
> |
assert(client_p->connection->fd->flags.open); |
| 257 |
> |
|
| 258 |
> |
|
| 259 |
|
assert((bufend - pbuffer) < IRCD_BUFSIZE); |
| 260 |
|
|
| 261 |
|
for (ch = pbuffer; *ch == ' '; ++ch) /* Skip spaces */ |
| 298 |
|
sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE, |
| 299 |
|
"Fake direction: dropped message from %s[%s] via %s", |
| 300 |
|
from->name, from->from->name, |
| 301 |
< |
get_client_name(client_p, SHOW_IP)); |
| 301 |
> |
client_get_name(client_p, SHOW_IP)); |
| 302 |
|
sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE, |
| 303 |
< |
"Fake direction: dropped message fro %s[%s] via %s", |
| 303 |
> |
"Fake direction: dropped message from %s[%s] via %s", |
| 304 |
|
from->name, from->from->name, |
| 305 |
< |
get_client_name(client_p, MASK_IP)); |
| 305 |
> |
client_get_name(client_p, MASK_IP)); |
| 306 |
|
return; |
| 307 |
|
} |
| 308 |
|
} |
| 337 |
|
} |
| 338 |
|
else |
| 339 |
|
{ |
| 335 |
– |
unsigned int length = 0; |
| 336 |
– |
|
| 340 |
|
if ((s = strchr(ch, ' '))) |
| 341 |
|
*s++ = '\0'; |
| 342 |
|
|
| 343 |
< |
if ((msg_ptr = find_command(ch)) == NULL) |
| 343 |
> |
if ((message = find_command(ch)) == NULL) |
| 344 |
|
{ |
| 345 |
|
/* |
| 346 |
|
* Note: Give error message *only* to recognized |
| 361 |
|
return; |
| 362 |
|
} |
| 363 |
|
|
| 364 |
< |
assert(msg_ptr->cmd); |
| 364 |
> |
assert(message->cmd); |
| 365 |
> |
|
| 366 |
> |
paramcount = message->args_max; |
| 367 |
|
|
| 368 |
< |
paramcount = msg_ptr->args_max; |
| 369 |
< |
length = bufend - ((s) ? s : ch); |
| 365 |
< |
msg_ptr->bytes += length; |
| 368 |
> |
size_t length = bufend - ((s) ? s : ch); |
| 369 |
> |
message->bytes += length; |
| 370 |
|
} |
| 371 |
|
|
| 372 |
|
/* |
| 380 |
|
|
| 381 |
|
para[parc] = ch; |
| 382 |
|
|
| 383 |
< |
if (msg_ptr && (msg_ptr->flags & MFLG_EXTRA)) |
| 383 |
> |
if (message && (message->flags & MFLG_EXTRA)) |
| 384 |
|
{ |
| 385 |
|
/* |
| 386 |
|
* XXX: This will have to go away after the command handler rewrite |
| 387 |
|
*/ |
| 388 |
< |
para[++parc] = msg_ptr->extra; |
| 388 |
> |
para[++parc] = message->extra; |
| 389 |
|
} |
| 390 |
|
|
| 391 |
|
if (s) |
| 420 |
|
|
| 421 |
|
para[++parc] = NULL; |
| 422 |
|
|
| 423 |
< |
if (msg_ptr) |
| 424 |
< |
parse_handle_command(msg_ptr, from, parc, para); |
| 423 |
> |
if (message) |
| 424 |
> |
parse_handle_command(message, from, parc, para); |
| 425 |
|
else |
| 426 |
|
parse_handle_numeric(numeric, from, parc, para); |
| 427 |
|
} |
| 467 |
|
*/ |
| 468 |
|
if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) == NULL) |
| 469 |
|
{ |
| 470 |
< |
ntree_p = MyCalloc(sizeof(struct MessageTree)); |
| 470 |
> |
ntree_p = xcalloc(sizeof(*ntree_p)); |
| 471 |
|
mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = ntree_p; |
| 472 |
|
|
| 473 |
|
mtree_p->links++; /* Have new pointer, so up ref count */ |
| 525 |
|
{ |
| 526 |
|
mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = NULL; |
| 527 |
|
mtree_p->links--; |
| 528 |
< |
MyFree(ntree_p); |
| 528 |
> |
xfree(ntree_p); |
| 529 |
|
} |
| 530 |
|
} |
| 531 |
|
} |
| 543 |
|
{ |
| 544 |
|
struct MessageTree *mtree = &msg_tree; |
| 545 |
|
|
| 546 |
< |
assert(cmd && *cmd); |
| 546 |
> |
assert(!EmptyString(cmd)); |
| 547 |
|
|
| 548 |
|
while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)])) |
| 549 |
|
if (*++cmd == '\0') |
| 561 |
|
void |
| 562 |
|
mod_add_cmd(struct Message *msg) |
| 563 |
|
{ |
| 564 |
< |
assert(msg && msg->cmd); |
| 564 |
> |
assert(msg); |
| 565 |
> |
assert(msg->cmd); |
| 566 |
|
|
| 567 |
|
/* Command already added? */ |
| 568 |
< |
if (msg_tree_parse(msg->cmd)) |
| 569 |
< |
return; |
| 565 |
< |
|
| 566 |
< |
add_msg_element(&msg_tree, msg, msg->cmd); |
| 568 |
> |
if (msg_tree_parse(msg->cmd) == NULL) |
| 569 |
> |
add_msg_element(&msg_tree, msg, msg->cmd); |
| 570 |
|
} |
| 571 |
|
|
| 572 |
|
/* mod_del_cmd() |
| 578 |
|
void |
| 579 |
|
mod_del_cmd(struct Message *msg) |
| 580 |
|
{ |
| 581 |
< |
assert(msg && msg->cmd); |
| 581 |
> |
assert(msg); |
| 582 |
> |
assert(msg->cmd); |
| 583 |
|
|
| 584 |
< |
if (!msg_tree_parse(msg->cmd)) |
| 585 |
< |
return; |
| 582 |
< |
|
| 583 |
< |
del_msg_element(&msg_tree, msg->cmd); |
| 584 |
> |
if (msg_tree_parse(msg->cmd)) |
| 585 |
> |
del_msg_element(&msg_tree, msg->cmd); |
| 586 |
|
} |
| 587 |
|
|
| 588 |
|
/* find_command() |