]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_pgsql.cpp
Fix whitelist check for a badchan redirect (#1676).
[user/henk/code/inspircd.git] / src / modules / extra / m_pgsql.cpp
index 25ce6c7f1168f72d281245576a161a1826c1c729..3484aeca2bd52daea4ba23c1064942581bab7ee7 100644 (file)
@@ -87,6 +87,16 @@ class PgSQLresult : public SQL::Result
        PGresult* res;
        int currentrow;
        int rows;
+       std::vector<std::string> colnames;
+
+       void getColNames()
+       {
+               colnames.resize(PQnfields(res));
+               for(unsigned int i=0; i < colnames.size(); i++)
+               {
+                       colnames[i] = PQfname(res, i);
+               }
+       }
  public:
        PgSQLresult(PGresult* result) : res(result), currentrow(0)
        {
@@ -107,11 +117,25 @@ class PgSQLresult : public SQL::Result
 
        void GetCols(std::vector<std::string>& result) CXX11_OVERRIDE
        {
-               result.resize(PQnfields(res));
-               for(unsigned int i=0; i < result.size(); i++)
+               if (colnames.empty())
+                       getColNames();
+               result = colnames;
+       }
+
+       bool HasColumn(const std::string& column, size_t& index) CXX11_OVERRIDE
+       {
+               if (colnames.empty())
+                       getColNames();
+
+               for (size_t i = 0; i < colnames.size(); ++i)
                {
-                       result[i] = PQfname(res, i);
+                       if (colnames[i] == column)
+                       {
+                               index = i;
+                               return true;
+                       }
                }
+               return false;
        }
 
        SQL::Field GetValue(int row, int column)
@@ -274,6 +298,7 @@ class SQLConn : public SQL::Provider, public EventHandler
                                SocketEngine::ChangeEventMask(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE);
                                status = WWRITE;
                                DoConnectedPoll();
+                               return true;
                        default:
                                return true;
                }
@@ -367,6 +392,7 @@ restart:
                                SocketEngine::ChangeEventMask(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE);
                                status = WWRITE;
                                DoConnectedPoll();
+                               return true;
                        default:
                                return true;
                }
@@ -392,6 +418,7 @@ restart:
 
        void Submit(SQL::Query *req, const std::string& q) CXX11_OVERRIDE
        {
+               ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Executing PostgreSQL query: " + q);
                if (qinprog.q.empty())
                {
                        DoQuery(QueueItem(req,q));
@@ -522,7 +549,7 @@ class ModulePgSQL : public Module
                ConfigTagList tags = ServerInstance->Config->ConfTags("database");
                for(ConfigIter i = tags.first; i != tags.second; i++)
                {
-                       if (i->second->getString("module", "pgsql") != "pgsql")
+                       if (!stdalgo::string::equalsci(i->second->getString("module"), "pgsql"))
                                continue;
                        std::string id = i->second->getString("id");
                        ConnMap::iterator curr = connections.find(id);