Comment on a lot of recently added stuff that wasnt properly documented (until now)

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6284 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2007-01-09 22:31:19 +00:00
parent d569a50e74
commit 49e34a508d
4 changed files with 190 additions and 8 deletions

View File

@ -41,11 +41,14 @@ enum CmdResult
#define CMD_LOCALONLY CMD_FAILURE #define CMD_LOCALONLY CMD_FAILURE
/** A structure that defines a command /** A structure that defines a command. Every command available
* in InspIRCd must be defined as derived from command_t.
*/ */
class command_t : public Extensible class command_t : public Extensible
{ {
protected: protected:
/** Owner/Creator object
*/
InspIRCd* ServerInstance; InspIRCd* ServerInstance;
public: public:
/** Command name /** Command name
@ -77,6 +80,16 @@ class command_t : public Extensible
*/ */
std::string syntax; std::string syntax;
/** Create a new command.
* @param Instance Pointer to creator class
* @param cmd Command name. This must be UPPER CASE.
* @param flags User modes required to execute the command.
* For oper only commands, set this to 'o', otherwise use 0.
* @param minpara Minimum parameters required for the command.
* @param before_reg If this is set to true, the command will
* be allowed before the user is 'registered' (has sent USER,
* NICK, optionally PASS, and been resolved).
*/
command_t(InspIRCd* Instance, const std::string &cmd, char flags, int minpara, int before_reg = false) : ServerInstance(Instance), command(cmd), flags_needed(flags), min_params(minpara), disabled(false), works_before_reg(before_reg) command_t(InspIRCd* Instance, const std::string &cmd, char flags, int minpara, int before_reg = false) : ServerInstance(Instance), command(cmd), flags_needed(flags), min_params(minpara), disabled(false), works_before_reg(before_reg)
{ {
use_count = total_bytes = 0; use_count = total_bytes = 0;
@ -84,36 +97,74 @@ class command_t : public Extensible
syntax = ""; syntax = "";
} }
/** Handle the command from a user.
* @param parameters The parameters for the command.
* @param pcnt The number of parameters available in 'parameters'
* @param user The user who issued the command.
* @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
* If the command succeeds but should remain local to this server,
* return CMD_LOCALONLY.
*/
virtual CmdResult Handle(const char** parameters, int pcnt, userrec* user) = 0; virtual CmdResult Handle(const char** parameters, int pcnt, userrec* user) = 0;
/** Handle an internal request from another command, the core, or a module
* @param Command ID
* @param Zero or more parameters, whos form is specified by the command ID.
* @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
* If the command succeeds but should remain local to this server,
* return CMD_LOCALONLY.
*/
virtual CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> &params) virtual CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> &params)
{ {
return CMD_INVALID; return CMD_INVALID;
} }
/** Handle the command from a server.
* Not currently used in this version of InspIRCd.
* @param parameters The parameters given
* @param pcnt The number of parameters available
* @param servername The server name which issued the command
* @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
* If the command succeeds but should remain local to this server,
* return CMD_LOCALONLY.
*/
virtual CmdResult HandleServer(const char** parameters, int pcnt, const std::string &servername) virtual CmdResult HandleServer(const char** parameters, int pcnt, const std::string &servername)
{ {
return CMD_INVALID; return CMD_INVALID;
} }
/** Disable or enable this command.
* @param setting True to disable the command.
*/
void Disable(bool setting) void Disable(bool setting)
{ {
disabled = setting; disabled = setting;
} }
/** Obtain this command's disable state.
* @return true if the command is currently disabled
* (disabled commands can be used only by operators)
*/
bool IsDisabled() bool IsDisabled()
{ {
return disabled; return disabled;
} }
/** @return true if the command works before registration.
*/
bool WorksBeforeReg() bool WorksBeforeReg()
{ {
return works_before_reg; return works_before_reg;
} }
/** Standard constructor gubbins
*/
virtual ~command_t() {} virtual ~command_t() {}
}; };
/** A hash of commands used by the core
*/
typedef nspace::hash_map<std::string,command_t*> command_table; typedef nspace::hash_map<std::string,command_t*> command_table;
#endif #endif

View File

@ -55,11 +55,25 @@ class Module;
class DNSResult : public classbase class DNSResult : public classbase
{ {
public: public:
/** Result ID
*/
int id; int id;
/** Result body, a hostname or IP address
*/
std::string result; std::string result;
/** Time-to-live value of the result
*/
unsigned long ttl; unsigned long ttl;
/** The original request, a hostname or IP address
*/
std::string original; std::string original;
/** Build a DNS result.
* @param i The request ID
* @param res The request result, a hostname or IP
* @param timetolive The request time-to-live
* @param orig The original request, a hostname or IP
*/
DNSResult(int i, const std::string &res, unsigned long timetolive, const std::string &orig) : id(i), result(res), ttl(timetolive), original(orig) { } DNSResult(int i, const std::string &res, unsigned long timetolive, const std::string &orig) : id(i), result(res), ttl(timetolive), original(orig) { }
}; };
@ -68,19 +82,30 @@ class DNSResult : public classbase
*/ */
typedef std::pair<unsigned char*, std::string> DNSInfo; typedef std::pair<unsigned char*, std::string> DNSInfo;
/** Cached item /** Cached item stored in the query cache.
*/ */
class CachedQuery class CachedQuery
{ {
public: public:
/** The cached result data, an IP or hostname
*/
std::string data; std::string data;
/** The time when the item is due to expire
*/
time_t expires; time_t expires;
/** Build a cached query
* @param res The result data, an IP or hostname
* @param ttl The time-to-live value of the query result
*/
CachedQuery(const std::string &res, unsigned int ttl) : data(res) CachedQuery(const std::string &res, unsigned int ttl) : data(res)
{ {
expires = time(NULL) + ttl; expires = time(NULL) + ttl;
} }
/** Returns the number of seconds remaining before this
* cache item has expired and should be removed.
*/
int CalcTTLRemaining() int CalcTTLRemaining()
{ {
int n = expires - time(NULL); int n = expires - time(NULL);
@ -88,7 +113,7 @@ class CachedQuery
} }
}; };
/** DNS cache information /** DNS cache information. Holds IPs mapped to hostnames, and hostnames mapped to IPs.
*/ */
typedef nspace::hash_map<irc::string, CachedQuery, nspace::hash<irc::string> > dnscache; typedef nspace::hash_map<irc::string, CachedQuery, nspace::hash<irc::string> > dnscache;
@ -277,12 +302,15 @@ class Resolver : public Extensible
* this method will return -1. * this method will return -1.
*/ */
int GetId(); int GetId();
/** /**
* Returns the creator module, or NULL * Returns the creator module, or NULL
*/ */
Module* GetCreator(); Module* GetCreator();
/**
* If the result is a cached result, this triggers the objects
* OnLookupComplete. This is done because it is not safe to call
* the abstract virtual method from the constructor.
*/
void TriggerCachedResult(); void TriggerCachedResult();
}; };
@ -295,6 +323,9 @@ class DNS : public EventHandler
{ {
private: private:
/**
* Creator/Owner object
*/
InspIRCd* ServerInstance; InspIRCd* ServerInstance;
/** /**
@ -326,6 +357,9 @@ class DNS : public EventHandler
*/ */
dnscache* cache; dnscache* cache;
/** A timer which ticks every hour to remove expired
* items from the DNS cache.
*/
class CacheTimer* PruneTimer; class CacheTimer* PruneTimer;
/** /**
@ -334,14 +368,17 @@ class DNS : public EventHandler
int MakePayload(const char* name, const QueryType rr, const unsigned short rr_class, unsigned char* payload); int MakePayload(const char* name, const QueryType rr, const unsigned short rr_class, unsigned char* payload);
public: public:
/** /**
* Currently active Resolver classes * Currently active Resolver classes
*/ */
Resolver* Classes[MAX_REQUEST_ID]; Resolver* Classes[MAX_REQUEST_ID];
/** /**
* Requests that are currently 'in flight' * Requests that are currently 'in flight'
*/ */
DNSRequest* requests[MAX_REQUEST_ID]; DNSRequest* requests[MAX_REQUEST_ID];
/** /**
* The port number DNS requests are made on, * The port number DNS requests are made on,
* and replies have as a source-port number. * and replies have as a source-port number.
@ -352,14 +389,17 @@ class DNS : public EventHandler
* Fill an rr (resource record) with data from input * Fill an rr (resource record) with data from input
*/ */
static void FillResourceRecord(ResourceRecord* rr, const unsigned char* input); static void FillResourceRecord(ResourceRecord* rr, const unsigned char* input);
/** /**
* Fill a header with data from input limited by a length * Fill a header with data from input limited by a length
*/ */
static void FillHeader(DNSHeader *header, const unsigned char *input, const int length); static void FillHeader(DNSHeader *header, const unsigned char *input, const int length);
/** /**
* Empty out a header into a data stream ready for transmission "on the wire" * Empty out a header into a data stream ready for transmission "on the wire"
*/ */
static void EmptyHeader(unsigned char *output, const DNSHeader *header, const int length); static void EmptyHeader(unsigned char *output, const DNSHeader *header, const int length);
/** /**
* Start the lookup of an ipv4 from a hostname * Start the lookup of an ipv4 from a hostname
*/ */
@ -447,11 +487,26 @@ class DNS : public EventHandler
*/ */
void CleanResolvers(Module* module); void CleanResolvers(Module* module);
/** Return the cached value of an IP or hostname
* @param source An IP or hostname to find in the cache.
* @return A pointer to a CachedQuery if the item exists,
* otherwise NULL.
*/
CachedQuery* GetCache(const std::string &source); CachedQuery* GetCache(const std::string &source);
/** Delete a cached item from the DNS cache.
* @param source An IP or hostname to remove
*/
void DelCache(const std::string &source); void DelCache(const std::string &source);
/** Clear all items from the DNS cache immediately.
*/
int ClearCache(); int ClearCache();
/** Prune the DNS cache, e.g. remove all expired
* items and rehash the cache buckets, but leave
* items in the hash which are still valid.
*/
int PruneCache(); int PruneCache();
}; };

View File

@ -30,7 +30,11 @@ class InspTimer : public Extensible
/** The triggering time /** The triggering time
*/ */
time_t trigger; time_t trigger;
/** Number of seconds between triggers
*/
long secs; long secs;
/** True if this is a repeating timer
*/
bool repeat; bool repeat;
public: public:
/** Default constructor, initializes the triggering time /** Default constructor, initializes the triggering time
@ -44,29 +48,49 @@ class InspTimer : public Extensible
secs = secs_from_now; secs = secs_from_now;
repeat = repeating; repeat = repeating;
} }
/** Default destructor, does nothing. /** Default destructor, does nothing.
*/ */
virtual ~InspTimer() { } virtual ~InspTimer() { }
/** Retrieve the current triggering time /** Retrieve the current triggering time
*/ */
virtual time_t GetTimer() virtual time_t GetTimer()
{ {
return trigger; return trigger;
} }
/** Called when the timer ticks. /** Called when the timer ticks.
* You should override this method with some useful code to
* handle the tick event.
*/ */
virtual void Tick(time_t TIME) = 0; virtual void Tick(time_t TIME) = 0;
/** Returns true if this timer is set to repeat
*/
bool GetRepeat() bool GetRepeat()
{ {
return repeat; return repeat;
} }
/** Returns the interval (number of seconds between ticks)
* of this timer object.
*/
long GetSecs() long GetSecs()
{ {
return secs; return secs;
} }
/** Cancels the repeat state of a repeating timer.
* If you call this method, then the next time your
* timer ticks, it will be removed immediately after.
* You should use this method call to remove a recurring
* timer if you wish to do so within the timer's Tick
* event, as calling TimerManager::DelTimer() from within
* the InspTimer::Tick() method is dangerous and may
* cause a segmentation fault. Calling CancelRepeat()
* is safe in this case.
*/
void CancelRepeat() void CancelRepeat()
{ {
repeat = false; repeat = false;

View File

@ -120,68 +120,107 @@ class ConnectClass : public classbase
public: public:
/** Create a new connect class with no settings.
*/
ConnectClass() : type(CC_DENY), registration_timeout(0), flood(0), host(""), pingtime(0), pass(""), ConnectClass() : type(CC_DENY), registration_timeout(0), flood(0), host(""), pingtime(0), pass(""),
threshold(0), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0) { } threshold(0), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0) { }
/** Create a new connect class to ALLOW connections.
* @param timeout The registration timeout
* @param fld The flood value
* @param hst The IP mask to allow
* @param ping The ping frequency
* @param pas The password to be used
* @param thres The flooding threshold
* @param sendq The maximum sendq value
* @param recvq The maximum recvq value
* @param maxl The maximum local sessions
* @param maxg The maximum global sessions
*/
ConnectClass(unsigned int timeout, unsigned int fld, const std::string &hst, unsigned int ping, ConnectClass(unsigned int timeout, unsigned int fld, const std::string &hst, unsigned int ping,
const std::string &pas, unsigned int thres, unsigned long sendq, unsigned long recvq, const std::string &pas, unsigned int thres, unsigned long sendq, unsigned long recvq,
unsigned long maxl, unsigned long maxg) : unsigned long maxl, unsigned long maxg) :
type(CC_ALLOW), registration_timeout(timeout), flood(fld), host(hst), pingtime(ping), pass(pas), type(CC_ALLOW), registration_timeout(timeout), flood(fld), host(hst), pingtime(ping), pass(pas),
threshold(thres), sendqmax(sendq), recvqmax(recvq), maxlocal(maxl), maxglobal(maxg) { } threshold(thres), sendqmax(sendq), recvqmax(recvq), maxlocal(maxl), maxglobal(maxg) { }
/** Create a new connect class to DENY connections
* @param hst The IP mask to deny
*/
ConnectClass(const std::string &hst) : type(CC_DENY), registration_timeout(0), flood(0), host(hst), pingtime(0), ConnectClass(const std::string &hst) : type(CC_DENY), registration_timeout(0), flood(0), host(hst), pingtime(0),
pass(""), threshold(0), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0) { } pass(""), threshold(0), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0) { }
/** Returns the type, CC_ALLOW or CC_DENY
*/
char GetType() char GetType()
{ {
return (type == CC_ALLOW ? CC_ALLOW : CC_DENY); return (type == CC_ALLOW ? CC_ALLOW : CC_DENY);
} }
/** Returns the registration timeout
*/
unsigned int GetRegTimeout() unsigned int GetRegTimeout()
{ {
return (registration_timeout ? registration_timeout : 90); return (registration_timeout ? registration_timeout : 90);
} }
/** Returns the flood limit
*/
unsigned int GetFlood() unsigned int GetFlood()
{ {
return (threshold ? flood : 999); return (threshold ? flood : 999);
} }
/** Returns the allowed or denied IP mask
*/
const std::string& GetHost() const std::string& GetHost()
{ {
return host; return host;
} }
/** Returns the ping frequency
*/
unsigned int GetPingTime() unsigned int GetPingTime()
{ {
return (pingtime ? pingtime : 120); return (pingtime ? pingtime : 120);
} }
/** Returns the password or an empty string
*/
const std::string& GetPass() const std::string& GetPass()
{ {
return pass; return pass;
} }
/** Returns the flood threshold value
*/
unsigned int GetThreshold() unsigned int GetThreshold()
{ {
return (threshold ? threshold : 1); return (threshold ? threshold : 1);
} }
/** Returns the maximum sendq value
*/
unsigned long GetSendqMax() unsigned long GetSendqMax()
{ {
return (sendqmax ? sendqmax : 262114); return (sendqmax ? sendqmax : 262114);
} }
/** Returns the maximum recvq value
*/
unsigned long GetRecvqMax() unsigned long GetRecvqMax()
{ {
return (recvqmax ? recvqmax : 4096); return (recvqmax ? recvqmax : 4096);
} }
/** Returusn the maximum number of local sessions
*/
unsigned long GetMaxLocal() unsigned long GetMaxLocal()
{ {
return (maxlocal ? maxlocal : 1); return (maxlocal ? maxlocal : 1);
} }
/** Returns the maximum number of global sessions
*/
unsigned long GetMaxGlobal() unsigned long GetMaxGlobal()
{ {
return (maxglobal ? maxglobal : 1); return (maxglobal ? maxglobal : 1);
@ -227,8 +266,16 @@ class userrec : public connection
*/ */
unsigned int ChannelCount; unsigned int ChannelCount;
/** Cached nick!ident@host value using the real hostname
*/
char* cached_fullhost; char* cached_fullhost;
/** Cached nick!ident@ip value using the real IP address
*/
char* cached_hostip; char* cached_hostip;
/** Cached nick!ident@host value using the masked hostname
*/
char* cached_makehost; char* cached_makehost;
char* cached_fullrealhost; char* cached_fullrealhost;
@ -368,7 +415,8 @@ class userrec : public connection
*/ */
long threshold; long threshold;
/** IPV4 or IPV6 ip address /** IPV4 or IPV6 ip address. Use SetSockAddr to set this and GetProtocolFamily/
* GetIPString/GetPort to obtain its values.
*/ */
sockaddr* ip; sockaddr* ip;
@ -404,11 +452,13 @@ class userrec : public connection
*/ */
std::string WriteError; std::string WriteError;
/** Maximum size this user's sendq can become /** Maximum size this user's sendq can become.
* Copied from the connect class on connect.
*/ */
long sendqmax; long sendqmax;
/** Maximum size this user's recvq can become /** Maximum size this user's recvq can become.
* Copied from the connect class on connect.
*/ */
long recvqmax; long recvqmax;
@ -838,6 +888,8 @@ class userrec : public connection
/** Handle socket event. /** Handle socket event.
* From EventHandler class. * From EventHandler class.
* @param et Event type
* @param errornum Error number for EVENT_ERROR events
*/ */
void HandleEvent(EventType et, int errornum = 0); void HandleEvent(EventType et, int errornum = 0);