1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* m_help.c: Provides help information to a user/operator. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1999-2015 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file m_help.c |
23 |
> |
* \brief Includes required functions for processing the HELP command. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
29 |
|
#include "ircd.h" |
30 |
|
#include "numeric.h" |
31 |
|
#include "send.h" |
32 |
< |
#include "s_conf.h" |
31 |
< |
#include "s_log.h" |
32 |
> |
#include "conf.h" |
33 |
|
#include "parse.h" |
34 |
|
#include "modules.h" |
35 |
|
#include "irc_string.h" |
36 |
|
|
36 |
– |
#define HELPLEN 400 |
37 |
– |
|
38 |
– |
static void dohelp(struct Client *, const char *, char *); |
39 |
– |
static void sendhelpfile(struct Client *, const char *, const char *); |
37 |
|
|
38 |
+ |
enum { HELPLEN = 400 }; |
39 |
|
|
42 |
– |
/* |
43 |
– |
* m_help - HELP message handler |
44 |
– |
* parv[0] = sender prefix |
45 |
– |
*/ |
40 |
|
static void |
41 |
< |
m_help(struct Client *client_p, struct Client *source_p, |
48 |
< |
int parc, char *parv[]) |
41 |
> |
sendhelpfile(struct Client *source_p, const char *path, const char *topic) |
42 |
|
{ |
43 |
< |
static time_t last_used = 0; |
43 |
> |
FILE *file = NULL; |
44 |
> |
char *p = NULL; |
45 |
> |
char line[HELPLEN] = ""; |
46 |
|
|
47 |
< |
/* HELP is always local */ |
53 |
< |
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) |
47 |
> |
if ((file = fopen(path, "r")) == NULL) |
48 |
|
{ |
49 |
< |
/* 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); |
49 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
50 |
|
return; |
51 |
|
} |
52 |
|
|
53 |
< |
last_used = CurrentTime; |
53 |
> |
if (fgets(line, sizeof(line), file) == NULL) |
54 |
> |
{ |
55 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
56 |
> |
fclose(file); |
57 |
> |
return; |
58 |
> |
} |
59 |
|
|
60 |
< |
dohelp(source_p, UHPATH, parv[1]); |
61 |
< |
} |
60 |
> |
if ((p = strpbrk(line, "\r\n"))) |
61 |
> |
*p = '\0'; |
62 |
|
|
63 |
< |
/* |
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 |
< |
} |
63 |
> |
sendto_one_numeric(source_p, &me, RPL_HELPSTART, topic, line); |
64 |
|
|
65 |
< |
/* |
66 |
< |
* mo_uhelp - HELP message handler |
67 |
< |
* This is used so that opers can view the user help file without deopering |
68 |
< |
* parv[0] = sender prefix |
69 |
< |
*/ |
70 |
< |
static void |
71 |
< |
mo_uhelp(struct Client *client_p, struct Client *source_p, |
72 |
< |
int parc, char *parv[]) |
73 |
< |
{ |
74 |
< |
dohelp(source_p, UHPATH, parv[1]); |
65 |
> |
while (fgets(line, sizeof(line), file)) |
66 |
> |
{ |
67 |
> |
if ((p = strpbrk(line, "\r\n"))) |
68 |
> |
*p = '\0'; |
69 |
> |
|
70 |
> |
sendto_one_numeric(source_p, &me, RPL_HELPTXT, topic, line); |
71 |
> |
} |
72 |
> |
|
73 |
> |
fclose(file); |
74 |
> |
sendto_one_numeric(source_p, &me, RPL_ENDOFHELP, topic); |
75 |
|
} |
76 |
|
|
77 |
|
static void |
78 |
< |
dohelp(struct Client *source_p, const char *hpath, char *topic) |
78 |
> |
do_help(struct Client *source_p, char *topic) |
79 |
|
{ |
80 |
|
char h_index[] = "index"; |
93 |
– |
char path[PATH_MAX + 1]; |
81 |
|
struct stat sb; |
95 |
– |
int i; |
82 |
|
|
83 |
< |
if (topic != NULL) |
84 |
< |
{ |
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 |
< |
} |
83 |
> |
if (EmptyString(topic)) |
84 |
> |
topic = h_index; |
85 |
|
else |
86 |
< |
topic = h_index; /* list available help topics */ |
86 |
> |
for (char *p = topic; *p; ++p) |
87 |
> |
*p = ToLower(*p); |
88 |
|
|
89 |
|
if (strpbrk(topic, "/\\")) |
90 |
|
{ |
91 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
114 |
< |
me.name, source_p->name, topic); |
91 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
92 |
|
return; |
93 |
|
} |
94 |
|
|
95 |
< |
if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX) |
96 |
< |
{ |
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); |
95 |
> |
char path[sizeof(HPATH) + strlen(topic) + 1]; |
96 |
> |
snprintf(path, sizeof(path), "%s/%s", HPATH, topic); |
97 |
|
|
98 |
|
if (stat(path, &sb) < 0) |
99 |
|
{ |
100 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
130 |
< |
me.name, source_p->name, topic); |
100 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
101 |
|
return; |
102 |
|
} |
103 |
|
|
104 |
|
if (!S_ISREG(sb.st_mode)) |
105 |
|
{ |
106 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
137 |
< |
me.name, source_p->name, topic); |
106 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
107 |
|
return; |
108 |
|
} |
109 |
|
|
110 |
|
sendhelpfile(source_p, path, topic); |
111 |
|
} |
112 |
|
|
113 |
< |
static void |
114 |
< |
sendhelpfile(struct Client *source_p, const char *path, const char *topic) |
113 |
> |
/*! \brief HELP command handler |
114 |
> |
* |
115 |
> |
* \param source_p Pointer to allocated Client struct from which the message |
116 |
> |
* originally comes from. This can be a local or remote client. |
117 |
> |
* \param parc Integer holding the number of supplied arguments. |
118 |
> |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
119 |
> |
* pointers. |
120 |
> |
* \note Valid arguments for this command are: |
121 |
> |
* - parv[0] = command |
122 |
> |
* - parv[1] = help topic |
123 |
> |
*/ |
124 |
> |
static int |
125 |
> |
m_help(struct Client *source_p, int parc, char *parv[]) |
126 |
|
{ |
127 |
< |
FBFILE *file; |
148 |
< |
char line[HELPLEN]; |
149 |
< |
char started = 0; |
150 |
< |
int type; |
127 |
> |
static time_t last_used = 0; |
128 |
|
|
129 |
< |
if ((file = fbopen(path, "r")) == NULL) |
129 |
> |
if ((last_used + ConfigGeneral.pace_wait_simple) > CurrentTime) |
130 |
|
{ |
131 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
132 |
< |
me.name, source_p->name, topic); |
156 |
< |
return; |
131 |
> |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "HELP"); |
132 |
> |
return 0; |
133 |
|
} |
134 |
|
|
135 |
< |
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 |
< |
} |
135 |
> |
last_used = CurrentTime; |
136 |
|
|
137 |
< |
else if (line[0] != '#') |
138 |
< |
{ |
139 |
< |
line[strlen(line) - 1] = '\0'; |
140 |
< |
sendto_one(source_p, form_str(RPL_HELPSTART), |
141 |
< |
me.name, source_p->name, topic, line); |
142 |
< |
started = 1; |
143 |
< |
} |
144 |
< |
|
145 |
< |
while (fbgets(line, sizeof(line), file)) |
146 |
< |
{ |
147 |
< |
line[strlen(line) - 1] = '\0'; |
148 |
< |
if (line[0] != '#') |
149 |
< |
{ |
150 |
< |
if (!started) |
151 |
< |
{ |
152 |
< |
type = RPL_HELPSTART; |
153 |
< |
started = 1; |
154 |
< |
} |
155 |
< |
else |
156 |
< |
type = RPL_HELPTXT; |
157 |
< |
|
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 |
< |
}; |
137 |
> |
do_help(source_p, parv[1]); |
138 |
> |
return 0; |
139 |
> |
} |
140 |
> |
|
141 |
> |
/*! \brief HELP command handler |
142 |
> |
* |
143 |
> |
* \param source_p Pointer to allocated Client struct from which the message |
144 |
> |
* originally comes from. This can be a local or remote client. |
145 |
> |
* \param parc Integer holding the number of supplied arguments. |
146 |
> |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
147 |
> |
* pointers. |
148 |
> |
* \note Valid arguments for this command are: |
149 |
> |
* - parv[0] = command |
150 |
> |
* - parv[1] = help topic |
151 |
> |
*/ |
152 |
> |
static int |
153 |
> |
mo_help(struct Client *source_p, int parc, char *parv[]) |
154 |
> |
{ |
155 |
> |
do_help(source_p, parv[1]); |
156 |
> |
return 0; |
157 |
> |
} |
158 |
|
|
159 |
< |
static struct Message uhelp_msgtab = { |
160 |
< |
"UHELP", 0, 0, 0, 0, MFLG_SLOW, 0, |
161 |
< |
{m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore} |
159 |
> |
static struct Message help_msgtab = |
160 |
> |
{ |
161 |
> |
.cmd = "HELP", |
162 |
> |
.args_max = MAXPARA, |
163 |
> |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
164 |
> |
.handlers[CLIENT_HANDLER] = m_help, |
165 |
> |
.handlers[SERVER_HANDLER] = m_ignore, |
166 |
> |
.handlers[ENCAP_HANDLER] = m_ignore, |
167 |
> |
.handlers[OPER_HANDLER] = mo_help |
168 |
|
}; |
169 |
|
|
170 |
|
static void |
171 |
|
module_init(void) |
172 |
|
{ |
173 |
|
mod_add_cmd(&help_msgtab); |
213 |
– |
mod_add_cmd(&uhelp_msgtab); |
174 |
|
} |
175 |
|
|
176 |
|
static void |
177 |
|
module_exit(void) |
178 |
|
{ |
179 |
|
mod_del_cmd(&help_msgtab); |
220 |
– |
mod_del_cmd(&uhelp_msgtab); |
180 |
|
} |
181 |
|
|
182 |
< |
struct module module_entry = { |
183 |
< |
.node = { NULL, NULL, NULL }, |
225 |
< |
.name = NULL, |
182 |
> |
struct module module_entry = |
183 |
> |
{ |
184 |
|
.version = "$Revision$", |
227 |
– |
.handle = NULL, |
185 |
|
.modinit = module_init, |
186 |
|
.modexit = module_exit, |
230 |
– |
.flags = 0 |
187 |
|
}; |