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-2014 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 |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id: m_help.c,v 1.42 2005/09/18 22:24:37 adx Exp $ |
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" |
26 |
– |
#include "handlers.h" |
28 |
|
#include "client.h" |
29 |
|
#include "ircd.h" |
29 |
– |
#include "ircd_handler.h" |
30 |
– |
#include "msg.h" |
30 |
|
#include "numeric.h" |
31 |
|
#include "send.h" |
32 |
< |
#include "s_conf.h" |
34 |
< |
#include "s_log.h" |
32 |
> |
#include "conf.h" |
33 |
|
#include "parse.h" |
34 |
|
#include "modules.h" |
35 |
|
#include "irc_string.h" |
36 |
|
|
39 |
– |
#define HPATH IRCD_PREFIX "/help/opers" |
40 |
– |
#define UHPATH IRCD_PREFIX "/help/users" |
37 |
|
#define HELPLEN 400 |
38 |
|
|
43 |
– |
static void m_help(struct Client *, struct Client *, int, char *[]); |
44 |
– |
static void mo_help(struct Client *, struct Client *, int, char *[]); |
45 |
– |
static void mo_uhelp(struct Client *, struct Client *, int, char *[]); |
46 |
– |
static void dohelp(struct Client *, const char *, char *); |
47 |
– |
static void sendhelpfile(struct Client *, const char *, const char *); |
48 |
– |
|
49 |
– |
struct Message help_msgtab = { |
50 |
– |
"HELP", 0, 0, 0, 0, MFLG_SLOW, 0, |
51 |
– |
{m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore} |
52 |
– |
}; |
53 |
– |
|
54 |
– |
struct Message uhelp_msgtab = { |
55 |
– |
"UHELP", 0, 0, 0, 0, MFLG_SLOW, 0, |
56 |
– |
{m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore} |
57 |
– |
}; |
58 |
– |
|
59 |
– |
#ifndef STATIC_MODULES |
60 |
– |
void |
61 |
– |
_modinit(void) |
62 |
– |
{ |
63 |
– |
mod_add_cmd(&help_msgtab); |
64 |
– |
mod_add_cmd(&uhelp_msgtab); |
65 |
– |
} |
66 |
– |
|
67 |
– |
void |
68 |
– |
_moddeinit(void) |
69 |
– |
{ |
70 |
– |
mod_del_cmd(&help_msgtab); |
71 |
– |
mod_del_cmd(&uhelp_msgtab); |
72 |
– |
} |
73 |
– |
|
74 |
– |
const char *_version = "$Revision: 1.42 $"; |
75 |
– |
#endif |
39 |
|
|
77 |
– |
/* |
78 |
– |
* m_help - HELP message handler |
79 |
– |
* parv[0] = sender prefix |
80 |
– |
*/ |
40 |
|
static void |
41 |
< |
m_help(struct Client *client_p, struct Client *source_p, |
83 |
< |
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 line[HELPLEN] = { '\0' }; |
45 |
|
|
46 |
< |
/* HELP is always local */ |
88 |
< |
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) |
46 |
> |
if ((file = fopen(path, "r")) == NULL) |
47 |
|
{ |
48 |
< |
/* safe enough to give this on a local connect only */ |
91 |
< |
sendto_one(source_p,form_str(RPL_LOAD2HI), |
92 |
< |
me.name, source_p->name); |
48 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
49 |
|
return; |
50 |
|
} |
51 |
|
|
52 |
< |
last_used = CurrentTime; |
52 |
> |
if (fgets(line, sizeof(line), file) == NULL) |
53 |
> |
{ |
54 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
55 |
> |
fclose(file); |
56 |
> |
return; |
57 |
> |
} |
58 |
|
|
59 |
< |
dohelp(source_p, UHPATH, parv[1]); |
60 |
< |
} |
59 |
> |
line[strlen(line) - 1] = '\0'; |
60 |
> |
sendto_one_numeric(source_p, &me, RPL_HELPSTART, topic, line); |
61 |
|
|
62 |
< |
/* |
63 |
< |
* mo_help - HELP message handler |
64 |
< |
* parv[0] = sender prefix |
104 |
< |
*/ |
105 |
< |
static void |
106 |
< |
mo_help(struct Client *client_p, struct Client *source_p, |
107 |
< |
int parc, char *parv[]) |
108 |
< |
{ |
109 |
< |
dohelp(source_p, HPATH, parv[1]); |
110 |
< |
} |
62 |
> |
while (fgets(line, sizeof(line), file)) |
63 |
> |
{ |
64 |
> |
line[strlen(line) - 1] = '\0'; |
65 |
|
|
66 |
< |
/* |
67 |
< |
* mo_uhelp - HELP message handler |
68 |
< |
* This is used so that opers can view the user help file without deopering |
69 |
< |
* parv[0] = sender prefix |
70 |
< |
*/ |
117 |
< |
static void |
118 |
< |
mo_uhelp(struct Client *client_p, struct Client *source_p, |
119 |
< |
int parc, char *parv[]) |
120 |
< |
{ |
121 |
< |
dohelp(source_p, UHPATH, parv[1]); |
66 |
> |
sendto_one_numeric(source_p, &me, RPL_HELPTXT, topic, line); |
67 |
> |
} |
68 |
> |
|
69 |
> |
fclose(file); |
70 |
> |
sendto_one_numeric(source_p, &me, RPL_ENDOFHELP, topic); |
71 |
|
} |
72 |
|
|
73 |
|
static void |
74 |
< |
dohelp(struct Client *source_p, const char *hpath, char *topic) |
74 |
> |
do_help(struct Client *source_p, char *topic) |
75 |
|
{ |
76 |
< |
char path[PATH_MAX + 1]; |
76 |
> |
char *p = topic; |
77 |
> |
char h_index[] = "index"; |
78 |
> |
char path[HYB_PATH_MAX + 1]; |
79 |
|
struct stat sb; |
129 |
– |
int i; |
80 |
|
|
81 |
< |
if (topic != NULL) |
82 |
< |
{ |
133 |
< |
if (*topic == '\0') |
134 |
< |
topic = "index"; |
135 |
< |
else |
136 |
< |
{ |
137 |
< |
/* convert to lower case */ |
138 |
< |
for (i = 0; topic[i] != '\0'; i++) |
139 |
< |
topic[i] = ToLower(topic[i]); |
140 |
< |
} |
141 |
< |
} |
81 |
> |
if (EmptyString(topic)) |
82 |
> |
topic = h_index; |
83 |
|
else |
84 |
< |
topic = "index"; /* list available help topics */ |
84 |
> |
for (; *p; ++p) |
85 |
> |
*p = ToLower(*p); |
86 |
|
|
87 |
|
if (strpbrk(topic, "/\\")) |
88 |
|
{ |
89 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
148 |
< |
me.name, source_p->name, topic); |
89 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
90 |
|
return; |
91 |
|
} |
92 |
|
|
93 |
< |
if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX) |
93 |
> |
if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX) |
94 |
|
{ |
95 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
155 |
< |
me.name, source_p->name, topic); |
95 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
96 |
|
return; |
97 |
|
} |
98 |
|
|
99 |
< |
snprintf(path, sizeof(path), "%s/%s", hpath, topic); |
99 |
> |
snprintf(path, sizeof(path), "%s/%s", HPATH, topic); |
100 |
|
|
101 |
|
if (stat(path, &sb) < 0) |
102 |
|
{ |
103 |
< |
ilog(L_NOTICE, "help file %s not found", path); |
164 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
165 |
< |
me.name, source_p->name, topic); |
103 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
104 |
|
return; |
105 |
|
} |
106 |
|
|
169 |
– |
#ifndef _WIN32 |
107 |
|
if (!S_ISREG(sb.st_mode)) |
108 |
|
{ |
109 |
< |
ilog(L_NOTICE, "help file %s not found", path); |
173 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
174 |
< |
me.name, source_p->name, topic); |
109 |
> |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
110 |
|
return; |
111 |
|
} |
177 |
– |
#endif |
112 |
|
|
113 |
|
sendhelpfile(source_p, path, topic); |
114 |
|
} |
115 |
|
|
116 |
< |
static void |
117 |
< |
sendhelpfile(struct Client *source_p, const char *path, const char *topic) |
116 |
> |
/*! \brief HELP command handler |
117 |
> |
* |
118 |
> |
* \param source_p Pointer to allocated Client struct from which the message |
119 |
> |
* originally comes from. This can be a local or remote client. |
120 |
> |
* \param parc Integer holding the number of supplied arguments. |
121 |
> |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
122 |
> |
* pointers. |
123 |
> |
* \note Valid arguments for this command are: |
124 |
> |
* - parv[0] = command |
125 |
> |
* - parv[1] = help topic |
126 |
> |
*/ |
127 |
> |
static int |
128 |
> |
m_help(struct Client *source_p, int parc, char *parv[]) |
129 |
|
{ |
130 |
< |
FBFILE *file; |
186 |
< |
char line[HELPLEN]; |
187 |
< |
char started = 0; |
188 |
< |
int type; |
130 |
> |
static time_t last_used = 0; |
131 |
|
|
132 |
< |
if ((file = fbopen(path, "r")) == NULL) |
132 |
> |
/* HELP is always local */ |
133 |
> |
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) |
134 |
|
{ |
135 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
136 |
< |
me.name, source_p->name, topic); |
137 |
< |
return; |
135 |
> |
/* safe enough to give this on a local connect only */ |
136 |
> |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
137 |
> |
return 0; |
138 |
|
} |
139 |
|
|
140 |
< |
if (fbgets(line, sizeof(line), file) == NULL) |
198 |
< |
{ |
199 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
200 |
< |
me.name, source_p->name, topic); |
201 |
< |
return; |
202 |
< |
} |
140 |
> |
last_used = CurrentTime; |
141 |
|
|
142 |
< |
else if (line[0] != '#') |
143 |
< |
{ |
144 |
< |
line[strlen(line) - 1] = '\0'; |
207 |
< |
sendto_one(source_p, form_str(RPL_HELPSTART), |
208 |
< |
me.name, source_p->name, topic, line); |
209 |
< |
started = 1; |
210 |
< |
} |
142 |
> |
do_help(source_p, parv[1]); |
143 |
> |
return 0; |
144 |
> |
} |
145 |
|
|
146 |
< |
while (fbgets(line, sizeof(line), file)) |
147 |
< |
{ |
148 |
< |
line[strlen(line) - 1] = '\0'; |
149 |
< |
if(line[0] != '#') |
150 |
< |
{ |
151 |
< |
if (!started) |
152 |
< |
{ |
153 |
< |
type = RPL_HELPSTART; |
154 |
< |
started = 1; |
155 |
< |
} |
156 |
< |
else |
157 |
< |
type = RPL_HELPTXT; |
158 |
< |
|
159 |
< |
sendto_one(source_p, form_str(RPL_HELPTXT), |
160 |
< |
me.name, source_p->name, topic, line); |
161 |
< |
} |
228 |
< |
} |
229 |
< |
|
230 |
< |
fbclose(file); |
231 |
< |
sendto_one(source_p, form_str(RPL_HELPTXT), |
232 |
< |
me.name, source_p->name, topic, ""); |
233 |
< |
sendto_one(source_p, form_str(RPL_ENDOFHELP), |
234 |
< |
me.name, source_p->name, topic); |
146 |
> |
/*! \brief HELP command handler |
147 |
> |
* |
148 |
> |
* \param source_p Pointer to allocated Client struct from which the message |
149 |
> |
* originally comes from. This can be a local or remote client. |
150 |
> |
* \param parc Integer holding the number of supplied arguments. |
151 |
> |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
152 |
> |
* pointers. |
153 |
> |
* \note Valid arguments for this command are: |
154 |
> |
* - parv[0] = command |
155 |
> |
* - parv[1] = help topic |
156 |
> |
*/ |
157 |
> |
static int |
158 |
> |
mo_help(struct Client *source_p, int parc, char *parv[]) |
159 |
> |
{ |
160 |
> |
do_help(source_p, parv[1]); |
161 |
> |
return 0; |
162 |
|
} |
163 |
+ |
|
164 |
+ |
static struct Message help_msgtab = |
165 |
+ |
{ |
166 |
+ |
"HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
167 |
+ |
{ m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore } |
168 |
+ |
}; |
169 |
+ |
|
170 |
+ |
static void |
171 |
+ |
module_init(void) |
172 |
+ |
{ |
173 |
+ |
mod_add_cmd(&help_msgtab); |
174 |
+ |
} |
175 |
+ |
|
176 |
+ |
static void |
177 |
+ |
module_exit(void) |
178 |
+ |
{ |
179 |
+ |
mod_del_cmd(&help_msgtab); |
180 |
+ |
} |
181 |
+ |
|
182 |
+ |
struct module module_entry = |
183 |
+ |
{ |
184 |
+ |
.node = { NULL, NULL, NULL }, |
185 |
+ |
.name = NULL, |
186 |
+ |
.version = "$Revision$", |
187 |
+ |
.handle = NULL, |
188 |
+ |
.modinit = module_init, |
189 |
+ |
.modexit = module_exit, |
190 |
+ |
.flags = 0 |
191 |
+ |
}; |