/[svn]/ircd-hybrid-8/modules/m_help.c
ViewVC logotype

Contents of /ircd-hybrid-8/modules/m_help.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1243 - (show annotations)
Fri Sep 30 10:47:53 2011 UTC (8 years, 9 months ago) by michael
File MIME type: text/x-chdr
File size: 5454 byte(s)
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_help.c: Provides help information to a user/operator.
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "client.h"
27 #include "ircd.h"
28 #include "numeric.h"
29 #include "send.h"
30 #include "s_conf.h"
31 #include "s_log.h"
32 #include "parse.h"
33 #include "modules.h"
34 #include "irc_string.h"
35
36 #define HELPLEN 400
37
38 static void dohelp(struct Client *, const char *, char *);
39 static void sendhelpfile(struct Client *, const char *, const char *);
40
41
42 /*
43 * m_help - HELP message handler
44 * parv[0] = sender prefix
45 */
46 static void
47 m_help(struct Client *client_p, struct Client *source_p,
48 int parc, char *parv[])
49 {
50 static time_t last_used = 0;
51
52 /* HELP is always local */
53 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
54 {
55 /* safe enough to give this on a local connect only */
56 sendto_one(source_p,form_str(RPL_LOAD2HI),
57 me.name, source_p->name);
58 return;
59 }
60
61 last_used = CurrentTime;
62
63 dohelp(source_p, UHPATH, parv[1]);
64 }
65
66 /*
67 * mo_help - HELP message handler
68 * parv[0] = sender prefix
69 */
70 static void
71 mo_help(struct Client *client_p, struct Client *source_p,
72 int parc, char *parv[])
73 {
74 dohelp(source_p, HPATH, parv[1]);
75 }
76
77 /*
78 * mo_uhelp - HELP message handler
79 * This is used so that opers can view the user help file without deopering
80 * parv[0] = sender prefix
81 */
82 static void
83 mo_uhelp(struct Client *client_p, struct Client *source_p,
84 int parc, char *parv[])
85 {
86 dohelp(source_p, UHPATH, parv[1]);
87 }
88
89 static void
90 dohelp(struct Client *source_p, const char *hpath, char *topic)
91 {
92 char h_index[] = "index";
93 char path[PATH_MAX + 1];
94 struct stat sb;
95 int i;
96
97 if (topic != NULL)
98 {
99 if (*topic == '\0')
100 topic = h_index;
101 else
102 {
103 /* convert to lower case */
104 for (i = 0; topic[i] != '\0'; ++i)
105 topic[i] = ToLower(topic[i]);
106 }
107 }
108 else
109 topic = h_index; /* list available help topics */
110
111 if (strpbrk(topic, "/\\"))
112 {
113 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
114 me.name, source_p->name, topic);
115 return;
116 }
117
118 if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX)
119 {
120 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
121 me.name, source_p->name, topic);
122 return;
123 }
124
125 snprintf(path, sizeof(path), "%s/%s", hpath, topic);
126
127 if (stat(path, &sb) < 0)
128 {
129 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
130 me.name, source_p->name, topic);
131 return;
132 }
133
134 if (!S_ISREG(sb.st_mode))
135 {
136 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
137 me.name, source_p->name, topic);
138 return;
139 }
140
141 sendhelpfile(source_p, path, topic);
142 }
143
144 static void
145 sendhelpfile(struct Client *source_p, const char *path, const char *topic)
146 {
147 FBFILE *file;
148 char line[HELPLEN];
149 char started = 0;
150 int type;
151
152 if ((file = fbopen(path, "r")) == NULL)
153 {
154 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
155 me.name, source_p->name, topic);
156 return;
157 }
158
159 if (fbgets(line, sizeof(line), file) == NULL)
160 {
161 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
162 me.name, source_p->name, topic);
163 return;
164 }
165
166 else if (line[0] != '#')
167 {
168 line[strlen(line) - 1] = '\0';
169 sendto_one(source_p, form_str(RPL_HELPSTART),
170 me.name, source_p->name, topic, line);
171 started = 1;
172 }
173
174 while (fbgets(line, sizeof(line), file))
175 {
176 line[strlen(line) - 1] = '\0';
177 if (line[0] != '#')
178 {
179 if (!started)
180 {
181 type = RPL_HELPSTART;
182 started = 1;
183 }
184 else
185 type = RPL_HELPTXT;
186
187 sendto_one(source_p, form_str(RPL_HELPTXT),
188 me.name, source_p->name, topic, line);
189 }
190 }
191
192 fbclose(file);
193 sendto_one(source_p, form_str(RPL_HELPTXT),
194 me.name, source_p->name, topic, "");
195 sendto_one(source_p, form_str(RPL_ENDOFHELP),
196 me.name, source_p->name, topic);
197 }
198
199 static struct Message help_msgtab = {
200 "HELP", 0, 0, 0, 0, MFLG_SLOW, 0,
201 {m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore}
202 };
203
204 static struct Message uhelp_msgtab = {
205 "UHELP", 0, 0, 0, 0, MFLG_SLOW, 0,
206 {m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore}
207 };
208
209 static void
210 module_init(void)
211 {
212 mod_add_cmd(&help_msgtab);
213 mod_add_cmd(&uhelp_msgtab);
214 }
215
216 static void
217 module_exit(void)
218 {
219 mod_del_cmd(&help_msgtab);
220 mod_del_cmd(&uhelp_msgtab);
221 }
222
223 struct module module_entry = {
224 .node = { NULL, NULL, NULL },
225 .name = NULL,
226 .version = "$Revision$",
227 .handle = NULL,
228 .modinit = module_init,
229 .modexit = module_exit,
230 .flags = 0
231 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28