X-Git-Url: http://git.hcoop.net/clinton/bobotpp.git/blobdiff_plain/a63393232f9a19067d58d12065255a10a053f723..815a1816c8a1ee14b28c776bf92c172b1fcdf13a:/source/UserList.C diff --git a/source/UserList.C b/source/UserList.C index b5a795e..afd49fa 100644 --- a/source/UserList.C +++ b/source/UserList.C @@ -14,8 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. +#include #include #include @@ -37,38 +39,48 @@ UserList::~UserList() void UserList::read() { - std::ifstream file(listFilename); + std::ifstream file(listFilename.c_str ()); String temp, empty = ""; int line = 1; clear(); - if (!file) { - std::cerr << "I cannot find the file " << listFilename << std::endl; - return; - } - - while (file >> temp, temp.length() != 0) { - StringTokenizer st(temp); - if (st.count_tokens(':') != 7) { - std::cerr << "Error when reading userlist (" << listFilename << - ") line " << line << "...\n"; + if (!file) + { + std::cerr << "I cannot find the file " << listFilename << std::endl; return; } - String mask = st.next_token(':'); - String maskChannel = st.next_token(':'); - String level = st.next_token(':'); - String prot = st.next_token(':'); - String aop = st.next_token(':'); - String expiration = st.next_token(':'); - String password = Utils::trim_str (st.rest()); - if (password == "*NONE*") - password = ""; - l.push_back(new UserListItem(mask, maskChannel, atoi(level), - atoi(prot), atoi(aop), - atol(expiration), password)); - line++; - } + + while (file >> temp, temp.length() != 0) + { + StringTokenizer st(temp); + + if (st.count_tokens(':') != 7) + { + std::cerr << "Error when reading userlist (" << listFilename << + ") line " << line << "...\n"; + return; + } + + String mask = st.next_token(':'); + String maskChannel = st.next_token(':'); + String level = st.next_token(':'); + String prot = st.next_token(':'); + String aop = st.next_token(':'); + String expiration = st.next_token(':'); + String password = Utils::trim_str (st.rest()); + + if (password == "*NONE*") + { + password = ""; + } + + l.push_back(new UserListItem(mask, maskChannel, std::atoi(level.c_str ()), + std::atoi(prot.c_str ()), std::atoi(aop.c_str ()), + std::atol(expiration.c_str ()), password)); + line++; + } + file.close(); } @@ -76,26 +88,35 @@ void UserList::save() { std::list::iterator it = l.begin(); - std::ofstream file(listFilename); + std::ofstream file(listFilename.c_str ()); if (!file) return; - // FIXME: fix bug (see BUGS) and inc once - ++it; ++it; // We skip the bot's entry + ++it; // Skip the bot's entry + for ( ; it != l.end(); ++it) - if ((*it)->isStillValid()) { - file << (*it)->mask.getMask() << ":" - << (*it)->channelMask.getMask() << ":" - << (*it)->level << ":" - << (*it)->prot << ":" - << (*it)->aop << ":" - << (*it)->expirationDate << ":"; - if ((*it)->passwd == "") - file << "*NONE*"; - else - file << (*it)->passwd; - file << std::endl; + { + if ((*it)->isStillValid()) + { + file << (*it)->mask.getMask() << ":" + << (*it)->channelMask.getMask() << ":" + << (*it)->level << ":" + << (*it)->prot << ":" + << (*it)->aop << ":" + << (*it)->expirationDate << ":"; + + if ((*it)->passwd == "") + { + file << "*NONE*"; + } + else + { + file << (*it)->passwd; + } + + file << std::endl; + } } } @@ -104,11 +125,12 @@ UserList::clear() { UserListItem *uli; - while (!l.empty()) { - uli = (*l.begin()); - l.erase(l.begin()); - delete uli; - } + while (!l.empty()) + { + uli = (*l.begin()); + l.erase(l.begin()); + delete uli; + } } void @@ -145,11 +167,16 @@ UserList::getMaxLevel(String nuh) for (std::list::iterator it = l.begin(); it != l.end(); it++) - if ((*it)->matches(nuh) && level < (*it)->level && - ((*it)->expirationDate == -1 || - (*it)->expirationDate > current_time) && - ((*it)->passwd == "" || (*it)->identified > 0)) - level = (*it)->level; + { + if ((*it)->matches(nuh) && level < (*it)->level + && ((*it)->expirationDate == -1 + || (*it)->expirationDate > current_time) + && ((*it)->passwd == "" + || (*it)->identified > 0)) + { + level = (*it)->level; + } + } return level; }