]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_pgsql.cpp
All of insp now builds with -pedantic (theres some warnings to squash in modules...
[user/henk/code/inspircd.git] / src / modules / extra / m_pgsql.cpp
index 76259a35b4ba9a7ba47f277a66a113dffcd24669..34e653e2ab6ad449acbc5b190e94ece5f4fbdce8 100644 (file)
  * ---------------------------------------------------
  */
 
+#include "inspircd.h"
 #include <cstdlib>
 #include <sstream>
-#include <string>
-#include <deque>
-#include <map>
 #include <libpq-fe.h>
-
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "inspircd.h"
 #include "configreader.h"
-
 #include "m_sqlv2.h"
 
 /* $ModDesc: PostgreSQL Service Provider module for all other m_sql* modules, uses v2 of the SQL API */
@@ -34,7 +29,7 @@
 
 /* SQLConn rewritten by peavey to
  * use EventHandler instead of
- * InspSocket. This is much neater
+ * BufferedSocket. This is much neater
  * and gives total control of destroy
  * and delete of resources.
  */
@@ -86,13 +81,13 @@ std::string SQLhost::GetDSN()
        return conninfo.str();
 }
 
-class ReconnectTimer : public InspTimer
+class ReconnectTimer : public Timer
 {
   private:
        Module* mod;
   public:
        ReconnectTimer(InspIRCd* SI, Module* m)
-       : InspTimer(5, SI->Time(), false), mod(m)
+       : Timer(5, SI->Time(), false), mod(m)
        {
        }
        virtual void Tick(time_t TIME);
@@ -112,7 +107,7 @@ class SQLresolver : public Resolver
        {
        }
 
-       virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
+       virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum = 0);
 
        virtual void OnError(ResolverError e, const std::string &errormessage)
        {
@@ -728,20 +723,20 @@ class ModulePgSQL : public Module
        ModulePgSQL(InspIRCd* Me)
        : Module::Module(Me), currid(0)
        {
-               ServerInstance->UseInterface("SQLutils");
+               ServerInstance->Modules->UseInterface("SQLutils");
 
                sqlsuccess = new char[strlen(SQLSUCCESS)+1];
 
                strlcpy(sqlsuccess, SQLSUCCESS, strlen(SQLSUCCESS));
 
-               if (!ServerInstance->PublishFeature("SQL", this))
+               if (!ServerInstance->Modules->PublishFeature("SQL", this))
                {
                        throw ModuleException("BUG: PgSQL Unable to publish feature 'SQL'");
                }
 
                ReadConf();
 
-               ServerInstance->PublishInterface("SQL", this);
+               ServerInstance->Modules->PublishInterface("SQL", this);
        }
 
        virtual ~ModulePgSQL()
@@ -750,9 +745,9 @@ class ModulePgSQL : public Module
                        ServerInstance->Timers->DelTimer(retimer);
                ClearAllConnections();
                delete[] sqlsuccess;
-               ServerInstance->UnpublishInterface("SQL", this);
-               ServerInstance->UnpublishFeature("SQL");
-               ServerInstance->DoneWithInterface("SQLutils");
+               ServerInstance->Modules->UnpublishInterface("SQL", this);
+               ServerInstance->Modules->UnpublishFeature("SQL");
+               ServerInstance->Modules->DoneWithInterface("SQLutils");
        }
 
        void Implements(char* List)
@@ -760,7 +755,7 @@ class ModulePgSQL : public Module
                List[I_OnUnloadModule] = List[I_OnRequest] = List[I_OnRehash] = List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnUserDisconnect] = 1;
        }
 
-       virtual void OnRehash(userrec* user, const std::string &parameter)
+       virtual void OnRehash(User* user, const std::string &parameter)
        {
                ReadConf();
        }
@@ -803,7 +798,6 @@ class ModulePgSQL : public Module
                {
                        SQLhost host;
                        int ipvalid;
-                       insp_inaddr blargle;
 
                        host.id         = conf.ReadValue("database", "id", i);
                        host.host       = conf.ReadValue("database", "hostname", i);
@@ -816,7 +810,18 @@ class ModulePgSQL : public Module
                        if (HasHost(host))
                                continue;
 
-                       ipvalid = insp_aton(host.host.c_str(), &blargle);
+#ifdef IPV6
+                       if (strchr(host.host.c_str(),':'))
+                       {
+                               in6_addr blargle;
+                               ipvalid = inet_pton(AF_INET6, host.host.c_str(), &blargle);
+                       }
+                       else
+#endif
+                       {
+                               in_addr blargle;
+                               ipvalid = inet_aton(host.host.c_str(), &blargle);
+                       }
 
                        if(ipvalid > 0)
                        {
@@ -958,11 +963,14 @@ class ModulePgSQL : public Module
 /* move this here to use AddConn, rather that than having the whole
  * module above SQLConn, since this is buggin me right now :/
  */
-void SQLresolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
+void SQLresolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum)
 {
-       host.ip = result;
-       ((ModulePgSQL*)mod)->AddConn(host);
-       ((ModulePgSQL*)mod)->ClearOldConnections();
+       if (!resultnum)
+       {
+               host.ip = result;
+               ((ModulePgSQL*)mod)->AddConn(host);
+               ((ModulePgSQL*)mod)->ClearOldConnections();
+       }
 }
 
 void ReconnectTimer::Tick(time_t time)
@@ -975,26 +983,4 @@ void SQLConn::DelayReconnect()
        ((ModulePgSQL*)us)->ReconnectConn(this);
 }
 
-
-class ModulePgSQLFactory : public ModuleFactory
-{
- public:
-       ModulePgSQLFactory()
-       {
-       }
-
-       ~ModulePgSQLFactory()
-       {
-       }
-
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModulePgSQL(Me);
-       }
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModulePgSQLFactory;
-}
+MODULE_INIT(ModulePgSQL)