]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_pgsql.cpp
Patch: /rehash (not /rehash ssl) will now rebind SSL ports, but not dh params etc...
[user/henk/code/inspircd.git] / src / modules / extra / m_pgsql.cpp
index 57c049f303ff746e1432d771a062698b6c81bcec..1e8813e2e48e0eaab968158a6f49596dd8b616be 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -29,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.
  */
@@ -81,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);
@@ -107,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)
        {
@@ -143,10 +143,10 @@ public:
        {
                /* If we allocated these, free them... */
                if(fieldlist)
-                       DELETE(fieldlist);
+                       delete fieldlist;
 
                if(fieldmap)
-                       DELETE(fieldmap);
+                       delete fieldmap;
 
                PQclear(res);
        }
@@ -301,12 +301,12 @@ public:
 
        virtual void Free(SQLfieldMap* fm)
        {
-               DELETE(fm);
+               delete fm;
        }
 
        virtual void Free(SQLfieldList* fl)
        {
-               DELETE(fl);
+               delete fl;
        }
 };
 
@@ -723,20 +723,22 @@ 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);
+               Implementation eventlist[] = { I_OnUnloadModule, I_OnRequest, I_OnRehash, I_OnUserRegister, I_OnCheckReady, I_OnUserDisconnect };
+               ServerInstance->Modules->Attach(eventlist, this, 6);
        }
 
        virtual ~ModulePgSQL()
@@ -745,17 +747,13 @@ 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)
-       {
-               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();
        }
@@ -860,7 +858,7 @@ class ModulePgSQL : public Module
                {
                        if (!HostInConf(iter->second->GetConfHost()))
                        {
-                               DELETE(iter->second);
+                               delete iter->second;
                                safei = iter;
                                --iter;
                                connections.erase(safei);
@@ -874,7 +872,7 @@ class ModulePgSQL : public Module
                while ((i = connections.begin()) != connections.end())
                {
                        connections.erase(i);
-                       DELETE(i->second);
+                       delete i->second;
                }
        }
 
@@ -900,7 +898,7 @@ class ModulePgSQL : public Module
                {
                        if (conn == iter->second)
                        {
-                               DELETE(iter->second);
+                               delete iter->second;
                                connections.erase(iter);
                                break;
                        }
@@ -963,11 +961,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)
@@ -980,26 +981,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)