]> jfr.im git - solanum.git/blob - modules/m_capab.c
Remove $Id tags from everything.
[solanum.git] / modules / m_capab.c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_capab.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
25 #include "stdinc.h"
26 #include "client.h"
27 #include "match.h"
28 #include "s_serv.h"
29 #include "s_conf.h"
30 #include "msg.h"
31 #include "parse.h"
32 #include "modules.h"
33
34 static int mr_capab(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
35 static int me_gcap(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
36
37 struct Message capab_msgtab = {
38 "CAPAB", 0, 0, 0, 0,
39 {{mr_capab, 2}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore}
40 };
41 struct Message gcap_msgtab = {
42 "GCAP", 0, 0, 0, 0,
43 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_gcap, 2}, mg_ignore}
44 };
45
46 mapi_clist_av1 capab_clist[] = { &capab_msgtab, &gcap_msgtab, NULL };
47 DECLARE_MODULE_AV1(capab, NULL, NULL, capab_clist, NULL, NULL, "$Revision: 1295 $");
48
49 /*
50 * mr_capab - CAPAB message handler
51 * parv[1] = space-separated list of capabilities
52 */
53 static int
54 mr_capab(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
55 {
56 int i;
57 char *p;
58 char *s;
59
60 /* ummm, this shouldn't happen. Could argue this should be logged etc. */
61 if(client_p->localClient == NULL)
62 return 0;
63
64 if(client_p->user)
65 return 0;
66
67 /* CAP_TS6 is set in PASS, so is valid.. */
68 if((client_p->localClient->caps & ~CAP_TS6) != 0)
69 {
70 exit_client(client_p, client_p, client_p, "CAPAB received twice");
71 return 0;
72 }
73 else
74 client_p->localClient->caps |= CAP_CAP;
75
76 rb_free(client_p->localClient->fullcaps);
77 client_p->localClient->fullcaps = rb_strdup(parv[1]);
78
79 for (i = 1; i < parc; i++)
80 {
81 char *t = LOCAL_COPY(parv[i]);
82 for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
83 client_p->localClient->caps |= capability_get(serv_capindex, s, NULL);
84 }
85
86 return 0;
87 }
88
89 static int
90 me_gcap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
91 int parc, const char *parv[])
92 {
93 char *t = LOCAL_COPY(parv[1]);
94 char *s;
95 char *p;
96
97 if(!IsServer(source_p))
98 return 0;
99
100 /* already had GCAPAB?! */
101 if(!EmptyString(source_p->serv->fullcaps))
102 {
103 source_p->serv->caps = 0;
104 rb_free(source_p->serv->fullcaps);
105 }
106
107 source_p->serv->fullcaps = rb_strdup(parv[1]);
108
109 for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
110 source_p->serv->caps |= capability_get(serv_capindex, s, NULL);
111
112 return 0;
113 }