]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_links.c
Removal of ancient SVN ID's part one
[irc/rqf/shadowircd.git] / modules / m_links.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_links.c: Shows what servers are currently connected.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
212380e3 24 */
25
26#include "stdinc.h"
27#include "client.h"
13ae2f4b 28#include "match.h"
212380e3 29#include "ircd.h"
30#include "numeric.h"
31#include "s_serv.h"
32#include "send.h"
33#include "s_conf.h"
34#include "msg.h"
35#include "parse.h"
36#include "modules.h"
37#include "hook.h"
994544c2 38#include "scache.h"
212380e3 39
40static int m_links(struct Client *, struct Client *, int, const char **);
41static int mo_links(struct Client *, struct Client *, int, const char **);
c6b83227 42static char * clean_string(char *dest, const unsigned char *src, size_t len);
212380e3 43
44struct Message links_msgtab = {
45 "LINKS", 0, 0, 0, MFLG_SLOW,
46 {mg_unreg, {m_links, 0}, {mo_links, 0}, mg_ignore, mg_ignore, {mo_links, 0}}
47};
48
49int doing_links_hook;
50
51mapi_clist_av1 links_clist[] = { &links_msgtab, NULL };
52mapi_hlist_av1 links_hlist[] = {
53 { "doing_links", &doing_links_hook },
54 { NULL, NULL }
55};
56
57DECLARE_MODULE_AV1(links, NULL, NULL, links_clist, links_hlist, NULL, "$Revision: 254 $");
58
212380e3 59/*
60 * m_links - LINKS message handler
212380e3 61 * parv[1] = servername mask
62 * or
212380e3 63 * parv[1] = server to query
64 * parv[2] = servername mask
65 */
66static int
67m_links(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
68{
69 if(ConfigServerHide.flatten_links && !IsExemptShide(source_p))
994544c2 70 scache_send_flattened_links(source_p);
212380e3 71 else
72 mo_links(client_p, source_p, parc, parv);
73
74 return 0;
75}
76
77static int
78mo_links(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
79{
80 const char *mask = "";
81 struct Client *target_p;
82 char clean_mask[2 * HOSTLEN + 4];
83 hook_data hd;
84
08d11e34 85 rb_dlink_node *ptr;
212380e3 86
87 if(parc > 2)
88 {
30627435
JT
89 if(strlen(parv[2]) > HOSTLEN)
90 return 0;
212380e3 91 if(hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv)
92 != HUNTED_ISME)
93 return 0;
94
95 mask = parv[2];
96 }
97 else if(parc == 2)
98 mask = parv[1];
99
100 if(*mask) /* only necessary if there is a mask */
101 mask = collapse(clean_string
102 (clean_mask, (const unsigned char *) mask, 2 * HOSTLEN));
103
104 hd.client = source_p;
105 hd.arg1 = mask;
106 hd.arg2 = NULL;
107
108 call_hook(doing_links_hook, &hd);
109
08d11e34 110 RB_DLINK_FOREACH(ptr, global_serv_list.head)
212380e3 111 {
112 target_p = ptr->data;
113
114 if(*mask && !match(mask, target_p->name))
115 continue;
116
117 /* We just send the reply, as if theyre here theres either no SHIDE,
118 * or theyre an oper..
119 */
120 sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS),
66c8fdd2 121 target_p->name, target_p->servptr->name,
212380e3 122 target_p->hopcount,
123 target_p->info[0] ? target_p->info : "(Unknown Location)");
124 }
125
126 sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS),
127 EmptyString(mask) ? "*" : mask);
128
129 return 0;
130}
131
c6b83227
VY
132static char *
133clean_string(char *dest, const unsigned char *src, size_t len)
134{
135 char *d = dest;
136 s_assert(0 != dest);
137 s_assert(0 != src);
138
139 if(dest == NULL || src == NULL)
140 return NULL;
141
30627435 142 while (*src && (len > 1))
c6b83227
VY
143 {
144 if(*src & 0x80) /* if high bit is set */
145 {
146 *d++ = '.';
147 --len;
30627435
JT
148 if(len <= 1)
149 break;
c6b83227
VY
150 }
151 else if(!IsPrint(*src)) /* if NOT printable */
152 {
153 *d++ = '^';
154 --len;
30627435
JT
155 if(len <= 1)
156 break;
c6b83227
VY
157 *d++ = 0x40 + *src; /* turn it into a printable */
158 }
159 else
160 *d++ = *src;
161 ++src;
162 --len;
163 }
164 *d = '\0';
165 return dest;
166}