ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_help.c
Revision: 1997
Committed: Sat May 11 17:35:07 2013 UTC (13 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_help.c
File size: 4817 byte(s)
Log Message:
- Mostly style cleanups & whitespace changes

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_help.c: Provides help information to a user/operator.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "client.h"
27     #include "ircd.h"
28     #include "numeric.h"
29     #include "send.h"
30 michael 1309 #include "conf.h"
31 adx 30 #include "parse.h"
32     #include "modules.h"
33     #include "irc_string.h"
34    
35     #define HELPLEN 400
36    
37    
38     static void
39 michael 1997 sendhelpfile(struct Client *source_p, const char *path, const char *topic)
40 adx 30 {
41 michael 1997 FILE *file;
42     char line[HELPLEN];
43 adx 30
44 michael 1997 if ((file = fopen(path, "r")) == NULL)
45 adx 30 {
46 michael 1997 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
47     me.name, source_p->name, topic);
48 adx 30 return;
49     }
50    
51 michael 1997 if (fgets(line, sizeof(line), file) == NULL)
52     {
53     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
54     me.name, source_p->name, topic);
55     return;
56     }
57 adx 30
58 michael 1997 line[strlen(line) - 1] = '\0';
59     sendto_one(source_p, form_str(RPL_HELPSTART),
60     me.name, source_p->name, 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 1997 sendto_one(source_p, form_str(RPL_HELPTXT),
67     me.name, source_p->name, topic, line);
68     }
69    
70     fclose(file);
71     sendto_one(source_p, form_str(RPL_ENDOFHELP),
72     me.name, source_p->name, topic);
73 adx 30 }
74    
75     static void
76     dohelp(struct Client *source_p, const char *hpath, char *topic)
77     {
78 michael 575 char h_index[] = "index";
79 michael 1737 char path[HYB_PATH_MAX + 1];
80 adx 30 struct stat sb;
81 michael 1674 unsigned int i;
82 adx 30
83 michael 1674 if (EmptyString(topic))
84     topic = h_index;
85 adx 30 else
86 michael 1674 for (i = 0; topic[i] != '\0'; ++i)
87     topic[i] = ToLower(topic[i]);
88 adx 30
89     if (strpbrk(topic, "/\\"))
90     {
91 michael 1834 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
92 adx 30 me.name, source_p->name, topic);
93     return;
94     }
95    
96 michael 1737 if (strlen(hpath) + strlen(topic) + 1 > HYB_PATH_MAX)
97 adx 30 {
98 michael 1834 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
99 adx 30 me.name, source_p->name, topic);
100     return;
101     }
102    
103     snprintf(path, sizeof(path), "%s/%s", hpath, topic);
104    
105     if (stat(path, &sb) < 0)
106     {
107 michael 1834 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
108 adx 30 me.name, source_p->name, topic);
109     return;
110     }
111    
112     if (!S_ISREG(sb.st_mode))
113     {
114 michael 1834 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
115 adx 30 me.name, source_p->name, topic);
116     return;
117     }
118    
119     sendhelpfile(source_p, path, topic);
120     }
121    
122 michael 1997 /*
123     * m_help - HELP message handler
124     * parv[0] = sender prefix
125     */
126     static void
127     m_help(struct Client *client_p, struct Client *source_p,
128     int parc, char *parv[])
129 adx 30 {
130 michael 1997 static time_t last_used = 0;
131 adx 30
132 michael 1997 /* HELP is always local */
133     if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
134 adx 30 {
135 michael 1997 /* safe enough to give this on a local connect only */
136     sendto_one(source_p,form_str(RPL_LOAD2HI),
137     me.name, source_p->name);
138 adx 30 return;
139     }
140    
141 michael 1997 last_used = CurrentTime;
142 adx 30
143 michael 1997 dohelp(source_p, UHPATH, parv[1]);
144     }
145 adx 30
146 michael 1997 /*
147     * mo_help - HELP message handler
148     * parv[0] = sender prefix
149     */
150     static void
151     mo_help(struct Client *client_p, struct Client *source_p,
152     int parc, char *parv[])
153     {
154     dohelp(source_p, HPATH, parv[1]);
155     }
156 michael 1674
157 michael 1997 /*
158     * mo_uhelp - HELP message handler
159     * This is used so that opers can view the user help file without deopering
160     * parv[0] = sender prefix
161     */
162     static void
163     mo_uhelp(struct Client *client_p, struct Client *source_p,
164     int parc, char *parv[])
165     {
166     dohelp(source_p, UHPATH, parv[1]);
167 adx 30 }
168 michael 1230
169     static struct Message help_msgtab = {
170 michael 1699 "HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
171 michael 1230 {m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore}
172     };
173    
174     static struct Message uhelp_msgtab = {
175 michael 1699 "UHELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
176 michael 1230 {m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore}
177     };
178    
179     static void
180     module_init(void)
181     {
182     mod_add_cmd(&help_msgtab);
183     mod_add_cmd(&uhelp_msgtab);
184     }
185    
186     static void
187     module_exit(void)
188     {
189     mod_del_cmd(&help_msgtab);
190     mod_del_cmd(&uhelp_msgtab);
191     }
192    
193     struct module module_entry = {
194     .node = { NULL, NULL, NULL },
195     .name = NULL,
196     .version = "$Revision$",
197     .handle = NULL,
198     .modinit = module_init,
199     .modexit = module_exit,
200     .flags = 0
201     };

Properties

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