ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_help.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/modules/m_help.c (file contents), Revision 897 by db, Sat Nov 3 17:13:32 2007 UTC vs.
ircd-hybrid/trunk/modules/m_help.c (file contents), Revision 6350 by michael, Tue Aug 11 17:53:44 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  m_help.c: Provides help information to a user/operator.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1999-2015 ircd-hybrid development team
5   *
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
# Line 16 | Line 15
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
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file m_help.c
23 > * \brief Includes required functions for processing the HELP command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
26 #include "handlers.h"
28   #include "client.h"
29   #include "ircd.h"
29 #include "ircd_handler.h"
30 #include "msg.h"
30   #include "numeric.h"
31   #include "send.h"
32 < #include "s_conf.h"
34 < #include "s_log.h"
32 > #include "conf.h"
33   #include "parse.h"
34   #include "modules.h"
35   #include "irc_string.h"
36  
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 }
37  
38 < const char *_version = "$Revision$";
73 < #endif
38 > enum { HELPLEN = 400 };
39  
75 /*
76 * m_help - HELP message handler
77 *      parv[0] = sender prefix
78 */
40   static void
41 < m_help(struct Client *client_p, struct Client *source_p,
81 <       int parc, char *parv[])
41 > sendhelpfile(struct Client *source_p, const char *path, const char *topic)
42   {
43 <  static time_t last_used = 0;
43 >  FILE *file = NULL;
44 >  char *p = NULL;
45 >  char line[HELPLEN] = "";
46  
47 <  /* HELP is always local */
86 <  if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
47 >  if ((file = fopen(path, "r")) == NULL)
48    {
49 <    /* 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);
49 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
50      return;
51    }
52  
53 <  last_used = CurrentTime;
53 >  if (fgets(line, sizeof(line), file) == NULL)
54 >  {
55 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
56 >    fclose(file);
57 >    return;
58 >  }
59  
60 <  dohelp(source_p, UHPATH, parv[1]);
61 < }
60 >  if ((p = strpbrk(line, "\r\n")))
61 >    *p = '\0';
62  
63 < /*
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 < }
63 >  sendto_one_numeric(source_p, &me, RPL_HELPSTART, topic, line);
64  
65 < /*
66 < * mo_uhelp - HELP message handler
67 < * This is used so that opers can view the user help file without deopering
68 < *      parv[0] = sender prefix
69 < */
70 < static void
71 < mo_uhelp(struct Client *client_p, struct Client *source_p,
72 <            int parc, char *parv[])
73 < {
74 <  dohelp(source_p, UHPATH, parv[1]);
65 >  while (fgets(line, sizeof(line), file))
66 >  {
67 >    if ((p = strpbrk(line, "\r\n")))
68 >      *p = '\0';
69 >
70 >    sendto_one_numeric(source_p, &me, RPL_HELPTXT, topic, line);
71 >  }
72 >
73 >  fclose(file);
74 >  sendto_one_numeric(source_p, &me, RPL_ENDOFHELP, topic);
75   }
76  
77   static void
78 < dohelp(struct Client *source_p, const char *hpath, char *topic)
78 > do_help(struct Client *source_p, char *topic)
79   {
80    char h_index[] = "index";
81 <  char path[PATH_MAX + 1];
81 >  char path[HYB_PATH_MAX + 1];
82    struct stat sb;
128  int i;
83  
84 <  if (topic != NULL)
85 <  {
132 <    if (*topic == '\0')
133 <      topic = h_index;
134 <    else
135 <    {
136 <      /* convert to lower case */
137 <      for (i = 0; topic[i] != '\0'; ++i)
138 <        topic[i] = ToLower(topic[i]);
139 <    }
140 <  }
84 >  if (EmptyString(topic))
85 >    topic = h_index;
86    else
87 <    topic = h_index;    /* list available help topics */
87 >    for (char *p = topic; *p; ++p)
88 >      *p = ToLower(*p);
89  
90    if (strpbrk(topic, "/\\"))
91    {
92 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
147 <               me.name, source_p->name, topic);
92 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
93      return;
94    }
95  
96 <  if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX)
96 >  if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX)
97    {
98 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
154 <               me.name, source_p->name, topic);
98 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
99      return;
100    }
101  
102 <  snprintf(path, sizeof(path), "%s/%s", hpath, topic);
102 >  snprintf(path, sizeof(path), "%s/%s", HPATH, topic);
103  
104    if (stat(path, &sb) < 0)
105    {
106 <    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);
106 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
107      return;
108    }
109  
168 #ifndef _WIN32
110    if (!S_ISREG(sb.st_mode))
111    {
112 <    ilog(L_NOTICE, "help file %s not found", path);
172 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
173 <               me.name, source_p->name, topic);
112 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
113      return;
114    }
176 #endif
115  
116    sendhelpfile(source_p, path, topic);
117   }
118  
119 < static void
120 < sendhelpfile(struct Client *source_p, const char *path, const char *topic)
119 > /*! \brief HELP command handler
120 > *
121 > * \param source_p Pointer to allocated Client struct from which the message
122 > *                 originally comes from.  This can be a local or remote client.
123 > * \param parc     Integer holding the number of supplied arguments.
124 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
125 > *                 pointers.
126 > * \note Valid arguments for this command are:
127 > *      - parv[0] = command
128 > *      - parv[1] = help topic
129 > */
130 > static int
131 > m_help(struct Client *source_p, int parc, char *parv[])
132   {
133 <  FBFILE *file;
185 <  char line[HELPLEN];
186 <  char started = 0;
187 <  int type;
133 >  static time_t last_used = 0;
134  
135 <  if ((file = fbopen(path, "r")) == NULL)
135 >  if ((last_used + ConfigGeneral.pace_wait_simple) > CurrentTime)
136    {
137 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
138 <               me.name, source_p->name, topic);
193 <    return;
137 >    sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "HELP");
138 >    return 0;
139    }
140  
141 <  if (fbgets(line, sizeof(line), file) == NULL)
197 <  {
198 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
199 <               me.name, source_p->name, topic);
200 <    return;
201 <  }
141 >  last_used = CurrentTime;
142  
143 <  else if (line[0] != '#')
144 <  {
145 <    line[strlen(line) - 1] = '\0';        
206 <    sendto_one(source_p, form_str(RPL_HELPSTART),
207 <             me.name, source_p->name, topic, line);
208 <    started = 1;
209 <  }
143 >  do_help(source_p, parv[1]);
144 >  return 0;
145 > }
146  
147 <  while (fbgets(line, sizeof(line), file))
148 <  {
149 <    line[strlen(line) - 1] = '\0';
150 <    if(line[0] != '#')
151 <    {
152 <      if (!started)
153 <      {
154 <        type = RPL_HELPSTART;
155 <        started = 1;
156 <      }
157 <      else
158 <        type = RPL_HELPTXT;
159 <      
160 <      sendto_one(source_p, form_str(RPL_HELPTXT),
161 <                 me.name, source_p->name, topic, line);
162 <    }
163 <  }
147 > /*! \brief HELP command handler
148 > *
149 > * \param source_p Pointer to allocated Client struct from which the message
150 > *                 originally comes from.  This can be a local or remote client.
151 > * \param parc     Integer holding the number of supplied arguments.
152 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
153 > *                 pointers.
154 > * \note Valid arguments for this command are:
155 > *      - parv[0] = command
156 > *      - parv[1] = help topic
157 > */
158 > static int
159 > mo_help(struct Client *source_p, int parc, char *parv[])
160 > {
161 >  do_help(source_p, parv[1]);
162 >  return 0;
163 > }
164  
165 <  fbclose(file);
166 <  sendto_one(source_p, form_str(RPL_HELPTXT),
167 <             me.name, source_p->name, topic, "");
168 <  sendto_one(source_p, form_str(RPL_ENDOFHELP),
169 <             me.name, source_p->name, topic);
165 > static struct Message help_msgtab =
166 > {
167 >  .cmd = "HELP",
168 >  .args_max = MAXPARA,
169 >  .handlers[UNREGISTERED_HANDLER] = m_unregistered,
170 >  .handlers[CLIENT_HANDLER] = m_help,
171 >  .handlers[SERVER_HANDLER] = m_ignore,
172 >  .handlers[ENCAP_HANDLER] = m_ignore,
173 >  .handlers[OPER_HANDLER] = mo_help
174 > };
175 >
176 > static void
177 > module_init(void)
178 > {
179 >  mod_add_cmd(&help_msgtab);
180   }
181 +
182 + static void
183 + module_exit(void)
184 + {
185 +  mod_del_cmd(&help_msgtab);
186 + }
187 +
188 + struct module module_entry =
189 + {
190 +  .version = "$Revision$",
191 +  .modinit = module_init,
192 +  .modexit = module_exit,
193 + };

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)