ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_encap.c
Revision: 9374
Committed: Sat May 9 20:54:46 2020 UTC (6 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 3258 byte(s)
Log Message:
- Each type of command handler now has its own min/max argument count pair;  remove remaining argument checks from all modules

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2003-2020 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
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
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 "server_capab.h"
31 #include "send.h"
32 #include "modules.h"
33 #include "irc_string.h"
34
35
36 /*
37 * ms_encap()
38 *
39 * inputs - destination server, subcommand, parameters
40 * output - none
41 * side effects - propagates subcommand to locally connected servers
42 */
43 static void
44 ms_encap(struct Client *source_p, int parc, char *parv[])
45 {
46 char buffer[IRCD_BUFSIZE] = "", *ptr = buffer;
47 unsigned int cur_len = 0, len;
48
49 for (unsigned int i = 1; i < (unsigned int)parc - 1; ++i)
50 {
51 len = strlen(parv[i]) + 1; /* +1 for the space */
52
53 /* Drop the whole command if this parameter would be truncated */
54 if ((cur_len + len) >= sizeof(buffer))
55 return;
56
57 snprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]);
58 cur_len += len;
59 ptr += len;
60 }
61
62 /* If it's a command without parameters, don't prepend a ':' */
63 if (parc == 3)
64 snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]);
65 else
66 snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc - 1]);
67
68 sendto_match_servs(source_p, parv[1], CAPAB_ENCAP, "ENCAP %s", buffer);
69
70 if (match(parv[1], me.name))
71 return;
72
73 struct Message *message = find_command(parv[2]);
74 if (message == NULL)
75 return;
76
77 const struct MessageHandler *const handler = &message->handlers[ENCAP_HANDLER];
78 message->bytes += strlen(buffer);
79 parv += 2;
80 parc -= 2;
81
82 if (handler->args_min &&
83 (((unsigned int)parc < handler->args_min) ||
84 (handler->empty_last_arg != true && EmptyString(parv[handler->args_min - 1]))))
85 return;
86
87 handler->handler(source_p, parc, parv);
88 }
89
90 static struct Message encap_msgtab =
91 {
92 .cmd = "ENCAP",
93 .handlers[UNREGISTERED_HANDLER] = { .handler = m_ignore },
94 .handlers[CLIENT_HANDLER] = { .handler = m_ignore },
95 .handlers[SERVER_HANDLER] = { .handler = ms_encap, .args_min = 3 },
96 .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
97 .handlers[OPER_HANDLER] = { .handler = m_ignore }
98 };
99
100 static void
101 module_init(void)
102 {
103 mod_add_cmd(&encap_msgtab);
104 capab_add("ENCAP", CAPAB_ENCAP);
105 }
106
107 static void
108 module_exit(void)
109 {
110 mod_del_cmd(&encap_msgtab);
111 capab_del("ENCAP");
112 }
113
114 struct module module_entry =
115 {
116 .version = "$Revision$",
117 .modinit = module_init,
118 .modexit = module_exit,
119 };

Properties

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