ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_help.c
Revision: 3156
Committed: Fri Mar 14 19:57:38 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 3905 byte(s)
Log Message:
- Removed client_p pointers from everywhere

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 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
49 michael 2972 return;
50 adx 30 }
51    
52 michael 1997 if (fgets(line, sizeof(line), file) == NULL)
53     {
54 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
55 michael 2657 fclose(file);
56 michael 2972 return;
57 michael 1997 }
58 adx 30
59 michael 1997 line[strlen(line) - 1] = '\0';
60 michael 3109 sendto_one_numeric(source_p, &me, RPL_HELPSTART, 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 3109 sendto_one_numeric(source_p, &me, RPL_HELPTXT, topic, line);
67 michael 1997 }
68    
69     fclose(file);
70 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFHELP, topic);
71 adx 30 }
72    
73 michael 2972 static void
74     do_help(struct Client *source_p, char *topic)
75 adx 30 {
76 michael 2045 char *p = topic;
77 michael 575 char h_index[] = "index";
78 michael 1737 char path[HYB_PATH_MAX + 1];
79 adx 30 struct stat sb;
80    
81 michael 1674 if (EmptyString(topic))
82     topic = h_index;
83 adx 30 else
84 michael 2045 for (; *p; ++p)
85     *p = ToLower(*p);
86 adx 30
87     if (strpbrk(topic, "/\\"))
88     {
89 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
90 michael 2972 return;
91 adx 30 }
92    
93 michael 2028 if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX)
94 adx 30 {
95 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
96 michael 2972 return;
97 adx 30 }
98    
99 michael 2028 snprintf(path, sizeof(path), "%s/%s", HPATH, topic);
100 adx 30
101     if (stat(path, &sb) < 0)
102     {
103 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
104 michael 2972 return;
105 adx 30 }
106    
107     if (!S_ISREG(sb.st_mode))
108     {
109 michael 3109 sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
110 michael 2972 return;
111 adx 30 }
112    
113 michael 2972 sendhelpfile(source_p, path, topic);
114 adx 30 }
115    
116 michael 1997 /*
117     * m_help - HELP message handler
118 michael 3096 * parv[0] = command
119 michael 1997 */
120 michael 2820 static int
121 michael 3156 m_help(struct Client *source_p, int parc, char *parv[])
122 adx 30 {
123 michael 1997 static time_t last_used = 0;
124 adx 30
125 michael 1997 /* HELP is always local */
126     if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
127 adx 30 {
128 michael 1997 /* safe enough to give this on a local connect only */
129 michael 3109 sendto_one_numeric(source_p, &me, RPL_LOAD2HI);
130 michael 2820 return 0;
131 adx 30 }
132    
133 michael 1997 last_used = CurrentTime;
134 adx 30
135 michael 2972 do_help(source_p, parv[1]);
136     return 0;
137 michael 1997 }
138 adx 30
139 michael 1997 /*
140     * mo_help - HELP message handler
141 michael 3096 * parv[0] = command
142 michael 1997 */
143 michael 2820 static int
144 michael 3156 mo_help(struct Client *source_p, int parc, char *parv[])
145 michael 1997 {
146 michael 2972 do_help(source_p, parv[1]);
147     return 0;
148 michael 1997 }
149 michael 1674
150 michael 2820 static struct Message help_msgtab =
151     {
152 michael 1699 "HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
153 michael 2820 { m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore }
154 michael 1230 };
155    
156     static void
157     module_init(void)
158     {
159     mod_add_cmd(&help_msgtab);
160     }
161    
162     static void
163     module_exit(void)
164     {
165     mod_del_cmd(&help_msgtab);
166     }
167    
168 michael 2820 struct module module_entry =
169     {
170 michael 1230 .node = { NULL, NULL, NULL },
171     .name = NULL,
172     .version = "$Revision$",
173     .handle = NULL,
174     .modinit = module_init,
175     .modexit = module_exit,
176     .flags = 0
177     };

Properties

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