summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-07 21:16:03 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-07 21:16:03 +0000
commitdac672cf303ce44dc5f877a5f9f7e5aee64b95e1 (patch)
tree3484e7870d732dd04a590640cfe5c72ea50e7dde /include
parent6b9eaeba4130acb818a63782640194c7e5bcc2fa (diff)
DNS Stuff - this wont work right yet, it will soon (tm)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6250 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include')
-rw-r--r--include/dns.h44
-rw-r--r--include/users.h2
2 files changed, 41 insertions, 5 deletions
diff --git a/include/dns.h b/include/dns.h
index cb7e0549a..83e4ab902 100644
--- a/include/dns.h
+++ b/include/dns.h
@@ -37,6 +37,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "base.h"
#include "socketengine.h"
#include "socket.h"
+#include "hash_map.h"
+#include "hashcomp.h"
using namespace std;
using irc::sockets::insp_aton;
@@ -56,8 +58,9 @@ class DNSResult : public classbase
int id;
std::string result;
unsigned long ttl;
+ std::string original;
- DNSResult(int i, const std::string &res, unsigned long timetolive) : id(i), result(res), ttl(timetolive) { }
+ DNSResult(int i, const std::string &res, unsigned long timetolive, const std::string &orig) : id(i), result(res), ttl(timetolive), original(orig) { }
};
/**
@@ -65,6 +68,30 @@ class DNSResult : public classbase
*/
typedef std::pair<unsigned char*, std::string> DNSInfo;
+/** Cached item
+ */
+class CachedQuery
+{
+ public:
+ std::string data;
+ time_t expires;
+
+ CachedQuery(const std::string &res, unsigned int ttl) : data(res)
+ {
+ expires = time(NULL) + ttl;
+ }
+
+ int CalcTTLRemaining()
+ {
+ int n = expires - time(NULL);
+ return (n < 0 ? 0 : n);
+ }
+};
+
+/** DNS cache information
+ */
+typedef nspace::hash_map<irc::string, CachedQuery, nspace::hash<irc::string> > dnscache;
+
/**
* Error types that class Resolver can emit to its error method.
*/
@@ -201,7 +228,7 @@ class Resolver : public Extensible
* whilst lookups are in progress, they can be safely removed and your module will not
* crash the server.
*/
- Resolver(InspIRCd* Instance, const std::string &source, QueryType qt, Module* creator = NULL);
+ Resolver(InspIRCd* Instance, const std::string &source, QueryType qt, bool &cached, Module* creator = NULL);
/**
* The default destructor does nothing.
@@ -211,7 +238,7 @@ class Resolver : public Extensible
* When your lookup completes, this method will be called.
* @param result The resulting DNS lookup, either an IP address or a hostname.
*/
- virtual void OnLookupComplete(const std::string &result, unsigned int ttl) = 0;
+ virtual void OnLookupComplete(const std::string &result, unsigned int ttl);
/**
* If an error occurs (such as NXDOMAIN, no domain name found) then this method
* will be called.
@@ -271,6 +298,11 @@ class DNS : public EventHandler
bool ip6munge;
/**
+ * Currently cached items
+ */
+ dnscache* cache;
+
+ /**
* Build a dns packet payload
*/
int MakePayload(const char* name, const QueryType rr, const unsigned short rr_class, unsigned char* payload);
@@ -352,7 +384,7 @@ class DNS : public EventHandler
/**
* Add a query to the list to be sent
*/
- DNSRequest* AddQuery(DNSHeader *header, int &id);
+ DNSRequest* AddQuery(DNSHeader *header, int &id, const char* original);
/**
* The constructor initialises the dns socket,
@@ -388,6 +420,10 @@ class DNS : public EventHandler
* are dns requests currently in progress.
*/
void CleanResolvers(Module* module);
+
+ CachedQuery* GetCache(const std::string &source);
+
+ void DelCache(const std::string &source);
};
#endif
diff --git a/include/users.h b/include/users.h
index 749030894..c26d791fa 100644
--- a/include/users.h
+++ b/include/users.h
@@ -67,7 +67,7 @@ class UserResolver : public Resolver
int bound_fd;
bool fwd;
public:
- UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, QueryType qt);
+ UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, QueryType qt, bool &cache);
void OnLookupComplete(const std::string &result, unsigned int ttl);
void OnError(ResolverError e, const std::string &errormessage);