ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_help.c
Revision: 1001
Committed: Sat Aug 29 22:44:44 2009 UTC (16 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_help.c
File size: 5658 byte(s)
Log Message:
- remove half done and broken win32 support

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 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 michael 575 char h_index[] = "index";
126 adx 30 char path[PATH_MAX + 1];
127     struct stat sb;
128     int i;
129    
130     if (topic != NULL)
131     {
132     if (*topic == '\0')
133 michael 575 topic = h_index;
134 adx 30 else
135     {
136     /* convert to lower case */
137 michael 575 for (i = 0; topic[i] != '\0'; ++i)
138 adx 30 topic[i] = ToLower(topic[i]);
139     }
140     }
141     else
142 michael 575 topic = h_index; /* list available help topics */
143 adx 30
144     if (strpbrk(topic, "/\\"))
145     {
146     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
147     me.name, source_p->name, topic);
148     return;
149     }
150    
151     if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX)
152     {
153     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
154     me.name, source_p->name, topic);
155     return;
156     }
157    
158     snprintf(path, sizeof(path), "%s/%s", hpath, topic);
159    
160     if (stat(path, &sb) < 0)
161     {
162     ilog(L_NOTICE, "help file %s not found", path);
163     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
164     me.name, source_p->name, topic);
165     return;
166     }
167    
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    
176     sendhelpfile(source_p, path, topic);
177     }
178    
179     static void
180     sendhelpfile(struct Client *source_p, const char *path, const char *topic)
181     {
182     FBFILE *file;
183     char line[HELPLEN];
184     char started = 0;
185     int type;
186    
187     if ((file = fbopen(path, "r")) == NULL)
188     {
189     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
190     me.name, source_p->name, topic);
191     return;
192     }
193    
194     if (fbgets(line, sizeof(line), file) == NULL)
195     {
196     sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
197     me.name, source_p->name, topic);
198     return;
199     }
200    
201     else if (line[0] != '#')
202     {
203     line[strlen(line) - 1] = '\0';
204     sendto_one(source_p, form_str(RPL_HELPSTART),
205     me.name, source_p->name, topic, line);
206     started = 1;
207     }
208    
209     while (fbgets(line, sizeof(line), file))
210     {
211     line[strlen(line) - 1] = '\0';
212     if(line[0] != '#')
213     {
214     if (!started)
215     {
216     type = RPL_HELPSTART;
217     started = 1;
218     }
219     else
220     type = RPL_HELPTXT;
221    
222     sendto_one(source_p, form_str(RPL_HELPTXT),
223     me.name, source_p->name, topic, line);
224     }
225     }
226    
227     fbclose(file);
228     sendto_one(source_p, form_str(RPL_HELPTXT),
229     me.name, source_p->name, topic, "");
230     sendto_one(source_p, form_str(RPL_ENDOFHELP),
231     me.name, source_p->name, topic);
232     }

Properties

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