2007-01-25 07:40:21 +01:00
|
|
|
/* modules/m_encap.c
|
|
|
|
* Copyright (C) 2003-2005 ircd-ratbox development team
|
|
|
|
* Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* 1.Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2.Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3.The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char encap_desc[] = "Provides the TS6 ENCAP facility";
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void ms_encap(struct MsgBuf *msgbuf_p, client::client &client, client::client &source,
|
2016-03-09 08:29:41 +01:00
|
|
|
int parc, const char *parv[]);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message encap_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"ENCAP", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_ignore, mg_ignore, {ms_encap, 3}, {ms_encap, 3}, mg_ignore, mg_ignore}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 encap_clist[] = { &encap_msgtab, NULL };
|
2016-03-07 08:59:08 +01:00
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(encap, NULL, NULL, encap_clist, NULL, NULL, NULL, NULL, encap_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* ms_encap()
|
|
|
|
*
|
|
|
|
* parv[1] - destination server
|
|
|
|
* parv[2] - subcommand
|
|
|
|
* parv[3] - parameters
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
ms_encap(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
char buffer[BUFSIZE];
|
|
|
|
char *ptr;
|
|
|
|
int cur_len = 0;
|
|
|
|
int len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ptr = buffer;
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
for(i = 1; i < parc - 1; i++)
|
|
|
|
{
|
|
|
|
len = strlen(parv[i]) + 1;
|
|
|
|
|
|
|
|
/* ugh, not even at the last parameter, just bail --fl */
|
|
|
|
if((size_t)(cur_len + len) >= sizeof(buffer))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]);
|
2007-01-25 07:40:21 +01:00
|
|
|
cur_len += len;
|
|
|
|
ptr += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen(parv[i]);
|
|
|
|
|
|
|
|
/* if its a command without parameters, dont prepend a ':' */
|
|
|
|
if(parc == 3)
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]);
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc-1]);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* add a trailing \0 if it was too long */
|
|
|
|
if((cur_len + len) >= BUFSIZE)
|
|
|
|
buffer[BUFSIZE-1] = '\0';
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_match_servs(&source, parv[1], CAP_ENCAP, NOCAPS,
|
2007-01-25 07:40:21 +01:00
|
|
|
"ENCAP %s", buffer);
|
|
|
|
|
|
|
|
/* if it matches us, find a matching handler and call it */
|
|
|
|
if(match(parv[1], me.name))
|
2016-08-23 02:37:07 +02:00
|
|
|
handle_encap(msgbuf_p, &client, &source, parv[2], parc - 2, parv + 2);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|