2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
2009-04-20 16:36:55 +02:00
|
|
|
* m_capab.c: Negotiates capabilities with a remote server.
|
2007-01-25 07:40:21 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char capab_desc[] = "Provides the commands used for server-to-server capability negotiation";
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void mr_capab(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void me_gcap(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message capab_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"CAPAB", 0, 0, 0, 0,
|
2012-12-31 20:13:05 +01:00
|
|
|
{{mr_capab, 2}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore}
|
2007-01-25 07:40:21 +01:00
|
|
|
};
|
|
|
|
struct Message gcap_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"GCAP", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_gcap, 2}, mg_ignore}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 capab_clist[] = { &capab_msgtab, &gcap_msgtab, NULL };
|
2016-03-07 08:52:16 +01:00
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(capab, NULL, NULL, capab_clist, NULL, NULL, NULL, NULL, capab_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mr_capab - CAPAB message handler
|
|
|
|
* parv[1] = space-separated list of capabilities
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
mr_capab(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
/* ummm, this shouldn't happen. Could argue this should be logged etc. */
|
2016-08-23 02:37:07 +02:00
|
|
|
if(client.localClient == NULL)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if(client.user)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* CAP_TS6 is set in PASS, so is valid.. */
|
2016-08-23 02:37:07 +02:00
|
|
|
if((client.localClient->caps & ~CAP_TS6) != 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
exit_client(&client, &client, &client, "CAPAB received twice");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
2016-08-23 02:37:07 +02:00
|
|
|
client.localClient->caps |= CAP_CAP;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
rb_free(client.localClient->fullcaps);
|
|
|
|
client.localClient->fullcaps = rb_strdup(parv[1]);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
for (i = 1; i < parc; i++)
|
|
|
|
{
|
|
|
|
char *t = LOCAL_COPY(parv[i]);
|
2008-04-20 07:20:25 +02:00
|
|
|
for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
|
2016-08-23 02:37:07 +02:00
|
|
|
client.localClient->caps |= serv_capindex.get(s, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
me_gcap(struct MsgBuf *msgbuf_p, client::client &client, client::client &source,
|
2007-01-25 07:40:21 +01:00
|
|
|
int parc, const char *parv[])
|
|
|
|
{
|
|
|
|
char *t = LOCAL_COPY(parv[1]);
|
|
|
|
char *s;
|
|
|
|
char *p;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!is_server(source))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* already had GCAPAB?! */
|
2016-08-23 02:37:07 +02:00
|
|
|
if (fullcaps(serv(source)).size())
|
|
|
|
caps(serv(source)) = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
fullcaps(serv(source)) = parv[1];
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-20 07:20:25 +02:00
|
|
|
for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
|
2016-08-23 02:37:07 +02:00
|
|
|
caps(serv(source)) |= serv_capindex.get(s, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|