]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
c6240d79 | 3 | * m_capab.c: Negotiates capabilities with a remote server. |
212380e3 AC |
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 | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
26 | #include "client.h" | |
4562c604 | 27 | #include "match.h" |
212380e3 AC |
28 | #include "s_serv.h" |
29 | #include "s_conf.h" | |
30 | #include "msg.h" | |
31 | #include "parse.h" | |
32 | #include "modules.h" | |
33 | ||
eeabf33a EM |
34 | static const char capab_desc[] = "Provides the commands used for server-to-server capability negotiation"; |
35 | ||
3c7d6fcc EM |
36 | static void mr_capab(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
37 | static void me_gcap(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
38 | |
39 | struct Message capab_msgtab = { | |
7baa37a9 | 40 | "CAPAB", 0, 0, 0, 0, |
ac0707aa | 41 | {{mr_capab, 2}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} |
212380e3 AC |
42 | }; |
43 | struct Message gcap_msgtab = { | |
7baa37a9 | 44 | "GCAP", 0, 0, 0, 0, |
212380e3 AC |
45 | {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_gcap, 2}, mg_ignore} |
46 | }; | |
47 | ||
48 | mapi_clist_av1 capab_clist[] = { &capab_msgtab, &gcap_msgtab, NULL }; | |
5544da98 | 49 | |
5544da98 | 50 | DECLARE_MODULE_AV2(capab, NULL, NULL, capab_clist, NULL, NULL, NULL, NULL, capab_desc); |
212380e3 AC |
51 | |
52 | /* | |
53 | * mr_capab - CAPAB message handler | |
212380e3 | 54 | * parv[1] = space-separated list of capabilities |
212380e3 | 55 | */ |
3c7d6fcc | 56 | static void |
428ca87b | 57 | mr_capab(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 58 | { |
212380e3 AC |
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) | |
3c7d6fcc | 65 | return; |
212380e3 AC |
66 | |
67 | if(client_p->user) | |
3c7d6fcc | 68 | return; |
212380e3 AC |
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"); | |
3c7d6fcc | 74 | return; |
212380e3 AC |
75 | } |
76 | else | |
77 | client_p->localClient->caps |= CAP_CAP; | |
78 | ||
637c4932 | 79 | rb_free(client_p->localClient->fullcaps); |
2bc1d86c | 80 | client_p->localClient->fullcaps = rb_strdup(parv[1]); |
212380e3 AC |
81 | |
82 | for (i = 1; i < parc; i++) | |
83 | { | |
84 | char *t = LOCAL_COPY(parv[i]); | |
4a2651e5 | 85 | for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p)) |
63b9db96 | 86 | client_p->localClient->caps |= capability_get(serv_capindex, s, NULL); |
212380e3 | 87 | } |
212380e3 AC |
88 | } |
89 | ||
3c7d6fcc | 90 | static void |
428ca87b | 91 | me_gcap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, |
212380e3 AC |
92 | int parc, const char *parv[]) |
93 | { | |
212380e3 AC |
94 | char *t = LOCAL_COPY(parv[1]); |
95 | char *s; | |
96 | char *p; | |
97 | ||
98 | if(!IsServer(source_p)) | |
3c7d6fcc | 99 | return; |
212380e3 AC |
100 | |
101 | /* already had GCAPAB?! */ | |
102 | if(!EmptyString(source_p->serv->fullcaps)) | |
1f112a04 AC |
103 | { |
104 | source_p->serv->caps = 0; | |
637c4932 | 105 | rb_free(source_p->serv->fullcaps); |
1f112a04 | 106 | } |
212380e3 | 107 | |
47a03750 | 108 | source_p->serv->fullcaps = rb_strdup(parv[1]); |
212380e3 | 109 | |
4a2651e5 | 110 | for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p)) |
63b9db96 | 111 | source_p->serv->caps |= capability_get(serv_capindex, s, NULL); |
212380e3 | 112 | } |