/[svn]/ircd-hybrid/branches/8.2.x/modules/m_ping.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/m_ping.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4714 - (show annotations)
Tue Oct 7 11:02:17 2014 UTC (5 years, 9 months ago) by michael
File MIME type: text/x-chdr
File size: 4755 byte(s)
- m_ping.c:ms_ping(): added sanity test for wrong directed PING messages as suggested by Adam.
  Needs more discussion whether that test is still needed with TS6

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., 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 const char *destination = NULL;
57
58 if (parc < 2 || EmptyString(parv[1]))
59 {
60 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
61 return 0;
62 }
63
64 destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */
65
66 if (ConfigServerHide.disable_remote_commands && !HasUMode(source_p, UMODE_OPER))
67 {
68 sendto_one(source_p, ":%s PONG %s :%s", me.name,
69 (destination) ? destination : me.name, parv[1]);
70 return 0;
71 }
72
73 if (!EmptyString(destination) && irccmp(destination, me.name))
74 {
75 if ((target_p = hash_find_server(destination)))
76 sendto_one(target_p, ":%s PING %s :%s",
77 ID_or_name(source_p, target_p), source_p->name,
78 ID_or_name(target_p, target_p));
79 else
80 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination);
81 }
82 else
83 sendto_one(source_p, ":%s PONG %s :%s", me.name,
84 (destination) ? destination : me.name, parv[1]);
85 return 0;
86 }
87
88 /*! \brief PING command handler
89 *
90 * \param source_p Pointer to allocated Client struct from which the message
91 * originally comes from. This can be a local or remote client.
92 * \param parc Integer holding the number of supplied arguments.
93 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
94 * pointers.
95 * \note Valid arguments for this command are:
96 * - parv[0] = command
97 * - parv[1] = origin
98 * - parv[2] = destination
99 */
100 static int
101 ms_ping(struct Client *source_p, int parc, char *parv[])
102 {
103 struct Client *target_p = NULL;
104 const char *destination = NULL;
105
106 if (parc < 2 || EmptyString(parv[1]))
107 {
108 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
109 return 0;
110 }
111
112 destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */
113
114 if (!EmptyString(destination) && irccmp(destination, me.name) && irccmp(destination, me.id))
115 {
116 if ((target_p = hash_find_server(destination)))
117 {
118 if (target_p->from != source_p->from)
119 sendto_one(target_p, ":%s PING %s :%s",
120 ID_or_name(source_p, target_p), source_p->name,
121 ID_or_name(target_p, target_p));
122 }
123 else if (!IsDigit(*destination))
124 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination);
125 }
126 else
127 sendto_one(source_p, ":%s PONG %s :%s", ID_or_name(&me, source_p),
128 (destination) ? destination : me.name, ID_or_name(source_p, source_p));
129 return 0;
130 }
131
132 static struct Message ping_msgtab =
133 {
134 "PING", NULL, 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
135 { m_unregistered, m_ping, ms_ping, m_ignore, m_ping, m_ping }
136 };
137
138 static void
139 module_init(void)
140 {
141 mod_add_cmd(&ping_msgtab);
142 }
143
144 static void
145 module_exit(void)
146 {
147 mod_del_cmd(&ping_msgtab);
148 }
149
150 struct module module_entry =
151 {
152 .node = { NULL, NULL, NULL },
153 .name = NULL,
154 .version = "$Revision$",
155 .handle = NULL,
156 .modinit = module_init,
157 .modexit = module_exit,
158 .flags = 0
159 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28