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$ |
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" |
36 |
|
|
37 |
|
#define HELPLEN 400 |
38 |
|
|
37 |
– |
static void dohelp(struct Client *, const char *, char *); |
38 |
– |
static void sendhelpfile(struct Client *, const char *, const char *); |
39 |
– |
|
39 |
|
|
41 |
– |
/* |
42 |
– |
* m_help - HELP message handler |
43 |
– |
* parv[0] = sender prefix |
44 |
– |
*/ |
40 |
|
static void |
41 |
< |
m_help(struct Client *client_p, struct Client *source_p, |
47 |
< |
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 */ |
52 |
< |
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 */ |
49 |
< |
sendto_one(source_p,form_str(RPL_LOAD2HI), |
56 |
< |
me.name, source_p->name); |
48 |
> |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
49 |
> |
me.name, source_p->name, topic); |
50 |
|
return; |
51 |
|
} |
52 |
|
|
53 |
< |
last_used = CurrentTime; |
53 |
> |
if (fgets(line, sizeof(line), file) == NULL) |
54 |
> |
{ |
55 |
> |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
56 |
> |
me.name, source_p->name, topic); |
57 |
> |
fclose(file); |
58 |
> |
return; |
59 |
> |
} |
60 |
|
|
61 |
< |
dohelp(source_p, UHPATH, parv[1]); |
62 |
< |
} |
61 |
> |
line[strlen(line) - 1] = '\0'; |
62 |
> |
sendto_one(source_p, form_str(RPL_HELPSTART), |
63 |
> |
me.name, source_p->name, topic, line); |
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 |
< |
} |
65 |
> |
while (fgets(line, sizeof(line), file)) |
66 |
> |
{ |
67 |
> |
line[strlen(line) - 1] = '\0'; |
68 |
|
|
69 |
< |
/* |
70 |
< |
* mo_uhelp - HELP message handler |
71 |
< |
* This is used so that opers can view the user help file without deopering |
72 |
< |
* parv[0] = sender prefix |
73 |
< |
*/ |
74 |
< |
static void |
75 |
< |
mo_uhelp(struct Client *client_p, struct Client *source_p, |
83 |
< |
int parc, char *parv[]) |
84 |
< |
{ |
85 |
< |
dohelp(source_p, UHPATH, parv[1]); |
69 |
> |
sendto_one(source_p, form_str(RPL_HELPTXT), |
70 |
> |
me.name, source_p->name, topic, line); |
71 |
> |
} |
72 |
> |
|
73 |
> |
fclose(file); |
74 |
> |
sendto_one(source_p, form_str(RPL_ENDOFHELP), |
75 |
> |
me.name, source_p->name, topic); |
76 |
|
} |
77 |
|
|
78 |
|
static void |
79 |
< |
dohelp(struct Client *source_p, const char *hpath, char *topic) |
79 |
> |
do_help(struct Client *source_p, char *topic) |
80 |
|
{ |
81 |
+ |
char *p = topic; |
82 |
|
char h_index[] = "index"; |
83 |
< |
char path[PATH_MAX + 1]; |
83 |
> |
char path[HYB_PATH_MAX + 1]; |
84 |
|
struct stat sb; |
94 |
– |
unsigned int i; |
85 |
|
|
86 |
|
if (EmptyString(topic)) |
87 |
|
topic = h_index; |
88 |
|
else |
89 |
< |
for (i = 0; topic[i] != '\0'; ++i) |
90 |
< |
topic[i] = ToLower(topic[i]); |
89 |
> |
for (; *p; ++p) |
90 |
> |
*p = ToLower(*p); |
91 |
|
|
92 |
|
if (strpbrk(topic, "/\\")) |
93 |
|
{ |
96 |
|
return; |
97 |
|
} |
98 |
|
|
99 |
< |
if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX) |
99 |
> |
if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX) |
100 |
|
{ |
101 |
|
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
102 |
|
me.name, source_p->name, topic); |
103 |
|
return; |
104 |
|
} |
105 |
|
|
106 |
< |
snprintf(path, sizeof(path), "%s/%s", hpath, topic); |
106 |
> |
snprintf(path, sizeof(path), "%s/%s", HPATH, topic); |
107 |
|
|
108 |
|
if (stat(path, &sb) < 0) |
109 |
|
{ |
122 |
|
sendhelpfile(source_p, path, topic); |
123 |
|
} |
124 |
|
|
125 |
< |
static void |
126 |
< |
sendhelpfile(struct Client *source_p, const char *path, const char *topic) |
125 |
> |
/* |
126 |
> |
* m_help - HELP message handler |
127 |
> |
* parv[0] = command |
128 |
> |
*/ |
129 |
> |
static int |
130 |
> |
m_help(struct Client *client_p, struct Client *source_p, |
131 |
> |
int parc, char *parv[]) |
132 |
|
{ |
133 |
< |
FILE *file; |
139 |
< |
char line[HELPLEN]; |
140 |
< |
|
141 |
< |
if ((file = fopen(path, "r")) == NULL) |
142 |
< |
{ |
143 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
144 |
< |
me.name, source_p->name, topic); |
145 |
< |
return; |
146 |
< |
} |
133 |
> |
static time_t last_used = 0; |
134 |
|
|
135 |
< |
if (fgets(line, sizeof(line), file) == NULL) |
135 |
> |
/* HELP is always local */ |
136 |
> |
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) |
137 |
|
{ |
138 |
< |
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
139 |
< |
me.name, source_p->name, topic); |
140 |
< |
return; |
138 |
> |
/* safe enough to give this on a local connect only */ |
139 |
> |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
140 |
> |
me.name, source_p->name); |
141 |
> |
return 0; |
142 |
|
} |
143 |
|
|
144 |
< |
line[strlen(line) - 1] = '\0'; |
156 |
< |
sendto_one(source_p, form_str(RPL_HELPSTART), |
157 |
< |
me.name, source_p->name, topic, line); |
158 |
< |
|
159 |
< |
while (fgets(line, sizeof(line), file)) |
160 |
< |
{ |
161 |
< |
line[strlen(line) - 1] = '\0'; |
144 |
> |
last_used = CurrentTime; |
145 |
|
|
146 |
< |
sendto_one(source_p, form_str(RPL_HELPTXT), |
147 |
< |
me.name, source_p->name, topic, line); |
148 |
< |
} |
146 |
> |
do_help(source_p, parv[1]); |
147 |
> |
return 0; |
148 |
> |
} |
149 |
|
|
150 |
< |
fclose(file); |
151 |
< |
sendto_one(source_p, form_str(RPL_ENDOFHELP), |
152 |
< |
me.name, source_p->name, topic); |
150 |
> |
/* |
151 |
> |
* mo_help - HELP message handler |
152 |
> |
* parv[0] = command |
153 |
> |
*/ |
154 |
> |
static int |
155 |
> |
mo_help(struct Client *client_p, struct Client *source_p, |
156 |
> |
int parc, char *parv[]) |
157 |
> |
{ |
158 |
> |
do_help(source_p, parv[1]); |
159 |
> |
return 0; |
160 |
|
} |
161 |
|
|
162 |
< |
static struct Message help_msgtab = { |
162 |
> |
static struct Message help_msgtab = |
163 |
> |
{ |
164 |
|
"HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
165 |
< |
{m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore} |
175 |
< |
}; |
176 |
< |
|
177 |
< |
static struct Message uhelp_msgtab = { |
178 |
< |
"UHELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
179 |
< |
{m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore} |
165 |
> |
{ m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore } |
166 |
|
}; |
167 |
|
|
168 |
|
static void |
169 |
|
module_init(void) |
170 |
|
{ |
171 |
|
mod_add_cmd(&help_msgtab); |
186 |
– |
mod_add_cmd(&uhelp_msgtab); |
172 |
|
} |
173 |
|
|
174 |
|
static void |
175 |
|
module_exit(void) |
176 |
|
{ |
177 |
|
mod_del_cmd(&help_msgtab); |
193 |
– |
mod_del_cmd(&uhelp_msgtab); |
178 |
|
} |
179 |
|
|
180 |
< |
struct module module_entry = { |
180 |
> |
struct module module_entry = |
181 |
> |
{ |
182 |
|
.node = { NULL, NULL, NULL }, |
183 |
|
.name = NULL, |
184 |
|
.version = "$Revision$", |