-/** SQLConn represents one SQL session.
- * Each session has its own persistent connection to the database.
- * This is a subclass of InspSocket so it can easily recieve read/write events from the core socket
- * engine, unlike the original MySQL module this module does not block. Ever. It gets a mild stabbing
- * if it dares to.
- */
-
-class SQLConn : public InspSocket
-{
-private:
- Module* us; /* Pointer to the SQL provider itself */
- std::string dbhost; /* Database server hostname */
- unsigned int dbport; /* Database server port */
- std::string dbname; /* Database name */
- std::string dbuser; /* Database username */
- std::string dbpass; /* Database password */
- bool ssl; /* If we should require SSL */
- PGconn* sql; /* PgSQL database connection handle */
- SQLstatus status; /* PgSQL database connection status */
- bool qinprog; /* If there is currently a query in progress */
- QueryQueue queue; /* Queue of queries waiting to be executed on this connection */
- time_t idle; /* Time we last heard from the database */
- SQLhost confhost; /* A copy of the config <database> entry for conf checks */
-public:
-
- /* This class should only ever be created inside this module, using this constructor, so we don't have to worry about the default ones */
-
- SQLConn(InspIRCd* SI, Module* self, const SQLhost& hostinfo, const SQLhost& confinfo);
-
- ~SQLConn();
-
- bool DoConnect();
-
- virtual void Close();
-
- void DoClose();
-
- bool DoPoll();
-
- bool DoConnectedPoll();
-
- bool DoResetPoll();
-
- void ShowStatus();
-
- virtual bool OnDataReady();
-
- virtual bool OnWriteReady();
-
- virtual bool OnConnected();
-
- bool DoEvent();
-
- bool Reconnect();
-
- std::string MkInfoStr();
-
- const char* StatusStr();
-
- SQLerror DoQuery(SQLrequest &req);
-
- SQLerror Query(const SQLrequest &req);
-
- void OnUnloadModule(Module* mod);
-
- const SQLhost GetConfHost();
-};
-
-SQLConn::SQLConn(InspIRCd* SI, Module* self, const SQLhost& hi, const SQLhost& ci)
-: InspSocket::InspSocket(SI), us(self), dbhost(hi.host), dbport(hi.port), dbname(hi.name), dbuser(hi.user), dbpass(hi.pass), ssl(hi.ssl), sql(NULL), status(CWRITE), qinprog(false)
-{
- //ServerInstance->Log(DEBUG, "Creating new PgSQL connection to database %s on %s:%u (%s/%s)", dbname.c_str(), dbhost.c_str(), dbport, dbuser.c_str(), dbpass.c_str());
-
- /* Some of this could be reviewed, unsure if I need to fill 'host' etc...
- * just copied this over from the InspSocket constructor.
- */
- confhost = ci;
- strlcpy(this->host, dbhost.c_str(), MAXBUF);
- strlcpy(this->IP, dbhost.c_str(), MAXBUF);
- this->port = dbport;
- idle = this->Instance->Time();
-
- this->ClosePending = false;
-
- Instance->Log(DEBUG,"No need to resolve %s", this->host);
-
- if(!this->DoConnect())
- {
- throw ModuleException("Connect failed");
- }
-}