]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_pgsql.cpp
Add extra parameter to OnUserPreNotice and OnUserPrePrivmsg, CUList &exempt_list...
[user/henk/code/inspircd.git] / src / modules / extra / m_pgsql.cpp
index a60fcb5f6a2c9c824ba98a3222a90cf84af4122e..ca74f4223cd8ca225fed2a5b5e67db0f9ef1b263 100644 (file)
@@ -25,7 +25,7 @@
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "helperfuncs.h"
+
 #include "inspircd.h"
 #include "configreader.h"
 
@@ -69,13 +69,13 @@ enum SQLstatus { CREAD, CWRITE, WREAD, WWRITE, RREAD, RWRITE };
 class SQLhost
 {
  public:
-       std::string             id;             /* Database handle id */
-       std::string     host;   /* Database server hostname */
+       std::string     id;     /* Database handle id */
+       std::string     host;   /* Database server hostname */
        unsigned int    port;   /* Database server port */
-       std::string     name;   /* Database name */
-       std::string     user;   /* Database username */
-       std::string     pass;   /* Database password */
-       bool                    ssl;    /* If we should require SSL */
+       std::string     name;   /* Database name */
+       std::string     user;   /* Database username */
+       std::string     pass;   /* Database password */
+       bool            ssl;    /* If we should require SSL */
  
        SQLhost()
        {
@@ -87,6 +87,8 @@ class SQLhost
        }
 };
 
+/** Used to resolve sql server hostnames
+ */
 class SQLresolver : public Resolver
 {
  private:
@@ -94,7 +96,7 @@ class SQLresolver : public Resolver
        ModulePgSQL* mod;
  public:
        SQLresolver(ModulePgSQL* m, InspIRCd* Instance, const SQLhost& hi)
-       : Resolver(Instance, hi.host, DNS_QUERY_FORWARD), host(hi), mod(m)
+       : Resolver(Instance, hi.host, DNS_QUERY_FORWARD, (Module*)m), host(hi), mod(m)
        {
        }
 
@@ -523,7 +525,7 @@ public:
                
                sqlsuccess = new char[strlen(SQLSUCCESS)+1];
                
-               strcpy(sqlsuccess, SQLSUCCESS);
+               strlcpy(sqlsuccess, SQLSUCCESS, strlen(SQLSUCCESS)+1);
 
                OnRehash("");
        }
@@ -575,9 +577,16 @@ public:
                                /* Conversion failed, assume it's a host */
                                SQLresolver* resolver;
                                
-                               resolver = new SQLresolver(this, ServerInstance, host);
-                               
-                               ServerInstance->AddResolver(resolver);
+                               try
+                               {
+                                       resolver = new SQLresolver(this, ServerInstance, host);
+                                       
+                                       ServerInstance->AddResolver(resolver);
+                               }
+                               catch(...)
+                               {
+                                       ServerInstance->Log(DEBUG, "Couldn't make a SQLresolver..this connection is gonna diiiiiie...actually we just won't create it");
+                               }
                        }
                        else
                        {
@@ -650,7 +659,7 @@ public:
                
        virtual Version GetVersion()
        {
-               return Version(1, 0, 0, 0, VF_VENDOR|VF_SERVICEPROVIDER);
+               return Version(1, 1, 0, 0, VF_VENDOR|VF_SERVICEPROVIDER, API_VERSION);
        }
        
        virtual ~ModulePgSQL()
@@ -731,13 +740,12 @@ bool SQLConn::DoConnect()
        }
        
        this->state = I_CONNECTING;
-       if (!this->Instance->SE->AddFd(this->fd,false,X_ESTAB_MODULE))
+       if (!this->Instance->SE->AddFd(this))
        {
                Instance->Log(DEBUG, "A PQsocket cant be added to the socket engine!");
                Close();
                return false;
        }
-       this->Instance->socket_ref[this->fd] = this;
        
        /* Socket all hooked into the engine, now to tell PgSQL to start connecting */
        
@@ -747,9 +755,7 @@ bool SQLConn::DoConnect()
 void SQLConn::Close()
 {
        Instance->Log(DEBUG,"SQLConn::Close");
-       
-       if(this->fd > 01)
-               Instance->socket_ref[this->fd] = NULL;
+
        this->fd = -1;
        this->state = I_ERROR;
        this->OnError(I_ERR_SOCKET);
@@ -843,6 +849,9 @@ bool SQLConn::DoConnectedPoll()
                        {
                                /* ..and the result */
                                PgSQLresult reply(us, to, query.id, result);
+
+                               /* Fix by brain, make sure the original query gets sent back in the reply */
+                               reply.query = query.query.q;
                                
                                Instance->Log(DEBUG, "Got result, status code: %s; error message: %s", PQresStatus(PQresultStatus(result)), PQresultErrorMessage(result));      
                                
@@ -1119,8 +1128,7 @@ SQLerror SQLConn::DoQuery(SQLrequest &req)
 #ifdef PGSQL_HAS_ESCAPECONN
                                                len = PQescapeStringConn(sql, queryend, req.query.p.front().c_str(), req.query.p.front().length(), &error);
 #else
-                                               len = PQescapeStringConn(queryend, req.query.p.front().c_str(), req.query.p.front().length());
-                                               error = 0;
+                                               len = PQescapeString         (queryend, req.query.p.front().c_str(), req.query.p.front().length());
 #endif
                                                if(error)
                                                {
@@ -1159,13 +1167,13 @@ SQLerror SQLConn::DoQuery(SQLrequest &req)
                        {
                                Instance->Log(DEBUG, "Dispatched query successfully");
                                qinprog = true;
-                               DELETE(query);
+                               delete[] query;
                                return SQLerror();
                        }
                        else
                        {
                                Instance->Log(DEBUG, "Failed to dispatch query: %s", PQerrorMessage(sql));
-                               DELETE(query);
+                               delete[] query;
                                return SQLerror(QSEND_FAIL, PQerrorMessage(sql));
                        }
                }