1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_encap.c: encapsulated command propagation and parsing |
4 |
* |
5 |
* Copyright (C) 2003 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "client.h" |
27 |
#include "parse.h" |
28 |
#include "s_serv.h" |
29 |
#include "send.h" |
30 |
#include "modules.h" |
31 |
#include "irc_string.h" |
32 |
|
33 |
|
34 |
/* |
35 |
* ms_encap() |
36 |
* |
37 |
* inputs - destination server, subcommand, parameters |
38 |
* output - none |
39 |
* side effects - propagates subcommand to locally connected servers |
40 |
*/ |
41 |
static void |
42 |
ms_encap(struct Client *client_p, struct Client *source_p, |
43 |
int parc, char *parv[]) |
44 |
{ |
45 |
char buffer[IRCD_BUFSIZE], *ptr = buffer; |
46 |
unsigned int cur_len = 0, len, i; |
47 |
#ifdef NOT_USED_YET |
48 |
int paramcount, mpara = 0; |
49 |
#endif |
50 |
struct Message *mptr = NULL; |
51 |
MessageHandler handler = 0; |
52 |
|
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; |
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]); |
66 |
|
67 |
/* |
68 |
* if the final parameter crosses our buffer size, should we bail, |
69 |
* like the rest, or should we truncate? ratbox seems to think truncate, |
70 |
* so i'll do that for now until i can talk to lee. -bill |
71 |
*/ |
72 |
|
73 |
if (parc == 3) |
74 |
snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]); |
75 |
else |
76 |
snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc - 1]); |
77 |
|
78 |
if ((cur_len + len) >= sizeof(buffer)) |
79 |
buffer[sizeof(buffer) - 1] = '\0'; |
80 |
|
81 |
sendto_match_servs(source_p, parv[1], CAP_ENCAP, |
82 |
"ENCAP %s", buffer); |
83 |
|
84 |
if (match(parv[1], me.name)) |
85 |
return; |
86 |
|
87 |
if ((mptr = find_command(parv[2])) == NULL) |
88 |
return; |
89 |
|
90 |
#ifdef NOT_USED_YET |
91 |
paramcount = mptr->parameters; |
92 |
mpara = mptr->maxpara; |
93 |
#endif |
94 |
mptr->bytes += strlen(buffer); |
95 |
|
96 |
/* |
97 |
* yes this is an ugly hack, but it is quicker than copying the entire array again |
98 |
* note: this hack wouldnt be needed if parv[0] were set to the command name, rather |
99 |
* than being derived from the prefix, as it should have been from the beginning. |
100 |
*/ |
101 |
ptr = parv[0]; |
102 |
parv += 2; |
103 |
parc -= 2; |
104 |
parv[0] = ptr; |
105 |
|
106 |
if ((handler = mptr->handlers[ENCAP_HANDLER])) |
107 |
(*handler)(client_p, source_p, parc, parv); |
108 |
} |
109 |
|
110 |
static struct Message encap_msgtab = { |
111 |
"ENCAP", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
112 |
{m_ignore, m_ignore, ms_encap, m_ignore, m_ignore, m_ignore} |
113 |
}; |
114 |
|
115 |
static void |
116 |
module_init(void) |
117 |
{ |
118 |
mod_add_cmd(&encap_msgtab); |
119 |
add_capability("ENCAP", CAP_ENCAP, 1); |
120 |
} |
121 |
|
122 |
static void |
123 |
module_exit(void) |
124 |
{ |
125 |
mod_del_cmd(&encap_msgtab); |
126 |
delete_capability("ENCAP"); |
127 |
} |
128 |
|
129 |
struct module module_entry = { |
130 |
.node = { NULL, NULL, NULL }, |
131 |
.name = NULL, |
132 |
.version = "$Revision$", |
133 |
.handle = NULL, |
134 |
.modinit = module_init, |
135 |
.modexit = module_exit, |
136 |
.flags = 0 |
137 |
}; |