-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;
-
- /* first cut the list to new size (maxgroups) and also prune entries that are timed out. */
- whowas_users::iterator iter;
- int fifosize;
- while ((fifosize = (int)ServerInstance->whowas_fifo.size()) > 0)
- {
- if (fifosize > maxgroups || ServerInstance->whowas_fifo[0].first < t - maxkeep)
- {
- iter = ServerInstance->whowas.find(ServerInstance->whowas_fifo[0].second);
- /* hopefully redundant integrity check, but added while debugging r6216 */
- if (iter == ServerInstance->whowas.end())
- {
- /* this should never happen, if it does maps are corrupt */
- ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (1)");
- return;
- }
- whowas_set* n = (whowas_set*)iter->second;
- if (n->size())
- {
- while (n->begin() != n->end())
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->pop_front();
- }
- }
- ServerInstance->whowas.erase(iter);
- ServerInstance->whowas_fifo.pop_front();
- }
- else
- break;
- }
-
- /* Then cut the whowas sets to new size (groupsize) */
- for (int i = 0; i < fifosize; i++)
- {
- iter = ServerInstance->whowas.find(ServerInstance->whowas_fifo[0].second);
- /* hopefully redundant integrity check, but added while debugging r6216 */
- if (iter == ServerInstance->whowas.end())
- {
- /* this should never happen, if it does maps are corrupt */
- ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (2)");
- return;
- }
- whowas_set* n = (whowas_set*)iter->second;
- if (n->size())
- {
- int nickcount = n->size();
- while (n->begin() != n->end() && nickcount > groupsize)
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->pop_front();
- nickcount--;
- }
- }
- }
- }
- };
-};
-