1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2019 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 m_ping.c |
23 |
* \brief Includes required functions for processing the PING command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "ircd.h" |
30 |
#include "numeric.h" |
31 |
#include "send.h" |
32 |
#include "irc_string.h" |
33 |
#include "parse.h" |
34 |
#include "modules.h" |
35 |
#include "hash.h" |
36 |
#include "conf.h" |
37 |
#include "server.h" |
38 |
|
39 |
|
40 |
/*! \brief PING command handler |
41 |
* |
42 |
* \param source_p Pointer to allocated Client struct from which the message |
43 |
* originally comes from. This can be a local or remote client. |
44 |
* \param parc Integer holding the number of supplied arguments. |
45 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
46 |
* pointers. |
47 |
* \note Valid arguments for this command are: |
48 |
* - parv[0] = command |
49 |
* - parv[1] = origin |
50 |
* - parv[2] = destination |
51 |
*/ |
52 |
static int |
53 |
m_ping(struct Client *source_p, int parc, char *parv[]) |
54 |
{ |
55 |
struct Client *target_p = NULL; |
56 |
|
57 |
if (parc < 2 || EmptyString(parv[1])) |
58 |
{ |
59 |
sendto_one_numeric(source_p, &me, ERR_NOORIGIN); |
60 |
return 0; |
61 |
} |
62 |
|
63 |
const char *const destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ |
64 |
if (ConfigServerHide.disable_remote_commands && !HasUMode(source_p, UMODE_OPER)) |
65 |
{ |
66 |
sendto_one(source_p, ":%s PONG %s :%s", me.name, |
67 |
(destination) ? destination : me.name, parv[1]); |
68 |
return 0; |
69 |
} |
70 |
|
71 |
if (EmptyString(destination) || ((target_p = hash_find_server(destination)) && IsMe(target_p))) |
72 |
sendto_one(source_p, ":%s PONG %s :%s", me.name, me.name, parv[1]); |
73 |
else if (target_p) |
74 |
sendto_one(target_p, ":%s PING %s :%s", |
75 |
ID_or_name(source_p, target_p), source_p->name, |
76 |
ID_or_name(target_p, target_p)); |
77 |
else |
78 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination); |
79 |
|
80 |
return 0; |
81 |
} |
82 |
|
83 |
/*! \brief PING command handler |
84 |
* |
85 |
* \param source_p Pointer to allocated Client struct from which the message |
86 |
* originally comes from. This can be a local or remote client. |
87 |
* \param parc Integer holding the number of supplied arguments. |
88 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
89 |
* pointers. |
90 |
* \note Valid arguments for this command are: |
91 |
* - parv[0] = command |
92 |
* - parv[1] = origin |
93 |
* - parv[2] = destination |
94 |
*/ |
95 |
static int |
96 |
ms_ping(struct Client *source_p, int parc, char *parv[]) |
97 |
{ |
98 |
struct Client *target_p = NULL; |
99 |
|
100 |
if (parc < 2 || EmptyString(parv[1])) |
101 |
{ |
102 |
sendto_one_numeric(source_p, &me, ERR_NOORIGIN); |
103 |
return 0; |
104 |
} |
105 |
|
106 |
const char *const destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ |
107 |
if (EmptyString(destination) || ((target_p = hash_find_server(destination)) && IsMe(target_p))) |
108 |
sendto_one(source_p, ":%s PONG %s :%s", ID_or_name(&me, source_p), |
109 |
me.name, ID_or_name(source_p, source_p)); |
110 |
else if (target_p) |
111 |
{ |
112 |
if (target_p->from != source_p->from) |
113 |
sendto_one(target_p, ":%s PING %s :%s", |
114 |
ID_or_name(source_p, target_p), source_p->name, |
115 |
ID_or_name(target_p, target_p)); |
116 |
} |
117 |
else if (!IsDigit(*destination)) |
118 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination); |
119 |
|
120 |
return 0; |
121 |
} |
122 |
|
123 |
static struct Message ping_msgtab = |
124 |
{ |
125 |
.cmd = "PING", |
126 |
.args_max = MAXPARA, |
127 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
128 |
.handlers[CLIENT_HANDLER] = m_ping, |
129 |
.handlers[SERVER_HANDLER] = ms_ping, |
130 |
.handlers[ENCAP_HANDLER] = m_ignore, |
131 |
.handlers[OPER_HANDLER] = m_ping |
132 |
}; |
133 |
|
134 |
static void |
135 |
module_init(void) |
136 |
{ |
137 |
mod_add_cmd(&ping_msgtab); |
138 |
} |
139 |
|
140 |
static void |
141 |
module_exit(void) |
142 |
{ |
143 |
mod_del_cmd(&ping_msgtab); |
144 |
} |
145 |
|
146 |
struct module module_entry = |
147 |
{ |
148 |
.version = "$Revision$", |
149 |
.modinit = module_init, |
150 |
.modexit = module_exit, |
151 |
}; |