ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_help.c
Revision: 5769
Committed: Thu Apr 2 19:51:53 2015 UTC (10 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 4703 byte(s)
Log Message:
- Cleaned up strlen() based array indices

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 5347 * Copyright (c) 1999-2015 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 5769 char *p = NULL;
45 michael 4269 char line[HELPLEN] = "";
46 adx 30
47 michael 1997 if ((file = fopen(path, "r")) == NULL)
48 adx 30 {
49 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
50 michael 2972 return;
51 adx 30 }
52    
53 michael 1997 if (fgets(line, sizeof(line), file) == NULL)
54     {
55 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
56 michael 2657 fclose(file);
57 michael 2972 return;
58 michael 1997 }
59 adx 30
60 michael 5769 if ((p = strpbrk(line, "\r\n")))
61     *p = '\0';
62    
63 michael 3109 sendto_one_numeric(source_p, &me, RPL_HELPSTART, topic, line);
64 adx 30
65 michael 1997 while (fgets(line, sizeof(line), file))
66     {
67 michael 5769 if ((p = strpbrk(line, "\r\n")))
68     *p = '\0';
69 adx 30
70 michael 3109 sendto_one_numeric(source_p, &me, RPL_HELPTXT, topic, line);
71 michael 1997 }
72    
73     fclose(file);
74 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFHELP, topic);
75 adx 30 }
76    
77 michael 2972 static void
78     do_help(struct Client *source_p, char *topic)
79 adx 30 {
80 michael 575 char h_index[] = "index";
81 michael 1737 char path[HYB_PATH_MAX + 1];
82 adx 30 struct stat sb;
83    
84 michael 1674 if (EmptyString(topic))
85     topic = h_index;
86 adx 30 else
87 michael 4269 for (char *p = topic; *p; ++p)
88 michael 2045 *p = ToLower(*p);
89 adx 30
90     if (strpbrk(topic, "/\\"))
91     {
92 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
93 michael 2972 return;
94 adx 30 }
95    
96 michael 2028 if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX)
97 adx 30 {
98 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
99 michael 2972 return;
100 adx 30 }
101    
102 michael 2028 snprintf(path, sizeof(path), "%s/%s", HPATH, topic);
103 adx 30
104     if (stat(path, &sb) < 0)
105     {
106 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
107 michael 2972 return;
108 adx 30 }
109    
110     if (!S_ISREG(sb.st_mode))
111     {
112 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
113 michael 2972 return;
114 adx 30 }
115    
116 michael 2972 sendhelpfile(source_p, path, topic);
117 adx 30 }
118    
119 michael 3266 /*! \brief HELP command handler
120     *
121     * \param source_p Pointer to allocated Client struct from which the message
122     * originally comes from. This can be a local or remote client.
123     * \param parc Integer holding the number of supplied arguments.
124     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
125     * pointers.
126     * \note Valid arguments for this command are:
127     * - parv[0] = command
128     * - parv[1] = help topic
129 michael 1997 */
130 michael 2820 static int
131 michael 3156 m_help(struct Client *source_p, int parc, char *parv[])
132 adx 30 {
133 michael 1997 static time_t last_used = 0;
134 adx 30
135 michael 4340 if ((last_used + ConfigGeneral.pace_wait_simple) > CurrentTime)
136 adx 30 {
137 michael 4759 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "HELP");
138 michael 2820 return 0;
139 adx 30 }
140    
141 michael 1997 last_used = CurrentTime;
142 adx 30
143 michael 2972 do_help(source_p, parv[1]);
144     return 0;
145 michael 1997 }
146 adx 30
147 michael 3266 /*! \brief HELP command handler
148     *
149     * \param source_p Pointer to allocated Client struct from which the message
150     * originally comes from. This can be a local or remote client.
151     * \param parc Integer holding the number of supplied arguments.
152     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
153     * pointers.
154     * \note Valid arguments for this command are:
155     * - parv[0] = command
156     * - parv[1] = help topic
157 michael 1997 */
158 michael 2820 static int
159 michael 3156 mo_help(struct Client *source_p, int parc, char *parv[])
160 michael 1997 {
161 michael 2972 do_help(source_p, parv[1]);
162     return 0;
163 michael 1997 }
164 michael 1674
165 michael 2820 static struct Message help_msgtab =
166     {
167 michael 4545 "HELP", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
168 michael 2820 { m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore }
169 michael 1230 };
170    
171     static void
172     module_init(void)
173     {
174     mod_add_cmd(&help_msgtab);
175     }
176    
177     static void
178     module_exit(void)
179     {
180     mod_del_cmd(&help_msgtab);
181     }
182    
183 michael 2820 struct module module_entry =
184     {
185 michael 1230 .node = { NULL, NULL, NULL },
186     .name = NULL,
187     .version = "$Revision$",
188     .handle = NULL,
189     .modinit = module_init,
190     .modexit = module_exit,
191     .flags = 0
192     };

Properties

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