1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2003-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 |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
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 "s_serv.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 *client_p, struct Client *source_p, |
45 |
int parc, char *parv[]) |
46 |
{ |
47 |
char buffer[IRCD_BUFSIZE], *ptr = buffer; |
48 |
unsigned int cur_len = 0, len, i; |
49 |
#ifdef NOT_USED_YET |
50 |
int paramcount, mpara = 0; |
51 |
#endif |
52 |
struct Message *mptr = NULL; |
53 |
MessageHandler handler = 0; |
54 |
|
55 |
for (i = 1; i < (unsigned int)parc - 1; i++) |
56 |
{ |
57 |
len = strlen(parv[i]) + 1; |
58 |
|
59 |
if ((cur_len + len) >= sizeof(buffer)) |
60 |
return; |
61 |
|
62 |
snprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]); |
63 |
cur_len += len; |
64 |
ptr += len; |
65 |
} |
66 |
|
67 |
len = strlen(parv[i]); |
68 |
|
69 |
/* |
70 |
* if the final parameter crosses our buffer size, should we bail, |
71 |
* like the rest, or should we truncate? ratbox seems to think truncate, |
72 |
* so i'll do that for now until i can talk to lee. -bill |
73 |
*/ |
74 |
|
75 |
if (parc == 3) |
76 |
snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]); |
77 |
else |
78 |
snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc - 1]); |
79 |
|
80 |
if ((cur_len + len) >= sizeof(buffer)) |
81 |
buffer[sizeof(buffer) - 1] = '\0'; |
82 |
|
83 |
sendto_match_servs(source_p, parv[1], CAP_ENCAP, |
84 |
"ENCAP %s", buffer); |
85 |
|
86 |
if (match(parv[1], me.name)) |
87 |
return; |
88 |
|
89 |
if ((mptr = find_command(parv[2])) == NULL) |
90 |
return; |
91 |
|
92 |
#ifdef NOT_USED_YET |
93 |
paramcount = mptr->parameters; |
94 |
mpara = mptr->maxpara; |
95 |
#endif |
96 |
mptr->bytes += strlen(buffer); |
97 |
|
98 |
/* |
99 |
* Yes this is an ugly hack, but it is quicker than copying the |
100 |
* entire array again. |
101 |
* |
102 |
* Note: this hack wouldn't be needed if parv[0] were set to the |
103 |
* command name, rather than being derived from the prefix, as |
104 |
* it should have been from the beginning. |
105 |
*/ |
106 |
ptr = parv[0]; |
107 |
parv += 2; |
108 |
parc -= 2; |
109 |
parv[0] = ptr; |
110 |
|
111 |
if ((handler = mptr->handlers[ENCAP_HANDLER])) |
112 |
(*handler)(client_p, source_p, parc, parv); |
113 |
} |
114 |
|
115 |
static struct Message encap_msgtab = |
116 |
{ |
117 |
"ENCAP", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
118 |
{ m_ignore, m_ignore, ms_encap, m_ignore, m_ignore, m_ignore } |
119 |
}; |
120 |
|
121 |
static void |
122 |
module_init(void) |
123 |
{ |
124 |
mod_add_cmd(&encap_msgtab); |
125 |
add_capability("ENCAP", CAP_ENCAP, 1); |
126 |
} |
127 |
|
128 |
static void |
129 |
module_exit(void) |
130 |
{ |
131 |
mod_del_cmd(&encap_msgtab); |
132 |
delete_capability("ENCAP"); |
133 |
} |
134 |
|
135 |
struct module module_entry = |
136 |
{ |
137 |
.node = { NULL, NULL, NULL }, |
138 |
.name = NULL, |
139 |
.version = "$Revision$", |
140 |
.handle = NULL, |
141 |
.modinit = module_init, |
142 |
.modexit = module_exit, |
143 |
.flags = 0 |
144 |
}; |