]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_mssql.cpp
Handle file not found, and tidy up the perl.
[user/henk/code/inspircd.git] / src / modules / extra / m_mssql.cpp
index 814f02691015bc924586fb309d6294d0a0abfb6a..3083dcec2f105e876dc1a1507ba08b869942f412 100644 (file)
@@ -21,6 +21,7 @@
 #include "m_sqlv2.h"
 
 /* $ModDesc: MsSQL provider */
+/* $CompileFlags: exec("grep VERSION_NO /usr/include/tdsver.h 2>/dev/null | perl -e 'print "-D_TDSVER=".((<> =~ /freetds v(\d+\.\d+)/i) ? $1*100 : 0);'") */
 /* $LinkerFlags: -ltds */
 /* $ModDep: m_sqlv2.h */
 
@@ -46,10 +47,10 @@ class QueryThread : public Thread
 {
   private:
        ModuleMsSQL* Parent;
-       InspIRCd* Instance;
+       InspIRCd* ServerInstance;
   public:
        QueryThread(InspIRCd* si, ModuleMsSQL* mod)
-       : Thread(), Parent(mod), Instance(si)
+       : Thread(), Parent(mod), ServerInstance(si)
        {
        }
        ~QueryThread() { }
@@ -68,7 +69,7 @@ class ResultNotifier : public BufferedSocket
        virtual bool OnDataReady()
        {
                char data = 0;
-               if (Instance->SE->Recv(this, &data, 1, 0) > 0)
+               if (ServerInstance->SE->Recv(this, &data, 1, 0) > 0)
                {
                        Dispatch();
                        return true;
@@ -82,7 +83,7 @@ class ResultNotifier : public BufferedSocket
 class MsSQLListener : public ListenSocketBase
 {
        ModuleMsSQL* Parent;
-       insp_sockaddr sock_us;
+       irc::sockets::insp_sockaddr sock_us;
        socklen_t uslen;
        FileReader* index;
 
@@ -285,7 +286,7 @@ class SQLConn : public classbase
 {
  private:
        ResultQueue results;
-       InspIRCd* Instance;
+       InspIRCd* ServerInstance;
        Module* mod;
        SQLhost host;
        TDSLOGIN* login;
@@ -296,7 +297,7 @@ class SQLConn : public classbase
        QueryQueue queue;
 
        SQLConn(InspIRCd* SI, Module* m, const SQLhost& hi)
-       : Instance(SI), mod(m), host(hi), login(NULL), sock(NULL), context(NULL)
+       : ServerInstance(SI), mod(m), host(hi), login(NULL), sock(NULL), context(NULL)
        {
                if (OpenDB())
                {
@@ -306,7 +307,7 @@ class SQLConn : public classbase
                                if (tds_process_simple_query(sock) != TDS_SUCCEED)
                                {
                                        LoggingMutex->Lock();
-                                       Instance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
+                                       ServerInstance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
                                        LoggingMutex->Unlock();
                                        CloseDB();
                                }
@@ -314,7 +315,7 @@ class SQLConn : public classbase
                        else
                        {
                                LoggingMutex->Lock();
-                               Instance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
+                               ServerInstance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
                                LoggingMutex->Unlock();
                                CloseDB();
                        }
@@ -322,7 +323,7 @@ class SQLConn : public classbase
                else
                {
                        LoggingMutex->Lock();
-                       Instance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not connect to DB with id: " + host.id);
+                       ServerInstance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not connect to DB with id: " + host.id);
                        LoggingMutex->Unlock();
                        CloseDB();
                }
@@ -414,7 +415,7 @@ class SQLConn : public classbase
 
                char* msquery = strdup(req.query.q.data());
                LoggingMutex->Lock();
-               Instance->Logs->Log("m_mssql",DEBUG,"doing Query: %s",msquery);
+               ServerInstance->Logs->Log("m_mssql",DEBUG,"doing Query: %s",msquery);
                LoggingMutex->Unlock();
                if (tds_submit_query(sock, msquery) != TDS_SUCCEED)
                {
@@ -430,8 +431,8 @@ class SQLConn : public classbase
                int tds_res;
                while (tds_process_tokens(sock, &tds_res, NULL, TDS_TOKEN_RESULTS) == TDS_SUCCEED)
                {
-                       //Instance->Logs->Log("m_mssql",DEBUG,"<******> result type: %d", tds_res);
-                       //Instance->Logs->Log("m_mssql",DEBUG,"AFFECTED ROWS: %d", sock->rows_affected);
+                       //ServerInstance->Logs->Log("m_mssql",DEBUG,"<******> result type: %d", tds_res);
+                       //ServerInstance->Logs->Log("m_mssql",DEBUG,"AFFECTED ROWS: %d", sock->rows_affected);
                        switch (tds_res)
                        {
                                case TDS_ROWFMT_RESULT:
@@ -469,7 +470,11 @@ class SQLConn : public classbase
                                                                unsigned char* src;
                                                                CONV_RESULT dres;
                                                                ctype = tds_get_conversion_type(col->column_type, col->column_size);
-                                                               src = &(sock->current_results->current_row[col->column_offset]);
+#if _TDSVER >= 82
+                                                                       src = col->column_data;
+#else
+                                                                       src = &(sock->current_results->current_row[col->column_offset]);
+#endif
                                                                srclen = col->column_cur_size;
                                                                tds_convert(sock->tds_ctx, ctype, (TDS_CHAR *) src, srclen, SYBCHAR, &dres);
                                                                data[j] = (char*)dres.ib;
@@ -494,7 +499,7 @@ class SQLConn : public classbase
        {
                SQLConn* sc = (SQLConn*)pContext->parent;
                LoggingMutex->Lock();
-               sc->Instance->Logs->Log("m_mssql", DEBUG, "Message for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
+               sc->ServerInstance->Logs->Log("m_mssql", DEBUG, "Message for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
                LoggingMutex->Unlock();
                return 0;
        }
@@ -503,7 +508,7 @@ class SQLConn : public classbase
        {
                SQLConn* sc = (SQLConn*)pContext->parent;
                LoggingMutex->Lock();
-               sc->Instance->Logs->Log("m_mssql", DEFAULT, "Error for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
+               sc->ServerInstance->Logs->Log("m_mssql", DEFAULT, "Error for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
                LoggingMutex->Unlock();
                return 0;
        }
@@ -620,15 +625,15 @@ class SQLConn : public classbase
                                return;
                        }
 
-                       insp_sockaddr addr;
+                       irc::sockets::insp_sockaddr addr;
 
 #ifdef IPV6
-                       insp_aton("::1", &addr.sin6_addr);
+                       irc::sockets::insp_aton("::1", &addr.sin6_addr);
                        addr.sin6_family = AF_FAMILY;
                        addr.sin6_port = htons(listener->GetPort());
 #else
-                       insp_inaddr ia;
-                       insp_aton("127.0.0.1", &ia);
+                       irc::sockets::insp_inaddr ia;
+                       irc::sockets::insp_aton("127.0.0.1", &ia);
                        addr.sin_family = AF_FAMILY;
                        addr.sin_addr = ia;
                        addr.sin_port = htons(listener->GetPort());
@@ -710,7 +715,6 @@ class ModuleMsSQL : public Module
                ClearAllConnections();
 
                ServerInstance->SE->DelFd(listener);
-               //listener->Close();
                ServerInstance->BufferedSocketCull();
 
                if (QueueFD >= 0)