ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_map.c
Revision: 7330
Committed: Fri Feb 19 17:50:13 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 5749 byte(s)
Log Message:
- Now that we got time_t to work nicely on openbsd with snprintf's conversion specifiers,
  we ran into a similiar issue on Raspbian/ARMv7's time_t which is of signed 32 bit and
  doesn't cope at all with %j. Instead of doing tricks, get rid of time_t everywhere and
  forever and use uintmax_t instead which has at least a 'standardized' conversion specifier
  associated with it.

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-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_map.c
23 * \brief Includes required functions for processing the MAP command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "client.h"
29 #include "modules.h"
30 #include "numeric.h"
31 #include "send.h"
32 #include "conf.h"
33 #include "ircd.h"
34 #include "parse.h"
35
36
37 static void dump_map(struct Client *client,
38 struct Client *server,
39 unsigned int prompt_length)
40 {
41 dlink_node *node = NULL;
42 struct Client *target_p = NULL;
43 static char prompt[64];
44 char buf[IRCD_BUFSIZE];
45 char *p = prompt + prompt_length;
46 unsigned int cnt = 0;
47 unsigned int bufpos = 0;
48
49 *p = '\0';
50
51 if (prompt_length > 60)
52 sendto_one_numeric(client, &me, RPL_MAPMORE, prompt, server->name);
53 else
54 {
55 int dashes;
56
57 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "%s", server->name);
58
59 if (HasUMode(client, UMODE_OPER))
60 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "[%s]", server->id);
61
62 buf[bufpos++] = ' ';
63 dashes = 50 - bufpos - prompt_length;
64 for (; dashes > 0; --dashes)
65 buf[bufpos++] = '-';
66 buf[bufpos++] = ' ';
67 buf[bufpos++] = '|';
68
69 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, " Users: %5d (%1.2f%%)",
70 dlink_list_length(&server->serv->client_list), 100 *
71 (float)dlink_list_length(&server->serv->client_list) /
72 (float)Count.total);
73 sendto_one_numeric(client, &me, RPL_MAP, prompt, buf);
74 }
75
76 if (prompt_length > 0)
77 {
78 *(p - 1) = ' ';
79
80 if (*(p - 2) == '`')
81 *(p - 2) = ' ';
82 }
83
84 if (prompt_length > 60)
85 return;
86 strcpy(p, "|-");
87
88 DLINK_FOREACH(node, server->serv->server_list.head)
89 {
90 target_p = node->data;
91
92 if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER))
93 continue;
94
95 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
96 if (!HasUMode(client, UMODE_OPER))
97 continue;
98
99 ++cnt;
100 }
101
102 DLINK_FOREACH(node, server->serv->server_list.head)
103 {
104 target_p = node->data;
105
106 if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER))
107 continue;
108
109 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
110 if (!HasUMode(client, UMODE_OPER))
111 continue;
112
113 if (--cnt == 0)
114 *p = '`';
115 dump_map(client, target_p, prompt_length + 2);
116 }
117
118 if (prompt_length > 0)
119 *(p - 1) = '-';
120 }
121
122 /*! \brief Sends a network topology map and notifies irc-operators
123 * about the MAP request
124 *
125 * \param source_p Pointer to client to report to
126 */
127 static void
128 do_map(struct Client *source_p)
129 {
130 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
131 "MAP requested by %s (%s@%s) [%s]",
132 source_p->name, source_p->username,
133 source_p->host, source_p->servptr->name);
134 dump_map(source_p, &me, 0);
135 }
136
137 /*! \brief MAP command handler
138 *
139 * \param source_p Pointer to allocated Client struct from which the message
140 * originally comes from. This can be a local or remote client.
141 * \param parc Integer holding the number of supplied arguments.
142 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
143 * pointers.
144 * \note Valid arguments for this command are:
145 * - parv[0] = command
146 */
147 static int
148 m_map(struct Client *source_p, int parc, char *parv[])
149 {
150 static uintmax_t last_used = 0;
151
152 if (ConfigServerHide.flatten_links)
153 return m_not_oper(source_p, parc, parv);
154
155 if ((last_used + ConfigGeneral.pace_wait) > CurrentTime)
156 {
157 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "MAP");
158 return 0;
159 }
160
161 last_used = CurrentTime;
162
163 do_map(source_p);
164 sendto_one_numeric(source_p, &me, RPL_MAPEND);
165 return 0;
166 }
167
168 /*! \brief MAP command handler
169 *
170 * \param source_p Pointer to allocated Client struct from which the message
171 * originally comes from. This can be a local or remote client.
172 * \param parc Integer holding the number of supplied arguments.
173 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
174 * pointers.
175 * \note Valid arguments for this command are:
176 * - parv[0] = command
177 */
178 static int
179 mo_map(struct Client *source_p, int parc, char *parv[])
180 {
181 do_map(source_p);
182 sendto_one_numeric(source_p, &me, RPL_MAPEND);
183 return 0;
184 }
185
186 static struct Message map_msgtab =
187 {
188 .cmd = "MAP",
189 .args_max = MAXPARA,
190 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
191 .handlers[CLIENT_HANDLER] = m_map,
192 .handlers[SERVER_HANDLER] = m_ignore,
193 .handlers[ENCAP_HANDLER] = m_ignore,
194 .handlers[OPER_HANDLER] = mo_map
195 };
196
197 static void
198 module_init(void)
199 {
200 mod_add_cmd(&map_msgtab);
201 }
202
203 static void
204 module_exit(void)
205 {
206 mod_del_cmd(&map_msgtab);
207 }
208
209 struct module module_entry =
210 {
211 .version = "$Revision$",
212 .modinit = module_init,
213 .modexit = module_exit,
214 };

Properties

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