| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
* 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 |
static struct pseudo_cmd |
| 42 |
{ |
| 43 |
dlink_node node; |
| 44 |
struct Message *msg; |
| 45 |
char name[NICKLEN + 1]; |
| 46 |
char nick[NICKLEN + 1]; |
| 47 |
char serv[HOSTLEN + 1]; |
| 48 |
char prep[IRCD_BUFSIZE]; |
| 49 |
char cmmd[IRCD_BUFSIZE]; |
| 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 |
struct pseudo_cmd *pseudo = NULL; |
| 59 |
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 |
pseudo = (struct pseudo_cmd *)parv[1]; |
| 70 |
|
| 71 |
if (pseudo->prep[0]) |
| 72 |
{ |
| 73 |
snprintf(buffer, sizeof(buffer), "%s%s", pseudo->prep, msg); |
| 74 |
msg = buffer; |
| 75 |
} |
| 76 |
|
| 77 |
target_p = find_person(source_p, pseudo->nick); |
| 78 |
server_p = hash_find_server(pseudo->serv); |
| 79 |
|
| 80 |
if (target_p && server_p && (target_p->servptr == server_p)) |
| 81 |
{ |
| 82 |
sendto_one(target_p, ":%s PRIVMSG %s :%s", |
| 83 |
source_p->id, target_p->id, msg); |
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
sendto_one_numeric(source_p, &me, ERR_SERVICESDOWN, pseudo->name); |
| 88 |
return 0; |
| 89 |
} |
| 90 |
|
| 91 |
void |
| 92 |
pseudo_register(const char *name, const char *nick, |
| 93 |
const char *serv, const char *prep, |
| 94 |
const char *cmmd) |
| 95 |
{ |
| 96 |
struct Message *msg = NULL; |
| 97 |
struct pseudo_cmd *pseudo = NULL; |
| 98 |
|
| 99 |
if (find_command(cmmd)) |
| 100 |
return; |
| 101 |
|
| 102 |
pseudo = MyCalloc(sizeof(struct pseudo_cmd)); |
| 103 |
strlcpy(pseudo->name, name, sizeof(pseudo->name)); |
| 104 |
strlcpy(pseudo->nick, nick, sizeof(pseudo->nick)); |
| 105 |
strlcpy(pseudo->serv, serv, sizeof(pseudo->serv)); |
| 106 |
strlcpy(pseudo->prep, prep, sizeof(pseudo->prep)); |
| 107 |
strlcpy(pseudo->cmmd, cmmd, sizeof(pseudo->cmmd)); |
| 108 |
dlinkAdd(pseudo, &pseudo->node, &pseudo_cmd_list); |
| 109 |
|
| 110 |
msg = MyCalloc(sizeof(struct Message)); |
| 111 |
msg->cmd = pseudo->cmmd; |
| 112 |
msg->args_max = 2; |
| 113 |
msg->flags = MFLG_EXTRA|MFLG_SLOW; |
| 114 |
msg->extra = pseudo; |
| 115 |
msg->handlers[UNREGISTERED_HANDLER] = m_ignore; |
| 116 |
msg->handlers[CLIENT_HANDLER] = m_pseudo; |
| 117 |
msg->handlers[SERVER_HANDLER] = m_ignore; |
| 118 |
msg->handlers[ENCAP_HANDLER] = m_ignore; |
| 119 |
msg->handlers[OPER_HANDLER] = m_pseudo; |
| 120 |
msg->handlers[DUMMY_HANDLER] = m_ignore; |
| 121 |
|
| 122 |
mod_add_cmd(msg); |
| 123 |
pseudo->msg = msg; |
| 124 |
} |
| 125 |
|
| 126 |
void |
| 127 |
pseudo_clear(void) |
| 128 |
{ |
| 129 |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 130 |
|
| 131 |
DLINK_FOREACH_SAFE(ptr, ptr_next, pseudo_cmd_list.head) |
| 132 |
{ |
| 133 |
struct pseudo_cmd *pseudo = ptr->data; |
| 134 |
assert(find_command(pseudo->cmmd)); |
| 135 |
|
| 136 |
mod_del_cmd(pseudo->msg); |
| 137 |
MyFree(pseudo->msg); |
| 138 |
MyFree(pseudo); |
| 139 |
} |
| 140 |
} |