ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_help.c
Revision: 1325
Committed: Sat Mar 31 10:29:02 2012 UTC (12 years ago) by michael
Content type: text/x-csrc
File size: 5427 byte(s)
Log Message:
- Get rid of fileio.c. Replace some ircsprintf() with snprintf() while on it

File Contents

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

Properties

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