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: 575
Committed: Mon May 1 11:41:09 2006 UTC (20 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_help.c
File size: 5762 byte(s)
Log Message:
- Fixed a bunch of compile warnings

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 "handlers.h"
27     #include "client.h"
28     #include "ircd.h"
29     #include "ircd_handler.h"
30     #include "msg.h"
31     #include "numeric.h"
32     #include "send.h"
33     #include "s_conf.h"
34     #include "s_log.h"
35     #include "parse.h"
36     #include "modules.h"
37     #include "irc_string.h"
38    
39     #define HPATH IRCD_PREFIX "/help/opers"
40     #define UHPATH IRCD_PREFIX "/help/users"
41     #define HELPLEN 400
42    
43     static void m_help(struct Client *, struct Client *, int, char *[]);
44     static void mo_help(struct Client *, struct Client *, int, char *[]);
45     static void mo_uhelp(struct Client *, struct Client *, int, char *[]);
46     static void dohelp(struct Client *, const char *, char *);
47     static void sendhelpfile(struct Client *, const char *, const char *);
48    
49     struct Message help_msgtab = {
50     "HELP", 0, 0, 0, 0, MFLG_SLOW, 0,
51     {m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore}
52     };
53    
54     struct Message uhelp_msgtab = {
55     "UHELP", 0, 0, 0, 0, MFLG_SLOW, 0,
56     {m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore}
57     };
58    
59     #ifndef STATIC_MODULES
60     void
61     _modinit(void)
62     {
63     mod_add_cmd(&help_msgtab);
64     mod_add_cmd(&uhelp_msgtab);
65     }
66    
67     void
68     _moddeinit(void)
69     {
70     mod_del_cmd(&help_msgtab);
71     mod_del_cmd(&uhelp_msgtab);
72     }
73    
74 knight 31 const char *_version = "$Revision$";
75 adx 30 #endif
76    
77     /*
78     * m_help - HELP message handler
79     * parv[0] = sender prefix
80     */
81     static void
82     m_help(struct Client *client_p, struct Client *source_p,
83     int parc, char *parv[])
84     {
85     static time_t last_used = 0;
86    
87     /* HELP is always local */
88     if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
89     {
90     /* safe enough to give this on a local connect only */
91     sendto_one(source_p,form_str(RPL_LOAD2HI),
92     me.name, source_p->name);
93     return;
94     }
95    
96     last_used = CurrentTime;
97    
98     dohelp(source_p, UHPATH, parv[1]);
99     }
100    
101     /*
102     * mo_help - HELP message handler
103     * parv[0] = sender prefix
104     */
105     static void
106     mo_help(struct Client *client_p, struct Client *source_p,
107     int parc, char *parv[])
108     {
109     dohelp(source_p, HPATH, parv[1]);
110     }
111    
112     /*
113     * mo_uhelp - HELP message handler
114     * This is used so that opers can view the user help file without deopering
115     * parv[0] = sender prefix
116     */
117     static void
118     mo_uhelp(struct Client *client_p, struct Client *source_p,
119     int parc, char *parv[])
120     {
121     dohelp(source_p, UHPATH, parv[1]);
122     }
123    
124     static void
125     dohelp(struct Client *source_p, const char *hpath, char *topic)
126     {
127 michael 575 char h_index[] = "index";
128 adx 30 char path[PATH_MAX + 1];
129     struct stat sb;
130     int i;
131    
132     if (topic != NULL)
133     {
134     if (*topic == '\0')
135 michael 575 topic = h_index;
136 adx 30 else
137     {
138     /* convert to lower case */
139 michael 575 for (i = 0; topic[i] != '\0'; ++i)
140 adx 30 topic[i] = ToLower(topic[i]);
141     }
142     }
143     else
144 michael 575 topic = h_index; /* list available help topics */
145 adx 30
146     if (strpbrk(topic, "/\\"))
147     {
148     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
149     me.name, source_p->name, topic);
150     return;
151     }
152    
153     if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX)
154     {
155     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
156     me.name, source_p->name, topic);
157     return;
158     }
159    
160     snprintf(path, sizeof(path), "%s/%s", hpath, topic);
161    
162     if (stat(path, &sb) < 0)
163     {
164     ilog(L_NOTICE, "help file %s not found", path);
165     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
166     me.name, source_p->name, topic);
167     return;
168     }
169    
170     #ifndef _WIN32
171     if (!S_ISREG(sb.st_mode))
172     {
173     ilog(L_NOTICE, "help file %s not found", path);
174     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
175     me.name, source_p->name, topic);
176     return;
177     }
178     #endif
179    
180     sendhelpfile(source_p, path, topic);
181     }
182    
183     static void
184     sendhelpfile(struct Client *source_p, const char *path, const char *topic)
185     {
186     FBFILE *file;
187     char line[HELPLEN];
188     char started = 0;
189     int type;
190    
191     if ((file = fbopen(path, "r")) == NULL)
192     {
193     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
194     me.name, source_p->name, topic);
195     return;
196     }
197    
198     if (fbgets(line, sizeof(line), file) == NULL)
199     {
200     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
201     me.name, source_p->name, topic);
202     return;
203     }
204    
205     else if (line[0] != '#')
206     {
207     line[strlen(line) - 1] = '\0';
208     sendto_one(source_p, form_str(RPL_HELPSTART),
209     me.name, source_p->name, topic, line);
210     started = 1;
211     }
212    
213     while (fbgets(line, sizeof(line), file))
214     {
215     line[strlen(line) - 1] = '\0';
216     if(line[0] != '#')
217     {
218     if (!started)
219     {
220     type = RPL_HELPSTART;
221     started = 1;
222     }
223     else
224     type = RPL_HELPTXT;
225    
226     sendto_one(source_p, form_str(RPL_HELPTXT),
227     me.name, source_p->name, topic, line);
228     }
229     }
230    
231     fbclose(file);
232     sendto_one(source_p, form_str(RPL_HELPTXT),
233     me.name, source_p->name, topic, "");
234     sendto_one(source_p, form_str(RPL_ENDOFHELP),
235     me.name, source_p->name, topic);
236     }

Properties

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