1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2820 |
* Copyright (c) 1999-2014 ircd-hybrid development team |
5 |
adx |
30 |
* |
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 |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
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 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2820 |
/*! \file m_help.c |
23 |
|
|
* \brief Includes required functions for processing the HELP command. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
|
|
#include "client.h" |
29 |
|
|
#include "ircd.h" |
30 |
|
|
#include "numeric.h" |
31 |
|
|
#include "send.h" |
32 |
michael |
1309 |
#include "conf.h" |
33 |
adx |
30 |
#include "parse.h" |
34 |
|
|
#include "modules.h" |
35 |
|
|
#include "irc_string.h" |
36 |
|
|
|
37 |
|
|
#define HELPLEN 400 |
38 |
|
|
|
39 |
|
|
|
40 |
michael |
2972 |
static void |
41 |
michael |
1997 |
sendhelpfile(struct Client *source_p, const char *path, const char *topic) |
42 |
adx |
30 |
{ |
43 |
michael |
2028 |
FILE *file = NULL; |
44 |
michael |
4269 |
char line[HELPLEN] = ""; |
45 |
adx |
30 |
|
46 |
michael |
1997 |
if ((file = fopen(path, "r")) == NULL) |
47 |
adx |
30 |
{ |
48 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
49 |
michael |
2972 |
return; |
50 |
adx |
30 |
} |
51 |
|
|
|
52 |
michael |
1997 |
if (fgets(line, sizeof(line), file) == NULL) |
53 |
|
|
{ |
54 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
55 |
michael |
2657 |
fclose(file); |
56 |
michael |
2972 |
return; |
57 |
michael |
1997 |
} |
58 |
adx |
30 |
|
59 |
michael |
1997 |
line[strlen(line) - 1] = '\0'; |
60 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_HELPSTART, topic, line); |
61 |
adx |
30 |
|
62 |
michael |
1997 |
while (fgets(line, sizeof(line), file)) |
63 |
|
|
{ |
64 |
|
|
line[strlen(line) - 1] = '\0'; |
65 |
adx |
30 |
|
66 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_HELPTXT, topic, line); |
67 |
michael |
1997 |
} |
68 |
|
|
|
69 |
|
|
fclose(file); |
70 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ENDOFHELP, topic); |
71 |
adx |
30 |
} |
72 |
|
|
|
73 |
michael |
2972 |
static void |
74 |
|
|
do_help(struct Client *source_p, char *topic) |
75 |
adx |
30 |
{ |
76 |
michael |
575 |
char h_index[] = "index"; |
77 |
michael |
1737 |
char path[HYB_PATH_MAX + 1]; |
78 |
adx |
30 |
struct stat sb; |
79 |
|
|
|
80 |
michael |
1674 |
if (EmptyString(topic)) |
81 |
|
|
topic = h_index; |
82 |
adx |
30 |
else |
83 |
michael |
4269 |
for (char *p = topic; *p; ++p) |
84 |
michael |
2045 |
*p = ToLower(*p); |
85 |
adx |
30 |
|
86 |
|
|
if (strpbrk(topic, "/\\")) |
87 |
|
|
{ |
88 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
89 |
michael |
2972 |
return; |
90 |
adx |
30 |
} |
91 |
|
|
|
92 |
michael |
2028 |
if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX) |
93 |
adx |
30 |
{ |
94 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
95 |
michael |
2972 |
return; |
96 |
adx |
30 |
} |
97 |
|
|
|
98 |
michael |
2028 |
snprintf(path, sizeof(path), "%s/%s", HPATH, topic); |
99 |
adx |
30 |
|
100 |
|
|
if (stat(path, &sb) < 0) |
101 |
|
|
{ |
102 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
103 |
michael |
2972 |
return; |
104 |
adx |
30 |
} |
105 |
|
|
|
106 |
|
|
if (!S_ISREG(sb.st_mode)) |
107 |
|
|
{ |
108 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic); |
109 |
michael |
2972 |
return; |
110 |
adx |
30 |
} |
111 |
|
|
|
112 |
michael |
2972 |
sendhelpfile(source_p, path, topic); |
113 |
adx |
30 |
} |
114 |
|
|
|
115 |
michael |
3266 |
/*! \brief HELP command handler |
116 |
|
|
* |
117 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
118 |
|
|
* originally comes from. This can be a local or remote client. |
119 |
|
|
* \param parc Integer holding the number of supplied arguments. |
120 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
121 |
|
|
* pointers. |
122 |
|
|
* \note Valid arguments for this command are: |
123 |
|
|
* - parv[0] = command |
124 |
|
|
* - parv[1] = help topic |
125 |
michael |
1997 |
*/ |
126 |
michael |
2820 |
static int |
127 |
michael |
3156 |
m_help(struct Client *source_p, int parc, char *parv[]) |
128 |
adx |
30 |
{ |
129 |
michael |
1997 |
static time_t last_used = 0; |
130 |
adx |
30 |
|
131 |
michael |
4340 |
if ((last_used + ConfigGeneral.pace_wait_simple) > CurrentTime) |
132 |
adx |
30 |
{ |
133 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
134 |
michael |
2820 |
return 0; |
135 |
adx |
30 |
} |
136 |
|
|
|
137 |
michael |
1997 |
last_used = CurrentTime; |
138 |
adx |
30 |
|
139 |
michael |
2972 |
do_help(source_p, parv[1]); |
140 |
|
|
return 0; |
141 |
michael |
1997 |
} |
142 |
adx |
30 |
|
143 |
michael |
3266 |
/*! \brief HELP command handler |
144 |
|
|
* |
145 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
146 |
|
|
* originally comes from. This can be a local or remote client. |
147 |
|
|
* \param parc Integer holding the number of supplied arguments. |
148 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
149 |
|
|
* pointers. |
150 |
|
|
* \note Valid arguments for this command are: |
151 |
|
|
* - parv[0] = command |
152 |
|
|
* - parv[1] = help topic |
153 |
michael |
1997 |
*/ |
154 |
michael |
2820 |
static int |
155 |
michael |
3156 |
mo_help(struct Client *source_p, int parc, char *parv[]) |
156 |
michael |
1997 |
{ |
157 |
michael |
2972 |
do_help(source_p, parv[1]); |
158 |
|
|
return 0; |
159 |
michael |
1997 |
} |
160 |
michael |
1674 |
|
161 |
michael |
2820 |
static struct Message help_msgtab = |
162 |
|
|
{ |
163 |
michael |
4545 |
"HELP", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
164 |
michael |
2820 |
{ m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore } |
165 |
michael |
1230 |
}; |
166 |
|
|
|
167 |
|
|
static void |
168 |
|
|
module_init(void) |
169 |
|
|
{ |
170 |
|
|
mod_add_cmd(&help_msgtab); |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
static void |
174 |
|
|
module_exit(void) |
175 |
|
|
{ |
176 |
|
|
mod_del_cmd(&help_msgtab); |
177 |
|
|
} |
178 |
|
|
|
179 |
michael |
2820 |
struct module module_entry = |
180 |
|
|
{ |
181 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
182 |
|
|
.name = NULL, |
183 |
|
|
.version = "$Revision$", |
184 |
|
|
.handle = NULL, |
185 |
|
|
.modinit = module_init, |
186 |
|
|
.modexit = module_exit, |
187 |
|
|
.flags = 0 |
188 |
|
|
}; |