ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_help.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 5688 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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

Properties

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