ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_ping.c
Revision: 7006
Committed: Fri Jan 1 00:07:54 2016 UTC (10 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 4798 byte(s)
Log Message:
- Update copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2016 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 .cmd = "PING",
135 .args_max = MAXPARA,
136 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
137 .handlers[CLIENT_HANDLER] = m_ping,
138 .handlers[SERVER_HANDLER] = ms_ping,
139 .handlers[ENCAP_HANDLER] = m_ignore,
140 .handlers[OPER_HANDLER] = m_ping
141 };
142
143 static void
144 module_init(void)
145 {
146 mod_add_cmd(&ping_msgtab);
147 }
148
149 static void
150 module_exit(void)
151 {
152 mod_del_cmd(&ping_msgtab);
153 }
154
155 struct module module_entry =
156 {
157 .version = "$Revision$",
158 .modinit = module_init,
159 .modexit = module_exit,
160 };

Properties

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