]>
Commit | Line | Data |
---|---|---|
1 | /* modules/m_encap.c | |
2 | * Copyright (C) 2003-2005 ircd-ratbox development team | |
3 | * Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk> | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are | |
7 | * met: | |
8 | * | |
9 | * 1.Redistributions of source code must retain the above copyright notice, | |
10 | * this list of conditions and the following disclaimer. | |
11 | * 2.Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * 3.The name of the author may not be used to endorse or promote products | |
15 | * derived from this software without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 | * POSSIBILITY OF SUCH DAMAGE. | |
28 | * | |
29 | * $Id: m_encap.c 254 2005-09-21 23:35:12Z nenolod $ | |
30 | */ | |
31 | ||
32 | #include "stdinc.h" | |
33 | #include "tools.h" | |
34 | #include "send.h" | |
35 | #include "channel.h" | |
36 | #include "client.h" | |
37 | #include "common.h" | |
38 | #include "config.h" | |
39 | #include "ircd.h" | |
40 | #include "numeric.h" | |
41 | #include "memory.h" | |
42 | #include "s_serv.h" | |
43 | #include "hash.h" | |
44 | #include "msg.h" | |
45 | #include "parse.h" | |
46 | #include "modules.h" | |
47 | #include "sprintf_irc.h" | |
48 | ||
49 | static int ms_encap(struct Client *client_p, struct Client *source_p, | |
50 | int parc, const char *parv[]); | |
51 | ||
52 | struct Message encap_msgtab = { | |
53 | "ENCAP", 0, 0, 0, MFLG_SLOW, | |
54 | {mg_ignore, mg_ignore, {ms_encap, 3}, {ms_encap, 3}, mg_ignore, mg_ignore} | |
55 | }; | |
56 | ||
57 | mapi_clist_av1 encap_clist[] = { &encap_msgtab, NULL }; | |
58 | DECLARE_MODULE_AV1(encap, NULL, NULL, encap_clist, NULL, NULL, "$Revision: 254 $"); | |
59 | ||
60 | /* ms_encap() | |
61 | * | |
62 | * parv[1] - destination server | |
63 | * parv[2] - subcommand | |
64 | * parv[3] - parameters | |
65 | */ | |
66 | static int | |
67 | ms_encap(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
68 | { | |
69 | char buffer[BUFSIZE]; | |
70 | char *ptr; | |
71 | int cur_len = 0; | |
72 | int len; | |
73 | int i; | |
74 | ||
75 | ptr = buffer; | |
76 | ||
77 | for(i = 1; i < parc - 1; i++) | |
78 | { | |
79 | len = strlen(parv[i]) + 1; | |
80 | ||
81 | /* ugh, not even at the last parameter, just bail --fl */ | |
82 | if((size_t)(cur_len + len) >= sizeof(buffer)) | |
83 | return 0; | |
84 | ||
85 | ircsnprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]); | |
86 | cur_len += len; | |
87 | ptr += len; | |
88 | } | |
89 | ||
90 | len = strlen(parv[i]); | |
91 | ||
92 | /* if its a command without parameters, dont prepend a ':' */ | |
93 | if(parc == 3) | |
94 | ircsnprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]); | |
95 | else | |
96 | ircsnprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc-1]); | |
97 | ||
98 | /* add a trailing \0 if it was too long */ | |
99 | if((cur_len + len) >= BUFSIZE) | |
100 | buffer[BUFSIZE-1] = '\0'; | |
101 | ||
102 | sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS, | |
103 | "ENCAP %s", buffer); | |
104 | ||
105 | /* if it matches us, find a matching handler and call it */ | |
106 | if(match(parv[1], me.name)) | |
107 | handle_encap(client_p, source_p, parv[2], parc - 2, parv + 2); | |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
112 |