1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
26 #include "configreader.h"
30 /* $ModDesc: PostgreSQL Service Provider module for all other m_sql* modules, uses v2 of the SQL API */
31 /* $CompileFlags: -I`pg_config --includedir` `perl extra/pgsql_config.pl` */
32 /* $LinkerFlags: -L`pg_config --libdir` -lpq */
33 /* $ModDep: m_sqlv2.h */
36 /* SQLConn rewritten by peavey to
37 * use EventHandler instead of
38 * InspSocket. This is much neater
39 * and gives total control of destroy
40 * and delete of resources.
43 /* Forward declare, so we can have the typedef neatly at the top */
46 typedef std::map<std::string, SQLConn*> ConnMap;
48 /* CREAD, Connecting and wants read event
49 * CWRITE, Connecting and wants write event
50 * WREAD, Connected/Working and wants read event
51 * WWRITE, Connected/Working and wants write event
52 * RREAD, Resetting and wants read event
53 * RWRITE, Resetting and wants write event
55 enum SQLstatus { CREAD, CWRITE, WREAD, WWRITE, RREAD, RWRITE };
57 /** SQLhost::GetDSN() - Overload to return correct DSN for PostgreSQL
59 std::string SQLhost::GetDSN()
61 std::ostringstream conninfo("connect_timeout = '2'");
64 conninfo << " hostaddr = '" << ip << "'";
67 conninfo << " port = '" << port << "'";
70 conninfo << " dbname = '" << name << "'";
73 conninfo << " user = '" << user << "'";
76 conninfo << " password = '" << pass << "'";
79 conninfo << " sslmode = 'require'";
81 return conninfo.str();
84 /** Used to resolve sql server hostnames
86 class SQLresolver : public Resolver
92 SQLresolver(Module* m, InspIRCd* Instance, const SQLhost& hi, bool &cached)
93 : Resolver(Instance, hi.host, DNS_QUERY_FORWARD, cached, (Module*)m), host(hi), mod(m)
97 virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
99 virtual void OnError(ResolverError e, const std::string &errormessage)
101 ServerInstance->Log(DEBUG, "DNS lookup failed (%s), dying horribly", errormessage.c_str());
105 /** QueryQueue, a queue of queries waiting to be executed.
106 * This maintains two queues internally, one for 'priority'
107 * queries and one for less important ones. Each queue has
108 * new queries appended to it and ones to execute are popped
109 * off the front. This keeps them flowing round nicely and no
110 * query should ever get 'stuck' for too long. If there are
111 * queries in the priority queue they will be executed first,
112 * 'unimportant' queries will only be executed when the
113 * priority queue is empty.
115 * We store lists of SQLrequest's here, by value as we want to avoid storing
116 * any data allocated inside the client module (in case that module is unloaded
117 * while the query is in progress).
119 * Because we want to work on the current SQLrequest in-situ, we need a way
120 * of accessing the request we are currently processing, QueryQueue::front(),
121 * but that call needs to always return the same request until that request
122 * is removed from the queue, this is what the 'which' variable is. New queries are
123 * always added to the back of one of the two queues, but if when front()
124 * is first called then the priority queue is empty then front() will return
125 * a query from the normal queue, but if a query is then added to the priority
126 * queue then front() must continue to return the front of the *normal* queue
127 * until pop() is called.
130 class QueryQueue : public classbase
133 typedef std::deque<SQLrequest> ReqDeque;
135 ReqDeque priority; /* The priority queue */
136 ReqDeque normal; /* The 'normal' queue */
137 enum { PRI, NOR, NON } which; /* Which queue the currently active element is at the front of */
145 void push(const SQLrequest &q)
147 //ServerInstance->Log(DEBUG, "QueryQueue::push(): Adding %s query to queue: %s", ((q.pri) ? "priority" : "non-priority"), q.query.q.c_str());
150 priority.push_back(q);
157 if((which == PRI) && priority.size())
159 priority.pop_front();
161 else if((which == NOR) && normal.size())
169 /* Silently do nothing if there was no element to pop() */
177 return priority.front();
179 return normal.front();
184 return priority.front();
190 return normal.front();
193 /* This will probably result in a segfault,
194 * but the caller should have checked totalsize()
195 * first so..meh - moron :p
198 return priority.front();
202 std::pair<int, int> size()
204 return std::make_pair(priority.size(), normal.size());
209 return priority.size() + normal.size();
212 void PurgeModule(Module* mod)
214 DoPurgeModule(mod, priority);
215 DoPurgeModule(mod, normal);
219 void DoPurgeModule(Module* mod, ReqDeque& q)
221 for(ReqDeque::iterator iter = q.begin(); iter != q.end(); iter++)
223 if(iter->GetSource() == mod)
225 if(iter->id == front().id)
227 /* It's the currently active query.. :x */
228 iter->SetSource(NULL);
232 /* It hasn't been executed yet..just remove it */
233 iter = q.erase(iter);
240 /** PgSQLresult is a subclass of the mostly-pure-virtual class SQLresult.
241 * All SQL providers must create their own subclass and define it's methods using that
242 * database library's data retriveal functions. The aim is to avoid a slow and inefficient process
243 * of converting all data to a common format before it reaches the result structure. This way
244 * data is passes to the module nearly as directly as if it was using the API directly itself.
247 class PgSQLresult : public SQLresult
254 SQLfieldList* fieldlist;
255 SQLfieldMap* fieldmap;
257 PgSQLresult(Module* self, Module* to, unsigned long id, PGresult* result)
258 : SQLresult(self, to, id), res(result), currentrow(0), fieldlist(NULL), fieldmap(NULL)
260 rows = PQntuples(res);
261 cols = PQnfields(res);
263 //ServerInstance->Log(DEBUG, "Created new PgSQL result; %d rows, %d columns, %s affected", rows, cols, PQcmdTuples(res));
268 /* If we allocated these, free them... */
282 return atoi(PQcmdTuples(res));
292 return PQnfields(res);
295 virtual std::string ColName(int column)
297 char* name = PQfname(res, column);
299 return (name) ? name : "";
302 virtual int ColNum(const std::string &column)
304 int n = PQfnumber(res, column.c_str());
308 throw SQLbadColName();
316 virtual SQLfield GetValue(int row, int column)
318 char* v = PQgetvalue(res, row, column);
322 return SQLfield(std::string(v, PQgetlength(res, row, column)), PQgetisnull(res, row, column));
326 //ServerInstance->Log(DEBUG, "PQgetvalue returned a null pointer..nobody wants to tell us what this means");
327 throw SQLbadColName();
331 virtual SQLfieldList& GetRow()
333 /* In an effort to reduce overhead we don't actually allocate the list
334 * until the first time it's needed...so...
342 fieldlist = new SQLfieldList;
345 if(currentrow < PQntuples(res))
347 int cols = PQnfields(res);
349 for(int i = 0; i < cols; i++)
351 fieldlist->push_back(GetValue(currentrow, i));
360 virtual SQLfieldMap& GetRowMap()
362 /* In an effort to reduce overhead we don't actually allocate the map
363 * until the first time it's needed...so...
371 fieldmap = new SQLfieldMap;
374 if(currentrow < PQntuples(res))
376 int cols = PQnfields(res);
378 for(int i = 0; i < cols; i++)
380 fieldmap->insert(std::make_pair(ColName(i), GetValue(currentrow, i)));
389 virtual SQLfieldList* GetRowPtr()
391 SQLfieldList* fl = new SQLfieldList;
393 if(currentrow < PQntuples(res))
395 int cols = PQnfields(res);
397 for(int i = 0; i < cols; i++)
399 fl->push_back(GetValue(currentrow, i));
408 virtual SQLfieldMap* GetRowMapPtr()
410 SQLfieldMap* fm = new SQLfieldMap;
412 if(currentrow < PQntuples(res))
414 int cols = PQnfields(res);
416 for(int i = 0; i < cols; i++)
418 fm->insert(std::make_pair(ColName(i), GetValue(currentrow, i)));
427 virtual void Free(SQLfieldMap* fm)
432 virtual void Free(SQLfieldList* fl)
438 /** SQLConn represents one SQL session.
440 class SQLConn : public EventHandler
444 SQLhost confhost; /* The <database> entry */
445 Module* us; /* Pointer to the SQL provider itself */
446 PGconn* sql; /* PgSQL database connection handle */
447 SQLstatus status; /* PgSQL database connection status */
448 bool qinprog; /* If there is currently a query in progress */
449 QueryQueue queue; /* Queue of queries waiting to be executed on this connection */
450 time_t idle; /* Time we last heard from the database */
455 SQLConn(InspIRCd* SI, Module* self, const SQLhost& hi)
456 : EventHandler(), Instance(SI), confhost(hi), us(self), sql(NULL), status(CWRITE), qinprog(false)
459 idle = this->Instance->Time();
463 Instance->Log(DEFAULT, "WARNING: Could not connect to database with id: " + ConvToStr(hi.id));
472 virtual bool Writeable()
477 virtual bool Readable()
482 virtual void HandleEvent(EventType et, int errornum)
507 if(!(sql = PQconnectStart(confhost.GetDSN().c_str())))
509 Instance->Log(DEBUG, "Couldn't allocate PGconn structure, aborting: %s", PQerrorMessage(sql));
513 if(PQstatus(sql) == CONNECTION_BAD)
515 Instance->Log(DEBUG, "PQconnectStart failed: %s", PQerrorMessage(sql));
520 if(PQsetnonblocking(sql, 1) == -1)
522 Instance->Log(DEBUG, "Couldn't set connection nonblocking: %s", PQerrorMessage(sql));
526 this->fd = PQsocket(sql);
528 Instance->Log(DEBUG, "New SQL socket: %d", this->fd);
532 Instance->Log(DEBUG, "PQsocket says we have an invalid FD: %d", this->fd);
537 if (!this->Instance->SE->AddFd(this))
539 Instance->Log(DEBUG, "A PQsocket cant be added to the socket engine!");
544 /* Socket all hooked into the engine, now to tell PgSQL to start connecting */
551 switch(PQconnectPoll(sql))
553 case PGRES_POLLING_WRITING:
557 case PGRES_POLLING_READING:
560 case PGRES_POLLING_FAILED:
562 case PGRES_POLLING_OK:
564 return DoConnectedPoll();
570 bool DoConnectedPoll()
572 if(!qinprog && queue.totalsize())
574 /* There's no query currently in progress, and there's queries in the queue. */
575 SQLrequest& query = queue.front();
579 if(PQconsumeInput(sql))
581 Instance->Log(DEBUG, "PQconsumeInput succeeded");
583 /* We just read stuff from the server, that counts as it being alive
584 * so update the idle-since time :p
586 idle = this->Instance->Time();
590 //ServerInstance->Log(DEBUG, "Still busy processing command though");
594 //ServerInstance->Log(DEBUG, "Looks like we have a result to process!");
596 /* Grab the request we're processing */
597 SQLrequest& query = queue.front();
599 Instance->Log(DEBUG, "ID is %lu", query.id);
601 /* Get a pointer to the module we're about to return the result to */
602 Module* to = query.GetSource();
604 /* Fetch the result.. */
605 PGresult* result = PQgetResult(sql);
607 /* PgSQL would allow a query string to be sent which has multiple
608 * queries in it, this isn't portable across database backends and
609 * we don't want modules doing it. But just in case we make sure we
610 * drain any results there are and just use the last one.
611 * If the module devs are behaving there will only be one result.
613 while (PGresult* temp = PQgetResult(sql))
621 /* ..and the result */
622 PgSQLresult reply(us, to, query.id, result);
624 /* Fix by brain, make sure the original query gets sent back in the reply */
625 reply.query = query.query.q;
627 Instance->Log(DEBUG, "Got result, status code: %s; error message: %s", PQresStatus(PQresultStatus(result)), PQresultErrorMessage(result));
629 switch(PQresultStatus(result))
631 case PGRES_EMPTY_QUERY:
632 case PGRES_BAD_RESPONSE:
633 case PGRES_FATAL_ERROR:
634 reply.error.Id(QREPLY_FAIL);
635 reply.error.Str(PQresultErrorMessage(result));
637 /* No action, other values are not errors */
642 /* PgSQLresult's destructor will free the PGresult */
646 /* If the client module is unloaded partway through a query then the provider will set
647 * the pointer to NULL. We cannot just cancel the query as the result will still come
648 * through at some point...and it could get messy if we play with invalid pointers...
650 Instance->Log(DEBUG, "Looks like we're handling a zombie query from a module which unloaded before it got a result..fun. ID: %lu", query.id);
659 Instance->Log(DEBUG, "Eh!? We just got a read event, and connection isn't busy..but no result :(");
665 /* I think we'll assume this means the server died...it might not,
666 * but I think that any error serious enough we actually get here
667 * deserves to reconnect [/excuse]
668 * Returning true so the core doesn't try and close the connection.
670 Instance->Log(DEBUG, "PQconsumeInput failed: %s", PQerrorMessage(sql));
678 switch(PQresetPoll(sql))
680 case PGRES_POLLING_WRITING:
681 //ServerInstance->Log(DEBUG, "PGresetPoll: PGRES_POLLING_WRITING");
685 case PGRES_POLLING_READING:
686 //ServerInstance->Log(DEBUG, "PGresetPoll: PGRES_POLLING_READING");
689 case PGRES_POLLING_FAILED:
690 //ServerInstance->Log(DEBUG, "PGresetPoll: PGRES_POLLING_FAILED: %s", PQerrorMessage(sql));
692 case PGRES_POLLING_OK:
693 //ServerInstance->Log(DEBUG, "PGresetPoll: PGRES_POLLING_OK");
695 return DoConnectedPoll();
697 //ServerInstance->Log(DEBUG, "PGresetPoll: wtf?");
704 switch(PQstatus(sql))
706 case CONNECTION_STARTED:
707 Instance->Log(DEBUG, "PQstatus: CONNECTION_STARTED: Waiting for connection to be made.");
710 case CONNECTION_MADE:
711 Instance->Log(DEBUG, "PQstatus: CONNECTION_MADE: Connection OK; waiting to send.");
714 case CONNECTION_AWAITING_RESPONSE:
715 Instance->Log(DEBUG, "PQstatus: CONNECTION_AWAITING_RESPONSE: Waiting for a response from the server.");
718 case CONNECTION_AUTH_OK:
719 Instance->Log(DEBUG, "PQstatus: CONNECTION_AUTH_OK: Received authentication; waiting for backend start-up to finish.");
722 case CONNECTION_SSL_STARTUP:
723 Instance->Log(DEBUG, "PQstatus: CONNECTION_SSL_STARTUP: Negotiating SSL encryption.");
726 case CONNECTION_SETENV:
727 Instance->Log(DEBUG, "PQstatus: CONNECTION_SETENV: Negotiating environment-driven parameter settings.");
731 Instance->Log(DEBUG, "PQstatus: ???");
737 /* Always return true here, false would close the socket - we need to do that ourselves with the pgsql API */
738 Instance->Log(DEBUG, "OnDataReady(): status = %s", StatusStr());
744 /* Always return true here, false would close the socket - we need to do that ourselves with the pgsql API */
745 Instance->Log(DEBUG, "OnWriteReady(): status = %s", StatusStr());
751 Instance->Log(DEBUG, "OnConnected(): status = %s", StatusStr());
757 Instance->Log(DEBUG, "Initiating reconnect");
758 if(PQresetStart(sql))
760 /* Successfully initiatied database reconnect,
761 * set flags so PQresetPoll() will be called appropriately
769 Instance->Log(DEBUG, "Failed to initiate reconnect...fun");
778 if((status == CREAD) || (status == CWRITE))
782 else if((status == RREAD) || (status == RWRITE))
788 ret = DoConnectedPoll();
794 Instance->Log(DEBUG, "Error flushing write queue: %s", PQerrorMessage(sql));
797 Instance->Log(DEBUG, "Successfully flushed write queue (or there was nothing to write)");
800 Instance->Log(DEBUG, "Not all of the write queue written, triggering write event so we can have another go");
808 const char* StatusStr()
810 if(status == CREAD) return "CREAD";
811 if(status == CWRITE) return "CWRITE";
812 if(status == WREAD) return "WREAD";
813 if(status == WWRITE) return "WWRITE";
814 return "Err...what, erm..BUG!";
817 SQLerror DoQuery(SQLrequest &req)
819 if((status == WREAD) || (status == WWRITE))
823 /* Parse the command string and dispatch it */
825 /* Pointer to the buffer we screw around with substitution in */
827 /* Pointer to the current end of query, where we append new stuff */
829 /* Total length of the unescaped parameters */
830 unsigned int paramlen;
834 for(ParamL::iterator i = req.query.p.begin(); i != req.query.p.end(); i++)
836 paramlen += i->size();
839 /* To avoid a lot of allocations, allocate enough memory for the biggest the escaped query could possibly be.
840 * sizeofquery + (totalparamlength*2) + 1
842 * The +1 is for null-terminating the string for PQsendQuery()
845 query = new char[req.query.q.length() + (paramlen*2) + 1];
848 /* Okay, now we have a buffer large enough we need to start copying the query into it and escaping and substituting
849 * the parameters into it...
852 for(unsigned int i = 0; i < req.query.q.length(); i++)
854 if(req.query.q[i] == '?')
856 /* We found a place to substitute..what fun.
857 * Use the PgSQL calls to escape and write the
858 * escaped string onto the end of our query buffer,
859 * then we "just" need to make sure queryend is
860 * pointing at the right place.
863 if(req.query.p.size())
868 #ifdef PGSQL_HAS_ESCAPECONN
869 len = PQescapeStringConn(sql, queryend, req.query.p.front().c_str(), req.query.p.front().length(), &error);
871 len = PQescapeString (queryend, req.query.p.front().c_str(), req.query.p.front().length());
875 Instance->Log(DEBUG, "Apparently PQescapeStringConn() failed somehow...don't know how or what to do...");
878 Instance->Log(DEBUG, "Appended %d bytes of escaped string onto the query", len);
880 /* Incremenet queryend to the end of the newly escaped parameter */
883 /* Remove the parameter we just substituted in */
884 req.query.p.pop_front();
888 Instance->Log(DEBUG, "Found a substitution location but no parameter to substitute :|");
894 *queryend = req.query.q[i];
899 /* Null-terminate the query */
902 Instance->Log(DEBUG, "Attempting to dispatch query: %s", query);
906 if(PQsendQuery(sql, query))
908 Instance->Log(DEBUG, "Dispatched query successfully");
915 Instance->Log(DEBUG, "Failed to dispatch query: %s", PQerrorMessage(sql));
917 return SQLerror(QSEND_FAIL, PQerrorMessage(sql));
922 return SQLerror(BAD_CONN, "Can't query until connection is complete");
925 SQLerror Query(const SQLrequest &req)
929 if(!qinprog && queue.totalsize())
931 /* There's no query currently in progress, and there's queries in the queue. */
932 SQLrequest& query = queue.front();
933 return DoQuery(query);
942 void OnUnloadModule(Module* mod)
944 queue.PurgeModule(mod);
947 const SQLhost GetConfHost()
958 Instance->Log(DEBUG,"SQLConn::Close");
960 if (!this->Instance->SE->DelFd(this))
962 Instance->Log(DEBUG, "PQsocket cant be removed from the socket engine!");
976 class ModulePgSQL : public Module
980 ConnMap deadconnections;
981 unsigned long currid;
985 ModulePgSQL(InspIRCd* Me)
986 : Module::Module(Me), currid(0)
988 ServerInstance->UseInterface("SQLutils");
990 sqlsuccess = new char[strlen(SQLSUCCESS)+1];
992 strlcpy(sqlsuccess, SQLSUCCESS, strlen(SQLSUCCESS));
994 if (!ServerInstance->PublishFeature("SQL", this))
996 throw ModuleException("m_pgsql: Unable to publish feature 'SQL'");
1001 ServerInstance->PublishInterface("SQL", this);
1004 virtual ~ModulePgSQL()
1006 ClearAllConnections();
1007 delete[] sqlsuccess;
1008 ServerInstance->UnpublishInterface("SQL", this);
1009 ServerInstance->UnpublishFeature("SQL");
1010 ServerInstance->DoneWithInterface("SQLutils");
1013 void Implements(char* List)
1015 List[I_OnUnloadModule] = List[I_OnRequest] = List[I_OnRehash] = List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnUserDisconnect] = 1;
1018 virtual void OnRehash(userrec* user, const std::string ¶meter)
1023 bool HasHost(const SQLhost &host)
1025 for (ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++)
1027 if (host == iter->second->GetConfHost())
1033 bool HostInConf(const SQLhost &h)
1035 ConfigReader conf(ServerInstance);
1036 for(int i = 0; i < conf.Enumerate("database"); i++)
1039 host.id = conf.ReadValue("database", "id", i);
1040 host.host = conf.ReadValue("database", "hostname", i);
1041 host.port = conf.ReadInteger("database", "port", i, true);
1042 host.name = conf.ReadValue("database", "name", i);
1043 host.user = conf.ReadValue("database", "username", i);
1044 host.pass = conf.ReadValue("database", "password", i);
1045 host.ssl = conf.ReadFlag("database", "ssl", i);
1054 ClearOldConnections();
1056 ConfigReader conf(ServerInstance);
1057 for(int i = 0; i < conf.Enumerate("database"); i++)
1061 insp_inaddr blargle;
1063 host.id = conf.ReadValue("database", "id", i);
1064 host.host = conf.ReadValue("database", "hostname", i);
1065 host.port = conf.ReadInteger("database", "port", i, true);
1066 host.name = conf.ReadValue("database", "name", i);
1067 host.user = conf.ReadValue("database", "username", i);
1068 host.pass = conf.ReadValue("database", "password", i);
1069 host.ssl = conf.ReadFlag("database", "ssl", i);
1074 ipvalid = insp_aton(host.host.c_str(), &blargle);
1078 /* The conversion succeeded, we were given an IP and we can give it straight to SQLConn */
1079 host.ip = host.host;
1080 this->AddConn(host);
1082 else if(ipvalid == 0)
1084 /* Conversion failed, assume it's a host */
1085 SQLresolver* resolver;
1090 resolver = new SQLresolver(this, ServerInstance, host, cached);
1091 ServerInstance->AddResolver(resolver, cached);
1095 /* THE WORLD IS COMING TO AN END! */
1096 ServerInstance->Log(DEBUG, "Couldn't make a SQLresolver..this connection is gonna diiiiiie...actually we just won't create it");
1101 /* Invalid address family, die horribly. */
1102 ServerInstance->Log(DEBUG, "insp_aton failed returning -1, oh noes.");
1107 void ClearOldConnections()
1109 ConnMap::iterator iter,safei;
1110 for (iter = connections.begin(); iter != connections.end(); iter++)
1112 if (!HostInConf(iter->second->GetConfHost()))
1114 DELETE(iter->second);
1117 connections.erase(safei);
1122 void ClearAllConnections()
1124 ConnMap::iterator i;
1125 while ((i = connections.begin()) != connections.end())
1127 connections.erase(i);
1132 void AddConn(const SQLhost& hi)
1136 ServerInstance->Log(DEFAULT, "WARNING: A pgsql connection with id: %s already exists, possibly due to DNS delay. Aborting connection attempt.", hi.id.c_str());
1142 /* The conversion succeeded, we were given an IP and we can give it straight to SQLConn */
1143 newconn = new SQLConn(ServerInstance, this, hi);
1145 connections.insert(std::make_pair(hi.id, newconn));
1148 virtual char* OnRequest(Request* request)
1150 if(strcmp(SQLREQID, request->GetId()) == 0)
1152 SQLrequest* req = (SQLrequest*)request;
1153 ConnMap::iterator iter;
1155 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());
1157 if((iter = connections.find(req->dbid)) != connections.end())
1161 req->error = iter->second->Query(*req);
1163 return (req->error.Id() == NO_ERROR) ? sqlsuccess : NULL;
1167 req->error.Id(BAD_DBID);
1172 ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId());
1177 virtual void OnUnloadModule(Module* mod, const std::string& name)
1179 /* When a module unloads we have to check all the pending queries for all our connections
1180 * and set the Module* specifying where the query came from to NULL. If the query has already
1181 * been dispatched then when it is processed it will be dropped if the pointer is NULL.
1183 * If the queries we find are not already being executed then we can simply remove them immediately.
1185 for(ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++)
1187 iter->second->OnUnloadModule(mod);
1191 unsigned long NewID()
1199 virtual Version GetVersion()
1201 return Version(1, 1, 0, 0, VF_VENDOR|VF_SERVICEPROVIDER, API_VERSION);
1205 /* move this here to use AddConn, rather that than having the whole
1206 * module above SQLConn, since this is buggin me right now :/
1208 void SQLresolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
1211 ((ModulePgSQL*)mod)->AddConn(host);
1212 ((ModulePgSQL*)mod)->ClearOldConnections();
1215 class ModulePgSQLFactory : public ModuleFactory
1218 ModulePgSQLFactory()
1222 ~ModulePgSQLFactory()
1226 virtual Module * CreateModule(InspIRCd* Me)
1228 return new ModulePgSQL(Me);
1233 extern "C" void * init_module( void )
1235 return new ModulePgSQLFactory;