]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqlite3.cpp
I lose for being slow. also tidyup a bit, still needs to fix that sizeof..
[user/henk/code/inspircd.git] / src / modules / extra / m_sqlite3.cpp
index 9c66c4f11cebc9b7887e3459e0124f1f81aa25d4..f37e52324fafbde2183477820ac783be925a8835 100644 (file)
  * ---------------------------------------------------
  */
 
-#include <string>
-#include <deque>
-#include <map>
+#include "inspircd.h"
 #include <sqlite3.h>
-
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "inspircd.h"
-#include "configreader.h"
 
 #include "m_sqlv2.h"
 
 /* $ModDesc: sqlite3 provider */
-/* $CompileFlags: pkgconfincludes("sqlite3","/sqlite3.h","") */
+/* $CompileFlags: pkgconfversion("sqlite3","3.3") pkgconfincludes("sqlite3","/sqlite3.h","") */
 /* $LinkerFlags: pkgconflibs("sqlite3","/libsqlite3.so","-lsqlite3") */
 /* $ModDep: m_sqlv2.h */
 
@@ -64,7 +59,6 @@ class ResultNotifier : public InspSocket
 
        ResultNotifier(InspIRCd* SI, Module* m, int newfd, char* ip) : InspSocket(SI, newfd, ip), mod(m)
        {
-               Instance->Log(DEBUG,"Constructor of new socket");
        }
 
        /* Using getsockname and ntohs, we can determine which port number we were allocated */
@@ -79,7 +73,6 @@ class ResultNotifier : public InspSocket
 
        virtual int OnIncomingConnection(int newsock, char* ip)
        {
-               Instance->Log(DEBUG,"Inbound connection on fd %d!",newsock);
                Dispatch();
                return false;
        }
@@ -269,11 +262,7 @@ class SQLConn : public classbase
        SQLConn(InspIRCd* SI, Module* m, const SQLhost& hi)
        : Instance(SI), mod(m), host(hi)
        {
-               if (OpenDB() == SQLITE_OK)
-               {
-                       Instance->Log(DEBUG, "Opened sqlite DB: " + host.host);
-               }
-               else
+               if (OpenDB() != SQLITE_OK)
                {
                        Instance->Log(DEFAULT, "WARNING: Could not open DB with id: " + host.id);
                        CloseDB();
@@ -355,12 +344,10 @@ class SQLConn : public classbase
                {
                        std::string error(errmsg);
                        sqlite3_free(errmsg);
-                       Instance->Log(DEBUG, "Query failed: " + ConvToStr(errmsg));
                        delete[] query;
                        delete res;
                        return SQLerror(QSEND_FAIL, error);
                }
-               Instance->Log(DEBUG, "Dispatched query successfully. ID: %d resulting rows %d", req.id, res->Rows());
                delete[] query;
 
                results.push_back(res);
@@ -379,7 +366,7 @@ class SQLConn : public classbase
        {
                paramlist* p = (paramlist*)params;
                ((SQLConn*)(*p)[0])->AffectedReady(((SQLite3Result*)(*p)[1]));
-       }\r
+       }
 
        void ResultReady(SQLite3Result *res, int cols, char **data, char **colnames)
        {
@@ -400,7 +387,6 @@ class SQLConn : public classbase
        {
                sqlite3_interrupt(conn);
                sqlite3_close(conn);
-               Instance->Log(DEBUG, "Closed sqlite DB: " + host.host);
        }
 
        SQLhost GetConfHost()
@@ -423,7 +409,6 @@ class SQLConn : public classbase
                                 * the pointer to NULL. We cannot just cancel the query as the result will still come
                                 * through at some point...and it could get messy if we play with invalid pointers...
                                 */
-                               Instance->Log(DEBUG, "Looks like we're handling a zombie query from a module which unloaded before it got a result..fun. ID: " + ConvToStr(res->GetId()));
                                delete res;
                        }
                        results.pop_front();
@@ -483,19 +468,18 @@ class ModuleSQLite3 : public Module
        ModuleSQLite3(InspIRCd* Me)
        : Module::Module(Me), currid(0)
        {
-               ServerInstance->UseInterface("SQLutils");
+               ServerInstance->Modules->UseInterface("SQLutils");
 
-               if (!ServerInstance->PublishFeature("SQL", this))
+               if (!ServerInstance->Modules->PublishFeature("SQL", this))
                {
                        throw ModuleException("m_sqlite3: Unable to publish feature 'SQL'");
                }
 
                resultnotify = new ResultNotifier(ServerInstance, this);
-               ServerInstance->Log(DEBUG,"Bound notifier to 127.0.0.1:%d",resultnotify->GetPort());
 
                ReadConf();
 
-               ServerInstance->PublishInterface("SQL", this);
+               ServerInstance->Modules->PublishInterface("SQL", this);
        }
 
        virtual ~ModuleSQLite3()
@@ -507,9 +491,9 @@ class ModuleSQLite3 : public Module
                resultnotify->OnError(I_ERR_SOCKET);
                resultnotify->ClosePending = true;
                delete resultnotify;
-               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)
@@ -637,7 +621,6 @@ class ModuleSQLite3 : public Module
                {
                        SQLrequest* req = (SQLrequest*)request;
                        ConnMap::iterator iter;
-                       ServerInstance->Log(DEBUG, "Got query: '%s' with %d replacement parameters on id '%s'", req->query.q.c_str(), req->query.p.size(), req->dbid.c_str());
                        if((iter = connections.find(req->dbid)) != connections.end())
                        {
                                req->id = NewID();
@@ -650,7 +633,6 @@ class ModuleSQLite3 : public Module
                                return NULL;
                        }
                }
-               ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId());
                return NULL;
        }
 
@@ -674,24 +656,5 @@ void ResultNotifier::Dispatch()
        ((ModuleSQLite3*)mod)->SendQueue();
 }
 
-class ModuleSQLite3Factory : public ModuleFactory
-{
-  public:
-       ModuleSQLite3Factory()
-       {
-       }
-
-       ~ModuleSQLite3Factory()
-       {
-       }
-
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleSQLite3(Me);
-       }
-};
+MODULE_INIT(ModuleSQLite3);
 
-extern "C" void * init_module( void )
-{
-       return new ModuleSQLite3Factory;
-}