]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_capab.c
Do not install ban .conf files (like kline.conf, rsv.conf, etc) as they aren't used...
[irc/rqf/shadowircd.git] / modules / m_capab.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
fde16193 3 * m_capab.c: Negotiates capabilities with a remote server.
212380e3 4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
212380e3 24 */
25
26#include "stdinc.h"
27#include "client.h"
13ae2f4b 28#include "match.h"
212380e3 29#include "s_serv.h"
30#include "s_conf.h"
31#include "msg.h"
32#include "parse.h"
33#include "modules.h"
34
35static int mr_capab(struct Client *, struct Client *, int, const char **);
36static int me_gcap(struct Client *, struct Client *, int, const char **);
37
38struct Message capab_msgtab = {
39 "CAPAB", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
40 {{mr_capab, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore}
41};
42struct Message gcap_msgtab = {
43 "GCAP", 0, 0, 0, MFLG_SLOW,
44 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_gcap, 2}, mg_ignore}
45};
46
47mapi_clist_av1 capab_clist[] = { &capab_msgtab, &gcap_msgtab, NULL };
48DECLARE_MODULE_AV1(capab, NULL, NULL, capab_clist, NULL, NULL, "$Revision: 1295 $");
49
50/*
51 * mr_capab - CAPAB message handler
212380e3 52 * parv[1] = space-separated list of capabilities
53 *
54 */
55static int
56mr_capab(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
57{
58 struct Capability *cap;
59 int i;
60 char *p;
61 char *s;
62
63 /* ummm, this shouldn't happen. Could argue this should be logged etc. */
64 if(client_p->localClient == NULL)
65 return 0;
66
67 if(client_p->user)
68 return 0;
69
70 /* CAP_TS6 is set in PASS, so is valid.. */
71 if((client_p->localClient->caps & ~CAP_TS6) != 0)
72 {
73 exit_client(client_p, client_p, client_p, "CAPAB received twice");
74 return 0;
75 }
76 else
77 client_p->localClient->caps |= CAP_CAP;
78
90a3c35b 79 rb_free(client_p->localClient->fullcaps);
bba1d5ba 80 client_p->localClient->fullcaps = rb_strdup(parv[1]);
212380e3 81
82 for (i = 1; i < parc; i++)
83 {
84 char *t = LOCAL_COPY(parv[i]);
dcbd1d07 85 for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
212380e3 86 {
87 for (cap = captab; cap->name; cap++)
88 {
89 if(!irccmp(cap->name, s))
90 {
91 client_p->localClient->caps |= cap->cap;
92 break;
93 }
94 }
95 }
96 }
97
98 return 0;
99}
100
101static int
102me_gcap(struct Client *client_p, struct Client *source_p,
103 int parc, const char *parv[])
104{
105 struct Capability *cap;
106 char *t = LOCAL_COPY(parv[1]);
107 char *s;
108 char *p;
109
110 if(!IsServer(source_p))
111 return 0;
112
113 /* already had GCAPAB?! */
114 if(!EmptyString(source_p->serv->fullcaps))
b37edd51
WP
115 {
116 source_p->serv->caps = 0;
90a3c35b 117 rb_free(source_p->serv->fullcaps);
b37edd51 118 }
212380e3 119
62d28946 120 source_p->serv->fullcaps = rb_strdup(parv[1]);
212380e3 121
dcbd1d07 122 for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
212380e3 123 {
124 for (cap = captab; cap->name; cap++)
125 {
126 if(!irccmp(cap->name, s))
127 {
128 source_p->serv->caps |= cap->cap;
129 break;
130 }
131 }
132 }
133
134 return 0;
135}