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 "handlers.h" |
27 |
#include "client.h" |
28 |
#include "msg.h" |
29 |
#include "parse.h" |
30 |
#include "sprintf_irc.h" |
31 |
#include "s_serv.h" |
32 |
#include "send.h" |
33 |
#include "modules.h" |
34 |
#include "irc_string.h" |
35 |
|
36 |
static void ms_encap(struct Client *, struct Client *, int, char *[]); |
37 |
|
38 |
struct Message encap_msgtab = { |
39 |
"ENCAP", 0, 0, 3, 0, MFLG_SLOW, 0, |
40 |
{m_ignore, m_ignore, ms_encap, m_ignore, m_ignore, m_ignore} |
41 |
}; |
42 |
|
43 |
#ifndef STATIC_MODULES |
44 |
void |
45 |
_modinit(void) |
46 |
{ |
47 |
mod_add_cmd(&encap_msgtab); |
48 |
add_capability("ENCAP", CAP_ENCAP, 1); |
49 |
} |
50 |
|
51 |
void |
52 |
_moddeinit(void) |
53 |
{ |
54 |
mod_del_cmd(&encap_msgtab); |
55 |
delete_capability("ENCAP"); |
56 |
} |
57 |
const char *_version = "$Revision$"; |
58 |
#endif |
59 |
|
60 |
/* |
61 |
* ms_encap() |
62 |
* |
63 |
* inputs - destination server, subcommand, parameters |
64 |
* output - none |
65 |
* side effects - propagates subcommand to locally connected servers |
66 |
*/ |
67 |
static void |
68 |
ms_encap(struct Client *client_p, struct Client *source_p, |
69 |
int parc, char *parv[]) |
70 |
{ |
71 |
char buffer[IRCD_BUFSIZE], *ptr = buffer; |
72 |
unsigned int cur_len = 0, len, i; |
73 |
int paramcount, mpara = 0; |
74 |
struct Message *mptr = NULL; |
75 |
MessageHandler handler = 0; |
76 |
|
77 |
for (i = 1; i < (unsigned int)parc - 1; i++) |
78 |
{ |
79 |
len = strlen(parv[i]) + 1; |
80 |
|
81 |
if ((cur_len + len) >= sizeof(buffer)) |
82 |
return; |
83 |
|
84 |
ircsprintf(ptr, "%s ", parv[i]); |
85 |
cur_len += len; |
86 |
ptr += len; |
87 |
} |
88 |
|
89 |
len = strlen(parv[i]); |
90 |
|
91 |
/* |
92 |
* if the final parameter crosses our buffer size, should we bail, |
93 |
* like the rest, or should we truncate? ratbox seems to think truncate, |
94 |
* so i'll do that for now until i can talk to lee. -bill |
95 |
*/ |
96 |
|
97 |
if (parc == 3) |
98 |
ircsprintf(ptr, "%s", parv[2]); |
99 |
else |
100 |
ircsprintf(ptr, ":%s", parv[parc-1]); |
101 |
|
102 |
if ((cur_len + len) >= sizeof(buffer)) |
103 |
buffer[sizeof(buffer)-1] = '\0'; |
104 |
|
105 |
sendto_match_servs(source_p, parv[1], CAP_ENCAP, |
106 |
"ENCAP %s", buffer); |
107 |
|
108 |
if (!match(parv[1], me.name)) |
109 |
return; |
110 |
|
111 |
if ((mptr = find_command(parv[2])) == NULL) |
112 |
return; |
113 |
|
114 |
paramcount = mptr->parameters; |
115 |
mpara = mptr->maxpara; |
116 |
|
117 |
mptr->bytes += strlen(buffer); |
118 |
|
119 |
/* |
120 |
* yes this is an ugly hack, but it is quicker than copying the entire array again |
121 |
* note: this hack wouldnt be needed if parv[0] were set to the command name, rather |
122 |
* than being derived from the prefix, as it should have been from the beginning. |
123 |
*/ |
124 |
ptr = parv[0]; |
125 |
parv += 2; |
126 |
parc -= 2; |
127 |
parv[0] = ptr; |
128 |
|
129 |
if ((handler = mptr->handlers[ENCAP_HANDLER]) == NULL) |
130 |
return; |
131 |
|
132 |
(*handler)(client_p, source_p, parc, parv); |
133 |
} |