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()
{
}
};
+/** Used to resolve sql server hostnames
+ */
class SQLresolver : public Resolver
{
private:
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)
{
}
sqlsuccess = new char[strlen(SQLSUCCESS)+1];
- strcpy(sqlsuccess, SQLSUCCESS);
+ strlcpy(sqlsuccess, SQLSUCCESS, strlen(SQLSUCCESS)+1);
OnRehash("");
}
/* 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
{
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()
}
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 */
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);
{
/* ..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));
#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)
{
{
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));
}
}