2 * ircd-ratbox: A slightly useful ircd.
3 * m_links.c: Shows what servers are currently connected.
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
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.
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.
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
40 static int m_links(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
41 static int mo_links(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
42 static char * clean_string(char *dest
, const unsigned char *src
, size_t len
);
44 struct Message links_msgtab
= {
46 {mg_unreg
, {m_links
, 0}, {mo_links
, 0}, mg_ignore
, mg_ignore
, {mo_links
, 0}}
51 mapi_clist_av1 links_clist
[] = { &links_msgtab
, NULL
};
52 mapi_hlist_av1 links_hlist
[] = {
53 { "doing_links", &doing_links_hook
},
57 DECLARE_MODULE_AV2(links
, NULL
, NULL
, links_clist
, links_hlist
, NULL
, NULL
, NULL
, NULL
);
60 * m_links - LINKS message handler
61 * parv[1] = servername mask
63 * parv[1] = server to query
64 * parv[2] = servername mask
67 m_links(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
69 if(ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))
70 scache_send_flattened_links(source_p
);
72 mo_links(msgbuf_p
, client_p
, source_p
, parc
, parv
);
78 mo_links(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
80 const char *mask
= "";
81 struct Client
*target_p
;
82 char clean_mask
[2 * HOSTLEN
+ 4];
89 if(strlen(parv
[2]) > HOSTLEN
)
91 if(hunt_server(client_p
, source_p
, ":%s LINKS %s :%s", 1, parc
, parv
)
100 if(*mask
) /* only necessary if there is a mask */
101 mask
= collapse(clean_string
102 (clean_mask
, (const unsigned char *) mask
, 2 * HOSTLEN
));
104 hd
.client
= source_p
;
108 call_hook(doing_links_hook
, &hd
);
110 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
112 target_p
= ptr
->data
;
114 if(*mask
&& !match(mask
, target_p
->name
))
117 /* We just send the reply, as if theyre here theres either no SHIDE,
118 * or theyre an oper..
120 sendto_one_numeric(source_p
, RPL_LINKS
, form_str(RPL_LINKS
),
121 target_p
->name
, target_p
->servptr
->name
,
123 target_p
->info
[0] ? target_p
->info
: "(Unknown Location)");
126 sendto_one_numeric(source_p
, RPL_ENDOFLINKS
, form_str(RPL_ENDOFLINKS
),
127 EmptyString(mask
) ? "*" : mask
);
133 clean_string(char *dest
, const unsigned char *src
, size_t len
)
139 if(dest
== NULL
|| src
== NULL
)
142 while (*src
&& (len
> 1))
144 if(*src
& 0x80) /* if high bit is set */
151 else if(!IsPrint(*src
)) /* if NOT printable */
157 *d
++ = 0x40 + *src
; /* turn it into a printable */