]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/channels.cpp
Merge pull request #1421 from B00mX0r/master+fix_extbans
[user/henk/code/inspircd.git] / src / channels.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2006, 2008 Oliver Lupton <oliverlupton@gmail.com>
7  *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
8  *   Copyright (C) 2003-2008 Craig Edwards <craigedwards@brainbox.cc>
9  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
10  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27 #include "listmode.h"
28
29 namespace
30 {
31         ChanModeReference ban(NULL, "ban");
32         ChanModeReference inviteonlymode(NULL, "inviteonly");
33         ChanModeReference keymode(NULL, "key");
34         ChanModeReference limitmode(NULL, "limit");
35 }
36
37 Channel::Channel(const std::string &cname, time_t ts)
38         : name(cname), age(ts), topicset(0)
39 {
40         if (!ServerInstance->chanlist.insert(std::make_pair(cname, this)).second)
41                 throw CoreException("Cannot create duplicate channel " + cname);
42 }
43
44 void Channel::SetMode(ModeHandler* mh, bool on)
45 {
46         modes[mh->GetId()] = on;
47 }
48
49 void Channel::SetTopic(User* u, const std::string& ntopic, time_t topicts, const std::string* setter)
50 {
51         // Send a TOPIC message to the channel only if the new topic text differs
52         if (this->topic != ntopic)
53         {
54                 this->topic = ntopic;
55                 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
56         }
57
58         // Always update setter and set time
59         if (!setter)
60                 setter = ServerInstance->Config->FullHostInTopic ? &u->GetFullHost() : &u->nick;
61         this->setby.assign(*setter, 0, ServerInstance->Config->Limits.GetMaxMask());
62         this->topicset = topicts;
63
64         FOREACH_MOD(OnPostTopicChange, (u, this, this->topic));
65 }
66
67 Membership* Channel::AddUser(User* user)
68 {
69         std::pair<MemberMap::iterator, bool> ret = userlist.insert(std::make_pair(user, insp::aligned_storage<Membership>()));
70         if (!ret.second)
71                 return NULL;
72
73         Membership* memb = new(ret.first->second) Membership(user, this);
74         return memb;
75 }
76
77 void Channel::DelUser(User* user)
78 {
79         MemberMap::iterator it = userlist.find(user);
80         if (it != userlist.end())
81                 DelUser(it);
82 }
83
84 void Channel::CheckDestroy()
85 {
86         if (!userlist.empty())
87                 return;
88
89         ModResult res;
90         FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
91         if (res == MOD_RES_DENY)
92                 return;
93
94         // If the channel isn't in chanlist then it is already in the cull list, don't add it again
95         chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
96         if ((iter == ServerInstance->chanlist.end()) || (iter->second != this))
97                 return;
98
99         FOREACH_MOD(OnChannelDelete, (this));
100         ServerInstance->chanlist.erase(iter);
101         ServerInstance->GlobalCulls.AddItem(this);
102 }
103
104 void Channel::DelUser(const MemberMap::iterator& membiter)
105 {
106         Membership* memb = membiter->second;
107         memb->cull();
108         memb->~Membership();
109         userlist.erase(membiter);
110
111         // If this channel became empty then it should be removed
112         CheckDestroy();
113 }
114
115 Membership* Channel::GetUser(User* user)
116 {
117         MemberMap::iterator i = userlist.find(user);
118         if (i == userlist.end())
119                 return NULL;
120         return i->second;
121 }
122
123 void Channel::SetDefaultModes()
124 {
125         ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "SetDefaultModes %s",
126                 ServerInstance->Config->DefaultModes.c_str());
127         irc::spacesepstream list(ServerInstance->Config->DefaultModes);
128         std::string modeseq;
129         std::string parameter;
130
131         list.GetToken(modeseq);
132
133         for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
134         {
135                 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
136                 if (mode)
137                 {
138                         if (mode->IsPrefixMode())
139                                 continue;
140
141                         if (mode->NeedsParam(true))
142                         {
143                                 list.GetToken(parameter);
144                                 // If the parameter begins with a ':' then it's invalid
145                                 if (parameter.c_str()[0] == ':')
146                                         continue;
147                         }
148                         else
149                                 parameter.clear();
150
151                         if ((mode->NeedsParam(true)) && (parameter.empty()))
152                                 continue;
153
154                         mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
155                 }
156         }
157 }
158
159 /*
160  * add a channel to a user, creating the record for it if needed and linking
161  * it to the user record
162  */
163 Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, const std::string& key)
164 {
165         if (user->registered != REG_ALL)
166         {
167                 ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join unregistered user " + user->uuid + " to channel " + cname);
168                 return NULL;
169         }
170
171         /*
172          * We don't restrict the number of channels that remote users or users that are override-joining may be in.
173          * We restrict local users to <connect:maxchans> channels.
174          * We restrict local operators to <oper:maxchans> channels.
175          * This is a lot more logical than how it was formerly. -- w00t
176          */
177         if (!override)
178         {
179                 unsigned int maxchans = user->GetClass()->maxchans;
180                 if (user->IsOper())
181                 {
182                         unsigned int opermaxchans = ConvToInt(user->oper->getConfig("maxchans"));
183                         // If not set, use 2.0's <channels:opers>, if that's not set either, use limit from CC
184                         if (!opermaxchans && user->HasPrivPermission("channels/high-join-limit"))
185                                 opermaxchans = ServerInstance->Config->OperMaxChans;
186                         if (opermaxchans)
187                                 maxchans = opermaxchans;
188                 }
189                 if (user->chans.size() >= maxchans)
190                 {
191                         user->WriteNumeric(ERR_TOOMANYCHANNELS, cname, "You are on too many channels");
192                         return NULL;
193                 }
194         }
195
196         // Crop channel name if it's too long
197         if (cname.length() > ServerInstance->Config->Limits.ChanMax)
198                 cname.resize(ServerInstance->Config->Limits.ChanMax);
199
200         Channel* chan = ServerInstance->FindChan(cname);
201         bool created_by_local = (chan == NULL); // Flag that will be passed to modules in the OnUserJoin() hook later
202         std::string privs; // Prefix mode(letter)s to give to the joining user
203
204         if (!chan)
205         {
206                 privs = ServerInstance->Config->DefaultModes.substr(0, ServerInstance->Config->DefaultModes.find(' '));
207
208                 if (override == false)
209                 {
210                         // Ask the modules whether they're ok with the join, pass NULL as Channel* as the channel is yet to be created
211                         ModResult MOD_RESULT;
212                         FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key));
213                         if (MOD_RESULT == MOD_RES_DENY)
214                                 return NULL; // A module wasn't happy with the join, abort
215                 }
216
217                 chan = new Channel(cname, ServerInstance->Time());
218                 // Set the default modes on the channel (<options:defaultmodes>)
219                 chan->SetDefaultModes();
220         }
221         else
222         {
223                 /* Already on the channel */
224                 if (chan->HasUser(user))
225                         return NULL;
226
227                 if (override == false)
228                 {
229                         ModResult MOD_RESULT;
230                         FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, chan, cname, privs, key));
231
232                         // A module explicitly denied the join and (hopefully) generated a message
233                         // describing the situation, so we may stop here without sending anything
234                         if (MOD_RESULT == MOD_RES_DENY)
235                                 return NULL;
236
237                         // If no module returned MOD_RES_DENY or MOD_RES_ALLOW (which is the case
238                         // most of the time) then proceed to check channel modes +k, +i, +l and bans,
239                         // in this order.
240                         // If a module explicitly allowed the join (by returning MOD_RES_ALLOW),
241                         // then this entire section is skipped
242                         if (MOD_RESULT == MOD_RES_PASSTHRU)
243                         {
244                                 std::string ckey = chan->GetModeParameter(keymode);
245                                 if (!ckey.empty())
246                                 {
247                                         FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key));
248                                         if (!MOD_RESULT.check(InspIRCd::TimingSafeCompare(ckey, key)))
249                                         {
250                                                 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
251                                                 user->WriteNumeric(ERR_BADCHANNELKEY, chan->name, "Cannot join channel (Incorrect channel key)");
252                                                 return NULL;
253                                         }
254                                 }
255
256                                 if (chan->IsModeSet(inviteonlymode))
257                                 {
258                                         FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan));
259                                         if (MOD_RESULT != MOD_RES_ALLOW)
260                                         {
261                                                 user->WriteNumeric(ERR_INVITEONLYCHAN, chan->name, "Cannot join channel (Invite only)");
262                                                 return NULL;
263                                         }
264                                 }
265
266                                 std::string limit = chan->GetModeParameter(limitmode);
267                                 if (!limit.empty())
268                                 {
269                                         FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan));
270                                         if (!MOD_RESULT.check(chan->GetUserCounter() < ConvToNum<size_t>(limit)))
271                                         {
272                                                 user->WriteNumeric(ERR_CHANNELISFULL, chan->name, "Cannot join channel (Channel is full)");
273                                                 return NULL;
274                                         }
275                                 }
276
277                                 if (chan->IsBanned(user))
278                                 {
279                                         user->WriteNumeric(ERR_BANNEDFROMCHAN, chan->name, "Cannot join channel (You're banned)");
280                                         return NULL;
281                                 }
282                         }
283                 }
284         }
285
286         // We figured that this join is allowed and also created the
287         // channel if it didn't exist before, now do the actual join
288         chan->ForceJoin(user, &privs, false, created_by_local);
289         return chan;
290 }
291
292 Membership* Channel::ForceJoin(User* user, const std::string* privs, bool bursting, bool created_by_local)
293 {
294         if (IS_SERVER(user))
295         {
296                 ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join server user " + user->uuid + " to channel " + this->name);
297                 return NULL;
298         }
299
300         Membership* memb = this->AddUser(user);
301         if (!memb)
302                 return NULL; // Already on the channel
303
304         user->chans.push_front(memb);
305
306         if (privs)
307         {
308                 // If the user was granted prefix modes (in the OnUserPreJoin hook, or he's a
309                 // remote user and his own server set the modes), then set them internally now
310                 for (std::string::const_iterator i = privs->begin(); i != privs->end(); ++i)
311                 {
312                         PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
313                         if (mh)
314                         {
315                                 std::string nick = user->nick;
316                                 // Set the mode on the user
317                                 mh->OnModeChange(ServerInstance->FakeClient, NULL, this, nick, true);
318                         }
319                 }
320         }
321
322         // Tell modules about this join, they have the chance now to populate except_list with users we won't send the JOIN (and possibly MODE) to
323         CUList except_list;
324         FOREACH_MOD(OnUserJoin, (memb, bursting, created_by_local, except_list));
325
326         this->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", this->name.c_str());
327
328         /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
329         if ((GetUserCounter() > 1) && (!memb->modes.empty()))
330         {
331                 std::string ms = memb->modes;
332                 for(unsigned int i=0; i < memb->modes.length(); i++)
333                         ms.append(" ").append(user->nick);
334
335                 except_list.insert(user);
336                 this->WriteAllExcept(user, !ServerInstance->Config->CycleHostsFromUser, 0, except_list, "MODE %s +%s", this->name.c_str(), ms.c_str());
337         }
338
339         FOREACH_MOD(OnPostJoin, (memb));
340         return memb;
341 }
342
343 bool Channel::IsBanned(User* user)
344 {
345         ModResult result;
346         FIRST_MOD_RESULT(OnCheckChannelBan, result, (user, this));
347
348         if (result != MOD_RES_PASSTHRU)
349                 return (result == MOD_RES_DENY);
350
351         ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
352         const ListModeBase::ModeList* bans = banlm->GetList(this);
353         if (bans)
354         {
355                 for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); it++)
356                 {
357                         if (CheckBan(user, it->mask))
358                                 return true;
359                 }
360         }
361         return false;
362 }
363
364 bool Channel::CheckBan(User* user, const std::string& mask)
365 {
366         ModResult result;
367         FIRST_MOD_RESULT(OnCheckBan, result, (user, this, mask));
368         if (result != MOD_RES_PASSTHRU)
369                 return (result == MOD_RES_DENY);
370
371         // extbans were handled above, if this is one it obviously didn't match
372         if ((mask.length() <= 2) || (mask[1] == ':'))
373                 return false;
374
375         std::string::size_type at = mask.find('@');
376         if (at == std::string::npos)
377                 return false;
378
379         const std::string nickIdent = user->nick + "!" + user->ident;
380         std::string prefix(mask, 0, at);
381         if (InspIRCd::Match(nickIdent, prefix, NULL))
382         {
383                 std::string suffix(mask, at + 1);
384                 if (InspIRCd::Match(user->GetRealHost(), suffix, NULL) ||
385                         InspIRCd::Match(user->GetDisplayedHost(), suffix, NULL) ||
386                         InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL))
387                         return true;
388         }
389         return false;
390 }
391
392 ModResult Channel::GetExtBanStatus(User *user, char type)
393 {
394         ModResult rv;
395         FIRST_MOD_RESULT(OnExtBanCheck, rv, (user, this, type));
396         if (rv != MOD_RES_PASSTHRU)
397                 return rv;
398
399         ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
400         const ListModeBase::ModeList* bans = banlm->GetList(this);
401         if (bans)
402         {
403                 for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); ++it)
404                 {
405                         if (it->mask[0] != type || it->mask[1] != ':')
406                                 continue;
407
408                         if (CheckBan(user, it->mask.substr(2)))
409                                 return MOD_RES_DENY;
410                 }
411         }
412         return MOD_RES_PASSTHRU;
413 }
414
415 /* Channel::PartUser
416  * Remove a channel from a users record, remove the reference to the Membership object
417  * from the channel and destroy it.
418  */
419 bool Channel::PartUser(User* user, std::string& reason)
420 {
421         MemberMap::iterator membiter = userlist.find(user);
422
423         if (membiter == userlist.end())
424                 return false;
425
426         Membership* memb = membiter->second;
427         CUList except_list;
428         FOREACH_MOD(OnUserPart, (memb, reason, except_list));
429
430         WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
431
432         // Remove this channel from the user's chanlist
433         user->chans.erase(memb);
434         // Remove the Membership from this channel's userlist and destroy it
435         this->DelUser(membiter);
436
437         return true;
438 }
439
440 void Channel::KickUser(User* src, const MemberMap::iterator& victimiter, const std::string& reason)
441 {
442         Membership* memb = victimiter->second;
443         CUList except_list;
444         FOREACH_MOD(OnUserKick, (src, memb, reason, except_list));
445
446         User* victim = memb->user;
447         WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), victim->nick.c_str(), reason.c_str());
448
449         victim->chans.erase(memb);
450         this->DelUser(victimiter);
451 }
452
453 void Channel::WriteChannel(User* user, const char* text, ...)
454 {
455         std::string textbuffer;
456         VAFORMAT(textbuffer, text, text);
457         this->WriteChannel(user, textbuffer);
458 }
459
460 void Channel::WriteChannel(User* user, const std::string &text)
461 {
462         const std::string message = ":" + user->GetFullHost() + " " + text;
463
464         for (MemberMap::iterator i = userlist.begin(); i != userlist.end(); i++)
465         {
466                 if (IS_LOCAL(i->first))
467                         i->first->Write(message);
468         }
469 }
470
471 void Channel::WriteChannelWithServ(const std::string& ServName, const char* text, ...)
472 {
473         std::string textbuffer;
474         VAFORMAT(textbuffer, text, text);
475         this->WriteChannelWithServ(ServName, textbuffer);
476 }
477
478 void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text)
479 {
480         const std::string message = ":" + (ServName.empty() ? ServerInstance->Config->ServerName : ServName) + " " + text;
481
482         for (MemberMap::iterator i = userlist.begin(); i != userlist.end(); i++)
483         {
484                 if (IS_LOCAL(i->first))
485                         i->first->Write(message);
486         }
487 }
488
489 /* write formatted text from a source user to all users on a channel except
490  * for the sender (for privmsg etc) */
491 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
492 {
493         std::string textbuffer;
494         VAFORMAT(textbuffer, text, text);
495         this->WriteAllExceptSender(user, serversource, status, textbuffer);
496 }
497
498 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
499 {
500         std::string textbuffer;
501         VAFORMAT(textbuffer, text, text);
502         textbuffer = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + textbuffer;
503         this->RawWriteAllExcept(user, serversource, status, except_list, textbuffer);
504 }
505
506 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
507 {
508         const std::string message = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + text;
509         this->RawWriteAllExcept(user, serversource, status, except_list, message);
510 }
511
512 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
513 {
514         unsigned int minrank = 0;
515         if (status)
516         {
517                 PrefixMode* mh = ServerInstance->Modes->FindPrefix(status);
518                 if (mh)
519                         minrank = mh->GetPrefixRank();
520         }
521         for (MemberMap::iterator i = userlist.begin(); i != userlist.end(); i++)
522         {
523                 if (IS_LOCAL(i->first) && (except_list.find(i->first) == except_list.end()))
524                 {
525                         /* User doesn't have the status we're after */
526                         if (minrank && i->second->getRank() < minrank)
527                                 continue;
528
529                         i->first->Write(out);
530                 }
531         }
532 }
533
534 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
535 {
536         CUList except_list;
537         except_list.insert(user);
538         this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
539 }
540
541 const char* Channel::ChanModes(bool showkey)
542 {
543         static std::string scratch;
544         std::string sparam;
545
546         scratch.clear();
547
548         /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
549         for(int n = 0; n < 64; n++)
550         {
551                 ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_CHANNEL);
552                 if (mh && IsModeSet(mh))
553                 {
554                         scratch.push_back(n + 65);
555
556                         ParamModeBase* pm = mh->IsParameterMode();
557                         if (!pm)
558                                 continue;
559
560                         if (n == 'k' - 65 && !showkey)
561                         {
562                                 sparam += " <key>";
563                         }
564                         else
565                         {
566                                 sparam += ' ';
567                                 pm->GetParameter(this, sparam);
568                         }
569                 }
570         }
571
572         scratch += sparam;
573         return scratch.c_str();
574 }
575
576 void Channel::WriteNotice(const std::string& text)
577 {
578         std::string rawmsg = "NOTICE ";
579         rawmsg.append(this->name).append(" :").append(text);
580         WriteChannelWithServ(ServerInstance->Config->ServerName, rawmsg);
581 }
582
583 /* returns the status character for a given user on a channel, e.g. @ for op,
584  * % for halfop etc. If the user has several modes set, the highest mode
585  * the user has must be returned.
586  */
587 char Membership::GetPrefixChar() const
588 {
589         char pf = 0;
590         unsigned int bestrank = 0;
591
592         for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i)
593         {
594                 PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
595                 if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
596                 {
597                         bestrank = mh->GetPrefixRank();
598                         pf = mh->GetPrefix();
599                 }
600         }
601         return pf;
602 }
603
604 unsigned int Membership::getRank()
605 {
606         char mchar = modes.c_str()[0];
607         unsigned int rv = 0;
608         if (mchar)
609         {
610                 PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(mchar);
611                 if (mh)
612                         rv = mh->GetPrefixRank();
613         }
614         return rv;
615 }
616
617 std::string Membership::GetAllPrefixChars() const
618 {
619         std::string ret;
620         for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i)
621         {
622                 PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
623                 if (mh && mh->GetPrefix())
624                         ret.push_back(mh->GetPrefix());
625         }
626
627         return ret;
628 }
629
630 unsigned int Channel::GetPrefixValue(User* user)
631 {
632         MemberMap::iterator m = userlist.find(user);
633         if (m == userlist.end())
634                 return 0;
635         return m->second->getRank();
636 }
637
638 bool Membership::SetPrefix(PrefixMode* delta_mh, bool adding)
639 {
640         char prefix = delta_mh->GetModeChar();
641         for (unsigned int i = 0; i < modes.length(); i++)
642         {
643                 char mchar = modes[i];
644                 PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(mchar);
645                 if (mh && mh->GetPrefixRank() <= delta_mh->GetPrefixRank())
646                 {
647                         modes = modes.substr(0,i) +
648                                 (adding ? std::string(1, prefix) : "") +
649                                 modes.substr(mchar == prefix ? i+1 : i);
650                         return adding != (mchar == prefix);
651                 }
652         }
653         if (adding)
654                 modes.push_back(prefix);
655         return adding;
656 }