]> jfr.im git - solanum.git/blame - modules/m_encap.c
modules: Add AV2 description to m_xline
[solanum.git] / modules / m_encap.c
CommitLineData
212380e3
AC
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.
212380e3
AC
28 */
29
30#include "stdinc.h"
212380e3
AC
31#include "send.h"
32#include "channel.h"
33#include "client.h"
34#include "common.h"
35#include "config.h"
36#include "ircd.h"
37#include "numeric.h"
212380e3
AC
38#include "s_serv.h"
39#include "hash.h"
40#include "msg.h"
41#include "parse.h"
42#include "modules.h"
212380e3 43
428ca87b 44static int ms_encap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
212380e3
AC
45 int parc, const char *parv[]);
46
47struct Message encap_msgtab = {
7baa37a9 48 "ENCAP", 0, 0, 0, 0,
212380e3
AC
49 {mg_ignore, mg_ignore, {ms_encap, 3}, {ms_encap, 3}, mg_ignore, mg_ignore}
50};
51
52mapi_clist_av1 encap_clist[] = { &encap_msgtab, NULL };
105a4985 53DECLARE_MODULE_AV2(encap, NULL, NULL, encap_clist, NULL, NULL, NULL, NULL, NULL);
212380e3
AC
54
55/* ms_encap()
56 *
57 * parv[1] - destination server
58 * parv[2] - subcommand
59 * parv[3] - parameters
60 */
61static int
428ca87b 62ms_encap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
63{
64 char buffer[BUFSIZE];
65 char *ptr;
66 int cur_len = 0;
67 int len;
68 int i;
69
70 ptr = buffer;
55abcbb2 71
212380e3
AC
72 for(i = 1; i < parc - 1; i++)
73 {
74 len = strlen(parv[i]) + 1;
75
76 /* ugh, not even at the last parameter, just bail --fl */
77 if((size_t)(cur_len + len) >= sizeof(buffer))
78 return 0;
79
5203cba5 80 snprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]);
212380e3
AC
81 cur_len += len;
82 ptr += len;
83 }
84
85 len = strlen(parv[i]);
86
87 /* if its a command without parameters, dont prepend a ':' */
88 if(parc == 3)
5203cba5 89 snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]);
212380e3 90 else
5203cba5 91 snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc-1]);
212380e3
AC
92
93 /* add a trailing \0 if it was too long */
94 if((cur_len + len) >= BUFSIZE)
95 buffer[BUFSIZE-1] = '\0';
96
97 sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS,
98 "ENCAP %s", buffer);
99
100 /* if it matches us, find a matching handler and call it */
101 if(match(parv[1], me.name))
428ca87b 102 handle_encap(msgbuf_p, client_p, source_p, parv[2], parc - 2, parv + 2);
212380e3
AC
103
104 return 0;
105}