2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "modules/invite.h"
29 typedef insp::intrusive_list<Invite, T> List;
31 /** List of pending Invites
36 template<typename T, ExtensionItem::ExtensibleType ExtType>
42 extern void RemoveInvite(Invite::Invite* inv, bool remove_user, bool remove_chan);
44 template<typename T, ExtensionItem::ExtensibleType ExtType>
45 class Invite::ExtItem : public ExtensionItem
48 ExtItem(Module* owner, const char* extname)
49 : ExtensionItem(extname, ExtType, owner)
53 Store<T>* get(Extensible* ext, bool create = false)
55 Store<T>* store = static_cast<Store<T>*>(get_raw(ext));
56 if ((create) && (!store))
64 void unset(Extensible* ext)
66 void* store = unset_raw(ext);
71 void free(void* item) CXX11_OVERRIDE
73 Store<T>* store = static_cast<Store<T>*>(item);
74 for (typename Store<T>::List::iterator i = store->invites.begin(); i != store->invites.end(); )
77 // Destructing the Invite invalidates the iterator, so move it now
79 RemoveInvite(inv, (ExtType != ExtensionItem::EXT_USER), (ExtType == ExtensionItem::EXT_USER));
85 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE
90 void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE
95 class Invite::APIImpl : public APIBase
97 ExtItem<LocalUser, ExtensionItem::EXT_USER> userext;
98 ExtItem<Channel, ExtensionItem::EXT_CHANNEL> chanext;
101 APIImpl(Module* owner);
103 void Create(LocalUser* user, Channel* chan, time_t timeout) CXX11_OVERRIDE;
104 Invite* Find(LocalUser* user, Channel* chan) CXX11_OVERRIDE;
105 bool Remove(LocalUser* user, Channel* chan) CXX11_OVERRIDE;
106 const List* GetList(LocalUser* user) CXX11_OVERRIDE;
108 void RemoveAll(LocalUser* user) { userext.unset(user); }
109 void RemoveAll(Channel* chan) { chanext.unset(chan); }
110 void Destruct(Invite* inv, bool remove_chan = true, bool remove_user = true);