ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_help.c
Revision: 3109
Committed: Thu Mar 6 19:25:12 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 3970 byte(s)
Log Message:
- Applied Adam's sendto_one_numeric() changes

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
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
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 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
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"
28 #include "client.h"
29 #include "ircd.h"
30 #include "numeric.h"
31 #include "send.h"
32 #include "conf.h"
33 #include "parse.h"
34 #include "modules.h"
35 #include "irc_string.h"
36
37 #define HELPLEN 400
38
39
40 static void
41 sendhelpfile(struct Client *source_p, const char *path, const char *topic)
42 {
43 FILE *file = NULL;
44 char line[HELPLEN] = { '\0' };
45
46 if ((file = fopen(path, "r")) == NULL)
47 {
48 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
49 return;
50 }
51
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 line[strlen(line) - 1] = '\0';
60 sendto_one_numeric(source_p, &me, RPL_HELPSTART, topic, line);
61
62 while (fgets(line, sizeof(line), file))
63 {
64 line[strlen(line) - 1] = '\0';
65
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 do_help(struct Client *source_p, char *topic)
75 {
76 char *p = topic;
77 char h_index[] = "index";
78 char path[HYB_PATH_MAX + 1];
79 struct stat sb;
80
81 if (EmptyString(topic))
82 topic = h_index;
83 else
84 for (; *p; ++p)
85 *p = ToLower(*p);
86
87 if (strpbrk(topic, "/\\"))
88 {
89 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
90 return;
91 }
92
93 if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX)
94 {
95 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
96 return;
97 }
98
99 snprintf(path, sizeof(path), "%s/%s", HPATH, topic);
100
101 if (stat(path, &sb) < 0)
102 {
103 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
104 return;
105 }
106
107 if (!S_ISREG(sb.st_mode))
108 {
109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
110 return;
111 }
112
113 sendhelpfile(source_p, path, topic);
114 }
115
116 /*
117 * m_help - HELP message handler
118 * parv[0] = command
119 */
120 static int
121 m_help(struct Client *client_p, struct Client *source_p,
122 int parc, char *parv[])
123 {
124 static time_t last_used = 0;
125
126 /* HELP is always local */
127 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
128 {
129 /* safe enough to give this on a local connect only */
130 sendto_one_numeric(source_p, &me, RPL_LOAD2HI);
131 return 0;
132 }
133
134 last_used = CurrentTime;
135
136 do_help(source_p, parv[1]);
137 return 0;
138 }
139
140 /*
141 * mo_help - HELP message handler
142 * parv[0] = command
143 */
144 static int
145 mo_help(struct Client *client_p, struct Client *source_p,
146 int parc, char *parv[])
147 {
148 do_help(source_p, parv[1]);
149 return 0;
150 }
151
152 static struct Message help_msgtab =
153 {
154 "HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
155 { m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore }
156 };
157
158 static void
159 module_init(void)
160 {
161 mod_add_cmd(&help_msgtab);
162 }
163
164 static void
165 module_exit(void)
166 {
167 mod_del_cmd(&help_msgtab);
168 }
169
170 struct module module_entry =
171 {
172 .node = { NULL, NULL, NULL },
173 .name = NULL,
174 .version = "$Revision$",
175 .handle = NULL,
176 .modinit = module_init,
177 .modexit = module_exit,
178 .flags = 0
179 };

Properties

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