ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_links.c
Revision: 91
Committed: Sat Oct 8 03:46:09 2005 UTC (20 years, 10 months ago) by db
Content type: text/x-csrc
File size: 5535 byte(s)
Log Message:
- Split out most of the *line *resv stuff into separate file
  parse_aline.c should go eventually into the subdir conf
- removed double -o in Makefile.in in src, this caused compile to fail for me


File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_links.c: Shows what servers are currently connected.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "ircd.h"
29     #include "numeric.h"
30     #include "s_serv.h"
31     #include "send.h"
32     #include "s_conf.h"
33     #include "msg.h"
34     #include "motd.h"
35     #include "parse.h"
36     #include "modules.h"
37    
38     static void do_links(struct Client *, int, char **);
39     static void m_links(struct Client*, struct Client*, int, char**);
40     static void mo_links(struct Client*, struct Client*, int, char**);
41     static void ms_links(struct Client*, struct Client*, int, char**);
42    
43     struct Message links_msgtab = {
44     "LINKS", 0, 0, 0, 0, MFLG_SLOW, 0,
45     {m_unregistered, m_links, ms_links, m_ignore, mo_links, m_ignore}
46     };
47    
48     #ifndef STATIC_MODULES
49 knight 31 const char *_version = "$Revision$";
50 adx 30 static struct Callback *links_cb;
51    
52     static void *
53     va_links(va_list args)
54     {
55     struct Client *source_p = va_arg(args, struct Client *);
56     int parc = va_arg(args, int);
57     char **parv = va_arg(args, char **);
58    
59     do_links(source_p, parc, parv);
60     return NULL;
61     }
62    
63     void
64     _modinit(void)
65     {
66     links_cb = register_callback("doing_links", va_links);
67     mod_add_cmd(&links_msgtab);
68     }
69    
70     void
71     _moddeinit(void)
72     {
73     mod_del_cmd(&links_msgtab);
74     uninstall_hook(links_cb, va_links);
75     }
76    
77     #endif
78    
79     static void
80     do_links(struct Client *source_p, int parc, char **parv)
81     {
82     if (IsOper(source_p) || !ConfigServerHide.flatten_links)
83     {
84     char *mask = (parc > 2 ? parv[2] : parv[1]);
85     const char *me_name, *nick, *p;
86     struct Client *target_p;
87     char clean_mask[2 * HOSTLEN + 4];
88     dlink_node *ptr;
89    
90     if (mask == NULL)
91     mask = "";
92     if (*mask) /* only necessary if there is a mask */
93     mask = collapse(clean_string(clean_mask, (const unsigned char*) mask, 2 * HOSTLEN));
94    
95     me_name = ID_or_name(&me, source_p->from);
96     nick = ID_or_name(source_p, source_p->from);
97    
98     DLINK_FOREACH(ptr, global_serv_list.head)
99     {
100     target_p = ptr->data;
101    
102     if (*mask && !match(mask, target_p->name))
103     continue;
104    
105     if (target_p->info[0])
106     {
107     if ((p = strchr(target_p->info, ']')))
108     p += 2; /* skip the nasty [IP] part */
109     else
110     p = target_p->info;
111     }
112     else
113     p = "(Unknown Location)";
114    
115     /* We just send the reply, as if they are here there's either no SHIDE,
116     * or they're an oper..
117     */
118     sendto_one(source_p, form_str(RPL_LINKS),
119     me_name, nick,
120     target_p->name, target_p->servptr->name,
121     target_p->hopcount, p);
122     }
123    
124     sendto_one(source_p, form_str(RPL_ENDOFLINKS),
125     me_name, nick,
126     EmptyString(mask) ? "*" : mask);
127     }
128 db 91 else
129     {
130 adx 30 /*
131     * Print our own info so at least it looks like a normal links
132     * then print out the file (which may or may not be empty)
133     */
134     sendto_one(source_p, form_str(RPL_LINKS),
135     ID_or_name(&me, source_p->from),
136     ID_or_name(source_p, source_p->from),
137     me.name, me.name, 0, me.info);
138     send_message_file(source_p, &ConfigFileEntry.linksfile);
139     sendto_one(source_p, form_str(RPL_ENDOFLINKS),
140     ID_or_name(&me, source_p->from), "*");
141     }
142     }
143    
144     /*
145     * m_links - LINKS message handler
146     * parv[0] = sender prefix
147     * parv[1] = servername mask
148     * or
149     * parv[0] = sender prefix
150     * parv[1] = server to query
151     * parv[2] = servername mask
152     */
153     static void
154     m_links(struct Client *client_p, struct Client *source_p,
155     int parc, char *parv[])
156     {
157     if (!ConfigServerHide.flatten_links)
158     {
159     mo_links(client_p, source_p, parc, parv);
160     return;
161     }
162    
163     #ifdef STATIC_MODULES
164     do_links(source_p, parc, parv);
165     #else
166     execute_callback(links_cb, source_p, parc, parv);
167     #endif
168     }
169    
170     static void
171     mo_links(struct Client *client_p, struct Client *source_p,
172     int parc, char *parv[])
173     {
174     if (parc > 2)
175     if (!ConfigFileEntry.disable_remote || IsOper(source_p))
176     {
177     if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv)
178     != HUNTED_ISME)
179     return;
180     }
181    
182     #ifdef STATIC_MODULES
183     do_links(source_p, parc, parv);
184     #else
185     execute_callback(links_cb, source_p, parc, parv);
186     #endif
187     }
188    
189     /*
190     * ms_links - LINKS message handler
191     * parv[0] = sender prefix
192     * parv[1] = servername mask
193     * or
194     * parv[0] = sender prefix
195     * parv[1] = server to query
196     * parv[2] = servername mask
197     */
198     static void
199     ms_links(struct Client *client_p, struct Client *source_p,
200     int parc, char *parv[])
201     {
202     if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv)
203     != HUNTED_ISME)
204     return;
205    
206     if (IsClient(source_p))
207     m_links(client_p, source_p, parc, parv);
208     }

Properties

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