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.3/modules/m_help.c (file contents), Revision 1121 by michael, Sun Jan 9 11:03:03 2011 UTC vs.
ircd-hybrid/trunk/modules/m_help.c (file contents), Revision 4565 by michael, Sun Aug 24 10:27:40 2014 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-2014 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  
37   #define HELPLEN 400
38  
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 void
58 _modinit(void)
59 {
60  mod_add_cmd(&help_msgtab);
61  mod_add_cmd(&uhelp_msgtab);
62 }
63
64 void
65 _moddeinit(void)
66 {
67  mod_del_cmd(&help_msgtab);
68  mod_del_cmd(&uhelp_msgtab);
69 }
39  
71 const char *_version = "$Revision$";
72
73 /*
74 * m_help - HELP message handler
75 *      parv[0] = sender prefix
76 */
40   static void
41 < m_help(struct Client *client_p, struct Client *source_p,
79 <       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 line[HELPLEN] = "";
45  
46 <  /* HELP is always local */
84 <  if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
46 >  if ((file = fopen(path, "r")) == NULL)
47    {
48 <    /* safe enough to give this on a local connect only */
87 <    sendto_one(source_p,form_str(RPL_LOAD2HI),
88 <               me.name, source_p->name);
48 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
49      return;
50    }
51  
52 <  last_used = CurrentTime;
52 >  if (fgets(line, sizeof(line), file) == NULL)
53 >  {
54 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
55 >    fclose(file);
56 >    return;
57 >  }
58  
59 <  dohelp(source_p, UHPATH, parv[1]);
60 < }
59 >  line[strlen(line) - 1] = '\0';
60 >  sendto_one_numeric(source_p, &me, RPL_HELPSTART, topic, line);
61  
62 < /*
63 < * mo_help - HELP message handler
64 < *      parv[0] = sender prefix
100 < */
101 < static void
102 < mo_help(struct Client *client_p, struct Client *source_p,
103 <        int parc, char *parv[])
104 < {
105 <  dohelp(source_p, HPATH, parv[1]);
106 < }
62 >  while (fgets(line, sizeof(line), file))
63 >  {
64 >    line[strlen(line) - 1] = '\0';
65  
66 < /*
67 < * mo_uhelp - HELP message handler
68 < * This is used so that opers can view the user help file without deopering
69 < *      parv[0] = sender prefix
70 < */
113 < static void
114 < mo_uhelp(struct Client *client_p, struct Client *source_p,
115 <            int parc, char *parv[])
116 < {
117 <  dohelp(source_p, UHPATH, parv[1]);
66 >    sendto_one_numeric(source_p, &me, RPL_HELPTXT, topic, line);
67 >  }
68 >
69 >  fclose(file);
70 >  sendto_one_numeric(source_p, &me, RPL_ENDOFHELP, topic);
71   }
72  
73   static void
74 < dohelp(struct Client *source_p, const char *hpath, char *topic)
74 > do_help(struct Client *source_p, char *topic)
75   {
76    char h_index[] = "index";
77 <  char path[PATH_MAX + 1];
77 >  char path[HYB_PATH_MAX + 1];
78    struct stat sb;
126  int i;
79  
80 <  if (topic != NULL)
81 <  {
130 <    if (*topic == '\0')
131 <      topic = h_index;
132 <    else
133 <    {
134 <      /* convert to lower case */
135 <      for (i = 0; topic[i] != '\0'; ++i)
136 <        topic[i] = ToLower(topic[i]);
137 <    }
138 <  }
80 >  if (EmptyString(topic))
81 >    topic = h_index;
82    else
83 <    topic = h_index;    /* list available help topics */
83 >    for (char *p = topic; *p; ++p)
84 >      *p = ToLower(*p);
85  
86    if (strpbrk(topic, "/\\"))
87    {
88 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
145 <               me.name, source_p->name, topic);
88 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
89      return;
90    }
91  
92 <  if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX)
92 >  if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX)
93    {
94 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
152 <               me.name, source_p->name, topic);
94 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
95      return;
96    }
97  
98 <  snprintf(path, sizeof(path), "%s/%s", hpath, topic);
98 >  snprintf(path, sizeof(path), "%s/%s", HPATH, topic);
99  
100    if (stat(path, &sb) < 0)
101    {
102 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
161 <               me.name, source_p->name, topic);
102 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
103      return;
104    }
105  
106    if (!S_ISREG(sb.st_mode))
107    {
108 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
168 <               me.name, source_p->name, topic);
108 >    sendto_one_numeric(source_p, &me, ERR_HELPNOTFOUND, topic);
109      return;
110    }
111  
112    sendhelpfile(source_p, path, topic);
113   }
114  
115 < static void
116 < sendhelpfile(struct Client *source_p, const char *path, const char *topic)
115 > /*! \brief HELP command handler
116 > *
117 > * \param source_p Pointer to allocated Client struct from which the message
118 > *                 originally comes from.  This can be a local or remote client.
119 > * \param parc     Integer holding the number of supplied arguments.
120 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
121 > *                 pointers.
122 > * \note Valid arguments for this command are:
123 > *      - parv[0] = command
124 > *      - parv[1] = help topic
125 > */
126 > static int
127 > m_help(struct Client *source_p, int parc, char *parv[])
128   {
129 <  FBFILE *file;
179 <  char line[HELPLEN];
180 <  char started = 0;
181 <  int type;
129 >  static time_t last_used = 0;
130  
131 <  if ((file = fbopen(path, "r")) == NULL)
131 >  if ((last_used + ConfigGeneral.pace_wait_simple) > CurrentTime)
132    {
133 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
134 <               me.name, source_p->name, topic);
187 <    return;
133 >    sendto_one_numeric(source_p, &me, RPL_LOAD2HI);
134 >    return 0;
135    }
136  
137 <  if (fbgets(line, sizeof(line), file) == NULL)
191 <  {
192 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
193 <               me.name, source_p->name, topic);
194 <    return;
195 <  }
137 >  last_used = CurrentTime;
138  
139 <  else if (line[0] != '#')
140 <  {
141 <    line[strlen(line) - 1] = '\0';        
200 <    sendto_one(source_p, form_str(RPL_HELPSTART),
201 <             me.name, source_p->name, topic, line);
202 <    started = 1;
203 <  }
139 >  do_help(source_p, parv[1]);
140 >  return 0;
141 > }
142  
143 <  while (fbgets(line, sizeof(line), file))
144 <  {
145 <    line[strlen(line) - 1] = '\0';
146 <    if (line[0] != '#')
147 <    {
148 <      if (!started)
149 <      {
150 <        type = RPL_HELPSTART;
151 <        started = 1;
152 <      }
153 <      else
154 <        type = RPL_HELPTXT;
155 <      
156 <      sendto_one(source_p, form_str(RPL_HELPTXT),
157 <                 me.name, source_p->name, topic, line);
158 <    }
159 <  }
160 <
161 <  fbclose(file);
162 <  sendto_one(source_p, form_str(RPL_HELPTXT),
163 <             me.name, source_p->name, topic, "");
164 <  sendto_one(source_p, form_str(RPL_ENDOFHELP),
165 <             me.name, source_p->name, topic);
143 > /*! \brief HELP command handler
144 > *
145 > * \param source_p Pointer to allocated Client struct from which the message
146 > *                 originally comes from.  This can be a local or remote client.
147 > * \param parc     Integer holding the number of supplied arguments.
148 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
149 > *                 pointers.
150 > * \note Valid arguments for this command are:
151 > *      - parv[0] = command
152 > *      - parv[1] = help topic
153 > */
154 > static int
155 > mo_help(struct Client *source_p, int parc, char *parv[])
156 > {
157 >  do_help(source_p, parv[1]);
158 >  return 0;
159 > }
160 >
161 > static struct Message help_msgtab =
162 > {
163 >  "HELP", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
164 >  { m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore }
165 > };
166 >
167 > static void
168 > module_init(void)
169 > {
170 >  mod_add_cmd(&help_msgtab);
171   }
172 +
173 + static void
174 + module_exit(void)
175 + {
176 +  mod_del_cmd(&help_msgtab);
177 + }
178 +
179 + struct module module_entry =
180 + {
181 +  .node    = { NULL, NULL, NULL },
182 +  .name    = NULL,
183 +  .version = "$Revision$",
184 +  .handle  = NULL,
185 +  .modinit = module_init,
186 +  .modexit = module_exit,
187 +  .flags   = 0
188 + };

Diff Legend

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