-namespace irc
-{
- namespace whowas
- {
-
- WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
- {
- this->host = strdup(user->host);
- this->dhost = strdup(user->dhost);
- this->ident = strdup(user->ident);
- this->server = user->server;
- this->gecos = strdup(user->fullname);
- }
-
- WhoWasGroup::~WhoWasGroup()
- {
- if (host)
- free(host);
- if (dhost)
- free(dhost);
- if (ident)
- free(ident);
- if (gecos)
- free(gecos);
- }
-
- /* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
- void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
- {
- for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
- {
- whowas_set* n = (whowas_set*)iter->second;
- if (n->size())
- {
- while ((n->begin() != n->end()) && ((*n->begin())->signon < t - ServerInstance->Config->WhoWasMaxKeep))
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->erase(n->begin());
- }
- }
- }
- }
- /* on rehash, refactor maps according to new conf values */
- void PruneWhoWas(InspIRCd* ServerInstance, time_t t)
- {
- /* config values */
- int groupsize = ServerInstance->Config->WhoWasGroupSize;
- int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
- int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
-
- int groupcount = ServerInstance->whowas.size();
- /* iterate whowas_fifo oldest first */
- whowas_users_fifo::iterator iter, safeiter;
- for (iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
- {
- /** prune all groups that has expired due to new maxkeep time and
- * also any group number higher than new maxgroups. The oldest are
- * removed first due to iteration over whowas_fifo
- */
- if (groupcount > maxgroups || iter->first < t - maxkeep)
- {
- whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
- if (n->size())
- {
- while (n->begin() != n->end())
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->erase(n->begin());
- }
- }
- ServerInstance->whowas.erase(iter->second);
- /* use a safe iter copy for erase and set the orig iter old valid ref by decrementing it */
- safeiter = iter;
- --iter;
- ServerInstance->whowas_fifo.erase(safeiter);
- }
- else {
- /* also trim individual groupsizes in case groupsize should have been lowered */
- whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
- if (n->size())
- {
- int nickcount = n->size();
- while (n->begin() != n->end() && nickcount > groupsize)
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->erase(n->begin());
- nickcount--;
- }
- }
- }
- groupcount--;
- }
- }
- };
-};