ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_help.c
Revision: 2820
Committed: Wed Jan 15 23:10:26 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 4363 byte(s)
Log Message:
- Clean up all files in modules/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years
- Made module handlers int type for later use

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 int
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(source_p, form_str(ERR_HELPNOTFOUND),
49 me.name, source_p->name, topic);
50 return 0;
51 }
52
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 0;
59 }
60
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 while (fgets(line, sizeof(line), file))
66 {
67 line[strlen(line) - 1] = '\0';
68
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 return 0;
77 }
78
79 static int
80 dohelp(struct Client *source_p, char *topic)
81 {
82 char *p = topic;
83 char h_index[] = "index";
84 char path[HYB_PATH_MAX + 1];
85 struct stat sb;
86
87 if (EmptyString(topic))
88 topic = h_index;
89 else
90 for (; *p; ++p)
91 *p = ToLower(*p);
92
93 if (strpbrk(topic, "/\\"))
94 {
95 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
96 me.name, source_p->name, topic);
97 return 0;
98 }
99
100 if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX)
101 {
102 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
103 me.name, source_p->name, topic);
104 return 0;
105 }
106
107 snprintf(path, sizeof(path), "%s/%s", HPATH, topic);
108
109 if (stat(path, &sb) < 0)
110 {
111 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
112 me.name, source_p->name, topic);
113 return 0;
114 }
115
116 if (!S_ISREG(sb.st_mode))
117 {
118 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
119 me.name, source_p->name, topic);
120 return 0;
121 }
122
123 return sendhelpfile(source_p, path, topic);
124 }
125
126 /*
127 * m_help - HELP message handler
128 * parv[0] = sender prefix
129 */
130 static int
131 m_help(struct Client *client_p, struct Client *source_p,
132 int parc, char *parv[])
133 {
134 static time_t last_used = 0;
135
136 /* HELP is always local */
137 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
138 {
139 /* safe enough to give this on a local connect only */
140 sendto_one(source_p,form_str(RPL_LOAD2HI),
141 me.name, source_p->name);
142 return 0;
143 }
144
145 last_used = CurrentTime;
146
147 return dohelp(source_p, parv[1]);
148 }
149
150 /*
151 * mo_help - HELP message handler
152 * parv[0] = sender prefix
153 */
154 static int
155 mo_help(struct Client *client_p, struct Client *source_p,
156 int parc, char *parv[])
157 {
158 return dohelp(source_p, parv[1]);
159 }
160
161 static struct Message help_msgtab =
162 {
163 "HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
164 { m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore }
165 };
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 struct module module_entry =
180 {
181 .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 };

Properties

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