ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_pong.c
Revision: 5881
Committed: Sun May 3 16:04:15 2015 UTC (10 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 4533 byte(s)
Log Message:
- Use C99-style initializers in all struct Message items
- Removed MFLG_SLOW
- Removed DUMMY_HANDLER

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 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_pong.c
23 * \brief Includes required functions for processing the PONG command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "ircd.h"
29 #include "user.h"
30 #include "client.h"
31 #include "hash.h"
32 #include "numeric.h"
33 #include "conf.h"
34 #include "send.h"
35 #include "irc_string.h"
36 #include "parse.h"
37 #include "modules.h"
38 #include "server.h"
39
40
41 /*! \brief PONG command handler
42 *
43 * \param source_p Pointer to allocated Client struct from which the message
44 * originally comes from. This can be a local or remote client.
45 * \param parc Integer holding the number of supplied arguments.
46 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
47 * pointers.
48 * \note Valid arguments for this command are:
49 * - parv[0] = command
50 * - parv[1] = origin
51 * - parv[2] = destination
52 */
53 static int
54 ms_pong(struct Client *source_p, int parc, char *parv[])
55 {
56 struct Client *target_p = NULL;
57 const char *destination = NULL;
58
59 if (parc < 2 || EmptyString(parv[1]))
60 {
61 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
62 return 0;
63 }
64
65 destination = parv[2];
66
67 /* Now attempt to route the PONG, comstud pointed out routable PING
68 * is used for SPING. routable PING should also probably be left in
69 * -Dianora
70 * That being the case, we will route, but only for registered clients (a
71 * case can be made to allow them only from servers). -Shadowfax
72 */
73 if (!EmptyString(destination) && match(destination, me.name) &&
74 irccmp(destination, me.id))
75 {
76 if ((target_p = hash_find_client(destination)) ||
77 (target_p = hash_find_id(destination)))
78 sendto_one(target_p, ":%s PONG %s %s",
79 ID_or_name(source_p, target_p), parv[1],
80 ID_or_name(target_p, target_p));
81 else if (!IsDigit(*destination))
82 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination);
83 }
84
85 return 0;
86 }
87
88 /*! \brief PONG 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/ping cookie
98 */
99 static int
100 mr_pong(struct Client *source_p, int parc, char *parv[])
101 {
102 assert(MyConnect(source_p));
103
104 if (parc == 2 && !EmptyString(parv[1]))
105 {
106 if (ConfigGeneral.ping_cookie && source_p->connection->random_ping)
107 {
108 unsigned int incoming_ping = strtoul(parv[1], NULL, 10);
109
110 if (source_p->connection->random_ping == incoming_ping)
111 {
112 SetPingCookie(source_p);
113
114 if (!source_p->connection->registration)
115 register_local_user(source_p);
116 }
117 else
118 sendto_one_numeric(source_p, &me, ERR_WRONGPONG,
119 source_p->connection->random_ping);
120 }
121 }
122 else
123 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
124
125 return 0;
126 }
127
128 static struct Message pong_msgtab =
129 {
130 .cmd = "PONG",
131 .args_max = MAXPARA,
132 .handlers[UNREGISTERED_HANDLER] = mr_pong,
133 .handlers[CLIENT_HANDLER] = m_ignore,
134 .handlers[SERVER_HANDLER] = ms_pong,
135 .handlers[ENCAP_HANDLER] = m_ignore,
136 .handlers[OPER_HANDLER] = m_ignore
137 };
138
139 static void
140 module_init(void)
141 {
142 mod_add_cmd(&pong_msgtab);
143 }
144
145 static void
146 module_exit(void)
147 {
148 mod_del_cmd(&pong_msgtab);
149 }
150
151 struct module module_entry =
152 {
153 .version = "$Revision$",
154 .modinit = module_init,
155 .modexit = module_exit,
156 };

Properties

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