| 1 |
michael |
4545 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
|
* |
| 4 |
michael |
5347 |
* Copyright (c) 1997-2015 ircd-hybrid development team |
| 5 |
michael |
4545 |
* |
| 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 |
| 8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
|
|
* (at your option) any later version. |
| 10 |
|
|
* |
| 11 |
|
|
* This program is distributed in the hope that it will be useful, |
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
* GNU General Public License for more details. |
| 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 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
michael |
4545 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
|
|
/*! \file conf_pseudo.c |
| 23 |
|
|
* \brief Handles with pseudo commands/service aliases. |
| 24 |
|
|
* \version $Id: conf_pseudo.c 4299 2014-07-20 13:51:28Z michael $ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
|
|
#include "stdinc.h" |
| 28 |
|
|
#include "list.h" |
| 29 |
|
|
#include "client.h" |
| 30 |
|
|
#include "parse.h" |
| 31 |
|
|
#include "hash.h" |
| 32 |
|
|
#include "irc_string.h" |
| 33 |
|
|
#include "ircd.h" |
| 34 |
|
|
#include "numeric.h" |
| 35 |
|
|
#include "send.h" |
| 36 |
|
|
#include "memory.h" |
| 37 |
|
|
#include "user.h" |
| 38 |
|
|
#include "server.h" |
| 39 |
|
|
#include "conf_pseudo.h" |
| 40 |
|
|
|
| 41 |
|
|
struct pseudo_cmd |
| 42 |
|
|
{ |
| 43 |
|
|
dlink_node node; |
| 44 |
|
|
struct Message msg; |
| 45 |
|
|
char *name; |
| 46 |
|
|
char *nick; |
| 47 |
|
|
char *serv; |
| 48 |
|
|
char *prep; |
| 49 |
|
|
char *command; |
| 50 |
|
|
}; |
| 51 |
|
|
|
| 52 |
|
|
static dlink_list pseudo_cmd_list; |
| 53 |
|
|
|
| 54 |
|
|
static int |
| 55 |
|
|
m_pseudo(struct Client *source_p, int parc, char *parv[]) |
| 56 |
|
|
{ |
| 57 |
|
|
char buffer[IRCD_BUFSIZE] = ""; |
| 58 |
michael |
4921 |
const struct pseudo_cmd *const pseudo = (const struct pseudo_cmd *)parv[1]; |
| 59 |
michael |
4545 |
struct Client *target_p = NULL; |
| 60 |
|
|
struct Client *server_p = NULL; |
| 61 |
|
|
const char *msg = parv[parc - 1]; |
| 62 |
|
|
|
| 63 |
|
|
if (parc < 3 || EmptyString(msg)) |
| 64 |
|
|
{ |
| 65 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOTEXTTOSEND); |
| 66 |
|
|
return 0; |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
|
if (!EmptyString(pseudo->prep)) |
| 70 |
|
|
{ |
| 71 |
|
|
snprintf(buffer, sizeof(buffer), "%s%s", pseudo->prep, msg); |
| 72 |
|
|
msg = buffer; |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
target_p = find_person(source_p, pseudo->nick); |
| 76 |
|
|
server_p = hash_find_server(pseudo->serv); |
| 77 |
|
|
|
| 78 |
|
|
if (target_p && server_p && (target_p->servptr == server_p) && !IsMe(server_p)) |
| 79 |
|
|
{ |
| 80 |
|
|
sendto_one(target_p, ":%s PRIVMSG %s :%s", |
| 81 |
|
|
source_p->id, target_p->id, msg); |
| 82 |
|
|
return 0; |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
|
|
sendto_one_numeric(source_p, &me, ERR_SERVICESDOWN, pseudo->name); |
| 86 |
|
|
return 0; |
| 87 |
|
|
} |
| 88 |
|
|
|
| 89 |
|
|
void |
| 90 |
|
|
pseudo_register(const char *name, const char *nick, |
| 91 |
|
|
const char *serv, const char *prep, |
| 92 |
|
|
const char *command) |
| 93 |
|
|
{ |
| 94 |
|
|
struct pseudo_cmd *cmd = NULL; |
| 95 |
|
|
|
| 96 |
|
|
if (find_command(command)) |
| 97 |
|
|
return; |
| 98 |
|
|
|
| 99 |
|
|
cmd = MyCalloc(sizeof(*cmd)); |
| 100 |
|
|
cmd->name = xstrdup(name); |
| 101 |
|
|
cmd->nick = xstrdup(nick); |
| 102 |
|
|
cmd->serv = xstrdup(serv); |
| 103 |
|
|
cmd->prep = xstrdup(prep); |
| 104 |
|
|
cmd->command = xstrdup(command); |
| 105 |
|
|
|
| 106 |
|
|
cmd->msg.cmd = cmd->command; |
| 107 |
|
|
cmd->msg.args_max = 2; |
| 108 |
michael |
5583 |
cmd->msg.flags = MFLG_EXTRA | MFLG_SLOW; |
| 109 |
michael |
4545 |
cmd->msg.extra = cmd; |
| 110 |
|
|
cmd->msg.handlers[UNREGISTERED_HANDLER] = m_unregistered; |
| 111 |
|
|
cmd->msg.handlers[CLIENT_HANDLER] = m_pseudo; |
| 112 |
|
|
cmd->msg.handlers[SERVER_HANDLER] = m_ignore; |
| 113 |
|
|
cmd->msg.handlers[ENCAP_HANDLER] = m_ignore; |
| 114 |
|
|
cmd->msg.handlers[OPER_HANDLER] = m_pseudo; |
| 115 |
|
|
cmd->msg.handlers[DUMMY_HANDLER] = m_ignore; |
| 116 |
|
|
dlinkAdd(cmd, &cmd->node, &pseudo_cmd_list); |
| 117 |
|
|
|
| 118 |
|
|
mod_add_cmd(&cmd->msg); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
void |
| 122 |
|
|
pseudo_clear(void) |
| 123 |
|
|
{ |
| 124 |
michael |
4815 |
dlink_node *node = NULL, *node_next = NULL; |
| 125 |
michael |
4545 |
|
| 126 |
michael |
4815 |
DLINK_FOREACH_SAFE(node, node_next, pseudo_cmd_list.head) |
| 127 |
michael |
4545 |
{ |
| 128 |
michael |
4815 |
struct pseudo_cmd *cmd = node->data; |
| 129 |
michael |
4545 |
assert(find_command(cmd->msg.cmd)); |
| 130 |
|
|
|
| 131 |
|
|
mod_del_cmd(&cmd->msg); |
| 132 |
|
|
dlinkDelete(&cmd->node, &pseudo_cmd_list); |
| 133 |
|
|
|
| 134 |
|
|
MyFree(cmd->name); |
| 135 |
|
|
MyFree(cmd->nick); |
| 136 |
|
|
MyFree(cmd->serv); |
| 137 |
|
|
MyFree(cmd->prep); |
| 138 |
|
|
MyFree(cmd->command); |
| 139 |
|
|
MyFree(cmd); |
| 140 |
|
|
} |
| 141 |
|
|
} |