]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_mssql.cpp
Fix this (thx danieldg and owine)
[user/henk/code/inspircd.git] / src / modules / extra / m_mssql.cpp
index 2038052055bec3f5502f1fb6bc68eb47597a4796..ab4d2aa717e6af1d90beaafaa33390716e35e149 100644 (file)
@@ -294,6 +294,9 @@ class SQLConn : public classbase
 
        SQLerror Query(SQLrequest &req)
        {
+               if (!sock)
+                       return SQLerror(BAD_CONN, "Socket was NULL, check if SQL server is running.");
+                       
                /* Pointer to the buffer we screw around with substitution in */
                char* query;
 
@@ -368,17 +371,18 @@ class SQLConn : public classbase
                res->dbid = host.id;
                res->query = req.query.q;
 
-               const char* msquery = strdup(req.query.q.data());
+               char* msquery = strdup(req.query.q.data());
                Instance->Logs->Log("m_mssql",DEBUG,"doing Query: %s",msquery);
                if (tds_submit_query(sock, msquery) != TDS_SUCCEED)
                {
                        std::string error("failed to execute: "+std::string(req.query.q.data()));
                        delete[] query;
                        delete res;
+                       free(msquery);
                        return SQLerror(QSEND_FAIL, error);
                }
                delete[] query;
-               delete[] msquery;
+               free(msquery);
                
                int tds_res;
                while (tds_process_tokens(sock, &tds_res, NULL, TDS_TOKEN_RESULTS) == TDS_SUCCEED)
@@ -443,17 +447,15 @@ class SQLConn : public classbase
 
        static int HandleMessage(const TDSCONTEXT * pContext, TDSSOCKET * pTdsSocket, TDSMESSAGE * pMessage)
        {
-               /* TODO: FIXME */
-               //Instance->Logs->Log("m_mssql",DEBUG,pMessage->message);
-               //printf("Message: %s\n", pMessage->message);
+               SQLConn* sc = (SQLConn*)pContext->parent;
+               sc->Instance->Logs->Log("m_mssql", DEBUG, "Message for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
                return 0;
        }
 
        static int HandleError(const TDSCONTEXT * pContext, TDSSOCKET * pTdsSocket, TDSMESSAGE * pMessage)
        {
-               /* TODO: FIXME */
-               //Instance->Logs->Log("m_mssql",DEBUG,pMessage->message);
-               //printf("Error: %s\n", pMessage->message);
+               SQLConn* sc = (SQLConn*)pContext->parent;
+               sc->Instance->Logs->Log("m_mssql", DEFAULT, "Error for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
                return 0;
        }
 
@@ -472,7 +474,7 @@ class SQLConn : public classbase
                CloseDB();
 
                TDSCONTEXT* cont;
-               cont = tds_alloc_context(NULL);
+               cont = tds_alloc_context(this);
                cont->msg_handler = HandleMessage;
                cont->err_handler = HandleError;
 
@@ -499,6 +501,9 @@ class SQLConn : public classbase
                        tds_free_socket(sock);
                if (conn)
                        tds_free_connection(conn);
+               login = NULL;
+               sock = NULL;
+               conn = NULL;
        }
 
        SQLhost GetConfHost()
@@ -649,7 +654,6 @@ class ModuleMsSQL : public Module
                        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", "0", i);
                        if (h == host)
                                return true;
                }
@@ -671,7 +675,6 @@ class ModuleMsSQL : public Module
                        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", "0", i);
 
                        if (HasHost(host))
                                continue;