1 // ShitList.C -*- C++ -*-
2 // Copyright (c) 1998 Etienne BERNARD
3 // Copyright (C) 2002,2005 Clinton Ebadi
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "ShitEntry.H"
31 #include "StringTokenizer.H"
34 ShitList::ShitList(String filename)
35 : listFileName(filename)
51 std::ifstream file(listFileName);
58 std::cerr << "I cannot find the file " << listFileName << std::endl;
62 while (file >> temp, temp.length() != 0) {
63 StringTokenizer st(temp);
64 String mask = st.next_token(':');
65 String channelMask = st.next_token(':');
66 String level = st.next_token(':');
67 String expiration = st.next_token(':');
68 String reason = Utils::trim_str (st.rest());
69 l.push_back (new ShitEntry(mask, channelMask, std::atoi(level),
70 std::atol(expiration), reason));
79 std::list<ShitEntry *>::iterator it = l.begin();
80 std::ofstream file(listFileName);
85 for ( ; it != l.end(); ++it)
86 if ((*it)->isStillValid()) {
87 file << (*it)->shitMask.getMask() << ":"
88 << (*it)->shitChannelMask.getMask() << ":"
89 << (*it)->shitLevel << ":"
90 << (*it)->expirationDate << ":"
91 << (*it)->shitReason << std::endl;
108 ShitList::addShit(String m, String mc, int lev, time_t e, String r)
110 l.push_back (new ShitEntry(m, mc, lev, e, r));
115 ShitList::delShit(String mask, String channelMask)
117 for (std::list<ShitEntry *>::iterator it = l.begin();
120 if ((*it)->shitMask.getMask() == mask &&
121 (*it)->shitChannelMask.getMask() == channelMask) {
129 ShitList::getShit(String nuh, String channel)
131 for (std::list<ShitEntry *>::iterator it = l.begin();
134 if ((*it)->matches(nuh, channel)) {