ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_pong.c
Revision: 5864
Committed: Tue Apr 28 12:23:30 2015 UTC (10 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 4404 byte(s)
Log Message:
- Removed useless zero initializers from the module_entry as suggested by Adam

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 5347 * Copyright (c) 1997-2015 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_pong.c
23     * \brief Includes required functions for processing the PONG command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "ircd.h"
29 michael 3347 #include "user.h"
30 adx 30 #include "client.h"
31 michael 2820 #include "hash.h"
32 adx 30 #include "numeric.h"
33 michael 1309 #include "conf.h"
34 adx 30 #include "send.h"
35     #include "irc_string.h"
36     #include "parse.h"
37     #include "modules.h"
38 michael 4712 #include "server.h"
39 adx 30
40    
41 michael 3346 /*! \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 michael 2820 static int
54 michael 3156 ms_pong(struct Client *source_p, int parc, char *parv[])
55 adx 30 {
56 michael 4712 struct Client *target_p = NULL;
57     const char *destination = NULL;
58 adx 30
59 michael 1121 if (parc < 2 || EmptyString(parv[1]))
60 adx 30 {
61 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
62 michael 2820 return 0;
63 adx 30 }
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 michael 1652 if (!EmptyString(destination) && match(destination, me.name) &&
74 adx 30 irccmp(destination, me.id))
75     {
76 michael 1169 if ((target_p = hash_find_client(destination)) ||
77 michael 4716 (target_p = hash_find_id(destination)))
78 michael 1169 sendto_one(target_p, ":%s PONG %s %s",
79 michael 4712 ID_or_name(source_p, target_p), parv[1],
80     ID_or_name(target_p, target_p));
81     else if (!IsDigit(*destination))
82 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination);
83 adx 30 }
84 michael 2820
85     return 0;
86 adx 30 }
87    
88 michael 3346 /*! \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 michael 2820 static int
100 michael 3156 mr_pong(struct Client *source_p, int parc, char *parv[])
101 adx 30 {
102 michael 3156 assert(MyConnect(source_p));
103 michael 503
104 michael 3331 if (parc == 2 && !EmptyString(parv[1]))
105 adx 30 {
106 michael 4886 if (ConfigGeneral.ping_cookie && source_p->connection->random_ping)
107 adx 30 {
108 michael 982 unsigned int incoming_ping = strtoul(parv[1], NULL, 10);
109 michael 503
110 michael 4886 if (source_p->connection->random_ping == incoming_ping)
111 michael 503 {
112 michael 4886 SetPingCookie(source_p);
113    
114     if (!source_p->connection->registration)
115 michael 1080 register_local_user(source_p);
116 adx 30 }
117 michael 4886 else
118     sendto_one_numeric(source_p, &me, ERR_WRONGPONG,
119     source_p->connection->random_ping);
120 adx 30 }
121 michael 503 }
122 adx 30 else
123 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
124    
125 michael 2820 return 0;
126 adx 30 }
127 michael 1230
128 michael 2820 static struct Message pong_msgtab =
129     {
130 michael 4545 "PONG", NULL, 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
131 michael 2820 { mr_pong, m_ignore, ms_pong, m_ignore, m_ignore, m_ignore }
132 michael 1230 };
133    
134     static void
135     module_init(void)
136     {
137     mod_add_cmd(&pong_msgtab);
138     }
139    
140     static void
141     module_exit(void)
142     {
143     mod_del_cmd(&pong_msgtab);
144     }
145    
146 michael 2820 struct module module_entry =
147     {
148 michael 1230 .version = "$Revision$",
149     .modinit = module_init,
150     .modexit = module_exit,
151     };

Properties

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