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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 897 - (show annotations)
Sat Nov 3 17:13:32 2007 UTC (12 years, 1 month ago) by db
File MIME type: text/x-chdr
File size: 5680 byte(s)
- Major cleanup of build system (Stu should review this)
  Basically move shared stuff like help messages modules to datadir
  Try to keep to the original layout under prefix if --datadir
  --sysconfdir --localstatedir are not given
- Make the example files have reasonable defaults, this bites me
  all the time anyway.


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

Properties

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

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