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: 2972
Committed: Fri Jan 31 11:40:14 2014 UTC (12 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_help.c
File size: 4347 byte(s)
Log Message:
- m_help.c: Made dohelp() and sendhelpfile() void functions

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1999-2014 ircd-hybrid development team
5 adx 30 *
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 michael 2820 /*! \file m_help.c
23     * \brief Includes required functions for processing the HELP command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "client.h"
29     #include "ircd.h"
30     #include "numeric.h"
31     #include "send.h"
32 michael 1309 #include "conf.h"
33 adx 30 #include "parse.h"
34     #include "modules.h"
35     #include "irc_string.h"
36    
37     #define HELPLEN 400
38    
39    
40 michael 2972 static void
41 michael 1997 sendhelpfile(struct Client *source_p, const char *path, const char *topic)
42 adx 30 {
43 michael 2028 FILE *file = NULL;
44     char line[HELPLEN] = { '\0' };
45 adx 30
46 michael 1997 if ((file = fopen(path, "r")) == NULL)
47 adx 30 {
48 michael 1997 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
49     me.name, source_p->name, topic);
50 michael 2972 return;
51 adx 30 }
52    
53 michael 1997 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 michael 2657 fclose(file);
58 michael 2972 return;
59 michael 1997 }
60 adx 30
61 michael 1997 line[strlen(line) - 1] = '\0';
62     sendto_one(source_p, form_str(RPL_HELPSTART),
63     me.name, source_p->name, topic, line);
64 adx 30
65 michael 1997 while (fgets(line, sizeof(line), file))
66     {
67     line[strlen(line) - 1] = '\0';
68 adx 30
69 michael 1997 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 adx 30 }
77    
78 michael 2972 static void
79     do_help(struct Client *source_p, char *topic)
80 adx 30 {
81 michael 2045 char *p = topic;
82 michael 575 char h_index[] = "index";
83 michael 1737 char path[HYB_PATH_MAX + 1];
84 adx 30 struct stat sb;
85    
86 michael 1674 if (EmptyString(topic))
87     topic = h_index;
88 adx 30 else
89 michael 2045 for (; *p; ++p)
90     *p = ToLower(*p);
91 adx 30
92     if (strpbrk(topic, "/\\"))
93     {
94 michael 1834 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
95 adx 30 me.name, source_p->name, topic);
96 michael 2972 return;
97 adx 30 }
98    
99 michael 2028 if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX)
100 adx 30 {
101 michael 1834 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
102 adx 30 me.name, source_p->name, topic);
103 michael 2972 return;
104 adx 30 }
105    
106 michael 2028 snprintf(path, sizeof(path), "%s/%s", HPATH, topic);
107 adx 30
108     if (stat(path, &sb) < 0)
109     {
110 michael 1834 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
111 adx 30 me.name, source_p->name, topic);
112 michael 2972 return;
113 adx 30 }
114    
115     if (!S_ISREG(sb.st_mode))
116     {
117 michael 1834 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
118 adx 30 me.name, source_p->name, topic);
119 michael 2972 return;
120 adx 30 }
121    
122 michael 2972 sendhelpfile(source_p, path, topic);
123 adx 30 }
124    
125 michael 1997 /*
126     * m_help - HELP message handler
127     * parv[0] = sender prefix
128     */
129 michael 2820 static int
130 michael 1997 m_help(struct Client *client_p, struct Client *source_p,
131     int parc, char *parv[])
132 adx 30 {
133 michael 1997 static time_t last_used = 0;
134 adx 30
135 michael 1997 /* HELP is always local */
136     if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
137 adx 30 {
138 michael 1997 /* safe enough to give this on a local connect only */
139     sendto_one(source_p,form_str(RPL_LOAD2HI),
140     me.name, source_p->name);
141 michael 2820 return 0;
142 adx 30 }
143    
144 michael 1997 last_used = CurrentTime;
145 adx 30
146 michael 2972 do_help(source_p, parv[1]);
147     return 0;
148 michael 1997 }
149 adx 30
150 michael 1997 /*
151     * mo_help - HELP message handler
152     * parv[0] = sender prefix
153     */
154 michael 2820 static int
155 michael 1997 mo_help(struct Client *client_p, struct Client *source_p,
156     int parc, char *parv[])
157     {
158 michael 2972 do_help(source_p, parv[1]);
159     return 0;
160 michael 1997 }
161 michael 1674
162 michael 2820 static struct Message help_msgtab =
163     {
164 michael 1699 "HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
165 michael 2820 { m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore }
166 michael 1230 };
167    
168     static void
169     module_init(void)
170     {
171     mod_add_cmd(&help_msgtab);
172     }
173    
174     static void
175     module_exit(void)
176     {
177     mod_del_cmd(&help_msgtab);
178     }
179    
180 michael 2820 struct module module_entry =
181     {
182 michael 1230 .node = { NULL, NULL, NULL },
183     .name = NULL,
184     .version = "$Revision$",
185     .handle = NULL,
186     .modinit = module_init,
187     .modexit = module_exit,
188     .flags = 0
189     };

Properties

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