]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/commands/cmd_whowas.h
Make valgrind happy and not leak mem.
[user/henk/code/inspircd.git] / include / commands / cmd_whowas.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2007 ChatSpike-Dev.
6  *                     E-mail:
7  *              <brain@chatspike.net>
8  *              <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *          the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __CMD_WHOWAS_H__
18 #define __CMD_WHOWAS_H__
19
20
21 // include the common header files
22
23 #include "users.h"
24 #include "channels.h"
25
26 /* list of available internal commands */
27 enum Internals
28 {
29         WHOWAS_ADD = 1,
30         WHOWAS_STATS = 2,
31         WHOWAS_PRUNE = 3,
32         WHOWAS_MAINTAIN = 4
33 };
34
35 /* Forward ref for timer */
36 class WhoWasMaintainTimer;
37
38 /* Forward ref for typedefs */
39 class WhoWasGroup;
40
41 /** InspTimer that is used to maintain the whowas list, called once an hour
42  */
43 extern WhoWasMaintainTimer* timer;
44
45 /** A group of users related by nickname
46  */
47 typedef std::deque<WhoWasGroup*> whowas_set;
48
49 /** Sets of users in the whowas system
50  */
51 typedef std::map<irc::string,whowas_set*> whowas_users;
52
53 /** Sets of time and users in whowas list
54  */
55 typedef std::deque<std::pair<time_t,irc::string> > whowas_users_fifo;
56
57 /** Handle /WHOWAS
58  */
59 class cmd_whowas : public command_t
60 {
61   private:
62         /** Whowas container, contains a map of vectors of users tracked by WHOWAS
63          */
64         whowas_users whowas;
65         
66         /** Whowas container, contains a map of time_t to users tracked by WHOWAS
67          */
68         whowas_users_fifo whowas_fifo;
69
70         /* String holding stats so it can be collected
71          */
72         std::string stats;
73
74   public:
75         cmd_whowas(InspIRCd* Instance);
76         CmdResult Handle(const char** parameters, int pcnt, userrec *user);
77         CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> &parameters);
78         void AddToWhoWas(userrec* user);
79         void GetStats(Extensible* ext);
80         void PruneWhoWas(time_t t);
81         void MaintainWhoWas(time_t t);
82         virtual ~cmd_whowas();
83 };
84
85 /** Used to hold WHOWAS information
86  */
87 class WhoWasGroup : public classbase
88 {
89  public:
90         /** Real host
91          */
92         char* host;
93         /** Displayed host
94          */
95         char* dhost;
96         /** Ident
97          */
98         char* ident;
99         /** Server name
100          */
101         const char* server;
102         /** Fullname (GECOS)
103          */
104         char* gecos;
105         /** Signon time
106          */
107         time_t signon;
108
109         /** Initialize this WhoQasFroup with a user
110          */
111         WhoWasGroup(userrec* user);
112         /** Destructor
113          */
114         ~WhoWasGroup();
115 };
116
117 class WhoWasMaintainTimer : public InspTimer
118 {
119   private:
120         InspIRCd* ServerInstance;
121   public:
122         WhoWasMaintainTimer(InspIRCd* Instance, long interval)
123         : InspTimer(interval, Instance->Time(), true), ServerInstance(Instance)
124         {
125         }
126         virtual void Tick(time_t TIME);
127 };
128
129 #endif