]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_mysql.cpp
The IPV6 stuff compiles now, with compile-correct ipv6 code. I dont know if this...
[user/henk/code/inspircd.git] / src / modules / extra / m_mysql.cpp
index 38c3b4c935549c689ebba4aef0ec7aae1c45fd67..7f2b96227177b4786cacc98337e6ddd8ea94b23a 100644 (file)
@@ -30,7 +30,7 @@ using namespace std;
 
 /* $ModDesc: SQL Service Provider module for all other m_sql* modules */
 /* $CompileFlags: `mysql_config --include` */
-/* $LinkerFlags: `mysql_config --libs_r` `perl ../mysql_rpath.pl` */
+/* $LinkerFlags: `mysql_config --libs_r` `perl extra/mysql_rpath.pl` */
 
 /* THE NONBLOCKING MYSQL API!
  * 
@@ -206,8 +206,9 @@ class MySQLresult : public SQLresult
        std::vector<std::string> colnames;
        std::vector<SQLfieldList> fieldlists;
        SQLfieldMap* fieldmap;
+       SQLfieldMap fieldmap2;
+       SQLfieldList emptyfieldlist;
        int rows;
-       int cols;
  public:
 
        MySQLresult(Module* self, Module* to, MYSQL_RES* res, int affected_rows, unsigned int id) : SQLresult(self, to, id), currentrow(0), fieldmap(NULL)
@@ -272,13 +273,7 @@ class MySQLresult : public SQLresult
 
        virtual int Rows()
        {
-               /* An INSERT can return 0 columns, but N rows. This is unsafe to
-                * allow the user to 'see'. Go figure. I hate you, MySQL devs.
-                */
-               if (colnames.size())
-                       return rows;
-               else
-                       return 0;
+               return rows;
        }
 
        virtual int Cols()
@@ -326,36 +321,55 @@ class MySQLresult : public SQLresult
 
        virtual SQLfieldList& GetRow()
        {
-               return fieldlists[currentrow];
+               if (currentrow < rows)
+                       return fieldlists[currentrow];
+               else
+                       return emptyfieldlist;
        }
 
        virtual SQLfieldMap& GetRowMap()
        {
-               fieldmap = new SQLfieldMap();
-               
-               for (int i = 0; i < cols; i++)
+               fieldmap2.clear();
+
+               if (currentrow < rows)
                {
-                       fieldmap->insert(std::make_pair(colnames[cols],GetValue(currentrow, i)));
+                       for (int i = 0; i < Cols(); i++)
+                       {
+                               fieldmap2.insert(std::make_pair(colnames[i],GetValue(currentrow, i)));
+                       }
+                       currentrow++;
                }
-               currentrow++;
 
-               return *fieldmap;
+               return fieldmap2;
        }
 
        virtual SQLfieldList* GetRowPtr()
        {
-               return &fieldlists[currentrow++];
+               SQLfieldList* fieldlist = new SQLfieldList();
+
+               if (currentrow < rows)
+               {
+                       for (int i = 0; i < Rows(); i++)
+                       {
+                               fieldlist->push_back(fieldlists[currentrow][i]);
+                       }
+                       currentrow++;
+               }
+               return fieldlist;
        }
 
        virtual SQLfieldMap* GetRowMapPtr()
        {
                fieldmap = new SQLfieldMap();
-
-               for (int i = 0; i < cols; i++)
+               
+               if (currentrow < rows)
                {
-                       fieldmap->insert(std::make_pair(colnames[cols],GetValue(currentrow, i)));
+                       for (int i = 0; i < Cols(); i++)
+                       {
+                               fieldmap->insert(std::make_pair(colnames[i],GetValue(currentrow, i)));
+                       }
+                       currentrow++;
                }
-               currentrow++;
 
                return fieldmap;
        }
@@ -367,11 +381,7 @@ class MySQLresult : public SQLresult
 
        virtual void Free(SQLfieldList* fl)
        {
-               /* XXX: Yes, this is SUPPOSED to do nothing, we
-                * dont want to free our fieldlist until we
-                * destruct the object. Unlike the pgsql module,
-                * we only have the one.
-                */
+               delete fl;
        }
 };
 
@@ -650,14 +660,18 @@ void* DispatcherThread(void* arg);
 
 class Notifier : public InspSocket
 {
-       sockaddr_in sock_us;
+       insp_sockaddr sock_us;
        socklen_t uslen;
        Server* Srv;
 
  public:
 
        /* Create a socket on a random port. Let the tcp stack allocate us an available port */
+#ifdef IPV6
+       Notifier(Server* S) : InspSocket("::1", 0, true, 3000), Srv(S)
+#else
        Notifier(Server* S) : InspSocket("127.0.0.1", 0, true, 3000), Srv(S)
+#endif
        {
                uslen = sizeof(sock_us);
                if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
@@ -674,7 +688,11 @@ class Notifier : public InspSocket
        /* Using getsockname and ntohs, we can determine which port number we were allocated */
        int GetPort()
        {
+#ifdef IPV6
+               return ntohs(sock_us.sin6_port);
+#else
                return ntohs(sock_us.sin_port);
+#endif
        }
 
        virtual int OnIncomingConnection(int newsock, char* ip)
@@ -735,7 +753,7 @@ class ModuleSQL : public Module
 
        char* OnRequest(Request* request)
        {
-               if(strcmp(SQLREQID, request->GetData()) == 0)
+               if(strcmp(SQLREQID, request->GetId()) == 0)
                {
                        SQLrequest* req = (SQLrequest*)request;
 
@@ -765,7 +783,7 @@ class ModuleSQL : public Module
                        return returnval;
                }
 
-               log(DEBUG, "Got unsupported API version string: %s", request->GetData());
+               log(DEBUG, "Got unsupported API version string: %s", request->GetId());
 
                return NULL;
        }
@@ -822,7 +840,7 @@ void* DispatcherThread(void* arg)
 
        /* Connect back to the Notifier */
 
-       if ((QueueFD = socket(AF_INET, SOCK_STREAM, 0)) == -1)
+       if ((QueueFD = socket(AF_FAMILY, SOCK_STREAM, 0)) == -1)
        {
                /* crap, we're out of sockets... */
                log(DEBUG,"QueueFD cant be created");
@@ -831,12 +849,19 @@ void* DispatcherThread(void* arg)
 
        log(DEBUG,"Initialize QueueFD to %d",QueueFD);
 
-       sockaddr_in addr;
-       in_addr ia;
-       inet_aton("127.0.0.1", &ia);
-       addr.sin_family = AF_INET;
+       insp_sockaddr addr;
+
+#ifdef IPV6
+       insp_aton("::1", &addr.sin6_addr);
+       addr.sin6_family = AF_FAMILY;
+       addr.sin6_port = htons(MessagePipe->GetPort());
+#else
+       insp_inaddr ia;
+       insp_aton("127.0.0.1", &ia);
+       addr.sin_family = AF_FAMILY;
        addr.sin_addr = ia;
        addr.sin_port = htons(MessagePipe->GetPort());
+#endif
 
        if (connect(QueueFD, (sockaddr*)&addr,sizeof(addr)) == -1)
        {
@@ -908,4 +933,3 @@ extern "C" void * init_module( void )
 {
        return new ModuleSQLFactory;
 }
-