]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_pgsql.cpp
m_pgsql Same fix as 0e09600a431d0e0f2cde6457e088d84caf6d6f5d
[user/henk/code/inspircd.git] / src / modules / extra / m_pgsql.cpp
index 2d8b832644eee9be3c9e0c3126c1235f1330800e..ac247548ac35c303a805734c483f112bb0c3f3f5 100644 (file)
@@ -1,16 +1,27 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2006-2007, 2009 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006-2007, 2009 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 #include <cstdlib>
 #include <sstream>
@@ -141,7 +152,7 @@ class SQLConn : public SQLProvider, public EventHandler
        {
                if (!DoConnect())
                {
-                       ServerInstance->Logs->Log("m_pgsql",DEFAULT, "WARNING: Could not connect to database " + tag->getString("id")); 
+                       ServerInstance->Logs->Log("m_pgsql",DEFAULT, "WARNING: Could not connect to database " + tag->getString("id"));
                        DelayReconnect();
                }
        }
@@ -320,7 +331,7 @@ restart:
                        }
                        else
                        {
-                               qinprog.q = "";
+                               qinprog.q.clear();
                        }
                }
                else
@@ -401,16 +412,16 @@ restart:
                                if (param < p.size())
                                {
                                        std::string parm = p[param++];
-                                       char buffer[MAXBUF];
+                                       std::vector<char> buffer(parm.length() * 2 + 1);
 #ifdef PGSQL_HAS_ESCAPECONN
                                        int error;
-                                       PQescapeStringConn(sql, buffer, parm.c_str(), parm.length(), &error);
+                                       size_t escapedsize = PQescapeStringConn(sql, &buffer[0], parm.data(), parm.length(), &error);
                                        if (error)
                                                ServerInstance->Logs->Log("m_pgsql", DEBUG, "BUG: Apparently PQescapeStringConn() failed");
 #else
-                                       PQescapeString         (buffer, parm.c_str(), parm.length());
+                                       size_t escapedsize = PQescapeString(&buffer[0], parm.data(), parm.length());
 #endif
-                                       res.append(buffer);
+                                       res.append(&buffer[0], escapedsize);
                                }
                        }
                }
@@ -436,16 +447,16 @@ restart:
                                if (it != p.end())
                                {
                                        std::string parm = it->second;
-                                       char buffer[MAXBUF];
+                                       std::vector<char> buffer(parm.length() * 2 + 1);
 #ifdef PGSQL_HAS_ESCAPECONN
                                        int error;
-                                       PQescapeStringConn(sql, buffer, parm.c_str(), parm.length(), &error);
+                                       size_t escapedsize = PQescapeStringConn(sql, &buffer[0], parm.data(), parm.length(), &error);
                                        if (error)
                                                ServerInstance->Logs->Log("m_pgsql", DEBUG, "BUG: Apparently PQescapeStringConn() failed");
 #else
-                                       PQescapeString         (buffer, parm.c_str(), parm.length());
+                                       size_t escapedsize = PQescapeString(&buffer[0], parm.data(), parm.length());
 #endif
-                                       res.append(buffer);
+                                       res.append(&buffer[0], escapedsize);
                                }
                        }
                }
@@ -502,7 +513,7 @@ class ModulePgSQL : public Module
                ReadConf();
 
                Implementation eventlist[] = { I_OnUnloadModule, I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, this, 2);
+               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
        virtual ~ModulePgSQL()