2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
2009-04-20 14:36:55 +00:00
|
|
|
* m_capab.c: Negotiates capabilities with a remote server.
|
2007-01-25 06:40:21 +00: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
|
|
|
|
*
|
|
|
|
* $Id: m_capab.c 1295 2006-05-08 13:05:25Z nenolod $
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "client.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "s_serv.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "modules.h"
|
|
|
|
|
2016-02-11 02:54:17 +00:00
|
|
|
static int mr_capab(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static int me_gcap(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
struct Message capab_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"CAPAB", 0, 0, 0, 0,
|
2012-12-31 19:13:05 +00:00
|
|
|
{{mr_capab, 2}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore}
|
2007-01-25 06:40:21 +00:00
|
|
|
};
|
|
|
|
struct Message gcap_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"GCAP", 0, 0, 0, 0,
|
2007-01-25 06:40:21 +00:00
|
|
|
{mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_gcap, 2}, mg_ignore}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 capab_clist[] = { &capab_msgtab, &gcap_msgtab, NULL };
|
|
|
|
DECLARE_MODULE_AV1(capab, NULL, NULL, capab_clist, NULL, NULL, "$Revision: 1295 $");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mr_capab - CAPAB message handler
|
|
|
|
* parv[1] = space-separated list of capabilities
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
mr_capab(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
/* ummm, this shouldn't happen. Could argue this should be logged etc. */
|
|
|
|
if(client_p->localClient == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(client_p->user)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* CAP_TS6 is set in PASS, so is valid.. */
|
|
|
|
if((client_p->localClient->caps & ~CAP_TS6) != 0)
|
|
|
|
{
|
|
|
|
exit_client(client_p, client_p, client_p, "CAPAB received twice");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
client_p->localClient->caps |= CAP_CAP;
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_free(client_p->localClient->fullcaps);
|
2008-04-01 23:09:21 +00:00
|
|
|
client_p->localClient->fullcaps = rb_strdup(parv[1]);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
for (i = 1; i < parc; i++)
|
|
|
|
{
|
|
|
|
char *t = LOCAL_COPY(parv[i]);
|
2008-04-20 05:20:25 +00:00
|
|
|
for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
|
2016-02-27 05:55:43 +00:00
|
|
|
client_p->localClient->caps |= capability_get(serv_capindex, s, NULL);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
me_gcap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 06:40:21 +00:00
|
|
|
int parc, const char *parv[])
|
|
|
|
{
|
|
|
|
char *t = LOCAL_COPY(parv[1]);
|
|
|
|
char *s;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if(!IsServer(source_p))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* already had GCAPAB?! */
|
|
|
|
if(!EmptyString(source_p->serv->fullcaps))
|
2008-04-01 16:45:46 +00:00
|
|
|
{
|
|
|
|
source_p->serv->caps = 0;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_free(source_p->serv->fullcaps);
|
2008-04-01 16:45:46 +00:00
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 23:26:34 +00:00
|
|
|
source_p->serv->fullcaps = rb_strdup(parv[1]);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-20 05:20:25 +00:00
|
|
|
for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
|
2016-02-27 05:55:43 +00:00
|
|
|
source_p->serv->caps |= capability_get(serv_capindex, s, NULL);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|