fixed ssl.c bug when ssl backend returns IO_BLOCKED but IO engine doesn't get informe...
[ircu2.10.12-pk.git] / ircd / m_uninvite.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_uninvite.c
3  * Written by Philipp Kreil.
4  *
5  * See file AUTHORS in IRC package for additional names of
6  * the programmers.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 1, or (at your option)
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */
23
24 /*
25  * m_functions execute protocol messages on this server:
26  *
27  *    cptr    is always NON-NULL, pointing to a *LOCAL* client
28  *            structure (with an open socket connected!). This
29  *            identifies the physical socket where the message
30  *            originated (or which caused the m_function to be
31  *            executed--some m_functions may call others...).
32  *
33  *    sptr    is the source of the message, defined by the
34  *            prefix part of the message if present. If not
35  *            or prefix not found, then sptr==cptr.
36  *
37  *            (!IsServer(cptr)) => (cptr == sptr), because
38  *            prefixes are taken *only* from servers...
39  *
40  *            (IsServer(cptr))
41  *                    (sptr == cptr) => the message didn't
42  *                    have the prefix.
43  *
44  *                    (sptr != cptr && IsServer(sptr) means
45  *                    the prefix specified servername. (?)
46  *
47  *                    (sptr != cptr && !IsServer(sptr) means
48  *                    that message originated from a remote
49  *                    user (not local).
50  *
51  *            combining
52  *
53  *            (!IsServer(sptr)) means that, sptr can safely
54  *            taken as defining the target structure of the
55  *            message in this server.
56  *
57  *    *Always* true (if 'parse' and others are working correct):
58  *
59  *    1)      sptr->from == cptr  (note: cptr->from == cptr)
60  *
61  *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
62  *            *cannot* be a local connection, unless it's
63  *            actually cptr!). [MyConnect(x) should probably
64  *            be defined as (x == x->from) --msa ]
65  *
66  *    parc    number of variable parameter strings (if zero,
67  *            parv is allowed to be NULL)
68  *
69  *    parv    a NULL terminated list of parameter pointers,
70  *
71  *                    parv[0], sender (prefix string), if not present
72  *                            this points to an empty string.
73  *                    parv[1]...parv[parc-1]
74  *                            pointers to additional parameters
75  *                    parv[parc] == NULL, *always*
76  *
77  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
78  *                    non-NULL pointers.
79  */
80 #include "config.h"
81
82 #include "channel.h"
83 #include "client.h"
84 #include "hash.h"
85 #include "ircd.h"
86 #include "ircd_features.h"
87 #include "ircd_log.h"
88 #include "ircd_reply.h"
89 #include "ircd_string.h"
90 #include "list.h"
91 #include "msg.h"
92 #include "numeric.h"
93 #include "numnicks.h"
94 #include "s_user.h"
95 #include "send.h"
96 #include "struct.h"
97
98 /* #include <assert.h> -- Now using assert in ircd_log.h */
99
100 /*
101  * m_uninvite - generic message handler
102  *
103  *   parv[0] - sender prefix
104  *   parv[1] - user to uninvite
105  *   parv[2] - channel name
106  *
107  */
108 int m_uninvite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
109 {
110   struct Client *acptr;
111   struct Channel *chptr;
112   
113   if (parc < 3 || EmptyString(parv[2]))
114     return need_more_params(sptr, "UNINVITE");
115
116   if (!(acptr = FindUser(parv[1]))) {
117     send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
118     return 0;
119   }
120
121   if (!IsChannelName(parv[2])
122       || !strIsIrcCh(parv[2])
123       || !(chptr = FindChannel(parv[2]))) {
124     send_reply(sptr, ERR_NOSUCHCHANNEL, parv[2]);
125     return 0;
126   }
127
128   if (!find_channel_member(sptr, chptr)) {
129     send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
130     return 0;
131   }
132
133   if (find_channel_member(acptr, chptr)) {
134     send_reply(sptr, ERR_USERONCHANNEL, cli_name(acptr), chptr->chname);
135     return 0;
136   }
137
138   if (!is_chan_op(sptr, chptr) && !is_halfop(sptr, chptr)) {
139     send_reply(sptr, ERR_CHANOPRIVSNEEDED, chptr->chname);
140     return 0;
141   }
142
143   if(!IsInvited(acptr, chptr)) {
144     send_reply(sptr, ERR_USERNOTINVITED, cli_name(acptr), chptr->chname);
145     return 0;
146   }
147
148   /* If we get here, it was a VALID and meaningful UNINVITE */
149
150   send_reply(sptr, RPL_UNINVITE, cli_name(acptr), chptr->chname);
151
152   if (MyConnect(acptr)) {
153     del_invite(acptr, chptr);
154     sendcmdto_one(sptr, CMD_UNINVITE, acptr, "%s %H", cli_name(acptr), chptr);
155   } else if (!IsLocalChannel(chptr->chname)) {
156     sendcmdto_one(sptr, CMD_UNINVITE, acptr, "%s %H %Tu", cli_name(acptr), chptr, chptr->creationtime);
157   }
158
159   return 0;
160 }
161
162 /*
163  * ms_uninvite - server message handler
164  *
165  *   parv[0] - sender prefix
166  *   parv[1] - user to invite
167  *   parv[2] - channel name
168  *   parv[3] - (optional) channel timestamp
169  *
170  */
171 int ms_uninvite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
172 {
173   struct Client *acptr;
174   struct Channel *chptr;
175   time_t uninvite_ts;
176   
177   if (IsServer(sptr)) {
178     /*
179      * this will blow up if we get an uninvite from a server
180      * we look for channel membership in sptr below. 
181      */
182     return protocol_violation(sptr,"Server attempting to uninvite");
183   }
184   if (parc < 3 || EmptyString(parv[2])) {
185     /*
186      * should have been handled upstream, ignore it.
187      */
188     protocol_violation(sptr,"Too few arguments to uninvite");
189     return need_more_params(sptr,"UNINVITE");
190   }
191   if (!IsGlobalChannel(parv[2])) {
192     /*
193      * should not be sent
194      */
195     return protocol_violation(sptr, "Uninvite from a non-standard channel %s",parv[2]);
196   }
197   if (!(acptr = FindUser(parv[1]))) {
198     send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
199     return 0;
200   }
201
202   if (!(chptr = FindChannel(parv[2]))) {
203     send_reply(sptr, ERR_NOSUCHCHANNEL, parv[2]);
204     return 0;
205   }
206
207   if (parc > 3) {
208     uninvite_ts = atoi(parv[3]);
209     if (uninvite_ts > chptr->creationtime)
210       return 0;
211   } else if (IsBurstOrBurstAck(cptr))
212     return 0;
213
214   if (!IsChannelService(sptr) && !find_channel_member(sptr, chptr)) {
215     send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
216     return 0;
217   }
218
219   if (find_channel_member(acptr, chptr)) {
220     send_reply(sptr, ERR_USERONCHANNEL, cli_name(acptr), chptr->chname);
221     return 0;
222   }
223
224   if(!IsInvited(acptr, chptr)) {
225     send_reply(sptr, ERR_USERNOTINVITED, cli_name(acptr), chptr->chname);
226     return 0;
227   }
228
229   if (MyConnect(acptr)) {
230     del_invite(acptr, chptr);
231     sendcmdto_one(sptr, CMD_UNINVITE, acptr, "%s %H", cli_name(acptr), chptr);
232   } else {
233     sendcmdto_one(sptr, CMD_UNINVITE, acptr, "%s %H %Tu", cli_name(acptr), chptr,
234                   chptr->creationtime);
235   }
236
237   return 0;
238 }