| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 2014-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 |
| 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
* USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/*! \file conf_pseudo.c |
| 23 |
* \brief Handles with pseudo commands/service aliases. |
| 24 |
* \version $Id$ |
| 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 |
|
| 42 |
static dlink_list pseudo_list; |
| 43 |
|
| 44 |
|
| 45 |
const dlink_list * |
| 46 |
pseudo_get_list(void) |
| 47 |
{ |
| 48 |
return &pseudo_list; |
| 49 |
} |
| 50 |
|
| 51 |
static int |
| 52 |
pseudo_message_handler(struct Client *source_p, int parc, char *parv[]) |
| 53 |
{ |
| 54 |
char buffer[IRCD_BUFSIZE] = ""; |
| 55 |
const struct PseudoItem *const pseudo = (const struct PseudoItem *)parv[1]; |
| 56 |
struct Client *target_p = NULL; |
| 57 |
struct Client *server_p = NULL; |
| 58 |
const char *msg = parv[parc - 1]; |
| 59 |
|
| 60 |
if (parc < 3 || EmptyString(msg)) |
| 61 |
{ |
| 62 |
sendto_one_numeric(source_p, &me, ERR_NOTEXTTOSEND); |
| 63 |
return 0; |
| 64 |
} |
| 65 |
|
| 66 |
if (pseudo->prepend) |
| 67 |
{ |
| 68 |
snprintf(buffer, sizeof(buffer), "%s%s", pseudo->prepend, msg); |
| 69 |
msg = buffer; |
| 70 |
} |
| 71 |
|
| 72 |
target_p = find_person(source_p, pseudo->nick); |
| 73 |
server_p = hash_find_server(pseudo->serv); |
| 74 |
|
| 75 |
if (target_p && server_p && (target_p->servptr == server_p) && !IsMe(server_p)) |
| 76 |
{ |
| 77 |
sendto_one(target_p, ":%s PRIVMSG %s :%s", |
| 78 |
source_p->id, target_p->id, msg); |
| 79 |
return 0; |
| 80 |
} |
| 81 |
|
| 82 |
sendto_one_numeric(source_p, &me, ERR_SERVICESDOWN, pseudo->name); |
| 83 |
return 0; |
| 84 |
} |
| 85 |
|
| 86 |
void |
| 87 |
pseudo_register(const char *name, const char *nick, const char *serv, |
| 88 |
const char *prepend, |
| 89 |
const char *command) |
| 90 |
{ |
| 91 |
if (find_command(command)) |
| 92 |
return; |
| 93 |
|
| 94 |
struct PseudoItem *pseudo = xcalloc(sizeof(*pseudo)); |
| 95 |
pseudo->name = xstrdup(name); |
| 96 |
pseudo->nick = xstrdup(nick); |
| 97 |
pseudo->serv = xstrdup(serv); |
| 98 |
pseudo->command = xstrdup(command); |
| 99 |
if (!EmptyString(prepend)) |
| 100 |
pseudo->prepend = xstrdup(prepend); |
| 101 |
|
| 102 |
pseudo->msg.cmd = pseudo->command; |
| 103 |
pseudo->msg.args_max = 2; |
| 104 |
pseudo->msg.flags = MFLG_EXTRA; |
| 105 |
pseudo->msg.extra = pseudo; |
| 106 |
pseudo->msg.handlers[UNREGISTERED_HANDLER] = m_unregistered; |
| 107 |
pseudo->msg.handlers[CLIENT_HANDLER] = pseudo_message_handler; |
| 108 |
pseudo->msg.handlers[SERVER_HANDLER] = m_ignore; |
| 109 |
pseudo->msg.handlers[ENCAP_HANDLER] = m_ignore; |
| 110 |
pseudo->msg.handlers[OPER_HANDLER] = pseudo_message_handler; |
| 111 |
dlinkAdd(pseudo, &pseudo->node, &pseudo_list); |
| 112 |
|
| 113 |
mod_add_cmd(&pseudo->msg); |
| 114 |
} |
| 115 |
|
| 116 |
void |
| 117 |
pseudo_clear(void) |
| 118 |
{ |
| 119 |
while (pseudo_list.head) |
| 120 |
{ |
| 121 |
struct PseudoItem *pseudo = pseudo_list.head->data; |
| 122 |
assert(find_command(pseudo->msg.cmd)); |
| 123 |
|
| 124 |
mod_del_cmd(&pseudo->msg); |
| 125 |
dlinkDelete(&pseudo->node, &pseudo_list); |
| 126 |
|
| 127 |
xfree(pseudo->name); |
| 128 |
xfree(pseudo->nick); |
| 129 |
xfree(pseudo->serv); |
| 130 |
xfree(pseudo->prepend); |
| 131 |
xfree(pseudo->command); |
| 132 |
xfree(pseudo); |
| 133 |
} |
| 134 |
} |