]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_capab.c
Some fixes to .depend generation.
[irc/rqf/shadowircd.git] / modules / m_capab.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_away.c: Negotiates capabilities with a remote server.
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 *
24 * $Id: m_capab.c 1295 2006-05-08 13:05:25Z nenolod $
25 */
26
27#include "stdinc.h"
28#include "client.h"
13ae2f4b 29#include "match.h"
212380e3 30#include "s_serv.h"
31#include "s_conf.h"
32#include "msg.h"
33#include "parse.h"
34#include "modules.h"
35
36static int mr_capab(struct Client *, struct Client *, int, const char **);
37static int me_gcap(struct Client *, struct Client *, int, const char **);
38
39struct Message capab_msgtab = {
40 "CAPAB", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
41 {{mr_capab, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore}
42};
43struct Message gcap_msgtab = {
44 "GCAP", 0, 0, 0, MFLG_SLOW,
45 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_gcap, 2}, mg_ignore}
46};
47
48mapi_clist_av1 capab_clist[] = { &capab_msgtab, &gcap_msgtab, NULL };
49DECLARE_MODULE_AV1(capab, NULL, NULL, capab_clist, NULL, NULL, "$Revision: 1295 $");
50
51/*
52 * mr_capab - CAPAB message handler
53 * parv[0] = sender prefix
54 * parv[1] = space-separated list of capabilities
55 *
56 */
57static int
58mr_capab(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
59{
60 struct Capability *cap;
61 int i;
62 char *p;
63 char *s;
64
65 /* ummm, this shouldn't happen. Could argue this should be logged etc. */
66 if(client_p->localClient == NULL)
67 return 0;
68
69 if(client_p->user)
70 return 0;
71
72 /* CAP_TS6 is set in PASS, so is valid.. */
73 if((client_p->localClient->caps & ~CAP_TS6) != 0)
74 {
75 exit_client(client_p, client_p, client_p, "CAPAB received twice");
76 return 0;
77 }
78 else
79 client_p->localClient->caps |= CAP_CAP;
80
90a3c35b 81 rb_free(client_p->localClient->fullcaps);
bba1d5ba 82 client_p->localClient->fullcaps = rb_strdup(parv[1]);
212380e3 83
84 for (i = 1; i < parc; i++)
85 {
86 char *t = LOCAL_COPY(parv[i]);
dcbd1d07 87 for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
212380e3 88 {
89 for (cap = captab; cap->name; cap++)
90 {
91 if(!irccmp(cap->name, s))
92 {
93 client_p->localClient->caps |= cap->cap;
94 break;
95 }
96 }
97 }
98 }
99
100 return 0;
101}
102
103static int
104me_gcap(struct Client *client_p, struct Client *source_p,
105 int parc, const char *parv[])
106{
107 struct Capability *cap;
108 char *t = LOCAL_COPY(parv[1]);
109 char *s;
110 char *p;
111
112 if(!IsServer(source_p))
113 return 0;
114
115 /* already had GCAPAB?! */
116 if(!EmptyString(source_p->serv->fullcaps))
b37edd51
WP
117 {
118 source_p->serv->caps = 0;
90a3c35b 119 rb_free(source_p->serv->fullcaps);
b37edd51 120 }
212380e3 121
62d28946 122 source_p->serv->fullcaps = rb_strdup(parv[1]);
212380e3 123
dcbd1d07 124 for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
212380e3 125 {
126 for (cap = captab; cap->name; cap++)
127 {
128 if(!irccmp(cap->name, s))
129 {
130 source_p->serv->caps |= cap->cap;
131 break;
132 }
133 }
134 }
135
136 return 0;
137}