- SQLhost host;
- int ipvalid;
- insp_inaddr blargle;
-
- host.id = conf.ReadValue("database", "id", i);
- host.host = conf.ReadValue("database", "hostname", i);
- host.port = conf.ReadInteger("database", "port", i, true);
- host.name = conf.ReadValue("database", "name", i);
- host.user = conf.ReadValue("database", "username", i);
- host.pass = conf.ReadValue("database", "password", i);
- host.ssl = conf.ReadFlag("database", "ssl", i);
-
- ipvalid = insp_aton(host.host.c_str(), &blargle);
-
- if(ipvalid > 0)
- {
- /* The conversion succeeded, we were given an IP and we can give it straight to SQLConn */
- this->AddConn(host);
- }
- else if(ipvalid == 0)
- {
- /* Conversion failed, assume it's a host */
- SQLresolver* 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
- {
- /* Invalid address family, die horribly. */
- ServerInstance->Log(DEBUG, "insp_aton failed returning -1, oh noes.");
- }
- }
- }
-
- void AddConn(const SQLhost& hi)
- {
- SQLConn* newconn;
-
- /* The conversion succeeded, we were given an IP and we can give it straight to SQLConn */
- newconn = new SQLConn(ServerInstance, this, hi);
-
- connections.insert(std::make_pair(hi.id, newconn));
- }
-
- virtual char* OnRequest(Request* request)
- {
- if(strcmp(SQLREQID, request->GetId()) == 0)
- {
- SQLrequest* req = (SQLrequest*)request;
- ConnMap::iterator iter;
-
- 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());
-
- if((iter = connections.find(req->dbid)) != connections.end())
- {
- /* Execute query */
- req->id = NewID();
- req->error = iter->second->Query(*req);
-
- return (req->error.Id() == NO_ERROR) ? sqlsuccess : NULL;
- }
- else
- {
- req->error.Id(BAD_DBID);
- return NULL;
- }