ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_encap.c
Revision: 9762
Committed: Mon Nov 30 18:02:23 2020 UTC (5 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 3273 byte(s)
Log Message:
- Stylistical changes

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2816 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 9101 * Copyright (c) 2003-2020 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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2816 /*! \file m_encap.c
23     * \brief Includes required functions for processing the ENCAP command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "client.h"
29     #include "parse.h"
30 michael 8166 #include "server_capab.h"
31 adx 30 #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 michael 9077 static void
44 michael 3156 ms_encap(struct Client *source_p, int parc, char *parv[])
45 adx 30 {
46 michael 9762 char buf[IRCD_BUFSIZE];
47     char *bufptr = buf;
48 michael 9374 unsigned int cur_len = 0, len;
49 adx 30
50 michael 9374 for (unsigned int i = 1; i < (unsigned int)parc - 1; ++i)
51 adx 30 {
52 michael 8260 len = strlen(parv[i]) + 1; /* +1 for the space */
53 adx 30
54 michael 8260 /* Drop the whole command if this parameter would be truncated */
55 michael 9762 if ((cur_len + len) >= sizeof(buf))
56 michael 9077 return;
57 adx 30
58 michael 9762 snprintf(bufptr, sizeof(buf) - cur_len, "%s ", parv[i]);
59 adx 30 cur_len += len;
60 michael 9762 bufptr += len;
61 adx 30 }
62    
63 michael 3037 /* If it's a command without parameters, don't prepend a ':' */
64 adx 30 if (parc == 3)
65 michael 9762 snprintf(bufptr, sizeof(buf) - cur_len, "%s", parv[2]);
66 adx 30 else
67 michael 9762 snprintf(bufptr, sizeof(buf) - cur_len, ":%s", parv[parc - 1]);
68 adx 30
69 michael 9762 sendto_match_servs(source_p, parv[1], CAPAB_ENCAP, "ENCAP %s", buf);
70 adx 30
71 michael 1652 if (match(parv[1], me.name))
72 michael 9077 return;
73 adx 30
74 michael 9374 struct Message *message = find_command(parv[2]);
75     if (message == NULL)
76 michael 9077 return;
77 adx 30
78 michael 9374 const struct MessageHandler *const handler = &message->handlers[ENCAP_HANDLER];
79 michael 9762 message->bytes += strlen(buf);
80 michael 9378 message->ecount++;
81    
82 adx 30 parv += 2;
83     parc -= 2;
84    
85 michael 9374 if (handler->args_min &&
86     (((unsigned int)parc < handler->args_min) ||
87     (handler->empty_last_arg != true && EmptyString(parv[handler->args_min - 1]))))
88     return;
89    
90     handler->handler(source_p, parc, parv);
91 adx 30 }
92 michael 1230
93 michael 2816 static struct Message encap_msgtab =
94     {
95 michael 5881 .cmd = "ENCAP",
96 michael 9374 .handlers[UNREGISTERED_HANDLER] = { .handler = m_ignore },
97     .handlers[CLIENT_HANDLER] = { .handler = m_ignore },
98     .handlers[SERVER_HANDLER] = { .handler = ms_encap, .args_min = 3 },
99     .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
100     .handlers[OPER_HANDLER] = { .handler = m_ignore }
101 michael 1230 };
102    
103     static void
104     module_init(void)
105     {
106     mod_add_cmd(&encap_msgtab);
107 michael 8166 capab_add("ENCAP", CAPAB_ENCAP);
108 michael 1230 }
109    
110     static void
111     module_exit(void)
112     {
113     mod_del_cmd(&encap_msgtab);
114 michael 8166 capab_del("ENCAP");
115 michael 1230 }
116    
117 michael 2816 struct module module_entry =
118     {
119 michael 1230 .version = "$Revision$",
120     .modinit = module_init,
121     .modexit = module_exit,
122     };

Properties

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