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

Comparing:
ircd-hybrid-8/modules/m_encap.c (file contents), Revision 1243 by michael, Fri Sep 30 10:47:53 2011 UTC vs.
ircd-hybrid/trunk/modules/m_encap.c (file contents), Revision 7924 by michael, Sat Dec 31 13:57:08 2016 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  m_encap.c: encapsulated command propagation and parsing
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2003 by the past and present ircd coders, and others.
4 > *  Copyright (c) 2003-2017 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_encap.c
23 > * \brief Includes required functions for processing the ENCAP command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "client.h"
29   #include "parse.h"
30 < #include "sprintf_irc.h"
29 < #include "s_serv.h"
30 > #include "server.h"
31   #include "send.h"
32   #include "modules.h"
33   #include "irc_string.h"
# Line 39 | Line 40
40   * output       - none
41   * side effects - propagates subcommand to locally connected servers
42   */
43 < static void
44 < ms_encap(struct Client *client_p, struct Client *source_p,
44 <         int parc, char *parv[])
43 > static int
44 > ms_encap(struct Client *source_p, int parc, char *parv[])
45   {
46 <  char buffer[IRCD_BUFSIZE], *ptr = buffer;
46 >  char buffer[IRCD_BUFSIZE] = "", *ptr = buffer;
47    unsigned int cur_len = 0, len, i;
48 + #ifdef NOT_USED_YET
49    int paramcount, mpara = 0;
50 + #endif
51    struct Message *mptr = NULL;
50  MessageHandler handler = 0;
52  
53 <  for (i = 1; i < (unsigned int)parc - 1; i++)
53 >  for (i = 1; i < (unsigned int)parc - 1; ++i)
54    {
55      len = strlen(parv[i]) + 1;
56  
57      if ((cur_len + len) >= sizeof(buffer))
58 <      return;
58 >      return 0;
59  
60      snprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]);
61      cur_len += len;
62      ptr += len;
63    }
64  
65 <  len = strlen(parv[i]);
65 <
66 <  /*
67 <   * if the final parameter crosses our buffer size, should we bail,
68 <   * like the rest, or should we truncate?  ratbox seems to think truncate,
69 <   * so i'll do that for now until i can talk to lee.  -bill
70 <   */
71 <
65 >  /* If it's a command without parameters, don't prepend a ':' */
66    if (parc == 3)
67      snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]);
68    else
69      snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc - 1]);
70  
71 <  if ((cur_len + len) >= sizeof(buffer))
78 <    buffer[sizeof(buffer) - 1] = '\0';
79 <
80 <  sendto_match_servs(source_p, parv[1], CAP_ENCAP,
71 >  sendto_match_servs(source_p, parv[1], CAPAB_ENCAP,
72                       "ENCAP %s", buffer);
73  
74 <  if (!match(parv[1], me.name))
75 <    return;
74 >  if (match(parv[1], me.name))
75 >    return 0;
76  
77    if ((mptr = find_command(parv[2])) == NULL)
78 <    return;
78 >    return 0;
79  
80   #ifdef NOT_USED_YET
81    paramcount = mptr->parameters;
# Line 92 | Line 83 | ms_encap(struct Client *client_p, struct
83   #endif
84    mptr->bytes += strlen(buffer);
85  
95  /*
96   * yes this is an ugly hack, but it is quicker than copying the entire array again
97   * note: this hack wouldnt be needed if parv[0] were set to the command name, rather
98   * than being derived from the prefix, as it should have been from the beginning.
99   */
100  ptr = parv[0];
86    parv += 2;
87    parc -= 2;
103  parv[0] = ptr;
88  
89 <  if ((handler = mptr->handlers[ENCAP_HANDLER]))
90 <    (*handler)(client_p, source_p, parc, parv);
89 >  if ((unsigned int)parc >= mptr->args_min)
90 >    mptr->handlers[ENCAP_HANDLER](source_p, parc, parv);
91 >  return 0;
92   }
93  
94 < static struct Message encap_msgtab = {
95 <  "ENCAP", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
96 <  {m_ignore, m_ignore, ms_encap, m_ignore, m_ignore, m_ignore}
94 > static struct Message encap_msgtab =
95 > {
96 >  .cmd = "ENCAP",
97 >  .args_min = 3,
98 >  .args_max = MAXPARA,
99 >  .handlers[UNREGISTERED_HANDLER] = m_ignore,
100 >  .handlers[CLIENT_HANDLER] = m_ignore,
101 >  .handlers[SERVER_HANDLER] = ms_encap,
102 >  .handlers[ENCAP_HANDLER] = m_ignore,
103 >  .handlers[OPER_HANDLER] = m_ignore
104   };
105  
106   static void
107   module_init(void)
108   {
109    mod_add_cmd(&encap_msgtab);
110 <  add_capability("ENCAP", CAP_ENCAP, 1);
110 >  add_capability("ENCAP", CAPAB_ENCAP);
111   }
112  
113   static void
# Line 125 | Line 117 | module_exit(void)
117    delete_capability("ENCAP");
118   }
119  
120 < struct module module_entry = {
121 <  .node    = { NULL, NULL, NULL },
130 <  .name    = NULL,
120 > struct module module_entry =
121 > {
122    .version = "$Revision$",
132  .handle  = NULL,
123    .modinit = module_init,
124    .modexit = module_exit,
135  .flags   = 0
125   };

Diff Legend

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